annotate h261_parser.c @ 12478:5942c42c44e5 libavcodec

Add G.722 ADPCM audio decoder
author mstorsjo
date Thu, 09 Sep 2010 19:21:16 +0000
parents 7dd2a45249a9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4905
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
1 /*
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
2 * H261 parser
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
3 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
4 * Copyright (c) 2004 Maarten Daniels
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
5 *
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
6 * This file is part of FFmpeg.
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
7 *
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
12 *
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
16 * Lesser General Public License for more details.
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
17 *
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
21 */
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
22
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
23 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 8718
diff changeset
24 * @file
4905
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
25 * h261codec.
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
26 */
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
27
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
28 #include "parser.h"
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
29
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
30
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
31 static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
32 int vop_found, i, j;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
33 uint32_t state;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
34
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
35 vop_found= pc->frame_start_found;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
36 state= pc->state;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
37
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
38 for(i=0; i<buf_size && !vop_found; i++){
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
39 state= (state<<8) | buf[i];
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
40 for(j=0; j<8; j++){
5046
da1ca444ff51 slightly more correct spliting of frames
michael
parents: 4931
diff changeset
41 if(((state>>j)&0xFFFFF0) == 0x000100){
4905
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
42 vop_found=1;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
43 break;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
44 }
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
45 }
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
46 }
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
47 if(vop_found){
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
48 for(; i<buf_size; i++){
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
49 state= (state<<8) | buf[i];
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
50 for(j=0; j<8; j++){
5046
da1ca444ff51 slightly more correct spliting of frames
michael
parents: 4931
diff changeset
51 if(((state>>j)&0xFFFFF0) == 0x000100){
4905
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
52 pc->frame_start_found=0;
5046
da1ca444ff51 slightly more correct spliting of frames
michael
parents: 4931
diff changeset
53 pc->state= (state>>(3*8))+0xFF00;
da1ca444ff51 slightly more correct spliting of frames
michael
parents: 4931
diff changeset
54 return i-2;
4905
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
55 }
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
56 }
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
57 }
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
58 }
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
59
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
60 pc->frame_start_found= vop_found;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
61 pc->state= state;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
62 return END_NOT_FOUND;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
63 }
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
64
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
65 static int h261_parse(AVCodecParserContext *s,
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
66 AVCodecContext *avctx,
4931
0d1cc37d9430 make some parser parameters const to avoid casting const to non-const
aurel
parents: 4919
diff changeset
67 const uint8_t **poutbuf, int *poutbuf_size,
4905
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
68 const uint8_t *buf, int buf_size)
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
69 {
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
70 ParseContext *pc = s->priv_data;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
71 int next;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
72
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
73 next= h261_find_frame_end(pc,avctx, buf, buf_size);
4931
0d1cc37d9430 make some parser parameters const to avoid casting const to non-const
aurel
parents: 4919
diff changeset
74 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
4905
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
75 *poutbuf = NULL;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
76 *poutbuf_size = 0;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
77 return buf_size;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
78 }
4931
0d1cc37d9430 make some parser parameters const to avoid casting const to non-const
aurel
parents: 4919
diff changeset
79 *poutbuf = buf;
4905
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
80 *poutbuf_size = buf_size;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
81 return next;
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
82 }
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
83
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
84 AVCodecParser h261_parser = {
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
85 { CODEC_ID_H261 },
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
86 sizeof(ParseContext),
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
87 NULL,
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
88 h261_parse,
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
89 ff_parse_close,
4578b68578bb Move H.261 parser to its own file.
diego
parents:
diff changeset
90 };