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 next= h261_find_frame_end(pc,avctx, buf, buf_size);
00074 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
00075 *poutbuf = NULL;
00076 *poutbuf_size = 0;
00077 return buf_size;
00078 }
00079 *poutbuf = buf;
00080 *poutbuf_size = buf_size;
00081 return next;
00082 }
00083
00084 AVCodecParser h261_parser = {
00085 { CODEC_ID_H261 },
00086 sizeof(ParseContext),
00087 NULL,
00088 h261_parse,
00089 ff_parse_close,
00090 };