Commit 1172b920 authored by Stan Seibert's avatar Stan Seibert

hh:mm:ss and end time patch from Hans Schou <chlor@schou.dk>. Also closes

bug 321.

svn path=/trunk/vorbis-tools/; revision=5272
parent 58c59262
......@@ -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 @@ struct option long_options[] = {
{"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 @@ struct option long_options[] = {
{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 @@ int parse_cmdline_options (int argc, char **argv,
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 @@ int parse_cmdline_options (int argc, char **argv,
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 @@ int parse_cmdline_options (int argc, char **argv,
}
}
/* 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 @@ void cmdline_usage (void)
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"
......
......@@ -76,7 +76,13 @@ will overwrite it.
.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
......
......@@ -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 @@ void options_init (ogg123_options_t *opts)
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 @@ void display_statistics_quick (stat_format_t *stat_format,
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 @@ void play (char *source_string)
} 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 */
......
......@@ -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 @@ typedef struct ogg123_options_t {
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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment