天天看點

OpenCores學習(3)--PVPlayer 引擎設計

PVPlayer引擎是PVPlayer SDK的心髒。它接收和處理所有PVPlayer SDK從使用者和管理PVMF播放多媒體所需的組成及相關業務的請求。其任務應用和簡化進階控制。這個PVPlayer引擎也偵測,處理,和過濾事件和資訊生成多媒體播放操 作控制。

3.1 PVPlayerInterface API

       PVPlayer使用者界面PVPlayer引擎通過PVPlayerInterface接口類來确定是否有一種适配接口用 戶和PVPlayer引擎。PVPlayerInterface是一種OSCL-based接口和遵循公共接口,除了多媒體播放特定api,PVPlayerInterface提供方法檢索SDK資訊、操縱和取消的指令。并描述PVPlayerInterface API,指的是一種PVPlayerInterface API文檔生成的支援的标記。

3.2 異步操作

       The PVPlayer engine processes most commands initiated by API calls asynchronously. There are some commands that are processed synchronously and they can be differentiated by the return value. Synchronous commands return a PVMF status code which tells the user whether the command succeeded or not and if it did fail, what the error was. All asynchronous commands return a command ID. For the user to be notified of asynchronous command completion, the user must specify a callback handler when instantiating PVPlayer engine via the factory function. When the asynchronous command completes, PVPlayer engine calls the callback handler with the command ID for the command, command status, and any other relevant data. To process the command asynchronously, the PVPlayer engine is implemented as an active object, which gets to run according to the active scheduler running in the thread. The PVPlayer engine expects scheduler to be available when instantiated and the engine itself will not directly create a thread or scheduler.

With asynchronous commands, there is a possibility of commands not completing in expected time. To deal with this issue, PVPlayer engine provides standard PV SDK APIs to cancel a specific or all issued commands. The user of PVPlayer SDK can use these APIs to cancel any request that did not complete in time or are not needed due to changing circumstances. In PVPlayer engine, it might have to deal with lower level components that behave asynchronously. To prevent an unresponsive lower level component from blocking PVPlayer engine operation, PVPlayer engine has timeout handling for any asynchronous commands that it issues. When timeout does occur, the asynchronous command is canceled and is handled appropriately (e.g. command failure, error event).

3.3 事件處理

  The PVPlayer engine notifies the user of errors and other information not related to API calls as unsolicited events. The notification is handled by making a callback on handlers specified by the user of PVPlayer engine. There are two callback handlers, one for error events and one for informational events, that must be specified by the user when instantiating PVPlayer engine via the factory function.

3.4 引擎架構

       下面的圖表說明了應用程式使用PVPlayer引擎的接口PVPlayerInterface時直接适配。PVPlayerFactory處理執行個體化元件和destory的PVPlayerEngine對象。所有PVPlayer引擎的api提供PVPlayerInterface。PVPlayerEngine采用三種回收處理過的應用,PVCommandStatusObserver,PVInformationalObserver,PVErrorEventObserver,通知申請上述指令完成同步誤差和資訊的事件。

OpenCores學習(3)--PVPlayer 引擎設計

       圖二 類圖

3.5 狀态機

OpenCores學習(3)--PVPlayer 引擎設計

圖三 狀态機

       PVPlayer 引擎執行個體化後狀态為IDLE,在IDLE狀态時,可以調用AddDataSource() 來指定需要回放的多媒體 資料,然後調用 init()初始化資料并且狀态轉為INITIALIZED,在進入INITIALIZED

狀态的時候,使用者可以擷取媒體的tracks和metadata,并且可以調用 AddDataSink()去指定具體的data sinks 去回放.

       在所有的data sinks添加後,使用者調用Prepare(),使引擎建立相關的PVMF節點,并為資料流指定多媒體播放的資料源 和資料接收器,建立需要播放的資料流隊列.使用者在PREPARED狀态時調用Start()進入到STARTED狀态,啟動多媒體播放.在調用Stop()後回到INITIALIZED狀态并且重新整理多媒體資料流.

       在STARTED狀态時,使用者也可以調用 Pause(). Stop().調用Stop()後停止回放,重新整理所有資料流,并且使引擎回到初始化狀态.調用Pause(),會停止回放,但不會重新整理資料流,而且可以調用Resume()繼續從暫停的地方播放.在PAUSED狀态時可以調用Stop()使引擎回到初始化狀态.

       調用Stop()回到INITIALIZED狀态後,資料隊列可以通過調用AddDataSink()和RemoveDataSink()來添加和删除.在調用Prepare()\Start()重新回放,但是關閉回到IDLE狀态時,或需要重新打開另一個媒體檔案時,需要調用Reset().因為在IDLE狀态調用RemoveDataSink()不能删除所有資料隊列.調用Reset()後,又回到起始狀态,流程如上一樣.如果使用者想退出PVPlayer,也可以調用Reset(),在PREPARED, STARTED,PAUSED狀态時都可以調用該函數.

       如果PVPlayer引擎收到錯誤資訊或從其它元件傳來 錯誤事件後,引擎會發送ERROR狀态并且嘗試恢複.如果這個錯誤是不可恢複的,剛引擎會清空所有狀态和資料列回到IDLE狀态.此時使用者應該等待PVMFInfoErrorHandlingComplete informational event.

       以上是這個狀态機的簡要 描述,具體參考OPENCORE源碼.

繼續閱讀