AwesomePlayer如何和OMX video decoder傳輸buffer呢鸠真?
1.OMXCodec會(huì)在開始的時(shí)候通過read()函數(shù)將未解碼的data送給decoder,并要求decoder將解碼后的data回傳外傅。
status_t OMXCodec::read(...)
{
if (mInitialBufferSubmit)
{
mInitialBufferSubmit = false;
drainInputBuffers(); <----- OMX_EmptyThisBuffer
fillOutputBuffers(); <----- OMX_FillThisBuffer
}
...
}
2.Decoder從input port讀取到數(shù)據(jù)后開始進(jìn)行解碼蹦哼,并且回傳EmptyBufferDone給OMXCodec鳄哭。
void OMXCodec::on_message(const omx_message &msg)
{
switch (msg.type)
{
case omx_message::EMPTY_BUFFER_DONE:
{
IOMX::buffer_id buffer = msg.u.extended_buffer_data.buffer;
drainInputBuffer(&buffers->editItemAt(i));
}
}
}
OMXCodec收到EMPTY_BUFFER_DONE之后,繼續(xù)發(fā)送下一個(gè)未解碼的data給decoder纲熏。
3.Decoder將解碼后的數(shù)據(jù)送到output port妆丘,并回傳FillBufferDone通知OMXCodec。
void OMXCodec::on_message(const omx_message &msg)
{
switch (msg.type)
{
case omx_message::FILL_BUFFER_DONE:
{
IOMX::buffer_id buffer = msg.u.extended_buffer_data.buffer;
fillOutputBuffer(info);
mFilledBuffers.push_back(i);
mBufferFilled.signal();
}
}
}
OMXCodec收到FILL_BUFFER_DONE之后局劲,將解碼后的數(shù)據(jù)放入mFilledBuffers勺拣,發(fā)出mBufferFilled信號(hào),并且要求decoder繼續(xù)送出數(shù)據(jù)鱼填。
4.read()函數(shù)在后面等待mBufferFilled信號(hào)药有。當(dāng)mFilledBuffers被填入數(shù)據(jù)后,read()函數(shù)將其指定給buffer指針苹丸,并回傳給AwesomePlayer塑猖。
status_t OMXCodec::read(MediaBuffer **buffer, ...)
{
...
while (mFilledBuffers.empty())
{
mBufferFilled.wait(mLock);
}
BufferInfo *info = &mPortBuffers[kPortIndexOutput].editItemAt(index);
info->mMediaBuffer->add_ref(); *buffer = info->mMediaBuffer;
}