Libav 0.7.1
|
00001 /* 00002 * H261 parser 00003 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> 00004 * Copyright (c) 2004 Maarten Daniels 00005 * 00006 * This file is part of Libav. 00007 * 00008 * Libav is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * Libav is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with Libav; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 ff_h261_parser = { 00085 { CODEC_ID_H261 }, 00086 sizeof(ParseContext), 00087 NULL, 00088 h261_parse, 00089 ff_parse_close, 00090 };