[MPlayer-dev-eng] [PATCH] Some cleanup about mencoder.

Andriy N. Gritsenko andrej at lucky.net
Fri Jan 17 18:59:15 CET 2003


    Hi, people!

    I've looked into code and I was wonder why there are variables muxer
and muxer_f into mencoder.c and tsese are _always_ implicitly used by any
of ve_*, and more of that - mencoder_write_chunk defined explicitly (!)
everywhere in *.c files! Since there are only muxer and muxer file (it's
impossible in current code have to another ones and it's too weird to
have another, IMHO) so I could simplify all muxer_* code well. :)  Please
commit it. :)

    With best wishes.
    Andriy.
-------------- next part --------------
diff -udpr MPlayer-20030117.orig/libmpcodecs/ve_divx4.c MPlayer-20030117/libmpcodecs/ve_divx4.c
--- MPlayer-20030117.orig/libmpcodecs/ve_divx4.c	Sat Dec 28 00:43:19 2002
+++ MPlayer-20030117/libmpcodecs/ve_divx4.c	Fri Jan 17 19:29:18 2003
@@ -44,7 +44,6 @@
 
 static int pass;
 extern char* passtmpfile;
-extern void mencoder_write_chunk(muxer_stream_t *s,int len,unsigned int flags);
 
 #include <encore2.h>
 
@@ -273,7 +272,7 @@ static int put_image(struct vf_instance_
 					       enc_result.quantizer);
 	}
     }
-    mencoder_write_chunk(mux_v,vf->priv->enc_frame.length,enc_result.is_key_frame?0x10:0);
+    muxer_write_chunk(mux_v,vf->priv->enc_frame.length,enc_result.is_key_frame?0x10:0);
     return 1;
 }
 
diff -udpr MPlayer-20030117.orig/libmpcodecs/ve_lavc.c MPlayer-20030117/libmpcodecs/ve_lavc.c
--- MPlayer-20030117.orig/libmpcodecs/ve_lavc.c	Sun Jan  5 18:06:17 2003
+++ MPlayer-20030117/libmpcodecs/ve_lavc.c	Fri Jan 17 19:29:58 2003
@@ -27,7 +27,6 @@
 #include "vf.h"
 
 extern char* passtmpfile;
-extern void mencoder_write_chunk(muxer_stream_t *s,int len,unsigned int flags);
 
 //===========================================================================//
 
@@ -486,7 +485,7 @@ static int put_image(struct vf_instance_
 	out_size = avcodec_encode_video(lavc_venc_context, mux_v->buffer, mux_v->buffer_size,
 	    pic);
 
-    mencoder_write_chunk(mux_v,out_size,lavc_venc_context->coded_frame->key_frame?0x10:0);
+    muxer_write_chunk(mux_v,out_size,lavc_venc_context->coded_frame->key_frame?0x10:0);
         
 #if LIBAVCODEC_BUILD >= 4643
     /* store psnr / pict size / type / qscale */
diff -udpr MPlayer-20030117.orig/libmpcodecs/ve_libdv.c MPlayer-20030117/libmpcodecs/ve_libdv.c
--- MPlayer-20030117.orig/libmpcodecs/ve_libdv.c	Sat Dec 28 00:43:19 2002
+++ MPlayer-20030117/libmpcodecs/ve_libdv.c	Fri Jan 17 19:30:10 2003
@@ -23,8 +23,6 @@
 
 #include <libdv/dv.h>
 
-extern void mencoder_write_chunk(muxer_stream_t *s,int len,unsigned int flags);
-
 #ifndef DV_WIDTH
 #define DV_WIDTH       720
 #define DV_PAL_HEIGHT  576
@@ -78,7 +76,7 @@ static int put_image(struct vf_instance_
 	(mpi->flags&MP_IMGFLAG_YUV) ? e_dv_color_yuv : e_dv_color_rgb,
 	mux_v->buffer);
 
-    mencoder_write_chunk(mux_v, 480 * (vf->priv->enc->isPAL ? 300 : 250) , 0x10);
+    muxer_write_chunk(mux_v, 480 * (vf->priv->enc->isPAL ? 300 : 250) , 0x10);
     return 1;
 }
 
diff -udpr MPlayer-20030117.orig/libmpcodecs/ve_qtvideo.c MPlayer-20030117/libmpcodecs/ve_qtvideo.c
--- MPlayer-20030117.orig/libmpcodecs/ve_qtvideo.c	Fri Jan  3 14:26:16 2003
+++ MPlayer-20030117/libmpcodecs/ve_qtvideo.c	Fri Jan 17 19:30:25 2003
@@ -90,8 +90,6 @@ static    long (*CountComponents)(Compon
 static    OSErr (*GetComponentInfo)(Component prev,ComponentDescription* desc,Handle h1,Handle h2,Handle h3);
 
 
-extern void mencoder_write_chunk(muxer_stream_t *s,int len,unsigned int flags);
-
 
 //static int format=mmioFOURCC('S','V','Q','1');
 static int format=mmioFOURCC('S','V','Q','3');
@@ -260,7 +258,7 @@ if(!codec_inited){
     printf("Size %i->%i   \n",stride*height,compressedsize);
     printf("Ratio: %i:1\n",(stride*height)/compressedsize);
 #endif
-    mencoder_write_chunk(mux_v, compressedsize , similarity?0:0x10);
+    muxer_write_chunk(mux_v, compressedsize , similarity?0:0x10);
 
     if(((*desc)->idSize)>MAX_IDSIZE){
 	printf("FATAL! idSize=%d too big, increase MAX_IDSIZE in ve_qtvideo.c!\n",((*desc)->idSize));
diff -udpr MPlayer-20030117.orig/libmpcodecs/ve_rawrgb.c MPlayer-20030117/libmpcodecs/ve_rawrgb.c
--- MPlayer-20030117.orig/libmpcodecs/ve_rawrgb.c	Sat Dec 28 00:43:19 2002
+++ MPlayer-20030117/libmpcodecs/ve_rawrgb.c	Fri Jan 17 19:30:37 2003
@@ -16,8 +16,6 @@
 #include "mp_image.h"
 #include "vf.h"
 
-extern void mencoder_write_chunk(muxer_stream_t *s,int len,unsigned int flags);
-
 //===========================================================================//
 
 struct vf_priv_s {
@@ -48,7 +46,7 @@ static int query_format(struct vf_instan
 
 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
     mux_v->buffer=mpi->planes[0];
-    mencoder_write_chunk(mux_v, mpi->width*mpi->height*3, 0x10);
+    muxer_write_chunk(mux_v, mpi->width*mpi->height*3, 0x10);
     return 1;
 }
 
diff -udpr MPlayer-20030117.orig/libmpcodecs/ve_vfw.c MPlayer-20030117/libmpcodecs/ve_vfw.c
--- MPlayer-20030117.orig/libmpcodecs/ve_vfw.c	Sat Dec 28 00:43:19 2002
+++ MPlayer-20030117/libmpcodecs/ve_vfw.c	Fri Jan 17 19:30:59 2003
@@ -25,8 +25,6 @@
 
 #include "muxer.h"
 
-extern void mencoder_write_chunk(muxer_stream_t *s,int len,unsigned int flags);
-
 //===========================================================================//
 
 static char *vfw_param_codec = NULL;
@@ -244,7 +242,7 @@ static int put_image(struct vf_instance_
     int ret;
 //    flip_upside_down(vo_image_ptr,vo_image_ptr,3*vo_w,vo_h); // dirty hack
     ret=vfw_encode_frame(mux_v->bih, mux_v->buffer, vfw_bih, mpi->planes[0], &flags, 10000);
-    mencoder_write_chunk(mux_v,mux_v->bih->biSizeImage,flags);
+    muxer_write_chunk(mux_v,mux_v->bih->biSizeImage,flags);
     return 1;
 }
 
diff -udpr MPlayer-20030117.orig/libmpcodecs/ve_xvid.c MPlayer-20030117/libmpcodecs/ve_xvid.c
--- MPlayer-20030117.orig/libmpcodecs/ve_xvid.c	Sat Dec 28 00:43:19 2002
+++ MPlayer-20030117/libmpcodecs/ve_xvid.c	Fri Jan 17 19:31:19 2003
@@ -65,7 +65,6 @@ static int const motion_presets[7] = {
 };
 
 extern char* passtmpfile;
-extern void mencoder_write_chunk(muxer_stream_t *s,int len,unsigned int flags);
 
 static int xvidenc_pass = 0;
 static int xvidenc_quality = 4;
@@ -454,7 +453,7 @@ put_image(struct vf_instance_s* vf, mp_i
     }
     
     // write output
-    mencoder_write_chunk(fp->mux, fp->enc_frame.length, fp->enc_frame.intra==1 ? 0x10 : 0);
+    muxer_write_chunk(fp->mux, fp->enc_frame.length, fp->enc_frame.intra==1 ? 0x10 : 0);
 
     // update the VBR engine
     vbrUpdate(&fp->vbr_state, enc_stats.quant, fp->enc_frame.intra,
diff -udpr MPlayer-20030117.orig/libmpdemux/muxer.c MPlayer-20030117/libmpdemux/muxer.c
--- MPlayer-20030117.orig/libmpdemux/muxer.c	Sat Dec 28 02:48:07 2002
+++ MPlayer-20030117/libmpdemux/muxer.c	Fri Jan 17 19:47:16 2003
@@ -12,11 +12,13 @@
 #include "wine/avifmt.h"
 #include "wine/vfw.h"
 
+#define _MUXER_C 1
 #include "muxer.h"
 
-muxer_t* muxer_new_muxer(int type){
-    muxer_t* muxer=malloc(sizeof(muxer_t));
+void muxer_new_muxer(int type,FILE *f){
+    muxer=malloc(sizeof(muxer_t));
     memset(muxer,0,sizeof(muxer_t));
+    muxer->file = f;
     switch (type) {
       case MUXER_TYPE_MPEG:
 	muxer_init_muxer_mpeg(muxer);
@@ -25,5 +27,4 @@ muxer_t* muxer_new_muxer(int type){
       default:
 	muxer_init_muxer_avi(muxer);
     }
-    return muxer;
 }
diff -udpr MPlayer-20030117.orig/libmpdemux/muxer.h MPlayer-20030117/libmpdemux/muxer.h
--- MPlayer-20030117.orig/libmpdemux/muxer.h	Sat Dec 28 00:43:20 2002
+++ MPlayer-20030117/libmpdemux/muxer.h	Fri Jan 17 19:44:24 2003
@@ -61,13 +61,20 @@ typedef struct muxer_t{
   void (*cont_write_header)(struct muxer_t *,FILE *);
   void (*cont_write_index)(struct muxer_t *,FILE *);
   muxer_stream_t* (*cont_new_stream)(struct muxer_t *,int);
+  FILE* file;
 } muxer_t;
 
-muxer_t* muxer_new_muxer(int type);
-#define muxer_new_stream(muxer,a) muxer->cont_new_stream(muxer,a)
-#define muxer_write_chunk(muxer,a,b,c,d) muxer->cont_write_chunk(muxer,a,b,c,d)
-#define muxer_write_header(muxer,f) muxer->cont_write_header(muxer,f)
-#define muxer_write_index(muxer,f) muxer->cont_write_index(muxer,f)
+#ifdef _MUXER_C
+muxer_t *muxer = NULL;
+#else
+extern muxer_t *muxer;
+#endif
+
+void muxer_new_muxer(int type,FILE *);
+#define muxer_new_stream(a) muxer->cont_new_stream(muxer,a)
+#define muxer_write_chunk(a,b,c) muxer->cont_write_chunk(muxer,a,b,muxer->file,c)
+#define muxer_write_header() muxer->cont_write_header(muxer,muxer->file)
+#define muxer_write_index() muxer->cont_write_index(muxer,muxer->file)
 
 void muxer_init_muxer_avi(muxer_t *);
 void muxer_init_muxer_mpeg(muxer_t *);
diff -udpr MPlayer-20030117.orig/mencoder.c MPlayer-20030117/mencoder.c
--- MPlayer-20030117.orig/mencoder.c	Fri Jan 17 01:03:06 2003
+++ MPlayer-20030117/mencoder.c	Fri Jan 17 19:49:52 2003
@@ -303,14 +303,8 @@ static void exit_sighandler(int x){
     interrupted=1;
 }
 
-static muxer_t* muxer=NULL;
 static FILE* muxer_f=NULL;
 
-// callback for ve_*.c:
-void mencoder_write_chunk(muxer_stream_t *s,int len,unsigned int flags){
-    muxer_write_chunk(muxer,s,muxer_f,len,flags);
-}
-
 extern void print_wave_header(WAVEFORMATEX *h);
 
 int main(int argc,char* argv[]){
@@ -606,11 +600,11 @@ if(!muxer_f) {
   mencoder_exit(1,NULL);
 }
 
-muxer=muxer_new_muxer(out_file_format);
+muxer_new_muxer(out_file_format,muxer_f);
 
 // ============= VIDEO ===============
 
-mux_v=muxer_new_stream(muxer,MUXER_TYPE_VIDEO);
+mux_v=muxer_new_stream(MUXER_TYPE_VIDEO);
 
 mux_v->buffer_size=0x200000; // 2MB
 mux_v->buffer=malloc(mux_v->buffer_size);
@@ -704,7 +698,7 @@ if ((force_fourcc != NULL) && (strlen(fo
 // ============= AUDIO ===============
 if(sh_audio){
 
-mux_a=muxer_new_stream(muxer,MUXER_TYPE_AUDIO);
+mux_a=muxer_new_stream(MUXER_TYPE_AUDIO);
 
 mux_a->buffer_size=0x100000; //16384;
 mux_a->buffer=malloc(mux_a->buffer_size);
@@ -815,7 +809,7 @@ if(audio_delay!=0.0){
 } // if(sh_audio)
 
 printf(MSGTR_WritingAVIHeader);
-muxer_write_header(muxer,muxer_f);
+muxer_write_header();
 
 decoded_frameno=0;
 
@@ -1001,7 +995,7 @@ if(sh_audio){
 	    }
 	}
 	if(len<=0) break; // EOF?
-	muxer_write_chunk(muxer,mux_a,muxer_f,len,0x10);
+	muxer_write_chunk(mux_a,len,0x10);
 	if(!mux_a->h.dwSampleSize && mux_a->timer>0)
 	    mux_a->wf->nAvgBytesPerSec=0.5f+(double)mux_a->size/mux_a->timer; // avg bps (VBR)
 	if(mux_a->buffer_len>=len){
@@ -1081,11 +1075,11 @@ ptimer_start = GetTimerMS();
 switch(mux_v->codec){
 case VCODEC_COPY:
     mux_v->buffer=start;
-    if(skip_flag<=0) muxer_write_chunk(muxer,mux_v,muxer_f,in_size,(sh_video->ds->flags&1)?0x10:0);
+    if(skip_flag<=0) muxer_write_chunk(mux_v,in_size,(sh_video->ds->flags&1)?0x10:0);
     break;
 case VCODEC_FRAMENO:
     mux_v->buffer=(unsigned char *)&decoded_frameno; // tricky
-    if(skip_flag<=0) muxer_write_chunk(muxer,mux_v,muxer_f,sizeof(int),0x10);
+    if(skip_flag<=0) muxer_write_chunk(mux_v,sizeof(int),0x10);
     break;
 default:
     // decode_video will callback down to ve_*.c encoders, through the video filters
@@ -1096,7 +1090,7 @@ default:
 	// unwanted skipping of a frame, what to do?
 	if(skip_limit==0){
 	    // skipping not allowed -> write empty frame:
-	    muxer_write_chunk(muxer,mux_v,muxer_f,0,0);
+	    muxer_write_chunk(mux_v,0,0);
 	} else {
 	    // skipping allowed -> skip it and distriubute timer error:
 	    v_timer_corr-=(float)mux_v->h.dwScale/mux_v->h.dwRate;
@@ -1113,7 +1107,7 @@ if(skip_flag<0){
 	if(!tv_param_on && !verbose) printf(MSGTR_DuplicateFrames,-skip_flag);
     while(skip_flag<0){
 	duplicatedframes++;
-	muxer_write_chunk(muxer,mux_v,muxer_f,0,0);
+	muxer_write_chunk(mux_v,0,0);
 	++skip_flag;
     }
 } else
@@ -1272,11 +1266,11 @@ if(sh_audio && mux_a->codec==ACODEC_VBRM
 #endif
 
 printf(MSGTR_WritingAVIIndex);
-muxer_write_index(muxer,muxer_f);
+muxer_write_index();
 muxer_f_size=ftello(muxer_f);
 printf(MSGTR_FixupAVIHeader);
 fseek(muxer_f,0,SEEK_SET);
-muxer_write_header(muxer,muxer_f); // update header
+muxer_write_header(); // update header
 if(ferror(muxer_f) || fclose(muxer_f) != 0) {
     mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_ErrorWritingFile, out_filename);
     mencoder_exit(1, NULL);


More information about the MPlayer-dev-eng mailing list