vc1dec: Fix leak on error for array allocations
[libav.git] / libavcodec / vc1dec.c
CommitLineData
b761659b
DB
1/*
2 * VC-1 and WMV3 decoder
cad16562 3 * Copyright (c) 2011 Mashiat Sarker Shakkhar
b761659b
DB
4 * Copyright (c) 2006-2007 Konstantin Shishkov
5 * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
6 *
2912e87a 7 * This file is part of Libav.
b761659b 8 *
2912e87a 9 * Libav is free software; you can redistribute it and/or
b761659b
DB
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
2912e87a 14 * Libav is distributed in the hope that it will be useful,
b761659b
DB
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
2912e87a 20 * License along with Libav; if not, write to the Free Software
b761659b
DB
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24/**
ba87f080 25 * @file
b761659b 26 * VC-1 and WMV3 decoder
b761659b 27 */
50f97219 28
b761659b 29#include "avcodec.h"
04d14c9b
LB
30#include "blockdsp.h"
31#include "get_bits.h"
32#include "internal.h"
7b9ef8d7 33#include "mpeg_er.h"
b761659b 34#include "mpegvideo.h"
31a117a0 35#include "msmpeg4.h"
04d14c9b 36#include "msmpeg4data.h"
2c681139 37#include "profiles.h"
b761659b
DB
38#include "vc1.h"
39#include "vc1data.h"
b761659b 40
45ecda85
AD
41#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
42
7f9f771e 43typedef struct SpriteData {
45ecda85
AD
44 /**
45 * Transform coefficients for both sprites in 16.16 fixed point format,
46 * in the order they appear in the bitstream:
47 * x scale
48 * rotation 1 (unused)
49 * x offset
50 * rotation 2 (unused)
51 * y scale
52 * y offset
53 * alpha
54 */
55 int coefs[2][7];
56
57 int effect_type, effect_flag;
58 int effect_pcount1, effect_pcount2; ///< amount of effect parameters stored in effect_params
59 int effect_params1[15], effect_params2[10]; ///< effect parameters in 16.16 fixed point format
60} SpriteData;
61
62static inline int get_fp_val(GetBitContext* gb)
768c5251 63{
50f97219 64 return (get_bits_long(gb, 30) - (1 << 29)) << 1;
768c5251
AD
65}
66
45ecda85 67static void vc1_sprite_parse_transform(GetBitContext* gb, int c[7])
768c5251 68{
45ecda85 69 c[1] = c[3] = 0;
768c5251
AD
70
71 switch (get_bits(gb, 2)) {
72 case 0:
50f97219 73 c[0] = 1 << 16;
45ecda85 74 c[2] = get_fp_val(gb);
50f97219 75 c[4] = 1 << 16;
768c5251
AD
76 break;
77 case 1:
45ecda85
AD
78 c[0] = c[4] = get_fp_val(gb);
79 c[2] = get_fp_val(gb);
768c5251
AD
80 break;
81 case 2:
45ecda85
AD
82 c[0] = get_fp_val(gb);
83 c[2] = get_fp_val(gb);
84 c[4] = get_fp_val(gb);
768c5251
AD
85 break;
86 case 3:
45ecda85
AD
87 c[0] = get_fp_val(gb);
88 c[1] = get_fp_val(gb);
89 c[2] = get_fp_val(gb);
90 c[3] = get_fp_val(gb);
91 c[4] = get_fp_val(gb);
768c5251
AD
92 break;
93 }
45ecda85 94 c[5] = get_fp_val(gb);
768c5251 95 if (get_bits1(gb))
45ecda85 96 c[6] = get_fp_val(gb);
768c5251 97 else
50f97219 98 c[6] = 1 << 16;
768c5251
AD
99}
100
45ecda85 101static void vc1_parse_sprites(VC1Context *v, GetBitContext* gb, SpriteData* sd)
768c5251 102{
45ecda85
AD
103 AVCodecContext *avctx = v->s.avctx;
104 int sprite, i;
105
106 for (sprite = 0; sprite <= v->two_sprites; sprite++) {
107 vc1_sprite_parse_transform(gb, sd->coefs[sprite]);
108 if (sd->coefs[sprite][1] || sd->coefs[sprite][3])
6d97484d 109 avpriv_request_sample(avctx, "Non-zero rotation coefficients");
45ecda85 110 av_log(avctx, AV_LOG_DEBUG, sprite ? "S2:" : "S1:");
768c5251 111 for (i = 0; i < 7; i++)
45ecda85
AD
112 av_log(avctx, AV_LOG_DEBUG, " %d.%.3d",
113 sd->coefs[sprite][i] / (1<<16),
50f97219 114 (abs(sd->coefs[sprite][i]) & 0xFFFF) * 1000 / (1 << 16));
45ecda85 115 av_log(avctx, AV_LOG_DEBUG, "\n");
768c5251 116 }
45ecda85 117
768c5251 118 skip_bits(gb, 2);
45ecda85
AD
119 if (sd->effect_type = get_bits_long(gb, 30)) {
120 switch (sd->effect_pcount1 = get_bits(gb, 4)) {
768c5251 121 case 7:
45ecda85 122 vc1_sprite_parse_transform(gb, sd->effect_params1);
768c5251
AD
123 break;
124 case 14:
45ecda85
AD
125 vc1_sprite_parse_transform(gb, sd->effect_params1);
126 vc1_sprite_parse_transform(gb, sd->effect_params1 + 7);
768c5251
AD
127 break;
128 default:
45ecda85
AD
129 for (i = 0; i < sd->effect_pcount1; i++)
130 sd->effect_params1[i] = get_fp_val(gb);
768c5251 131 }
45ecda85 132 if (sd->effect_type != 13 || sd->effect_params1[0] != sd->coefs[0][6]) {
768c5251 133 // effect 13 is simple alpha blending and matches the opacity above
45ecda85
AD
134 av_log(avctx, AV_LOG_DEBUG, "Effect: %d; params: ", sd->effect_type);
135 for (i = 0; i < sd->effect_pcount1; i++)
136 av_log(avctx, AV_LOG_DEBUG, " %d.%.2d",
50f97219
KS
137 sd->effect_params1[i] / (1 << 16),
138 (abs(sd->effect_params1[i]) & 0xFFFF) * 1000 / (1 << 16));
45ecda85 139 av_log(avctx, AV_LOG_DEBUG, "\n");
768c5251
AD
140 }
141
45ecda85
AD
142 sd->effect_pcount2 = get_bits(gb, 16);
143 if (sd->effect_pcount2 > 10) {
144 av_log(avctx, AV_LOG_ERROR, "Too many effect parameters\n");
768c5251 145 return;
45ecda85
AD
146 } else if (sd->effect_pcount2) {
147 i = -1;
148 av_log(avctx, AV_LOG_DEBUG, "Effect params 2: ");
50f97219 149 while (++i < sd->effect_pcount2) {
45ecda85
AD
150 sd->effect_params2[i] = get_fp_val(gb);
151 av_log(avctx, AV_LOG_DEBUG, " %d.%.2d",
50f97219
KS
152 sd->effect_params2[i] / (1 << 16),
153 (abs(sd->effect_params2[i]) & 0xFFFF) * 1000 / (1 << 16));
768c5251 154 }
45ecda85 155 av_log(avctx, AV_LOG_DEBUG, "\n");
768c5251
AD
156 }
157 }
45ecda85
AD
158 if (sd->effect_flag = get_bits1(gb))
159 av_log(avctx, AV_LOG_DEBUG, "Effect flag set\n");
768c5251
AD
160
161 if (get_bits_count(gb) >= gb->size_in_bits +
36ef5369 162 (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE ? 64 : 0))
45ecda85 163 av_log(avctx, AV_LOG_ERROR, "Buffer overrun\n");
768c5251 164 if (get_bits_count(gb) < gb->size_in_bits - 8)
45ecda85
AD
165 av_log(avctx, AV_LOG_WARNING, "Buffer not fully read\n");
166}
167
168static void vc1_draw_sprites(VC1Context *v, SpriteData* sd)
169{
170 int i, plane, row, sprite;
171 int sr_cache[2][2] = { { -1, -1 }, { -1, -1 } };
172 uint8_t* src_h[2][2];
173 int xoff[2], xadv[2], yoff[2], yadv[2], alpha;
174 int ysub[2];
175 MpegEncContext *s = &v->s;
176
177 for (i = 0; i < 2; i++) {
178 xoff[i] = av_clip(sd->coefs[i][2], 0, v->sprite_width-1 << 16);
179 xadv[i] = sd->coefs[i][0];
50f97219 180 if (xadv[i] != 1<<16 || (v->sprite_width << 16) - (v->output_width << 16) - xoff[i])
45ecda85
AD
181 xadv[i] = av_clip(xadv[i], 0, ((v->sprite_width<<16) - xoff[i] - 1) / v->output_width);
182
183 yoff[i] = av_clip(sd->coefs[i][5], 0, v->sprite_height-1 << 16);
50f97219 184 yadv[i] = av_clip(sd->coefs[i][4], 0, ((v->sprite_height << 16) - yoff[i]) / v->output_height);
45ecda85 185 }
9abc80f1 186 alpha = av_clip_uint16(sd->coefs[1][6]);
45ecda85 187
7c6eb0a1 188 for (plane = 0; plane < (s->avctx->flags & AV_CODEC_FLAG_GRAY ? 1 : 3); plane++) {
45ecda85
AD
189 int width = v->output_width>>!!plane;
190
191 for (row = 0; row < v->output_height>>!!plane; row++) {
6792559f
AK
192 uint8_t *dst = v->sprite_output_frame->data[plane] +
193 v->sprite_output_frame->linesize[plane] * row;
45ecda85
AD
194
195 for (sprite = 0; sprite <= v->two_sprites; sprite++) {
f6774f90 196 uint8_t *iplane = s->current_picture.f->data[plane];
197 int iline = s->current_picture.f->linesize[plane];
50f97219
KS
198 int ycoord = yoff[sprite] + yadv[sprite] * row;
199 int yline = ycoord >> 16;
2bf369b6 200 int next_line;
50f97219 201 ysub[sprite] = ycoord & 0xFFFF;
45ecda85 202 if (sprite) {
f6774f90 203 iplane = s->last_picture.f->data[plane];
204 iline = s->last_picture.f->linesize[plane];
45ecda85 205 }
2bf369b6 206 next_line = FFMIN(yline + 1, (v->sprite_height >> !!plane) - 1) * iline;
50f97219
KS
207 if (!(xoff[sprite] & 0xFFFF) && xadv[sprite] == 1 << 16) {
208 src_h[sprite][0] = iplane + (xoff[sprite] >> 16) + yline * iline;
45ecda85 209 if (ysub[sprite])
2bf369b6 210 src_h[sprite][1] = iplane + (xoff[sprite] >> 16) + next_line;
45ecda85
AD
211 } else {
212 if (sr_cache[sprite][0] != yline) {
213 if (sr_cache[sprite][1] == yline) {
214 FFSWAP(uint8_t*, v->sr_rows[sprite][0], v->sr_rows[sprite][1]);
215 FFSWAP(int, sr_cache[sprite][0], sr_cache[sprite][1]);
216 } else {
50f97219 217 v->vc1dsp.sprite_h(v->sr_rows[sprite][0], iplane + yline * iline, xoff[sprite], xadv[sprite], width);
45ecda85
AD
218 sr_cache[sprite][0] = yline;
219 }
220 }
221 if (ysub[sprite] && sr_cache[sprite][1] != yline + 1) {
2bf369b6
MN
222 v->vc1dsp.sprite_h(v->sr_rows[sprite][1],
223 iplane + next_line, xoff[sprite],
224 xadv[sprite], width);
45ecda85
AD
225 sr_cache[sprite][1] = yline + 1;
226 }
227 src_h[sprite][0] = v->sr_rows[sprite][0];
228 src_h[sprite][1] = v->sr_rows[sprite][1];
229 }
230 }
231
232 if (!v->two_sprites) {
233 if (ysub[0]) {
234 v->vc1dsp.sprite_v_single(dst, src_h[0][0], src_h[0][1], ysub[0], width);
235 } else {
236 memcpy(dst, src_h[0][0], width);
237 }
238 } else {
239 if (ysub[0] && ysub[1]) {
240 v->vc1dsp.sprite_v_double_twoscale(dst, src_h[0][0], src_h[0][1], ysub[0],
241 src_h[1][0], src_h[1][1], ysub[1], alpha, width);
242 } else if (ysub[0]) {
243 v->vc1dsp.sprite_v_double_onescale(dst, src_h[0][0], src_h[0][1], ysub[0],
244 src_h[1][0], alpha, width);
245 } else if (ysub[1]) {
246 v->vc1dsp.sprite_v_double_onescale(dst, src_h[1][0], src_h[1][1], ysub[1],
247 src_h[0][0], (1<<16)-1-alpha, width);
248 } else {
249 v->vc1dsp.sprite_v_double_noscale(dst, src_h[0][0], src_h[1][0], alpha, width);
250 }
251 }
252 }
253
254 if (!plane) {
255 for (i = 0; i < 2; i++) {
256 xoff[i] >>= 1;
257 yoff[i] >>= 1;
258 }
259 }
260
261 }
262}
263
264
265static int vc1_decode_sprites(VC1Context *v, GetBitContext* gb)
266{
50f97219 267 MpegEncContext *s = &v->s;
45ecda85
AD
268 AVCodecContext *avctx = s->avctx;
269 SpriteData sd;
270
271 vc1_parse_sprites(v, gb, &sd);
272
f6774f90 273 if (!s->current_picture.f->data[0]) {
45ecda85
AD
274 av_log(avctx, AV_LOG_ERROR, "Got no sprites\n");
275 return -1;
276 }
277
f6774f90 278 if (v->two_sprites && (!s->last_picture_ptr || !s->last_picture.f->data[0])) {
45ecda85
AD
279 av_log(avctx, AV_LOG_WARNING, "Need two sprites, only got one\n");
280 v->two_sprites = 0;
281 }
282
6792559f
AK
283 av_frame_unref(v->sprite_output_frame);
284 if (ff_get_buffer(avctx, v->sprite_output_frame, 0) < 0) {
45ecda85
AD
285 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
286 return -1;
287 }
288
289 vc1_draw_sprites(v, &sd);
290
291 return 0;
292}
293
294static void vc1_sprite_flush(AVCodecContext *avctx)
295{
50f97219 296 VC1Context *v = avctx->priv_data;
45ecda85 297 MpegEncContext *s = &v->s;
f6774f90 298 AVFrame *f = s->current_picture.f;
45ecda85
AD
299 int plane, i;
300
301 /* Windows Media Image codecs have a convergence interval of two keyframes.
302 Since we can't enforce it, clear to black the missing sprite. This is
303 wrong but it looks better than doing nothing. */
304
68211c70 305 if (f && f->data[0])
7c6eb0a1 306 for (plane = 0; plane < (s->avctx->flags & AV_CODEC_FLAG_GRAY ? 1 : 3); plane++)
45ecda85 307 for (i = 0; i < v->sprite_height>>!!plane; i++)
50f97219 308 memset(f->data[plane] + i * f->linesize[plane],
45ecda85 309 plane ? 128 : 0, f->linesize[plane]);
768c5251
AD
310}
311
45ecda85
AD
312#endif
313
7627c35a 314av_cold int ff_vc1_decode_init_alloc_tables(VC1Context *v)
d2f119a1
AD
315{
316 MpegEncContext *s = &v->s;
317 int i;
d8fd1836 318 int mb_height = FFALIGN(s->mb_height, 2);
d2f119a1
AD
319
320 /* Allocate mb bitplanes */
d8fd1836
MN
321 v->mv_type_mb_plane = av_malloc (s->mb_stride * mb_height);
322 v->direct_mb_plane = av_malloc (s->mb_stride * mb_height);
323 v->forward_mb_plane = av_malloc (s->mb_stride * mb_height);
324 v->fieldtx_plane = av_mallocz(s->mb_stride * mb_height);
325 v->acpred_plane = av_malloc (s->mb_stride * mb_height);
326 v->over_flags_plane = av_malloc (s->mb_stride * mb_height);
d2f119a1
AD
327
328 v->n_allocated_blks = s->mb_width + 2;
50f97219
KS
329 v->block = av_malloc(sizeof(*v->block) * v->n_allocated_blks);
330 v->cbp_base = av_malloc(sizeof(v->cbp_base[0]) * 2 * s->mb_stride);
331 v->cbp = v->cbp_base + s->mb_stride;
332 v->ttblk_base = av_malloc(sizeof(v->ttblk_base[0]) * 2 * s->mb_stride);
333 v->ttblk = v->ttblk_base + s->mb_stride;
334 v->is_intra_base = av_mallocz(sizeof(v->is_intra_base[0]) * 2 * s->mb_stride);
335 v->is_intra = v->is_intra_base + s->mb_stride;
336 v->luma_mv_base = av_malloc(sizeof(v->luma_mv_base[0]) * 2 * s->mb_stride);
337 v->luma_mv = v->luma_mv_base + s->mb_stride;
d2f119a1
AD
338
339 /* allocate block type info in that way so it could be used with s->block_index[] */
d8fd1836 340 v->mb_type_base = av_malloc(s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
50f97219 341 v->mb_type[0] = v->mb_type_base + s->b8_stride + 1;
d8fd1836
MN
342 v->mb_type[1] = v->mb_type_base + s->b8_stride * (mb_height * 2 + 1) + s->mb_stride + 1;
343 v->mb_type[2] = v->mb_type[1] + s->mb_stride * (mb_height + 1);
d2f119a1 344
cad16562 345 /* allocate memory to store block level MV info */
d8fd1836 346 v->blk_mv_type_base = av_mallocz( s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
50f97219 347 v->blk_mv_type = v->blk_mv_type_base + s->b8_stride + 1;
d8fd1836 348 v->mv_f_base = av_mallocz(2 * (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2));
50f97219 349 v->mv_f[0] = v->mv_f_base + s->b8_stride + 1;
d8fd1836
MN
350 v->mv_f[1] = v->mv_f[0] + (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
351 v->mv_f_next_base = av_mallocz(2 * (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2));
50f97219 352 v->mv_f_next[0] = v->mv_f_next_base + s->b8_stride + 1;
d8fd1836 353 v->mv_f_next[1] = v->mv_f_next[0] + (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
cad16562 354
d2f119a1
AD
355 ff_intrax8_common_init(&v->x8,s);
356
36ef5369 357 if (s->avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || s->avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
01f0e6a0
VG
358 for (i = 0; i < 4; i++) {
359 v->sr_rows[i >> 1][i & 1] = av_malloc(v->output_width);
360 if (!v->sr_rows[i >> 1][i & 1])
361 goto error;
362 }
d2f119a1
AD
363 }
364
365 if (!v->mv_type_mb_plane || !v->direct_mb_plane || !v->acpred_plane || !v->over_flags_plane ||
366 !v->block || !v->cbp_base || !v->ttblk_base || !v->is_intra_base || !v->luma_mv_base ||
ede50844 367 !v->mb_type_base) {
f91d94bd 368 goto error;
ede50844 369 }
d2f119a1
AD
370
371 return 0;
f91d94bd
VG
372
373error:
374 ff_vc1_decode_end(s->avctx);
375 return AVERROR(ENOMEM);
d2f119a1
AD
376}
377
7627c35a
KS
378av_cold void ff_vc1_init_transposed_scantables(VC1Context *v)
379{
380 int i;
381 for (i = 0; i < 64; i++) {
382#define transpose(x) ((x >> 3) | ((x & 7) << 3))
383 v->zz_8x8[0][i] = transpose(ff_wmv1_scantable[0][i]);
384 v->zz_8x8[1][i] = transpose(ff_wmv1_scantable[1][i]);
385 v->zz_8x8[2][i] = transpose(ff_wmv1_scantable[2][i]);
386 v->zz_8x8[3][i] = transpose(ff_wmv1_scantable[3][i]);
387 v->zzi_8x8[i] = transpose(ff_vc1_adv_interlaced_8x8_zz[i]);
388 }
389 v->left_blk_sh = 0;
390 v->top_blk_sh = 3;
391}
392
b761659b
DB
393/** Initialize a VC1/WMV3 decoder
394 * @todo TODO: Handle VC-1 IDUs (Transport level?)
395 * @todo TODO: Decypher remaining bits in extra_data
396 */
397static av_cold int vc1_decode_init(AVCodecContext *avctx)
398{
399 VC1Context *v = avctx->priv_data;
400 MpegEncContext *s = &v->s;
401 GetBitContext gb;
402
45ecda85
AD
403 /* save the container output size for WMImage */
404 v->output_width = avctx->width;
405 v->output_height = avctx->height;
406
50f97219
KS
407 if (!avctx->extradata_size || !avctx->extradata)
408 return -1;
7c6eb0a1 409 if (!(avctx->flags & AV_CODEC_FLAG_GRAY))
632ad224 410 avctx->pix_fmt = ff_get_format(avctx, avctx->codec->pix_fmts);
b761659b 411 else
716d413c 412 avctx->pix_fmt = AV_PIX_FMT_GRAY8;
b761659b 413 v->s.avctx = avctx;
b761659b 414
c742ab4e 415 if (ff_vc1_init_common(v) < 0)
50f97219 416 return -1;
e74433a8 417 ff_blockdsp_init(&s->bdsp, avctx);
79dad2a9 418 ff_h264chroma_init(&v->h264chroma, 8);
368f5035 419 ff_qpeldsp_init(&s->qdsp);
b761659b 420
36ef5369 421 if (avctx->codec_id == AV_CODEC_ID_WMV3 || avctx->codec_id == AV_CODEC_ID_WMV3IMAGE) {
b761659b
DB
422 int count = 0;
423
424 // looks like WMV3 has a sequence header stored in the extradata
425 // advanced sequence header may be before the first frame
426 // the last byte of the extradata is a version number, 1 for the
427 // samples we can decode
428
429 init_get_bits(&gb, avctx->extradata, avctx->extradata_size*8);
430
5f2c159c 431 if (ff_vc1_decode_sequence_header(avctx, v, &gb) < 0)
b761659b
DB
432 return -1;
433
434 count = avctx->extradata_size*8 - get_bits_count(&gb);
50f97219 435 if (count > 0) {
b761659b 436 av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n",
072756cd 437 count, get_bits_long(&gb, FFMIN(count, 32)));
50f97219 438 } else if (count < 0) {
b761659b
DB
439 av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count);
440 }
768c5251 441 } else { // VC1/WVC1/WVP2
b761659b
DB
442 const uint8_t *start = avctx->extradata;
443 uint8_t *end = avctx->extradata + avctx->extradata_size;
444 const uint8_t *next;
445 int size, buf2_size;
446 uint8_t *buf2 = NULL;
447 int seq_initialized = 0, ep_initialized = 0;
448
50f97219 449 if (avctx->extradata_size < 16) {
b761659b
DB
450 av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", avctx->extradata_size);
451 return -1;
452 }
453
059a9348 454 buf2 = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
95ce961d 455 start = find_next_marker(start, end); // in WVC1 extradata first byte is its size, but can be 0 in mkv
50f97219
KS
456 next = start;
457 for (; next < end; start = next) {
b761659b
DB
458 next = find_next_marker(start + 4, end);
459 size = next - start - 4;
50f97219
KS
460 if (size <= 0)
461 continue;
b761659b
DB
462 buf2_size = vc1_unescape_buffer(start + 4, size, buf2);
463 init_get_bits(&gb, buf2, buf2_size * 8);
50f97219 464 switch (AV_RB32(start)) {
b761659b 465 case VC1_CODE_SEQHDR:
5f2c159c 466 if (ff_vc1_decode_sequence_header(avctx, v, &gb) < 0) {
b761659b
DB
467 av_free(buf2);
468 return -1;
469 }
470 seq_initialized = 1;
471 break;
472 case VC1_CODE_ENTRYPOINT:
5f2c159c 473 if (ff_vc1_decode_entry_point(avctx, v, &gb) < 0) {
b761659b
DB
474 av_free(buf2);
475 return -1;
476 }
477 ep_initialized = 1;
478 break;
479 }
480 }
481 av_free(buf2);
50f97219 482 if (!seq_initialized || !ep_initialized) {
b761659b
DB
483 av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n");
484 return -1;
485 }
77bcb896 486 v->res_sprite = (avctx->codec_id == AV_CODEC_ID_VC1IMAGE);
b761659b 487 }
7b20d35a 488
6792559f
AK
489 v->sprite_output_frame = av_frame_alloc();
490 if (!v->sprite_output_frame)
491 return AVERROR(ENOMEM);
492
0215006a
HL
493 avctx->profile = v->profile;
494 if (v->profile == PROFILE_ADVANCED)
495 avctx->level = v->level;
496
3dc99a18 497 avctx->has_b_frames = !!avctx->max_b_frames;
b761659b 498
1a02e786
VG
499 if (v->color_prim == 1 || v->color_prim == 5 || v->color_prim == 6)
500 avctx->color_primaries = v->color_prim;
501 if (v->transfer_char == 1 || v->transfer_char == 7)
502 avctx->color_trc = v->transfer_char;
503 if (v->matrix_coef == 1 || v->matrix_coef == 6 || v->matrix_coef == 7)
504 avctx->colorspace = v->matrix_coef;
505
50f97219
KS
506 s->mb_width = (avctx->coded_width + 15) >> 4;
507 s->mb_height = (avctx->coded_height + 15) >> 4;
b761659b 508
0b05864e 509 if (v->profile == PROFILE_ADVANCED || v->res_fasttx) {
7627c35a 510 ff_vc1_init_transposed_scantables(v);
58bb6b7d 511 } else {
1fec0550 512 memcpy(v->zz_8x8, ff_wmv1_scantable, 4*64);
58bb6b7d
RB
513 v->left_blk_sh = 3;
514 v->top_blk_sh = 0;
515 }
516
36ef5369 517 if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
45ecda85
AD
518 v->sprite_width = avctx->coded_width;
519 v->sprite_height = avctx->coded_height;
520
521 avctx->coded_width = avctx->width = v->output_width;
522 avctx->coded_height = avctx->height = v->output_height;
523
524 // prevent 16.16 overflows
50f97219
KS
525 if (v->sprite_width > 1 << 14 ||
526 v->sprite_height > 1 << 14 ||
527 v->output_width > 1 << 14 ||
528 v->output_height > 1 << 14) return -1;
45ecda85 529 }
b761659b
DB
530 return 0;
531}
532
d2f119a1
AD
533/** Close a VC1/WMV3 decoder
534 * @warning Initial try at using MpegEncContext stuff
535 */
7627c35a 536av_cold int ff_vc1_decode_end(AVCodecContext *avctx)
d2f119a1
AD
537{
538 VC1Context *v = avctx->priv_data;
539 int i;
540
6792559f 541 av_frame_free(&v->sprite_output_frame);
759001c5 542
d2f119a1 543 for (i = 0; i < 4; i++)
50f97219 544 av_freep(&v->sr_rows[i >> 1][i & 1]);
d2f119a1
AD
545 av_freep(&v->hrd_rate);
546 av_freep(&v->hrd_buffer);
835f798c 547 ff_mpv_common_end(&v->s);
d2f119a1
AD
548 av_freep(&v->mv_type_mb_plane);
549 av_freep(&v->direct_mb_plane);
cad16562
MSS
550 av_freep(&v->forward_mb_plane);
551 av_freep(&v->fieldtx_plane);
d2f119a1
AD
552 av_freep(&v->acpred_plane);
553 av_freep(&v->over_flags_plane);
554 av_freep(&v->mb_type_base);
cad16562
MSS
555 av_freep(&v->blk_mv_type_base);
556 av_freep(&v->mv_f_base);
cad16562 557 av_freep(&v->mv_f_next_base);
d2f119a1
AD
558 av_freep(&v->block);
559 av_freep(&v->cbp_base);
560 av_freep(&v->ttblk_base);
561 av_freep(&v->is_intra_base); // FIXME use v->mb_type[]
562 av_freep(&v->luma_mv_base);
563 ff_intrax8_common_end(&v->x8);
564 return 0;
565}
566
b761659b
DB
567
568/** Decode a VC1/WMV3 frame
569 * @todo TODO: Handle VC-1 IDUs (Transport level?)
570 */
50f97219 571static int vc1_decode_frame(AVCodecContext *avctx, void *data,
df9b9567 572 int *got_frame, AVPacket *avpkt)
b761659b
DB
573{
574 const uint8_t *buf = avpkt->data;
759001c5 575 int buf_size = avpkt->size, n_slices = 0, i, ret;
b761659b
DB
576 VC1Context *v = avctx->priv_data;
577 MpegEncContext *s = &v->s;
578 AVFrame *pict = data;
579 uint8_t *buf2 = NULL;
580 const uint8_t *buf_start = buf;
cad16562 581 int mb_height, n_slices1;
f44d6445
RB
582 struct {
583 uint8_t *buf;
584 GetBitContext gb;
585 int mby_start;
b797f735 586 } *slices = NULL, *tmp;
b761659b
DB
587
588 /* no supplementary picture */
fb985071 589 if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == VC1_CODE_ENDOFSEQ)) {
b761659b 590 /* special case for last picture */
50f97219 591 if (s->low_delay == 0 && s->next_picture_ptr) {
f6774f90 592 if ((ret = av_frame_ref(pict, s->next_picture_ptr->f)) < 0)
759001c5 593 return ret;
50f97219 594 s->next_picture_ptr = NULL;
b761659b 595
df9b9567 596 *got_frame = 1;
b761659b
DB
597 }
598
599 return 0;
600 }
601
b761659b 602 //for advanced profile we may need to parse and unescape data
36ef5369 603 if (avctx->codec_id == AV_CODEC_ID_VC1 || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
b761659b 604 int buf_size2 = 0;
059a9348 605 buf2 = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
b761659b 606
50f97219 607 if (IS_MARKER(AV_RB32(buf))) { /* frame starts with marker and needs to be parsed */
b761659b
DB
608 const uint8_t *start, *end, *next;
609 int size;
610
611 next = buf;
50f97219 612 for (start = buf, end = buf + buf_size; next < end; start = next) {
b761659b
DB
613 next = find_next_marker(start + 4, end);
614 size = next - start - 4;
50f97219
KS
615 if (size <= 0) continue;
616 switch (AV_RB32(start)) {
b761659b 617 case VC1_CODE_FRAME:
578ea75a 618 if (avctx->hwaccel)
b761659b
DB
619 buf_start = start;
620 buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
621 break;
cad16562
MSS
622 case VC1_CODE_FIELD: {
623 int buf_size3;
714f5ab5
JG
624 tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1));
625 if (!tmp)
50f97219 626 goto err;
714f5ab5 627 slices = tmp;
059a9348 628 slices[n_slices].buf = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
50f97219
KS
629 if (!slices[n_slices].buf)
630 goto err;
cad16562
MSS
631 buf_size3 = vc1_unescape_buffer(start + 4, size,
632 slices[n_slices].buf);
633 init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
634 buf_size3 << 3);
635 /* assuming that the field marker is at the exact middle,
636 hope it's correct */
637 slices[n_slices].mby_start = s->mb_height >> 1;
638 n_slices1 = n_slices - 1; // index of the last slice of the first field
639 n_slices++;
cad16562
MSS
640 break;
641 }
b761659b
DB
642 case VC1_CODE_ENTRYPOINT: /* it should be before frame data */
643 buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
50f97219 644 init_get_bits(&s->gb, buf2, buf_size2 * 8);
5f2c159c 645 ff_vc1_decode_entry_point(avctx, v, &s->gb);
b761659b 646 break;
f44d6445
RB
647 case VC1_CODE_SLICE: {
648 int buf_size3;
714f5ab5
JG
649 tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1));
650 if (!tmp)
50f97219 651 goto err;
714f5ab5 652 slices = tmp;
059a9348 653 slices[n_slices].buf = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
50f97219
KS
654 if (!slices[n_slices].buf)
655 goto err;
f44d6445
RB
656 buf_size3 = vc1_unescape_buffer(start + 4, size,
657 slices[n_slices].buf);
658 init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
659 buf_size3 << 3);
660 slices[n_slices].mby_start = get_bits(&slices[n_slices].gb, 9);
661 n_slices++;
662 break;
663 }
b761659b
DB
664 }
665 }
50f97219 666 } else if (v->interlace && ((buf[0] & 0xC0) == 0xC0)) { /* WVC1 interlaced stores both fields divided by marker */
b761659b 667 const uint8_t *divider;
0a6aff69 668 int buf_size3;
b761659b
DB
669
670 divider = find_next_marker(buf, buf + buf_size);
50f97219 671 if ((divider == (buf + buf_size)) || AV_RB32(divider) != VC1_CODE_FIELD) {
b761659b 672 av_log(avctx, AV_LOG_ERROR, "Error in WVC1 interlaced frame\n");
b81a935b 673 goto err;
cad16562 674 } else { // found field marker, unescape second field
0a6aff69
AD
675 tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1));
676 if (!tmp)
677 goto err;
678 slices = tmp;
059a9348 679 slices[n_slices].buf = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
0a6aff69
AD
680 if (!slices[n_slices].buf)
681 goto err;
682 buf_size3 = vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf);
683 init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
684 buf_size3 << 3);
685 slices[n_slices].mby_start = s->mb_height >> 1;
686 n_slices1 = n_slices - 1;
687 n_slices++;
b761659b 688 }
b761659b 689 buf_size2 = vc1_unescape_buffer(buf, divider - buf, buf2);
50f97219 690 } else {
b761659b
DB
691 buf_size2 = vc1_unescape_buffer(buf, buf_size, buf2);
692 }
693 init_get_bits(&s->gb, buf2, buf_size2*8);
694 } else
695 init_get_bits(&s->gb, buf, buf_size*8);
768c5251
AD
696
697 if (v->res_sprite) {
50f97219
KS
698 v->new_sprite = !get_bits1(&s->gb);
699 v->two_sprites = get_bits1(&s->gb);
36ef5369 700 /* res_sprite means a Windows Media Image stream, AV_CODEC_ID_*IMAGE means
45ecda85
AD
701 we're using the sprite compositor. These are intentionally kept separate
702 so you can get the raw sprites by using the wmv3 decoder for WMVP or
703 the vc1 one for WVP2 */
36ef5369 704 if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
45ecda85
AD
705 if (v->new_sprite) {
706 // switch AVCodecContext parameters to those of the sprites
707 avctx->width = avctx->coded_width = v->sprite_width;
708 avctx->height = avctx->coded_height = v->sprite_height;
709 } else {
710 goto image;
711 }
712 }
768c5251
AD
713 }
714
d2f119a1
AD
715 if (s->context_initialized &&
716 (s->width != avctx->coded_width ||
717 s->height != avctx->coded_height)) {
7627c35a 718 ff_vc1_decode_end(avctx);
d2f119a1
AD
719 }
720
721 if (!s->context_initialized) {
b772b0e2 722 if (ff_msmpeg4_decode_init(avctx) < 0)
6f8ef532 723 goto err;
b772b0e2 724 if (ff_vc1_decode_init_alloc_tables(v) < 0) {
835f798c 725 ff_mpv_common_end(s);
b772b0e2
MS
726 goto err;
727 }
d2f119a1
AD
728
729 s->low_delay = !avctx->has_b_frames || v->res_sprite;
730
731 if (v->profile == PROFILE_ADVANCED) {
732 s->h_edge_pos = avctx->coded_width;
733 s->v_edge_pos = avctx->coded_height;
734 }
735 }
736
b761659b 737 // do parse frame header
cad16562 738 v->pic_header_flag = 0;
4162fc62 739 v->first_pic_header_flag = 1;
50f97219 740 if (v->profile < PROFILE_ADVANCED) {
ec7d002e 741 if (ff_vc1_parse_frame_header(v, &s->gb) < 0) {
b81a935b 742 goto err;
b761659b
DB
743 }
744 } else {
ec7d002e 745 if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
b81a935b 746 goto err;
b761659b
DB
747 }
748 }
4162fc62 749 v->first_pic_header_flag = 0;
b761659b 750
36ef5369 751 if ((avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE)
50f97219 752 && s->pict_type != AV_PICTURE_TYPE_I) {
45ecda85
AD
753 av_log(v->s.avctx, AV_LOG_ERROR, "Sprite decoder: expected I-frame\n");
754 goto err;
cba322d7
KS
755 }
756
8ed2ae09 757 // for skipping the frame
f6774f90 758 s->current_picture.f->pict_type = s->pict_type;
759 s->current_picture.f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
b761659b
DB
760
761 /* skip B-frames if we don't have reference frames */
f929ab05 762 if (!s->last_picture_ptr && (s->pict_type == AV_PICTURE_TYPE_B || s->droppable)) {
cdf6eb5a 763 goto end;
b761659b 764 }
50f97219
KS
765 if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||
766 (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) ||
767 avctx->skip_frame >= AVDISCARD_ALL) {
b81a935b 768 goto end;
b761659b 769 }
b761659b 770
50f97219
KS
771 if (s->next_p_frame_damaged) {
772 if (s->pict_type == AV_PICTURE_TYPE_B)
b81a935b 773 goto end;
b761659b 774 else
50f97219 775 s->next_p_frame_damaged = 0;
b761659b
DB
776 }
777
835f798c 778 if (ff_mpv_frame_start(s, avctx) < 0) {
b81a935b 779 goto err;
b761659b
DB
780 }
781
ac1fc92e 782 // process pulldown flags
f6774f90 783 s->current_picture_ptr->f->repeat_pict = 0;
ac1fc92e
AK
784 // Pulldown flags are only valid when 'broadcast' has been set.
785 // So ticks_per_frame will be 2
786 if (v->rff) {
787 // repeat field
f6774f90 788 s->current_picture_ptr->f->repeat_pict = 1;
ac1fc92e
AK
789 } else if (v->rptfrm) {
790 // repeat frames
f6774f90 791 s->current_picture_ptr->f->repeat_pict = v->rptfrm * 2;
ac1fc92e
AK
792 }
793
368f5035
DB
794 s->me.qpel_put = s->qdsp.put_qpel_pixels_tab;
795 s->me.qpel_avg = s->qdsp.avg_qpel_pixels_tab;
b761659b 796
578ea75a 797 if (avctx->hwaccel) {
b761659b 798 if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0)
b81a935b 799 goto err;
b761659b 800 if (avctx->hwaccel->decode_slice(avctx, buf_start, (buf + buf_size) - buf_start) < 0)
b81a935b 801 goto err;
b761659b 802 if (avctx->hwaccel->end_frame(avctx) < 0)
b81a935b 803 goto err;
b761659b 804 } else {
bb7bf175
MN
805 int header_ret = 0;
806
54974c62 807 ff_mpeg_er_frame_start(s);
b761659b
DB
808
809 v->bits = buf_size * 8;
ee769c6a 810 v->end_mb_x = s->mb_width;
cad16562 811 if (v->field_mode) {
f6774f90 812 s->current_picture.f->linesize[0] <<= 1;
813 s->current_picture.f->linesize[1] <<= 1;
814 s->current_picture.f->linesize[2] <<= 1;
50f97219
KS
815 s->linesize <<= 1;
816 s->uvlinesize <<= 1;
cad16562
MSS
817 }
818 mb_height = s->mb_height >> v->field_mode;
43bacd5b
LB
819
820 if (!mb_height) {
821 av_log(v->s.avctx, AV_LOG_ERROR, "Invalid mb_height.\n");
822 goto err;
823 }
824
f44d6445 825 for (i = 0; i <= n_slices; i++) {
cad16562 826 if (i > 0 && slices[i - 1].mby_start >= mb_height) {
1100acba
MN
827 if (v->field_mode <= 0) {
828 av_log(v->s.avctx, AV_LOG_ERROR, "Slice %d starts beyond "
829 "picture boundary (%d >= %d)\n", i,
830 slices[i - 1].mby_start, mb_height);
831 continue;
832 }
cad16562 833 v->second_field = 1;
50f97219 834 v->blocks_off = s->mb_width * s->mb_height << 1;
cad16562
MSS
835 v->mb_off = s->mb_stride * s->mb_height >> 1;
836 } else {
837 v->second_field = 0;
838 v->blocks_off = 0;
839 v->mb_off = 0;
840 }
841 if (i) {
842 v->pic_header_flag = 0;
0aa907cf 843 if (v->field_mode && i == n_slices1 + 2) {
bb7bf175 844 if ((header_ret = ff_vc1_parse_frame_header_adv(v, &s->gb)) < 0) {
0aa907cf 845 av_log(v->s.avctx, AV_LOG_ERROR, "Field header damaged\n");
23d6ba2c
MS
846 if (avctx->err_recognition & AV_EF_EXPLODE)
847 goto err;
0aa907cf
MN
848 continue;
849 }
850 } else if (get_bits1(&s->gb)) {
cad16562 851 v->pic_header_flag = 1;
bb7bf175 852 if ((header_ret = ff_vc1_parse_frame_header_adv(v, &s->gb)) < 0) {
0aa907cf 853 av_log(v->s.avctx, AV_LOG_ERROR, "Slice header damaged\n");
23d6ba2c
MS
854 if (avctx->err_recognition & AV_EF_EXPLODE)
855 goto err;
0aa907cf
MN
856 continue;
857 }
cad16562
MSS
858 }
859 }
bb7bf175
MN
860 if (header_ret < 0)
861 continue;
cad16562
MSS
862 s->start_mb_y = (i == 0) ? 0 : FFMAX(0, slices[i-1].mby_start % mb_height);
863 if (!v->field_mode || v->second_field)
864 s->end_mb_y = (i == n_slices ) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height);
865 else
510ef04a 866 s->end_mb_y = (i <= n_slices1 + 1) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height);
7627c35a 867 ff_vc1_decode_blocks(v);
cad16562
MSS
868 if (i != n_slices)
869 s->gb = slices[i].gb;
870 }
871 if (v->field_mode) {
cad16562 872 v->second_field = 0;
f6774f90 873 s->current_picture.f->linesize[0] >>= 1;
874 s->current_picture.f->linesize[1] >>= 1;
875 s->current_picture.f->linesize[2] >>= 1;
50f97219
KS
876 s->linesize >>= 1;
877 s->uvlinesize >>= 1;
93b12812
MN
878 if (v->s.pict_type != AV_PICTURE_TYPE_BI && v->s.pict_type != AV_PICTURE_TYPE_B) {
879 FFSWAP(uint8_t *, v->mv_f_next[0], v->mv_f[0]);
880 FFSWAP(uint8_t *, v->mv_f_next[1], v->mv_f[1]);
881 }
f44d6445 882 }
6a85dfc8 883 ff_dlog(s->avctx, "Consumed %i/%i bits\n",
1218777f 884 get_bits_count(&s->gb), s->gb.size_in_bits);
50f97219 885// if (get_bits_count(&s->gb) > buf_size * 8)
b761659b 886// return -1;
46430fd4
MN
887 if (!v->field_mode)
888 ff_er_frame_end(&s->er);
b761659b
DB
889 }
890
835f798c 891 ff_mpv_frame_end(s);
b761659b 892
36ef5369 893 if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
45ecda85
AD
894image:
895 avctx->width = avctx->coded_width = v->output_width;
896 avctx->height = avctx->coded_height = v->output_height;
50f97219
KS
897 if (avctx->skip_frame >= AVDISCARD_NONREF)
898 goto end;
45ecda85 899#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
50f97219
KS
900 if (vc1_decode_sprites(v, &s->gb))
901 goto err;
45ecda85 902#endif
6792559f 903 if ((ret = av_frame_ref(pict, v->sprite_output_frame)) < 0)
759001c5 904 goto err;
df9b9567 905 *got_frame = 1;
45ecda85 906 } else {
50f97219 907 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
f6774f90 908 if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0)
759001c5
AK
909 goto err;
910 ff_print_debug_info(s, s->current_picture_ptr);
de4ec972 911 *got_frame = 1;
4b1f5e50 912 } else if (s->last_picture_ptr) {
f6774f90 913 if ((ret = av_frame_ref(pict, s->last_picture_ptr->f)) < 0)
759001c5
AK
914 goto err;
915 ff_print_debug_info(s, s->last_picture_ptr);
df9b9567 916 *got_frame = 1;
50f97219 917 }
45ecda85
AD
918 }
919
b81a935b 920end:
b761659b 921 av_free(buf2);
f44d6445
RB
922 for (i = 0; i < n_slices; i++)
923 av_free(slices[i].buf);
924 av_free(slices);
b761659b 925 return buf_size;
b81a935b
RB
926
927err:
928 av_free(buf2);
f44d6445
RB
929 for (i = 0; i < n_slices; i++)
930 av_free(slices[i].buf);
931 av_free(slices);
b81a935b 932 return -1;
b761659b
DB
933}
934
935
8d061989 936static const enum AVPixelFormat vc1_hwaccel_pixfmt_list_420[] = {
654c7446 937#if CONFIG_VC1_DXVA2_HWACCEL
8d061989
RB
938 AV_PIX_FMT_DXVA2_VLD,
939#endif
d8039ef8
SL
940#if CONFIG_VC1_D3D11VA_HWACCEL
941 AV_PIX_FMT_D3D11VA_VLD,
942#endif
654c7446 943#if CONFIG_VC1_VAAPI_HWACCEL
8d061989
RB
944 AV_PIX_FMT_VAAPI_VLD,
945#endif
654c7446 946#if CONFIG_VC1_VDPAU_HWACCEL
8d061989
RB
947 AV_PIX_FMT_VDPAU,
948#endif
949 AV_PIX_FMT_YUV420P,
950 AV_PIX_FMT_NONE
951};
952
d36beb3f 953AVCodec ff_vc1_decoder = {
ec6402b7 954 .name = "vc1",
b2bed932 955 .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1"),
ec6402b7 956 .type = AVMEDIA_TYPE_VIDEO,
36ef5369 957 .id = AV_CODEC_ID_VC1,
ec6402b7
AK
958 .priv_data_size = sizeof(VC1Context),
959 .init = vc1_decode_init,
7627c35a 960 .close = ff_vc1_decode_end,
ec6402b7 961 .decode = vc1_decode_frame,
4dc8c838 962 .flush = ff_mpeg_flush,
def97856 963 .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
8d061989 964 .pix_fmts = vc1_hwaccel_pixfmt_list_420,
2c681139 965 .profiles = NULL_IF_CONFIG_SMALL(ff_vc1_profiles)
b761659b
DB
966};
967
700363af 968#if CONFIG_WMV3_DECODER
d36beb3f 969AVCodec ff_wmv3_decoder = {
ec6402b7 970 .name = "wmv3",
b2bed932 971 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9"),
ec6402b7 972 .type = AVMEDIA_TYPE_VIDEO,
36ef5369 973 .id = AV_CODEC_ID_WMV3,
ec6402b7
AK
974 .priv_data_size = sizeof(VC1Context),
975 .init = vc1_decode_init,
7627c35a 976 .close = ff_vc1_decode_end,
ec6402b7 977 .decode = vc1_decode_frame,
4dc8c838 978 .flush = ff_mpeg_flush,
def97856 979 .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
8d061989 980 .pix_fmts = vc1_hwaccel_pixfmt_list_420,
2c681139 981 .profiles = NULL_IF_CONFIG_SMALL(ff_vc1_profiles)
b761659b 982};
700363af 983#endif
b761659b 984
45ecda85
AD
985#if CONFIG_WMV3IMAGE_DECODER
986AVCodec ff_wmv3image_decoder = {
987 .name = "wmv3image",
b2bed932 988 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 Image"),
45ecda85 989 .type = AVMEDIA_TYPE_VIDEO,
36ef5369 990 .id = AV_CODEC_ID_WMV3IMAGE,
45ecda85
AD
991 .priv_data_size = sizeof(VC1Context),
992 .init = vc1_decode_init,
7627c35a 993 .close = ff_vc1_decode_end,
45ecda85 994 .decode = vc1_decode_frame,
def97856 995 .capabilities = AV_CODEC_CAP_DR1,
45ecda85 996 .flush = vc1_sprite_flush,
6f6c0294
VG
997 .pix_fmts = (const enum AVPixelFormat[]) {
998 AV_PIX_FMT_YUV420P,
999 AV_PIX_FMT_NONE
1000 },
45ecda85
AD
1001};
1002#endif
1003
1004#if CONFIG_VC1IMAGE_DECODER
1005AVCodec ff_vc1image_decoder = {
1006 .name = "vc1image",
b2bed932 1007 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 Image v2"),
45ecda85 1008 .type = AVMEDIA_TYPE_VIDEO,
36ef5369 1009 .id = AV_CODEC_ID_VC1IMAGE,
45ecda85
AD
1010 .priv_data_size = sizeof(VC1Context),
1011 .init = vc1_decode_init,
7627c35a 1012 .close = ff_vc1_decode_end,
45ecda85 1013 .decode = vc1_decode_frame,
def97856 1014 .capabilities = AV_CODEC_CAP_DR1,
45ecda85 1015 .flush = vc1_sprite_flush,
6f6c0294
VG
1016 .pix_fmts = (const enum AVPixelFormat[]) {
1017 AV_PIX_FMT_YUV420P,
1018 AV_PIX_FMT_NONE
1019 },
45ecda85
AD
1020};
1021#endif