*/
#include "libavutil/attributes.h"
+#include "libavutil/thread.h"
#include "internal.h"
#include "avcodec.h"
#include "mpegvideo.h"
v->multires = get_bits1(gb);
v->res_fasttx = get_bits1(gb);
if (!v->res_fasttx) {
- v->vc1dsp.vc1_inv_trans_8x8 = ff_simple_idct_8;
+ v->vc1dsp.vc1_inv_trans_8x8 = ff_simple_idct_int16_8bit;
v->vc1dsp.vc1_inv_trans_8x4 = ff_simple_idct84_add;
v->vc1dsp.vc1_inv_trans_4x8 = ff_simple_idct48_add;
v->vc1dsp.vc1_inv_trans_4x4 = ff_simple_idct44_add;
- v->vc1dsp.vc1_inv_trans_8x8_dc = ff_simple_idct_add_8;
+ v->vc1dsp.vc1_inv_trans_8x8_dc = ff_simple_idct_add_int16_8bit;
v->vc1dsp.vc1_inv_trans_8x4_dc = ff_simple_idct84_add;
v->vc1dsp.vc1_inv_trans_4x8_dc = ff_simple_idct48_add;
v->vc1dsp.vc1_inv_trans_4x4_dc = ff_simple_idct44_add;
} else {
v->res_rtm_flag = get_bits1(gb); //reserved
}
- if (!v->res_rtm_flag) {
- av_log(avctx, AV_LOG_ERROR,
- "Old WMV3 version detected, some frames may be decoded incorrectly\n");
- //return -1;
- }
//TODO: figure out what they mean (always 0x402F)
if (!v->res_fasttx)
skip_bits(gb, 16);
h = get_bits(gb, 8) + 1;
v->s.avctx->sample_aspect_ratio = (AVRational){w, h};
} else {
- av_reduce(&v->s.avctx->sample_aspect_ratio.num,
+ if (v->s.avctx->width > v->max_coded_width ||
+ v->s.avctx->height > v->max_coded_height) {
+ avpriv_request_sample(v->s.avctx, "Huge resolution");
+ } else
+ av_reduce(&v->s.avctx->sample_aspect_ratio.num,
&v->s.avctx->sample_aspect_ratio.den,
v->s.avctx->height * w,
v->s.avctx->width * h,
int pqindex, lowquant, status;
v->field_mode = 0;
- v->fcm = 0;
+ v->fcm = PROGRESSIVE;
if (v->finterpflag)
v->interpfrm = get_bits1(gb);
if (!v->s.avctx->codec)
/* Hopefully this is correct for P-frames */
v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
- v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
+ v->cbptab = get_bits(gb, 2);
+ v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[v->cbptab];
if (v->dquant) {
av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
"Imode: %i, Invert: %i\n", status>>1, status&1);
v->s.mv_table_index = get_bits(gb, 2);
- v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
+ v->cbptab = get_bits(gb, 2);
+ v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[v->cbptab];
if (v->dquant) {
av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
{
int pqindex, lowquant;
int status;
- int mbmodetab, imvtab, icbptab, twomvbptab, fourmvbptab; /* useful only for debugging */
int field_mode, fcm;
v->numref = 0;
else if ((v->s.pict_type != AV_PICTURE_TYPE_B) && (v->s.pict_type != AV_PICTURE_TYPE_BI)) {
v->refdist = get_bits(gb, 2);
if (v->refdist == 3)
- v->refdist += get_unary(gb, 0, 16);
+ v->refdist += get_unary(gb, 0, 14);
+ if (v->refdist > 16)
+ return AVERROR_INVALIDDATA;
}
if ((v->s.pict_type == AV_PICTURE_TYPE_B) || (v->s.pict_type == AV_PICTURE_TYPE_BI)) {
if (read_bfraction(v, gb) < 0)
v->pquantizer = 1;
break;
}
+ v->dquantfrm = 0;
if (v->postprocflag)
v->postproc = get_bits(gb, 2);
return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "FIELDTX plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
- }
+ } else
+ v->fieldtx_is_raw = 0;
status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v);
if (status < 0)
return -1;
v->last_use_ic = 1;
}
status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
+ if (status < 0)
+ return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "SKIPMB plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
- mbmodetab = get_bits(gb, 2);
+ v->mbmodetab = get_bits(gb, 2);
if (v->fourmvswitch)
- v->mbmode_vlc = &ff_vc1_intfr_4mv_mbmode_vlc[mbmodetab];
+ v->mbmode_vlc = &ff_vc1_intfr_4mv_mbmode_vlc[v->mbmodetab];
else
- v->mbmode_vlc = &ff_vc1_intfr_non4mv_mbmode_vlc[mbmodetab];
- imvtab = get_bits(gb, 2);
- v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[imvtab];
+ v->mbmode_vlc = &ff_vc1_intfr_non4mv_mbmode_vlc[v->mbmodetab];
+ v->imvtab = get_bits(gb, 2);
+ v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[v->imvtab];
// interlaced p-picture cbpcy range is [1, 63]
- icbptab = get_bits(gb, 3);
- v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab];
- twomvbptab = get_bits(gb, 2);
- v->twomvbp_vlc = &ff_vc1_2mv_block_pattern_vlc[twomvbptab];
+ v->icbptab = get_bits(gb, 3);
+ v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[v->icbptab];
+ v->twomvbptab = get_bits(gb, 2);
+ v->twomvbp_vlc = &ff_vc1_2mv_block_pattern_vlc[v->twomvbptab];
if (v->fourmvswitch) {
- fourmvbptab = get_bits(gb, 2);
- v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab];
+ v->fourmvbptab = get_bits(gb, 2);
+ v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
}
}
}
/* Hopefully this is correct for P-frames */
v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
- v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
+ v->cbptab = get_bits(gb, 2);
+ v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[v->cbptab];
} else if (v->fcm == ILACE_FRAME) { // frame interlaced
v->qs_last = v->s.quarter_sample;
v->s.quarter_sample = 1;
v->s.mspel = 1;
} else { // field interlaced
- mbmodetab = get_bits(gb, 3);
- imvtab = get_bits(gb, 2 + v->numref);
+ v->mbmodetab = get_bits(gb, 3);
+ v->imvtab = get_bits(gb, 2 + v->numref);
if (!v->numref)
- v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[imvtab];
+ v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[v->imvtab];
else
- v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[imvtab];
- icbptab = get_bits(gb, 3);
- v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab];
+ v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[v->imvtab];
+ v->icbptab = get_bits(gb, 3);
+ v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[v->icbptab];
if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
v->mv_mode2 == MV_PMODE_MIXED_MV) || v->mv_mode == MV_PMODE_MIXED_MV) {
- fourmvbptab = get_bits(gb, 2);
- v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab];
- v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[mbmodetab];
+ v->fourmvbptab = get_bits(gb, 2);
+ v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
+ v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[v->mbmodetab];
} else {
- v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[mbmodetab];
+ v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[v->mbmodetab];
}
}
if (v->dquant) {
v->mv_mode = ff_vc1_mv_pmode_table2[lowquant][mvmode];
v->qs_last = v->s.quarter_sample;
v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV || v->mv_mode == MV_PMODE_MIXED_MV);
- v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || v->mv_mode == MV_PMODE_1MV_HPEL);
+ v->s.mspel = (v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
status = bitplane_decoding(v->forward_mb_plane, &v->fmb_is_raw, v);
if (status < 0)
return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "MB Forward Type plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
- mbmodetab = get_bits(gb, 3);
+ v->mbmodetab = get_bits(gb, 3);
if (v->mv_mode == MV_PMODE_MIXED_MV)
- v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[mbmodetab];
+ v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[v->mbmodetab];
else
- v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[mbmodetab];
- imvtab = get_bits(gb, 3);
- v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[imvtab];
- icbptab = get_bits(gb, 3);
- v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab];
+ v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[v->mbmodetab];
+ v->imvtab = get_bits(gb, 3);
+ v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[v->imvtab];
+ v->icbptab = get_bits(gb, 3);
+ v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[v->icbptab];
if (v->mv_mode == MV_PMODE_MIXED_MV) {
- fourmvbptab = get_bits(gb, 2);
- v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab];
+ v->fourmvbptab = get_bits(gb, 2);
+ v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
}
v->numref = 1; // interlaced field B pictures are always 2-ref
} else if (v->fcm == ILACE_FRAME) {
return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
- mbmodetab = get_bits(gb, 2);
- v->mbmode_vlc = &ff_vc1_intfr_non4mv_mbmode_vlc[mbmodetab];
- imvtab = get_bits(gb, 2);
- v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[imvtab];
+ v->mbmodetab = get_bits(gb, 2);
+ v->mbmode_vlc = &ff_vc1_intfr_non4mv_mbmode_vlc[v->mbmodetab];
+ v->imvtab = get_bits(gb, 2);
+ v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[v->imvtab];
// interlaced p/b-picture cbpcy range is [1, 63]
- icbptab = get_bits(gb, 3);
- v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab];
- twomvbptab = get_bits(gb, 2);
- v->twomvbp_vlc = &ff_vc1_2mv_block_pattern_vlc[twomvbptab];
- fourmvbptab = get_bits(gb, 2);
- v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab];
+ v->icbptab = get_bits(gb, 3);
+ v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[v->icbptab];
+ v->twomvbptab = get_bits(gb, 2);
+ v->twomvbp_vlc = &ff_vc1_2mv_block_pattern_vlc[v->twomvbptab];
+ v->fourmvbptab = get_bits(gb, 2);
+ v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
} else {
v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
v->qs_last = v->s.quarter_sample;
av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
v->s.mv_table_index = get_bits(gb, 2);
- v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
+ v->cbptab = get_bits(gb, 2);
+ v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[v->cbptab];
}
if (v->dquant) {
break;
}
- if (v->fcm != PROGRESSIVE && !v->s.quarter_sample) {
- v->range_x <<= 1;
- v->range_y <<= 1;
- }
/* AC Syntax */
v->c_ac_table_index = decode012(gb);
if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) {
v->y_ac_table_index = decode012(gb);
}
+ else if (v->fcm != PROGRESSIVE && !v->s.quarter_sample) {
+ v->range_x <<= 1;
+ v->range_y <<= 1;
+ }
+
/* DC Syntax */
v->s.dc_table_index = get_bits1(gb);
if ((v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
31714, 31746, 31778, 32306, 32340, 32372
};
-/**
- * Init VC-1 specific tables and VC1Context members
- * @param v The VC1Context to initialize
- * @return Status
- */
-av_cold int ff_vc1_init_common(VC1Context *v)
+static av_cold void vc1_init_static(void)
{
- static int done = 0;
int i = 0;
static VLC_TYPE vlc_table[32372][2];
- v->hrd_rate = v->hrd_buffer = NULL;
-
- /* VLC tables */
- if (!done) {
INIT_VLC_STATIC(&ff_vc1_bfraction_vlc, VC1_BFRACTION_VLC_BITS, 23,
ff_vc1_bfraction_bits, 1, 1,
ff_vc1_bfraction_codes, 1, 1, 1 << VC1_BFRACTION_VLC_BITS);
ff_vc1_if_1mv_mbmode_bits[i], 1, 1,
ff_vc1_if_1mv_mbmode_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
}
- done = 1;
- }
+}
- /* Other defaults */
+/**
+ * Init VC-1 specific tables and VC1Context members
+ * @param v The VC1Context to initialize
+ * @return Status
+ */
+av_cold void ff_vc1_init_common(VC1Context *v)
+{
+ static AVOnce init_static_once = AV_ONCE_INIT;
+
+ /* defaults */
v->pq = -1;
v->mvrange = 0; /* 7.1.1.18, p80 */
ff_vc1dsp_init(&v->vc1dsp);
- return 0;
+ /* VLC tables */
+ ff_thread_once(&init_static_once, vc1_init_static);
}