changeset 9007:12fc55eb3373

Cleanup of the muxer API, func parameters muxer & muxer_f eliminated. patch by Andriy N. Gritsenko <andrej@lucky.net>
author arpi
date Sun, 19 Jan 2003 00:33:11 +0000
parents d00997f12257
children 654bc667a450
files libmpdemux/muxer.c libmpdemux/muxer.h libmpdemux/muxer_avi.c libmpdemux/muxer_mpeg.c
diffstat 4 files changed, 35 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/muxer.c	Sun Jan 19 00:21:54 2003 +0000
+++ b/libmpdemux/muxer.c	Sun Jan 19 00:33:11 2003 +0000
@@ -14,9 +14,10 @@
 
 #include "muxer.h"
 
-muxer_t* muxer_new_muxer(int type){
+muxer_t *muxer_new_muxer(int type,FILE *f){
     muxer_t* 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);
--- a/libmpdemux/muxer.h	Sun Jan 19 00:21:54 2003 +0000
+++ b/libmpdemux/muxer.h	Sun Jan 19 00:33:11 2003 +0000
@@ -34,6 +34,8 @@
   // mpeg specific:
   unsigned int gop_start; // frame number of this GOP start
   size_t ipb[3]; // sizes of I/P/B frames
+  // muxer of that stream
+  struct muxer_t *muxer;
 } muxer_stream_t;
 
 typedef struct {
@@ -57,17 +59,18 @@
   //int num_streams;
   muxer_stream_t* def_v;  // default video stream (for general headers)
   muxer_stream_t* streams[MUXER_MAX_STREAMS];
-  void (*cont_write_chunk)(struct muxer_t *,muxer_stream_t *,FILE *,size_t,unsigned int);
-  void (*cont_write_header)(struct muxer_t *,FILE *);
-  void (*cont_write_index)(struct muxer_t *,FILE *);
+  void (*cont_write_chunk)(muxer_stream_t *,size_t,unsigned int);
+  void (*cont_write_header)(struct muxer_t *);
+  void (*cont_write_index)(struct muxer_t *);
   muxer_stream_t* (*cont_new_stream)(struct muxer_t *,int);
+  FILE* file;
 } muxer_t;
 
-muxer_t* muxer_new_muxer(int type);
+muxer_t *muxer_new_muxer(int type,FILE *);
 #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)
+#define muxer_write_chunk(a,b,c) a->muxer->cont_write_chunk(a,b,c)
+#define muxer_write_header(muxer) muxer->cont_write_header(muxer)
+#define muxer_write_index(muxer) muxer->cont_write_index(muxer)
 
 void muxer_init_muxer_avi(muxer_t *);
 void muxer_init_muxer_mpeg(muxer_t *);
--- a/libmpdemux/muxer_avi.c	Sun Jan 19 00:21:54 2003 +0000
+++ b/libmpdemux/muxer_avi.c	Sun Jan 19 00:33:11 2003 +0000
@@ -30,6 +30,7 @@
 
 static muxer_stream_t* avifile_new_stream(muxer_t *muxer,int type){
     muxer_stream_t* s;
+    if (!muxer) return NULL;
     if(muxer->avih.dwStreams>=MUXER_MAX_STREAMS){
 	printf("Too many streams! increase MUXER_MAX_STREAMS !\n");
 	return NULL;
@@ -42,6 +43,7 @@
     s->id=muxer->avih.dwStreams;
     s->timer=0.0;
     s->size=0;
+    s->muxer=muxer;
     switch(type){
     case MUXER_TYPE_VIDEO:
       s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
@@ -88,7 +90,8 @@
 }
 }
 
-static void avifile_write_chunk(muxer_t *muxer,muxer_stream_t *s, FILE *f,size_t len,unsigned int flags){
+static void avifile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags){
+    muxer_t *muxer=s->muxer;
 
     // add to the index:
     if(muxer->idx_pos>=muxer->idx_size){
@@ -97,12 +100,12 @@
     }
     muxer->idx[muxer->idx_pos].ckid=s->ckid;
     muxer->idx[muxer->idx_pos].dwFlags=flags; // keyframe?
-    muxer->idx[muxer->idx_pos].dwChunkOffset=ftell(f)-(muxer->movi_start-4);
+    muxer->idx[muxer->idx_pos].dwChunkOffset=ftell(muxer->file)-(muxer->movi_start-4);
     muxer->idx[muxer->idx_pos].dwChunkLength=len;
     ++muxer->idx_pos;
 
     // write out the chunk:
-    write_avi_chunk(f,s->ckid,len,s->buffer); /* unsigned char */
+    write_avi_chunk(muxer->file,s->ckid,len,s->buffer); /* unsigned char */
 
     // alter counters:
     if(s->h.dwSampleSize){
@@ -135,11 +138,12 @@
 // muxer->streams[i]->wf->cbSize
 #define WFSIZE(wf) (sizeof(WAVEFORMATEX)+(((wf)->cbSize)?((wf)->cbSize-2):0))
 
-static void avifile_write_header(muxer_t *muxer,FILE *f){
+static void avifile_write_header(muxer_t *muxer){
   uint32_t riff[3];
   unsigned int i;
   unsigned int hdrsize;
   muxer_info_t info[16];
+  FILE *f=muxer->file;
 
   // RIFF header:
   riff[0]=mmioFOURCC('R','I','F','F');
@@ -275,19 +279,19 @@
   muxer->movi_start=ftell(f);
 }
 
-static void avifile_write_index(muxer_t *muxer,FILE *f){
-  muxer->movi_end=ftell(f);
+static void avifile_write_index(muxer_t *muxer){
+  muxer->movi_end=ftell(muxer->file);
   if(muxer->idx && muxer->idx_pos>0){
       int i;
       // fixup index entries:
 //      for(i=0;i<muxer->idx_pos;i++) muxer->idx[i].dwChunkOffset-=muxer->movi_start-4;
       // write index chunk:
       for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i]));
-      write_avi_chunk(f,ckidAVINEWINDEX,16*muxer->idx_pos,muxer->idx); /* AVIINDEXENTRY */
+      write_avi_chunk(muxer->file,ckidAVINEWINDEX,16*muxer->idx_pos,muxer->idx); /* AVIINDEXENTRY */
       for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i]));
       muxer->avih.dwFlags|=AVIF_HASINDEX;
   }
-  muxer->file_end=ftell(f);
+  muxer->file_end=ftell(muxer->file);
 }
 
 void muxer_init_muxer_avi(muxer_t *muxer){
--- a/libmpdemux/muxer_mpeg.c	Sun Jan 19 00:21:54 2003 +0000
+++ b/libmpdemux/muxer_mpeg.c	Sun Jan 19 00:33:11 2003 +0000
@@ -32,6 +32,7 @@
 static muxer_stream_t* mpegfile_new_stream(muxer_t *muxer,int type){
   muxer_stream_t *s;
 
+  if (!muxer) return NULL;
   if(muxer->avih.dwStreams>=MUXER_MAX_STREAMS){
     printf("Too many streams! increase MUXER_MAX_STREAMS !\n");
     return NULL;
@@ -75,6 +76,7 @@
   s->id=muxer->avih.dwStreams;
   s->timer=0.0;
   s->size=0;
+  s->muxer=muxer;
   muxer->avih.dwStreams++;
   return s;
 }
@@ -239,10 +241,13 @@
   write_mpeg_ts (s->b_buffer+7, dts, 0x10);
 }
 
-static void mpegfile_write_chunk(muxer_t *muxer,muxer_stream_t *s,FILE *f,size_t len,unsigned int flags){
+static void mpegfile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags){
   size_t ptr=0, sz;
   unsigned int pts=0;
+  muxer_t *muxer = s->muxer;
+  FILE *f;
 
+  f = muxer->file;
   if (s->type == MUXER_TYPE_VIDEO) { // try to recognize frame type...
     if (s->buffer[0] != 0 || s->buffer[1] != 0 || s->buffer[2] != 1 || len<6) {
       printf ("Unknown block type, possibly non-MPEG stream!\n");
@@ -358,13 +363,14 @@
   }
 }
 
-static void mpegfile_write_header(muxer_t *muxer,FILE *f){
+static void mpegfile_write_header(muxer_t *muxer){
   unsigned int i;
   size_t sz = MUXER_MPEG_BLOCKSIZE-24;
   unsigned char buff[12];
   muxer_stream_t *s = muxer->streams[0];
   uint32_t l1;
   uint16_t l2;
+  FILE *f = muxer->file;
 
   if (s == NULL)
     return; // no streams!?
@@ -407,7 +413,7 @@
   muxer->movi_end = MUXER_MPEG_BLOCKSIZE;
 }
 
-static void mpegfile_write_index(muxer_t *muxer,FILE *f){
+static void mpegfile_write_index(muxer_t *muxer){
   unsigned int i;
   unsigned int rsr;
 
@@ -415,9 +421,9 @@
   // finish all but one video and audio streams
   rsr = muxer->sysrate; // reserve it since it's silly change it at that point
   for (i = 0; i < muxer->avih.dwStreams-1; i++)
-    write_mpeg_block (muxer, muxer->streams[i], f, NULL, 0, 0);
+    write_mpeg_block (muxer, muxer->streams[i], muxer->file, NULL, 0, 0);
   // end sequence: ISO-11172-End (0x1b9) and finish very last block
-  write_mpeg_block (muxer, muxer->streams[i], f, NULL, 0, 1);
+  write_mpeg_block (muxer, muxer->streams[i], muxer->file, NULL, 0, 1);
 //fprintf (stderr, "PTS to SCR delay: min %u.%03u, max %u.%03u\n",
 //	mpeg_min_delay/90000, (mpeg_min_delay/90)%1000,
 //	mpeg_max_delay/90000, (mpeg_max_delay/90)%1000);