vc1dec.c 38.2 KB
Newer Older
1 2
/*
 * VC-1 and WMV3 decoder
3
 * Copyright (c) 2011 Mashiat Sarker Shakkhar
4 5 6
 * Copyright (c) 2006-2007 Konstantin Shishkov
 * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
 *
7
 * This file is part of Libav.
8
 *
9
 * Libav is free software; you can redistribute it and/or
10 11 12 13
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
14
 * Libav is distributed in the hope that it will be useful,
15 16 17 18 19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with Libav; if not, write to the Free Software
21 22 23 24
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

/**
25
 * @file
26 27
 * VC-1 and WMV3 decoder
 */
28

29
#include "avcodec.h"
30 31 32
#include "blockdsp.h"
#include "get_bits.h"
#include "internal.h"
33
#include "mpeg_er.h"
34
#include "mpegvideo.h"
35
#include "msmpeg4.h"
36
#include "msmpeg4data.h"
37
#include "profiles.h"
38 39 40
#include "vc1.h"
#include "vc1data.h"

41 42
#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER

43
typedef struct SpriteData {
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    /**
     * Transform coefficients for both sprites in 16.16 fixed point format,
     * in the order they appear in the bitstream:
     *  x scale
     *  rotation 1 (unused)
     *  x offset
     *  rotation 2 (unused)
     *  y scale
     *  y offset
     *  alpha
     */
    int coefs[2][7];

    int effect_type, effect_flag;
    int effect_pcount1, effect_pcount2;   ///< amount of effect parameters stored in effect_params
    int effect_params1[15], effect_params2[10]; ///< effect parameters in 16.16 fixed point format
} SpriteData;

static inline int get_fp_val(GetBitContext* gb)
63
{
64
    return (get_bits_long(gb, 30) - (1 << 29)) << 1;
65 66
}

67
static void vc1_sprite_parse_transform(GetBitContext* gb, int c[7])
68
{
69
    c[1] = c[3] = 0;
70 71 72

    switch (get_bits(gb, 2)) {
    case 0:
73
        c[0] = 1 << 16;
74
        c[2] = get_fp_val(gb);
75
        c[4] = 1 << 16;
76 77
        break;
    case 1:
78 79
        c[0] = c[4] = get_fp_val(gb);
        c[2] = get_fp_val(gb);
80 81
        break;
    case 2:
82 83 84
        c[0] = get_fp_val(gb);
        c[2] = get_fp_val(gb);
        c[4] = get_fp_val(gb);
85 86
        break;
    case 3:
87 88 89 90 91
        c[0] = get_fp_val(gb);
        c[1] = get_fp_val(gb);
        c[2] = get_fp_val(gb);
        c[3] = get_fp_val(gb);
        c[4] = get_fp_val(gb);
92 93
        break;
    }
94
    c[5] = get_fp_val(gb);
95
    if (get_bits1(gb))
96
        c[6] = get_fp_val(gb);
97
    else
98
        c[6] = 1 << 16;
99 100
}

101
static void vc1_parse_sprites(VC1Context *v, GetBitContext* gb, SpriteData* sd)
102
{
103 104 105 106 107 108
    AVCodecContext *avctx = v->s.avctx;
    int sprite, i;

    for (sprite = 0; sprite <= v->two_sprites; sprite++) {
        vc1_sprite_parse_transform(gb, sd->coefs[sprite]);
        if (sd->coefs[sprite][1] || sd->coefs[sprite][3])
109
            avpriv_request_sample(avctx, "Non-zero rotation coefficients");
110
        av_log(avctx, AV_LOG_DEBUG, sprite ? "S2:" : "S1:");
111
        for (i = 0; i < 7; i++)
112 113
            av_log(avctx, AV_LOG_DEBUG, " %d.%.3d",
                   sd->coefs[sprite][i] / (1<<16),
114
                   (abs(sd->coefs[sprite][i]) & 0xFFFF) * 1000 / (1 << 16));
115
        av_log(avctx, AV_LOG_DEBUG, "\n");
116
    }
117

118
    skip_bits(gb, 2);
119 120
    if (sd->effect_type = get_bits_long(gb, 30)) {
        switch (sd->effect_pcount1 = get_bits(gb, 4)) {
121
        case 7:
122
            vc1_sprite_parse_transform(gb, sd->effect_params1);
123 124
            break;
        case 14:
125 126
            vc1_sprite_parse_transform(gb, sd->effect_params1);
            vc1_sprite_parse_transform(gb, sd->effect_params1 + 7);
127 128
            break;
        default:
129 130
            for (i = 0; i < sd->effect_pcount1; i++)
                sd->effect_params1[i] = get_fp_val(gb);
131
        }
132
        if (sd->effect_type != 13 || sd->effect_params1[0] != sd->coefs[0][6]) {
133
            // effect 13 is simple alpha blending and matches the opacity above
134 135 136
            av_log(avctx, AV_LOG_DEBUG, "Effect: %d; params: ", sd->effect_type);
            for (i = 0; i < sd->effect_pcount1; i++)
                av_log(avctx, AV_LOG_DEBUG, " %d.%.2d",
137 138
                       sd->effect_params1[i] / (1 << 16),
                       (abs(sd->effect_params1[i]) & 0xFFFF) * 1000 / (1 << 16));
139
            av_log(avctx, AV_LOG_DEBUG, "\n");
140 141
        }

142 143 144
        sd->effect_pcount2 = get_bits(gb, 16);
        if (sd->effect_pcount2 > 10) {
            av_log(avctx, AV_LOG_ERROR, "Too many effect parameters\n");
145
            return;
146 147 148
        } else if (sd->effect_pcount2) {
            i = -1;
            av_log(avctx, AV_LOG_DEBUG, "Effect params 2: ");
149
            while (++i < sd->effect_pcount2) {
150 151
                sd->effect_params2[i] = get_fp_val(gb);
                av_log(avctx, AV_LOG_DEBUG, " %d.%.2d",
152 153
                       sd->effect_params2[i] / (1 << 16),
                       (abs(sd->effect_params2[i]) & 0xFFFF) * 1000 / (1 << 16));
154
            }
155
            av_log(avctx, AV_LOG_DEBUG, "\n");
156 157
        }
    }
158 159
    if (sd->effect_flag = get_bits1(gb))
        av_log(avctx, AV_LOG_DEBUG, "Effect flag set\n");
160 161

    if (get_bits_count(gb) >= gb->size_in_bits +
162
       (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE ? 64 : 0))
163
        av_log(avctx, AV_LOG_ERROR, "Buffer overrun\n");
164
    if (get_bits_count(gb) < gb->size_in_bits - 8)
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
        av_log(avctx, AV_LOG_WARNING, "Buffer not fully read\n");
}

static void vc1_draw_sprites(VC1Context *v, SpriteData* sd)
{
    int i, plane, row, sprite;
    int sr_cache[2][2] = { { -1, -1 }, { -1, -1 } };
    uint8_t* src_h[2][2];
    int xoff[2], xadv[2], yoff[2], yadv[2], alpha;
    int ysub[2];
    MpegEncContext *s = &v->s;

    for (i = 0; i < 2; i++) {
        xoff[i] = av_clip(sd->coefs[i][2], 0, v->sprite_width-1 << 16);
        xadv[i] = sd->coefs[i][0];
180
        if (xadv[i] != 1<<16 || (v->sprite_width << 16) - (v->output_width << 16) - xoff[i])
181 182 183
            xadv[i] = av_clip(xadv[i], 0, ((v->sprite_width<<16) - xoff[i] - 1) / v->output_width);

        yoff[i] = av_clip(sd->coefs[i][5], 0, v->sprite_height-1 << 16);
184
        yadv[i] = av_clip(sd->coefs[i][4], 0, ((v->sprite_height << 16) - yoff[i]) / v->output_height);
185
    }
186
    alpha = av_clip_uint16(sd->coefs[1][6]);
187

188
    for (plane = 0; plane < (s->avctx->flags & AV_CODEC_FLAG_GRAY ? 1 : 3); plane++) {
189 190 191
        int width = v->output_width>>!!plane;

        for (row = 0; row < v->output_height>>!!plane; row++) {
192 193
            uint8_t *dst = v->sprite_output_frame->data[plane] +
                           v->sprite_output_frame->linesize[plane] * row;
194 195

            for (sprite = 0; sprite <= v->two_sprites; sprite++) {
196 197
                uint8_t *iplane = s->current_picture.f->data[plane];
                int      iline  = s->current_picture.f->linesize[plane];
198 199
                int      ycoord = yoff[sprite] + yadv[sprite] * row;
                int      yline  = ycoord >> 16;
200
                int      next_line;
201
                ysub[sprite] = ycoord & 0xFFFF;
202
                if (sprite) {
203 204
                    iplane = s->last_picture.f->data[plane];
                    iline  = s->last_picture.f->linesize[plane];
205
                }
206
                next_line = FFMIN(yline + 1, (v->sprite_height >> !!plane) - 1) * iline;
207 208
                if (!(xoff[sprite] & 0xFFFF) && xadv[sprite] == 1 << 16) {
                        src_h[sprite][0] = iplane + (xoff[sprite] >> 16) +  yline      * iline;
209
                    if (ysub[sprite])
210
                        src_h[sprite][1] = iplane + (xoff[sprite] >> 16) + next_line;
211 212 213 214 215 216
                } else {
                    if (sr_cache[sprite][0] != yline) {
                        if (sr_cache[sprite][1] == yline) {
                            FFSWAP(uint8_t*, v->sr_rows[sprite][0], v->sr_rows[sprite][1]);
                            FFSWAP(int,        sr_cache[sprite][0],   sr_cache[sprite][1]);
                        } else {
217
                            v->vc1dsp.sprite_h(v->sr_rows[sprite][0], iplane + yline * iline, xoff[sprite], xadv[sprite], width);
218 219 220 221
                            sr_cache[sprite][0] = yline;
                        }
                    }
                    if (ysub[sprite] && sr_cache[sprite][1] != yline + 1) {
222 223 224
                        v->vc1dsp.sprite_h(v->sr_rows[sprite][1],
                                           iplane + next_line, xoff[sprite],
                                           xadv[sprite], width);
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
                        sr_cache[sprite][1] = yline + 1;
                    }
                    src_h[sprite][0] = v->sr_rows[sprite][0];
                    src_h[sprite][1] = v->sr_rows[sprite][1];
                }
            }

            if (!v->two_sprites) {
                if (ysub[0]) {
                    v->vc1dsp.sprite_v_single(dst, src_h[0][0], src_h[0][1], ysub[0], width);
                } else {
                    memcpy(dst, src_h[0][0], width);
                }
            } else {
                if (ysub[0] && ysub[1]) {
                    v->vc1dsp.sprite_v_double_twoscale(dst, src_h[0][0], src_h[0][1], ysub[0],
                                                       src_h[1][0], src_h[1][1], ysub[1], alpha, width);
                } else if (ysub[0]) {
                    v->vc1dsp.sprite_v_double_onescale(dst, src_h[0][0], src_h[0][1], ysub[0],
                                                       src_h[1][0], alpha, width);
                } else if (ysub[1]) {
                    v->vc1dsp.sprite_v_double_onescale(dst, src_h[1][0], src_h[1][1], ysub[1],
                                                       src_h[0][0], (1<<16)-1-alpha, width);
                } else {
                    v->vc1dsp.sprite_v_double_noscale(dst, src_h[0][0], src_h[1][0], alpha, width);
                }
            }
        }

        if (!plane) {
            for (i = 0; i < 2; i++) {
                xoff[i] >>= 1;
                yoff[i] >>= 1;
            }
        }

    }
}


static int vc1_decode_sprites(VC1Context *v, GetBitContext* gb)
{
267
    MpegEncContext *s     = &v->s;
268 269 270 271 272
    AVCodecContext *avctx = s->avctx;
    SpriteData sd;

    vc1_parse_sprites(v, gb, &sd);

273
    if (!s->current_picture.f->data[0]) {
274 275 276 277
        av_log(avctx, AV_LOG_ERROR, "Got no sprites\n");
        return -1;
    }

278
    if (v->two_sprites && (!s->last_picture_ptr || !s->last_picture.f->data[0])) {
279 280 281 282
        av_log(avctx, AV_LOG_WARNING, "Need two sprites, only got one\n");
        v->two_sprites = 0;
    }

283 284
    av_frame_unref(v->sprite_output_frame);
    if (ff_get_buffer(avctx, v->sprite_output_frame, 0) < 0) {
285 286 287 288 289 290 291 292 293 294 295
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
        return -1;
    }

    vc1_draw_sprites(v, &sd);

    return 0;
}

static void vc1_sprite_flush(AVCodecContext *avctx)
{
296
    VC1Context *v     = avctx->priv_data;
297
    MpegEncContext *s = &v->s;
298
    AVFrame *f = s->current_picture.f;
299 300 301 302 303 304
    int plane, i;

    /* Windows Media Image codecs have a convergence interval of two keyframes.
       Since we can't enforce it, clear to black the missing sprite. This is
       wrong but it looks better than doing nothing. */

305
    if (f && f->data[0])
306
        for (plane = 0; plane < (s->avctx->flags & AV_CODEC_FLAG_GRAY ? 1 : 3); plane++)
307
            for (i = 0; i < v->sprite_height>>!!plane; i++)
308
                memset(f->data[plane] + i * f->linesize[plane],
309
                       plane ? 128 : 0, f->linesize[plane]);
310 311
}

312 313
#endif

314
av_cold int ff_vc1_decode_init_alloc_tables(VC1Context *v)
315 316
{
    MpegEncContext *s = &v->s;
317
    int i, ret = AVERROR(ENOMEM);
318
    int mb_height = FFALIGN(s->mb_height, 2);
319 320

    /* Allocate mb bitplanes */
321 322 323 324 325 326
    v->mv_type_mb_plane = av_malloc (s->mb_stride * mb_height);
    v->direct_mb_plane  = av_malloc (s->mb_stride * mb_height);
    v->forward_mb_plane = av_malloc (s->mb_stride * mb_height);
    v->fieldtx_plane    = av_mallocz(s->mb_stride * mb_height);
    v->acpred_plane     = av_malloc (s->mb_stride * mb_height);
    v->over_flags_plane = av_malloc (s->mb_stride * mb_height);
327 328 329
    if (!v->mv_type_mb_plane || !v->direct_mb_plane || !v->forward_mb_plane ||
        !v->fieldtx_plane || !v->acpred_plane || !v->over_flags_plane)
        goto error;
330 331

    v->n_allocated_blks = s->mb_width + 2;
332 333
    v->block            = av_malloc(sizeof(*v->block) * v->n_allocated_blks);
    v->cbp_base         = av_malloc(sizeof(v->cbp_base[0]) * 2 * s->mb_stride);
334 335
    if (!v->block || !v->cbp_base)
        goto error;
336 337
    v->cbp              = v->cbp_base + s->mb_stride;
    v->ttblk_base       = av_malloc(sizeof(v->ttblk_base[0]) * 2 * s->mb_stride);
338 339
    if (!v->ttblk_base)
        goto error;
340 341
    v->ttblk            = v->ttblk_base + s->mb_stride;
    v->is_intra_base    = av_mallocz(sizeof(v->is_intra_base[0]) * 2 * s->mb_stride);
342 343
    if (!v->is_intra_base)
        goto error;
344 345
    v->is_intra         = v->is_intra_base + s->mb_stride;
    v->luma_mv_base     = av_malloc(sizeof(v->luma_mv_base[0]) * 2 * s->mb_stride);
346 347
    if (!v->luma_mv_base)
        goto error;
348
    v->luma_mv          = v->luma_mv_base + s->mb_stride;
349 350

    /* allocate block type info in that way so it could be used with s->block_index[] */
351
    v->mb_type_base = av_malloc(s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
352 353
    if (!v->mb_type_base)
        goto error;
354
    v->mb_type[0]   = v->mb_type_base + s->b8_stride + 1;
355 356
    v->mb_type[1]   = v->mb_type_base + s->b8_stride * (mb_height * 2 + 1) + s->mb_stride + 1;
    v->mb_type[2]   = v->mb_type[1] + s->mb_stride * (mb_height + 1);
357

358
    /* allocate memory to store block level MV info */
359
    v->blk_mv_type_base = av_mallocz(     s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
360 361
    if (!v->blk_mv_type_base)
        goto error;
362
    v->blk_mv_type      = v->blk_mv_type_base + s->b8_stride + 1;
363
    v->mv_f_base        = av_mallocz(2 * (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2));
364 365
    if (!v->mv_f_base)
        goto error;
366
    v->mv_f[0]          = v->mv_f_base + s->b8_stride + 1;
367 368
    v->mv_f[1]          = v->mv_f[0] + (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
    v->mv_f_next_base   = av_mallocz(2 * (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2));
369 370
    if (!v->mv_f_next_base)
        goto error;
371
    v->mv_f_next[0]     = v->mv_f_next_base + s->b8_stride + 1;
372
    v->mv_f_next[1]     = v->mv_f_next[0] + (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
373

374
    if (s->avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || s->avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
375 376 377 378 379
        for (i = 0; i < 4; i++) {
            v->sr_rows[i >> 1][i & 1] = av_malloc(v->output_width);
            if (!v->sr_rows[i >> 1][i & 1])
                goto error;
        }
380 381
    }

382
    ret = ff_intrax8_common_init(s->avctx, &v->x8, &s->idsp,
383
                                 s->block, s->block_last_index,
384
                                 s->mb_width, s->mb_height);
385 386 387
    if (ret < 0)
        goto error;

388
    return 0;
389 390 391

error:
    ff_vc1_decode_end(s->avctx);
392
    return ret;
393 394
}

395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
av_cold void ff_vc1_init_transposed_scantables(VC1Context *v)
{
    int i;
    for (i = 0; i < 64; i++) {
#define transpose(x) ((x >> 3) | ((x & 7) << 3))
        v->zz_8x8[0][i] = transpose(ff_wmv1_scantable[0][i]);
        v->zz_8x8[1][i] = transpose(ff_wmv1_scantable[1][i]);
        v->zz_8x8[2][i] = transpose(ff_wmv1_scantable[2][i]);
        v->zz_8x8[3][i] = transpose(ff_wmv1_scantable[3][i]);
        v->zzi_8x8[i]   = transpose(ff_vc1_adv_interlaced_8x8_zz[i]);
    }
    v->left_blk_sh = 0;
    v->top_blk_sh  = 3;
}

410 411
/** Initialize a VC1/WMV3 decoder
 * @todo TODO: Handle VC-1 IDUs (Transport level?)
412
 * @todo TODO: Decipher remaining bits in extra_data
413 414 415 416 417 418 419
 */
static av_cold int vc1_decode_init(AVCodecContext *avctx)
{
    VC1Context *v = avctx->priv_data;
    MpegEncContext *s = &v->s;
    GetBitContext gb;

420 421 422 423
    /* save the container output size for WMImage */
    v->output_width  = avctx->width;
    v->output_height = avctx->height;

424 425
    if (!avctx->extradata_size || !avctx->extradata)
        return -1;
426
    if (!(avctx->flags & AV_CODEC_FLAG_GRAY))
427
        avctx->pix_fmt = ff_get_format(avctx, avctx->codec->pix_fmts);
428
    else
429
        avctx->pix_fmt = AV_PIX_FMT_GRAY8;
430 431
    v->s.avctx = avctx;

432
    if (ff_vc1_init_common(v) < 0)
433
        return -1;
434
    ff_blockdsp_init(&s->bdsp, avctx);
435
    ff_h264chroma_init(&v->h264chroma, 8);
436
    ff_qpeldsp_init(&s->qdsp);
437

438
    if (avctx->codec_id == AV_CODEC_ID_WMV3 || avctx->codec_id == AV_CODEC_ID_WMV3IMAGE) {
439 440 441 442 443 444 445 446 447
        int count = 0;

        // looks like WMV3 has a sequence header stored in the extradata
        // advanced sequence header may be before the first frame
        // the last byte of the extradata is a version number, 1 for the
        // samples we can decode

        init_get_bits(&gb, avctx->extradata, avctx->extradata_size*8);

448
        if (ff_vc1_decode_sequence_header(avctx, v, &gb) < 0)
449 450 451
          return -1;

        count = avctx->extradata_size*8 - get_bits_count(&gb);
452
        if (count > 0) {
453
            av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n",
454
                   count, get_bits_long(&gb, FFMIN(count, 32)));
455
        } else if (count < 0) {
456 457
            av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count);
        }
458
    } else { // VC1/WVC1/WVP2
459 460 461 462 463 464 465
        const uint8_t *start = avctx->extradata;
        uint8_t *end = avctx->extradata + avctx->extradata_size;
        const uint8_t *next;
        int size, buf2_size;
        uint8_t *buf2 = NULL;
        int seq_initialized = 0, ep_initialized = 0;

466
        if (avctx->extradata_size < 16) {
467 468 469 470
            av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", avctx->extradata_size);
            return -1;
        }

471
        buf2  = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
472
        start = find_next_marker(start, end); // in WVC1 extradata first byte is its size, but can be 0 in mkv
473 474
        next  = start;
        for (; next < end; start = next) {
475 476
            next = find_next_marker(start + 4, end);
            size = next - start - 4;
477 478
            if (size <= 0)
                continue;
479 480
            buf2_size = vc1_unescape_buffer(start + 4, size, buf2);
            init_get_bits(&gb, buf2, buf2_size * 8);
481
            switch (AV_RB32(start)) {
482
            case VC1_CODE_SEQHDR:
483
                if (ff_vc1_decode_sequence_header(avctx, v, &gb) < 0) {
484 485 486 487 488 489
                    av_free(buf2);
                    return -1;
                }
                seq_initialized = 1;
                break;
            case VC1_CODE_ENTRYPOINT:
490
                if (ff_vc1_decode_entry_point(avctx, v, &gb) < 0) {
491 492 493 494 495 496 497 498
                    av_free(buf2);
                    return -1;
                }
                ep_initialized = 1;
                break;
            }
        }
        av_free(buf2);
499
        if (!seq_initialized || !ep_initialized) {
500 501 502
            av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n");
            return -1;
        }
503
        v->res_sprite = (avctx->codec_id == AV_CODEC_ID_VC1IMAGE);
504
    }
505

506 507 508 509
    v->sprite_output_frame = av_frame_alloc();
    if (!v->sprite_output_frame)
        return AVERROR(ENOMEM);

510 511 512 513
    avctx->profile = v->profile;
    if (v->profile == PROFILE_ADVANCED)
        avctx->level = v->level;

514
    avctx->has_b_frames = !!avctx->max_b_frames;
515

516 517 518 519 520 521 522
    if (v->color_prim == 1 || v->color_prim == 5 || v->color_prim == 6)
        avctx->color_primaries = v->color_prim;
    if (v->transfer_char == 1 || v->transfer_char == 7)
        avctx->color_trc = v->transfer_char;
    if (v->matrix_coef == 1 || v->matrix_coef == 6 || v->matrix_coef == 7)
        avctx->colorspace = v->matrix_coef;

523 524
    s->mb_width  = (avctx->coded_width  + 15) >> 4;
    s->mb_height = (avctx->coded_height + 15) >> 4;
525

526
    if (v->profile == PROFILE_ADVANCED || v->res_fasttx) {
527
        ff_vc1_init_transposed_scantables(v);
528
    } else {
529
        memcpy(v->zz_8x8, ff_wmv1_scantable, 4*64);
530 531 532 533
        v->left_blk_sh = 3;
        v->top_blk_sh  = 0;
    }

534
    if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
535 536 537 538 539 540 541
        v->sprite_width  = avctx->coded_width;
        v->sprite_height = avctx->coded_height;

        avctx->coded_width  = avctx->width  = v->output_width;
        avctx->coded_height = avctx->height = v->output_height;

        // prevent 16.16 overflows
542 543 544 545
        if (v->sprite_width  > 1 << 14 ||
            v->sprite_height > 1 << 14 ||
            v->output_width  > 1 << 14 ||
            v->output_height > 1 << 14) return -1;
546
    }
547 548 549
    return 0;
}

550 551 552
/** Close a VC1/WMV3 decoder
 * @warning Initial try at using MpegEncContext stuff
 */
553
av_cold int ff_vc1_decode_end(AVCodecContext *avctx)
554 555 556 557
{
    VC1Context *v = avctx->priv_data;
    int i;

558
    av_frame_free(&v->sprite_output_frame);
559

560
    for (i = 0; i < 4; i++)
561
        av_freep(&v->sr_rows[i >> 1][i & 1]);
562 563
    av_freep(&v->hrd_rate);
    av_freep(&v->hrd_buffer);
564
    ff_mpv_common_end(&v->s);
565 566
    av_freep(&v->mv_type_mb_plane);
    av_freep(&v->direct_mb_plane);
567 568
    av_freep(&v->forward_mb_plane);
    av_freep(&v->fieldtx_plane);
569 570 571
    av_freep(&v->acpred_plane);
    av_freep(&v->over_flags_plane);
    av_freep(&v->mb_type_base);
572 573 574
    av_freep(&v->blk_mv_type_base);
    av_freep(&v->mv_f_base);
    av_freep(&v->mv_f_next_base);
575 576 577 578 579 580 581 582 583
    av_freep(&v->block);
    av_freep(&v->cbp_base);
    av_freep(&v->ttblk_base);
    av_freep(&v->is_intra_base); // FIXME use v->mb_type[]
    av_freep(&v->luma_mv_base);
    ff_intrax8_common_end(&v->x8);
    return 0;
}

584 585 586 587

/** Decode a VC1/WMV3 frame
 * @todo TODO: Handle VC-1 IDUs (Transport level?)
 */
588
static int vc1_decode_frame(AVCodecContext *avctx, void *data,
589
                            int *got_frame, AVPacket *avpkt)
590 591
{
    const uint8_t *buf = avpkt->data;
592
    int buf_size = avpkt->size, n_slices = 0, i, ret;
593 594 595 596 597
    VC1Context *v = avctx->priv_data;
    MpegEncContext *s = &v->s;
    AVFrame *pict = data;
    uint8_t *buf2 = NULL;
    const uint8_t *buf_start = buf;
598
    int mb_height, n_slices1;
Ronald S. Bultje's avatar
Ronald S. Bultje committed
599 600 601 602
    struct {
        uint8_t *buf;
        GetBitContext gb;
        int mby_start;
603
    } *slices = NULL, *tmp;
604 605

    /* no supplementary picture */
606
    if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == VC1_CODE_ENDOFSEQ)) {
607
        /* special case for last picture */
608
        if (s->low_delay == 0 && s->next_picture_ptr) {
609
            if ((ret = av_frame_ref(pict, s->next_picture_ptr->f)) < 0)
610
                return ret;
611
            s->next_picture_ptr = NULL;
612

613
            *got_frame = 1;
614 615 616 617 618 619
        }

        return 0;
    }

    //for advanced profile we may need to parse and unescape data
620
    if (avctx->codec_id == AV_CODEC_ID_VC1 || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
621
        int buf_size2 = 0;
622
        buf2 = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
623

624
        if (IS_MARKER(AV_RB32(buf))) { /* frame starts with marker and needs to be parsed */
625 626 627 628
            const uint8_t *start, *end, *next;
            int size;

            next = buf;
629
            for (start = buf, end = buf + buf_size; next < end; start = next) {
630 631
                next = find_next_marker(start + 4, end);
                size = next - start - 4;
632 633
                if (size <= 0) continue;
                switch (AV_RB32(start)) {
634
                case VC1_CODE_FRAME:
635
                    if (avctx->hwaccel)
636 637 638
                        buf_start = start;
                    buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
                    break;
639 640
                case VC1_CODE_FIELD: {
                    int buf_size3;
641 642
                    tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1));
                    if (!tmp)
643
                        goto err;
644
                    slices = tmp;
645
                    slices[n_slices].buf = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
646 647
                    if (!slices[n_slices].buf)
                        goto err;
648 649 650 651 652 653 654 655 656 657 658
                    buf_size3 = vc1_unescape_buffer(start + 4, size,
                                                    slices[n_slices].buf);
                    init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
                                  buf_size3 << 3);
                    /* assuming that the field marker is at the exact middle,
                       hope it's correct */
                    slices[n_slices].mby_start = s->mb_height >> 1;
                    n_slices1 = n_slices - 1; // index of the last slice of the first field
                    n_slices++;
                    break;
                }
659 660
                case VC1_CODE_ENTRYPOINT: /* it should be before frame data */
                    buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
661
                    init_get_bits(&s->gb, buf2, buf_size2 * 8);
662
                    ff_vc1_decode_entry_point(avctx, v, &s->gb);
663
                    break;
Ronald S. Bultje's avatar
Ronald S. Bultje committed
664 665
                case VC1_CODE_SLICE: {
                    int buf_size3;
666 667
                    tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1));
                    if (!tmp)
668
                        goto err;
669
                    slices = tmp;
670
                    slices[n_slices].buf = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
671 672
                    if (!slices[n_slices].buf)
                        goto err;
Ronald S. Bultje's avatar
Ronald S. Bultje committed
673 674 675 676 677 678 679 680
                    buf_size3 = vc1_unescape_buffer(start + 4, size,
                                                    slices[n_slices].buf);
                    init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
                                  buf_size3 << 3);
                    slices[n_slices].mby_start = get_bits(&slices[n_slices].gb, 9);
                    n_slices++;
                    break;
                }
681 682
                }
            }
683
        } else if (v->interlace && ((buf[0] & 0xC0) == 0xC0)) { /* WVC1 interlaced stores both fields divided by marker */
684
            const uint8_t *divider;
685
            int buf_size3;
686 687

            divider = find_next_marker(buf, buf + buf_size);
688
            if ((divider == (buf + buf_size)) || AV_RB32(divider) != VC1_CODE_FIELD) {
689
                av_log(avctx, AV_LOG_ERROR, "Error in WVC1 interlaced frame\n");
690
                goto err;
691
            } else { // found field marker, unescape second field
692 693 694 695
                tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1));
                if (!tmp)
                    goto err;
                slices = tmp;
696
                slices[n_slices].buf = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
697 698 699 700 701 702 703 704
                if (!slices[n_slices].buf)
                    goto err;
                buf_size3 = vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf);
                init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
                              buf_size3 << 3);
                slices[n_slices].mby_start = s->mb_height >> 1;
                n_slices1 = n_slices - 1;
                n_slices++;
705 706
            }
            buf_size2 = vc1_unescape_buffer(buf, divider - buf, buf2);
707
        } else {
708 709 710 711 712
            buf_size2 = vc1_unescape_buffer(buf, buf_size, buf2);
        }
        init_get_bits(&s->gb, buf2, buf_size2*8);
    } else
        init_get_bits(&s->gb, buf, buf_size*8);
713 714

    if (v->res_sprite) {
715 716
        v->new_sprite  = !get_bits1(&s->gb);
        v->two_sprites =  get_bits1(&s->gb);
717
        /* res_sprite means a Windows Media Image stream, AV_CODEC_ID_*IMAGE means
718 719 720
           we're using the sprite compositor. These are intentionally kept separate
           so you can get the raw sprites by using the wmv3 decoder for WMVP or
           the vc1 one for WVP2 */
721
        if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
722 723 724 725 726 727 728 729
            if (v->new_sprite) {
                // switch AVCodecContext parameters to those of the sprites
                avctx->width  = avctx->coded_width  = v->sprite_width;
                avctx->height = avctx->coded_height = v->sprite_height;
            } else {
                goto image;
            }
        }
730 731
    }

732 733 734
    if (s->context_initialized &&
        (s->width  != avctx->coded_width ||
         s->height != avctx->coded_height)) {
735
        ff_vc1_decode_end(avctx);
736 737 738
    }

    if (!s->context_initialized) {
739
        if (ff_msmpeg4_decode_init(avctx) < 0)
740
            goto err;
741
        if (ff_vc1_decode_init_alloc_tables(v) < 0) {
742
            ff_mpv_common_end(s);
743 744
            goto err;
        }
745 746 747 748 749 750 751 752 753

        s->low_delay = !avctx->has_b_frames || v->res_sprite;

        if (v->profile == PROFILE_ADVANCED) {
            s->h_edge_pos = avctx->coded_width;
            s->v_edge_pos = avctx->coded_height;
        }
    }

754
    // do parse frame header
755
    v->pic_header_flag = 0;
756
    v->first_pic_header_flag = 1;
757
    if (v->profile < PROFILE_ADVANCED) {
758
        if (ff_vc1_parse_frame_header(v, &s->gb) < 0) {
759
            goto err;
760 761
        }
    } else {
762
        if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
763
            goto err;
764 765
        }
    }
766
    v->first_pic_header_flag = 0;
767

768
    if ((avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE)
769
        && s->pict_type != AV_PICTURE_TYPE_I) {
770 771
        av_log(v->s.avctx, AV_LOG_ERROR, "Sprite decoder: expected I-frame\n");
        goto err;
772 773
    }

774
    // for skipping the frame
775 776
    s->current_picture.f->pict_type = s->pict_type;
    s->current_picture.f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
777 778

    /* skip B-frames if we don't have reference frames */
779
    if (!s->last_picture_ptr && (s->pict_type == AV_PICTURE_TYPE_B || s->droppable)) {
780
        goto end;
781
    }
782 783 784
    if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||
        (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) ||
         avctx->skip_frame >= AVDISCARD_ALL) {
785
        goto end;
786 787
    }

788 789
    if (s->next_p_frame_damaged) {
        if (s->pict_type == AV_PICTURE_TYPE_B)
790
            goto end;
791
        else
792
            s->next_p_frame_damaged = 0;
793 794
    }

795
    if (ff_mpv_frame_start(s, avctx) < 0) {
796
        goto err;
797 798
    }

799
    // process pulldown flags
800
    s->current_picture_ptr->f->repeat_pict = 0;
801 802 803 804
    // Pulldown flags are only valid when 'broadcast' has been set.
    // So ticks_per_frame will be 2
    if (v->rff) {
        // repeat field
805
        s->current_picture_ptr->f->repeat_pict = 1;
806 807
    } else if (v->rptfrm) {
        // repeat frames
808
        s->current_picture_ptr->f->repeat_pict = v->rptfrm * 2;
809 810
    }

811 812
    s->me.qpel_put = s->qdsp.put_qpel_pixels_tab;
    s->me.qpel_avg = s->qdsp.avg_qpel_pixels_tab;
813

814
    if (avctx->hwaccel) {
815
        if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0)
816
            goto err;
817
        if (avctx->hwaccel->decode_slice(avctx, buf_start, (buf + buf_size) - buf_start) < 0)
818
            goto err;
819
        if (avctx->hwaccel->end_frame(avctx) < 0)
820
            goto err;
821
    } else {
822 823
        int header_ret = 0;

824
        ff_mpeg_er_frame_start(s);
825 826

        v->bits = buf_size * 8;
Alberto Delmás's avatar
Alberto Delmás committed
827
        v->end_mb_x = s->mb_width;
828
        if (v->field_mode) {
829 830 831
            s->current_picture.f->linesize[0] <<= 1;
            s->current_picture.f->linesize[1] <<= 1;
            s->current_picture.f->linesize[2] <<= 1;
832 833
            s->linesize                      <<= 1;
            s->uvlinesize                    <<= 1;
834 835
        }
        mb_height = s->mb_height >> v->field_mode;
836 837 838 839 840 841

        if (!mb_height) {
            av_log(v->s.avctx, AV_LOG_ERROR, "Invalid mb_height.\n");
            goto err;
        }

Ronald S. Bultje's avatar
Ronald S. Bultje committed
842
        for (i = 0; i <= n_slices; i++) {
843
            if (i > 0 &&  slices[i - 1].mby_start >= mb_height) {
844 845 846 847 848 849
                if (v->field_mode <= 0) {
                    av_log(v->s.avctx, AV_LOG_ERROR, "Slice %d starts beyond "
                           "picture boundary (%d >= %d)\n", i,
                           slices[i - 1].mby_start, mb_height);
                    continue;
                }
850
                v->second_field = 1;
851
                v->blocks_off   = s->mb_width  * s->mb_height << 1;
852 853 854 855 856 857 858 859
                v->mb_off       = s->mb_stride * s->mb_height >> 1;
            } else {
                v->second_field = 0;
                v->blocks_off   = 0;
                v->mb_off       = 0;
            }
            if (i) {
                v->pic_header_flag = 0;
860
                if (v->field_mode && i == n_slices1 + 2) {
861
                    if ((header_ret = ff_vc1_parse_frame_header_adv(v, &s->gb)) < 0) {
862
                        av_log(v->s.avctx, AV_LOG_ERROR, "Field header damaged\n");
863 864
                        if (avctx->err_recognition & AV_EF_EXPLODE)
                            goto err;
865 866 867
                        continue;
                    }
                } else if (get_bits1(&s->gb)) {
868
                    v->pic_header_flag = 1;
869
                    if ((header_ret = ff_vc1_parse_frame_header_adv(v, &s->gb)) < 0) {
870
                        av_log(v->s.avctx, AV_LOG_ERROR, "Slice header damaged\n");
871 872
                        if (avctx->err_recognition & AV_EF_EXPLODE)
                            goto err;
873 874
                        continue;
                    }
875 876
                }
            }
877 878
            if (header_ret < 0)
                continue;
879 880 881 882
            s->start_mb_y = (i == 0) ? 0 : FFMAX(0, slices[i-1].mby_start % mb_height);
            if (!v->field_mode || v->second_field)
                s->end_mb_y = (i == n_slices     ) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height);
            else
883
                s->end_mb_y = (i <= n_slices1 + 1) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height);
884 885 886 887 888 889

            if (s->end_mb_y <= s->start_mb_y) {
                av_log(v->s.avctx, AV_LOG_ERROR, "Invalid slice size\n");
                goto err;
            }

890
            ff_vc1_decode_blocks(v);
891 892 893 894 895
            if (i != n_slices)
                s->gb = slices[i].gb;
        }
        if (v->field_mode) {
            v->second_field = 0;
896 897 898
            s->current_picture.f->linesize[0] >>= 1;
            s->current_picture.f->linesize[1] >>= 1;
            s->current_picture.f->linesize[2] >>= 1;
899 900
            s->linesize                      >>= 1;
            s->uvlinesize                    >>= 1;
901 902 903 904
            if (v->s.pict_type != AV_PICTURE_TYPE_BI && v->s.pict_type != AV_PICTURE_TYPE_B) {
                FFSWAP(uint8_t *, v->mv_f_next[0], v->mv_f[0]);
                FFSWAP(uint8_t *, v->mv_f_next[1], v->mv_f[1]);
            }
Ronald S. Bultje's avatar
Ronald S. Bultje committed
905
        }
906
        ff_dlog(s->avctx, "Consumed %i/%i bits\n",
907
                get_bits_count(&s->gb), s->gb.size_in_bits);
908
//  if (get_bits_count(&s->gb) > buf_size * 8)
909
//      return -1;
910 911
        if (!v->field_mode)
            ff_er_frame_end(&s->er);
912 913
    }

914
    ff_mpv_frame_end(s);
915

916
    if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
917 918 919
image:
        avctx->width  = avctx->coded_width  = v->output_width;
        avctx->height = avctx->coded_height = v->output_height;
920 921
        if (avctx->skip_frame >= AVDISCARD_NONREF)
            goto end;
922
#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
923 924
        if (vc1_decode_sprites(v, &s->gb))
            goto err;
925
#endif
926
        if ((ret = av_frame_ref(pict, v->sprite_output_frame)) < 0)
927
            goto err;
928
        *got_frame = 1;
929
    } else {
930
        if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
931
            if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0)
932 933
                goto err;
            ff_print_debug_info(s, s->current_picture_ptr);
Anton Khirnov's avatar
Anton Khirnov committed
934
            *got_frame = 1;
935
        } else if (s->last_picture_ptr) {
936
            if ((ret = av_frame_ref(pict, s->last_picture_ptr->f)) < 0)
937 938
                goto err;
            ff_print_debug_info(s, s->last_picture_ptr);
939
            *got_frame = 1;
940
        }
941 942
    }

943
end:
944
    av_free(buf2);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
945 946 947
    for (i = 0; i < n_slices; i++)
        av_free(slices[i].buf);
    av_free(slices);
948
    return buf_size;
949 950 951

err:
    av_free(buf2);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
952 953 954
    for (i = 0; i < n_slices; i++)
        av_free(slices[i].buf);
    av_free(slices);
955
    return -1;
956 957 958
}


959
static const enum AVPixelFormat vc1_hwaccel_pixfmt_list_420[] = {
960
#if CONFIG_VC1_DXVA2_HWACCEL
961 962
    AV_PIX_FMT_DXVA2_VLD,
#endif
963 964 965
#if CONFIG_VC1_D3D11VA_HWACCEL
    AV_PIX_FMT_D3D11VA_VLD,
#endif
966
#if CONFIG_VC1_VAAPI_HWACCEL
967
    AV_PIX_FMT_VAAPI,
968
#endif
969
#if CONFIG_VC1_VDPAU_HWACCEL
970 971 972 973 974 975
    AV_PIX_FMT_VDPAU,
#endif
    AV_PIX_FMT_YUV420P,
    AV_PIX_FMT_NONE
};

976
AVCodec ff_vc1_decoder = {
977
    .name           = "vc1",
978
    .long_name      = NULL_IF_CONFIG_SMALL("SMPTE VC-1"),
979
    .type           = AVMEDIA_TYPE_VIDEO,
980
    .id             = AV_CODEC_ID_VC1,
981 982
    .priv_data_size = sizeof(VC1Context),
    .init           = vc1_decode_init,
983
    .close          = ff_vc1_decode_end,
984
    .decode         = vc1_decode_frame,
985
    .flush          = ff_mpeg_flush,
986
    .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
987
    .pix_fmts       = vc1_hwaccel_pixfmt_list_420,
988
    .profiles       = NULL_IF_CONFIG_SMALL(ff_vc1_profiles)
989 990
};

991
#if CONFIG_WMV3_DECODER
992
AVCodec ff_wmv3_decoder = {
993
    .name           = "wmv3",
994
    .long_name      = NULL_IF_CONFIG_SMALL("Windows Media Video 9"),
995
    .type           = AVMEDIA_TYPE_VIDEO,
996
    .id             = AV_CODEC_ID_WMV3,
997 998
    .priv_data_size = sizeof(VC1Context),
    .init           = vc1_decode_init,
999
    .close          = ff_vc1_decode_end,
1000
    .decode         = vc1_decode_frame,
1001
    .flush          = ff_mpeg_flush,
1002
    .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
1003
    .pix_fmts       = vc1_hwaccel_pixfmt_list_420,
1004
    .profiles       = NULL_IF_CONFIG_SMALL(ff_vc1_profiles)
1005
};
1006
#endif
1007

1008 1009 1010
#if CONFIG_WMV3IMAGE_DECODER
AVCodec ff_wmv3image_decoder = {
    .name           = "wmv3image",
1011
    .long_name      = NULL_IF_CONFIG_SMALL("Windows Media Video 9 Image"),
1012
    .type           = AVMEDIA_TYPE_VIDEO,
1013
    .id             = AV_CODEC_ID_WMV3IMAGE,
1014 1015
    .priv_data_size = sizeof(VC1Context),
    .init           = vc1_decode_init,
1016
    .close          = ff_vc1_decode_end,
1017
    .decode         = vc1_decode_frame,
1018
    .capabilities   = AV_CODEC_CAP_DR1,
1019
    .flush          = vc1_sprite_flush,
1020 1021 1022 1023
    .pix_fmts       = (const enum AVPixelFormat[]) {
        AV_PIX_FMT_YUV420P,
        AV_PIX_FMT_NONE
    },
1024 1025 1026 1027 1028 1029
};
#endif

#if CONFIG_VC1IMAGE_DECODER
AVCodec ff_vc1image_decoder = {
    .name           = "vc1image",
1030
    .long_name      = NULL_IF_CONFIG_SMALL("Windows Media Video 9 Image v2"),
1031
    .type           = AVMEDIA_TYPE_VIDEO,
1032
    .id             = AV_CODEC_ID_VC1IMAGE,
1033 1034
    .priv_data_size = sizeof(VC1Context),
    .init           = vc1_decode_init,
1035
    .close          = ff_vc1_decode_end,
1036
    .decode         = vc1_decode_frame,
1037
    .capabilities   = AV_CODEC_CAP_DR1,
1038
    .flush          = vc1_sprite_flush,
1039 1040 1041 1042
    .pix_fmts       = (const enum AVPixelFormat[]) {
        AV_PIX_FMT_YUV420P,
        AV_PIX_FMT_NONE
    },
1043 1044
};
#endif