1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
6 * PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE Ogg123 SOURCE CODE IS (C) COPYRIGHT 2000-2001 *
9 * by Stan Seibert <volsung@xiph.org> AND OTHER CONTRIBUTORS *
10 * http://www.xiph.org/ *
12 ********************************************************************
14 last mod: $Id: cmdline_options.c,v 1.15 2003/09/01 23:54:01 volsung Exp $
16 ********************************************************************/
27 #include "cmdline_options.h"
31 #define MIN_INPUT_BUFFER_SIZE 8
33 extern double strtotime(char *s
);
34 extern void set_seek_opt(ogg123_options_t
*ogg123_opts
, char *buf
);
36 struct option long_options
[] = {
37 /* GNU standard options */
38 {"help", no_argument
, 0, 'h'},
39 {"version", no_argument
, 0, 'V'},
40 /* ogg123-specific options */
41 {"buffer", required_argument
, 0, 'b'},
42 {"config", optional_argument
, 0, 'c'},
43 {"device", required_argument
, 0, 'd'},
44 {"file", required_argument
, 0, 'f'},
45 {"skip", required_argument
, 0, 'k'},
46 {"end", required_argument
, 0, 'K'},
47 {"delay", required_argument
, 0, 'l'},
48 {"device-option", required_argument
, 0, 'o'},
49 {"prebuffer", required_argument
, 0, 'p'},
50 {"quiet", no_argument
, 0, 'q'},
51 {"remote", no_argument
, 0, 'R'},
52 {"verbose", no_argument
, 0, 'v'},
53 {"nth", required_argument
, 0, 'x'},
54 {"ntimes", required_argument
, 0, 'y'},
55 {"shuffle", no_argument
, 0, 'z'},
56 {"random", no_argument
, 0, 'Z'},
57 {"list", required_argument
, 0, '@'},
58 {"audio-buffer", required_argument
, 0, 0},
59 {"repeat", no_argument
, 0, 'r'},
63 int parse_cmdline_options (int argc
, char **argv
,
64 ogg123_options_t
*ogg123_opts
,
65 file_option_t
*file_opts
)
68 ao_option
*temp_options
= NULL
;
69 ao_option
** current_options
= &temp_options
;
71 int temp_driver_id
= -1;
72 audio_device_t
*current
;
75 while (-1 != (ret
= getopt_long(argc
, argv
, "b:c::d:f:hl:k:K:o:p:qrRvVx:y:zZ@:",
76 long_options
, &option_index
))) {
80 if(!strcmp(long_options
[option_index
].name
, "audio-buffer")) {
81 ogg123_opts
->buffer_size
= 1024 * atoi(optarg
);
83 status_error(_("Internal error parsing command line options.\n"));
88 ogg123_opts
->input_buffer_size
= atoi(optarg
) * 1024;
89 if (ogg123_opts
->input_buffer_size
< MIN_INPUT_BUFFER_SIZE
* 1024) {
90 status_error(_("Input buffer size smaller than minimum size of %dkB."),
91 MIN_INPUT_BUFFER_SIZE
);
92 ogg123_opts
->input_buffer_size
= MIN_INPUT_BUFFER_SIZE
* 1024;
98 char *tmp
= strdup (optarg
);
99 parse_code_t pcode
= parse_line(file_opts
, tmp
);
101 if (pcode
!= parse_ok
)
102 status_error(_("=== Error \"%s\" while parsing config option from command line.\n"
103 "=== Option was: %s\n"),
104 parse_error_string(pcode
), optarg
);
108 /* not using the status interface here */
109 fprintf (stdout
, _("Available options:\n"));
110 file_options_describe(file_opts
, stdout
);
116 temp_driver_id
= ao_driver_id(optarg
);
117 if (temp_driver_id
< 0) {
118 status_error(_("=== No such device %s.\n"), optarg
);
122 current
= append_audio_device(ogg123_opts
->devices
,
125 if(ogg123_opts
->devices
== NULL
)
126 ogg123_opts
->devices
= current
;
127 current_options
= ¤t
->options
;
131 if (temp_driver_id
>= 0) {
133 info
= ao_driver_info(temp_driver_id
);
134 if (info
->type
== AO_TYPE_FILE
) {
135 free(current
->filename
);
136 current
->filename
= strdup(optarg
);
138 status_error(_("=== Driver %s is not a file output driver.\n"),
143 status_error(_("=== Cannot specify output file without specifying a driver.\n"));
149 set_seek_opt(ogg123_opts
, optarg
);
153 ogg123_opts
->endpos
= strtotime(optarg
);
157 ogg123_opts
->delay
= atoi(optarg
);
161 if (optarg
&& !add_ao_option(current_options
, optarg
)) {
162 status_error(_("=== Incorrect option format: %s.\n"), optarg
);
173 ogg123_opts
->input_prebuffer
= atof (optarg
);
174 if (ogg123_opts
->input_prebuffer
< 0.0f
||
175 ogg123_opts
->input_prebuffer
> 100.0f
) {
177 status_error (_("--- Prebuffer value invalid. Range is 0-100.\n"));
178 ogg123_opts
->input_prebuffer
=
179 ogg123_opts
->input_prebuffer
< 0.0f
? 0.0f
: 100.0f
;
184 ogg123_opts
->verbosity
= 0;
188 ogg123_opts
->repeat
= 1;
192 ogg123_opts
->remote
= 1;
193 ogg123_opts
->verbosity
= 0;
197 ogg123_opts
->verbosity
++;
201 status_error(_("ogg123 from %s %s"), PACKAGE
, VERSION
);
206 ogg123_opts
->nth
= atoi(optarg
);
207 if (ogg123_opts
->nth
== 0) {
208 status_error(_("--- Cannot play every 0th chunk!\n"));
209 ogg123_opts
->nth
= 1;
214 ogg123_opts
->ntimes
= atoi(optarg
);
215 if (ogg123_opts
->ntimes
== 0) {
216 status_error(_("--- Cannot play every chunk 0 times.\n"
217 "--- To do a test decode, use the null output driver.\n"));
218 ogg123_opts
->ntimes
= 1;
223 ogg123_opts
->shuffle
= 1;
227 ogg123_opts
->repeat
= ogg123_opts
->shuffle
= 1;
231 if (playlist_append_from_file(ogg123_opts
->playlist
, optarg
) == 0)
232 status_error(_("--- Cannot open playlist file %s. Skipped.\n"),
245 /* Sanity check bad option combinations */
246 if (ogg123_opts
->endpos
> 0.0 &&
247 ogg123_opts
->seekoff
> ogg123_opts
->endpos
) {
248 status_error(_("=== Option conflict: End time is before start time.\n"));
253 /* Add last device to device list or use the default device */
254 if (temp_driver_id
< 0) {
256 /* First try config file setting */
257 if (ogg123_opts
->default_device
) {
258 temp_driver_id
= ao_driver_id(ogg123_opts
->default_device
);
260 if (temp_driver_id
< 0)
261 status_error(_("--- Driver %s specified in configuration file invalid.\n"),
262 ogg123_opts
->default_device
);
265 /* Then try libao autodetect */
266 if (temp_driver_id
< 0)
267 temp_driver_id
= ao_default_driver_id();
269 /* Finally, give up */
270 if (temp_driver_id
< 0) {
271 status_error(_("=== Could not load default driver and no driver specified in config file. Exiting.\n"));
275 ogg123_opts
->devices
= append_audio_device(ogg123_opts
->devices
,
285 #define LIST_SEP(x) ((x)==0?' ':',')
287 void cmdline_usage (void)
289 int i
, j
, driver_count
;
290 ao_info
**devices
= ao_driver_info_list(&driver_count
);
292 printf (_("ogg123 from %s %s\n"
293 " by the Xiph.Org Foundation (http://www.xiph.org/)\n\n"), PACKAGE
, VERSION
);
295 printf (_("Usage: ogg123 [options] file ...\n"
296 "Play Ogg audio files and network streams.\n\n"));
298 printf (_("Available codecs: "));
301 printf (_("FLAC, "));
305 printf (_("Speex, "));
308 printf (_("Ogg Vorbis.\n\n"));
310 printf (_("Output options\n"));
311 printf (_(" -d dev, --device dev Use output device \"dev\". Available devices:\n"));
315 for(i
= 0, j
= 0; i
< driver_count
; i
++) {
316 if (devices
[i
]->type
== AO_TYPE_LIVE
) {
317 printf ("%c %s", LIST_SEP(j
), devices
[i
]->short_name
);
323 for(i
= 0, j
= 0; i
< driver_count
; i
++) {
324 if (devices
[i
]->type
== AO_TYPE_FILE
) {
325 printf ("%c %s", LIST_SEP(j
), devices
[i
]->short_name
);
331 printf (_(" -f file, --file file Set the output filename for a file device\n"
332 " previously specified with --device.\n"));
334 printf (_(" --audio-buffer n Use an output audio buffer of 'n' kilobytes\n"));
335 printf (_(" -o k:v, --device-option k:v\n"
336 " Pass special option 'k' with value 'v' to the\n"
337 " device previously specified with --device. See\n"
338 " the ogg123 man page for available device options.\n"));
341 printf (_("Playlist options\n"));
342 printf (_(" -@ file, --list file Read playlist of files and URLs from \"file\"\n"));
343 printf (_(" -r, --repeat Repeat playlist indefinitely\n"));
344 printf (_(" -R, --remote Use remote control interface\n"));
345 printf (_(" -z, --shuffle Shuffle list of files before playing\n"));
346 printf (_(" -Z, --random Play files randomly until interrupted\n"));
349 printf (_("Input options\n"));
350 printf (_(" -b n, --buffer n Use an input buffer of 'n' kilobytes\n"));
351 printf (_(" -p n, --prebuffer n Load n%% of the input buffer before playing\n"));
354 printf (_("Decode options\n"));
355 printf (_(" -k n, --skip n Skip the first 'n' seconds (or hh:mm:ss format)\n"));
356 printf (_(" -K n, --end n End at 'n' seconds (or hh:mm:ss format)\n"));
357 printf (_(" -x n, --nth n Play every 'n'th block\n"));
358 printf (_(" -y n, --ntimes n Repeat every played block 'n' times\n"));
361 printf (_("Miscellaneous options\n"));
362 printf (_(" -l s, --delay s Set termination timeout in milliseconds. ogg123\n"
363 " will skip to the next song on SIGINT (Ctrl-C),\n"
364 " and will terminate if two SIGINTs are received\n"
365 " within the specified timeout 's'. (default 500)\n"));
367 printf (_(" -h, --help Display this help\n"));
368 printf (_(" -q, --quiet Don't display anything (no title)\n"));
369 printf (_(" -v, --verbose Display progress and other status information\n"));
370 printf (_(" -V, --version Display ogg123 version\n"));