[vorbis-dev] ogg123 --end 1:59 patch.ogg

Hans Schou chlor at schou.dk
Sun Mar 9 08:39:53 PST 2003


Hi

Here is another patch regarding time in ogg123 which is more
controvercial than the other one I send some days ago. (see
attachment)

When working with Daisy/SMIL [1] files it would be helpfull if the
user could stop play at a specific time. Currently .ogg files are not
allowed in the Daisy format but that will hopefully happen one day if
I work hard at it.

A clip in a Daisy file could look like this:
<audio src="sound.ogg" clip-begin="npt=1.399s" clip-end="npt=5.799s" id="qwrt_0002" />
which should result in a command line like this:
  ogg123 --skip 1.399 --end 5.799 sound.ogg
...easy to handle with a little shell/perl script.

If the patch is not accepted we can live with it. After all it is only
a few people who might find it usefull - which is a minority group
identified as "blind Linux users".

1] http://www.daisy.org/publications/specifications/daisy_202.html#audioformats

best regards

-- 
Hamletsgade 4 - 201, DK-2200 København N, Phone: +45 3582 9079
Schou Industries ApS      http://schou.dk/    CVR: 26 13 44 39
--------------------------------------------------------------
Please don't call me at all, (E-)mail is sufficient)
				-- Anne Bezemer

-------------- next part --------------
diff -Naur vorbis-tools-1.0.orig/ogg123/cmdline_options.c vorbis-tools-1.0/ogg123/cmdline_options.c
--- vorbis-tools-1.0.orig/ogg123/cmdline_options.c	Thu Jul 11 04:44:39 2002
+++ vorbis-tools-1.0/ogg123/cmdline_options.c	Sun Mar  9 16:28:14 2003
@@ -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':
@@ -279,6 +295,7 @@
 	 _("  -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, --end n   End at 'n' second\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"
diff -Naur vorbis-tools-1.0.orig/ogg123/ogg123.c vorbis-tools-1.0/ogg123/ogg123.c
--- vorbis-tools-1.0.orig/ogg123/ogg123.c	Sat Jul  6 21:12:18 2002
+++ vorbis-tools-1.0/ogg123/ogg123.c	Sun Mar  9 16:59:39 2003
@@ -140,6 +140,7 @@
   opts->nth = 1;
   opts->ntimes = 1;
   opts->seekpos = 0.0;
+  opts->endpos = 0.0;
   opts->buffer_size = 128 * 1024;
   opts->prebuffer = 0.0f;
   opts->input_buffer_size = 64 * 1024;
@@ -250,6 +251,18 @@
     print_statistics_action(NULL, pstats_arg);
 }
 
+double currenttime (stat_format_t *stat_format,
+			 data_source_t *source,
+			 decoder_t *decoder)
+{
+  print_statistics_arg_t *pstats_arg;
+
+  pstats_arg = new_print_statistics_arg(stat_format,
+					source->transport->statistics(source),
+					decoder->format->statistics(decoder));
+
+  return pstats_arg->decoder_statistics->current_time;
+}
 
 void print_audio_devices_info(audio_device_t *d)
 {
@@ -473,6 +486,10 @@
     if (!format->seek(decoder, options.seekpos, DECODER_SEEK_START))
       status_error(_("Could not skip %f seconds of audio."), options.seekpos);
   }
+  if (options.seekpos > options.endpos) {
+    printf("Error: -k > -K\n");
+    options.endpos = 0.0;
+  }
 
   /* Main loop:  Iterates over all of the logical bitstreams in the file */
   while (!eof && !sig_request.exit) {
@@ -539,6 +556,12 @@
 	next_status = status_interval;
       } else
 	next_status -= ret;
+
+      if (options.endpos > 0.0)
+	if (options.endpos <= currenttime(stat_format, source, decoder)) {
+	  eof = eos = 1;
+	  break;
+	}
 
 
       /* Write audio data block to output, skipping or repeating chunks
diff -Naur vorbis-tools-1.0.orig/ogg123/ogg123.h vorbis-tools-1.0/ogg123/ogg123.h
--- vorbis-tools-1.0.orig/ogg123/ogg123.h	Sat Jul  6 21:12:18 2002
+++ vorbis-tools-1.0/ogg123/ogg123.h	Sun Mar  9 16:24:55 2003
@@ -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 */


More information about the Vorbis-dev mailing list