[MPlayer-dev-eng] a patch for VCD detecting and playing

scott fagg scottf at bigpond.net.au
Tue Jan 1 11:11:27 CET 2002


I'd like to offer a patch for mplayer, related to detection and playing
of VCD's. Currently using the command line interface, to play a vcd, it's
something like:

mplayer -vcd 1 /dev/cdrom

To start the gui playing a VCD, it's much the same:

gmplayer -vcd 1 /dev/cdrom

To start the gui playing a file, it's generally something like:

gmplayer movie.mpg

I noticed that if you start gmplayer in vcd mode (gmplayer -vcd ..) then
try to play an ordinary file (via the Select File button) it complains
about the file not being a VCD and vice versa, if you start gmplayer
without any options and then try to play a VCD, it also complains.

To get around this, i've patched libmpdemux/open.c

The patch makes it possible to start mplayer without the -vcd option and
still succesfully play VCDs or ordinary MPEG files. Both of the following
work fine:

mplayer /dev/cdrom (plays a VCD)
mplayer /home/scottf/movie.mpeg

After patching, gmplayer also happily plays files and VCDs without a
restart.

I noticed that middle clicking on gmplayer pops-up a menu with a 'play
vcd' option, but this didn't do anything other than generate some output:

[psignal] PopUpMenu: 0 param: 0
[mw] event none received.

I wrote my patch agains 0.60pre1 and tested it against 0.60pre2 and CVS
without any problems.

The patch is below. The basic premise is that that if a user specifies a
filename (or  device name), mplayer tries it as a VCD before carrying
on. 

I felt the patch had value from a usability point of view.

Any thoughts or comments ?

(careful of word-wrapping below, hopefully PINE hasn't mangled it too 
much)

--- open.c	Tue Jan  1 19:57:02 2002
+++ /home/scottf/src/MPlayer-0.60pre1.sf/libmpdemux/open.c	Sat Dec 29 
20:12:19 2001
@@ -76,17 +76,30 @@
 
 //============ Open VideoCD track ==============
 #ifdef HAVE_VCD
-if(vcd_track){
-  int ret,ret2;
-  if(!filename) filename=DEFAULT_CDROM_DEVICE;
+if(1){
+  int ret,ret2,vcd_opened;
+  vcd_opened = 1;
+  
+  // if no filename was specifed, 
+  // but a track was explicitely set via -vcd , default device
+  if(!filename && vcd_track) filename=DEFAULT_CDROM_DEVICE;
+  
+  // if no track specified, use track 1
+  if(!vcd_track) { vcd_track = 1 ;}
   f=open(filename,O_RDONLY);
   if(f<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CdDevNotfound,filename);return NULL; }
   vcd_read_toc(f);
   ret2=vcd_get_track_end(f,vcd_track);
-  if(ret2<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n");return NULL;}
+  if(ret2<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n");vcd_opened=0;}
   ret=vcd_seek_to_track(f,vcd_track);
-  if(ret<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n");return NULL;}
+  if(ret<0 && vcd_opened == 1){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n");vcd_opened=0;}
 //  seek_to_byte+=ret;
+
+// if we succesfully opened a VCD, carry on, otherwise
+// close the open file handle and carry on as though
+// nothing had happened
+  if (vcd_opened == 1)
+  {
   mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X  end: 
0x%X\n",ret,ret2);
 #ifdef VCD_CACHE
   vcd_cache_init(vcd_cache_size);
@@ -100,6 +113,11 @@
   stream->start_pos=ret;
   stream->end_pos=ret2;
   return stream;
+  }
+  else
+  {
+  close(f);
+  }
 }
 #endif

-- 
--
scottf at bigpond.net.au





More information about the MPlayer-dev-eng mailing list