• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/h263_parser.c

Go to the documentation of this file.
00001 /*
00002  * H.263 parser
00003  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00027 #include "parser.h"
00028 #include "h263_parser.h"
00029 
00030 int ff_h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
00031     int vop_found, i;
00032     uint32_t state;
00033 
00034     vop_found= pc->frame_start_found;
00035     state= pc->state;
00036 
00037     i=0;
00038     if(!vop_found){
00039         for(i=0; i<buf_size; i++){
00040             state= (state<<8) | buf[i];
00041             if(state>>(32-22) == 0x20){
00042                 i++;
00043                 vop_found=1;
00044                 break;
00045             }
00046         }
00047     }
00048 
00049     if(vop_found){
00050       for(; i<buf_size; i++){
00051         state= (state<<8) | buf[i];
00052         if(state>>(32-22) == 0x20){
00053             pc->frame_start_found=0;
00054             pc->state=-1;
00055             return i-3;
00056         }
00057       }
00058     }
00059     pc->frame_start_found= vop_found;
00060     pc->state= state;
00061 
00062     return END_NOT_FOUND;
00063 }
00064 
00065 static int h263_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= ff_h263_find_frame_end(pc, buf, buf_size);
00077 
00078         if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
00079             *poutbuf = NULL;
00080             *poutbuf_size = 0;
00081             return buf_size;
00082         }
00083     }
00084 
00085     *poutbuf = buf;
00086     *poutbuf_size = buf_size;
00087     return next;
00088 }
00089 
00090 AVCodecParser ff_h263_parser = {
00091     .codec_ids      = { CODEC_ID_H263 },
00092     .priv_data_size = sizeof(ParseContext),
00093     .parser_parse   = h263_parse,
00094     .parser_close   = ff_parse_close,
00095 };
Generated on Fri Feb 1 2013 14:34:35 for FFmpeg by doxygen 1.7.1