Friday, February 20, 2009

Encrypt your private blog post

[轉載] [Javascript] Encrypt your private blog post from the article of Kaie's Blog

今日在PPT上的Blog版逛到版友weijr所提到的一篇好文章,可以用來針對Blog中某一段文字給予加密,變成讓人無法理解的「火星文」 XD.. 解密過程只輸入正確的密碼之後,即可馬上在Blog上顯示出正確的「地球文」,不用重新Reload...超棒的Hack,對於此類技術性的Hack,個人超愛的…

研究所時有碰過一些跟Cryptography(密碼學)有關的東西,但只懂一點理論上的皮毛而已,沒有動作實作過,如今玩Blogger的同時,剛好有個有人心士將他所學應用在他的需求上,真是與實務面作了結合,太棒了老兄…我要向他看齊..XD。

原作者實現此Hack的用意就是: 他想要將他一些私人的、不方便公開的東西,亦或某些只想供親朋好友看的內容,記錄在公開的Blog上頭,又不失隱密性,且方便日後查詢,於是針對這些私密訊息的簡易加解密功能就如此誕生啦! (所利用的演算法是 256-bit AES,目前來說「安全性」算相當高了)

※適用範圍: 所有支援Javascript的Blog,若不幸你的Blog不支援的話,快跳槽來「Blogger」吧,保證可以隨便你惡搞的Blog平台,不會後悔的資料來源:
Vincent Cheung -> Encrypted blog posts
快往下瞧瞧這強大的Hack吧... :D
:: Demo (展現出來的效果如下,兩種方式) ::
Key(密鑰): ie-sucks

* Demo1:
Click to Decrypt text (點擊此處解開火星文,裡頭有清涼的唷)

恭喜你解碼成功,順便送你看個辣妹,地球文還是好懂多了吧...
* Demo2:
Show encrypted text (點擊此處變身為火星人)


火星人:是不是超屌的呀!! 再不來安裝一下,就對不起自己了..



上方展現出來的效果是不是很炫呀 ^_^,超吸引人的吧,快來安裝一下吧,底下開始中文化原文..囧rz,方法如下:

首先在你的Blog中嵌入此Hack所需的Javascript,在Blogger的使用方法就是將底下的code加在Template中的上面即可(其它Blog方法就是加在header裡頭就對了)

完成上面動作之後,基本上就完成了,若要在新文章中新增「火星文時」的話,請透過底下兩個步驟:

1. 產生加密過後的火星文:
透過此網站,輸入「Key」欄位以及「Plain Text」欄位,接著按Encrypt Button(加密鈕,在Plain Text欄的下方),此時便會在「Cipher Text」欄位產生加密過後的火星文字啦(底下會用到..)!!
※千萬要記得上方你自行定義的Key,之後解密時要用的,若忘記了,恐怕沒有量子電腦(Quantum Computer)這般等級的高速電腦是解不出來的。
2. 嵌入火星文片段至新文章中:
共有底下兩種顯示方式,依個人喜好選擇擇一
.方法一(如上頭Demo1,直接在文章中顯示火星文):Click to Decrypt text (點擊此處解開火星文)

此段內容為由上面Step1.所產生出來的一整段火星文(例如:wRxSwskrWsmohc1...之類的文字)


.方法二(如上頭Demo2,隱藏火星文,只顯示連結):Show encrypted text



※注意上方的unique_name型態是div tag的一個id名子,可以自行命名,只要在template中,或文章中不出現同樣的id即可,否則會造成判斷錯誤!!也就是在一個顯示頁面中,有用到兩個以上火星文片段的話,那麼此id的命名就必須是unique_name,unique_name1,unique_name2...之類的。


最後,作者很風趣的列舉了幾個常見問題(Faq),很北爛的一個傢伙...有興趣去看看...

Wednesday, February 18, 2009

Make the DLL compiled-linked with GCC under Cygwin valid and acceptable for Microsoft Visual Studio

First of all, we need to have the DLL and DEF files generated by GCC. Here is the command to do so.
Assuming we have foo.c
gcc -mno-cygwin -shared -o foo.dll foo.c -Wl,--output-def,foo.def,--out-implib,libfoo.a
The output files are foo.dll, libfoo.a, foo.def.
Second, using Microsoft Library Manager lib.exe utility to generate the foo.lib with foo.def. Here is the command:
lib.exe /machine:i386 /def:foo.def
Then we will get a foo.lib
Now, we are ready to use it in the Visual Studio's Project.
All you need to do is to add the foo.lib to Linker->Input->Additional Dependencies field and put foo.lib and foo.dll in your project's folder.
P.S. If you cannot find lib.exe or fail to launch lib.exe, check the PATH of your System Variables. (right click on My Computer->Properties->Advanced tab->Environment Variables->System Variables)
Make sure C:\Program Files\Microsoft Visual Studio 8\VC\bin and C:\Program Files\Microsoft Visual Studio 8\Common7\IDE are there in the PATH.

Using GCC to create static and shared library

[轉貼]用GCC自製Library

引用: PTT看板: LinuxDev (作者: cole945)



Library可分成三種,staticshareddynamically loaded

1. Static libraries

Static
程式庫用於靜態連結,簡單講是把一堆object檔用ar(archiver)
包裝集合起來,檔名以 `.a' 結尾。優點是執行效能通常會比後兩者快,
而且因為是靜態連結,所以不易發生執行時找不到library或版本錯置而
無法執行的問題。缺點則是檔案較大,維護度較低;例如library如果發
bug需要更新,那麼就必須重新連結執行檔。

1.1
編譯

編譯方式很簡單,先例用 `-c' 編出 object 檔,再用 ar 包起來即可。

____ hello.c ____
#include <stdio.h>
void hello(){ printf("Hello "); }

____ world.c ____
#include <stdio.h>
void world(){ printf("world."); }

____ mylib.h ____
void hello();
void world();

$ gcc -c hello.c world.c /*
編出 hello.o world.o */
$ ar rcs libmylib.a hello.o world.o /*
包成 limylib.a */

這樣就可以建出一個檔名為 libmylib.a 的檔。輸出的檔名其實沒有硬性規定,
但如果想要配合 gcc '-l' 參數來連結,一定要以 `lib' 開頭,中間是你要
library名稱,然後緊接著 `.a' 結尾。

1.2
使用

____ main.c ____
#include "mylib.h"
int main() {
hello();
world();
}

使用上就像與一般的 object 檔連結沒有差別。

$ gcc main.c libmylib.a

也可以配合 gcc `-l' 參數使用

$ gcc main.c -L. -lmylib

`-Ldir'
參數用來指定要搜尋程式庫的目錄,`.' 表示搜尋現在所在的目錄。
通常預設會搜 /usr/lib /lib 等目錄。
`-llibrary'
參數用來指定要連結的程式庫 'mylib' 表示要與mylib進行連結
,他會搜尋library名稱前加`lib'後接`.a'的檔案來連結。

$ ./a.out
Hello world.


2. Shared libraries

Shared library
會在程式執行起始時才被自動載入。因為程式庫與執行檔
是分離的,所以維護彈性較好。有兩點要注意,shared library是在程式起始
時就要被載入,而不是執行中用到才載入,而且在連結階段需要有該程式庫
才能進行連結。

首先有一些名詞要弄懂,sonamereal namelinker name

soname
用來表示是一個特定 library 的名稱,像是 libmylib.so.1
前面以 `lib' 開頭,接著是該 library 的名稱,然後是 `.so' ,接著
是版號,用來表名他的介面;如果介面改變時,就會增加版號來維護相容度。

real name
是實際放有library程式的檔案名稱,後面會再加上 minor 版號與
release
版號,像是 libmylib.so.1.0.0

一般來說,版號的改變規則是(印象中在 APress-Difinitive Guide to GCC中有
提到,但目前手邊沒這本書),最尾碼的release版號用於程式內容的修正,
介面完全沒有改變。中間的minor用於有新增加介面,但相舊介面沒改變,所以
與舊版本相容。最前面的version版號用於原介面有移除或改變,與舊版不相容
時。

linker name
是用於連結時的名稱,是不含版號的 soname ,如: libmylib.so
通常 linker name real name是用 ln 指到對應的 real name ,用來提供
彈性與維護性。

2.1 編譯
shared library
的製作過程較複雜。

$ gcc -c -fPIC hello.c world.c

編譯時要加上 -fPIC 用來產生 position-independent code。也可以用 -fpic
參數。 (不太清楚差異,只知道 -fPIC 較通用於不同平台,但產生的code較大
,而且編譯速度較慢)

$ gcc -shared -Wl,-soname,libmylib.so.1 -o libmylib.so.1.0.0 \
hello.o world.o

-shared
表示要編譯成 shared library
-Wl
用於參遞參數給linker,因此-sonamelibmylib.so.1會被傳給linker處理。
-soname
用來指名 soname limylib.so.1
library
會被輸出成libmylib.so.1.0.0 (也就是real name)

若不指定 soname 的話,在編譯結連後的執行檔會以連時的library檔名為
soname
,並載入他。否則是載入soname指定的library檔案。

可以利用 objdump 來看 library soname

$ objdump -p libmylib.so | grep SONAME
SONAME libmylib.so.1

若不指名-soname參數的話,則library不會有這個欄位資料。

在編譯後再用 ln 來建立 soname linker name 兩個檔案。
$ ln -s libmylib.so.1.0.0 libmylib.so
$ ln -s libmylib.so.1.0.0 libmylib.so.1


2.2
使用

與使用 static library 同。

$ gcc main.c libmylib.so

以上直接指定與 libmylib.so 連結。

或用

$ gcc main.c -L. -lmylib

linker
會搜尋 libmylib.so 來進行連結。

如果目錄下同時有staticshared library的話,會以shared為主。
使用 -static 參數可以避免使用shared連結。

$ gcc main.c -static -L. -lmylib

此時可以用 ldd 看編譯出的執行檔與shared程式庫的相依性
$ldd a.out
linux-gate.so.1 => (0xffffe000)
libmylib.so.1 => not found
libc.so.6 => /lib/libc.so.6 (0xb7dd6000)
/lib/ld-linux.so.2 (0xb7f07000)
輸出結果顯示出該執行檔需要 libmylib.so.1 這個shared library
會顯示 not found 因為沒指定該library所在的目錄,所找不到該library

因為編譯時有指定-soname參數為 libmylib.so.1 的關係,所以該執行檔會
載入libmylib.so.1。否則以libmylib.so連結,執行檔則會變成要求載入
libmylib.so

$ ./a.out
./a.out: error while loading shared libraries: libmylib.so.1:
cannot open shared object file: No such file or directory

因為找不到 libmylib.so.1 所以無法執行程式。
有幾個方式可以處理。

a.
libmylib.so.1 安裝到系統的library目錄,如/usr/lib
b.
設定 /etc/ld.so.conf ,加入一個新的library搜尋目錄,並執行ldconfig
更新快取
c.
設定 LD_LIBRARY_PATH 環境變數來搜尋library
這個例子是加入目前的目錄來搜尋要載作的library
$ LD_LIBRARY_PATH=. ./a.out
Hello world.

3. Dynamically loaded libraries

Dynamicaaly loaded libraries
才是像 windows 所用的 DLL ,在使用到
時才載入,編譯連結時不需要相關的library。動態載入庫常被用於像plug-ins
的應用。

3.1
使用方式
動態載入是透過一套 dl function來處理。
#include <dlfcn.h>
void *dlopen(const char *filename, int flag);
開啟載入 filename 指定的 library
void *dlsym(void *handle, const char *symbol);
取得 symbol 指定的symbol namelibrary被載入的記憶體位址。
int dlclose(void *handle);
關閉dlopen開啟的handle
char *dlerror(void);
傳回最近所發生的錯誤訊息。

____ dltest.c ____
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
int main() {
void *handle;
void (*f)();
char *error;

/*
開啟之前所撰寫的 libmylib.so 程式庫 */
handle = dlopen("./libmylib.so", RTLD_LAZY);
if( !handle ) {
fputs( dlerror(), stderr);
exit(1);
}

/*
取得 hello function address */
f = dlsym(handle, "hello");
if(( error=dlerror())!=NULL) {
fputs(error, stderr);
exit(1);
}
/*
呼叫該 function */
f();
dlclose(handle);
}

編譯時要加上 -ldl 參數來與 dl library 連結
$ gcc dltest.c -ldl
結果會印出 Hello 字串
$ ./a.out
Hello

關於dl的詳細內容請參閱 man dlopen

--
參考資料:

Creating a shared and static library with the gnu compiler [gcc]
http://www.adp-gmbh.ch/cpp/gcc/create_lib.html

Program Library HOWTO
http://tldp.org/HOWTO/Program-Library-HOWTO/index.html

APress - Definitive Guide to GCC

Monday, February 16, 2009

Compile FFMPEG with Cygwin under Windows

This atricle guides you how to compile FFMPEG with Cygwin under Windows. The orginal post is at http://mqjing.blogspot.com/2008/12/c-cygwin-ffmpeg-make-ffmpeg-under.html by 井民全.

FFmpeg 是著名的多媒體壓縮解壓縮 library, 例如: 你想處理壓縮 Xvid 或 Divx 壓縮解壓縮, 這個專案裡面的 source 你都可以參考. 可是呢...

這東西不好編譯!

尤其是你以為正在編譯的版本和網路上文章作者所說的一樣時, 你就會開始犯錯. 要正確的編譯 FFmpeg 你一定要注意版本序號以及你的編譯環境.

FFmpeg 版本一直在進展, 昨天更新的最新 source code 並不一定保證在任何的編譯環境都能順利成功. 因為 update 的作者不一定會把所有的編譯環境都測過才 update, 如此一來可以意味著 open source 領域有一個 source code dependency 問題.

如果你想要編譯 FFmpeg 最好使用作者當時寫作並測試通過的所有軟體版本, 已保證第一次就會成功.

open source 社群漏掉的拼圖, 就是編譯環境與 source code 的版本控制還不是那麼的完善, 新版本的 library source code 可能造成其他的第三方應用軟體編譯失敗. 現在想想很明白這道理, 可是這卻是大家花費大量寶貴時間解決編譯問題的根源所在.

或許在編譯之前就要詳細檢查所有會用到 source code 的版本, 現在 ./configure 不完整, 要徹底解決 source code 版本 dependency 的問題, 還有待大家努力!

Step 1: Checkout the FFmpeg source code (20080508 版本)

  • svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk@12383 ffmpeg-12383

(我使用 revision 12383 版以前的原因, 在於最新版的 vfwcap.c 無法在 cygwin 下編譯成功)


Step 2: Patch--ffmpeg--cygwin (see link)

  • replace all llrint functions to the lrint in the libavcodec/mpegaudiodec.c

Step 3: Setup the configure option script

1. modify the option from --enable-pp to the --enable-postproc

  • from revision 12376, rename pp variable to postproc for consistency

2. --target-os=mingw32 (from revision 8049)

3. [Optional] modify the option from --enable-amr_nb to the --enable-libamr-nb (not free. see:http://www.3gpp.org)

4. [Optional] add the option --enable-nonfree , if you add the option --enable-amr_nb

ex:

--------------------- configure-ffmpeg.sh ---------------------

./configure --enable-memalign-hack \
--enable-postproc \
--extra-cflags=-I/usr/win32/include \
--extra-ldflags=-L/usr/win32/lib \
--prefix=/usr/win32 \
--cc="gcc -mno-cygwin" \
--enable-gpl \
--disable-vhook \
--enable-shared \
--target-os=mingw32 \
--extra-cflags=-mno-cygwin \
--extra-libs=-mno-cygwin

--------------------- configure-ffmpeg.sh ---------------------

5. Update your /usr/win32/include

These content is out of the version of the FFmpeg which you want to build. Update these files by yourself. Copy all header files in the following directories to /usr/win32/include.

ffmpeg-12383\libavcodec, libavdevice, libavfilter, libavformat, libavutil, libpostproc, libswscale

7. Create Makefile for building the FFmpeg

run the following command to setup the FFmpeg configures

   configure-ffmpeg.sh


 


6. make


加入 amr 語音libarary 的步驟


1. 新增 configure-ffmpeg.sh



--enable-libamr-nb \

--enable-nonfree \



2. 修改 source code



at ffmpeg-12383/libavcodec/libamr.c



#include 改成 #include



#include 改成 #include



否則你可能會遭遇到 下面的錯誤訊息



libamr.c:80:30: amrnb/interf_dec.h: No such file or directory

libamr.c:81:30: amrnb/interf_enc.h: No such file or directory


libamr.c:93: error: field `mode' has incomplete type



3. 增加 amr_float 內相關的 depend



否則你會遭遇到下面的錯誤



---------------------------------------------------------------------



libamr.o: In function `amr_nb_decode_init':

/home/Jing/ffmpeg-12383/libavcodec/libamr.c:369: undefined reference to `_Decode


r_Interface_init'


libamr.o: In function `amr_nb_encode_init':


/home/Jing/ffmpeg-12383/libavcodec/libamr.c:408: undefined reference to `_Encode


r_Interface_init'



---------------------------------------------------------------------



a. cd /home/Jing/ffmpeg-12383/libavcodec/amr_float



b. 修改 amr_float 裡面的 makefile.gcc, 讓他獨立於 cygwin



原來是



CFLAGS = -Wall -I. $(CFLAGS_$(MODE)) -D$(VAD)



加上 CFLAGS = -Wall -mno-cygwin -I. $(CFLAGS_$(MODE)) -D$(VAD)



否則你在編譯 ffmpeg 的 libcodec 時, 會遇到 找不到 ___getreent 的錯誤.



amr_float/interf_dec.o:interf_dec.c:(.text+0x34e): undefined reference to `___ge

treent'


amr_float/interf_enc.o:interf_enc.c:(.text+0x56e): undefined reference to `___ge


treent'



c. 產生必要的 .o 檔



make -fmakefile.gcc



d. 修改 ffmpeg/libcocdec 的 Makefile, 加入必要的 amr_float object files



OBJS-$(CONFIG_LIBAMR_NB) += libamr.o



改成


OBJS-$(CONFIG_LIBAMR_NB) += libamr.o ./amr_float/interf_dec.o ./amr_float/interf_enc.o ./amr_float/sp_dec.o ./amr_float/sp_enc.o

Thursday, February 21, 2008

My girl is coming to this world

Today, Feb. 21 2008, is my wife's estimated date of delivery. However, it seems that my little girl doesn't wanna come to this world yet. This does piss my wife off. Haha...
Anyway, we are having the childbirth examine tonite and see what's next.
Hope anything is going well~
My little girl~ See you soon!

A man who can't even believe he is gonna be the father wrote.

MPEG-2 Transmission

Source from http://www.erg.abdn.ac.uk/research/future-net/digital-video/mpeg2-trans.html.


MPEG-2 Transmission

The MPEG-2 standards define how to format the various component parts of a multimedia programme (which may consist of: MPEG-2 compressed video, compressed audio, control data and/or user data). It also defines how these components are combined into a single synchronous transmission bit stream. The process of combining the steams is known as multiplexing.

The multiplexed stream may be transmitted over a variety of links, standards / products are (or will soon be) available for :

  • Radio Frequency Links (UHF/VHF)
  • Digital Broadcast Satellite Links
  • Cable TV Networks
  • Standard Terrestrial Communication Links (PDH, SDH)
  • Microwave Line of Sight (LoS) Links (wireless)
  • Digital Subscriber Links (ADSL family)
  • Packet / Cell Links (ATM, IP, IPv6, Ethernet)

Many of these formats are being standardised by the DVB project.


Building the MPEG Bit Stream

To understand how the component parts of the bit stream are multiplexed, we need to first look at each component part. The most basic component is known as an Elementary Stream in MPEG. A programme (perhaps most easily thought of as a television programme, or a Digital Versatile Disk (DVD) track) contains a combination of elementary streams (typically one for video, one or more for audio, control data, subtitles, etc).

Elementary Stream (ES)

Each Elementary Stream (ES) output by an MPEG audio, video and (some) data encoders contain a single type of (usually compressed) signal. There are various forms of ES, including:

  • Digital Control Data
  • Digital Audio (sampled and compressed)
  • Digital Video (sampled and compressed)
  • Digital Data (synchronous, or asynchronous)

For video and audio, the data is organised into access units, each representing a fundamental unit of encoding. For example, in video, an access unit will usually be a complete encoded video frame.

Packetised Elementary Stream (PES)

Each ES is input to an MPEG-2 processor (e.g. a video compressor or data formatted) which accumulates the data into a stream of Packetised Elementary Stream (PES) packets. A PES packet may be a fixed (or variable) sized block, with up to 65536 bytes per block and includes a 6 byte protocol header. A PES is usually organised to contain an integral number of ES access units.

The PES header starts with a 3 byte start code, followed by a one byte stream ID and a 2 byte length field.

The following well-known stream IDs are defined in the MPEG standard:

  1. 110x xxxx - MPEG-2 audio stream number x xxxx.
  2. 1110 yyyy - MPEG-2 video stream number yyyy.
  3. 1111 0010 - MPEG-2 DSM-CC control packets.

The next field contain the PES Indicators. These provide additional information about the stream to assist the decoder at the receiver. The following indicators are defined:

  • PES_Scrambling_Control - Defines whether scrambling is used, and the chosen scrambling method.
  • PES_Priority - Indicates priority of the current PES packet.
  • data_alignment_indicator - Indicates if the payload starts with a video or audio start code.
  • copyright information - Indicates if the payload is copyright protected.
  • original_or_copy - Indicates if this is the original ES.

A one byte flags field completes the PES header. This defines the following optional fields, which if present, are inserted before the start of the PES payload.

  • Presentation Time Stamp (PTS) and possibly a Decode Time Stamp (DTS) - For audio / video streams these time stamps which may be used to synchronise a set of elementary streams and control the rate at which they are replayed by the receiver.
  • Elementary Stream Clock Reference (ESCR)
  • Elementary Stream rate - Rate at which the ES was encoded.
  • Trick Mode - indicates the video/audio is not the normal ES, e.g. after DSM-CC has signalled a replay.
  • Copyright Information - set to 1 to indicated a copyright ES.
  • CRC - this may be used to monitor errors in the previous PES packet
  • PES Extension Information - may be used to support MPEG-1 streams.

The PES packet payload includes the ES data. The information in the PES header is, in general, independent of the transmission method used.

MPEG-2 Multiplexing

The MPEG-2 standard allows two forms of multiplexing:

  • MPEG Program Stream A group of tightly coupled PES packets referenced to the same time base. Such streams are suited for transmission in a relatively error-free environment and enable easy software processing of the received data. This form of multiplexing is used for video playback and for some network applications.
  • MPEG Transport Stream Each PES packet is broken into fixed-sized transport packets forming a general purpose way of combining one or more streams, possibly with independent time bases. This is suited for transmission in which there may be potential packet loss or corruption by noise, or / and where there is a need to send more than one programme at a time.

Combining Elementary Streams from encoders into a Transport Stream (red) or a Programme Stream (yellow).The Service Information (SI) component on the transport stream is not shown.

The Programme Stream is widely used in digital video storage devices, and also where the video is reliably transmitted over a network (e.g. video-clip down load). Digital Video Broadcast (DVB) uses the MPEG-2 Transport Stream over a wide variety of under-lying networks. Since both the Program Stream and Transport Stream multiplex a set of PES inputs, interoperability between the two formats may be achieved at the PES level.


MPEG Transport Streams

A transport stream consists of a sequence of fixed sized transport packet of 188 B. Each packet comprises 184 B of payload and a 4 B header. One of the items in this 4 B header is the 13 bit Packet Identifier (PID) which plays a key role in the operation of the Transport Stream.

The format of the transport stream is described using the figure below (a later section describes the detailed format of the TS packet header). This figure shows two elementary streams sent in the same MPEG-2 transport multiplex. Each packet is associated with a PES through the setting of the PID value in the packet header (the values of 64 and 51 in the figure). The audio packets have been assigned PID 64, and the video packets PID 51 (these are arbitrary, but different values). As is usual, there are more video than audio packets, but you may also note that the two types of packets are not evenly spaced in time. The MPEG-TS is not a time division multiplex, packets with any PID may be inserted into the TS at any time by the TS multiplexor. If no packets are available at the multiplexor, it inserts null packets (denoted by a PID value of 0x1FFF) to retain the specified TS bit rate. The multiplexor also does not synchronise the two PESs, indeed the encoding and decoding delay for each PES may (and usually is different). A separate process is therefore require to synchronise the two streams (see below).

Single Program Transport Stream (Audio and Video PES).

Transmission of the MPEG-TS

Although the MPEG TS may be directly used over a wide variety of media (as in DVB), it may also be used over a communication network. It is designed to be robust with short frames, each one being protected by a strong error correction mechanism. It is constructed to match the characteristics of the generic radio or cable channel and expects an uncorrected Bit Error Rate (BER) of better than 10-10. (The different variants of DVB each have their own outer coding and modulation methods designed for the particular environment.)

The MPEG-2 Transport Stream is so called, to signify that it is the input to the Transport Layer in the ISO Open System Interconnection (OSI) seven-layer network reference model. It is not, in itself, a transport layer protocol and no mechanism is provided to ensure the reliable delivery of the transported data. MPEG-2 relies on underlying layers for such services. MPEG-2 transport relies on underlying layers for such services. MPEG-2 transport requires the underlying layer to identify the transport packets, and to indicate in the transport packet header, when a transport packet has been erroneously transmitted.

When the MPEG-TS is used over a lower layer network protocol, the lower layer must identify the start of each transport packets, and indicate in the transport packet header, when a transport packet has been erroneously received. The MPEG TS packet size also corresponds to eight Asynchronous Transfer Mode (ATM) cells, assuming 8 B overhead (associated with the ATM Adaptation Layer (AAL)).

Single and Multiple Program Transport Streams

A TS may correspond to a single TV programme, or multimedia stream (e.g. with two a video PES and an audio PES). This type of TS is normally called a Single Programme Transport Stream (SPTS).

An SPTS contains all the information requires to reproduce the encoded TV channel or multimedia stream. It may contain only an audio and video PESs, but in practice there will be other types of PES as well. Each PES shares a common timebase. Although some equipments output and use SPTS, this is not the normal form transmitted over a DVB link.

In most cases one or more SPTS streams are combined to form a Multiple Programme Transport Stream (MPTS). This larger aggregate also contains all the control information (Program Specific Information (PSI)) required to co-ordinate the DVB system, and any other data which is to be sent.

Streams supported by the MPTS

Most transport streams consist of a number of related elementary streams (e.g. the video and audio of a TV programme). The decoding of the elementary streams may need to be co-ordinated (synchronised) to ensure that the audio playback is in synchronism with the corresponding video frames. Each stream may be tightly synchronised (usually necessary for digital TV programs, or for digital radio programs), or not synchronised (in the case of programs offering downloading of software or games, as an example). To help synchronisation time stamps may be (optionally) sent in the transport stream.

They are two types of time stamps:

  • The first type is usually called a reference time stamp. This time stamp is the indication of the current time. Reference time stamps are to be found in the PES syntax (ESCR), in the program syntax (SCR), and in the transport packet adaption Program Clock Reference (PCR) field.
  • The second type of time stamp is called Decoding Time Stamp (DTS) or Presentation Time Stamp (PTS ). These time stamps are inserted close to the material to which they refer (normally in the PES packet header). They indicate the exact moment where a video frame or an audio frame has to be decoded or presented to the user respectively. These rely on reference time stamps for operation.


Signalling Tables

For a user to receive a particular transport stream, the user must first determine the PID being used, and then filter packets which have a matching PID value. To help the user identify which PID corresponds to which programme, a special set of streams, known as Signalling Tables, are transmitted with a description of each program carried within the MPEG-2 Transport Stream. Signalling tables are sent separately to PES, and are not synchronised with the elementary streams (i.e they are an independent control channel).

DVB Signalling Tables and Transport Layer PIDs

The tables (called Program Specific Information (PSI) in MPEG-2) consist of a description of the elementary streams which need to be combined to build programmes, and a description of the programmes. Each PSI table is carried in a sequence of PSI Sections, which may be of variable length (but are usually small, c.f. PES packets). Each section is protected by a CRC (checksum) to verify the integrity of the table being carried. The length of a section allows a decoder to identify the next section in a packet. A PSI section may also be used for down-loading data to a remote site. Tables are sent periodically by including them in the transmitted transport multiplex.

MPEG-2 Signalling Tables

PAT - Program Association Table (lists the PIDs of tables describing each programme). The PAT is sent with the well-known PID value of 0x000.
CAT - Conditional Access Table (defines type of scrambling used and PID values of transport streams which contain the conditional access management and entitlement information (EMM)). The PAT is sent with the well-known PID value of 0x001.
PMT - Program Map Table (defines the set of PIDs associated with a programme, e.g. audio, video, ...)
NIT - Network Information Table (PID=10, contains details of the bearer network used to transmit the MPEG multiplex, including the carrier frequency)
DSM-CC - Digital Storage Media Command and Control (messages to the receivers)

Programme Service Information (SI) provided by MPEG-2 and used by DVB

To identify the required PID to de-multiplex a particular PES, the user searches for a description in a particular table, the Program Association Table (PAT). This lists all programmes in the multiplex. Each programme is associated with a set of PIDs (one for each PES) which correspond to a Programme Map Table (PMT) carried as a separate PSI section. There is one PMT per programme. DVB also adds a number of additional tables including those shown below.

DVB Signalling Tables

In addition to the PSI carried in each multiplex (MPTS), a service also carries information relating to the service as a whole. Since a service may use a number of MPTS to send all the required programs. Information is provided in the PSI tables defined by DVB. Each PSI table refers to the MPTS in which it is carried and any other MPTSs which carry other TS which are offered as a part of the same service.

BAT- Bouquet Association Table (groups services into logical groups)
SDT- Service Description Table (describes the name and other details of services)
TDT - Time and Date Table (PID=14, provides present time and date)
RST - Running Status Table (PID=13, provides status of a programmed transmission, allows for automatic event switching)
EIT - Event Information Table (PID=12, provides details of a programmed transmission)
Service Information (SI) provided by DVB

Most viewers have little knowledge of the operation of these tables and interact with the decoder through a graphical or textual programme guide.


Format of a Transport Stream Packet

Each MPEG-2 TS packet carries 184 B of payload data prefixed by a 4 B (32 bit) header.

The header has the following fields:

  • The header starts with a well-known Synchronisation Byte (8 bits). This has the bit pattern 0x47 (0100 0111).
  • A set of three flag bits are used to indicate how the payload should be processed.
    1. The first flag indicates a transport error.
    2. The second flag indicates the start of a payload (payload_unit_start_indicator)
    3. The third flag indicates transport priority bit.
  • The flags are followed by a 13 bit Packet Identifier (PID). This is used to uniquely identify the stream to which the packet belongs (e.g. PES packets corresponding to an ES) generated by the multiplexer. The PID allows the receiver to differentiate the stream to which each received packet belongs. Some PID values are predefined and are used to indicate various streams of control information. A packet with an unknown PID, or one with a PID which is not required by the receiver, is silently discarded. The particular PID value of 0x1FFF is reserved to indicate that the packet is a null packet (and is to be ignored by the receiver).
  • The two scrambling control bits are used by conditional access procedures to encrypted the payload of some TS packets.
  • Two adaption field control bits which may take four values:
    1. 01 – no adaptation field, payload only
    2. 10 – adaptation field only, no payload
    3. 11 – adaptation field followed by payload
    4. 00 - RESERVED for future use
  • Finally there is a half byte Continuity Counter (4 bits)

Two options are possible for inserting PES data into the TS packet payload:

  1. The simplest option, from both the encoder and receiver viewpoints, is to send only one PES (or a part of single PES) in a TS packet. This allows the TS packet header to indicate the start of the PES, but since a PES packet may have an arbitrary length, also requires the remainder of the TS packet to be padded, ensuring correct alignment of the next PES to the start of a TS packet. In MPEG-2 the padding value is the hexadecimal byte 0xFF.
  2. In general a given PES packet spans several TS packets so that the majority of TS packets contain continuation data in their payloads. When a PES packet is starting, however, the payload_unit_start_indicator bit is set to 『1』 which means the first byte of the TS payload contains the first byte of the PES packet header. Only one PES packet can start in any single TS packet. The TS header also contains the PID so that the receiver can accept or reject PES packets at a high level without burdening the receiver with too much processing. This has an impact on short PES packets

MPEG PES mapping onto the MPEG-2 TS

Option Transport Packet Adaption Field

The presence of an adaptation field is indicated by the adaption field control bits in a transport stream packet. If present, the adaption field directly follows the 4 B packet header, before any user payload data. It may contain a variety of data used for timing and control.

One important item in most adaption packets is the Program Clock Reference (PCR) field.

Another important item is splice_countdown field. This field is used to indicate the end of a series of ES access units. It allows the MPEG-2 TS multiplexor to determine appropriate places in a stream were the video may be spliced to another video source without introducing undesirable disruption to the video replayed by the receiver. Since MPEG-2 video uses inter-frame coding a seamless switch-over between sources can only occur on an I-frame boundary (indicated by a splice count of 0). This feature may, for instance be used to insert a news flash in a scheduled TV transmission.

One other bit of interest here is the transport_private_data_flag which is set to 1 when the adaptation field contains private data bytes. Another is the transport_private_data_length field which specifies how many private data bytes will follow the field. Private data is not allowed to increase the adaptation field beyond the TS payload size of 184 bytes.

DVB Satellite

DVB transmission via satellite (often known as DVB-S), defines a series of options for sending MPEG-TS packets over satellite links. The DVB-S standard requires the 188 B (scrambled) transport packets to be protected by 16 bytes of Reed Solomon (RS) coding.

MPEG Transport Service Encoding Specified by DVB-S

The resultant bit stream is then interleaved and convolutional coding is applied. The level of coding may be selected by the service provider (from 1/2 to 7/8 depending on the intended application and available bandwidth). The digital bit stream is then modulated using Quadrature Phase Shift Keying (QPSK). A typical satellite channel has a 36 MHz bandwidth, which may support transmission at up to 35-40 Mbps (assuming delivery to a 0.5m receiving antenna).


Digital Storage Media Command and Control (DSM-CC)

DSM-CC is a toolkit for developing control channels associated with MPEG-1 and MPEG-2 streams. It uses a client/server model connected via an underlying network (carried via the MPEG-2 multiplex or independently if needed). DSM-CC may be used for controlling the video reception, providing features normally found on Video Cassette Recorders (VCR) (fast-forward, rewind, pause, etc). It may also be used for a wide variety of other purposes including packet data


See also :

Tuesday, January 1, 2008

Customer communication skills - part 1

. Always keep your passion for the products you are selling.
. Influence your customers with your passion.
. Do not ever lose your passion for your products.
. Familiarize yourself with not only your products but also your competitors' products.
. Make your first impression the best one. The way you dress, talk matters!
. Have your things well prepared such as the well-organized briefcase, promotional business card, attractive brochures etc. !

Check clients which connect to Mac OS X Wi-Fi Internet Sharing

arp -i bridge100 -a bridge100 may be different on your Mac OSX