天天看點

Opencore and OMX core/component interaction (二)

3.5 進入 Idle 狀态以後, OMX component 就可以進入執行狀态處理資料 ,并與 PVMF 進行資料交換。

@首先 PVMF 還是發送 command 給 omx component 來改變狀态,從 OMX_StateIdle 到 OMX_Executing 。

@同樣 PVMF 會等待 component 通過 EventHandler callback 傳回的 OMX_EventCmdComplete ,表明 component 已經完成狀态轉換。

@進入執行狀态以後, PCMF 會通過 OMX_EmptyThisBuffer() 來向 component 的某個 input port 發送資料,并要求 component 取得 buffer 中的資料進行處理 , 同時通過 OMX_FillThisBuffer() 要求 component 向其的某個 output port 填充解碼或者編碼完的資料。 Component 會通過 callback 來傳回 buffer 。

因為 inputbuffer 和 outputbuffer 的個數都是有限的,一旦使用 emptythisbuffer 将所有的 inputbuffer 都填滿資料,如果此時 component 不傳回,則就不能再有新的資料能進來。對 outputbuffer 同樣,如果所有的 outputbuffer 都被 fillthisbuffer 占用,等待填充資料,在 component 傳回之前将不再有新的 buffer 能用來填充輸出資料。

在 PCMF 沒有重新将 buffer 配置設定給 omx component 之前, component 不能對一個 buffer 進行多次傳回。一旦 component 傳回 buffer ,在 PCMF 沒有使用 emptythisbuffer 或者 fillthisbuffer 将這個 buffer 的所有權分給 component 之前, component 不能對 buffer 進行操作。

[有點小疑問:從上面的原來分析可以看出來,實際上雖然配置設定了 NumiputBuffer 和 NumoutputBuffer ,但這些 buffer 的所有權并不是 component ,對這個向 "component 發送 buffer “總是無法了解,在配置設定 buffer 的時候不是根據 port 來進行配置設定的麼,為什麼現在所有權不屬于 component ,而且好像跟 port 也不是相對應的]

具體過程:

Opencore and OMX core/component interaction (二)

3.6 pausing 和 resuming 是在播放器中經常用到的,從執行狀态到暫停,再從暫停回到播放都是通過 OMX_SendCommand 來實作的,過程同前面的狀态改變一樣 OMX_StateExecuting-----> OMX_StatePause ------> OMX_StateExecuting 。一旦進入停止狀态, PVMF 就不再向 component 發送 input/output buffer ,直到收到從 component 發送來的進入執行狀态的 callback 。

具體過程:

Opencore and OMX core/component interaction (二)

3.7 port flush 主要用在解碼器中,比如說播放器複位的時候,這裡的也是通過 OMX_SendCommand 來實作的。另外 port flush 也用在 IL client 釋放動态 port 的過程中。[也有個小疑問,這裡沖刷的究竟是哪個 buffer 裡面的内容呢?]

具體過程:

Opencore and OMX core/component interaction (二)

3.8 在執行和暫停狀态都可以通過發送 stop command 使 component 進入 Idle 狀态。一旦進入 Idle 狀态, PVMF 就會假定 component 已經傳回了所有的 buffer 。

具體過程:

Opencore and OMX core/component interaction (二)

3.9 從 Idle 狀态進入 Loaded 狀态的過程如下:

@首先通過 OMX_SendCommand ,将狀态從 OMX_StateIdle 轉變成 OMX_StateLoaded 。

@然後調用 OMX_FreeBuffer 釋放掉 input/output buffers ,調用次數根據 NumInput/outputBuffers 。

@然後等待 comonent 的 call back

@最後調用 OMX_FreeHandle 使 OMX core 釋放掉所有的 comonent 的 handle 。

在進行狀态轉換之前, PVMF 會等待 component 傳回所有的 input/output buffer ,因為是異步調用, EmptyBufferDone/FillBufferDone call back 可能在 omx component 從 executing 到 idle 狀态轉變的 call back 之後到達。

具體過程:

Opencore and OMX core/component interaction (二)

3.10 最後 PVMF 調用 OMX_Deinit() 來釋放 omx core 。