aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2004-03-16 16:11:29 +0000
committerMichael Niedermayer <michaelni@gmx.at>2004-03-16 16:11:29 +0000
commit3edcacde04911dac4c56fd74053505a493e561f8 (patch)
treeeff6e5bc0a3dcecec4b78e3709b2c9c4fc6271d2 /libavcodec
parent6fe1a1a55b90849974a22118040aef6e17999688 (diff)
downloadffmpeg-3edcacde04911dac4c56fd74053505a493e561f8.tar.gz
init cleanup
Originally committed as revision 2899 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/h263dec.c2
-rw-r--r--libavcodec/h264.c3
-rw-r--r--libavcodec/mjpeg.c8
-rw-r--r--libavcodec/mpeg12.c3
-rw-r--r--libavcodec/mpegvideo.c112
-rw-r--r--libavcodec/mpegvideo.h1
-rw-r--r--libavcodec/rv10.c4
-rw-r--r--libavcodec/svq1.c2
8 files changed, 76 insertions, 59 deletions
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 88db359fe9..b934db3c87 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -42,8 +42,8 @@ int ff_h263_decode_init(AVCodecContext *avctx)
s->workaround_bugs= avctx->workaround_bugs;
// set defaults
+ MPV_decode_defaults(s);
s->quant_precision=5;
- s->progressive_sequence=1;
s->decode_mb= ff_h263_decode_mb;
s->low_delay= 1;
avctx->pix_fmt= PIX_FMT_YUV420P;
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 3f60e35e86..632f8a50f7 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -2166,6 +2166,8 @@ static int decode_init(AVCodecContext *avctx){
H264Context *h= avctx->priv_data;
MpegEncContext * const s = &h->s;
+ MPV_decode_defaults(s);
+
s->avctx = avctx;
common_init(h);
@@ -2173,7 +2175,6 @@ static int decode_init(AVCodecContext *avctx){
s->workaround_bugs= avctx->workaround_bugs;
// set defaults
- s->progressive_sequence=1;
// s->decode_mb= ff_h263_decode_mb;
s->low_delay= 1;
avctx->pix_fmt= PIX_FMT_YUV420P;
diff --git a/libavcodec/mjpeg.c b/libavcodec/mjpeg.c
index 30029d40c0..3325173bca 100644
--- a/libavcodec/mjpeg.c
+++ b/libavcodec/mjpeg.c
@@ -862,13 +862,11 @@ static int mjpeg_decode_init(AVCodecContext *avctx)
memset(&s2, 0, sizeof(MpegEncContext));
s2.avctx= avctx;
// s2->out_format = FMT_MJPEG;
- s2.width = 8;
- s2.height = 8;
- if (MPV_common_init(&s2) < 0)
- return -1;
+ dsputil_init(&s2.dsp, avctx);
+ DCT_common_init(&s2);
+
s->scantable= s2.intra_scantable;
s->idct_put= s2.dsp.idct_put;
- MPV_common_end(&s2);
s->mpeg_enc_ctx_allocated = 0;
s->buffer_size = 102400; /* smaller buffer should be enough,
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 9cfc36d41d..f3d118469d 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -1760,6 +1760,9 @@ typedef struct Mpeg1Context {
static int mpeg_decode_init(AVCodecContext *avctx)
{
Mpeg1Context *s = avctx->priv_data;
+ MpegEncContext *s2 = &s->mpeg_enc_ctx;
+
+ MPV_decode_defaults(s2);
s->mpeg_enc_ctx.avctx= avctx;
s->mpeg_enc_ctx.flags= avctx->flags;
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 58d7430e33..f1cbfd751a 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -502,7 +502,62 @@ static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContex
#undef COPY
}
-/* init common structure for both encoder and decoder */
+/**
+ * sets the given MpegEncContext to common defaults (same for encoding and decoding).
+ * the changed fields will not depend upon the prior state of the MpegEncContext.
+ */
+static void MPV_common_defaults(MpegEncContext *s){
+ s->y_dc_scale_table=
+ s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
+ s->chroma_qscale_table= ff_default_chroma_qscale_table;
+ s->progressive_frame= 1;
+ s->progressive_sequence= 1;
+ s->picture_structure= PICT_FRAME;
+
+ s->coded_picture_number = 0;
+ s->picture_number = 0;
+ s->input_picture_number = 0;
+
+ s->picture_in_gop_number = 0;
+}
+
+/**
+ * sets the given MpegEncContext to defaults for decoding.
+ * the changed fields will not depend upon the prior state of the MpegEncContext.
+ */
+void MPV_decode_defaults(MpegEncContext *s){
+ MPV_common_defaults(s);
+}
+
+/**
+ * sets the given MpegEncContext to defaults for encoding.
+ * the changed fields will not depend upon the prior state of the MpegEncContext.
+ */
+void MPV_encode_defaults(MpegEncContext *s){
+ static int done=0;
+
+ MPV_common_defaults(s);
+
+ if(!done){
+ int i;
+ done=1;
+
+ default_mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) );
+ memset(default_mv_penalty, 0, sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1));
+ memset(default_fcode_tab , 0, sizeof(uint8_t)*(2*MAX_MV+1));
+
+ for(i=-16; i<16; i++){
+ default_fcode_tab[i + MAX_MV]= 1;
+ }
+ }
+ s->me.mv_penalty= default_mv_penalty;
+ s->fcode_tab= default_fcode_tab;
+}
+
+/**
+ * init common structure for both encoder and decoder.
+ * this assumes that some variables like width/height are already set
+ */
int MPV_common_init(MpegEncContext *s)
{
int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y;
@@ -533,28 +588,11 @@ int MPV_common_init(MpegEncContext *s)
s->block_wrap[3]= s->mb_width*2 + 2;
s->block_wrap[4]=
s->block_wrap[5]= s->mb_width + 2;
-
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
- s->chroma_qscale_table= ff_default_chroma_qscale_table;
- if( s->codec_id != CODEC_ID_MPEG1VIDEO &&
- s->codec_id != CODEC_ID_MPEG2VIDEO)
- {
- /* default structure is frame */
- s->progressive_frame= 1;
- s->picture_structure= PICT_FRAME;
-
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
- if (!s->encoding)
- s->progressive_sequence= 1;
- }
- s->coded_picture_number = 0;
-
+
y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);
c_size = (s->mb_width + 2) * (s->mb_height + 2);
yc_size = y_size + 2 * c_size;
-
+
/* convert fourcc to upper case */
s->avctx->codec_tag= toupper( s->avctx->codec_tag &0xFF)
+ (toupper((s->avctx->codec_tag>>8 )&0xFF)<<8 )
@@ -663,9 +701,6 @@ int MPV_common_init(MpegEncContext *s)
CHECKED_ALLOCZ(s->mbintra_table, mb_array_size);
memset(s->mbintra_table, 1, mb_array_size);
- /* default structure is frame */
- s->picture_structure = PICT_FRAME;
-
/* init macroblock skip table */
CHECKED_ALLOCZ(s->mbskip_table, mb_array_size+2);
//Note the +1 is for a quicker mpeg4 slice_end detection
@@ -787,6 +822,8 @@ int MPV_encode_init(AVCodecContext *avctx)
MpegEncContext *s = avctx->priv_data;
int i, dummy;
int chroma_h_shift, chroma_v_shift;
+
+ MPV_encode_defaults(s);
avctx->pix_fmt = PIX_FMT_YUV420P; // FIXME
@@ -1070,28 +1107,6 @@ int MPV_encode_init(AVCodecContext *avctx)
return -1;
}
- { /* set up some save defaults, some codecs might override them later */
- static int done=0;
- if(!done){
- int i;
- done=1;
-
- default_mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) );
- memset(default_mv_penalty, 0, sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1));
- memset(default_fcode_tab , 0, sizeof(uint8_t)*(2*MAX_MV+1));
-
- for(i=-16; i<16; i++){
- default_fcode_tab[i + MAX_MV]= 1;
- }
- }
- }
- s->me.mv_penalty= default_mv_penalty;
- s->fcode_tab= default_fcode_tab;
-
- /* dont use mv_penalty table for crap MV as it would be confused */
- //FIXME remove after fixing / removing old ME
- if (s->me_method < ME_EPZS) s->me.mv_penalty = default_mv_penalty;
-
s->encoding = 1;
/* init */
@@ -1119,7 +1134,7 @@ int MPV_encode_init(AVCodecContext *avctx)
ff_mpeg1_encode_init(s);
#endif
- /* init default q matrix */
+ /* init q matrix */
for(i=0;i<64;i++) {
int j= s->dsp.idct_permutation[i];
#ifdef CONFIG_RISKY
@@ -1153,13 +1168,10 @@ int MPV_encode_init(AVCodecContext *avctx)
if(ff_rate_control_init(s) < 0)
return -1;
- s->picture_number = 0;
- s->input_picture_number = 0;
- s->picture_in_gop_number = 0;
/* motion detector init */
s->f_code = 1;
s->b_code = 1;
-
+
return 0;
}
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 171d66d837..fbbd54065e 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -706,6 +706,7 @@ typedef struct MpegEncContext {
int DCT_common_init(MpegEncContext *s);
+void MPV_decode_defaults(MpegEncContext *s);
int MPV_common_init(MpegEncContext *s);
void MPV_common_end(MpegEncContext *s);
void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 11c9734fc0..461cd032e7 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -441,6 +441,8 @@ static int rv10_decode_init(AVCodecContext *avctx)
MpegEncContext *s = avctx->priv_data;
static int done=0;
+ MPV_decode_defaults(s);
+
s->avctx= avctx;
s->out_format = FMT_H263;
s->codec_id= avctx->codec_id;
@@ -490,8 +492,6 @@ static int rv10_decode_init(AVCodecContext *avctx)
h263_decode_init_vlc(s);
- s->progressive_sequence=1;
-
/* init rv vlc */
if (!done) {
init_vlc(&rv_dc_lum, DC_VLC_BITS, 256,
diff --git a/libavcodec/svq1.c b/libavcodec/svq1.c
index 6a15270b76..781194f03c 100644
--- a/libavcodec/svq1.c
+++ b/libavcodec/svq1.c
@@ -783,6 +783,8 @@ static int svq1_decode_init(AVCodecContext *avctx)
MpegEncContext *s = avctx->priv_data;
int i;
+ MPV_decode_defaults(s);
+
s->avctx = avctx;
s->width = (avctx->width+3)&~3;
s->height = (avctx->height+3)&~3;