changeset 1467:f352e1e951ba

stream opening -> open.c, initialframes ignored
author arpi
date Thu, 09 Aug 2001 01:17:24 +0000
parents 7845f6d7c4ba
children fbed9c34069c
files Makefile mplayer.c open.c
diffstat 3 files changed, 122 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Wed Aug 08 19:37:45 2001 +0000
+++ b/Makefile	Thu Aug 09 01:17:24 2001 +0000
@@ -16,7 +16,7 @@
 #prefix = /usr/local
 BINDIR = ${prefix}/bin
 # BINDIR = /usr/local/bin
-SRCS = seek.c parse_es.c find_sub.c aviprint.c dec_audio.c dec_video.c aviwrite.c aviheader.c asfheader.c demux_avi.c demux_asf.c demux_mpg.c demuxer.c stream.c codec-cfg.c subreader.c linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c lirc_mp.c cfgparser.c mixer.c dvdauth.c spudec.c $(STREAM_SRCS)
+SRCS = open.c seek.c parse_es.c find_sub.c aviprint.c dec_audio.c dec_video.c aviwrite.c aviheader.c asfheader.c demux_avi.c demux_asf.c demux_mpg.c demuxer.c stream.c codec-cfg.c subreader.c linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c lirc_mp.c cfgparser.c mixer.c dvdauth.c spudec.c $(STREAM_SRCS)
 OBJS = $(SRCS:.c=.o)
 CFLAGS = $(OPTFLAGS) -Iloader -Ilibvo $(CSS_INC) $(EXTRA_INC) # -Wall
 A_LIBS = -Lmp3lib -lMP3 -Llibac3 -lac3 $(ALSA_LIB) $(ESD_LIB)
--- a/mplayer.c	Wed Aug 08 19:37:45 2001 +0000
+++ b/mplayer.c	Thu Aug 09 01:17:24 2001 +0000
@@ -74,12 +74,6 @@
 
 #include "help_mp.h"
 
-#ifdef STREAMING
-#include "url.h"
-#include "network.h"
-static URL_t* url;
-#endif
-
 
 #define DEBUG if(0)
 #ifdef HAVE_GUI
@@ -385,7 +379,8 @@
   exit_player(NULL);
 }
 
-extern int vcd_get_track_end(int fd,int track);
+extern stream_t* open_stream(char* filename,int vcd_track,int* file_format);
+
 extern void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height);
 
 // dec_audio.c:
@@ -458,12 +453,6 @@
 int file_format=DEMUXER_TYPE_UNKNOWN;
 //
 int delay_corrected=1;
-#ifdef VCD_CACHE
-int vcd_cache_size=128;
-#endif
-#ifdef __FreeBSD__
-int bsize = VCD_SECTOR_SIZE;
-#endif
 char* title="MPlayer";
 
 // movie info:
@@ -483,7 +472,7 @@
 float rel_seek_secs=0;
 
 int i;
-int f; // filedes
+int use_stdin=0; //int f; // filedes
 
   printf("%s",banner_text);
 
@@ -625,83 +614,15 @@
        subtitles=sub_read_file(sub_name);
        if(!subtitles) fprintf(stderr,"Can't load subtitles: %s\n",sub_name);
   } else {
-    if ( sub_auto )
-      {
-       // auto load sub file ...
-       subtitles=sub_read_file( sub_filename( get_path("sub/"), filename ) );
-      }
-      if ( subtitles == NULL ) subtitles=sub_read_file(get_path("default.sub")); // try default:
+      if(sub_auto)  // auto load sub file ...
+         subtitles=sub_read_file( sub_filename( get_path("sub/"), filename ) );
+      if(!subtitles) subtitles=sub_read_file(get_path("default.sub")); // try default
   }
 #endif
 
-if(vcd_track){
-//============ Open VideoCD track ==============
-  int ret,ret2;
-  f=open(filename,O_RDONLY);
-  if(f<0){ fprintf(stderr,"CD-ROM Device '%s' not found!\n",filename);return 1; }
-  vcd_read_toc(f);
-  ret2=vcd_get_track_end(f,vcd_track);
-  if(ret2<0){ fprintf(stderr,"Error selecting VCD track! (get)\n");return 1;}
-  ret=vcd_seek_to_track(f,vcd_track);
-  if(ret<0){ fprintf(stderr,"Error selecting VCD track! (seek)\n");return 1;}
-  seek_to_byte+=ret;
-  if(verbose) printf("VCD start byte position: 0x%X  end: 0x%X\n",seek_to_byte,ret2);
-#ifdef VCD_CACHE
-  vcd_cache_init(vcd_cache_size);
-#endif
-#ifdef __FreeBSD__
-  if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) {
-        perror ( "Error in CDRIOCSETBLOCKSIZE");
-  }
-#endif
-  stream=new_stream(f,STREAMTYPE_VCD);
-  stream->start_pos=ret;
-  stream->end_pos=ret2;
-} else {
-//============ Open plain FILE ============
-  off_t len;
-  if(!strcmp(filename,"-")){
-      // read from stdin
-      printf("Reading from stdin...\n");
-      f=0; // 0=stdin
-      stream=new_stream(f,STREAMTYPE_STREAM);
-  } else {
-#ifdef STREAMING
-      url = url_new(filename);
-      if(url==NULL) {
-       // failed to create a new URL, so it's not an URL (or a malformed URL)
-#endif
-       f=open(filename,O_RDONLY);
-       if(f<0){ fprintf(stderr,"File not found: '%s'\n",filename);return 1; }
-       len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET);
-       if (len == -1)
-	 perror("Error: lseek failed to obtain video file size");
-       else
-        if(verbose)
-#ifdef _LARGEFILE_SOURCE
-	 printf("File size is %lld bytes\n", (long long)len);
-#else
-	 printf("File size is %u bytes\n", (unsigned int)len);
-#endif
-       stream=new_stream(f,STREAMTYPE_FILE);
-       stream->end_pos=len;
-#ifdef STREAMING
-      } else {
-        file_format=autodetectProtocol( url, &f );
-        if( file_format==DEMUXER_TYPE_UNKNOWN ) { 
-          fprintf(stderr,"Unable to open URL: %s\n", filename);
-          url_free(url);
-          return 1; 
-        } else {
-          f=streaming_start( &url, f, file_format );
-          if(f<0){ fprintf(stderr,"Unable to open URL: %s\n", url->url); return 1; }
-          printf("Connected to server: %s\n", url->hostname );
-        }
-        stream=new_stream(f,STREAMTYPE_STREAM);
-      }
-#endif
-  }
-}
+  stream=open_stream(filename,vcd_track,&file_format);
+  if(!stream) return 1; // error...
+  use_stdin=(!strcmp(filename,"-"));
 
 #ifdef HAVE_LIBCSS
   if (dvdimportkey) {
@@ -1062,7 +983,7 @@
 #ifdef USE_TERMCAP
   load_termcap(NULL); // load key-codes
 #endif
-  if(f) getch2_enable();
+  if(!use_stdin) getch2_enable();
   #ifdef HAVE_GUI
    }
   #endif 
@@ -1447,9 +1368,11 @@
 //        float x=d_audio->pts-d_video->pts-(delay);
         float x=d_audio->pts-d_video->pts-(delay+audio_delay);
         float y=-(delay+audio_delay);
-        printf("Initial PTS delay: %5.3f sec  (calculated: %5.3f)  audio_delay=%5.3f\n",x,y,audio_delay);
-	initial_pts_delay+=x;
-        audio_delay+=x;
+      float bps_a_pts=(ds_tell(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->wf->nAvgBytesPerSec;
+      float bps_v_pts=d_video->pack_no*(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
+        printf("Initial PTS delay: %5.3f sec ->%5.3f (bps: %5.3f)  audio_delay=%5.3f\n",x,2*sh_video->frametime,bps_a_pts-bps_v_pts-(delay+audio_delay),audio_delay);
+	x=2*sh_video->frametime;
+//	initial_pts_delay+=x; audio_delay+=x;
         delay_corrected=1;
         if(verbose)
         printf("v: audio_delay=%5.3f  buffer_delay=%5.3f  a.pts=%5.3f  v.pts=%5.3f\n",
@@ -1562,11 +1485,11 @@
 #ifdef HAVE_LIRC
              lirc_mp_getinput()<=0 &&
 #endif
-             (!f || getch2(20)<=0) && mplayer_get_key()<=0){
+             (use_stdin || getch2(20)<=0) && mplayer_get_key()<=0){
 #ifndef USE_LIBVO2
 	     video_out->check_events();
 #endif
-             if(!f) usec_sleep(1000); // do not eat the CPU
+             if(use_stdin) usec_sleep(1000); // do not eat the CPU
          }
          osd_function=OSD_PLAY;
 #ifdef HAVE_GUI
@@ -1588,7 +1511,7 @@
 #ifdef HAVE_LIRC
       (c=lirc_mp_getinput())>0 ||
 #endif
-      (f && (c=getch2(0))>0) || (c=mplayer_get_key())>0) switch(c){
+      (!use_stdin && (c=getch2(0))>0) || (c=mplayer_get_key())>0) switch(c){
     // seek 10 sec
     case KEY_RIGHT:
       osd_function=OSD_FFW;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open.c	Thu Aug 09 01:17:24 2001 +0000
@@ -0,0 +1,103 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "config.h"
+
+#include "stream.h"
+
+#ifdef STREAMING
+#include "url.h"
+#include "network.h"
+static URL_t* url;
+#endif
+
+extern int verbose;
+extern int vcd_get_track_end(int fd,int track);
+
+// Open a new stream  (stdin/file/vcd/url)
+
+stream_t* open_stream(char* filename,int vcd_track,int* file_format){
+stream_t* stream=NULL;
+int f=-1;
+off_t len;
+#ifdef VCD_CACHE
+int vcd_cache_size=128;
+#endif
+#ifdef __FreeBSD__
+int bsize = VCD_SECTOR_SIZE;
+#endif
+
+//============ Open VideoCD track ==============
+if(vcd_track){
+  int ret,ret2;
+  f=open(filename,O_RDONLY);
+  if(f<0){ fprintf(stderr,"CD-ROM Device '%s' not found!\n",filename);return NULL; }
+  vcd_read_toc(f);
+  ret2=vcd_get_track_end(f,vcd_track);
+  if(ret2<0){ fprintf(stderr,"Error selecting VCD track! (get)\n");return NULL;}
+  ret=vcd_seek_to_track(f,vcd_track);
+  if(ret<0){ fprintf(stderr,"Error selecting VCD track! (seek)\n");return NULL;}
+//  seek_to_byte+=ret;
+  if(verbose) printf("VCD start byte position: 0x%X  end: 0x%X\n",ret,ret2);
+#ifdef VCD_CACHE
+  vcd_cache_init(vcd_cache_size);
+#endif
+#ifdef __FreeBSD__
+  if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) {
+        perror ( "Error in CDRIOCSETBLOCKSIZE");
+  }
+#endif
+  stream=new_stream(f,STREAMTYPE_VCD);
+  stream->start_pos=ret;
+  stream->end_pos=ret2;
+  return stream;
+}
+
+//============ Open STDIN ============
+  if(!strcmp(filename,"-")){
+      // read from stdin
+      printf("Reading from stdin...\n");
+      f=0; // 0=stdin
+      stream=new_stream(f,STREAMTYPE_STREAM);
+      return stream;
+  }
+  
+#ifdef STREAMING
+  url = url_new(filename);
+  if(url) {
+        (*file_format)=autodetectProtocol( url, &f );
+        if( (*file_format)==DEMUXER_TYPE_UNKNOWN ) { 
+          fprintf(stderr,"Unable to open URL: %s\n", filename);
+          url_free(url);
+          return NULL;
+        }
+        f=streaming_start( &url, f, file_format );
+        if(f<0){ fprintf(stderr,"Unable to open URL: %s\n", url->url); return NULL; }
+        printf("Connected to server: %s\n", url->hostname );
+        stream=new_stream(f,STREAMTYPE_STREAM);
+	return NULL;
+  }
+#endif
+
+//============ Open plain FILE ============
+       f=open(filename,O_RDONLY);
+       if(f<0){ fprintf(stderr,"File not found: '%s'\n",filename);return NULL; }
+       len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET);
+       if (len == -1)
+	 perror("Error: lseek failed to obtain video file size");
+       else
+        if(verbose)
+#ifdef _LARGEFILE_SOURCE
+	 printf("File size is %lld bytes\n", (long long)len);
+#else
+	 printf("File size is %u bytes\n", (unsigned int)len);
+#endif
+       stream=new_stream(f,STREAMTYPE_FILE);
+       stream->end_pos=len;
+       return stream;
+
+}