00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028 #include "parser.h"
00029
00030
00031 static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){
00032 int vop_found, i, j;
00033 uint32_t state;
00034
00035 vop_found= pc->frame_start_found;
00036 state= pc->state;
00037
00038 for(i=0; i<buf_size && !vop_found; i++){
00039 state= (state<<8) | buf[i];
00040 for(j=0; j<8; j++){
00041 if(((state>>j)&0xFFFFF0) == 0x000100){
00042 vop_found=1;
00043 break;
00044 }
00045 }
00046 }
00047 if(vop_found){
00048 for(; i<buf_size; i++){
00049 state= (state<<8) | buf[i];
00050 for(j=0; j<8; j++){
00051 if(((state>>j)&0xFFFFF0) == 0x000100){
00052 pc->frame_start_found=0;
00053 pc->state= (state>>(3*8))+0xFF00;
00054 return i-2;
00055 }
00056 }
00057 }
00058 }
00059
00060 pc->frame_start_found= vop_found;
00061 pc->state= state;
00062 return END_NOT_FOUND;
00063 }
00064
00065 static int h261_parse(AVCodecParserContext *s,
00066 AVCodecContext *avctx,
00067 const uint8_t **poutbuf, int *poutbuf_size,
00068 const uint8_t *buf, int buf_size)
00069 {
00070 ParseContext *pc = s->priv_data;
00071 int next;
00072
00073 if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
00074 next = buf_size;
00075 } else {
00076 next= h261_find_frame_end(pc,avctx, buf, buf_size);
00077 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
00078 *poutbuf = NULL;
00079 *poutbuf_size = 0;
00080 return buf_size;
00081 }
00082 }
00083 *poutbuf = buf;
00084 *poutbuf_size = buf_size;
00085 return next;
00086 }
00087
00088 AVCodecParser ff_h261_parser = {
00089 .codec_ids = { CODEC_ID_H261 },
00090 .priv_data_size = sizeof(ParseContext),
00091 .parser_parse = h261_parse,
00092 .parser_close = ff_parse_close,
00093 };