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