changeset 552:c2a449f90087

dvd sub support reading
author arpi_esp
date Fri, 20 Apr 2001 22:35:15 +0000
parents e6263c6d377a
children 576d0157aa42
files cfg-mplayer.h demux_mpg.c demuxer.c mplayer.c
diffstat 4 files changed, 54 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/cfg-mplayer.h	Fri Apr 20 20:48:25 2001 +0000
+++ b/cfg-mplayer.h	Fri Apr 20 22:35:15 2001 +0000
@@ -60,8 +60,10 @@
 	{"noalsa", &alsa, CONF_TYPE_FLAG, 0, 1, 0},
 	{"ni", &force_ni, CONF_TYPE_FLAG, 0, 0, 1},
 	{"noni", &force_ni, CONF_TYPE_FLAG, 0, 1, 0},
+
 	{"aid", &audio_id, CONF_TYPE_INT, CONF_RANGE, 0, 256},
 	{"vid", &video_id, CONF_TYPE_INT, CONF_RANGE, 0, 256},
+	{"sid", &dvdsub_id, CONF_TYPE_INT, CONF_RANGE, 0, 32},
 
 	{"dumpfile", &stream_dump_name, CONF_TYPE_STRING, 0, 0, 0},
 	{"dumpaudio", &stream_dump_type, CONF_TYPE_FLAG, 0, 0, 1},
@@ -78,7 +80,7 @@
 	{"pp", &divx_quality, CONF_TYPE_INT, CONF_RANGE, 0, 63},
 	{"br", &encode_bitrate, CONF_TYPE_INT, CONF_RANGE, 10000, 10000000},
 #ifdef HAVE_PNG
-	{"z", &z_compression, CONF_TYPE_INT, CONF_RANGE, 0, 9},
+	{"z", &z_compression, CONF_TYPE_INT, CONF_RANGE, 0, 10},
 #endif	
 
 	{"x", &screen_size_x, CONF_TYPE_INT, CONF_RANGE, 1, 4096},
--- a/demux_mpg.c	Fri Apr 20 20:48:25 2001 +0000
+++ b/demux_mpg.c	Fri Apr 20 22:35:15 2001 +0000
@@ -3,6 +3,10 @@
 //#define MAX_PS_PACKETSIZE 2048
 #define MAX_PS_PACKETSIZE (224*1024)
 
+static void parse_dvdsub(unsigned char *buf,int len){
+    printf("\rDVDsub packet: %d  \n",len);
+}
+
 static int mpeg_pts_error=0;
 
 static unsigned int read_mpeg_timestamp(stream_t *s,int c){
@@ -112,11 +116,36 @@
     
     //============== DVD Audio sub-stream ======================
     if(id==0x1BD){
-      int aid=128+(stream_read_char(demux->stream)&0x7F);--len;
+      int aid=stream_read_char(demux->stream);--len;
       if(len<3) return -1; // invalid audio packet
+      
+      // AID:
+      // 0x20..0x3F  subtitle
+      // 0x80..0x9F  AC3 audio
+      // 0xA0..0xBF  PCM audio
+      
+      if((aid & 0xE0) == 0x20){
+        // subtitle:
+        aid&=0x1F;
 
-      if(!avi_header.a_streams[aid]) new_sh_audio(aid);
-      if(demux->audio->id==-1) demux->audio->id=aid;
+        if(!avi_header.s_streams[aid]){
+            printf("==> Found subtitle: %d\n",aid);
+            avi_header.s_streams[aid]=1;
+            // new_sh_audio(aid);
+        }
+
+        //if(demux->audio->id==-1) demux->audio->id=aid; // autodetect :)
+        if(demux->sub->id==aid){
+            ds=demux->sub;
+        }
+          
+      } else if((aid & 0xC0) == 0x80) {
+
+//        aid=128+(aid&0x7F);
+        // aid=0x80..0xBF
+
+        if(!avi_header.a_streams[aid]) new_sh_audio(aid);
+        if(demux->audio->id==-1) demux->audio->id=aid;
 
       if(demux->audio->id==aid){
 //        int type;
@@ -130,7 +159,7 @@
         len-=3;
         if(ds->type==-1){
           // autodetect type
-          ds->type=((aid&0x70)==0x20)?2:3;
+          ds->type=((aid&0xE0)==0xA0)?2:3;
         }
         if(ds->type==2 && len>=2){
           // read PCM header
@@ -144,8 +173,11 @@
           }
           if(!len) printf("End of packet while searching for PCM header\n");
         }
-      }
-    }
+      } //  if(demux->audio->id==aid)
+
+      } else printf("Unknown 0x1BD substream: 0x%02X  \n",aid);
+
+    } //if(id==0x1BD)
 
   } else {
     if(c!=0x0f){
@@ -194,6 +226,7 @@
     }
 #endif
     ds_read_packet(ds,demux->stream,len,pts/90000.0f,0);
+    if(ds==demux->sub) parse_dvdsub(ds->last->buffer,ds->last->len);
     return 1;
   }
   if(verbose>=2) printf("DEMUX_MPG: Skipping %d data bytes from packet %04X\n",len,id);
@@ -256,12 +289,14 @@
   } // else
   if(demux->synced==2){
       ret=demux_mpg_read_packet(demux,head);
+/*
       if(!ret)
         if(--max_packs==0){
           demux->stream->eof=1;
           printf("demux: file doesn't contain the selected audio or video stream\n");
           return 0;
         }
+*/
   } else {
     if(head>=0x100 && head<0x1B0){
       if(head==0x100)
--- a/demuxer.c	Fri Apr 20 20:48:25 2001 +0000
+++ b/demuxer.c	Fri Apr 20 22:35:15 2001 +0000
@@ -94,15 +94,17 @@
 //  int time_src;// time source (pts/file/bps)
   demux_stream_t *audio;
   demux_stream_t *video;
+  demux_stream_t *sub;
 } demuxer_t;
 
-demuxer_t* new_demuxer(stream_t *stream,int type,int a_id,int v_id){
+demuxer_t* new_demuxer(stream_t *stream,int type,int a_id,int v_id,int s_id){
   demuxer_t *d=malloc(sizeof(demuxer_t));
   d->stream=stream;
   d->synced=0;
   d->filepos=0;
   d->audio=new_demuxer_stream(d,a_id);
   d->video=new_demuxer_stream(d,v_id);
+  d->sub=new_demuxer_stream(d,s_id);
   d->type=type;
   return d;
 }
--- a/mplayer.c	Fri Apr 20 20:48:25 2001 +0000
+++ b/mplayer.c	Fri Apr 20 22:35:15 2001 +0000
@@ -251,6 +251,7 @@
   // streams:
   sh_audio_t* a_streams[256];
   sh_video_t* v_streams[256];
+  char s_streams[32]; // dvd subtitles
   // video:
   unsigned int bitrate;
 } avi_header_t;
@@ -462,6 +463,7 @@
 int audio_buffer_size=-1;
 int audio_id=-1;
 int video_id=-1;
+int dvdsub_id=-1;
 float default_max_pts_correction=0.01f;
 int delay_corrected=1;
 float force_fps=0;
@@ -497,7 +499,7 @@
 float sub_delay=0;
 float sub_fps=0;
 int   sub_auto = 1;
-char stream_dump_name=NULL;
+char *stream_dump_name=NULL;
 int stream_dump_type=0;
 //int user_bpp=0;
 
@@ -638,7 +640,7 @@
 
 //=============== Try to open as AVI file: =================
 stream_reset(stream);
-demuxer=new_demuxer(stream,DEMUXER_TYPE_AVI,audio_id,video_id);
+demuxer=new_demuxer(stream,DEMUXER_TYPE_AVI,audio_id,video_id,dvdsub_id);
 stream_seek(demuxer->stream,seek_to_byte);
 { //---- RIFF header:
   int id=stream_read_dword_le(demuxer->stream); // "RIFF"
@@ -654,7 +656,7 @@
 //=============== Try to open as ASF file: =================
 if(file_format==DEMUXER_TYPE_UNKNOWN){
   stream_reset(stream);
-  demuxer=new_demuxer(stream,DEMUXER_TYPE_ASF,audio_id,video_id);
+  demuxer=new_demuxer(stream,DEMUXER_TYPE_ASF,audio_id,video_id,dvdsub_id);
   stream_seek(demuxer->stream,seek_to_byte);
   if(asf_check_header()){
       printf("Detected ASF file format!\n");
@@ -664,7 +666,7 @@
 //=============== Try to open as MPEG-PS file: =================
 if(file_format==DEMUXER_TYPE_UNKNOWN){
   stream_reset(stream);
-  demuxer=new_demuxer(stream,DEMUXER_TYPE_MPEG_PS,audio_id,video_id);
+  demuxer=new_demuxer(stream,DEMUXER_TYPE_MPEG_PS,audio_id,video_id,dvdsub_id);
   stream_seek(demuxer->stream,seek_to_byte);
   if(audio_format) demuxer->audio->type=audio_format; // override audio format
   if(ds_fill_buffer(demuxer->video)){
@@ -688,7 +690,7 @@
 //=============== Try to open as MPEG-ES file: =================
 if(file_format==DEMUXER_TYPE_MPEG_ES){ // little hack, see above!
   stream_reset(stream);
-  demuxer=new_demuxer(stream,DEMUXER_TYPE_MPEG_ES,audio_id,video_id);
+  demuxer=new_demuxer(stream,DEMUXER_TYPE_MPEG_ES,audio_id,video_id,dvdsub_id);
   stream_seek(demuxer->stream,seek_to_byte);
   if(!ds_fill_buffer(demuxer->video)){
     printf("Invalid MPEG-ES stream??? contact the author, it may be a bug :(\n");