/*
* MSMPEG4 backend for ffmpeg encoder and decoder
- * Copyright (c) 2001 Fabrice Bellard.
+ * Copyright (c) 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
* msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
*/
/**
- * @file msmpeg4.c
+ * @file libavcodec/msmpeg4.c
* MSMPEG4 backend for ffmpeg encoder and decoder.
*/
static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr);
static void init_h263_dc_for_msmpeg4(void);
static inline void msmpeg4_memsetw(short *tab, int val, int n);
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
static void msmpeg4v2_encode_motion(MpegEncContext * s, int val);
static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra);
#endif //CONFIG_ENCODERS
static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);
/* vc1 externs */
-extern uint8_t wmv3_dc_scale_table[32];
+extern const uint8_t wmv3_dc_scale_table[32];
#ifdef DEBUG
int intra_count = 0;
#include "msmpeg4data.h"
-#ifdef CONFIG_ENCODERS //strangely gcc includes this even if it is not references
+#if CONFIG_ENCODERS //strangely gcc includes this even if it is not referenced
static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
#endif //CONFIG_ENCODERS
static uint8_t static_rl_table_store[NB_RL_TABLES][2][2*MAX_RUN + MAX_LEVEL + 3];
-static void common_init(MpegEncContext * s)
+static av_cold void common_init(MpegEncContext * s)
{
- static int inited=0;
+ static int initialized=0;
switch(s->msmpeg4_version){
case 1:
case 3:
if(s->workaround_bugs){
s->y_dc_scale_table= old_ff_y_dc_scale_table;
- s->c_dc_scale_table= old_ff_c_dc_scale_table;
+ s->c_dc_scale_table= wmv1_c_dc_scale_table;
} else{
s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table;
s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;
s->y_dc_scale_table= wmv1_y_dc_scale_table;
s->c_dc_scale_table= wmv1_c_dc_scale_table;
break;
-#if defined(CONFIG_WMV3_DECODER)||defined(CONFIG_VC1_DECODER)
+#if CONFIG_WMV3_DECODER || CONFIG_VC1_DECODER
case 6:
s->y_dc_scale_table= wmv3_dc_scale_table;
s->c_dc_scale_table= wmv3_dc_scale_table;
}
//Note the default tables are set in common_init in mpegvideo.c
- if(!inited){
- inited=1;
+ if(!initialized){
+ initialized=1;
init_h263_dc_for_msmpeg4();
}
}
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
/* build the table which associate a (x,y) motion vector to a vlc */
static void init_mv_table(MVTable *tab)
}
}
-void ff_msmpeg4_encode_init(MpegEncContext *s)
+av_cold void ff_msmpeg4_encode_init(MpegEncContext *s)
{
static int init_done=0;
int i;
return size;
}
-void ff_find_best_tables(MpegEncContext * s)
+static void find_best_tables(MpegEncContext * s)
{
int i;
int best =-1, best_size =9999999;
int intra_luma_count = s->ac_stats[1][0][level][run][last];
int intra_chroma_count= s->ac_stats[1][1][level][run][last];
- if(s->pict_type==I_TYPE){
+ if(s->pict_type==FF_I_TYPE){
size += intra_luma_count *rl_length[i ][level][run][last];
chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last];
}else{
// printf("type:%d, best:%d, qp:%d, var:%d, mcvar:%d, size:%d //\n",
// s->pict_type, best, s->qscale, s->mb_var_sum, s->mc_mb_var_sum, best_size);
- if(s->pict_type==P_TYPE) chroma_best= best;
+ if(s->pict_type==FF_P_TYPE) chroma_best= best;
memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);
if(s->pict_type != s->last_non_b_pict_type){
s->rl_table_index= 2;
- if(s->pict_type==I_TYPE)
+ if(s->pict_type==FF_I_TYPE)
s->rl_chroma_table_index= 1;
else
s->rl_chroma_table_index= 2;
/* write MSMPEG4 compatible frame header */
void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
{
- ff_find_best_tables(s);
+ find_best_tables(s);
align_put_bits(&s->pb);
put_bits(&s->pb, 2, s->pict_type - 1);
s->use_skip_mb_code = 1; /* only if P frame */
s->per_mb_rl_table = 0;
if(s->msmpeg4_version==4)
- s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==P_TYPE);
+ s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==FF_P_TYPE);
//printf("%d %d %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height);
- if (s->pict_type == I_TYPE) {
+ if (s->pict_type == FF_I_TYPE) {
s->slice_height= s->mb_height/1;
put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height);
return pred;
}
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
void ff_msmpeg4_encode_motion(MpegEncContext * s,
int mx, int my)
#endif
if(s->msmpeg4_version<=2){
- if (s->pict_type == I_TYPE) {
+ if (s->pict_type == FF_I_TYPE) {
put_bits(&s->pb,
v2_intra_cbpc[cbp&3][1], v2_intra_cbpc[cbp&3][0]);
} else {
cbpy_tab[cbp>>2][1],
cbpy_tab[cbp>>2][0]);
}else{
- if (s->pict_type == I_TYPE) {
+ if (s->pict_type == FF_I_TYPE) {
put_bits(&s->pb,
ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
} else {
necessitate to modify mpegvideo.c. The problem comes from the
fact they decided to store the quantized DC (which would lead
to problems if Q could vary !) */
-#if (defined(ARCH_X86)) && !defined PIC
- asm volatile(
+#if ARCH_X86 && !defined PIC
+ __asm__ volatile(
"movl %3, %%eax \n\t"
"shrl $1, %%eax \n\t"
"addl %%eax, %2 \n\t"
: "%eax", "%edx"
);
#else
- /* #elif defined (ARCH_ALPHA) */
+ /* #elif ARCH_ALPHA */
/* Divisions are extremely costly on Alpha; optimize the most
common case. But they are costly everywhere...
*/
put_bits(&s->pb, s->esc3_level_length, level);
}else{
put_bits(&s->pb, 6, run);
- put_bits(&s->pb, 8, slevel & 0xff);
+ put_sbits(&s->pb, 8, slevel);
}
} else {
/* second escape */
/* This table is practically identical to the one from h263
* except that it is inverted. */
-static void init_h263_dc_for_msmpeg4(void)
+static av_cold void init_h263_dc_for_msmpeg4(void)
{
int level, uni_code, uni_len;
}
/* init all vlc decoding tables */
-int ff_msmpeg4_decode_init(MpegEncContext *s)
+av_cold int ff_msmpeg4_decode_init(MpegEncContext *s)
{
static int done = 0;
int i;
for(i=0;i<NB_RL_TABLES;i++) {
init_rl(&rl_table[i], static_rl_table_store[i]);
- init_vlc_rl(&rl_table[i], 1);
}
+ INIT_VLC_RL(rl_table[0], 642);
+ INIT_VLC_RL(rl_table[1], 1104);
+ INIT_VLC_RL(rl_table[2], 554);
+ INIT_VLC_RL(rl_table[3], 940);
+ INIT_VLC_RL(rl_table[4], 962);
+ INIT_VLC_RL(rl_table[5], 554);
for(i=0;i<2;i++) {
mv = &mv_tables[i];
init_vlc(&mv->vlc, MV_VLC_BITS, mv->n + 1,
s->decode_mb= msmpeg4v34_decode_mb;
break;
case 5:
- if (ENABLE_WMV2_DECODER)
- s->decode_mb= ff_wmv2_decode_mb;
+ if (CONFIG_WMV2_DECODER)
+ s->decode_mb= ff_wmv2_decode_mb;
case 6:
//FIXME + TODO VC1 decode mb
break;
}
s->pict_type = get_bits(&s->gb, 2) + 1;
- if (s->pict_type != I_TYPE &&
- s->pict_type != P_TYPE){
+ if (s->pict_type != FF_I_TYPE &&
+ s->pict_type != FF_P_TYPE){
av_log(s->avctx, AV_LOG_ERROR, "invalid picture type\n");
return -1;
}
#if 0
{
static int had_i=0;
- if(s->pict_type == I_TYPE) had_i=1;
+ if(s->pict_type == FF_I_TYPE) had_i=1;
if(!had_i) return -1;
}
#endif
return -1;
}
- if (s->pict_type == I_TYPE) {
+ if (s->pict_type == FF_I_TYPE) {
code = get_bits(&s->gb, 5);
if(s->msmpeg4_version==1){
if(code==0 || code>s->mb_height){
tab[i] = val;
}
-#ifdef CONFIG_ENCODERS
+#if CONFIG_ENCODERS
static void msmpeg4v2_encode_motion(MpegEncContext * s, int val)
{
int range, bit_size, sign, code, bits;
{
int cbp, code, i;
- if (s->pict_type == P_TYPE) {
+ if (s->pict_type == FF_P_TYPE) {
if (s->use_skip_mb_code) {
if (get_bits1(&s->gb)) {
/* skip mb */
} else{
s->ac_pred = 0;
cbp|= get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors
- if(s->pict_type==P_TYPE) cbp^=0x3C;
+ if(s->pict_type==FF_P_TYPE) cbp^=0x3C;
}
}
uint8_t *coded_val;
uint32_t * const mb_type_ptr= &s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ];
- if (s->pict_type == P_TYPE) {
+ if (s->pict_type == FF_P_TYPE) {
if (s->use_skip_mb_code) {
if (get_bits1(&s->gb)) {
/* skip mb */
int n, int coded, const uint8_t *scan_table)
{
int level, i, last, run, run_diff;
- int dc_pred_dir;
+ int av_uninit(dc_pred_dir);
RLTable *rl;
RL_VLC_ELEM *rl_vlc;
int qmul, qadd;
i-= 192;
if(i&(~63)){
const int left= s->gb.size_in_bits - get_bits_count(&s->gb);
- if(((i+192 == 64 && level/qmul==-1) || s->error_resilience<=1) && left>=0){
+ if(((i+192 == 64 && level/qmul==-1) || s->error_recognition<=1) && left>=0){
av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y);
break;
}else{