static int vc1_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { VC1ParseContext *vpc = (VC1ParseContext *)s->priv_data; int next; if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ next= buf_size; }else{ next= vc1_find_frame_end(&vpc->pc, buf, buf_size); if (ff_combine_frame(&vpc->pc, next, &buf, &buf_size) < 0) { *poutbuf = NULL; *poutbuf_size = 0; return buf_size; } } vc1_extract_headers(s, avctx, buf, buf_size); *poutbuf = buf; *poutbuf_size = buf_size; return next; }
/* 新增函数:寻找完整的一幅图像(一场或是一帧) */ int VC1_Frame_Parse(AVCodecContext *pstAVCodecContext,const uint8_t **pucOutBuf, unsigned int *puiOutBufSize,const uint8_t *pucInBuf, unsigned int uiInBufSize, int *piLength) { int iRet = IMEDIA_RET_SUCCESS; VC1Context *pstVC1Context; ParseContext *pstParseContext; int iBytesConsumed = 0; int iReturn = 0; if(NULL == pstAVCodecContext) { av_log(pstAVCodecContext, AV_LOG_ERROR, "the decoder handle is NULL\n"); return IMEDIA_RET_PARAM_NULL; } if(0 == uiInBufSize) { av_log(pstAVCodecContext, AV_LOG_INFO, "the length of input bitstream is zero!\n"); } if(0 != uiInBufSize && NULL == pucInBuf) { av_log(pstAVCodecContext, AV_LOG_ERROR, "input bitstream buf is NULL\n"); return IMEDIA_RET_PARAM_NULL; } if(NULL == pucOutBuf || NULL == puiOutBufSize) { av_log(pstAVCodecContext, AV_LOG_ERROR,"output bitstream buf or length pointer is NULL\n"); return IMEDIA_RET_PARAM_NULL; } pstVC1Context = (VC1Context*)pstAVCodecContext->priv_data; pstParseContext = &pstVC1Context->s.parse_context; iBytesConsumed = vc1_find_frame_end(pstParseContext, pucInBuf, uiInBufSize); iReturn = ff_combine_frame(pstParseContext, iBytesConsumed, &pucInBuf, &uiInBufSize); if (0 > iReturn) { /* start and end of the frame is not fount! */ *pucOutBuf = NULL; *puiOutBufSize = 0; *piLength = uiInBufSize; return iRet; } /* 如果当前解析帧在前一个buffer的边界,则当前buffer的解析用掉的字节数为0 */ if(0 > iBytesConsumed) { iBytesConsumed = 0; } *pucOutBuf = pucInBuf; *puiOutBufSize = uiInBufSize; *piLength = iBytesConsumed; return iRet; }