Mercurial > libavcodec.hg
annotate vc1_parser.c @ 10559:93b8130bf480 libavcodec
Correct order of arguments for avcodec_check_dimensions().
author | michael |
---|---|
date | Mon, 23 Nov 2009 19:24:17 +0000 |
parents | c25359a56edf |
children | 7dd2a45249a9 |
rev | line source |
---|---|
4900 | 1 /* |
2 * VC-1 and WMV3 parser | |
3 * Copyright (c) 2006-2007 Konstantin Shishkov | |
4 * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer | |
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 /** | |
8718
e9d9d946f213
Use full internal pathname in doxygen @file directives.
diego
parents:
4931
diff
changeset
|
24 * @file libavcodec/vc1_parser.c |
4900 | 25 * VC-1 and WMV3 parser |
26 */ | |
4919
983533ccc393
Remove superfluous #includes, parser.h now includes its prerequisites.
diego
parents:
4904
diff
changeset
|
27 |
4900 | 28 #include "parser.h" |
29 #include "vc1.h" | |
9732
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
30 #include "get_bits.h" |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
31 |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
32 typedef struct { |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
33 ParseContext pc; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
34 VC1Context v; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
35 } VC1ParseContext; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
36 |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
37 static void vc1_extract_headers(AVCodecParserContext *s, AVCodecContext *avctx, |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
38 const uint8_t *buf, int buf_size) |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
39 { |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
40 VC1ParseContext *vpc = s->priv_data; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
41 GetBitContext gb; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
42 const uint8_t *start, *end, *next; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
43 uint8_t *buf2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
44 |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
45 vpc->v.s.avctx = avctx; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
46 vpc->v.parse_only = 1; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
47 next = buf; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
48 |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
49 for(start = buf, end = buf + buf_size; next < end; start = next){ |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
50 int buf2_size, size; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
51 |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
52 next = find_next_marker(start + 4, end); |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
53 size = next - start - 4; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
54 buf2_size = vc1_unescape_buffer(start + 4, size, buf2); |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
55 init_get_bits(&gb, buf2, buf2_size * 8); |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
56 if(size <= 0) continue; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
57 switch(AV_RB32(start)){ |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
58 case VC1_CODE_SEQHDR: |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
59 vc1_decode_sequence_header(avctx, &vpc->v, &gb); |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
60 break; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
61 case VC1_CODE_ENTRYPOINT: |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
62 vc1_decode_entry_point(avctx, &vpc->v, &gb); |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
63 break; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
64 case VC1_CODE_FRAME: |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
65 if(vpc->v.profile < PROFILE_ADVANCED) |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
66 vc1_parse_frame_header (&vpc->v, &gb); |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
67 else |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
68 vc1_parse_frame_header_adv(&vpc->v, &gb); |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
69 |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
70 /* keep FF_BI_TYPE internal to VC1 */ |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
71 if (vpc->v.s.pict_type == FF_BI_TYPE) |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
72 s->pict_type = FF_B_TYPE; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
73 else |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
74 s->pict_type = vpc->v.s.pict_type; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
75 |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
76 break; |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
77 } |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
78 } |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
79 |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
80 av_free(buf2); |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
81 } |
4900 | 82 |
83 /** | |
84 * finds the end of the current frame in the bitstream. | |
85 * @return the position of the first byte of the next frame, or -1 | |
86 */ | |
87 static int vc1_find_frame_end(ParseContext *pc, const uint8_t *buf, | |
88 int buf_size) { | |
89 int pic_found, i; | |
90 uint32_t state; | |
91 | |
92 pic_found= pc->frame_start_found; | |
93 state= pc->state; | |
94 | |
95 i=0; | |
96 if(!pic_found){ | |
97 for(i=0; i<buf_size; i++){ | |
98 state= (state<<8) | buf[i]; | |
99 if(state == VC1_CODE_FRAME || state == VC1_CODE_FIELD){ | |
100 i++; | |
101 pic_found=1; | |
102 break; | |
103 } | |
104 } | |
105 } | |
106 | |
107 if(pic_found){ | |
108 /* EOF considered as end of frame */ | |
109 if (buf_size == 0) | |
110 return 0; | |
111 for(; i<buf_size; i++){ | |
112 state= (state<<8) | buf[i]; | |
113 if(IS_MARKER(state) && state != VC1_CODE_FIELD && state != VC1_CODE_SLICE){ | |
114 pc->frame_start_found=0; | |
115 pc->state=-1; | |
116 return i-3; | |
117 } | |
118 } | |
119 } | |
120 pc->frame_start_found= pic_found; | |
121 pc->state= state; | |
122 return END_NOT_FOUND; | |
123 } | |
124 | |
125 static int vc1_parse(AVCodecParserContext *s, | |
126 AVCodecContext *avctx, | |
4931
0d1cc37d9430
make some parser parameters const to avoid casting const to non-const
aurel
parents:
4927
diff
changeset
|
127 const uint8_t **poutbuf, int *poutbuf_size, |
4900 | 128 const uint8_t *buf, int buf_size) |
129 { | |
9732
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
130 VC1ParseContext *vpc = s->priv_data; |
4900 | 131 int next; |
132 | |
133 if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ | |
134 next= buf_size; | |
135 }else{ | |
9732
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
136 next= vc1_find_frame_end(&vpc->pc, buf, buf_size); |
4900 | 137 |
9732
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
138 if (ff_combine_frame(&vpc->pc, next, &buf, &buf_size) < 0) { |
4900 | 139 *poutbuf = NULL; |
140 *poutbuf_size = 0; | |
141 return buf_size; | |
142 } | |
143 } | |
9732
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
144 |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
145 vc1_extract_headers(s, avctx, buf, buf_size); |
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
146 |
4931
0d1cc37d9430
make some parser parameters const to avoid casting const to non-const
aurel
parents:
4927
diff
changeset
|
147 *poutbuf = buf; |
4900 | 148 *poutbuf_size = buf_size; |
149 return next; | |
150 } | |
151 | |
152 static int vc1_split(AVCodecContext *avctx, | |
153 const uint8_t *buf, int buf_size) | |
154 { | |
155 int i; | |
156 uint32_t state= -1; | |
9009 | 157 int charged=0; |
4900 | 158 |
159 for(i=0; i<buf_size; i++){ | |
160 state= (state<<8) | buf[i]; | |
9009 | 161 if(IS_MARKER(state)){ |
162 if(state == VC1_CODE_SEQHDR || state == VC1_CODE_ENTRYPOINT){ | |
163 charged=1; | |
164 }else if(charged){ | |
165 return i-3; | |
166 } | |
167 } | |
4900 | 168 } |
169 return 0; | |
170 } | |
171 | |
172 AVCodecParser vc1_parser = { | |
173 { CODEC_ID_VC1 }, | |
9732
c25359a56edf
set pict_type in VC-1 parser, fix some timestamps problems
bcoudurier
parents:
9009
diff
changeset
|
174 sizeof(VC1ParseContext), |
4900 | 175 NULL, |
176 vc1_parse, | |
177 ff_parse1_close, | |
178 vc1_split, | |
179 }; |