[xiph-cvs] cvs commit: vorbis-tools/ogg123 cmdline_options.c ogg123.1 ogg123.c ogg123.h

Stan Seibert volsung at xiph.org
Mon Sep 1 16:54:04 PDT 2003



volsung     03/09/01 19:54:03

  Modified:    ogg123   cmdline_options.c ogg123.1 ogg123.c ogg123.h
  Log:
  hh:mm:ss and end time patch from Hans Schou <chlor at schou.dk>.  Also closes
  bug 321.

Revision  Changes    Path
1.15      +29 -4     vorbis-tools/ogg123/cmdline_options.c

Index: cmdline_options.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/cmdline_options.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- cmdline_options.c	1 Sep 2003 19:36:39 -0000	1.14
+++ cmdline_options.c	1 Sep 2003 23:54:01 -0000	1.15
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: cmdline_options.c,v 1.14 2003/09/01 19:36:39 volsung Exp $
+ last mod: $Id: cmdline_options.c,v 1.15 2003/09/01 23:54:01 volsung Exp $
 
  ********************************************************************/
 
@@ -37,6 +37,7 @@
     {"device", required_argument, 0, 'd'},
     {"file", required_argument, 0, 'f'},
     {"skip", required_argument, 0, 'k'},
+    {"end", required_argument, 0, 'K'},
     {"delay", required_argument, 0, 'l'},
     {"device-option", required_argument, 0, 'o'},
     {"prebuffer", required_argument, 0, 'p'},
@@ -50,6 +51,17 @@
     {0, 0, 0, 0}
 };
 
+double strtotime(char *s)
+{
+	double time;
+
+	time = strtod(s, &s);
+
+	while (*s == ':')
+		time = 60 * time + strtod(s + 1, &s);
+
+	return time;
+}
 
 int parse_cmdline_options (int argc, char **argv,
                            ogg123_options_t *ogg123_opts,
@@ -63,7 +75,7 @@
   audio_device_t *current;
   int ret;
 
-  while (-1 != (ret = getopt_long(argc, argv, "b:c::d:f:hl:k:o:p:qvVx:y:z@:",
+  while (-1 != (ret = getopt_long(argc, argv, "b:c::d:f:hl:k:K:o:p:qvVx:y:z@:",
                                   long_options, &option_index))) {
 
       switch (ret) {
@@ -137,7 +149,11 @@
         break;
 
         case 'k':
-	  ogg123_opts->seekpos = atof(optarg);
+	  ogg123_opts->seekpos = strtotime(optarg);
+	  break;
+	  
+	case 'K':
+	  ogg123_opts->endpos = strtotime(optarg);
           break;
           
         case 'l':
@@ -216,6 +232,14 @@
       }
   }
 
+  /* Sanity check bad option combinations */
+  if (ogg123_opts->endpos > 0.0 &&
+      ogg123_opts->seekpos > ogg123_opts->endpos) {
+    status_error(_("=== Option conflict: End time is before start time.\n"));
+    exit(1);
+  }
+
+
   /* Add last device to device list or use the default device */
   if (temp_driver_id < 0) {
 
@@ -278,7 +302,8 @@
   printf (
          _("  -f, --file=filename  Set the output filename for a previously\n"
          "      specified file device (with -d).\n"
-	 "  -k n, --skip n  Skip the first 'n' seconds\n"
+	 "  -k n, --skip n  Skip the first 'n' seconds (or hh:mm:ss format)\n"
+	 "  -K n, --end n   End at 'n' seconds (or hh:mm:ss format)\n"
          "  -o, --device-option=k:v passes special option k with value\n"
          "      v to previously specified device (with -d).  See\n"
          "      man page for more info.\n"

<p><p>1.18      +7 -1      vorbis-tools/ogg123/ogg123.1

Index: ogg123.1
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.1,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ogg123.1	12 Jul 2002 02:24:49 -0000	1.17
+++ ogg123.1	1 Sep 2003 23:54:02 -0000	1.18
@@ -76,7 +76,13 @@
 .IP "-h, --help"
 Show command help.
 .IP "-k n, --skip n"
-Skip the first 'n' seconds
+Skip the first 'n' seconds.  'n' may also be in minutes:seconds or 
+hours:minutes:seconds form.
+.IP "-K n, --end n"
+Stops playing 'n' seconds from the start of the stream.  'n' may also have the
+same format as used in the
+.I --skip
+option.
 .IP "-o option:value, --device-option option:value"
 Assigns the option
 .I option

<p><p>1.69      +19 -1     vorbis-tools/ogg123/ogg123.c

Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -r1.68 -r1.69
--- ogg123.c	1 Sep 2003 22:50:32 -0000	1.68
+++ ogg123.c	1 Sep 2003 23:54:02 -0000	1.69
@@ -14,7 +14,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: ogg123.c,v 1.68 2003/09/01 22:50:32 volsung Exp $
+ last mod: $Id: ogg123.c,v 1.69 2003/09/01 23:54:02 volsung Exp $
 
  ********************************************************************/
 
@@ -140,6 +140,7 @@
   opts->nth = 1;
   opts->ntimes = 1;
   opts->seekpos = 0.0;
+  opts->endpos = -1.0; /* Mark as unset */
   opts->buffer_size = 128 * 1024;
   opts->prebuffer = 0.0f;
   opts->input_buffer_size = 64 * 1024;
@@ -253,6 +254,18 @@
     print_statistics_action(NULL, pstats_arg);
 }
 
+double current_time (decoder_t *decoder)
+{
+  decoder_stats_t *stats;
+  double ret;
+
+  stats = decoder->format->statistics(decoder);
+  ret = stats->current_time;
+
+  free(stats);
+
+  return ret;
+}
 
 void print_audio_devices_info(audio_device_t *d)
 {
@@ -547,6 +560,11 @@
       } else
         next_status -= ret;
 
+      if (options.endpos > 0.0 && options.endpos <= current_time(decoder)) {
+	eof = eos = 1;
+	break;
+      }
+
 
       /* Write audio data block to output, skipping or repeating chunks
          as needed */

<p><p>1.15      +2 -1      vorbis-tools/ogg123/ogg123.h

Index: ogg123.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ogg123.h	6 Jul 2002 19:12:18 -0000	1.14
+++ ogg123.h	1 Sep 2003 23:54:02 -0000	1.15
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: ogg123.h,v 1.14 2002/07/06 19:12:18 volsung Exp $
+ last mod: $Id: ogg123.h,v 1.15 2003/09/01 23:54:02 volsung Exp $
 
  ********************************************************************/
 
@@ -30,6 +30,7 @@
   int nth;                    /* Play every nth chunk */
   int ntimes;                 /* Play every chunk n times */
   double seekpos;             /* Position in file to seek to */
+  double endpos;              /* Position in file to play to (greater than seekpos) */
 
   long buffer_size;           /* Size of audio buffer */
   float prebuffer;            /* Percent of buffer to fill before playing */

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list