2009-06-11 12:31:31 +03:00
|
|
|
/*
|
|
|
|
* VC-1 and WMV3 decoder
|
2011-10-06 22:00:26 +03:00
|
|
|
* Copyright (c) 2011 Mashiat Sarker Shakkhar
|
2009-06-11 12:31:31 +03:00
|
|
|
* Copyright (c) 2006-2007 Konstantin Shishkov
|
|
|
|
* Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 17:45:34 +03:00
|
|
|
* @file
|
2009-06-11 12:31:31 +03:00
|
|
|
* VC-1 and WMV3 decoder
|
|
|
|
*/
|
2011-10-11 12:59:57 +03:00
|
|
|
|
2022-02-23 14:56:49 +02:00
|
|
|
#include "config_components.h"
|
|
|
|
|
2009-06-11 12:31:31 +03:00
|
|
|
#include "avcodec.h"
|
2014-07-16 21:18:20 +03:00
|
|
|
#include "blockdsp.h"
|
2022-03-16 19:18:28 +02:00
|
|
|
#include "codec_internal.h"
|
2022-08-24 19:54:25 +02:00
|
|
|
#include "decode.h"
|
2014-07-16 21:18:20 +03:00
|
|
|
#include "get_bits.h"
|
2020-04-13 17:33:14 +02:00
|
|
|
#include "hwconfig.h"
|
2014-06-20 16:05:45 +03:00
|
|
|
#include "mpeg_er.h"
|
2009-06-11 12:31:31 +03:00
|
|
|
#include "mpegvideo.h"
|
2022-02-01 09:42:25 +02:00
|
|
|
#include "mpegvideodec.h"
|
2014-07-16 21:18:20 +03:00
|
|
|
#include "msmpeg4data.h"
|
2022-02-01 08:10:17 +02:00
|
|
|
#include "msmpeg4dec.h"
|
2014-12-31 08:57:59 +02:00
|
|
|
#include "profiles.h"
|
2009-06-11 12:31:31 +03:00
|
|
|
#include "vc1.h"
|
|
|
|
#include "vc1data.h"
|
2012-03-27 14:20:51 +03:00
|
|
|
#include "libavutil/avassert.h"
|
2009-06-11 12:31:31 +03:00
|
|
|
|
|
|
|
|
2011-08-17 15:24:42 +03:00
|
|
|
#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
|
|
|
|
|
2014-09-22 12:01:31 +03:00
|
|
|
typedef struct SpriteData {
|
2011-08-17 15:24:42 +03:00
|
|
|
/**
|
|
|
|
* 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)
|
2011-04-08 21:00:48 +03:00
|
|
|
{
|
2011-10-11 12:59:57 +03:00
|
|
|
return (get_bits_long(gb, 30) - (1 << 29)) << 1;
|
2011-04-08 21:00:48 +03:00
|
|
|
}
|
|
|
|
|
2011-08-17 15:24:42 +03:00
|
|
|
static void vc1_sprite_parse_transform(GetBitContext* gb, int c[7])
|
2011-04-08 21:00:48 +03:00
|
|
|
{
|
2011-08-17 15:24:42 +03:00
|
|
|
c[1] = c[3] = 0;
|
2011-04-08 21:00:48 +03:00
|
|
|
|
|
|
|
switch (get_bits(gb, 2)) {
|
|
|
|
case 0:
|
2011-10-11 12:59:57 +03:00
|
|
|
c[0] = 1 << 16;
|
2011-08-17 15:24:42 +03:00
|
|
|
c[2] = get_fp_val(gb);
|
2011-10-11 12:59:57 +03:00
|
|
|
c[4] = 1 << 16;
|
2011-04-08 21:00:48 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
2011-08-17 15:24:42 +03:00
|
|
|
c[0] = c[4] = get_fp_val(gb);
|
|
|
|
c[2] = get_fp_val(gb);
|
2011-04-08 21:00:48 +03:00
|
|
|
break;
|
|
|
|
case 2:
|
2011-08-17 15:24:42 +03:00
|
|
|
c[0] = get_fp_val(gb);
|
|
|
|
c[2] = get_fp_val(gb);
|
|
|
|
c[4] = get_fp_val(gb);
|
2011-04-08 21:00:48 +03:00
|
|
|
break;
|
|
|
|
case 3:
|
2011-08-17 15:24:42 +03:00
|
|
|
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);
|
2011-04-08 21:00:48 +03:00
|
|
|
break;
|
|
|
|
}
|
2011-08-17 15:24:42 +03:00
|
|
|
c[5] = get_fp_val(gb);
|
2011-04-08 21:00:48 +03:00
|
|
|
if (get_bits1(gb))
|
2011-08-17 15:24:42 +03:00
|
|
|
c[6] = get_fp_val(gb);
|
2011-04-08 21:00:48 +03:00
|
|
|
else
|
2011-10-11 12:59:57 +03:00
|
|
|
c[6] = 1 << 16;
|
2011-04-08 21:00:48 +03:00
|
|
|
}
|
|
|
|
|
2013-12-14 03:07:34 +03:00
|
|
|
static int vc1_parse_sprites(VC1Context *v, GetBitContext* gb, SpriteData* sd)
|
2011-04-08 21:00:48 +03:00
|
|
|
{
|
2011-08-17 15:24:42 +03:00
|
|
|
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])
|
2013-03-13 23:17:05 +03:00
|
|
|
avpriv_request_sample(avctx, "Non-zero rotation coefficients");
|
2011-08-17 15:24:42 +03:00
|
|
|
av_log(avctx, AV_LOG_DEBUG, sprite ? "S2:" : "S1:");
|
2011-04-08 21:00:48 +03:00
|
|
|
for (i = 0; i < 7; i++)
|
2011-08-17 15:24:42 +03:00
|
|
|
av_log(avctx, AV_LOG_DEBUG, " %d.%.3d",
|
|
|
|
sd->coefs[sprite][i] / (1<<16),
|
2011-10-11 12:59:57 +03:00
|
|
|
(abs(sd->coefs[sprite][i]) & 0xFFFF) * 1000 / (1 << 16));
|
2011-08-17 15:24:42 +03:00
|
|
|
av_log(avctx, AV_LOG_DEBUG, "\n");
|
2011-04-08 21:00:48 +03:00
|
|
|
}
|
2011-08-17 15:24:42 +03:00
|
|
|
|
2011-04-08 21:00:48 +03:00
|
|
|
skip_bits(gb, 2);
|
2011-08-17 15:24:42 +03:00
|
|
|
if (sd->effect_type = get_bits_long(gb, 30)) {
|
|
|
|
switch (sd->effect_pcount1 = get_bits(gb, 4)) {
|
2011-04-08 21:00:48 +03:00
|
|
|
case 7:
|
2011-08-17 15:24:42 +03:00
|
|
|
vc1_sprite_parse_transform(gb, sd->effect_params1);
|
2011-04-08 21:00:48 +03:00
|
|
|
break;
|
|
|
|
case 14:
|
2011-08-17 15:24:42 +03:00
|
|
|
vc1_sprite_parse_transform(gb, sd->effect_params1);
|
|
|
|
vc1_sprite_parse_transform(gb, sd->effect_params1 + 7);
|
2011-04-08 21:00:48 +03:00
|
|
|
break;
|
|
|
|
default:
|
2011-08-17 15:24:42 +03:00
|
|
|
for (i = 0; i < sd->effect_pcount1; i++)
|
|
|
|
sd->effect_params1[i] = get_fp_val(gb);
|
2011-04-08 21:00:48 +03:00
|
|
|
}
|
2011-08-17 15:24:42 +03:00
|
|
|
if (sd->effect_type != 13 || sd->effect_params1[0] != sd->coefs[0][6]) {
|
2011-04-08 21:00:48 +03:00
|
|
|
// effect 13 is simple alpha blending and matches the opacity above
|
2011-08-17 15:24:42 +03:00
|
|
|
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",
|
2011-10-11 12:59:57 +03:00
|
|
|
sd->effect_params1[i] / (1 << 16),
|
|
|
|
(abs(sd->effect_params1[i]) & 0xFFFF) * 1000 / (1 << 16));
|
2011-08-17 15:24:42 +03:00
|
|
|
av_log(avctx, AV_LOG_DEBUG, "\n");
|
2011-04-08 21:00:48 +03:00
|
|
|
}
|
|
|
|
|
2011-08-17 15:24:42 +03:00
|
|
|
sd->effect_pcount2 = get_bits(gb, 16);
|
|
|
|
if (sd->effect_pcount2 > 10) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Too many effect parameters\n");
|
2013-12-14 03:07:34 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
2011-08-17 15:24:42 +03:00
|
|
|
} else if (sd->effect_pcount2) {
|
|
|
|
i = -1;
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, "Effect params 2: ");
|
2011-10-11 12:59:57 +03:00
|
|
|
while (++i < sd->effect_pcount2) {
|
2011-08-17 15:24:42 +03:00
|
|
|
sd->effect_params2[i] = get_fp_val(gb);
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, " %d.%.2d",
|
2011-10-11 12:59:57 +03:00
|
|
|
sd->effect_params2[i] / (1 << 16),
|
|
|
|
(abs(sd->effect_params2[i]) & 0xFFFF) * 1000 / (1 << 16));
|
2011-04-08 21:00:48 +03:00
|
|
|
}
|
2011-08-17 15:24:42 +03:00
|
|
|
av_log(avctx, AV_LOG_DEBUG, "\n");
|
2011-04-08 21:00:48 +03:00
|
|
|
}
|
|
|
|
}
|
2011-08-17 15:24:42 +03:00
|
|
|
if (sd->effect_flag = get_bits1(gb))
|
|
|
|
av_log(avctx, AV_LOG_DEBUG, "Effect flag set\n");
|
2011-04-08 21:00:48 +03:00
|
|
|
|
|
|
|
if (get_bits_count(gb) >= gb->size_in_bits +
|
2013-12-14 03:07:34 +03:00
|
|
|
(avctx->codec_id == AV_CODEC_ID_WMV3IMAGE ? 64 : 0)) {
|
2011-08-17 15:24:42 +03:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Buffer overrun\n");
|
2013-12-14 03:07:34 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2011-04-08 21:00:48 +03:00
|
|
|
if (get_bits_count(gb) < gb->size_in_bits - 8)
|
2011-08-17 15:24:42 +03:00
|
|
|
av_log(avctx, AV_LOG_WARNING, "Buffer not fully read\n");
|
2013-12-14 03:07:34 +03:00
|
|
|
|
|
|
|
return 0;
|
2011-08-17 15:24:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-12-14 02:58:18 +03:00
|
|
|
for (i = 0; i <= v->two_sprites; i++) {
|
2011-08-17 15:24:42 +03:00
|
|
|
xoff[i] = av_clip(sd->coefs[i][2], 0, v->sprite_width-1 << 16);
|
|
|
|
xadv[i] = sd->coefs[i][0];
|
2011-10-11 12:59:57 +03:00
|
|
|
if (xadv[i] != 1<<16 || (v->sprite_width << 16) - (v->output_width << 16) - xoff[i])
|
2011-08-17 15:24:42 +03:00
|
|
|
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);
|
2011-10-11 12:59:57 +03:00
|
|
|
yadv[i] = av_clip(sd->coefs[i][4], 0, ((v->sprite_height << 16) - yoff[i]) / v->output_height);
|
2011-08-17 15:24:42 +03:00
|
|
|
}
|
2015-02-20 02:35:35 +02:00
|
|
|
alpha = av_clip_uint16(sd->coefs[1][6]);
|
2011-08-17 15:24:42 +03:00
|
|
|
|
2015-07-27 21:14:31 +02:00
|
|
|
for (plane = 0; plane < (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY ? 1 : 3); plane++) {
|
2011-08-17 15:24:42 +03:00
|
|
|
int width = v->output_width>>!!plane;
|
|
|
|
|
|
|
|
for (row = 0; row < v->output_height>>!!plane; row++) {
|
2013-11-09 12:14:46 +03:00
|
|
|
uint8_t *dst = v->sprite_output_frame->data[plane] +
|
|
|
|
v->sprite_output_frame->linesize[plane] * row;
|
2011-08-17 15:24:42 +03:00
|
|
|
|
|
|
|
for (sprite = 0; sprite <= v->two_sprites; sprite++) {
|
2014-03-31 20:46:29 +03:00
|
|
|
uint8_t *iplane = s->current_picture.f->data[plane];
|
|
|
|
int iline = s->current_picture.f->linesize[plane];
|
2011-10-11 12:59:57 +03:00
|
|
|
int ycoord = yoff[sprite] + yadv[sprite] * row;
|
|
|
|
int yline = ycoord >> 16;
|
2012-07-28 13:27:55 +03:00
|
|
|
int next_line;
|
2011-10-11 12:59:57 +03:00
|
|
|
ysub[sprite] = ycoord & 0xFFFF;
|
2011-08-17 15:24:42 +03:00
|
|
|
if (sprite) {
|
2014-03-31 20:46:29 +03:00
|
|
|
iplane = s->last_picture.f->data[plane];
|
|
|
|
iline = s->last_picture.f->linesize[plane];
|
2011-08-17 15:24:42 +03:00
|
|
|
}
|
2012-07-28 13:27:55 +03:00
|
|
|
next_line = FFMIN(yline + 1, (v->sprite_height >> !!plane) - 1) * iline;
|
2011-10-11 12:59:57 +03:00
|
|
|
if (!(xoff[sprite] & 0xFFFF) && xadv[sprite] == 1 << 16) {
|
|
|
|
src_h[sprite][0] = iplane + (xoff[sprite] >> 16) + yline * iline;
|
2011-08-17 15:24:42 +03:00
|
|
|
if (ysub[sprite])
|
2012-07-28 13:27:55 +03:00
|
|
|
src_h[sprite][1] = iplane + (xoff[sprite] >> 16) + next_line;
|
2011-08-17 15:24:42 +03:00
|
|
|
} 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 {
|
2011-10-11 12:59:57 +03:00
|
|
|
v->vc1dsp.sprite_h(v->sr_rows[sprite][0], iplane + yline * iline, xoff[sprite], xadv[sprite], width);
|
2011-08-17 15:24:42 +03:00
|
|
|
sr_cache[sprite][0] = yline;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ysub[sprite] && sr_cache[sprite][1] != yline + 1) {
|
2012-07-28 13:27:55 +03:00
|
|
|
v->vc1dsp.sprite_h(v->sr_rows[sprite][1],
|
|
|
|
iplane + next_line, xoff[sprite],
|
|
|
|
xadv[sprite], width);
|
2011-08-17 15:24:42 +03:00
|
|
|
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) {
|
2013-12-14 02:58:18 +03:00
|
|
|
for (i = 0; i <= v->two_sprites; i++) {
|
2011-08-17 15:24:42 +03:00
|
|
|
xoff[i] >>= 1;
|
|
|
|
yoff[i] >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int vc1_decode_sprites(VC1Context *v, GetBitContext* gb)
|
|
|
|
{
|
lavc: factorize ff_{thread_,re,}get_buffer error messages.
Coccinelle profile used:
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_get_buffer(ctx, f, flags)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str;
@@
-if ((r = ff_reget_buffer(ctx, f)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_reget_buffer(ctx, f)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0)
+ return r;
...along with some manual patches for the remaining ones.
2013-03-12 10:41:53 +03:00
|
|
|
int ret;
|
2011-10-11 12:59:57 +03:00
|
|
|
MpegEncContext *s = &v->s;
|
2011-08-17 15:24:42 +03:00
|
|
|
AVCodecContext *avctx = s->avctx;
|
|
|
|
SpriteData sd;
|
|
|
|
|
2013-12-14 02:58:18 +03:00
|
|
|
memset(&sd, 0, sizeof(sd));
|
|
|
|
|
2013-12-14 03:07:34 +03:00
|
|
|
ret = vc1_parse_sprites(v, gb, &sd);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2011-08-17 15:24:42 +03:00
|
|
|
|
2014-08-25 03:17:32 +03:00
|
|
|
if (!s->current_picture.f || !s->current_picture.f->data[0]) {
|
2011-08-17 15:24:42 +03:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Got no sprites\n");
|
2015-08-06 11:20:25 +02:00
|
|
|
return AVERROR_UNKNOWN;
|
2011-08-17 15:24:42 +03:00
|
|
|
}
|
|
|
|
|
2014-03-31 20:46:29 +03:00
|
|
|
if (v->two_sprites && (!s->last_picture_ptr || !s->last_picture.f->data[0])) {
|
2011-08-17 15:24:42 +03:00
|
|
|
av_log(avctx, AV_LOG_WARNING, "Need two sprites, only got one\n");
|
|
|
|
v->two_sprites = 0;
|
|
|
|
}
|
|
|
|
|
2013-11-09 12:14:46 +03:00
|
|
|
av_frame_unref(v->sprite_output_frame);
|
2013-11-17 05:31:32 +03:00
|
|
|
if ((ret = ff_get_buffer(avctx, v->sprite_output_frame, 0)) < 0)
|
lavc: factorize ff_{thread_,re,}get_buffer error messages.
Coccinelle profile used:
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_get_buffer(ctx, f, flags)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str;
@@
-if ((r = ff_reget_buffer(ctx, f)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_reget_buffer(ctx, f)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0)
+ return r;
...along with some manual patches for the remaining ones.
2013-03-12 10:41:53 +03:00
|
|
|
return ret;
|
2011-08-17 15:24:42 +03:00
|
|
|
|
|
|
|
vc1_draw_sprites(v, &sd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vc1_sprite_flush(AVCodecContext *avctx)
|
|
|
|
{
|
2011-10-11 12:59:57 +03:00
|
|
|
VC1Context *v = avctx->priv_data;
|
2011-08-17 15:24:42 +03:00
|
|
|
MpegEncContext *s = &v->s;
|
2014-03-31 20:46:29 +03:00
|
|
|
AVFrame *f = s->current_picture.f;
|
2011-08-17 15:24:42 +03:00
|
|
|
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. */
|
|
|
|
|
2014-08-11 03:16:43 +03:00
|
|
|
if (f && f->data[0])
|
2015-07-27 21:14:31 +02:00
|
|
|
for (plane = 0; plane < (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY ? 1 : 3); plane++)
|
2011-08-17 15:24:42 +03:00
|
|
|
for (i = 0; i < v->sprite_height>>!!plane; i++)
|
2011-10-11 12:59:57 +03:00
|
|
|
memset(f->data[plane] + i * f->linesize[plane],
|
2011-08-17 15:24:42 +03:00
|
|
|
plane ? 128 : 0, f->linesize[plane]);
|
2011-04-08 21:00:48 +03:00
|
|
|
}
|
|
|
|
|
2011-08-17 15:24:42 +03:00
|
|
|
#endif
|
|
|
|
|
2012-08-27 20:21:00 +03:00
|
|
|
av_cold int ff_vc1_decode_init_alloc_tables(VC1Context *v)
|
2011-08-27 20:37:26 +03:00
|
|
|
{
|
|
|
|
MpegEncContext *s = &v->s;
|
2016-02-20 00:43:24 +02:00
|
|
|
int i, ret = AVERROR(ENOMEM);
|
2013-12-14 16:52:31 +03:00
|
|
|
int mb_height = FFALIGN(s->mb_height, 2);
|
2011-08-27 20:37:26 +03:00
|
|
|
|
|
|
|
/* Allocate mb bitplanes */
|
2013-12-14 16:52:31 +03:00
|
|
|
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);
|
2016-02-24 21:40:19 +02:00
|
|
|
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;
|
2011-08-27 20:37:26 +03:00
|
|
|
|
|
|
|
v->n_allocated_blks = s->mb_width + 2;
|
2011-10-11 12:59:57 +03:00
|
|
|
v->block = av_malloc(sizeof(*v->block) * v->n_allocated_blks);
|
2018-04-23 20:58:59 +02:00
|
|
|
v->cbp_base = av_malloc(sizeof(v->cbp_base[0]) * 3 * s->mb_stride);
|
2016-02-24 21:40:19 +02:00
|
|
|
if (!v->block || !v->cbp_base)
|
|
|
|
goto error;
|
2018-04-23 20:58:59 +02:00
|
|
|
v->cbp = v->cbp_base + 2 * s->mb_stride;
|
|
|
|
v->ttblk_base = av_malloc(sizeof(v->ttblk_base[0]) * 3 * s->mb_stride);
|
2016-02-24 21:40:19 +02:00
|
|
|
if (!v->ttblk_base)
|
|
|
|
goto error;
|
2018-04-23 20:58:59 +02:00
|
|
|
v->ttblk = v->ttblk_base + 2 * s->mb_stride;
|
|
|
|
v->is_intra_base = av_mallocz(sizeof(v->is_intra_base[0]) * 3 * s->mb_stride);
|
2016-02-24 21:40:19 +02:00
|
|
|
if (!v->is_intra_base)
|
|
|
|
goto error;
|
2018-04-23 20:58:59 +02:00
|
|
|
v->is_intra = v->is_intra_base + 2 * s->mb_stride;
|
|
|
|
v->luma_mv_base = av_mallocz(sizeof(v->luma_mv_base[0]) * 3 * s->mb_stride);
|
2016-02-24 21:40:19 +02:00
|
|
|
if (!v->luma_mv_base)
|
|
|
|
goto error;
|
2018-04-23 20:58:59 +02:00
|
|
|
v->luma_mv = v->luma_mv_base + 2 * s->mb_stride;
|
2011-08-27 20:37:26 +03:00
|
|
|
|
|
|
|
/* allocate block type info in that way so it could be used with s->block_index[] */
|
2013-12-14 16:52:31 +03:00
|
|
|
v->mb_type_base = av_malloc(s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
|
2016-02-24 21:40:19 +02:00
|
|
|
if (!v->mb_type_base)
|
|
|
|
goto error;
|
2011-10-11 12:59:57 +03:00
|
|
|
v->mb_type[0] = v->mb_type_base + s->b8_stride + 1;
|
2013-12-14 16:52:31 +03:00
|
|
|
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);
|
2011-08-27 20:37:26 +03:00
|
|
|
|
2011-10-06 22:00:26 +03:00
|
|
|
/* allocate memory to store block level MV info */
|
2013-12-14 16:52:31 +03:00
|
|
|
v->blk_mv_type_base = av_mallocz( s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
|
2016-02-24 21:40:19 +02:00
|
|
|
if (!v->blk_mv_type_base)
|
|
|
|
goto error;
|
2011-10-11 12:59:57 +03:00
|
|
|
v->blk_mv_type = v->blk_mv_type_base + s->b8_stride + 1;
|
2013-12-14 16:52:31 +03:00
|
|
|
v->mv_f_base = av_mallocz(2 * (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2));
|
2016-02-24 21:40:19 +02:00
|
|
|
if (!v->mv_f_base)
|
|
|
|
goto error;
|
2011-10-11 12:59:57 +03:00
|
|
|
v->mv_f[0] = v->mv_f_base + s->b8_stride + 1;
|
2013-12-14 16:52:31 +03:00
|
|
|
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));
|
2016-02-24 21:40:19 +02:00
|
|
|
if (!v->mv_f_next_base)
|
|
|
|
goto error;
|
2011-10-11 12:59:57 +03:00
|
|
|
v->mv_f_next[0] = v->mv_f_next_base + s->b8_stride + 1;
|
2013-12-14 16:52:31 +03:00
|
|
|
v->mv_f_next[1] = v->mv_f_next[0] + (s->b8_stride * (mb_height * 2 + 1) + s->mb_stride * (mb_height + 1) * 2);
|
2011-10-06 22:00:26 +03:00
|
|
|
|
2012-08-05 12:11:04 +03:00
|
|
|
if (s->avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || s->avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
|
2011-08-27 20:37:26 +03:00
|
|
|
for (i = 0; i < 4; i++)
|
2013-09-23 15:53:48 +03:00
|
|
|
if (!(v->sr_rows[i >> 1][i & 1] = av_malloc(v->output_width)))
|
2021-04-08 01:49:53 +02:00
|
|
|
goto error;
|
2011-08-27 20:37:26 +03:00
|
|
|
}
|
|
|
|
|
2022-07-31 09:17:44 +02:00
|
|
|
ret = ff_intrax8_common_init(s->avctx, &v->x8,
|
2016-02-20 08:57:47 +02:00
|
|
|
s->block, s->block_last_index,
|
2016-02-20 09:29:43 +02:00
|
|
|
s->mb_width, s->mb_height);
|
2016-02-20 00:43:24 +02:00
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
|
2011-08-27 20:37:26 +03:00
|
|
|
return 0;
|
2016-02-24 21:40:17 +02:00
|
|
|
|
|
|
|
error:
|
|
|
|
ff_vc1_decode_end(s->avctx);
|
2016-02-20 00:43:24 +02:00
|
|
|
return ret;
|
2011-08-27 20:37:26 +03:00
|
|
|
}
|
|
|
|
|
2012-08-27 20:21:00 +03:00
|
|
|
av_cold void ff_vc1_init_transposed_scantables(VC1Context *v)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 64; i++) {
|
2014-06-08 16:26:18 +03:00
|
|
|
#define transpose(x) (((x) >> 3) | (((x) & 7) << 3))
|
2012-08-27 20:21:00 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-06-11 12:31:31 +03:00
|
|
|
/** Initialize a VC1/WMV3 decoder
|
|
|
|
* @todo TODO: Handle VC-1 IDUs (Transport level?)
|
2016-04-27 19:45:23 +02:00
|
|
|
* @todo TODO: Decipher remaining bits in extra_data
|
2009-06-11 12:31:31 +03:00
|
|
|
*/
|
|
|
|
static av_cold int vc1_decode_init(AVCodecContext *avctx)
|
|
|
|
{
|
|
|
|
VC1Context *v = avctx->priv_data;
|
|
|
|
MpegEncContext *s = &v->s;
|
|
|
|
GetBitContext gb;
|
2013-09-23 15:57:30 +03:00
|
|
|
int ret;
|
2009-06-11 12:31:31 +03:00
|
|
|
|
2011-08-17 15:24:42 +03:00
|
|
|
/* save the container output size for WMImage */
|
|
|
|
v->output_width = avctx->width;
|
|
|
|
v->output_height = avctx->height;
|
|
|
|
|
2011-10-11 12:59:57 +03:00
|
|
|
if (!avctx->extradata_size || !avctx->extradata)
|
2019-12-17 01:04:23 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2009-06-11 12:31:31 +03:00
|
|
|
v->s.avctx = avctx;
|
|
|
|
|
2020-12-22 18:55:19 +02:00
|
|
|
ff_vc1_init_common(v);
|
2009-06-11 12:31:31 +03:00
|
|
|
|
2012-08-05 12:11:04 +03:00
|
|
|
if (avctx->codec_id == AV_CODEC_ID_WMV3 || avctx->codec_id == AV_CODEC_ID_WMV3IMAGE) {
|
2009-06-11 12:31:31 +03:00
|
|
|
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
|
|
|
|
|
2021-08-23 20:24:56 +02:00
|
|
|
ret = init_get_bits8(&gb, avctx->extradata, avctx->extradata_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-06-11 12:31:31 +03:00
|
|
|
|
2013-09-23 15:57:30 +03:00
|
|
|
if ((ret = ff_vc1_decode_sequence_header(avctx, v, &gb)) < 0)
|
|
|
|
return ret;
|
2009-06-11 12:31:31 +03:00
|
|
|
|
2019-08-15 20:04:35 +02:00
|
|
|
if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE && !v->res_sprite) {
|
|
|
|
avpriv_request_sample(avctx, "Non sprite WMV3IMAGE");
|
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
|
|
|
|
2009-06-11 12:31:31 +03:00
|
|
|
count = avctx->extradata_size*8 - get_bits_count(&gb);
|
2011-10-11 12:59:57 +03:00
|
|
|
if (count > 0) {
|
2009-06-11 12:31:31 +03:00
|
|
|
av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n",
|
2015-06-25 22:47:38 +02:00
|
|
|
count, get_bits_long(&gb, FFMIN(count, 32)));
|
2011-10-11 12:59:57 +03:00
|
|
|
} else if (count < 0) {
|
2009-06-11 12:31:31 +03:00
|
|
|
av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count);
|
|
|
|
}
|
2011-04-08 21:00:48 +03:00
|
|
|
} else { // VC1/WVC1/WVP2
|
2009-06-11 12:31:31 +03:00
|
|
|
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;
|
|
|
|
|
2011-10-11 12:59:57 +03:00
|
|
|
if (avctx->extradata_size < 16) {
|
2009-06-11 12:31:31 +03:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", avctx->extradata_size);
|
2019-12-17 01:04:23 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
|
|
|
|
2015-06-29 23:48:34 +02:00
|
|
|
buf2 = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
|
2015-04-06 15:06:42 +02:00
|
|
|
if (!buf2)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2009-10-06 18:30:08 +03:00
|
|
|
start = find_next_marker(start, end); // in WVC1 extradata first byte is its size, but can be 0 in mkv
|
2011-10-11 12:59:57 +03:00
|
|
|
next = start;
|
|
|
|
for (; next < end; start = next) {
|
2009-06-11 12:31:31 +03:00
|
|
|
next = find_next_marker(start + 4, end);
|
|
|
|
size = next - start - 4;
|
2011-10-11 12:59:57 +03:00
|
|
|
if (size <= 0)
|
|
|
|
continue;
|
2022-03-31 19:23:45 +02:00
|
|
|
buf2_size = v->vc1dsp.vc1_unescape_buffer(start + 4, size, buf2);
|
2009-06-11 12:31:31 +03:00
|
|
|
init_get_bits(&gb, buf2, buf2_size * 8);
|
2011-10-11 12:59:57 +03:00
|
|
|
switch (AV_RB32(start)) {
|
2009-06-11 12:31:31 +03:00
|
|
|
case VC1_CODE_SEQHDR:
|
2013-09-23 15:57:30 +03:00
|
|
|
if ((ret = ff_vc1_decode_sequence_header(avctx, v, &gb)) < 0) {
|
2009-06-11 12:31:31 +03:00
|
|
|
av_free(buf2);
|
2013-09-23 15:57:30 +03:00
|
|
|
return ret;
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
|
|
|
seq_initialized = 1;
|
|
|
|
break;
|
|
|
|
case VC1_CODE_ENTRYPOINT:
|
2013-09-23 15:57:30 +03:00
|
|
|
if ((ret = ff_vc1_decode_entry_point(avctx, v, &gb)) < 0) {
|
2009-06-11 12:31:31 +03:00
|
|
|
av_free(buf2);
|
2013-09-23 15:57:30 +03:00
|
|
|
return ret;
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
|
|
|
ep_initialized = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
av_free(buf2);
|
2011-10-11 12:59:57 +03:00
|
|
|
if (!seq_initialized || !ep_initialized) {
|
2009-06-11 12:31:31 +03:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n");
|
2019-12-17 01:04:23 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
2013-02-05 15:31:43 +03:00
|
|
|
v->res_sprite = (avctx->codec_id == AV_CODEC_ID_VC1IMAGE);
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
2011-06-07 20:53:31 +03:00
|
|
|
|
2011-03-12 00:12:04 +02:00
|
|
|
avctx->profile = v->profile;
|
|
|
|
if (v->profile == PROFILE_ADVANCED)
|
|
|
|
avctx->level = v->level;
|
|
|
|
|
avcodec/vc1dec: Re-order init to avoid initting hwaccel too early
At least for vdpau, the hwaccel init code tries to check the video
profile and ensure that there is a matching vdpau profile available.
If it can't find a match, it will fail to initialise.
In the case of wmv3/vc1, I observed initialisation to fail all the
time. It turns out that this is due to the hwaccel being initialised
very early in the codec init, before the profile has been extracted
and set.
Conceptually, it's a simple fix to reorder the init code, but it gets
messy really fast because ff_get_format(), which is what implicitly
trigger hwaccel init, is called multiple times through various shared
init calls from h263, etc. It's incredibly hard to prove to my own
satisfaction that it's safe to move the vc1 specific init code
ahead of this generic code, but all the vc1 fate tests pass, and I've
visually inspected a couple of samples and things seem correct.
Signed-off-by: Philip Langdale <philipl@overt.org>
2015-08-08 23:59:09 +02:00
|
|
|
if (!CONFIG_GRAY || !(avctx->flags & AV_CODEC_FLAG_GRAY))
|
|
|
|
avctx->pix_fmt = ff_get_format(avctx, avctx->codec->pix_fmts);
|
|
|
|
else {
|
|
|
|
avctx->pix_fmt = AV_PIX_FMT_GRAY8;
|
|
|
|
if (avctx->color_range == AVCOL_RANGE_UNSPECIFIED)
|
|
|
|
avctx->color_range = AVCOL_RANGE_MPEG;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure static VLC tables are initialized
|
|
|
|
if ((ret = ff_msmpeg4_decode_init(avctx)) < 0)
|
|
|
|
return ret;
|
|
|
|
if ((ret = ff_vc1_decode_init_alloc_tables(v)) < 0)
|
|
|
|
return ret;
|
|
|
|
// Hack to ensure the above functions will be called
|
|
|
|
// again once we know all necessary settings.
|
|
|
|
// That this is necessary might indicate a bug.
|
|
|
|
ff_vc1_decode_end(avctx);
|
|
|
|
|
2022-09-20 02:52:15 +02:00
|
|
|
ff_blockdsp_init(&s->bdsp);
|
avcodec/vc1dec: Re-order init to avoid initting hwaccel too early
At least for vdpau, the hwaccel init code tries to check the video
profile and ensure that there is a matching vdpau profile available.
If it can't find a match, it will fail to initialise.
In the case of wmv3/vc1, I observed initialisation to fail all the
time. It turns out that this is due to the hwaccel being initialised
very early in the codec init, before the profile has been extracted
and set.
Conceptually, it's a simple fix to reorder the init code, but it gets
messy really fast because ff_get_format(), which is what implicitly
trigger hwaccel init, is called multiple times through various shared
init calls from h263, etc. It's incredibly hard to prove to my own
satisfaction that it's safe to move the vc1 specific init code
ahead of this generic code, but all the vc1 fate tests pass, and I've
visually inspected a couple of samples and things seem correct.
Signed-off-by: Philip Langdale <philipl@overt.org>
2015-08-08 23:59:09 +02:00
|
|
|
ff_h264chroma_init(&v->h264chroma, 8);
|
|
|
|
ff_qpeldsp_init(&s->qdsp);
|
|
|
|
|
2012-01-07 21:07:42 +03:00
|
|
|
avctx->has_b_frames = !!avctx->max_b_frames;
|
2009-06-11 12:31:31 +03:00
|
|
|
|
2014-10-06 00:58:50 +03:00
|
|
|
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;
|
|
|
|
|
2011-10-11 12:59:57 +03:00
|
|
|
s->mb_width = (avctx->coded_width + 15) >> 4;
|
|
|
|
s->mb_height = (avctx->coded_height + 15) >> 4;
|
2009-06-11 12:31:31 +03:00
|
|
|
|
2011-04-16 22:29:05 +03:00
|
|
|
if (v->profile == PROFILE_ADVANCED || v->res_fasttx) {
|
2012-08-27 20:21:00 +03:00
|
|
|
ff_vc1_init_transposed_scantables(v);
|
2011-04-16 22:07:14 +03:00
|
|
|
} else {
|
2012-02-15 13:56:41 +03:00
|
|
|
memcpy(v->zz_8x8, ff_wmv1_scantable, 4*64);
|
2011-04-16 22:07:14 +03:00
|
|
|
v->left_blk_sh = 3;
|
|
|
|
v->top_blk_sh = 0;
|
|
|
|
}
|
|
|
|
|
2012-08-05 12:11:04 +03:00
|
|
|
if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
|
2011-08-17 15:24:42 +03:00
|
|
|
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
|
2011-10-11 12:59:57 +03:00
|
|
|
if (v->sprite_width > 1 << 14 ||
|
|
|
|
v->sprite_height > 1 << 14 ||
|
|
|
|
v->output_width > 1 << 14 ||
|
2019-12-17 00:31:22 +02:00
|
|
|
v->output_height > 1 << 14) {
|
2020-12-22 18:21:48 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2019-12-17 00:31:22 +02:00
|
|
|
}
|
2013-03-06 02:03:58 +03:00
|
|
|
|
|
|
|
if ((v->sprite_width&1) || (v->sprite_height&1)) {
|
2013-03-15 20:13:52 +03:00
|
|
|
avpriv_request_sample(avctx, "odd sprites support");
|
2020-12-22 18:21:48 +02:00
|
|
|
return AVERROR_PATCHWELCOME;
|
2013-03-06 02:03:58 +03:00
|
|
|
}
|
2011-08-17 15:24:42 +03:00
|
|
|
}
|
2009-06-11 12:31:31 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-27 20:37:26 +03:00
|
|
|
/** Close a VC1/WMV3 decoder
|
|
|
|
* @warning Initial try at using MpegEncContext stuff
|
|
|
|
*/
|
2012-08-27 20:21:00 +03:00
|
|
|
av_cold int ff_vc1_decode_end(AVCodecContext *avctx)
|
2011-08-27 20:37:26 +03:00
|
|
|
{
|
|
|
|
VC1Context *v = avctx->priv_data;
|
|
|
|
int i;
|
|
|
|
|
2013-11-09 12:14:46 +03:00
|
|
|
av_frame_free(&v->sprite_output_frame);
|
2012-11-21 23:34:46 +03:00
|
|
|
|
2011-08-27 20:37:26 +03:00
|
|
|
for (i = 0; i < 4; i++)
|
2011-10-11 12:59:57 +03:00
|
|
|
av_freep(&v->sr_rows[i >> 1][i & 1]);
|
2014-08-10 18:25:12 +03:00
|
|
|
ff_mpv_common_end(&v->s);
|
2011-08-27 20:37:26 +03:00
|
|
|
av_freep(&v->mv_type_mb_plane);
|
|
|
|
av_freep(&v->direct_mb_plane);
|
2011-10-06 22:00:26 +03:00
|
|
|
av_freep(&v->forward_mb_plane);
|
|
|
|
av_freep(&v->fieldtx_plane);
|
2011-08-27 20:37:26 +03:00
|
|
|
av_freep(&v->acpred_plane);
|
|
|
|
av_freep(&v->over_flags_plane);
|
|
|
|
av_freep(&v->mb_type_base);
|
2011-10-06 22:00:26 +03:00
|
|
|
av_freep(&v->blk_mv_type_base);
|
|
|
|
av_freep(&v->mv_f_base);
|
|
|
|
av_freep(&v->mv_f_next_base);
|
2011-08-27 20:37:26 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-06-11 12:31:31 +03:00
|
|
|
|
|
|
|
/** Decode a VC1/WMV3 frame
|
|
|
|
* @todo TODO: Handle VC-1 IDUs (Transport level?)
|
|
|
|
*/
|
2022-03-30 21:33:24 +02:00
|
|
|
static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
|
2012-11-13 21:35:22 +03:00
|
|
|
int *got_frame, AVPacket *avpkt)
|
2009-06-11 12:31:31 +03:00
|
|
|
{
|
|
|
|
const uint8_t *buf = avpkt->data;
|
2012-11-21 23:34:46 +03:00
|
|
|
int buf_size = avpkt->size, n_slices = 0, i, ret;
|
2009-06-11 12:31:31 +03:00
|
|
|
VC1Context *v = avctx->priv_data;
|
|
|
|
MpegEncContext *s = &v->s;
|
|
|
|
uint8_t *buf2 = NULL;
|
2012-01-14 00:13:51 +03:00
|
|
|
const uint8_t *buf_start = buf, *buf_start_second_field = NULL;
|
2011-10-11 03:39:50 +03:00
|
|
|
int mb_height, n_slices1=-1;
|
2011-03-21 16:00:43 +02:00
|
|
|
struct {
|
|
|
|
uint8_t *buf;
|
|
|
|
GetBitContext gb;
|
|
|
|
int mby_start;
|
2016-11-15 11:28:10 +02:00
|
|
|
const uint8_t *rawbuf;
|
|
|
|
int raw_size;
|
2011-12-20 11:53:18 +03:00
|
|
|
} *slices = NULL, *tmp;
|
2009-06-11 12:31:31 +03:00
|
|
|
|
2012-01-14 00:13:51 +03:00
|
|
|
v->second_field = 0;
|
|
|
|
|
2015-07-27 21:14:31 +02:00
|
|
|
if(s->avctx->flags & AV_CODEC_FLAG_LOW_DELAY)
|
2011-11-02 21:35:22 +03:00
|
|
|
s->low_delay = 1;
|
|
|
|
|
2009-06-11 12:31:31 +03:00
|
|
|
/* no supplementary picture */
|
2011-03-02 13:17:33 +02:00
|
|
|
if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == VC1_CODE_ENDOFSEQ)) {
|
2009-06-11 12:31:31 +03:00
|
|
|
/* special case for last picture */
|
2011-10-11 12:59:57 +03:00
|
|
|
if (s->low_delay == 0 && s->next_picture_ptr) {
|
2014-03-31 20:46:29 +03:00
|
|
|
if ((ret = av_frame_ref(pict, s->next_picture_ptr->f)) < 0)
|
2012-11-21 23:34:46 +03:00
|
|
|
return ret;
|
2011-10-11 12:59:57 +03:00
|
|
|
s->next_picture_ptr = NULL;
|
2009-06-11 12:31:31 +03:00
|
|
|
|
2012-11-13 21:35:22 +03:00
|
|
|
*got_frame = 1;
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
|
|
|
|
2012-07-28 20:24:39 +03:00
|
|
|
return buf_size;
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//for advanced profile we may need to parse and unescape data
|
2012-08-05 12:11:04 +03:00
|
|
|
if (avctx->codec_id == AV_CODEC_ID_VC1 || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
|
2009-06-11 12:31:31 +03:00
|
|
|
int buf_size2 = 0;
|
2015-06-29 23:48:34 +02:00
|
|
|
buf2 = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
|
2013-06-29 15:49:47 +03:00
|
|
|
if (!buf2)
|
|
|
|
return AVERROR(ENOMEM);
|
2009-06-11 12:31:31 +03:00
|
|
|
|
2011-10-11 12:59:57 +03:00
|
|
|
if (IS_MARKER(AV_RB32(buf))) { /* frame starts with marker and needs to be parsed */
|
2009-06-11 12:31:31 +03:00
|
|
|
const uint8_t *start, *end, *next;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
next = buf;
|
2011-10-11 12:59:57 +03:00
|
|
|
for (start = buf, end = buf + buf_size; next < end; start = next) {
|
2009-06-11 12:31:31 +03:00
|
|
|
next = find_next_marker(start + 4, end);
|
|
|
|
size = next - start - 4;
|
2011-10-11 12:59:57 +03:00
|
|
|
if (size <= 0) continue;
|
|
|
|
switch (AV_RB32(start)) {
|
2009-06-11 12:31:31 +03:00
|
|
|
case VC1_CODE_FRAME:
|
2013-07-25 22:30:17 +03:00
|
|
|
if (avctx->hwaccel)
|
2009-06-11 12:31:31 +03:00
|
|
|
buf_start = start;
|
2022-03-31 19:23:45 +02:00
|
|
|
buf_size2 = v->vc1dsp.vc1_unescape_buffer(start + 4, size, buf2);
|
2009-06-11 12:31:31 +03:00
|
|
|
break;
|
2011-10-06 22:00:26 +03:00
|
|
|
case VC1_CODE_FIELD: {
|
|
|
|
int buf_size3;
|
2017-10-22 04:40:03 +02:00
|
|
|
if (avctx->hwaccel)
|
2012-01-14 00:13:51 +03:00
|
|
|
buf_start_second_field = start;
|
2019-12-26 03:31:04 +02:00
|
|
|
tmp = av_realloc_array(slices, sizeof(*slices), n_slices+1);
|
2015-08-06 11:20:25 +02:00
|
|
|
if (!tmp) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
2011-10-11 12:59:57 +03:00
|
|
|
goto err;
|
2015-08-06 11:20:25 +02:00
|
|
|
}
|
2012-10-09 17:07:12 +03:00
|
|
|
slices = tmp;
|
2019-10-12 17:54:29 +02:00
|
|
|
slices[n_slices].buf = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE);
|
2015-08-06 11:20:25 +02:00
|
|
|
if (!slices[n_slices].buf) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
2011-10-11 12:59:57 +03:00
|
|
|
goto err;
|
2015-08-06 11:20:25 +02:00
|
|
|
}
|
2022-03-31 19:23:45 +02:00
|
|
|
buf_size3 = v->vc1dsp.vc1_unescape_buffer(start + 4, size,
|
|
|
|
slices[n_slices].buf);
|
2011-10-06 22:00:26 +03:00
|
|
|
init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
|
|
|
|
buf_size3 << 3);
|
2018-05-09 07:50:28 +02:00
|
|
|
slices[n_slices].mby_start = avctx->coded_height + 31 >> 5;
|
2016-11-15 11:28:10 +02:00
|
|
|
slices[n_slices].rawbuf = start;
|
|
|
|
slices[n_slices].raw_size = size + 4;
|
2011-10-06 22:00:26 +03:00
|
|
|
n_slices1 = n_slices - 1; // index of the last slice of the first field
|
|
|
|
n_slices++;
|
|
|
|
break;
|
|
|
|
}
|
2009-06-11 12:31:31 +03:00
|
|
|
case VC1_CODE_ENTRYPOINT: /* it should be before frame data */
|
2022-03-31 19:23:45 +02:00
|
|
|
buf_size2 = v->vc1dsp.vc1_unescape_buffer(start + 4, size, buf2);
|
2011-10-11 12:59:57 +03:00
|
|
|
init_get_bits(&s->gb, buf2, buf_size2 * 8);
|
2012-02-15 14:00:08 +03:00
|
|
|
ff_vc1_decode_entry_point(avctx, v, &s->gb);
|
2009-06-11 12:31:31 +03:00
|
|
|
break;
|
2011-03-21 16:00:43 +02:00
|
|
|
case VC1_CODE_SLICE: {
|
|
|
|
int buf_size3;
|
2019-12-26 03:31:04 +02:00
|
|
|
tmp = av_realloc_array(slices, sizeof(*slices), n_slices+1);
|
2015-08-06 11:20:25 +02:00
|
|
|
if (!tmp) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
2011-10-11 12:59:57 +03:00
|
|
|
goto err;
|
2015-08-06 11:20:25 +02:00
|
|
|
}
|
2012-10-09 17:07:12 +03:00
|
|
|
slices = tmp;
|
2019-10-12 17:54:29 +02:00
|
|
|
slices[n_slices].buf = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE);
|
2015-08-06 11:20:25 +02:00
|
|
|
if (!slices[n_slices].buf) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
2011-10-11 12:59:57 +03:00
|
|
|
goto err;
|
2015-08-06 11:20:25 +02:00
|
|
|
}
|
2022-03-31 19:23:45 +02:00
|
|
|
buf_size3 = v->vc1dsp.vc1_unescape_buffer(start + 4, size,
|
|
|
|
slices[n_slices].buf);
|
2011-03-21 16:00:43 +02:00
|
|
|
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);
|
2016-11-15 11:28:10 +02:00
|
|
|
slices[n_slices].rawbuf = start;
|
|
|
|
slices[n_slices].raw_size = size + 4;
|
2011-03-21 16:00:43 +02:00
|
|
|
n_slices++;
|
|
|
|
break;
|
|
|
|
}
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
|
|
|
}
|
2011-10-11 12:59:57 +03:00
|
|
|
} else if (v->interlace && ((buf[0] & 0xC0) == 0xC0)) { /* WVC1 interlaced stores both fields divided by marker */
|
2009-06-11 12:31:31 +03:00
|
|
|
const uint8_t *divider;
|
2011-12-19 23:08:19 +03:00
|
|
|
int buf_size3;
|
2009-06-11 12:31:31 +03:00
|
|
|
|
|
|
|
divider = find_next_marker(buf, buf + buf_size);
|
2011-10-11 12:59:57 +03:00
|
|
|
if ((divider == (buf + buf_size)) || AV_RB32(divider) != VC1_CODE_FIELD) {
|
2009-06-11 12:31:31 +03:00
|
|
|
av_log(avctx, AV_LOG_ERROR, "Error in WVC1 interlaced frame\n");
|
2015-08-06 11:20:25 +02:00
|
|
|
ret = AVERROR_INVALIDDATA;
|
2011-03-01 18:37:55 +02:00
|
|
|
goto err;
|
2011-10-06 22:00:26 +03:00
|
|
|
} else { // found field marker, unescape second field
|
2017-10-22 04:40:03 +02:00
|
|
|
if (avctx->hwaccel)
|
2012-01-14 00:13:51 +03:00
|
|
|
buf_start_second_field = divider;
|
2019-12-26 03:31:04 +02:00
|
|
|
tmp = av_realloc_array(slices, sizeof(*slices), n_slices+1);
|
2015-08-06 11:20:25 +02:00
|
|
|
if (!tmp) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
2011-12-19 23:08:19 +03:00
|
|
|
goto err;
|
2015-08-06 11:20:25 +02:00
|
|
|
}
|
2011-12-19 23:08:19 +03:00
|
|
|
slices = tmp;
|
2015-06-29 23:48:34 +02:00
|
|
|
slices[n_slices].buf = av_mallocz(buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
|
2015-08-06 11:20:25 +02:00
|
|
|
if (!slices[n_slices].buf) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
2011-12-19 23:08:19 +03:00
|
|
|
goto err;
|
2015-08-06 11:20:25 +02:00
|
|
|
}
|
2022-03-31 19:23:45 +02:00
|
|
|
buf_size3 = v->vc1dsp.vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf);
|
2011-12-19 23:08:19 +03:00
|
|
|
init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
|
|
|
|
buf_size3 << 3);
|
2013-12-14 19:11:21 +03:00
|
|
|
slices[n_slices].mby_start = s->mb_height + 1 >> 1;
|
2016-11-15 11:28:10 +02:00
|
|
|
slices[n_slices].rawbuf = divider;
|
|
|
|
slices[n_slices].raw_size = buf + buf_size - divider;
|
2011-12-19 23:08:19 +03:00
|
|
|
n_slices1 = n_slices - 1;
|
|
|
|
n_slices++;
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
2022-03-31 19:23:45 +02:00
|
|
|
buf_size2 = v->vc1dsp.vc1_unescape_buffer(buf, divider - buf, buf2);
|
2011-10-11 12:59:57 +03:00
|
|
|
} else {
|
2022-03-31 19:23:45 +02:00
|
|
|
buf_size2 = v->vc1dsp.vc1_unescape_buffer(buf, buf_size, buf2);
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
|
|
|
init_get_bits(&s->gb, buf2, buf_size2*8);
|
2021-08-23 20:24:56 +02:00
|
|
|
} else{
|
|
|
|
ret = init_get_bits8(&s->gb, buf, buf_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2011-04-08 21:00:48 +03:00
|
|
|
|
|
|
|
if (v->res_sprite) {
|
2011-10-11 12:59:57 +03:00
|
|
|
v->new_sprite = !get_bits1(&s->gb);
|
|
|
|
v->two_sprites = get_bits1(&s->gb);
|
2012-08-05 12:11:04 +03:00
|
|
|
/* res_sprite means a Windows Media Image stream, AV_CODEC_ID_*IMAGE means
|
2011-08-17 15:24:42 +03:00
|
|
|
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 */
|
2012-08-05 12:11:04 +03:00
|
|
|
if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
|
2011-08-17 15:24:42 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2011-04-08 21:00:48 +03:00
|
|
|
}
|
|
|
|
|
2011-08-27 20:37:26 +03:00
|
|
|
if (s->context_initialized &&
|
|
|
|
(s->width != avctx->coded_width ||
|
|
|
|
s->height != avctx->coded_height)) {
|
2012-08-27 20:21:00 +03:00
|
|
|
ff_vc1_decode_end(avctx);
|
2011-08-27 20:37:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!s->context_initialized) {
|
2015-08-06 11:20:25 +02:00
|
|
|
if ((ret = ff_msmpeg4_decode_init(avctx)) < 0)
|
2012-10-09 17:09:41 +03:00
|
|
|
goto err;
|
2015-08-06 11:20:25 +02:00
|
|
|
if ((ret = ff_vc1_decode_init_alloc_tables(v)) < 0) {
|
2014-08-10 18:25:12 +03:00
|
|
|
ff_mpv_common_end(s);
|
2013-09-20 11:16:57 +03:00
|
|
|
goto err;
|
|
|
|
}
|
2011-08-27 20:37:26 +03:00
|
|
|
|
|
|
|
s->low_delay = !avctx->has_b_frames || v->res_sprite;
|
|
|
|
|
|
|
|
if (v->profile == PROFILE_ADVANCED) {
|
2015-08-06 11:20:25 +02:00
|
|
|
if(avctx->coded_width<=1 || avctx->coded_height<=1) {
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
2012-11-14 21:03:07 +03:00
|
|
|
goto err;
|
2015-08-06 11:20:25 +02:00
|
|
|
}
|
2011-08-27 20:37:26 +03:00
|
|
|
s->h_edge_pos = avctx->coded_width;
|
|
|
|
s->v_edge_pos = avctx->coded_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-11 12:31:31 +03:00
|
|
|
// do parse frame header
|
2011-10-06 22:00:26 +03:00
|
|
|
v->pic_header_flag = 0;
|
2012-11-16 02:48:15 +03:00
|
|
|
v->first_pic_header_flag = 1;
|
2011-10-11 12:59:57 +03:00
|
|
|
if (v->profile < PROFILE_ADVANCED) {
|
2015-08-06 11:20:25 +02:00
|
|
|
if ((ret = ff_vc1_parse_frame_header(v, &s->gb)) < 0) {
|
2011-03-01 18:37:55 +02:00
|
|
|
goto err;
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
|
|
|
} else {
|
2015-08-06 11:20:25 +02:00
|
|
|
if ((ret = ff_vc1_parse_frame_header_adv(v, &s->gb)) < 0) {
|
2011-03-01 18:37:55 +02:00
|
|
|
goto err;
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
|
|
|
}
|
2012-11-16 02:48:15 +03:00
|
|
|
v->first_pic_header_flag = 0;
|
2009-06-11 12:31:31 +03:00
|
|
|
|
2012-08-12 01:27:57 +03:00
|
|
|
if (avctx->debug & FF_DEBUG_PICT_INFO)
|
|
|
|
av_log(v->s.avctx, AV_LOG_DEBUG, "pict_type: %c\n", av_get_picture_type_char(s->pict_type));
|
|
|
|
|
2012-08-05 12:11:04 +03:00
|
|
|
if ((avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE)
|
2011-10-11 12:59:57 +03:00
|
|
|
&& s->pict_type != AV_PICTURE_TYPE_I) {
|
2011-08-17 15:24:42 +03:00
|
|
|
av_log(v->s.avctx, AV_LOG_ERROR, "Sprite decoder: expected I-frame\n");
|
2015-08-06 11:20:25 +02:00
|
|
|
ret = AVERROR_INVALIDDATA;
|
2011-08-17 15:24:42 +03:00
|
|
|
goto err;
|
2010-09-26 16:56:50 +03:00
|
|
|
}
|
2019-12-08 21:18:07 +02:00
|
|
|
if ((avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE)
|
|
|
|
&& v->field_mode) {
|
|
|
|
av_log(v->s.avctx, AV_LOG_ERROR, "Sprite decoder: expected Frames not Fields\n");
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
goto err;
|
|
|
|
}
|
2012-11-12 03:22:31 +03:00
|
|
|
if ((s->mb_height >> v->field_mode) == 0) {
|
|
|
|
av_log(v->s.avctx, AV_LOG_ERROR, "image too short\n");
|
2015-08-06 11:20:25 +02:00
|
|
|
ret = AVERROR_INVALIDDATA;
|
2012-11-12 03:22:31 +03:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2011-04-02 12:56:21 +03:00
|
|
|
// for skipping the frame
|
2014-03-31 20:46:29 +03:00
|
|
|
s->current_picture.f->pict_type = s->pict_type;
|
|
|
|
s->current_picture.f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
|
2009-06-11 12:31:31 +03:00
|
|
|
|
|
|
|
/* skip B-frames if we don't have reference frames */
|
2021-12-12 22:32:21 +02:00
|
|
|
if (!s->last_picture_ptr && s->pict_type == AV_PICTURE_TYPE_B) {
|
2014-04-27 15:50:14 +03:00
|
|
|
av_log(v->s.avctx, AV_LOG_DEBUG, "Skipping B frame without reference frames\n");
|
2014-04-21 20:10:52 +03:00
|
|
|
goto end;
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
2011-10-11 12:59:57 +03:00
|
|
|
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) {
|
2011-03-01 18:37:55 +02:00
|
|
|
goto end;
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
|
|
|
|
2015-08-06 11:20:25 +02:00
|
|
|
if ((ret = ff_mpv_frame_start(s, avctx)) < 0) {
|
2011-03-01 18:37:55 +02:00
|
|
|
goto err;
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
|
|
|
|
2014-02-01 07:34:25 +03:00
|
|
|
v->s.current_picture_ptr->field_picture = v->field_mode;
|
2014-04-09 15:36:47 +03:00
|
|
|
v->s.current_picture_ptr->f->interlaced_frame = (v->fcm != PROGRESSIVE);
|
|
|
|
v->s.current_picture_ptr->f->top_field_first = v->tff;
|
2012-01-14 00:14:36 +03:00
|
|
|
|
2013-11-30 20:36:00 +03:00
|
|
|
// process pulldown flags
|
2014-03-31 20:46:29 +03:00
|
|
|
s->current_picture_ptr->f->repeat_pict = 0;
|
2013-11-30 20:36:00 +03:00
|
|
|
// Pulldown flags are only valid when 'broadcast' has been set.
|
|
|
|
// So ticks_per_frame will be 2
|
|
|
|
if (v->rff) {
|
|
|
|
// repeat field
|
2014-03-31 20:46:29 +03:00
|
|
|
s->current_picture_ptr->f->repeat_pict = 1;
|
2013-11-30 20:36:00 +03:00
|
|
|
} else if (v->rptfrm) {
|
|
|
|
// repeat frames
|
2014-03-31 20:46:29 +03:00
|
|
|
s->current_picture_ptr->f->repeat_pict = v->rptfrm * 2;
|
2013-11-30 20:36:00 +03:00
|
|
|
}
|
|
|
|
|
2014-01-08 16:00:10 +03:00
|
|
|
s->me.qpel_put = s->qdsp.put_qpel_pixels_tab;
|
|
|
|
s->me.qpel_avg = s->qdsp.avg_qpel_pixels_tab;
|
2009-06-11 12:31:31 +03:00
|
|
|
|
2015-08-17 01:35:59 +02:00
|
|
|
if (avctx->hwaccel) {
|
2016-11-15 11:28:10 +02:00
|
|
|
s->mb_y = 0;
|
2012-01-14 00:13:51 +03:00
|
|
|
if (v->field_mode && buf_start_second_field) {
|
|
|
|
// decode first field
|
|
|
|
s->picture_structure = PICT_BOTTOM_FIELD - v->tff;
|
2015-08-06 11:20:25 +02:00
|
|
|
if ((ret = avctx->hwaccel->start_frame(avctx, buf_start, buf_start_second_field - buf_start)) < 0)
|
2012-01-14 00:13:51 +03:00
|
|
|
goto err;
|
2018-05-09 07:50:28 +02:00
|
|
|
|
|
|
|
if (n_slices1 == -1) {
|
|
|
|
// no slices, decode the field as-is
|
|
|
|
if ((ret = avctx->hwaccel->decode_slice(avctx, buf_start, buf_start_second_field - buf_start)) < 0)
|
|
|
|
goto err;
|
|
|
|
} else {
|
|
|
|
if ((ret = avctx->hwaccel->decode_slice(avctx, buf_start, slices[0].rawbuf - buf_start)) < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
for (i = 0 ; i < n_slices1 + 1; i++) {
|
|
|
|
s->gb = slices[i].gb;
|
|
|
|
s->mb_y = slices[i].mby_start;
|
|
|
|
|
|
|
|
v->pic_header_flag = get_bits1(&s->gb);
|
|
|
|
if (v->pic_header_flag) {
|
|
|
|
if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
|
|
|
|
av_log(v->s.avctx, AV_LOG_ERROR, "Slice header damaged\n");
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
if (avctx->err_recognition & AV_EF_EXPLODE)
|
|
|
|
goto err;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret = avctx->hwaccel->decode_slice(avctx, slices[i].rawbuf, slices[i].raw_size)) < 0)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-06 11:20:25 +02:00
|
|
|
if ((ret = avctx->hwaccel->end_frame(avctx)) < 0)
|
2012-01-14 00:13:51 +03:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
// decode second field
|
|
|
|
s->gb = slices[n_slices1 + 1].gb;
|
2018-05-09 07:50:28 +02:00
|
|
|
s->mb_y = slices[n_slices1 + 1].mby_start;
|
2012-01-14 00:13:51 +03:00
|
|
|
s->picture_structure = PICT_TOP_FIELD + v->tff;
|
|
|
|
v->second_field = 1;
|
|
|
|
v->pic_header_flag = 0;
|
|
|
|
if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "parsing header for second field failed");
|
2015-08-06 11:20:25 +02:00
|
|
|
ret = AVERROR_INVALIDDATA;
|
2012-01-14 00:13:51 +03:00
|
|
|
goto err;
|
|
|
|
}
|
2014-04-09 15:36:47 +03:00
|
|
|
v->s.current_picture_ptr->f->pict_type = v->s.pict_type;
|
2012-01-14 00:13:51 +03:00
|
|
|
|
2015-08-06 11:20:25 +02:00
|
|
|
if ((ret = avctx->hwaccel->start_frame(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field)) < 0)
|
2012-01-14 00:13:51 +03:00
|
|
|
goto err;
|
2018-05-09 07:50:28 +02:00
|
|
|
|
|
|
|
if (n_slices - n_slices1 == 2) {
|
|
|
|
// no slices, decode the field as-is
|
|
|
|
if ((ret = avctx->hwaccel->decode_slice(avctx, buf_start_second_field, (buf + buf_size) - buf_start_second_field)) < 0)
|
|
|
|
goto err;
|
|
|
|
} else {
|
|
|
|
if ((ret = avctx->hwaccel->decode_slice(avctx, buf_start_second_field, slices[n_slices1 + 2].rawbuf - buf_start_second_field)) < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
for (i = n_slices1 + 2; i < n_slices; i++) {
|
|
|
|
s->gb = slices[i].gb;
|
|
|
|
s->mb_y = slices[i].mby_start;
|
|
|
|
|
|
|
|
v->pic_header_flag = get_bits1(&s->gb);
|
|
|
|
if (v->pic_header_flag) {
|
|
|
|
if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
|
|
|
|
av_log(v->s.avctx, AV_LOG_ERROR, "Slice header damaged\n");
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
if (avctx->err_recognition & AV_EF_EXPLODE)
|
|
|
|
goto err;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret = avctx->hwaccel->decode_slice(avctx, slices[i].rawbuf, slices[i].raw_size)) < 0)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-06 11:20:25 +02:00
|
|
|
if ((ret = avctx->hwaccel->end_frame(avctx)) < 0)
|
2012-01-14 00:13:51 +03:00
|
|
|
goto err;
|
|
|
|
} else {
|
|
|
|
s->picture_structure = PICT_FRAME;
|
2015-08-06 11:20:25 +02:00
|
|
|
if ((ret = avctx->hwaccel->start_frame(avctx, buf_start, (buf + buf_size) - buf_start)) < 0)
|
2012-01-14 00:13:51 +03:00
|
|
|
goto err;
|
2016-11-15 11:28:10 +02:00
|
|
|
|
|
|
|
if (n_slices == 0) {
|
|
|
|
// no slices, decode the frame as-is
|
|
|
|
if ((ret = avctx->hwaccel->decode_slice(avctx, buf_start, (buf + buf_size) - buf_start)) < 0)
|
|
|
|
goto err;
|
|
|
|
} else {
|
|
|
|
// decode the frame part as the first slice
|
|
|
|
if ((ret = avctx->hwaccel->decode_slice(avctx, buf_start, slices[0].rawbuf - buf_start)) < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
// and process the slices as additional slices afterwards
|
|
|
|
for (i = 0 ; i < n_slices; i++) {
|
|
|
|
s->gb = slices[i].gb;
|
|
|
|
s->mb_y = slices[i].mby_start;
|
|
|
|
|
|
|
|
v->pic_header_flag = get_bits1(&s->gb);
|
|
|
|
if (v->pic_header_flag) {
|
|
|
|
if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
|
|
|
|
av_log(v->s.avctx, AV_LOG_ERROR, "Slice header damaged\n");
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
if (avctx->err_recognition & AV_EF_EXPLODE)
|
|
|
|
goto err;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret = avctx->hwaccel->decode_slice(avctx, slices[i].rawbuf, slices[i].raw_size)) < 0)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
2015-08-06 11:20:25 +02:00
|
|
|
if ((ret = avctx->hwaccel->end_frame(avctx)) < 0)
|
2012-01-14 00:13:51 +03:00
|
|
|
goto err;
|
|
|
|
}
|
2009-06-11 12:31:31 +03:00
|
|
|
} else {
|
2013-02-19 23:40:09 +03:00
|
|
|
int header_ret = 0;
|
|
|
|
|
2013-02-02 22:42:07 +03:00
|
|
|
ff_mpeg_er_frame_start(s);
|
2009-06-11 12:31:31 +03:00
|
|
|
|
2012-08-24 18:45:57 +03:00
|
|
|
v->end_mb_x = s->mb_width;
|
2011-10-06 22:00:26 +03:00
|
|
|
if (v->field_mode) {
|
2014-03-31 20:46:29 +03:00
|
|
|
s->current_picture.f->linesize[0] <<= 1;
|
|
|
|
s->current_picture.f->linesize[1] <<= 1;
|
|
|
|
s->current_picture.f->linesize[2] <<= 1;
|
2011-10-11 12:59:57 +03:00
|
|
|
s->linesize <<= 1;
|
|
|
|
s->uvlinesize <<= 1;
|
2011-10-06 22:00:26 +03:00
|
|
|
}
|
|
|
|
mb_height = s->mb_height >> v->field_mode;
|
2013-08-05 07:30:24 +03:00
|
|
|
|
2013-08-06 17:02:33 +03:00
|
|
|
av_assert0 (mb_height > 0);
|
2013-08-05 07:30:24 +03:00
|
|
|
|
2011-03-21 16:00:43 +02:00
|
|
|
for (i = 0; i <= n_slices; i++) {
|
2011-10-06 22:00:26 +03:00
|
|
|
if (i > 0 && slices[i - 1].mby_start >= mb_height) {
|
2012-07-28 14:14:50 +03:00
|
|
|
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);
|
2012-04-19 12:02:22 +03:00
|
|
|
continue;
|
|
|
|
}
|
2011-10-06 22:00:26 +03:00
|
|
|
v->second_field = 1;
|
2013-12-14 16:52:31 +03:00
|
|
|
av_assert0((s->mb_height & 1) == 0);
|
2013-02-01 01:20:15 +03:00
|
|
|
v->blocks_off = s->b8_stride * (s->mb_height&~1);
|
2011-10-06 22:00:26 +03:00
|
|
|
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;
|
2012-03-27 14:21:56 +03:00
|
|
|
if (v->field_mode && i == n_slices1 + 2) {
|
2013-02-19 23:40:09 +03:00
|
|
|
if ((header_ret = ff_vc1_parse_frame_header_adv(v, &s->gb)) < 0) {
|
2012-07-28 14:14:48 +03:00
|
|
|
av_log(v->s.avctx, AV_LOG_ERROR, "Field header damaged\n");
|
2015-08-06 11:20:25 +02:00
|
|
|
ret = AVERROR_INVALIDDATA;
|
2013-09-22 14:50:48 +03:00
|
|
|
if (avctx->err_recognition & AV_EF_EXPLODE)
|
|
|
|
goto err;
|
2012-03-27 14:21:56 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if (get_bits1(&s->gb)) {
|
2011-10-06 22:00:26 +03:00
|
|
|
v->pic_header_flag = 1;
|
2013-02-19 23:40:09 +03:00
|
|
|
if ((header_ret = ff_vc1_parse_frame_header_adv(v, &s->gb)) < 0) {
|
2012-07-28 14:14:48 +03:00
|
|
|
av_log(v->s.avctx, AV_LOG_ERROR, "Slice header damaged\n");
|
2015-08-06 11:20:25 +02:00
|
|
|
ret = AVERROR_INVALIDDATA;
|
2013-09-22 14:50:48 +03:00
|
|
|
if (avctx->err_recognition & AV_EF_EXPLODE)
|
|
|
|
goto err;
|
2012-03-27 14:21:56 +03:00
|
|
|
continue;
|
|
|
|
}
|
2011-10-06 22:00:26 +03:00
|
|
|
}
|
|
|
|
}
|
2013-02-19 23:40:09 +03:00
|
|
|
if (header_ret < 0)
|
|
|
|
continue;
|
2011-10-06 22:00:26 +03:00
|
|
|
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);
|
2012-11-14 19:34:37 +03:00
|
|
|
else {
|
|
|
|
if (i >= n_slices) {
|
|
|
|
av_log(v->s.avctx, AV_LOG_ERROR, "first field slice count too large\n");
|
|
|
|
continue;
|
|
|
|
}
|
2018-05-18 17:06:32 +02:00
|
|
|
s->end_mb_y = (i == n_slices1 + 1) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height);
|
2012-11-14 19:34:37 +03:00
|
|
|
}
|
2012-04-16 14:35:41 +03:00
|
|
|
if (s->end_mb_y <= s->start_mb_y) {
|
|
|
|
av_log(v->s.avctx, AV_LOG_ERROR, "end mb y %d %d invalid\n", s->end_mb_y, s->start_mb_y);
|
|
|
|
continue;
|
|
|
|
}
|
2018-06-20 15:17:34 +02:00
|
|
|
if (((s->pict_type == AV_PICTURE_TYPE_P && !v->p_frame_skipped) ||
|
|
|
|
(s->pict_type == AV_PICTURE_TYPE_B && !v->bi_type)) &&
|
|
|
|
!v->cbpcy_vlc) {
|
2013-01-12 05:40:54 +03:00
|
|
|
av_log(v->s.avctx, AV_LOG_ERROR, "missing cbpcy_vlc\n");
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-27 20:21:00 +03:00
|
|
|
ff_vc1_decode_blocks(v);
|
2019-12-08 20:37:46 +02:00
|
|
|
if (i != n_slices) {
|
2011-10-06 22:00:26 +03:00
|
|
|
s->gb = slices[i].gb;
|
2019-12-08 20:37:46 +02:00
|
|
|
}
|
2011-10-06 22:00:26 +03:00
|
|
|
}
|
|
|
|
if (v->field_mode) {
|
|
|
|
v->second_field = 0;
|
2014-03-31 20:46:29 +03:00
|
|
|
s->current_picture.f->linesize[0] >>= 1;
|
|
|
|
s->current_picture.f->linesize[1] >>= 1;
|
|
|
|
s->current_picture.f->linesize[2] >>= 1;
|
2011-10-11 12:59:57 +03:00
|
|
|
s->linesize >>= 1;
|
|
|
|
s->uvlinesize >>= 1;
|
2013-04-24 14:51:10 +03:00
|
|
|
if (v->s.pict_type != AV_PICTURE_TYPE_BI && v->s.pict_type != AV_PICTURE_TYPE_B) {
|
2013-04-25 03:31:58 +03:00
|
|
|
FFSWAP(uint8_t *, v->mv_f_next[0], v->mv_f[0]);
|
|
|
|
FFSWAP(uint8_t *, v->mv_f_next[1], v->mv_f[1]);
|
2013-04-24 14:51:10 +03:00
|
|
|
}
|
2011-03-21 16:00:43 +02:00
|
|
|
}
|
2015-03-16 10:57:36 +02:00
|
|
|
ff_dlog(s->avctx, "Consumed %i/%i bits\n",
|
2012-08-21 13:41:40 +03:00
|
|
|
get_bits_count(&s->gb), s->gb.size_in_bits);
|
2011-10-11 12:59:57 +03:00
|
|
|
// if (get_bits_count(&s->gb) > buf_size * 8)
|
2009-06-11 12:31:31 +03:00
|
|
|
// return -1;
|
2015-08-06 11:20:25 +02:00
|
|
|
if(s->er.error_occurred && s->pict_type == AV_PICTURE_TYPE_B) {
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
2011-11-25 22:55:25 +03:00
|
|
|
goto err;
|
2015-08-06 11:20:25 +02:00
|
|
|
}
|
2021-07-31 00:01:53 +02:00
|
|
|
if ( !v->field_mode
|
|
|
|
&& avctx->codec_id != AV_CODEC_ID_WMV3IMAGE
|
|
|
|
&& avctx->codec_id != AV_CODEC_ID_VC1IMAGE)
|
2013-02-16 20:46:28 +03:00
|
|
|
ff_er_frame_end(&s->er);
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
|
|
|
|
2014-08-10 18:25:12 +03:00
|
|
|
ff_mpv_frame_end(s);
|
2009-06-11 12:31:31 +03:00
|
|
|
|
2012-08-05 12:11:04 +03:00
|
|
|
if (avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || avctx->codec_id == AV_CODEC_ID_VC1IMAGE) {
|
2011-08-17 15:24:42 +03:00
|
|
|
image:
|
|
|
|
avctx->width = avctx->coded_width = v->output_width;
|
|
|
|
avctx->height = avctx->coded_height = v->output_height;
|
2011-10-11 12:59:57 +03:00
|
|
|
if (avctx->skip_frame >= AVDISCARD_NONREF)
|
|
|
|
goto end;
|
2020-12-22 18:21:48 +02:00
|
|
|
if (!v->sprite_output_frame &&
|
|
|
|
!(v->sprite_output_frame = av_frame_alloc())) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto err;
|
|
|
|
}
|
2011-08-17 15:24:42 +03:00
|
|
|
#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
|
2015-08-06 11:20:25 +02:00
|
|
|
if ((ret = vc1_decode_sprites(v, &s->gb)) < 0)
|
2011-10-11 12:59:57 +03:00
|
|
|
goto err;
|
2011-08-17 15:24:42 +03:00
|
|
|
#endif
|
2013-11-09 12:14:46 +03:00
|
|
|
if ((ret = av_frame_ref(pict, v->sprite_output_frame)) < 0)
|
2012-11-21 23:34:46 +03:00
|
|
|
goto err;
|
2012-11-13 21:35:22 +03:00
|
|
|
*got_frame = 1;
|
2011-08-17 15:24:42 +03:00
|
|
|
} else {
|
2011-10-11 12:59:57 +03:00
|
|
|
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
|
2014-03-31 20:46:29 +03:00
|
|
|
if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0)
|
2012-11-21 23:34:46 +03:00
|
|
|
goto err;
|
2021-08-08 20:46:32 +02:00
|
|
|
if (!v->field_mode)
|
|
|
|
ff_print_debug_info(s, s->current_picture_ptr, pict);
|
2013-11-15 17:33:20 +03:00
|
|
|
*got_frame = 1;
|
2014-08-14 23:31:25 +03:00
|
|
|
} else if (s->last_picture_ptr) {
|
2014-03-31 20:46:29 +03:00
|
|
|
if ((ret = av_frame_ref(pict, s->last_picture_ptr->f)) < 0)
|
2012-11-21 23:34:46 +03:00
|
|
|
goto err;
|
2021-08-08 20:46:32 +02:00
|
|
|
if (!v->field_mode)
|
|
|
|
ff_print_debug_info(s, s->last_picture_ptr, pict);
|
2012-11-13 21:35:22 +03:00
|
|
|
*got_frame = 1;
|
2011-10-11 12:59:57 +03:00
|
|
|
}
|
2011-08-17 15:24:42 +03:00
|
|
|
}
|
|
|
|
|
2011-03-01 18:37:55 +02:00
|
|
|
end:
|
2009-06-11 12:31:31 +03:00
|
|
|
av_free(buf2);
|
2011-03-21 16:00:43 +02:00
|
|
|
for (i = 0; i < n_slices; i++)
|
|
|
|
av_free(slices[i].buf);
|
|
|
|
av_free(slices);
|
2009-06-11 12:31:31 +03:00
|
|
|
return buf_size;
|
2011-03-01 18:37:55 +02:00
|
|
|
|
|
|
|
err:
|
|
|
|
av_free(buf2);
|
2011-03-21 16:00:43 +02:00
|
|
|
for (i = 0; i < n_slices; i++)
|
|
|
|
av_free(slices[i].buf);
|
|
|
|
av_free(slices);
|
2015-08-06 11:20:25 +02:00
|
|
|
return ret;
|
2009-06-11 12:31:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-18 19:15:52 +03:00
|
|
|
static const enum AVPixelFormat vc1_hwaccel_pixfmt_list_420[] = {
|
2014-03-25 23:19:58 +03:00
|
|
|
#if CONFIG_VC1_DXVA2_HWACCEL
|
2013-02-18 19:15:52 +03:00
|
|
|
AV_PIX_FMT_DXVA2_VLD,
|
|
|
|
#endif
|
2015-05-11 10:52:47 +02:00
|
|
|
#if CONFIG_VC1_D3D11VA_HWACCEL
|
|
|
|
AV_PIX_FMT_D3D11VA_VLD,
|
2017-06-07 17:11:17 +02:00
|
|
|
AV_PIX_FMT_D3D11,
|
2015-05-11 10:52:47 +02:00
|
|
|
#endif
|
2017-11-14 07:09:27 +02:00
|
|
|
#if CONFIG_VC1_NVDEC_HWACCEL
|
|
|
|
AV_PIX_FMT_CUDA,
|
|
|
|
#endif
|
2014-03-25 23:19:58 +03:00
|
|
|
#if CONFIG_VC1_VAAPI_HWACCEL
|
2015-07-28 10:16:59 +02:00
|
|
|
AV_PIX_FMT_VAAPI,
|
2013-02-18 19:15:52 +03:00
|
|
|
#endif
|
2014-03-25 23:19:58 +03:00
|
|
|
#if CONFIG_VC1_VDPAU_HWACCEL
|
2013-02-18 19:15:52 +03:00
|
|
|
AV_PIX_FMT_VDPAU,
|
|
|
|
#endif
|
|
|
|
AV_PIX_FMT_YUV420P,
|
|
|
|
AV_PIX_FMT_NONE
|
|
|
|
};
|
|
|
|
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_vc1_decoder = {
|
|
|
|
.p.name = "vc1",
|
2022-08-29 13:38:02 +02:00
|
|
|
CODEC_LONG_NAME("SMPTE VC-1"),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.p.id = AV_CODEC_ID_VC1,
|
2011-07-17 13:54:31 +03:00
|
|
|
.priv_data_size = sizeof(VC1Context),
|
|
|
|
.init = vc1_decode_init,
|
2012-08-27 20:21:00 +03:00
|
|
|
.close = ff_vc1_decode_end,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_DECODE_CB(vc1_decode_frame),
|
2012-09-27 20:25:06 +03:00
|
|
|
.flush = ff_mpeg_flush,
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
|
|
|
|
.p.pix_fmts = vc1_hwaccel_pixfmt_list_420,
|
2020-12-27 18:36:59 +02:00
|
|
|
.hw_configs = (const AVCodecHWConfigInternal *const []) {
|
2017-11-27 03:22:17 +02:00
|
|
|
#if CONFIG_VC1_DXVA2_HWACCEL
|
|
|
|
HWACCEL_DXVA2(vc1),
|
2017-10-26 01:18:40 +02:00
|
|
|
#endif
|
2017-11-27 03:22:17 +02:00
|
|
|
#if CONFIG_VC1_D3D11VA_HWACCEL
|
|
|
|
HWACCEL_D3D11VA(vc1),
|
2017-10-26 01:18:40 +02:00
|
|
|
#endif
|
2017-11-27 03:22:17 +02:00
|
|
|
#if CONFIG_VC1_D3D11VA2_HWACCEL
|
|
|
|
HWACCEL_D3D11VA2(vc1),
|
2017-10-26 01:18:40 +02:00
|
|
|
#endif
|
2017-11-27 03:22:17 +02:00
|
|
|
#if CONFIG_VC1_NVDEC_HWACCEL
|
|
|
|
HWACCEL_NVDEC(vc1),
|
2017-10-26 01:18:40 +02:00
|
|
|
#endif
|
2017-11-27 03:22:17 +02:00
|
|
|
#if CONFIG_VC1_VAAPI_HWACCEL
|
|
|
|
HWACCEL_VAAPI(vc1),
|
2017-10-26 01:18:40 +02:00
|
|
|
#endif
|
2017-11-27 03:22:17 +02:00
|
|
|
#if CONFIG_VC1_VDPAU_HWACCEL
|
|
|
|
HWACCEL_VDPAU(vc1),
|
2017-10-26 01:18:40 +02:00
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
},
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.profiles = NULL_IF_CONFIG_SMALL(ff_vc1_profiles)
|
2009-06-11 12:31:31 +03:00
|
|
|
};
|
|
|
|
|
2009-07-29 14:31:52 +03:00
|
|
|
#if CONFIG_WMV3_DECODER
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_wmv3_decoder = {
|
|
|
|
.p.name = "wmv3",
|
2022-08-29 13:38:02 +02:00
|
|
|
CODEC_LONG_NAME("Windows Media Video 9"),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.p.id = AV_CODEC_ID_WMV3,
|
2011-07-17 13:54:31 +03:00
|
|
|
.priv_data_size = sizeof(VC1Context),
|
|
|
|
.init = vc1_decode_init,
|
2012-08-27 20:21:00 +03:00
|
|
|
.close = ff_vc1_decode_end,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_DECODE_CB(vc1_decode_frame),
|
2012-09-27 20:25:06 +03:00
|
|
|
.flush = ff_mpeg_flush,
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
|
|
|
|
.p.pix_fmts = vc1_hwaccel_pixfmt_list_420,
|
2020-12-27 18:36:59 +02:00
|
|
|
.hw_configs = (const AVCodecHWConfigInternal *const []) {
|
2017-11-27 03:22:17 +02:00
|
|
|
#if CONFIG_WMV3_DXVA2_HWACCEL
|
2017-10-26 01:18:40 +02:00
|
|
|
HWACCEL_DXVA2(wmv3),
|
|
|
|
#endif
|
2017-11-27 03:22:17 +02:00
|
|
|
#if CONFIG_WMV3_D3D11VA_HWACCEL
|
2017-10-26 01:18:40 +02:00
|
|
|
HWACCEL_D3D11VA(wmv3),
|
|
|
|
#endif
|
2017-11-27 03:22:17 +02:00
|
|
|
#if CONFIG_WMV3_D3D11VA2_HWACCEL
|
2017-10-26 01:18:40 +02:00
|
|
|
HWACCEL_D3D11VA2(wmv3),
|
|
|
|
#endif
|
2017-11-27 03:22:17 +02:00
|
|
|
#if CONFIG_WMV3_NVDEC_HWACCEL
|
2017-10-26 01:18:40 +02:00
|
|
|
HWACCEL_NVDEC(wmv3),
|
|
|
|
#endif
|
2017-11-27 03:22:17 +02:00
|
|
|
#if CONFIG_WMV3_VAAPI_HWACCEL
|
2017-10-26 01:18:40 +02:00
|
|
|
HWACCEL_VAAPI(wmv3),
|
|
|
|
#endif
|
2017-11-27 03:22:17 +02:00
|
|
|
#if CONFIG_WMV3_VDPAU_HWACCEL
|
2017-10-26 01:18:40 +02:00
|
|
|
HWACCEL_VDPAU(wmv3),
|
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
},
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.profiles = NULL_IF_CONFIG_SMALL(ff_vc1_profiles)
|
2009-06-11 12:31:31 +03:00
|
|
|
};
|
2009-07-29 14:31:52 +03:00
|
|
|
#endif
|
2009-06-11 12:31:31 +03:00
|
|
|
|
2011-08-17 15:24:42 +03:00
|
|
|
#if CONFIG_WMV3IMAGE_DECODER
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_wmv3image_decoder = {
|
|
|
|
.p.name = "wmv3image",
|
2022-08-29 13:38:02 +02:00
|
|
|
CODEC_LONG_NAME("Windows Media Video 9 Image"),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.p.id = AV_CODEC_ID_WMV3IMAGE,
|
2011-08-17 15:24:42 +03:00
|
|
|
.priv_data_size = sizeof(VC1Context),
|
|
|
|
.init = vc1_decode_init,
|
2012-08-27 20:21:00 +03:00
|
|
|
.close = ff_vc1_decode_end,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_DECODE_CB(vc1_decode_frame),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.capabilities = AV_CODEC_CAP_DR1,
|
2011-08-17 15:24:42 +03:00
|
|
|
.flush = vc1_sprite_flush,
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.pix_fmts = (const enum AVPixelFormat[]) {
|
2014-03-17 20:03:47 +03:00
|
|
|
AV_PIX_FMT_YUV420P,
|
|
|
|
AV_PIX_FMT_NONE
|
|
|
|
},
|
2011-08-17 15:24:42 +03:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_VC1IMAGE_DECODER
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_vc1image_decoder = {
|
|
|
|
.p.name = "vc1image",
|
2022-08-29 13:38:02 +02:00
|
|
|
CODEC_LONG_NAME("Windows Media Video 9 Image v2"),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.p.id = AV_CODEC_ID_VC1IMAGE,
|
2011-08-17 15:24:42 +03:00
|
|
|
.priv_data_size = sizeof(VC1Context),
|
|
|
|
.init = vc1_decode_init,
|
2012-08-27 20:21:00 +03:00
|
|
|
.close = ff_vc1_decode_end,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_DECODE_CB(vc1_decode_frame),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.capabilities = AV_CODEC_CAP_DR1,
|
2011-08-17 15:24:42 +03:00
|
|
|
.flush = vc1_sprite_flush,
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.pix_fmts = (const enum AVPixelFormat[]) {
|
2014-03-17 20:03:47 +03:00
|
|
|
AV_PIX_FMT_YUV420P,
|
|
|
|
AV_PIX_FMT_NONE
|
|
|
|
},
|
2011-08-17 15:24:42 +03:00
|
|
|
};
|
|
|
|
#endif
|