comparison h261_parser.c @ 4905:4578b68578bb libavcodec

Move H.261 parser to its own file.
author diego
date Fri, 04 May 2007 19:38:10 +0000
parents
children 983533ccc393
comparison
equal deleted inserted replaced
4904:811b9d7e1d3d 4905:4578b68578bb
1 /*
2 * H261 parser
3 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
4 * Copyright (c) 2004 Maarten Daniels
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file h261_parser.c
25 * h261codec.
26 */
27
28 #include "dsputil.h"
29 #include "parser.h"
30
31
32 static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){
33 int vop_found, i, j;
34 uint32_t state;
35
36 vop_found= pc->frame_start_found;
37 state= pc->state;
38
39 for(i=0; i<buf_size && !vop_found; i++){
40 state= (state<<8) | buf[i];
41 for(j=0; j<8; j++){
42 if(((state>>j)&0xFFFFF) == 0x00010){
43 vop_found=1;
44 break;
45 }
46 }
47 }
48 if(vop_found){
49 for(; i<buf_size; i++){
50 state= (state<<8) | buf[i];
51 for(j=0; j<8; j++){
52 if(((state>>j)&0xFFFFF) == 0x00010){
53 pc->frame_start_found=0;
54 pc->state= state>>(2*8);
55 return i-1;
56 }
57 }
58 }
59 }
60
61 pc->frame_start_found= vop_found;
62 pc->state= state;
63 return END_NOT_FOUND;
64 }
65
66 static int h261_parse(AVCodecParserContext *s,
67 AVCodecContext *avctx,
68 uint8_t **poutbuf, int *poutbuf_size,
69 const uint8_t *buf, int buf_size)
70 {
71 ParseContext *pc = s->priv_data;
72 int next;
73
74 next= h261_find_frame_end(pc,avctx, buf, buf_size);
75 if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
76 *poutbuf = NULL;
77 *poutbuf_size = 0;
78 return buf_size;
79 }
80 *poutbuf = (uint8_t *)buf;
81 *poutbuf_size = buf_size;
82 return next;
83 }
84
85 AVCodecParser h261_parser = {
86 { CODEC_ID_H261 },
87 sizeof(ParseContext),
88 NULL,
89 h261_parse,
90 ff_parse_close,
91 };