AwesomePlayer如何和OMX video decoder传输buffer呢?
1.OMXCodec会在开始的时候通过read()函数将未解码的data送给decoder,并要求decoder将解码后的data回传。
status_t OMXCodec::read(...)
{
if (mInitialBufferSubmit)
{
mInitialBufferSubmit = false;
drainInputBuffers(); <----- OMX_EmptyThisBuffer
fillOutputBuffers(); <----- OMX_FillThisBuffer
}
...
}
2.Decoder从input port读取到数据后开始进行解码,并且回传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之后,继续发送下一个未解码的data给decoder。
3.Decoder将解码后的数据送到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之后,将解码后的数据放入mFilledBuffers,发出mBufferFilled信号,并且要求decoder继续送出数据。
4.read()函数在后面等待mBufferFilled信号。当mFilledBuffers被填入数据后,read()函数将其指定给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;
}