源码来源:TI - DM8168 - EZSDK - OMX - examples - decode_display
基本执行流程如下:
Decode_GetNextFrameSize(H264_ParsingCtx *pc)函数源码(加注释)如下:
/*****************************************************************************\
* Decode_GetNextFrameSize Function Declaration
\*****************************************************************************/
/**
*
* @brief Gets the size of thenext frame, It is doing chunking of h264
* elementary bitstream and providing frames to OMX component.
*
* @param in:
* pc: Pointer to H264_ParsingCtx structure
*
* @param Out:
* None
*
* @return uint32_t - Frame Size
*
*/
unsigned int Decode_GetNextFrameSize(H264_ParsingCtx *pc)
{
FILE *fp = pc->fp; // pc->fp指向的是H264文件
unsigned char *readBuf = pc->readBuf;
H264_ChunkingCtx *ctx = &pc->ctx;
AVChunk_Buf *inBuf = &pc->inBuf;
AVChunk_Buf *outBuf = &pc->outBuf;
unsigned char termCond = 1;
if(pc->firstParse == 1) // pc->firstParse的初始化值就是1
termCond = 0;
while ((!feof (fp)) ||
((((pc->firstParse == 0) && (pc->bytes != 0))
&& (pc->bytes <= READSIZE) && (pc->tmp <=pc->bytes))))
{
if (pc->firstParse == 1)
{
pc->bytes = fread (readBuf, 1, READSIZE, fp);//将H264比特流读取到readBuf
if (!pc->bytes)
{
return 0;
}
inBuf->ptr = readBuf; // inBuf->ptr也指向了H264比特流数据
pc->tmp = 0;
pc->firstParse = 0;
}
else
{
if (pc->bytes <= pc->tmp)
{
pc->bytes = fread (readBuf, 1, READSIZE, fp);
if (!pc->bytes)
{
return 0;
}
inBuf->ptr = readBuf;
pc->tmp = 0;
}
}
while (pc->bytes > pc->tmp)
{
inBuf->bufsize =
((pc->bytes - pc->tmp) > 184) ? 184 : (pc->bytes -pc->tmp)