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