changeset 1289:3f490fad9bdf

some code clanup (first step to libdemuxer)
author arpi
date Sat, 07 Jul 2001 18:46:15 +0000
parents c311bfd737b1
children af0b764f34c5
files asfheader.c aviheader.c dec_audio.c demux_mpg.c mplayer.c stheader.h
diffstat 6 files changed, 55 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/asfheader.c	Sat Jul 07 16:37:02 2001 +0000
+++ b/asfheader.c	Sat Jul 07 18:46:15 2001 +0000
@@ -165,7 +165,7 @@
       stream_read(demuxer->stream,(char*) buffer,streamh.type_size);
       switch(*((unsigned int*)&streamh.type)){
       case 0xF8699E40: { // guid_audio_stream
-        sh_audio_t* sh_audio=new_sh_audio(streamh.stream_no & 0x7F);
+        sh_audio_t* sh_audio=new_sh_audio(demuxer,streamh.stream_no & 0x7F);
         sh_audio->wf=calloc((streamh.type_size<sizeof(WAVEFORMATEX))?sizeof(WAVEFORMATEX):streamh.type_size,1);
         memcpy(sh_audio->wf,buffer,streamh.type_size);
         if(verbose>=1) print_wave_header(sh_audio->wf);
@@ -183,7 +183,7 @@
         break;
         }
       case 0xBC19EFC0: { // guid_video_stream
-        sh_video_t* sh_video=new_sh_video(streamh.stream_no & 0x7F);
+        sh_video_t* sh_video=new_sh_video(demuxer,streamh.stream_no & 0x7F);
         int len=streamh.type_size-(4+4+1+2);
 //        sh_video->bih=malloc(chunksize); memset(sh_video->bih,0,chunksize);
         sh_video->bih=calloc((len<sizeof(BITMAPINFOHEADER))?sizeof(BITMAPINFOHEADER):len,1);
--- a/aviheader.c	Sat Jul 07 16:37:02 2001 +0000
+++ b/aviheader.c	Sat Jul 07 18:46:15 2001 +0000
@@ -70,11 +70,11 @@
       chunksize-=MIN(size2,sizeof(h));
       ++stream_id;
       if(h.fccType==streamtypeVIDEO){
-        sh_video=new_sh_video(stream_id);
+        sh_video=new_sh_video(demuxer,stream_id);
         memcpy(&sh_video->video,&h,sizeof(h));
       } else
       if(h.fccType==streamtypeAUDIO){
-        sh_audio=new_sh_audio(stream_id);
+        sh_audio=new_sh_audio(demuxer,stream_id);
         memcpy(&sh_audio->audio,&h,sizeof(h));
       }
       last_fccType=h.fccType;
--- a/dec_audio.c	Sat Jul 07 16:37:02 2001 +0000
+++ b/dec_audio.c	Sat Jul 07 18:46:15 2001 +0000
@@ -31,11 +31,11 @@
 #include "loader/DirectShow/DS_AudioDec.h"
 
 
-static sh_audio_t* ac3_audio_sh=NULL;
+static sh_audio_t* dec_audio_sh=NULL;
 
 // AC3 decoder buffer callback:
 static void ac3_fill_buffer(uint8_t **start,uint8_t **end){
-    int len=ds_get_packet(ac3_audio_sh->ds,start);
+    int len=ds_get_packet(dec_audio_sh->ds,start);
     //printf("<ac3:%d>\n",len);
     if(len<0)
           *start = *end = NULL;
@@ -43,6 +43,13 @@
           *end = *start + len;
 }
 
+// MP3 decoder buffer callback:
+int mplayer_audio_read(char *buf,int size){
+  int len;
+  len=demux_read_data(dec_audio_sh->ds,buf,size);
+  return len;
+}
+
 
 int init_audio(sh_audio_t *sh_audio){
 
@@ -177,7 +184,7 @@
 }
 case 3: {
   // Dolby AC3 audio:
-  ac3_audio_sh=sh_audio; // save sh_audio for the callback:
+  dec_audio_sh=sh_audio; // save sh_audio for the callback:
   ac3_config.fill_buffer_callback = ac3_fill_buffer;
   ac3_config.num_output_ch = 2;
   ac3_config.flags = 0;
@@ -221,6 +228,7 @@
 }
 case 1: {
   // MPEG Audio:
+  dec_audio_sh=sh_audio; // save sh_audio for the callback:
 #ifdef USE_FAKE_MONO
   MP3_Init(fakemono);
 #else
--- a/demux_mpg.c	Sat Jul 07 16:37:02 2001 +0000
+++ b/demux_mpg.c	Sat Jul 07 18:46:15 2001 +0000
@@ -36,8 +36,8 @@
 //static char dvdaudio_table[256];
 //static unsigned int packet_start_pos=0;
 
-extern void *new_sh_audio(int id);
-extern void *new_sh_video(int id);
+extern void *new_sh_audio(demuxer_t *demux,int id);
+extern void *new_sh_video(demuxer_t *demux,int id);
 
 static int demux_mpg_read_packet(demuxer_t *demux,int id){
   int d;
@@ -157,7 +157,7 @@
 //        aid=128+(aid&0x7F);
         // aid=0x80..0xBF
 
-        if(!demux->a_streams[aid]) new_sh_audio(aid);
+        if(!demux->a_streams[aid]) new_sh_audio(demux,aid);
         if(demux->audio->id==-1) demux->audio->id=aid;
 
       if(demux->audio->id==aid){
@@ -210,7 +210,7 @@
   if(id>=0x1C0 && id<=0x1DF){
     // mpeg audio
     int aid=id-0x1C0;
-    if(!demux->a_streams[aid]) new_sh_audio(aid);
+    if(!demux->a_streams[aid]) new_sh_audio(demux,aid);
     if(demux->audio->id==-1) demux->audio->id=aid;
     if(demux->audio->id==aid){
       ds=demux->audio;
@@ -221,7 +221,7 @@
   if(id>=0x1E0 && id<=0x1EF){
     // mpeg video
     int aid=id-0x1E0;
-    if(!demux->v_streams[aid]) new_sh_video(aid);
+    if(!demux->v_streams[aid]) new_sh_video(demux,aid);
     if(demux->video->id==-1) demux->video->id=aid;
     if(demux->video->id==aid){
       ds=demux->video;
--- a/mplayer.c	Sat Jul 07 16:37:02 2001 +0000
+++ b/mplayer.c	Sat Jul 07 18:46:15 2001 +0000
@@ -20,15 +20,15 @@
 #include "version.h"
 #include "config.h"
 
-#if	defined(sun)
-#define	DEFAULT_CDROM_DEVICE	"/vol/dev/aliases/cdrom0"
-#elif defined(__FreeBSD__)
-#define DEFAULT_CDROM_DEVICE    "/dev/cdrom"
+#ifdef __FreeBSD__
 #include <sys/cdrio.h>
-#else
-#define	DEFAULT_CDROM_DEVICE	"/dev/cdrom"
 #endif
 
+#ifdef sun
+#define	DEFAULT_CDROM_DEVICE	"/vol/dev/aliases/cdrom0"
+#else
+#define DEFAULT_CDROM_DEVICE    "/dev/cdrom"
+#endif
 
 #ifndef MAX_OUTBURST
 #error "============================================="
@@ -74,14 +74,9 @@
 
 #include "opendivx/decore.h"
 
-
-#ifdef X11_FULLSCREEN
-extern int vo_screenwidth;
-#endif
-
 extern char* win32_codec_name;  // must be set before calling DrvOpen() !!!
 
-extern int errno;
+// extern int errno;
 
 #include "linux/getch2.h"
 #include "linux/keycodes.h"
@@ -109,7 +104,6 @@
 
 #define ABS(x) (((x)>=0)?(x):(-(x)))
 
-static subtitle* subtitles=NULL;
 void find_sub(subtitle* subtitles,int key);
 
 static int
@@ -160,27 +154,24 @@
 	return buff;
 }
 
-static int max_framesize=0;
-
-//static int show_packets=0;
-
 //**************************************************************************//
 //**************************************************************************//
 //             Input media streaming & demultiplexer:
 //**************************************************************************//
 
+static int max_framesize=0;
+//static int show_packets=0;
+
 #include "stream.h"
 #include "demuxer.h"
 
 #include "stheader.h"
 
-int avi_bitrate=0;
-
-demuxer_t *demuxer=NULL;
+static int avi_bitrate=0;
 
 //#include "aviprint.c"
 
-sh_audio_t* new_sh_audio(int id){
+sh_audio_t* new_sh_audio(demuxer_t *demuxer,int id){
     if(demuxer->a_streams[id]){
         printf("Warning! Audio stream header %d redefined!\n",id);
     } else {
@@ -191,7 +182,7 @@
     return demuxer->a_streams[id];
 }
 
-sh_video_t* new_sh_video(int id){
+sh_video_t* new_sh_video(demuxer_t *demuxer,int id){
     if(demuxer->v_streams[id]){
         printf("Warning! video stream header %d redefined!\n",id);
     } else {
@@ -202,13 +193,6 @@
     return demuxer->v_streams[id];
 }
 
-demux_stream_t *d_audio=NULL;
-demux_stream_t *d_video=NULL;
-demux_stream_t *d_dvdsub=NULL;
-
-sh_audio_t *sh_audio=NULL;
-sh_video_t *sh_video=NULL;
-
 char* encode_name=NULL;
 char* encode_index_name=NULL;
 int encode_bitrate=0;
@@ -243,22 +227,10 @@
 };
 
 //**************************************************************************//
-//             Audio codecs:
+//             The OpenDivX stuff:
 //**************************************************************************//
 
-// MP3 decoder buffer callback:
-int mplayer_audio_read(char *buf,int size){
-  int len;
-  len=demux_read_data(sh_audio->ds,buf,size);
-  return len;
-}
-
-//#include "dec_audio.c"
-
 #ifndef NEW_DECORE
-//**************************************************************************//
-//             The OpenDivX stuff:
-//**************************************************************************//
 
 unsigned char *opendivx_src[3];
 int opendivx_stride[3];
@@ -289,13 +261,13 @@
 //**************************************************************************//
 
 static vo_functions_t *video_out=NULL;
-ao_functions_t *audio_out=NULL;
+static ao_functions_t *audio_out=NULL;
 
-double video_time_usage=0;
-double vout_time_usage=0;
-double audio_time_usage=0;
-int total_time_usage_start=0;
-int benchmark=0;
+static double video_time_usage=0;
+static double vout_time_usage=0;
+static double audio_time_usage=0;
+static int total_time_usage_start=0;
+static int benchmark=0;
 
 static int play_in_bg=0;
 
@@ -496,6 +468,17 @@
  int mplayer(int argc,char* argv[], char *envp[]){
 #endif
 
+static subtitle* subtitles=NULL;
+
+static demuxer_t *demuxer=NULL;
+
+static demux_stream_t *d_audio=NULL;
+static demux_stream_t *d_video=NULL;
+static demux_stream_t *d_dvdsub=NULL;
+
+static sh_audio_t *sh_audio=NULL;
+static sh_video_t *sh_video=NULL;
+
 char* filename=NULL; //"MI2-Trailer.avi";
 stream_t* stream=NULL;
 int file_format=DEMUXER_TYPE_UNKNOWN;
@@ -816,7 +799,7 @@
   demuxer=new_demuxer(stream,DEMUXER_TYPE_MOV,audio_id,video_id,dvdsub_id);
 //  stream_seek(demuxer->stream,seek_to_byte);
   if(mov_check_file(demuxer)){
-      printf("Detected MOV file format!\n");
+      printf("Detected QuickTime/MOV file format!\n");
       file_format=DEMUXER_TYPE_MOV;
   }
 }
@@ -832,10 +815,6 @@
 d_audio=demuxer->audio;
 d_video=demuxer->video;
 d_dvdsub=demuxer->sub;
-//d_audio->sh=sh_audio; 
-//d_video->sh=sh_video; 
-//sh_audio=d_audio->sh;sh_audio->ds=d_audio;
-//sh_video=d_video->sh;sh_video->ds=d_video;
 
 sh_audio=NULL;
 sh_video=NULL;
@@ -973,7 +952,7 @@
  case DEMUXER_TYPE_MPEG_ES: {
    d_audio->type=0;
    has_audio=0;sh_audio=NULL;   // ES streams has no audio channel
-   d_video->sh=new_sh_video(0); // create dummy video stream header, id=0
+   d_video->sh=new_sh_video(demuxer,0); // create dummy video stream header, id=0
    break;
  }
  case DEMUXER_TYPE_MPEG_PS: {
--- a/stheader.h	Sat Jul 07 16:37:02 2001 +0000
+++ b/stheader.h	Sat Jul 07 18:46:15 2001 +0000
@@ -60,6 +60,6 @@
   HIC hic;  // handle
 } sh_video_t;
 
-sh_audio_t* new_sh_audio(int id);
-sh_video_t* new_sh_video(int id);
+sh_audio_t* new_sh_audio(demuxer_t *demuxer,int id);
+sh_video_t* new_sh_video(demuxer_t *demuxer,int id);