You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avcodec/mpegvideo: Move MSMPEG4 fields to MSMPEG4 contexts
Several fields are not used by any generic code and can therefore be moved to more specialized contexts. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@ -372,11 +372,6 @@ typedef struct MpegEncContext {
|
||||
int esc_pos;
|
||||
|
||||
/* MSMPEG4 specific */
|
||||
int mv_table_index;
|
||||
int rl_table_index;
|
||||
int rl_chroma_table_index;
|
||||
int dc_table_index;
|
||||
int use_skip_mb_code;
|
||||
int slice_height; ///< in macroblocks
|
||||
int first_slice_line; ///< used in MPEG-4 too to handle resync markers
|
||||
int flipflop_rounding;
|
||||
@ -389,9 +384,7 @@ typedef struct MpegEncContext {
|
||||
MSMP4_WMV2,
|
||||
MSMP4_VC1, ///< for VC1 (image), WMV3 (image) and MSS2.
|
||||
} msmpeg4_version;
|
||||
int per_mb_rl_table;
|
||||
int esc3_level_length;
|
||||
int esc3_run_length;
|
||||
int inter_intra_pred;
|
||||
int mspel;
|
||||
|
||||
|
@ -107,11 +107,12 @@ static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code)
|
||||
|
||||
static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
|
||||
{
|
||||
MSMP4DecContext *const ms = mpv_to_msmpeg4(s);
|
||||
int cbp, code, i;
|
||||
uint32_t * const mb_type_ptr = &s->cur_pic.mb_type[s->mb_x + s->mb_y*s->mb_stride];
|
||||
|
||||
if (s->pict_type == AV_PICTURE_TYPE_P) {
|
||||
if (s->use_skip_mb_code) {
|
||||
if (ms->use_skip_mb_code) {
|
||||
if (get_bits1(&s->gb)) {
|
||||
/* skip mb */
|
||||
s->mb_intra = 0;
|
||||
@ -198,7 +199,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
|
||||
|
||||
s->bdsp.clear_blocks(s->block[0]);
|
||||
for (i = 0; i < 6; i++) {
|
||||
if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
|
||||
if (ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
|
||||
{
|
||||
av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
|
||||
return -1;
|
||||
@ -209,6 +210,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
|
||||
|
||||
static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
|
||||
{
|
||||
MSMP4DecContext *const ms = mpv_to_msmpeg4(s);
|
||||
int cbp, code, i;
|
||||
uint8_t *coded_val;
|
||||
uint32_t * const mb_type_ptr = &s->cur_pic.mb_type[s->mb_x + s->mb_y*s->mb_stride];
|
||||
@ -217,7 +219,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
if (s->pict_type == AV_PICTURE_TYPE_P) {
|
||||
if (s->use_skip_mb_code) {
|
||||
if (ms->use_skip_mb_code) {
|
||||
if (get_bits1(&s->gb)) {
|
||||
/* skip mb */
|
||||
s->mb_intra = 0;
|
||||
@ -257,12 +259,12 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
|
||||
|
||||
if (!s->mb_intra) {
|
||||
int mx, my;
|
||||
if(s->per_mb_rl_table && cbp){
|
||||
s->rl_table_index = decode012(&s->gb);
|
||||
s->rl_chroma_table_index = s->rl_table_index;
|
||||
if (ms->per_mb_rl_table && cbp) {
|
||||
ms->rl_table_index = decode012(&s->gb);
|
||||
ms->rl_chroma_table_index = ms->rl_table_index;
|
||||
}
|
||||
ff_h263_pred_motion(s, 0, 0, &mx, &my);
|
||||
ff_msmpeg4_decode_motion(s, &mx, &my);
|
||||
ff_msmpeg4_decode_motion(ms, &mx, &my);
|
||||
s->mv_dir = MV_DIR_FORWARD;
|
||||
s->mv_type = MV_TYPE_16X16;
|
||||
s->mv[0][0][0] = mx;
|
||||
@ -279,15 +281,15 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
|
||||
ff_dlog(s->avctx, "%d%d %d %d/",
|
||||
s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
|
||||
}
|
||||
if(s->per_mb_rl_table && cbp){
|
||||
s->rl_table_index = decode012(&s->gb);
|
||||
s->rl_chroma_table_index = s->rl_table_index;
|
||||
if (ms->per_mb_rl_table && cbp) {
|
||||
ms->rl_table_index = decode012(&s->gb);
|
||||
ms->rl_chroma_table_index = ms->rl_table_index;
|
||||
}
|
||||
}
|
||||
|
||||
s->bdsp.clear_blocks(s->block[0]);
|
||||
for (i = 0; i < 6; i++) {
|
||||
if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
|
||||
if (ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
|
||||
{
|
||||
av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
|
||||
return -1;
|
||||
@ -443,31 +445,31 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s)
|
||||
switch(s->msmpeg4_version){
|
||||
case MSMP4_V1:
|
||||
case MSMP4_V2:
|
||||
s->rl_chroma_table_index = 2;
|
||||
s->rl_table_index = 2;
|
||||
ms->rl_chroma_table_index = 2;
|
||||
ms->rl_table_index = 2;
|
||||
|
||||
s->dc_table_index = 0; //not used
|
||||
ms->dc_table_index = 0; //not used
|
||||
break;
|
||||
case MSMP4_V3:
|
||||
s->rl_chroma_table_index = decode012(&s->gb);
|
||||
s->rl_table_index = decode012(&s->gb);
|
||||
ms->rl_chroma_table_index = decode012(&s->gb);
|
||||
ms->rl_table_index = decode012(&s->gb);
|
||||
|
||||
s->dc_table_index = get_bits1(&s->gb);
|
||||
ms->dc_table_index = get_bits1(&s->gb);
|
||||
break;
|
||||
case MSMP4_WMV1:
|
||||
ff_msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8);
|
||||
|
||||
if (ms->bit_rate > MBAC_BITRATE)
|
||||
s->per_mb_rl_table = get_bits1(&s->gb);
|
||||
ms->per_mb_rl_table = get_bits1(&s->gb);
|
||||
else
|
||||
s->per_mb_rl_table = 0;
|
||||
ms->per_mb_rl_table = 0;
|
||||
|
||||
if(!s->per_mb_rl_table){
|
||||
s->rl_chroma_table_index = decode012(&s->gb);
|
||||
s->rl_table_index = decode012(&s->gb);
|
||||
if (!ms->per_mb_rl_table) {
|
||||
ms->rl_chroma_table_index = decode012(&s->gb);
|
||||
ms->rl_table_index = decode012(&s->gb);
|
||||
}
|
||||
|
||||
s->dc_table_index = get_bits1(&s->gb);
|
||||
ms->dc_table_index = get_bits1(&s->gb);
|
||||
s->inter_intra_pred= 0;
|
||||
break;
|
||||
}
|
||||
@ -475,49 +477,49 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s)
|
||||
if(s->avctx->debug&FF_DEBUG_PICT_INFO)
|
||||
av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n",
|
||||
s->qscale,
|
||||
s->rl_chroma_table_index,
|
||||
s->rl_table_index,
|
||||
s->dc_table_index,
|
||||
s->per_mb_rl_table,
|
||||
ms->rl_chroma_table_index,
|
||||
ms->rl_table_index,
|
||||
ms->dc_table_index,
|
||||
ms->per_mb_rl_table,
|
||||
s->slice_height);
|
||||
} else {
|
||||
switch(s->msmpeg4_version){
|
||||
case MSMP4_V1:
|
||||
case MSMP4_V2:
|
||||
if (s->msmpeg4_version == MSMP4_V1)
|
||||
s->use_skip_mb_code = 1;
|
||||
ms->use_skip_mb_code = 1;
|
||||
else
|
||||
s->use_skip_mb_code = get_bits1(&s->gb);
|
||||
s->rl_table_index = 2;
|
||||
s->rl_chroma_table_index = s->rl_table_index;
|
||||
s->dc_table_index = 0; //not used
|
||||
s->mv_table_index = 0;
|
||||
ms->use_skip_mb_code = get_bits1(&s->gb);
|
||||
ms->rl_table_index = 2;
|
||||
ms->rl_chroma_table_index = ms->rl_table_index;
|
||||
ms->dc_table_index = 0; //not used
|
||||
ms->mv_table_index = 0;
|
||||
break;
|
||||
case MSMP4_V3:
|
||||
s->use_skip_mb_code = get_bits1(&s->gb);
|
||||
s->rl_table_index = decode012(&s->gb);
|
||||
s->rl_chroma_table_index = s->rl_table_index;
|
||||
ms->use_skip_mb_code = get_bits1(&s->gb);
|
||||
ms->rl_table_index = decode012(&s->gb);
|
||||
ms->rl_chroma_table_index = ms->rl_table_index;
|
||||
|
||||
s->dc_table_index = get_bits1(&s->gb);
|
||||
ms->dc_table_index = get_bits1(&s->gb);
|
||||
|
||||
s->mv_table_index = get_bits1(&s->gb);
|
||||
ms->mv_table_index = get_bits1(&s->gb);
|
||||
break;
|
||||
case MSMP4_WMV1:
|
||||
s->use_skip_mb_code = get_bits1(&s->gb);
|
||||
ms->use_skip_mb_code = get_bits1(&s->gb);
|
||||
|
||||
if (ms->bit_rate > MBAC_BITRATE)
|
||||
s->per_mb_rl_table = get_bits1(&s->gb);
|
||||
ms->per_mb_rl_table = get_bits1(&s->gb);
|
||||
else
|
||||
s->per_mb_rl_table = 0;
|
||||
ms->per_mb_rl_table = 0;
|
||||
|
||||
if(!s->per_mb_rl_table){
|
||||
s->rl_table_index = decode012(&s->gb);
|
||||
s->rl_chroma_table_index = s->rl_table_index;
|
||||
if (!ms->per_mb_rl_table) {
|
||||
ms->rl_table_index = decode012(&s->gb);
|
||||
ms->rl_chroma_table_index = ms->rl_table_index;
|
||||
}
|
||||
|
||||
s->dc_table_index = get_bits1(&s->gb);
|
||||
ms->dc_table_index = get_bits1(&s->gb);
|
||||
|
||||
s->mv_table_index = get_bits1(&s->gb);
|
||||
ms->mv_table_index = get_bits1(&s->gb);
|
||||
s->inter_intra_pred = s->width*s->height < 320*240 &&
|
||||
ms->bit_rate <= II_BITRATE;
|
||||
break;
|
||||
@ -525,12 +527,12 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s)
|
||||
|
||||
if(s->avctx->debug&FF_DEBUG_PICT_INFO)
|
||||
av_log(s->avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n",
|
||||
s->use_skip_mb_code,
|
||||
s->rl_table_index,
|
||||
s->rl_chroma_table_index,
|
||||
s->dc_table_index,
|
||||
s->mv_table_index,
|
||||
s->per_mb_rl_table,
|
||||
ms->use_skip_mb_code,
|
||||
ms->rl_table_index,
|
||||
ms->rl_chroma_table_index,
|
||||
ms->dc_table_index,
|
||||
ms->mv_table_index,
|
||||
ms->per_mb_rl_table,
|
||||
s->qscale);
|
||||
|
||||
if(s->flipflop_rounding){
|
||||
@ -542,8 +544,8 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s)
|
||||
ff_dlog(s->avctx, "%d %d %d %d %d\n", s->pict_type, ms->bit_rate,
|
||||
s->inter_intra_pred, s->width, s->height);
|
||||
|
||||
s->esc3_level_length= 0;
|
||||
s->esc3_run_length= 0;
|
||||
ms->esc3_level_length = 0;
|
||||
ms->esc3_run_length = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -577,8 +579,9 @@ int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
|
||||
static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr)
|
||||
{
|
||||
MpegEncContext *const s = &ms->m;
|
||||
int level, pred;
|
||||
|
||||
if (s->msmpeg4_version <= MSMP4_V2) {
|
||||
@ -594,7 +597,7 @@ static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
|
||||
}
|
||||
level-=256;
|
||||
} else {
|
||||
level = get_vlc2(&s->gb, ff_msmp4_dc_vlc[s->dc_table_index][n >= 4],
|
||||
level = get_vlc2(&s->gb, ff_msmp4_dc_vlc[ms->dc_table_index][n >= 4],
|
||||
MSMP4_DC_VLC_BITS, 3);
|
||||
|
||||
if (level == DC_MAX) {
|
||||
@ -630,9 +633,10 @@ static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
|
||||
return level;
|
||||
}
|
||||
|
||||
int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block,
|
||||
int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block,
|
||||
int n, int coded, const uint8_t *scan_table)
|
||||
{
|
||||
MpegEncContext *const s = &ms->m;
|
||||
int level, i, last, run, run_diff;
|
||||
int dc_pred_dir = -1; //unused but its passed around, so it needs to be initialized
|
||||
const RLTable *rl;
|
||||
@ -644,20 +648,20 @@ int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block,
|
||||
qadd=0;
|
||||
|
||||
/* DC coef */
|
||||
level = msmpeg4_decode_dc(s, n, &dc_pred_dir);
|
||||
level = msmpeg4_decode_dc(ms, n, &dc_pred_dir);
|
||||
|
||||
if (level < 0){
|
||||
av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale);
|
||||
if(s->inter_intra_pred) level=0;
|
||||
}
|
||||
if (n < 4) {
|
||||
rl = &ff_rl_table[s->rl_table_index];
|
||||
rl = &ff_rl_table[ms->rl_table_index];
|
||||
if(level > 256*s->y_dc_scale){
|
||||
av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale);
|
||||
if(!s->inter_intra_pred) return -1;
|
||||
}
|
||||
} else {
|
||||
rl = &ff_rl_table[3 + s->rl_chroma_table_index];
|
||||
rl = &ff_rl_table[3 + ms->rl_chroma_table_index];
|
||||
if(level > 256*s->c_dc_scale){
|
||||
av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale);
|
||||
if(!s->inter_intra_pred) return -1;
|
||||
@ -683,7 +687,7 @@ int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block,
|
||||
qmul = s->qscale << 1;
|
||||
qadd = (s->qscale - 1) | 1;
|
||||
i = -1;
|
||||
rl = &ff_rl_table[3 + s->rl_table_index];
|
||||
rl = &ff_rl_table[3 + ms->rl_table_index];
|
||||
|
||||
if (s->msmpeg4_version == MSMP4_V2)
|
||||
run_diff = 0;
|
||||
@ -721,7 +725,7 @@ int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block,
|
||||
}else{
|
||||
int sign;
|
||||
last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
|
||||
if(!s->esc3_level_length){
|
||||
if (!ms->esc3_level_length) {
|
||||
int ll;
|
||||
ff_dlog(s->avctx, "ESC-3 %X at %d %d\n",
|
||||
show_bits(&s->gb, 24), s->mb_x, s->mb_y);
|
||||
@ -739,18 +743,18 @@ int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block,
|
||||
if(ll<8) SKIP_BITS(re, &s->gb, 1);
|
||||
}
|
||||
|
||||
s->esc3_level_length= ll;
|
||||
s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);
|
||||
ms->esc3_level_length = ll;
|
||||
ms->esc3_run_length = SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);
|
||||
UPDATE_CACHE(re, &s->gb);
|
||||
}
|
||||
run= SHOW_UBITS(re, &s->gb, s->esc3_run_length);
|
||||
SKIP_BITS(re, &s->gb, s->esc3_run_length);
|
||||
run = SHOW_UBITS(re, &s->gb, ms->esc3_run_length);
|
||||
SKIP_BITS(re, &s->gb, ms->esc3_run_length);
|
||||
|
||||
sign= SHOW_UBITS(re, &s->gb, 1);
|
||||
SKIP_BITS(re, &s->gb, 1);
|
||||
|
||||
level= SHOW_UBITS(re, &s->gb, s->esc3_level_length);
|
||||
SKIP_BITS(re, &s->gb, s->esc3_level_length);
|
||||
level = SHOW_UBITS(re, &s->gb, ms->esc3_level_length);
|
||||
SKIP_BITS(re, &s->gb, ms->esc3_level_length);
|
||||
if(sign) level= -level;
|
||||
}
|
||||
|
||||
@ -814,9 +818,10 @@ int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ff_msmpeg4_decode_motion(MpegEncContext *s, int *mx_ptr, int *my_ptr)
|
||||
void ff_msmpeg4_decode_motion(MSMP4DecContext *const ms, int *mx_ptr, int *my_ptr)
|
||||
{
|
||||
const VLCElem *const mv_vlc = mv_tables[s->mv_table_index];
|
||||
const VLCElem *const mv_vlc = mv_tables[ms->mv_table_index];
|
||||
MpegEncContext *const s = &ms->m;
|
||||
int sym, mx, my;
|
||||
|
||||
sym = get_vlc2(&s->gb, mv_vlc, MV_VLC_BITS, 2);
|
||||
|
@ -31,6 +31,14 @@
|
||||
typedef struct MSMP4DecContext {
|
||||
MpegEncContext m;
|
||||
int bit_rate;
|
||||
int mv_table_index;
|
||||
int rl_table_index;
|
||||
int rl_chroma_table_index;
|
||||
int dc_table_index;
|
||||
int use_skip_mb_code;
|
||||
int per_mb_rl_table;
|
||||
int esc3_level_length;
|
||||
int esc3_run_length;
|
||||
} MSMP4DecContext;
|
||||
|
||||
static inline MSMP4DecContext *mpv_to_msmpeg4(MpegEncContext *s)
|
||||
@ -45,8 +53,8 @@ extern VLCElem ff_inter_intra_vlc[8];
|
||||
int ff_msmpeg4_decode_init(AVCodecContext *avctx);
|
||||
int ff_msmpeg4_decode_picture_header(MpegEncContext *s);
|
||||
int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size);
|
||||
void ff_msmpeg4_decode_motion(MpegEncContext * s, int *mx_ptr, int *my_ptr);
|
||||
int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block,
|
||||
void ff_msmpeg4_decode_motion(MSMP4DecContext *ms, int *mx_ptr, int *my_ptr);
|
||||
int ff_msmpeg4_decode_block(MSMP4DecContext *ms, int16_t * block,
|
||||
int n, int coded, const uint8_t *scan_table);
|
||||
|
||||
#endif
|
||||
|
@ -200,15 +200,15 @@ static void find_best_tables(MSMPEG4EncContext *ms)
|
||||
|
||||
memset(ms->ac_stats, 0, sizeof(ms->ac_stats));
|
||||
|
||||
s->rl_table_index = best;
|
||||
s->rl_chroma_table_index= chroma_best;
|
||||
ms->rl_table_index = best;
|
||||
ms->rl_chroma_table_index = chroma_best;
|
||||
|
||||
if(s->pict_type != s->last_non_b_pict_type){
|
||||
s->rl_table_index= 2;
|
||||
ms->rl_table_index = 2;
|
||||
if(s->pict_type==AV_PICTURE_TYPE_I)
|
||||
s->rl_chroma_table_index= 1;
|
||||
ms->rl_chroma_table_index = 1;
|
||||
else
|
||||
s->rl_chroma_table_index= 2;
|
||||
ms->rl_chroma_table_index = 2;
|
||||
}
|
||||
|
||||
}
|
||||
@ -226,14 +226,14 @@ static int msmpeg4_encode_picture_header(MPVMainEncContext *const m)
|
||||
|
||||
put_bits(&s->pb, 5, s->qscale);
|
||||
if (s->msmpeg4_version <= MSMP4_V2) {
|
||||
s->rl_table_index = 2;
|
||||
s->rl_chroma_table_index = 2;
|
||||
ms->rl_table_index = 2;
|
||||
ms->rl_chroma_table_index = 2;
|
||||
}
|
||||
|
||||
s->dc_table_index = 1;
|
||||
s->mv_table_index = 1; /* only if P-frame */
|
||||
s->use_skip_mb_code = 1; /* only if P-frame */
|
||||
s->per_mb_rl_table = 0;
|
||||
ms->dc_table_index = 1;
|
||||
ms->mv_table_index = 1; /* only if P-frame */
|
||||
ms->use_skip_mb_code = 1; /* only if P-frame */
|
||||
ms->per_mb_rl_table = 0;
|
||||
if (s->msmpeg4_version == MSMP4_WMV1)
|
||||
s->inter_intra_pred = s->width * s->height < 320*240 &&
|
||||
m->bit_rate <= II_BITRATE &&
|
||||
@ -248,35 +248,35 @@ static int msmpeg4_encode_picture_header(MPVMainEncContext *const m)
|
||||
if (s->msmpeg4_version == MSMP4_WMV1) {
|
||||
ff_msmpeg4_encode_ext_header(s);
|
||||
if (m->bit_rate > MBAC_BITRATE)
|
||||
put_bits(&s->pb, 1, s->per_mb_rl_table);
|
||||
put_bits(&s->pb, 1, ms->per_mb_rl_table);
|
||||
}
|
||||
|
||||
if (s->msmpeg4_version > MSMP4_V2) {
|
||||
if(!s->per_mb_rl_table){
|
||||
ff_msmpeg4_code012(&s->pb, s->rl_chroma_table_index);
|
||||
ff_msmpeg4_code012(&s->pb, s->rl_table_index);
|
||||
if (!ms->per_mb_rl_table){
|
||||
ff_msmpeg4_code012(&s->pb, ms->rl_chroma_table_index);
|
||||
ff_msmpeg4_code012(&s->pb, ms->rl_table_index);
|
||||
}
|
||||
|
||||
put_bits(&s->pb, 1, s->dc_table_index);
|
||||
put_bits(&s->pb, 1, ms->dc_table_index);
|
||||
}
|
||||
} else {
|
||||
put_bits(&s->pb, 1, s->use_skip_mb_code);
|
||||
put_bits(&s->pb, 1, ms->use_skip_mb_code);
|
||||
|
||||
if (s->msmpeg4_version == MSMP4_WMV1 && m->bit_rate > MBAC_BITRATE)
|
||||
put_bits(&s->pb, 1, s->per_mb_rl_table);
|
||||
put_bits(&s->pb, 1, ms->per_mb_rl_table);
|
||||
|
||||
if (s->msmpeg4_version > MSMP4_V2) {
|
||||
if(!s->per_mb_rl_table)
|
||||
ff_msmpeg4_code012(&s->pb, s->rl_table_index);
|
||||
if (!ms->per_mb_rl_table)
|
||||
ff_msmpeg4_code012(&s->pb, ms->rl_table_index);
|
||||
|
||||
put_bits(&s->pb, 1, s->dc_table_index);
|
||||
put_bits(&s->pb, 1, ms->dc_table_index);
|
||||
|
||||
put_bits(&s->pb, 1, s->mv_table_index);
|
||||
put_bits(&s->pb, 1, ms->mv_table_index);
|
||||
}
|
||||
}
|
||||
|
||||
s->esc3_level_length= 0;
|
||||
s->esc3_run_length= 0;
|
||||
s->esc3_level_length = 0;
|
||||
ms->esc3_run_length = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -308,10 +308,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
||||
av_assert0(!s->flipflop_rounding);
|
||||
}
|
||||
|
||||
void ff_msmpeg4_encode_motion(MpegEncContext * s,
|
||||
void ff_msmpeg4_encode_motion(MSMPEG4EncContext *const ms,
|
||||
int mx, int my)
|
||||
{
|
||||
const uint32_t *const mv_vector_table = mv_vector_tables[s->mv_table_index];
|
||||
MpegEncContext *const s = &ms->m.s;
|
||||
const uint32_t *const mv_vector_table = mv_vector_tables[ms->mv_table_index];
|
||||
uint32_t code;
|
||||
|
||||
/* modulo encoding */
|
||||
@ -382,6 +383,7 @@ static void msmpeg4_encode_mb(MpegEncContext *const s,
|
||||
int16_t block[][64],
|
||||
int motion_x, int motion_y)
|
||||
{
|
||||
MSMPEG4EncContext *const ms = mpv_to_msmpeg4(s);
|
||||
int cbp, coded_cbp, i;
|
||||
int pred_x, pred_y;
|
||||
|
||||
@ -394,7 +396,7 @@ static void msmpeg4_encode_mb(MpegEncContext *const s,
|
||||
if (s->block_last_index[i] >= 0)
|
||||
cbp |= 1 << (5 - i);
|
||||
}
|
||||
if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
|
||||
if (ms->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
|
||||
/* skip macroblock */
|
||||
put_bits(&s->pb, 1, 1);
|
||||
s->last_bits++;
|
||||
@ -402,7 +404,7 @@ static void msmpeg4_encode_mb(MpegEncContext *const s,
|
||||
|
||||
return;
|
||||
}
|
||||
if (s->use_skip_mb_code)
|
||||
if (ms->use_skip_mb_code)
|
||||
put_bits(&s->pb, 1, 0); /* mb coded */
|
||||
|
||||
if (s->msmpeg4_version <= MSMP4_V2) {
|
||||
@ -430,8 +432,8 @@ static void msmpeg4_encode_mb(MpegEncContext *const s,
|
||||
|
||||
/* motion vector */
|
||||
ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
|
||||
ff_msmpeg4_encode_motion(s, motion_x - pred_x,
|
||||
motion_y - pred_y);
|
||||
ff_msmpeg4_encode_motion(ms, motion_x - pred_x,
|
||||
motion_y - pred_y);
|
||||
}
|
||||
|
||||
s->mv_bits += get_bits_diff(s);
|
||||
@ -452,7 +454,7 @@ static void msmpeg4_encode_mb(MpegEncContext *const s,
|
||||
put_bits(&s->pb,
|
||||
ff_v2_intra_cbpc[cbp&3][1], ff_v2_intra_cbpc[cbp&3][0]);
|
||||
} else {
|
||||
if (s->use_skip_mb_code)
|
||||
if (ms->use_skip_mb_code)
|
||||
put_bits(&s->pb, 1, 0); /* mb coded */
|
||||
put_bits(&s->pb,
|
||||
ff_v2_mb_type[(cbp&3) + 4][1],
|
||||
@ -479,7 +481,7 @@ static void msmpeg4_encode_mb(MpegEncContext *const s,
|
||||
put_bits(&s->pb,
|
||||
ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
|
||||
} else {
|
||||
if (s->use_skip_mb_code)
|
||||
if (ms->use_skip_mb_code)
|
||||
put_bits(&s->pb, 1, 0); /* mb coded */
|
||||
put_bits(&s->pb,
|
||||
ff_table_mb_non_intra[cbp][1],
|
||||
@ -501,8 +503,9 @@ static void msmpeg4_encode_mb(MpegEncContext *const s,
|
||||
}
|
||||
}
|
||||
|
||||
static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
|
||||
static void msmpeg4_encode_dc(MSMPEG4EncContext *const ms, int level, int n, int *dir_ptr)
|
||||
{
|
||||
MpegEncContext *const s = &ms->m.s;
|
||||
int sign, code;
|
||||
int pred;
|
||||
|
||||
@ -539,8 +542,8 @@ static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr
|
||||
if (code > DC_MAX)
|
||||
code = DC_MAX;
|
||||
|
||||
put_bits(&s->pb, ff_msmp4_dc_tables[s->dc_table_index][n >= 4][code][1],
|
||||
ff_msmp4_dc_tables[s->dc_table_index][n >= 4][code][0]);
|
||||
put_bits(&s->pb, ff_msmp4_dc_tables[ms->dc_table_index][n >= 4][code][1],
|
||||
ff_msmp4_dc_tables[ms->dc_table_index][n >= 4][code][0]);
|
||||
|
||||
if (code == DC_MAX)
|
||||
put_bits(&s->pb, 8, level);
|
||||
@ -563,18 +566,18 @@ void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n)
|
||||
const uint8_t *scantable;
|
||||
|
||||
if (s->mb_intra) {
|
||||
msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
|
||||
msmpeg4_encode_dc(ms, block[0], n, &dc_pred_dir);
|
||||
i = 1;
|
||||
if (n < 4) {
|
||||
rl = &ff_rl_table[s->rl_table_index];
|
||||
rl = &ff_rl_table[ms->rl_table_index];
|
||||
} else {
|
||||
rl = &ff_rl_table[3 + s->rl_chroma_table_index];
|
||||
rl = &ff_rl_table[3 + ms->rl_chroma_table_index];
|
||||
}
|
||||
run_diff = s->msmpeg4_version >= MSMP4_WMV1;
|
||||
scantable= s->intra_scantable.permutated;
|
||||
} else {
|
||||
i = 0;
|
||||
rl = &ff_rl_table[3 + s->rl_table_index];
|
||||
rl = &ff_rl_table[3 + ms->rl_table_index];
|
||||
run_diff = s->msmpeg4_version > MSMP4_V2;
|
||||
scantable= s->inter_scantable.permutated;
|
||||
}
|
||||
@ -635,16 +638,16 @@ void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n)
|
||||
put_bits(&s->pb, 1, 0);
|
||||
put_bits(&s->pb, 1, last);
|
||||
if (s->msmpeg4_version >= MSMP4_WMV1) {
|
||||
if(s->esc3_level_length==0){
|
||||
s->esc3_level_length=8;
|
||||
s->esc3_run_length= 6;
|
||||
if (s->esc3_level_length == 0) {
|
||||
s->esc3_level_length = 8;
|
||||
ms->esc3_run_length = 6;
|
||||
//ESCLVLSZ + ESCRUNSZ
|
||||
if(s->qscale<8)
|
||||
put_bits(&s->pb, 6, 3);
|
||||
else
|
||||
put_bits(&s->pb, 8, 3);
|
||||
}
|
||||
put_bits(&s->pb, s->esc3_run_length, run);
|
||||
put_bits(&s->pb, ms->esc3_run_length, run);
|
||||
put_bits(&s->pb, 1, sign);
|
||||
put_bits(&s->pb, s->esc3_level_length, level);
|
||||
}else{
|
||||
|
@ -29,15 +29,29 @@
|
||||
typedef struct MSMPEG4EncContext {
|
||||
MPVMainEncContext m;
|
||||
|
||||
int mv_table_index;
|
||||
int rl_table_index;
|
||||
int rl_chroma_table_index;
|
||||
int dc_table_index;
|
||||
int use_skip_mb_code;
|
||||
int per_mb_rl_table;
|
||||
int esc3_run_length;
|
||||
|
||||
/** [mb_intra][isChroma][level][run][last] */
|
||||
unsigned ac_stats[2][2][MAX_LEVEL + 1][MAX_RUN + 1][2];
|
||||
} MSMPEG4EncContext;
|
||||
|
||||
static inline MSMPEG4EncContext *mpv_to_msmpeg4(MpegEncContext *s)
|
||||
{
|
||||
// Only legal because no MSMPEG-4 decoder uses slice-threading.
|
||||
return (MSMPEG4EncContext*)s;
|
||||
}
|
||||
|
||||
void ff_msmpeg4_encode_init(MPVMainEncContext *m);
|
||||
void ff_msmpeg4_encode_ext_header(MpegEncContext *s);
|
||||
void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n);
|
||||
void ff_msmpeg4_handle_slices(MpegEncContext *s);
|
||||
void ff_msmpeg4_encode_motion(MpegEncContext * s, int mx, int my);
|
||||
void ff_msmpeg4_encode_motion(MSMPEG4EncContext *ms, int mx, int my);
|
||||
|
||||
void ff_msmpeg4_code012(PutBitContext *pb, int n);
|
||||
|
||||
|
@ -343,7 +343,7 @@ static int vaapi_vc1_start_frame(AVCodecContext *avctx,
|
||||
.mv_fields.bits = {
|
||||
.mv_mode = vc1_get_MVMODE(v),
|
||||
.mv_mode2 = vc1_get_MVMODE2(v),
|
||||
.mv_table = (v->fcm == PROGRESSIVE ? s->mv_table_index : v->imvtab),
|
||||
.mv_table = (v->fcm == PROGRESSIVE ? v->mv_table_index : v->imvtab),
|
||||
.two_mv_block_pattern_table = v->twomvbptab,
|
||||
.four_mv_switch = v->fourmvswitch,
|
||||
.four_mv_block_pattern_table = v->fourmvbptab,
|
||||
@ -371,7 +371,7 @@ static int vaapi_vc1_start_frame(AVCodecContext *avctx,
|
||||
.frame_level_transform_type = vc1_get_TTFRM(v),
|
||||
.transform_ac_codingset_idx1 = v->c_ac_table_index,
|
||||
.transform_ac_codingset_idx2 = v->y_ac_table_index,
|
||||
.intra_transform_dc_table = v->s.dc_table_index,
|
||||
.intra_transform_dc_table = v->dc_table_index,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -765,7 +765,7 @@ int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
/* Hopefully this is correct for P-frames */
|
||||
v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
|
||||
v->mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
|
||||
v->cbptab = get_bits(gb, 2);
|
||||
v->cbpcy_vlc = ff_vc1_cbpcy_p_vlc[v->cbptab];
|
||||
|
||||
@ -804,7 +804,7 @@ int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
|
||||
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->mv_table_index = get_bits(gb, 2);
|
||||
v->cbptab = get_bits(gb, 2);
|
||||
v->cbpcy_vlc = ff_vc1_cbpcy_p_vlc[v->cbptab];
|
||||
|
||||
@ -833,7 +833,7 @@ int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
|
||||
v->y_ac_table_index = decode012(gb);
|
||||
}
|
||||
/* DC Syntax */
|
||||
v->s.dc_table_index = get_bits1(gb);
|
||||
v->dc_table_index = get_bits1(gb);
|
||||
}
|
||||
|
||||
if (v->s.pict_type == AV_PICTURE_TYPE_BI) {
|
||||
@ -1158,7 +1158,7 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
|
||||
"Imode: %i, Invert: %i\n", status>>1, status&1);
|
||||
|
||||
/* Hopefully this is correct for P-frames */
|
||||
v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
|
||||
v->mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
|
||||
v->cbptab = get_bits(gb, 2);
|
||||
v->cbpcy_vlc = ff_vc1_cbpcy_p_vlc[v->cbptab];
|
||||
} else if (v->fcm == ILACE_FRAME) { // frame interlaced
|
||||
@ -1295,7 +1295,7 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
|
||||
return -1;
|
||||
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->mv_table_index = get_bits(gb, 2);
|
||||
v->cbptab = get_bits(gb, 2);
|
||||
v->cbpcy_vlc = ff_vc1_cbpcy_p_vlc[v->cbptab];
|
||||
}
|
||||
@ -1330,7 +1330,7 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
|
||||
}
|
||||
|
||||
/* DC Syntax */
|
||||
v->s.dc_table_index = get_bits1(gb);
|
||||
v->dc_table_index = get_bits1(gb);
|
||||
if ((v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
|
||||
&& v->dquant) {
|
||||
av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
|
||||
|
@ -246,6 +246,7 @@ typedef struct VC1Context{
|
||||
uint8_t dqsbedge;
|
||||
uint8_t dqbilevel;
|
||||
//@}
|
||||
int dc_table_index;
|
||||
/** AC coding set indexes
|
||||
* @see 8.1.1.10, p(1)10
|
||||
*/
|
||||
@ -253,6 +254,8 @@ typedef struct VC1Context{
|
||||
int c_ac_table_index; ///< Chroma index from ACFRM element
|
||||
int y_ac_table_index; ///< Luma index from AC2FRM element
|
||||
//@}
|
||||
int esc3_level_length;
|
||||
int esc3_run_length;
|
||||
int ttfrm; ///< Transform type info present at frame level
|
||||
uint8_t ttmbf; ///< Transform type flag
|
||||
int *ttblk_base, *ttblk; ///< Transform type at the block level
|
||||
@ -282,6 +285,7 @@ typedef struct VC1Context{
|
||||
uint8_t pquantizer; ///< Uniform (over sequence) quantizer in use
|
||||
const VLCElem *cbpcy_vlc; ///< CBPCY VLC table
|
||||
int tt_index; ///< Index for Transform Type tables (to decode TTMB)
|
||||
int mv_table_index;
|
||||
uint8_t* mv_type_mb_plane; ///< bitplane for mv_type == (4MV)
|
||||
uint8_t* direct_mb_plane; ///< bitplane for "direct" MBs
|
||||
uint8_t* forward_mb_plane; ///< bitplane for "forward" MBs
|
||||
|
@ -227,7 +227,7 @@ static void vc1_put_blocks_clamped(VC1Context *v, int put_signed)
|
||||
* @param _dmv_y Vertical differential for decoded MV
|
||||
*/
|
||||
#define GET_MVDATA(_dmv_x, _dmv_y) \
|
||||
index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index], \
|
||||
index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[v->mv_table_index], \
|
||||
VC1_MV_DIFF_VLC_BITS, 2); \
|
||||
if (index > 36) { \
|
||||
mb_has_coeffs = 1; \
|
||||
@ -549,19 +549,19 @@ static int vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip,
|
||||
sign = get_bits1(gb);
|
||||
} else {
|
||||
lst = get_bits1(gb);
|
||||
if (v->s.esc3_level_length == 0) {
|
||||
if (v->esc3_level_length == 0) {
|
||||
if (v->pq < 8 || v->dquantfrm) { // table 59
|
||||
v->s.esc3_level_length = get_bits(gb, 3);
|
||||
if (!v->s.esc3_level_length)
|
||||
v->s.esc3_level_length = get_bits(gb, 2) + 8;
|
||||
v->esc3_level_length = get_bits(gb, 3);
|
||||
if (!v->esc3_level_length)
|
||||
v->esc3_level_length = get_bits(gb, 2) + 8;
|
||||
} else { // table 60
|
||||
v->s.esc3_level_length = get_unary(gb, 1, 6) + 2;
|
||||
v->esc3_level_length = get_unary(gb, 1, 6) + 2;
|
||||
}
|
||||
v->s.esc3_run_length = 3 + get_bits(gb, 2);
|
||||
v->esc3_run_length = 3 + get_bits(gb, 2);
|
||||
}
|
||||
run = get_bits(gb, v->s.esc3_run_length);
|
||||
run = get_bits(gb, v->esc3_run_length);
|
||||
sign = get_bits1(gb);
|
||||
level = get_bits(gb, v->s.esc3_level_length);
|
||||
level = get_bits(gb, v->esc3_level_length);
|
||||
}
|
||||
}
|
||||
|
||||
@ -590,7 +590,7 @@ static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,
|
||||
int dcdiff, scale;
|
||||
|
||||
/* Get DC differential */
|
||||
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_vlc[s->dc_table_index][n >= 4],
|
||||
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_vlc[v->dc_table_index][n >= 4],
|
||||
MSMP4_DC_VLC_BITS, 3);
|
||||
if (dcdiff) {
|
||||
const int m = (v->pq == 1 || v->pq == 2) ? 3 - v->pq : 0;
|
||||
@ -723,7 +723,7 @@ static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n,
|
||||
int quant = FFABS(mquant);
|
||||
|
||||
/* Get DC differential */
|
||||
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_vlc[s->dc_table_index][n >= 4],
|
||||
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_vlc[v->dc_table_index][n >= 4],
|
||||
MSMP4_DC_VLC_BITS, 3);
|
||||
if (dcdiff) {
|
||||
const int m = (quant == 1 || quant == 2) ? 3 - quant : 0;
|
||||
@ -911,7 +911,7 @@ static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n,
|
||||
s->y_dc_scale = ff_wmv3_dc_scale_table[quant];
|
||||
|
||||
/* Get DC differential */
|
||||
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_vlc[s->dc_table_index][n >= 4],
|
||||
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_vlc[v->dc_table_index][n >= 4],
|
||||
MSMP4_DC_VLC_BITS, 3);
|
||||
if (dcdiff) {
|
||||
const int m = (quant == 1 || quant == 2) ? 3 - quant : 0;
|
||||
@ -2946,7 +2946,7 @@ static void vc1_decode_skip_blocks(VC1Context *v)
|
||||
void ff_vc1_decode_blocks(VC1Context *v)
|
||||
{
|
||||
|
||||
v->s.esc3_level_length = 0;
|
||||
v->esc3_level_length = 0;
|
||||
if (v->x8_type) {
|
||||
ff_intrax8_decode_picture(&v->x8, v->s.cur_pic.ptr,
|
||||
&v->s.gb, &v->s.mb_x, &v->s.mb_y,
|
||||
|
@ -248,16 +248,16 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
|
||||
|
||||
if (!w->j_type) {
|
||||
if (w->per_mb_rl_bit)
|
||||
s->per_mb_rl_table = get_bits1(&s->gb);
|
||||
w->ms.per_mb_rl_table = get_bits1(&s->gb);
|
||||
else
|
||||
s->per_mb_rl_table = 0;
|
||||
w->ms.per_mb_rl_table = 0;
|
||||
|
||||
if (!s->per_mb_rl_table) {
|
||||
s->rl_chroma_table_index = decode012(&s->gb);
|
||||
s->rl_table_index = decode012(&s->gb);
|
||||
if (!w->ms.per_mb_rl_table) {
|
||||
w->ms.rl_chroma_table_index = decode012(&s->gb);
|
||||
w->ms.rl_table_index = decode012(&s->gb);
|
||||
}
|
||||
|
||||
s->dc_table_index = get_bits1(&s->gb);
|
||||
w->ms.dc_table_index = get_bits1(&s->gb);
|
||||
|
||||
// at minimum one bit per macroblock is required at least in a valid frame,
|
||||
// we discard frames much smaller than this. Frames smaller than 1/8 of the
|
||||
@ -272,8 +272,8 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
|
||||
if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
|
||||
av_log(s->avctx, AV_LOG_DEBUG,
|
||||
"qscale:%d rlc:%d rl:%d dc:%d mbrl:%d j_type:%d \n",
|
||||
s->qscale, s->rl_chroma_table_index, s->rl_table_index,
|
||||
s->dc_table_index, s->per_mb_rl_table, w->j_type);
|
||||
s->qscale, w->ms.rl_chroma_table_index, w->ms.rl_table_index,
|
||||
w->ms.dc_table_index, w->ms.per_mb_rl_table, w->j_type);
|
||||
}
|
||||
} else {
|
||||
int cbp_index;
|
||||
@ -298,20 +298,20 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
|
||||
}
|
||||
|
||||
if (w->per_mb_rl_bit)
|
||||
s->per_mb_rl_table = get_bits1(&s->gb);
|
||||
w->ms.per_mb_rl_table = get_bits1(&s->gb);
|
||||
else
|
||||
s->per_mb_rl_table = 0;
|
||||
w->ms.per_mb_rl_table = 0;
|
||||
|
||||
if (!s->per_mb_rl_table) {
|
||||
s->rl_table_index = decode012(&s->gb);
|
||||
s->rl_chroma_table_index = s->rl_table_index;
|
||||
if (!w->ms.per_mb_rl_table) {
|
||||
w->ms.rl_table_index = decode012(&s->gb);
|
||||
w->ms.rl_chroma_table_index = w->ms.rl_table_index;
|
||||
}
|
||||
|
||||
if (get_bits_left(&s->gb) < 2)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
s->dc_table_index = get_bits1(&s->gb);
|
||||
s->mv_table_index = get_bits1(&s->gb);
|
||||
w->ms.dc_table_index = get_bits1(&s->gb);
|
||||
w->ms.mv_table_index = get_bits1(&s->gb);
|
||||
|
||||
s->inter_intra_pred = 0; // (s->width * s->height < 320 * 240 && w->ms.bit_rate <= II_BITRATE);
|
||||
s->no_rounding ^= 1;
|
||||
@ -320,15 +320,15 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
|
||||
av_log(s->avctx, AV_LOG_DEBUG,
|
||||
"rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d mspel:%d "
|
||||
"per_mb_abt:%d abt_type:%d cbp:%d ii:%d\n",
|
||||
s->rl_table_index, s->rl_chroma_table_index,
|
||||
s->dc_table_index, s->mv_table_index,
|
||||
s->per_mb_rl_table, s->qscale, s->mspel,
|
||||
w->ms.rl_table_index, w->ms.rl_chroma_table_index,
|
||||
w->ms.dc_table_index, w->ms.mv_table_index,
|
||||
w->ms.per_mb_rl_table, s->qscale, s->mspel,
|
||||
w->per_mb_abt, w->abt_type, w->cbp_table_index,
|
||||
s->inter_intra_pred);
|
||||
}
|
||||
}
|
||||
s->esc3_level_length = 0;
|
||||
s->esc3_run_length = 0;
|
||||
w->ms.esc3_level_length = 0;
|
||||
w->ms.esc3_run_length = 0;
|
||||
|
||||
if (w->j_type) {
|
||||
ff_intrax8_decode_picture(&w->x8, s->cur_pic.ptr,
|
||||
@ -349,7 +349,7 @@ static inline void wmv2_decode_motion(WMV2DecContext *w, int *mx_ptr, int *my_pt
|
||||
{
|
||||
MpegEncContext *const s = &w->ms.m;
|
||||
|
||||
ff_msmpeg4_decode_motion(s, mx_ptr, my_ptr);
|
||||
ff_msmpeg4_decode_motion(&w->ms, mx_ptr, my_ptr);
|
||||
|
||||
if ((((*mx_ptr) | (*my_ptr)) & 1) && s->mspel)
|
||||
w->common.hshift = get_bits1(&s->gb);
|
||||
@ -423,19 +423,23 @@ static inline int wmv2_decode_inter_block(WMV2DecContext *w, int16_t *block,
|
||||
|
||||
sub_cbp = sub_cbp_table[decode012(&s->gb)];
|
||||
|
||||
if (sub_cbp & 1)
|
||||
if ((ret = ff_msmpeg4_decode_block(s, block, n, 1, scantable)) < 0)
|
||||
if (sub_cbp & 1) {
|
||||
ret = ff_msmpeg4_decode_block(&w->ms, block, n, 1, scantable);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (sub_cbp & 2)
|
||||
if ((ret = ff_msmpeg4_decode_block(s, w->abt_block2[n], n, 1, scantable)) < 0)
|
||||
if (sub_cbp & 2) {
|
||||
ret = ff_msmpeg4_decode_block(&w->ms, w->abt_block2[n], n, 1, scantable);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
s->block_last_index[n] = 63;
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
return ff_msmpeg4_decode_block(s, block, n, 1,
|
||||
return ff_msmpeg4_decode_block(&w->ms, block, n, 1,
|
||||
s->inter_scantable.permutated);
|
||||
}
|
||||
}
|
||||
@ -445,6 +449,7 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
|
||||
/* The following is only allowed because this encoder
|
||||
* does not use slice threading. */
|
||||
WMV2DecContext *const w = (WMV2DecContext *) s;
|
||||
MSMP4DecContext *const ms = &w->ms;
|
||||
int cbp, code, i, ret;
|
||||
uint8_t *coded_val;
|
||||
|
||||
@ -498,9 +503,9 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
|
||||
|
||||
if (cbp) {
|
||||
s->bdsp.clear_blocks(s->block[0]);
|
||||
if (s->per_mb_rl_table) {
|
||||
s->rl_table_index = decode012(&s->gb);
|
||||
s->rl_chroma_table_index = s->rl_table_index;
|
||||
if (ms->per_mb_rl_table) {
|
||||
ms->rl_table_index = decode012(&s->gb);
|
||||
ms->rl_chroma_table_index = ms->rl_table_index;
|
||||
}
|
||||
|
||||
if (w->abt_flag && w->per_mb_abt) {
|
||||
@ -539,14 +544,15 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
|
||||
ff_dlog(s->avctx, "%d%d %d %d/",
|
||||
s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
|
||||
}
|
||||
if (s->per_mb_rl_table && cbp) {
|
||||
s->rl_table_index = decode012(&s->gb);
|
||||
s->rl_chroma_table_index = s->rl_table_index;
|
||||
if (ms->per_mb_rl_table && cbp) {
|
||||
ms->rl_table_index = decode012(&s->gb);
|
||||
ms->rl_chroma_table_index = ms->rl_table_index;
|
||||
}
|
||||
|
||||
s->bdsp.clear_blocks(s->block[0]);
|
||||
for (i = 0; i < 6; i++) {
|
||||
if ((ret = ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL)) < 0) {
|
||||
ret = ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL);
|
||||
if (ret < 0) {
|
||||
av_log(s->avctx, AV_LOG_ERROR,
|
||||
"\nerror while decoding intra block: %d x %d (%d)\n",
|
||||
s->mb_x, s->mb_y, i);
|
||||
|
@ -75,6 +75,7 @@ static int encode_ext_header(WMV2EncContext *w)
|
||||
static int wmv2_encode_picture_header(MPVMainEncContext *const m)
|
||||
{
|
||||
WMV2EncContext *const w = (WMV2EncContext *) m;
|
||||
MSMPEG4EncContext *const ms = &w->msmpeg4;
|
||||
MpegEncContext *const s = &m->s;
|
||||
|
||||
put_bits(&s->pb, 1, s->pict_type - 1);
|
||||
@ -82,9 +83,9 @@ static int wmv2_encode_picture_header(MPVMainEncContext *const m)
|
||||
put_bits(&s->pb, 7, 0);
|
||||
put_bits(&s->pb, 5, s->qscale);
|
||||
|
||||
s->dc_table_index = 1;
|
||||
s->mv_table_index = 1; /* only if P-frame */
|
||||
s->per_mb_rl_table = 0;
|
||||
ms->dc_table_index = 1;
|
||||
ms->mv_table_index = 1; /* only if P-frame */
|
||||
ms->per_mb_rl_table = 0;
|
||||
s->mspel = 0;
|
||||
w->per_mb_abt = 0;
|
||||
w->abt_type = 0;
|
||||
@ -98,14 +99,14 @@ static int wmv2_encode_picture_header(MPVMainEncContext *const m)
|
||||
put_bits(&s->pb, 1, w->j_type);
|
||||
|
||||
if (w->per_mb_rl_bit)
|
||||
put_bits(&s->pb, 1, s->per_mb_rl_table);
|
||||
put_bits(&s->pb, 1, ms->per_mb_rl_table);
|
||||
|
||||
if (!s->per_mb_rl_table) {
|
||||
ff_msmpeg4_code012(&s->pb, s->rl_chroma_table_index);
|
||||
ff_msmpeg4_code012(&s->pb, s->rl_table_index);
|
||||
if (!ms->per_mb_rl_table) {
|
||||
ff_msmpeg4_code012(&s->pb, ms->rl_chroma_table_index);
|
||||
ff_msmpeg4_code012(&s->pb, ms->rl_table_index);
|
||||
}
|
||||
|
||||
put_bits(&s->pb, 1, s->dc_table_index);
|
||||
put_bits(&s->pb, 1, ms->dc_table_index);
|
||||
|
||||
s->inter_intra_pred = 0;
|
||||
} else {
|
||||
@ -126,19 +127,19 @@ static int wmv2_encode_picture_header(MPVMainEncContext *const m)
|
||||
}
|
||||
|
||||
if (w->per_mb_rl_bit)
|
||||
put_bits(&s->pb, 1, s->per_mb_rl_table);
|
||||
put_bits(&s->pb, 1, ms->per_mb_rl_table);
|
||||
|
||||
if (!s->per_mb_rl_table) {
|
||||
ff_msmpeg4_code012(&s->pb, s->rl_table_index);
|
||||
s->rl_chroma_table_index = s->rl_table_index;
|
||||
if (!ms->per_mb_rl_table) {
|
||||
ff_msmpeg4_code012(&s->pb, ms->rl_table_index);
|
||||
ms->rl_chroma_table_index = ms->rl_table_index;
|
||||
}
|
||||
put_bits(&s->pb, 1, s->dc_table_index);
|
||||
put_bits(&s->pb, 1, s->mv_table_index);
|
||||
put_bits(&s->pb, 1, ms->dc_table_index);
|
||||
put_bits(&s->pb, 1, ms->mv_table_index);
|
||||
|
||||
s->inter_intra_pred = 0; // (s->width * s->height < 320 * 240 && m->bit_rate <= II_BITRATE);
|
||||
}
|
||||
s->esc3_level_length = 0;
|
||||
s->esc3_run_length = 0;
|
||||
ms->esc3_run_length = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -170,7 +171,7 @@ static void wmv2_encode_mb(MpegEncContext *const s, int16_t block[][64],
|
||||
s->misc_bits += get_bits_diff(s);
|
||||
/* motion vector */
|
||||
ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
|
||||
ff_msmpeg4_encode_motion(s, motion_x - pred_x,
|
||||
ff_msmpeg4_encode_motion(&w->msmpeg4, motion_x - pred_x,
|
||||
motion_y - pred_y);
|
||||
s->mv_bits += get_bits_diff(s);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user