Rename var: val -> energy
[FFMpeg-mirror/DVCPRO-HD.git] / libavcodec / h263_parser.c
blobbfef3b5bbdc31a4bd895ff322cdf312203099f5f
1 /*
2 * H.263 parser
3 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 /**
23 * @file h263_parser.c
24 * H.263 parser
27 #include "parser.h"
29 int ff_h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){
30 int vop_found, i;
31 uint32_t state;
33 vop_found= pc->frame_start_found;
34 state= pc->state;
36 i=0;
37 if(!vop_found){
38 for(i=0; i<buf_size; i++){
39 state= (state<<8) | buf[i];
40 if(state>>(32-22) == 0x20){
41 i++;
42 vop_found=1;
43 break;
48 if(vop_found){
49 for(; i<buf_size; i++){
50 state= (state<<8) | buf[i];
51 if(state>>(32-22) == 0x20){
52 pc->frame_start_found=0;
53 pc->state=-1;
54 return i-3;
58 pc->frame_start_found= vop_found;
59 pc->state= state;
61 return END_NOT_FOUND;
64 static int h263_parse(AVCodecParserContext *s,
65 AVCodecContext *avctx,
66 const uint8_t **poutbuf, int *poutbuf_size,
67 const uint8_t *buf, int buf_size)
69 ParseContext *pc = s->priv_data;
70 int next;
72 next= ff_h263_find_frame_end(pc, buf, buf_size);
74 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
75 *poutbuf = NULL;
76 *poutbuf_size = 0;
77 return buf_size;
80 *poutbuf = buf;
81 *poutbuf_size = buf_size;
82 return next;
85 AVCodecParser h263_parser = {
86 { CODEC_ID_H263 },
87 sizeof(ParseContext),
88 NULL,
89 h263_parse,
90 ff_parse_close,