vlc官網文章《Introduction to libVLCcore》

1 Introduction to libVLCcore
介紹libVLCcore
The core of VLC media player is called libVLCcore.
It manages the threads, the modules (codecs, demuxers, etc…), the modules’ layers, the clocks,
the playlist and all low-level control in VLC.
For example, it is responsible for the synchronization management between all the audio, video and
subtitle tracks.
On top of libVLCcore, there is libVLC that allow external application builders to access to all
features of the core.
Modules are linked with libvlccore, to interact with the core.
Modules are built against libvlccore. External applications are built against libVLC.
VLC媒體播放器的核心是叫libVLCcore。
它管理線程、模塊(編解碼器,分配器,等等),模塊層,時鐘,播放列表和所有低級別的控制。
例如,它負責所有音頻、視頻和字幕軌道之間的同步管理。
libvlccore層上面有libVLC,它允許外部應用訪問所有的核心特徵
模塊鏈接到與libvlccore,與核心相互工作。
模塊內置構成libVLCcore。libVLC構成外部應用程序。

2 VLC Pipeline and Modularity VLC流水線和模塊

One of the main concepts in VLC is "modularity".
VLC is, in fact, a complete multimedia framework (like DirectShow or GStreamer) where you can load 
and plug-in many modules dynamically, depending on the necessity.
The core framework is used to do the "wiring" and the media processing, from input 
(files, network streams) to output (audio or video, on a screen or a network). 
It uses modules to  do most of the work at every stage (various muxers, demuxers, decoders, filters and outputs).
Even the interfaces are plugins for libVLC.
VLC的主要概念之一是“模塊化”。
VLC事實上是一個完整的多媒體框架(如DirectShow或GStreamer)您可以根據必要性動態的加載和插件的多模塊。
核心框架用於進行“連線”和媒體處理,從輸入(文件、網絡流)到輸出(音頻或視頻、屏幕或網絡)。
它在每一個階段使用的模塊做大部分的工作(各種muxers,分配器,解碼器,濾波器和輸出)。
甚至接口也是VLC的插件。

2.1 The modules in VLC //VLC模塊
So, VLC uses modules to do most of the work, at every stage of the pipeline. 
Modules are loaded accordingly at runtime depending on the necessity. 
(See VLC Modules loading mechanism).
Every module offers different features that will best suit a particular use-case or a particular environment.
Besides, most portability of VLC results from writing audio_output/video_output/interface 
modules specific to the platform.
plugins modules are loaded and unloaded dynamically by functions in src/modules/modules.c .
Modules can also be built directly into the application which uses libVLC, for instance 
when VLC is on an operating system that does not have support for dynamically loadable code.
They are then called builtins.
In the source code, modules are usually located inside the modules/ subdirectory.
所以,VLC在每個不同層使用模塊來做大部分的工作。
根據需要,模塊在運行時相應加載。
(見VLC模塊加載機制)。
每個模塊都提供了最適合特定用例或特定環境的不同特性。
此外,大多數攜帶VLC結果寫audio_output / video_output /接口平臺相關模塊。
插件模塊是動態地加載和卸載的。
模塊也可以直接建立在以libVLC應用,例如當VLC是一個操作系統,不支持動態加載的代碼。他們被稱爲內部。
在源代碼中,模塊通常位於模塊/子目錄中(modules/)。

3 Thread management 線程管理

VLC is heavily multi-threaded.
VLC是高度多線程的。

The single-threaded approach would have introduced too much complexity because decoder preemptibility 
and scheduling would then be a mastermind (for instance decoders and outputs have to be separated, 
otherwise it cannot be warrantied that a frame will be played at the exact presentation time).
Multi-process approach wasn't chosen either, because multi-process decoders usually imply more overhead
 (problems of shared memory) and communication between processes is harder.
VLC's threading structure is modeled after POSIX threads (pthread). However, for portability reasons,
 VLC does not use pthread_* functions directly, but a similar custom set of APIs.
 單線程的方法會引入太多的複雜性因爲解碼器搶佔 和調度將是一個策劃者
(例如解碼器和輸出必須分開,否則不能保修,框架將在準確的呈現時間扮演)。
也沒有選擇多進程方法,因爲多進程解碼器通常意味着更多開銷。
(共享內存的問題)和進程之間的通信更加困難。
VLC的線程結構是仿照POSIX線程(線程)。然而,出於可移植性的考慮,
VLC不使用pthread_ *的直接功能,但自定義類似的API集。



3.1 Threads (vlc_thread_t)//線程集
    vlc_clone()//Creates a thread.用於創建一個線程
    vlc_join()//Waits for a thread to terminate and releases its resources
             //等待線程終止並釋放其資源。

3.2 Mutual exclusion (vlc_mutex_t)//互斥鎖
    vlc_mutex_init()//Creates a non-recursive mutex. 創建非遞歸互斥鎖。

    vlc_mutex_init_recursive()//Creates a recursive mutex (discouraged).創建遞歸互斥鎖(不建議使用)。

    vlc_mutex_lock()//Locks a mutex, waiting if required.鎖定互斥體,如果需要則等待。

    vlc_mutex_trylock()//Locks a mutex if it is not already locked, or returns an error otherwise.
                        //如果尚未鎖定,則鎖定互斥鎖,否則返回錯誤。
    vlc_mutex_unlock()//Unlocks a mutex.解鎖互斥鎖。

    vlc_mutex_destroy()//Destroys a mutex.銷燬互斥鎖。

3.3 Condition variable (vlc_cond_t)//環境變量(vlc_cond_t)
vlc_cond_init()
/*
Creates a condition variable using the monotonic clock (mdate()) for timeouts.
使用單一時鐘創造環境變量(mdate())。
*/

vlc_cond_init_daytime()
/*
Creates a condition variable using the realtime clock / wall clock for timeouts.
創建一個環境變量使用實時時鐘/時鐘。
*/

vlc_cond_signal()
/*
Signals one thread waiting on a condition variable.
信號一個線程等待環境變量。
*/
vlc_cond_broadcast()
/*Signals all threads waiting on a condition variable.
指示等待環境變量的所有線程。
*/

vlc_cond_wait()
/*Waits for a condition variable to be signaled (can also wake up spuriously).
等待環境變量來表示(也可以醒來貌似)
*/

vlc_cond_timedwait()
/*Waits for a condition variable to be signaled up to a certain timeout (can also wake up spuriosuly).
等待環境變量來通知到某一時間(也可以喚醒spuriosuly)。
*/

vlc_cond_destroy()
/*Destroys a condition variable.
破壞環境變量。
*/

3.4 Misc其它
VLC also has abstractions for slim read/write locks, spin locks, thread-specific variables, similar to 
POSIX threads.
VLC也抽象爲讀寫鎖,自旋鎖,線程特定的變量,類似於POSIX線程。


3.5 Atomic variables //原子變量
Atomic variables are small (sizeof(void *)) values that can be manipulated from multiple threads 
without locking. See include/vlc_atomic.h for the list of supported operations.

原子變量是最小的值(sizeof(void *)),它可以從多個線程無鎖定操作。
在頭文件include/vlc_atomic.h。列出了它支持的操作

4、Synchronization異步

Another key feature of VLC is that decoding and playing are asynchronous: decoding is done by a decoder 
thread, playing is done by audio_output or video_output thread. 
The design goal is to ensure that an audio or video frame is played exactly at the right time,
without blocking any of the decoder threads.
This leads to a complex communication structure between the interface, the input, the decoders and the outputs.
VLC的另一個重要特點是,解碼和播放是異步的:解碼器在一個解碼線程工作。
播放是在audio_output 或者 video_output線程,
這樣設計目標是確保音頻或視頻幀在正確的時間準確地播放,
而不阻塞任何解碼器線程。這將導致接口、輸入、解碼器和輸出之間的複雜通信結構。


Having several input and video_output threads reading multiple files at the same time is permitted, 
despite the fact that the current interface doesn't allow any way to do it (this is subject to change 
in the near future). Anyway the client has been written from the ground up with this in mind. 
This also implies that a non-reentrant library (including in particular liba52See talk page)
cannot be used without using a global lock.
具有多個輸入和video_output線程同時讀取多個文件是允許的,儘管目前的接口不允許任何方式去做
 (這是在不久的將來改變)。不管怎樣,客戶都是從這一點寫出來的。這也意味着一個不可重入的圖書館
 (特別是liba52see討論頁)不能使用,不使用全局鎖。

Presentation Time Stamps located in the system layer of the stream are passed to the decoders, 
and all resulting samples are dated accordingly. The output layers are supposed to play them at 
the right time. Dates are converted to microseconds, an absolute date is the number of microseconds 
since Epoch (Jan 1st, 1970). The mtime_t type is a signed 64-bit integer.
系統層中流用顯示時間戳位,然後傳遞到解碼器,所有結果樣本都根據相應的日期。
輸出層應該在適當的時候播放它們。日期轉換爲微秒,絕對日期是自紀元(1970年1月1日)以來的微秒數。
mtime_t類型是有符號的64位整數。

The current date can be retrieved with mdate(). The execution of a thread can be suspended until a 
certain date via mwait ( mtime_t date ). You can sleep for a fixed number of microseconds with 
msleep( mtime_t delay ).
 mdate()可以檢索當前日期。通過mwait(mtime_t date)函數,一個正在執行的線程可以暫停到某個確定的日期。
 msleep( mtime_t delay )可以讓你休眠一段微秒級的時間


Warning警告
Please remember to wake up slightly before the presentation date, if some particular treatment needs 
to be done (e.g. a chroma transformation). For instance in modules/codec/libmpeg2.c, track of the 
average decoding times is kept to ensure pictures are not decoded too late.

請記住在演示日期前稍微醒來,如果需要做一些特殊的處理(例如色度變換)。比如在模塊/解碼器/ libmpeg2
(modules/codec/libmpeg2.c),保持平均解碼時間的軌跡,以確保圖片不被解碼太晚


Core Source code details
核心源代碼細節
All the libVLCcore source files are located in the src/ directory and its subdirectories:
所有的libvlccore源文件位於src/目錄及其子目錄:

audio_output/
Initializes the audio mixer, ie. finds the right playing frequency, and then resamples audio frames 
received from the decoder(s).
初始化音頻混合器等。找到正確的播放頻率,然後進行音頻幀從解碼器接收(S)。

config/
Load the configuration from command line and configuration file, provides functions for
the modules to read and write to configuration
從命令行和配置文件加載配置,爲模塊的讀寫寄存器提供功能。

control/
Functions to control the behaviour of libVLCcore, like Play/Pause, volume management, 
fullscreen, log verbosity, etc.
控制libvlccore功能行爲,如播放/暫停、音量管理,全屏,日誌冗長,等。

extras/
Mostly platform-specific code
主要是特定於平臺的代碼

input/
Opens an input module, reads packets, parses them and passes reconstituted elementary 
streams to the decoder(s).
打開一個輸入模塊,讀取數據包,解析它們並傳遞經過重組的基礎流到解碼器(s)。

interface/
Contains code for user interaction such as key presses and device ejection.
包含用於用戶交互的代碼,如按鍵和設備彈出。

misc/
Miscellaneous utilities used in other parts of libvlc, such as the thread system,
the message queue, CPU detection, the object lookup system, or platform-specific code.
雜項工具用於其他部分libVLC,,如thread system,
消息隊列、CPU檢測、對象查找系統或特定於平臺的代碼。

modules/
Modules management
模塊管理

network/
Network interface (socket management, network errors, etc.)
網絡接口(套接字管理、網絡錯誤等)

osd/
On Screen Display manipulation
屏幕顯示操作

playlist/
Manages playlist interaction such as stop, play, next, or random playback.
管理播放列表交互,如停止、播放、下一個或隨機播放。

stream_output/
Functions to stream audio and video to the network
向網絡傳輸音頻和視頻的功能。

test/
libVLC needs to be tested, and not only by users :)
libVLC需要測試,用戶不只是:)

text/
Charset stuff
字符集的東西

video_output/
Initializes the video display, gets all pictures and subpictures (ie. subtitles) from the decoder(s), 
optionally converts them to another format (such as YUV to RGB), and displays them.
初始化視頻顯示,獲取所有圖片和子(即字幕)從解碼器(S),
可以將它們轉換爲另一種格式(例如YUV到RGB),並顯示。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章