• 沒有找到結果。

VLC 播放器之 thread 架構

第二章 VLC 多媒體播放器機制介紹

2.2 VLC 播放器之 thread 架構

2.2 VLC 播放器之 thread 架構

VLC 是由 multi-thread 的架構所組成,利用每一個 thread 運作和資料分享的方式來 建立起一個完整的播放影片系統,例如:解多工器模組和解碼器模組就是在各自在不同的 thread 下工作,但是解碼器模組會不斷讀取由解多工器模組得到的 audio bitstream 及 video bitstream 來進行解碼程序。

當我們開啟VLC 時,就會出現一個 GUI 的介面,此時的 VLC 就會同時啟動 4 個 thread;

每個thread 都有自己的程序要執行,其中以 playlist thread 最為重要,因為它會不斷的等

待使用者下達播放影音檔案的指令,是啟動VLC 播放程序的重要關鍵點。上述的解多

工器模組和解碼器模組的thread 也要由 playlist thread 正式接收到使用者需要開啟影音檔

案的訊息後才會分別的開始啟動。

Graphical User Interfacd

Demuxer

video decoder Audio decoder

Video output Audio output

data stream

audio bitstream video bitstream

video frame

audio frame

Local Video/Audio

Files

mp4,avi,mp3.mkv…

5

啟動VLC

Playlist thread preparser thread interface thread manager thread

圖2.2 VLC multi-thread 的架構示意圖

資源擷取(Access)、解多工器(demuxer)、解碼器(decoder)等等模組的尋找和基本的 參數設定都會在Input thread 下的 Run()函數中完成,不過解多工器模組是在 Input thread 下MainLoop()函數中被呼叫並開始對影音資料進行解多工的動作,這時 MainLoop()函數 是不斷的利用callback function 的方式來呼叫解多工器模組,然後再經過層層的呼叫來 尋找解碼器的模組,接著就會各自產生影像和聲音解碼的thread。此時Audio Output 和 Video Output thread 分別會在影像和聲音的解碼器模組中被呼叫並開始運作。 MainLoop()函數會利用 while()迴圈持續作影音資料解多工的動作並將資料放入 FIFO Buffer 中,而Audio Dcoder 和 Video Dcoder thread 也會在 DecoderDecode()函數 中利用while()迴圈不斷讀取 FIFO Buffer 中已經連結串列好的影音資料來進行解碼的動

作,並開始開啟各自的輸出模組,上述詳細的過程會在後面章節一一的介紹。

6

Playlist thread RunThread()

Input thread Run()

Audio Decoder Thread

Decoder() Video Decoder Thread Decoder()

Audio Output Thread Video Outout Thread

圖2.3 VLC Thread 的關係示意圖

— playlist thread:

主要是檢查目前播放的狀態和處理使用者的指令,例如是否要開始播放影音資料 或者停止 目前所播放的影音資料。若確定有影音資料要播放,那麼就會開啟 input thread 來開始進行整個播放影音的程序。

7

— input thread:

主要是先尋找合適存取模組以及解多工模組,然後將所讀取的影音資料解多工成 audio bitstream 及 video bitstream。而在這裡也會尋找合適的聲音和影像的解碼器 模組,並分別開啟audio decoder thread 和 video decoder thread。

— audio decoder thread:

負責將解多工後的audio bitstream,進行聲音的解碼程序;而進行解碼的程序前,

會先尋找合適的聲音輸出模組並開啟audio output thread。

— video decoder thread:

負責將解多工後的 video bitstream,進行影像的解碼程序;而開始進行解碼的程

序之前,會先尋找合適的影像輸出模組並開啟video output thread。

— audio output thread:

負責將解碼後的聲音輸出到使用者的喇叭上。

— video output thread:

負責將解碼後的影像輸出到使用者的螢幕上。

8