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