| 1 |
/* |
| 2 |
mpg123: main code of the program (not of the decoder...) |
| 3 |
|
| 4 |
copyright 1995-2023 by the mpg123 project - free software under the terms of the LGPL 2.1 |
| 5 |
see COPYING and AUTHORS files in distribution or http://mpg123.org |
| 6 |
initially written by Michael Hipp |
| 7 |
*/ |
| 8 |
|
| 9 |
#define ME "main" |
| 10 |
#include "mpg123app.h" |
| 11 |
#include "mpg123.h" |
| 12 |
#include "out123.h" |
| 13 |
#include "syn123.h" |
| 14 |
#include "version.h" |
| 15 |
#include "local.h" |
| 16 |
|
| 17 |
#ifdef HAVE_SYS_WAIT_H |
| 18 |
#include <sys/wait.h> |
| 19 |
#endif |
| 20 |
#ifdef HAVE_SYS_RESOURCE_H |
| 21 |
#include <sys/resource.h> |
| 22 |
#endif |
| 23 |
|
| 24 |
#include <errno.h> |
| 25 |
#include <string.h> |
| 26 |
#include <time.h> |
| 27 |
|
| 28 |
#ifdef HAVE_SCHED_H |
| 29 |
#include <sched.h> |
| 30 |
#endif |
| 31 |
|
| 32 |
/* be paranoid about setpriority support */ |
| 33 |
#ifndef PRIO_PROCESS |
| 34 |
#undef HAVE_SETPRIORITY |
| 35 |
#endif |
| 36 |
|
| 37 |
#include "common.h" |
| 38 |
#include "sysutil.h" |
| 39 |
#include "getlopt.h" |
| 40 |
#include "term.h" |
| 41 |
#include "terms.h" |
| 42 |
#include "playlist.h" |
| 43 |
#include "metaprint.h" |
| 44 |
#include "httpget.h" |
| 45 |
#include "streamdump.h" |
| 46 |
|
| 47 |
#include "common/debug.h" |
| 48 |
|
| 49 |
static void usage(int err); |
| 50 |
static void want_usage(char* arg, topt *); |
| 51 |
static void long_usage(int err); |
| 52 |
static void want_long_usage(char* arg, topt *); |
| 53 |
static void print_title(FILE* o); |
| 54 |
static void give_version(char* arg, topt *); |
| 55 |
static void give_libversion(char* arg, topt *); |
| 56 |
|
| 57 |
struct parameter param = { |
| 58 |
FALSE , /* aggressiv */ |
| 59 |
FALSE , /* shuffle */ |
| 60 |
FALSE , /* remote */ |
| 61 |
FALSE , /* remote to stderr */ |
| 62 |
FALSE , /* silent operation */ |
| 63 |
FALSE , /* xterm title on/off */ |
| 64 |
0 , /* second level buffer size */ |
| 65 |
0 , /* verbose level */ |
| 66 |
DEFAULT_OUTPUT_MODULE, /* output module */ |
| 67 |
NULL, /* output device */ |
| 68 |
0, /* destination (headphones, ...) */ |
| 69 |
FALSE, /* term control */ |
| 70 |
TRUE, /* term visuals */ |
| 71 |
MPG123_TERM_USR1, |
| 72 |
MPG123_TERM_USR2, |
| 73 |
FALSE , /* checkrange */ |
| 74 |
0 , /* force_reopen, always (re)opens audio device for next song */ |
| 75 |
FALSE, /* try to run process in 'realtime mode' */ |
| 76 |
#ifdef HAVE_WINDOWS_H |
| 77 |
0, /* win32 process priority */ |
| 78 |
#endif |
| 79 |
0, /* default is to play all titles in playlist */ |
| 80 |
NULL, /* no playlist per default */ |
| 81 |
0 /* condensed id3 per default */ |
| 82 |
,NULL /* cpu */ |
| 83 |
#ifdef FIFO |
| 84 |
,NULL |
| 85 |
#endif |
| 86 |
,0 /* timeout */ |
| 87 |
,1 /* loop */ |
| 88 |
,0 /* delay */ |
| 89 |
,0 /* index */ |
| 90 |
/* Parameters for mpg123 handle, defaults are queried from library! */ |
| 91 |
,0 /* down_sample */ |
| 92 |
,0 /* rva */ |
| 93 |
,0 /* halfspeed */ |
| 94 |
,0 /* doublespeed */ |
| 95 |
,0 /* start_frame */ |
| 96 |
,-1 /* frame_number */ |
| 97 |
,0 /* outscale */ |
| 98 |
,0 /* flags */ |
| 99 |
,0 /* force_rate */ |
| 100 |
#ifndef NO_REAL |
| 101 |
,2 /* fine resampling */ |
| 102 |
#else |
| 103 |
,0 /* NtoM resampler */ |
| 104 |
#endif |
| 105 |
,1 /* ICY */ |
| 106 |
,1024 /* resync_limit */ |
| 107 |
,0 /* smooth */ |
| 108 |
,0.0 /* pitch */ |
| 109 |
,0.5 // pauseloop |
| 110 |
,0 /* appflags */ |
| 111 |
,NULL /* proxyurl */ |
| 112 |
,0 /* keep_open */ |
| 113 |
,0 /* force_utf8 */ |
| 114 |
,INDEX_SIZE |
| 115 |
,NULL /* force_encoding */ |
| 116 |
,0.2 /* preload */ |
| 117 |
,-1 /* preframes */ |
| 118 |
,-1 /* gain */ |
| 119 |
,NULL /* stream dump file */ |
| 120 |
,0 /* ICY interval */ |
| 121 |
,"mpg123" /* name */ |
| 122 |
,0. /* device buffer */ |
| 123 |
#if defined(NETWORK) || defined(NET123) |
| 124 |
,NULL /* auth */ |
| 125 |
#endif |
| 126 |
#ifdef NET123 |
| 127 |
,"auto" /* network_backend */ |
| 128 |
#endif |
| 129 |
}; |
| 130 |
|
| 131 |
mpg123_handle *mh = NULL; |
| 132 |
off_t framenum; |
| 133 |
off_t frames_left; |
| 134 |
out123_handle *ao = NULL; |
| 135 |
|
| 136 |
static long output_propflags = 0; |
| 137 |
char *prgName = NULL; |
| 138 |
/* ThOr: pointers are not TRUE or FALSE */ |
| 139 |
char *equalfile = NULL; |
| 140 |
int fresh = TRUE; |
| 141 |
FILE* aux_out = NULL; /* Output for interesting information, normally on stdout to be parseable. */ |
| 142 |
|
| 143 |
enum runmodes |
| 144 |
{ |
| 145 |
RUN_MAIN = 0 |
| 146 |
, LIST_CPU |
| 147 |
, TEST_CPU |
| 148 |
, LIST_MODULES |
| 149 |
, LIST_DEVICES |
| 150 |
}; |
| 151 |
|
| 152 |
static int runmode = RUN_MAIN; |
| 153 |
|
| 154 |
int stdin_is_term = FALSE; // It's an interactive terminal. |
| 155 |
int stdout_is_term = FALSE; // It's an interactive terminal. |
| 156 |
int stderr_is_term = FALSE; // It's an interactive terminal. |
| 157 |
int got_played = 0; // State of attempted playback and success: 0, -1, 1 |
| 158 |
int intflag = FALSE; |
| 159 |
int deathflag = FALSE; |
| 160 |
static int skip_tracks = 0; |
| 161 |
|
| 162 |
struct stream *filept = NULL; |
| 163 |
|
| 164 |
char *fullprogname = NULL; /* Copy of argv[0]. */ |
| 165 |
char *binpath; /* Path to myself. */ |
| 166 |
|
| 167 |
/* File-global storage of command line arguments. |
| 168 |
They may be needed for cleanup after charset conversion. */ |
| 169 |
static char **argv = NULL; |
| 170 |
static int argc = 0; |
| 171 |
|
| 172 |
/* Cleanup marker to know that we intiialized libmpg123 already. */ |
| 173 |
static int cleanup_mpg123 = FALSE; |
| 174 |
|
| 175 |
static long new_header = FALSE; |
| 176 |
static char *prebuffer = NULL; |
| 177 |
static size_t prebuffer_size = 0; |
| 178 |
static size_t prebuffer_fill = 0; |
| 179 |
static size_t minbytes = 0; |
| 180 |
|
| 181 |
void set_intflag(void) |
| 182 |
{ |
| 183 |
debug("set_intflag TRUE"); |
| 184 |
intflag = TRUE; |
| 185 |
skip_tracks = 0; |
| 186 |
} |
| 187 |
|
| 188 |
#if !defined(WIN32) && !defined(GENERIC) |
| 189 |
static void catch_interrupt(int sig) |
| 190 |
{ |
| 191 |
intflag = TRUE; |
| 192 |
} |
| 193 |
|
| 194 |
static void handle_fatal(void) |
| 195 |
{ |
| 196 |
intflag = TRUE; |
| 197 |
deathflag = TRUE; |
| 198 |
} |
| 199 |
|
| 200 |
static void handle_fatal_msg(const char *msg) |
| 201 |
{ |
| 202 |
if(msg && !param.quiet) |
| 203 |
fprintf(stderr, "%s", msg); |
| 204 |
handle_fatal(); |
| 205 |
} |
| 206 |
static void catch_fatal_term(int sig) |
| 207 |
{ |
| 208 |
handle_fatal_msg("\nmpg123: death by SIGTERM\n"); |
| 209 |
} |
| 210 |
static void catch_fatal_pipe(int sig) |
| 211 |
{ |
| 212 |
/* If the SIGPIPE is because of piped stderr, trying to write |
| 213 |
in the signal handler hangs the program. */ |
| 214 |
handle_fatal(); |
| 215 |
} |
| 216 |
#endif |
| 217 |
|
| 218 |
static void skip_track(void) |
| 219 |
{ |
| 220 |
intflag = TRUE; |
| 221 |
++skip_tracks; |
| 222 |
} |
| 223 |
|
| 224 |
void next_track(void) |
| 225 |
{ |
| 226 |
playlist_jump(+1); |
| 227 |
skip_track(); |
| 228 |
} |
| 229 |
|
| 230 |
void prev_track(void) |
| 231 |
{ |
| 232 |
playlist_jump(-1); |
| 233 |
skip_track(); |
| 234 |
} |
| 235 |
|
| 236 |
void next_dir(void) |
| 237 |
{ |
| 238 |
playlist_next_dir(); |
| 239 |
skip_track(); |
| 240 |
} |
| 241 |
|
| 242 |
void prev_dir(void) |
| 243 |
{ |
| 244 |
playlist_prev_dir(); |
| 245 |
skip_track(); |
| 246 |
} |
| 247 |
|
| 248 |
void safe_exit(int code); |
| 249 |
|
| 250 |
void play_prebuffer(void) |
| 251 |
{ |
| 252 |
/* Ensure that the prebuffer bit has been posted. */ |
| 253 |
if(prebuffer_fill) |
| 254 |
{ |
| 255 |
if(audio_play(ao, prebuffer, prebuffer_fill) < prebuffer_fill) |
| 256 |
{ |
| 257 |
error("Deep trouble! Cannot flush to my output anymore!"); |
| 258 |
safe_exit(133); |
| 259 |
} |
| 260 |
prebuffer_fill = 0; |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
/* Drain output device/buffer, but still give the option to interrupt things. */ |
| 265 |
static void controlled_drain(void) |
| 266 |
{ |
| 267 |
int framesize; |
| 268 |
size_t drain_block; |
| 269 |
|
| 270 |
play_prebuffer(); |
| 271 |
|
| 272 |
if(intflag || !out123_buffered(ao)) |
| 273 |
return; |
| 274 |
if(out123_getformat(ao, NULL, NULL, NULL, &framesize)) |
| 275 |
return; |
| 276 |
drain_block = 1152*framesize; |
| 277 |
if(param.verbose) |
| 278 |
fprintf(stderr, "\n"); |
| 279 |
do |
| 280 |
{ |
| 281 |
out123_ndrain(ao, drain_block); |
| 282 |
if(param.verbose) |
| 283 |
print_buf("Draining buffer: ", ao); |
| 284 |
if(param.term_ctrl) |
| 285 |
term_control(mh, ao); |
| 286 |
} |
| 287 |
while(!intflag && out123_buffered(ao)); |
| 288 |
if(param.verbose) |
| 289 |
fprintf(stderr, "\n"); |
| 290 |
} |
| 291 |
|
| 292 |
void safe_exit(int code) |
| 293 |
{ |
| 294 |
const char *dummy, *dammy; |
| 295 |
|
| 296 |
dump_close(); |
| 297 |
if(!code) |
| 298 |
controlled_drain(); |
| 299 |
if(intflag) |
| 300 |
out123_drop(ao); |
| 301 |
audio_cleanup(); |
| 302 |
out123_del(ao); |
| 303 |
|
| 304 |
// Free the memory after the output is not working on it anymore! |
| 305 |
if(prebuffer) |
| 306 |
free(prebuffer); |
| 307 |
|
| 308 |
if(mh != NULL) mpg123_delete(mh); |
| 309 |
|
| 310 |
if(cleanup_mpg123) mpg123_exit(); |
| 311 |
|
| 312 |
stream_close(filept); |
| 313 |
filept = NULL; |
| 314 |
|
| 315 |
#ifdef WANT_WIN32_UNICODE |
| 316 |
win32_cmdline_free(argc, argv); /* This handles the premature argv == NULL, too. */ |
| 317 |
#endif |
| 318 |
#if defined (WANT_WIN32_SOCKETS) |
| 319 |
win32_net_deinit(); |
| 320 |
#endif |
| 321 |
/* It's ugly... but let's just fix this still-reachable memory chunk of static char*. */ |
| 322 |
split_dir_file("", &dummy, &dammy); |
| 323 |
if(fullprogname) free(fullprogname); |
| 324 |
|
| 325 |
#if defined(NETWORK) || defined(NET123) |
| 326 |
if(param.httpauth) free(param.httpauth); |
| 327 |
#endif |
| 328 |
term_exit(); |
| 329 |
exit(code); |
| 330 |
} |
| 331 |
|
| 332 |
static void check_fatal_output(int code) |
| 333 |
{ |
| 334 |
if(code) |
| 335 |
{ |
| 336 |
if(out123_errcode(ao)) |
| 337 |
error2( "out123 error %i: %s" |
| 338 |
, out123_errcode(ao), out123_strerror(ao) ); |
| 339 |
else |
| 340 |
error("fatal output (setup) error"); |
| 341 |
safe_exit(code); |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
static void set_output_module(char *arg, topt *opts) |
| 346 |
{ |
| 347 |
unsigned int i; |
| 348 |
|
| 349 |
/* Search for a colon and set the device if found */ |
| 350 |
for(i=0; i< strlen( arg ); i++) { |
| 351 |
if (arg[i] == ':') { |
| 352 |
arg[i] = 0; |
| 353 |
getlopt_set_char(opts, "audiodevice", &arg[i+1]); |
| 354 |
debug1("Setting output device: %s", param.output_device); |
| 355 |
break; |
| 356 |
} |
| 357 |
} |
| 358 |
/* Set the output module */ |
| 359 |
param.output_module = arg; |
| 360 |
debug1("Setting output module: %s", param.output_module ); |
| 361 |
} |
| 362 |
|
| 363 |
static void set_output_flag(int flag) |
| 364 |
{ |
| 365 |
if(param.output_flags <= 0) param.output_flags = flag; |
| 366 |
else param.output_flags |= flag; |
| 367 |
} |
| 368 |
|
| 369 |
static void set_output_h(char *a, topt *opts) |
| 370 |
{ |
| 371 |
set_output_flag(OUT123_HEADPHONES); |
| 372 |
} |
| 373 |
|
| 374 |
static void set_output_s(char *a, topt *opts) |
| 375 |
{ |
| 376 |
set_output_flag(OUT123_INTERNAL_SPEAKER); |
| 377 |
} |
| 378 |
|
| 379 |
static void set_output_l(char *a, topt *opts) |
| 380 |
{ |
| 381 |
set_output_flag(OUT123_LINE_OUT); |
| 382 |
} |
| 383 |
|
| 384 |
static void set_output(char *arg, topt *opts) |
| 385 |
{ |
| 386 |
/* If single letter, it's the legacy output switch for AIX/HP/Sun. |
| 387 |
If longer, it's module[:device] . If zero length, it's rubbish. */ |
| 388 |
if(strlen(arg) <= 1) switch(arg[0]) |
| 389 |
{ |
| 390 |
case 'h': set_output_h(arg, opts); break; |
| 391 |
case 's': set_output_s(arg, opts); break; |
| 392 |
case 'l': set_output_l(arg, opts); break; |
| 393 |
default: |
| 394 |
error1("\"%s\" is no valid output", arg); |
| 395 |
safe_exit(1); |
| 396 |
} |
| 397 |
else set_output_module(arg, opts); |
| 398 |
} |
| 399 |
|
| 400 |
static void set_resample(char *arg, topt *opts) |
| 401 |
{ |
| 402 |
if(!strcasecmp("ntom", arg)) |
| 403 |
param.resample = 0; |
| 404 |
else if(!strcasecmp("dirty", arg)) |
| 405 |
param.resample = 1; |
| 406 |
else if(!strcasecmp("fine", arg)) |
| 407 |
param.resample = 2; |
| 408 |
else |
| 409 |
{ |
| 410 |
merror("\"%s\" is no valid resampler choice", arg); |
| 411 |
safe_exit(1); |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
static void set_verbose (char *arg, topt *opts) |
| 416 |
{ |
| 417 |
param.verbose++; |
| 418 |
} |
| 419 |
|
| 420 |
static void set_quiet (char *arg, topt *opts) |
| 421 |
{ |
| 422 |
param.verbose=0; |
| 423 |
param.quiet=TRUE; |
| 424 |
} |
| 425 |
|
| 426 |
static void set_out_wav(char *arg, topt *opts) |
| 427 |
{ |
| 428 |
param.output_module = "wav"; |
| 429 |
getlopt_set_char(opts, "audiodevice", arg); |
| 430 |
} |
| 431 |
|
| 432 |
void set_out_cdr(char *arg, topt *opts) |
| 433 |
{ |
| 434 |
param.output_module = "cdr"; |
| 435 |
getlopt_set_char(opts, "audiodevice", arg); |
| 436 |
} |
| 437 |
|
| 438 |
void set_out_au(char *arg, topt *opts) |
| 439 |
{ |
| 440 |
param.output_module = "au"; |
| 441 |
getlopt_set_char(opts, "audiodevice", arg); |
| 442 |
} |
| 443 |
|
| 444 |
void set_out_test(char *arg, topt *opts) |
| 445 |
{ |
| 446 |
param.output_module = "test"; |
| 447 |
getlopt_set_char(opts, "audiodevice", NULL); |
| 448 |
} |
| 449 |
|
| 450 |
static void set_out_file(char *arg, topt *opts) |
| 451 |
{ |
| 452 |
param.output_module = "raw"; |
| 453 |
getlopt_set_char(opts, "audiodevice", arg); |
| 454 |
} |
| 455 |
|
| 456 |
static void set_out_stdout(char *arg, topt *opts) |
| 457 |
{ |
| 458 |
param.remote_err = TRUE; |
| 459 |
param.output_module = "raw"; |
| 460 |
getlopt_set_char(opts, "audiodevice", NULL); |
| 461 |
} |
| 462 |
|
| 463 |
#if !defined (HAVE_SCHED_SETSCHEDULER) && !defined (HAVE_WINDOWS_H) |
| 464 |
static void realtime_not_compiled(char *arg, topt *opts) |
| 465 |
{ |
| 466 |
fprintf(stderr,"Option '-T / --realtime' not compiled into this binary.\n"); |
| 467 |
} |
| 468 |
#endif |
| 469 |
|
| 470 |
static long frameflag; /* ugly, but that's the way without hacking getlopt */ |
| 471 |
static void set_frameflag(char *arg, topt *opts) |
| 472 |
{ |
| 473 |
/* Only one mono flag at a time! */ |
| 474 |
if(frameflag & MPG123_FORCE_MONO) param.flags &= ~MPG123_FORCE_MONO; |
| 475 |
param.flags |= frameflag; |
| 476 |
} |
| 477 |
static void unset_frameflag(char *arg, topt *opts) |
| 478 |
{ |
| 479 |
param.flags &= ~frameflag; |
| 480 |
} |
| 481 |
|
| 482 |
long appflag; /* still ugly, but works */ |
| 483 |
static void set_appflag(char *arg, topt *opts) |
| 484 |
{ |
| 485 |
param.appflags |= appflag; |
| 486 |
} |
| 487 |
#if defined(NETWORK) || defined(NET123) |
| 488 |
static void set_httpauth(char *arg, topt *opts) |
| 489 |
{ |
| 490 |
param.httpauth = INT123_compat_strdup(arg); |
| 491 |
// Do not advertise the password for all system users. |
| 492 |
memset(arg, 'x', strlen(arg)); |
| 493 |
} |
| 494 |
static void set_httpauth_file(char *arg, topt *opts) |
| 495 |
{ |
| 496 |
char buf[4096]; |
| 497 |
int fd = open(arg, 0); |
| 498 |
int good = 0; |
| 499 |
if(fd >= 0) |
| 500 |
{ |
| 501 |
mpg123_ssize_t rdb = read(fd, buf, sizeof(buf)); |
| 502 |
// If the file filled the whole buffer, this is too much. |
| 503 |
// realistic limits for aith are 255:255. |
| 504 |
if(rdb > 0 && rdb < sizeof(buf)) |
| 505 |
{ |
| 506 |
buf[sizeof(buf)-1] = 0; |
| 507 |
for(size_t i=0; i<sizeof(buf); ++i) |
| 508 |
{ |
| 509 |
if(buf[i] == '\r' || buf[i] == '\n' || buf[i] == 0) |
| 510 |
{ |
| 511 |
buf[i] = 0; |
| 512 |
break; |
| 513 |
} |
| 514 |
} |
| 515 |
set_httpauth(buf, opts); |
| 516 |
good = 1; |
| 517 |
} |
| 518 |
close(fd); |
| 519 |
} |
| 520 |
if(!good) |
| 521 |
{ |
| 522 |
error("failed to apply given auth file"); |
| 523 |
safe_exit(12); |
| 524 |
} |
| 525 |
} |
| 526 |
#endif |
| 527 |
|
| 528 |
static void list_output_modules(void) |
| 529 |
{ |
| 530 |
char **names = NULL; |
| 531 |
char **descr = NULL; |
| 532 |
int count = -1; |
| 533 |
out123_handle *lao; |
| 534 |
|
| 535 |
if((lao=out123_new())) |
| 536 |
{ |
| 537 |
printf("\n"); |
| 538 |
printf("Available modules\n"); |
| 539 |
printf("-----------------\n"); |
| 540 |
out123_param_string(lao, OUT123_BINDIR, binpath); |
| 541 |
out123_param_int(lao, OUT123_VERBOSE, param.verbose); |
| 542 |
if(param.quiet) |
| 543 |
out123_param_int(lao, OUT123_FLAGS, OUT123_QUIET); |
| 544 |
if((count=out123_drivers(lao, &names, &descr)) >= 0) |
| 545 |
{ |
| 546 |
int i; |
| 547 |
for(i=0; i<count; ++i) |
| 548 |
{ |
| 549 |
printf( "%-15s%s %s\n" |
| 550 |
, names[i], "output", descr[i] ); |
| 551 |
free(names[i]); |
| 552 |
free(descr[i]); |
| 553 |
} |
| 554 |
free(names); |
| 555 |
free(descr); |
| 556 |
} |
| 557 |
out123_del(lao); |
| 558 |
} |
| 559 |
else if(!param.quiet) |
| 560 |
error("Failed to create an out123 handle."); |
| 561 |
exit(count >= 0 ? 0 : 1); |
| 562 |
} |
| 563 |
|
| 564 |
static void list_output_devices(void) |
| 565 |
{ |
| 566 |
int count = 0; |
| 567 |
char **names = NULL; |
| 568 |
char **descr = NULL; |
| 569 |
out123_handle *ao = NULL; |
| 570 |
ao = out123_new(); |
| 571 |
char *driver = NULL; |
| 572 |
count = out123_devices(ao, param.output_module, &names, &descr, &driver); |
| 573 |
if(count >= 0) |
| 574 |
{ |
| 575 |
printf("Devices for output module %s:\n", driver); |
| 576 |
for(int i=0; i<count; ++i) |
| 577 |
{ |
| 578 |
// Always print like it's a terminal to avoid confusion with extra line breaks. |
| 579 |
print_outstr(stdout, names[i], 1, 1); |
| 580 |
printf("\t"); |
| 581 |
print_outstr(stdout, descr[i], 1, 1); |
| 582 |
printf("\n"); |
| 583 |
} |
| 584 |
out123_stringlists_free(names, descr, count); |
| 585 |
free(driver); |
| 586 |
} else |
| 587 |
{ |
| 588 |
merror("Failed to enumerate output devices: %s", out123_strerror(ao)); |
| 589 |
} |
| 590 |
out123_del(ao); |
| 591 |
exit(count < 0 ? 1 : 0); |
| 592 |
} |
| 593 |
/* static void unset_appflag(char *arg) |
| 594 |
{ |
| 595 |
param.appflags &= ~appflag; |
| 596 |
} */ |
| 597 |
|
| 598 |
/* Please note: GLO_NUM expects point to LONG! */ |
| 599 |
/* ThOr: |
| 600 |
* Yeah, and despite that numerous addresses to int variables were |
| 601 |
passed. |
| 602 |
* That's not good on my Alpha machine with int=32bit and long=64bit! |
| 603 |
* Introduced GLO_INT and GLO_LONG as different bits to make that clear. |
| 604 |
* GLO_NUM no longer exists. |
| 605 |
*/ |
| 606 |
#ifdef OPT_3DNOW |
| 607 |
static int dnow = 0; /* helper for mapping the old 3dnow options */ |
| 608 |
#endif |
| 609 |
topt opts[] = { |
| 610 |
{'k', "skip", GLO_ARG | GLO_LONG, 0, ¶m.start_frame, 0}, |
| 611 |
{'2', "2to1", GLO_INT, 0, ¶m.down_sample, 1}, |
| 612 |
{'4', "4to1", GLO_INT, 0, ¶m.down_sample, 2}, |
| 613 |
{'t', "test", GLO_INT, set_out_test, NULL, 0}, |
| 614 |
{'s', "stdout", GLO_INT, set_out_stdout, NULL, 0}, |
| 615 |
{'O', "outfile", GLO_ARG | GLO_CHAR, set_out_file, NULL, 0}, |
| 616 |
{'c', "check", GLO_INT, 0, ¶m.checkrange, TRUE}, |
| 617 |
{'v', "verbose", 0, set_verbose, 0, 0}, |
| 618 |
{'q', "quiet", 0, set_quiet, 0, 0}, |
| 619 |
{'y', "no-resync", GLO_LONG, set_frameflag, &frameflag, MPG123_NO_RESYNC}, |
| 620 |
{'F', "no-frankenstein", GLO_LONG, set_frameflag, &frameflag, MPG123_NO_FRANKENSTEIN}, |
| 621 |
/* compatibility, no-resync is to be used nowadays */ |
| 622 |
{0, "resync", GLO_LONG, set_frameflag, &frameflag, MPG123_NO_RESYNC}, |
| 623 |
{'0', "single0", GLO_LONG, set_frameflag, &frameflag, MPG123_MONO_LEFT}, |
| 624 |
{0, "left", GLO_LONG, set_frameflag, &frameflag, MPG123_MONO_LEFT}, |
| 625 |
{'1', "single1", GLO_LONG, set_frameflag, &frameflag, MPG123_MONO_RIGHT}, |
| 626 |
{0, "right", GLO_LONG, set_frameflag, &frameflag, MPG123_MONO_RIGHT}, |
| 627 |
{'m', "singlemix", GLO_LONG, set_frameflag, &frameflag, MPG123_MONO_MIX}, |
| 628 |
{0, "mix", GLO_LONG, set_frameflag, &frameflag, MPG123_MONO_MIX}, |
| 629 |
{0, "mono", GLO_LONG, set_frameflag, &frameflag, MPG123_MONO_MIX}, |
| 630 |
{0, "stereo", GLO_LONG, set_frameflag, &frameflag, MPG123_FORCE_STEREO}, |
| 631 |
{0, "reopen", GLO_INT, 0, ¶m.force_reopen, 1}, |
| 632 |
{'g', "gain", GLO_ARG | GLO_LONG, 0, ¶m.gain, 0}, |
| 633 |
{'r', "rate", GLO_ARG | GLO_LONG, 0, ¶m.force_rate, 0}, |
| 634 |
{0, "resample", GLO_ARG | GLO_CHAR, set_resample, NULL, 0}, |
| 635 |
{0, "8bit", GLO_LONG, set_frameflag, &frameflag, MPG123_FORCE_8BIT}, |
| 636 |
{0, "float", GLO_LONG, set_frameflag, &frameflag, MPG123_FORCE_FLOAT}, |
| 637 |
{0, "headphones", 0, set_output_h, 0,0}, |
| 638 |
{0, "speaker", 0, set_output_s, 0,0}, |
| 639 |
{0, "lineout", 0, set_output_l, 0,0}, |
| 640 |
{'o', "output", GLO_ARG | GLO_CHAR, set_output, 0, 0}, |
| 641 |
{0, "list-modules", GLO_INT, 0, &runmode, LIST_MODULES}, |
| 642 |
{0, "list-devices", GLO_INT, 0, &runmode, LIST_DEVICES}, |
| 643 |
{'a', "audiodevice", GLO_ARG | GLO_CHAR, 0, ¶m.output_device, 0}, |
| 644 |
{'f', "scale", GLO_ARG | GLO_LONG, 0, ¶m.outscale, 0}, |
| 645 |
{'n', "frames", GLO_ARG | GLO_LONG, 0, ¶m.frame_number, 0}, |
| 646 |
{0, "no-visual", GLO_INT, 0, ¶m.term_visual, FALSE}, |
| 647 |
{'C', "control", GLO_INT, 0, ¶m.term_ctrl, TRUE}, |
| 648 |
{0, "no-control", GLO_INT, 0, ¶m.term_ctrl, FALSE}, |
| 649 |
{0, "ctrlusr1", GLO_ARG | GLO_CHAR, 0, ¶m.term_usr1, 0}, |
| 650 |
{0, "ctrlusr2", GLO_ARG | GLO_CHAR, 0, ¶m.term_usr2, 0}, |
| 651 |
#ifndef NOXFERMEM |
| 652 |
{'b', "buffer", GLO_ARG | GLO_LONG, 0, ¶m.usebuffer, 0}, |
| 653 |
{0, "smooth", GLO_INT, 0, ¶m.smooth, 1}, |
| 654 |
{0, "preload", GLO_ARG|GLO_DOUBLE, 0, ¶m.preload, 0}, |
| 655 |
#endif |
| 656 |
{'R', "remote", GLO_INT, 0, ¶m.remote, TRUE}, |
| 657 |
{0, "remote-err", GLO_INT, 0, ¶m.remote_err, TRUE}, |
| 658 |
{'d', "doublespeed", GLO_ARG | GLO_LONG, 0, ¶m.doublespeed, 0}, |
| 659 |
{'h', "halfspeed", GLO_ARG | GLO_LONG, 0, ¶m.halfspeed, 0}, |
| 660 |
#ifdef NETWORK |
| 661 |
{'p', "proxy", GLO_ARG | GLO_CHAR, 0, ¶m.proxyurl, 0}, |
| 662 |
#endif |
| 663 |
{'@', "list", GLO_ARG | GLO_CHAR, 0, ¶m.listname, 0}, |
| 664 |
/* 'z' comes from the the german word 'zufall' (eng: random) */ |
| 665 |
{'z', "shuffle", GLO_INT, 0, ¶m.shuffle, 1}, |
| 666 |
{'Z', "random", GLO_INT, 0, ¶m.shuffle, 2}, |
| 667 |
{'E', "equalizer", GLO_ARG | GLO_CHAR, 0, &equalfile,1}, |
| 668 |
#ifdef HAVE_SETPRIORITY |
| 669 |
{0, "aggressive", GLO_INT, 0, ¶m.aggressive, 2}, |
| 670 |
#endif |
| 671 |
#ifdef OPT_3DNOW |
| 672 |
#define SET_3DNOW 1 |
| 673 |
#define SET_I586 2 |
| 674 |
{0, "force-3dnow", GLO_CHAR, 0, &dnow, SET_3DNOW}, |
| 675 |
{0, "no-3dnow", GLO_CHAR, 0, &dnow, SET_I586}, |
| 676 |
{0, "test-3dnow", GLO_INT, 0, &runmode, TEST_CPU}, |
| 677 |
#endif |
| 678 |
{0, "cpu", GLO_ARG | GLO_CHAR, 0, ¶m.cpu, 0}, |
| 679 |
{0, "test-cpu", GLO_INT, 0, &runmode, TEST_CPU}, |
| 680 |
{0, "list-cpu", GLO_INT, 0, &runmode , LIST_CPU}, |
| 681 |
#if defined(NETWORK) || defined(NET123) |
| 682 |
#ifdef NET123 |
| 683 |
{0, "network", GLO_ARG|GLO_CHAR, 0, ¶m.network_backend, 0}, |
| 684 |
#endif |
| 685 |
{'u', "auth", GLO_ARG | GLO_CHAR, set_httpauth, 0, 0}, |
| 686 |
{0, "auth-file", GLO_ARG | GLO_CHAR, set_httpauth_file, 0, 0}, |
| 687 |
#endif |
| 688 |
#if defined (HAVE_SCHED_SETSCHEDULER) || defined (HAVE_WINDOWS_H) |
| 689 |
/* check why this should be a long variable instead of int! */ |
| 690 |
{'T', "realtime", GLO_LONG, 0, ¶m.realtime, TRUE }, |
| 691 |
#else |
| 692 |
{'T', "realtime", 0, realtime_not_compiled, 0, 0 }, |
| 693 |
#endif |
| 694 |
#ifdef HAVE_WINDOWS_H |
| 695 |
{0, "priority", GLO_ARG | GLO_INT, 0, ¶m.w32_priority, 0}, |
| 696 |
#endif |
| 697 |
{0, "title", GLO_INT, 0, ¶m.xterm_title, TRUE }, |
| 698 |
{'w', "wav", GLO_ARG | GLO_CHAR, set_out_wav, 0, 0 }, |
| 699 |
{0, "cdr", GLO_ARG | GLO_CHAR, set_out_cdr, 0, 0 }, |
| 700 |
{0, "au", GLO_ARG | GLO_CHAR, set_out_au, 0, 0 }, |
| 701 |
{0, "gapless", GLO_LONG, set_frameflag, &frameflag, MPG123_GAPLESS}, |
| 702 |
{0, "no-gapless", GLO_LONG, unset_frameflag, &frameflag, MPG123_GAPLESS}, |
| 703 |
{0, "no-infoframe", GLO_LONG, set_frameflag, &frameflag, MPG123_IGNORE_INFOFRAME}, |
| 704 |
{'?', "help", 0, want_usage, 0, 0 }, |
| 705 |
{0 , "longhelp" , 0, want_long_usage, 0, 0 }, |
| 706 |
{0 , "version" , 0, give_version, 0, 0 }, |
| 707 |
{0, "libversion" , 0, give_libversion, 0, 0 }, |
| 708 |
{'l', "listentry", GLO_ARG | GLO_LONG, 0, ¶m.listentry, 0 }, |
| 709 |
{0, "continue", GLO_LONG, set_appflag, &appflag, MPG123APP_CONTINUE }, |
| 710 |
{0, "rva-mix", GLO_INT, 0, ¶m.rva, 1 }, |
| 711 |
{0, "rva-radio", GLO_INT, 0, ¶m.rva, 1 }, |
| 712 |
{0, "rva-album", GLO_INT, 0, ¶m.rva, 2 }, |
| 713 |
{0, "rva-audiophile", GLO_INT, 0, ¶m.rva, 2 }, |
| 714 |
{0, "no-icy-meta", GLO_INT, 0, ¶m.talk_icy, 0 }, |
| 715 |
{0, "long-tag", GLO_INT, 0, ¶m.long_id3, 1 }, |
| 716 |
#ifdef FIFO |
| 717 |
{0, "fifo", GLO_ARG | GLO_CHAR, 0, ¶m.fifo, 0}, |
| 718 |
#endif |
| 719 |
{0, "timeout", GLO_ARG | GLO_LONG, 0, ¶m.timeout, 0}, |
| 720 |
{0, "loop", GLO_ARG | GLO_LONG, 0, ¶m.loop, 0}, |
| 721 |
{'i', "index", GLO_INT, 0, ¶m.index, 1}, |
| 722 |
{'D', "delay", GLO_ARG | GLO_INT, 0, ¶m.delay, 0}, |
| 723 |
{0, "resync-limit", GLO_ARG | GLO_LONG, 0, ¶m.resync_limit, 0}, |
| 724 |
{0, "pitch", GLO_ARG|GLO_DOUBLE, 0, ¶m.pitch, 0}, |
| 725 |
{0, "pauseloop", GLO_ARG|GLO_DOUBLE, 0, ¶m.pauseloop, 0}, |
| 726 |
{0, "presetloop", GLO_ARG|GLO_DOUBLE, 0, ¶m.pauseloop, 0}, |
| 727 |
#ifdef NETWORK |
| 728 |
{0, "ignore-mime", GLO_LONG, set_appflag, &appflag, MPG123APP_IGNORE_MIME }, |
| 729 |
#endif |
| 730 |
{0, "lyrics", GLO_LONG, set_appflag, &appflag, MPG123APP_LYRICS}, |
| 731 |
{0, "keep-open", GLO_INT, 0, ¶m.keep_open, 1}, |
| 732 |
{0, "utf8", GLO_INT, 0, ¶m.force_utf8, 1}, |
| 733 |
{0, "fuzzy", GLO_LONG, set_frameflag, &frameflag, MPG123_FUZZY}, |
| 734 |
{0, "index-size", GLO_ARG|GLO_LONG, 0, ¶m.index_size, 0}, |
| 735 |
{0, "no-seekbuffer", GLO_LONG, unset_frameflag, &frameflag, MPG123_SEEKBUFFER}, |
| 736 |
{'e', "encoding", GLO_ARG|GLO_CHAR, 0, ¶m.force_encoding, 0}, |
| 737 |
{0, "preframes", GLO_ARG|GLO_LONG, 0, ¶m.preframes, 0}, |
| 738 |
{0, "skip-id3v2", GLO_LONG, set_frameflag, &frameflag, MPG123_SKIP_ID3V2}, |
| 739 |
{0, "streamdump", GLO_ARG|GLO_CHAR, 0, ¶m.streamdump, 0}, |
| 740 |
{0, "icy-interval", GLO_ARG|GLO_LONG, 0, ¶m.icy_interval, 0}, |
| 741 |
{0, "ignore-streamlength", GLO_LONG, set_frameflag, &frameflag, MPG123_IGNORE_STREAMLENGTH}, |
| 742 |
{0, "name", GLO_ARG|GLO_CHAR, 0, ¶m.name, 0}, |
| 743 |
{0, "devbuffer", GLO_ARG|GLO_DOUBLE, 0, ¶m.device_buffer, 0}, |
| 744 |
{0, 0, 0, 0, 0, 0} |
| 745 |
}; |
| 746 |
|
| 747 |
/* 1 on success, 0 on failure */ |
| 748 |
int open_track(char *fname) |
| 749 |
{ |
| 750 |
if(filept) // total paranoia |
| 751 |
stream_close(filept); |
| 752 |
filept = stream_open(fname); |
| 753 |
if(!filept) |
| 754 |
return 0; |
| 755 |
|
| 756 |
/* now check if we got sth. and if we got sth. good */ |
| 757 |
if( filept->htd.content_type.p != NULL |
| 758 |
&& !APPFLAG(MPG123APP_IGNORE_MIME) && !(debunk_mime(filept->htd.content_type.p) & IS_FILE) ) |
| 759 |
{ |
| 760 |
error1("Unknown mpeg MIME type %s - is it perhaps a playlist (use -@)?", filept->htd.content_type.p == NULL ? "<nil>" : filept->htd.content_type.p); |
| 761 |
error("If you know the stream is mpeg1/2 audio, then please report this as "PACKAGE_NAME" bug"); |
| 762 |
return 0; |
| 763 |
} |
| 764 |
|
| 765 |
debug("OK... going to hook up libmpg123 and dump."); |
| 766 |
if(dump_setup(filept, mh)) |
| 767 |
return 0; |
| 768 |
fresh = TRUE; |
| 769 |
return 1; |
| 770 |
} |
| 771 |
|
| 772 |
/* for symmetry */ |
| 773 |
void close_track(void) |
| 774 |
{ |
| 775 |
mpg123_close(mh); |
| 776 |
stream_close(filept); |
| 777 |
filept = NULL; |
| 778 |
} |
| 779 |
|
| 780 |
/* return 1 on success, 0 on failure */ |
| 781 |
int play_frame(void) |
| 782 |
{ |
| 783 |
unsigned char *audio; |
| 784 |
int mc; |
| 785 |
size_t bytes = 0; |
| 786 |
debug("play_frame"); |
| 787 |
mc = mpg123_decode_frame(mh, &framenum, &audio, &bytes); |
| 788 |
mpg123_getstate(mh, MPG123_FRESH_DECODER, &new_header, NULL); |
| 789 |
|
| 790 |
/* Play what is there to play (starting with second decode_frame call!) */ |
| 791 |
if(bytes) |
| 792 |
{ |
| 793 |
if(param.frame_number > -1) --frames_left; |
| 794 |
if(fresh && framenum >= param.start_frame) |
| 795 |
{ |
| 796 |
fresh = FALSE; |
| 797 |
} |
| 798 |
if(bytes < minbytes && !prebuffer_fill) |
| 799 |
{ |
| 800 |
/* Postpone playback of little buffers until large buffers can |
| 801 |
follow them right away, preventing underruns. */ |
| 802 |
if(prebuffer_size < minbytes) |
| 803 |
{ |
| 804 |
if(prebuffer) |
| 805 |
free(prebuffer); |
| 806 |
if(!(prebuffer = malloc(minbytes))) |
| 807 |
safe_exit(11); |
| 808 |
prebuffer_size = minbytes; |
| 809 |
} |
| 810 |
memcpy(prebuffer, audio, bytes); |
| 811 |
prebuffer_fill = bytes; |
| 812 |
bytes = 0; |
| 813 |
debug1("prebuffered %zu bytes", prebuffer_fill); |
| 814 |
} |
| 815 |
if(param.checkrange) |
| 816 |
{ |
| 817 |
long clip = mpg123_clip(mh); |
| 818 |
if(clip > 0) fprintf(stderr,"\n%ld samples clipped\n", clip); |
| 819 |
} |
| 820 |
} |
| 821 |
/* The bytes could have been postponed to later. */ |
| 822 |
if(bytes) |
| 823 |
{ |
| 824 |
unsigned char *playbuf = audio; |
| 825 |
if(prebuffer_fill) |
| 826 |
{ |
| 827 |
size_t missing; |
| 828 |
/* This is tricky: The small piece needs to be filled up. Playing 10 |
| 829 |
pcm frames will always trigger underruns with ALSA, dammit! |
| 830 |
This grabs some data from current frame, unless it itself would |
| 831 |
end up smaller than the prebuffer. Ending up empty is fine. */ |
| 832 |
if( prebuffer_fill < prebuffer_size |
| 833 |
&& ( bytes <= (missing=prebuffer_size-prebuffer_fill) |
| 834 |
|| bytes >= missing+prebuffer_size ) ) |
| 835 |
{ |
| 836 |
if(bytes < missing) |
| 837 |
missing=bytes; |
| 838 |
memcpy(prebuffer+prebuffer_fill, playbuf, missing); |
| 839 |
playbuf += missing; |
| 840 |
bytes -= missing; |
| 841 |
prebuffer_fill += missing; |
| 842 |
} |
| 843 |
if( audio_play(ao, prebuffer, prebuffer_fill) < prebuffer_fill |
| 844 |
&& !intflag ) |
| 845 |
{ |
| 846 |
error("Deep trouble! Cannot flush to my output anymore!"); |
| 847 |
safe_exit(133); |
| 848 |
} |
| 849 |
prebuffer_fill = 0; |
| 850 |
} |
| 851 |
/* Interrupt here doesn't necessarily interrupt out123_play(). |
| 852 |
I wonder if that makes us miss errors. Actual issues should |
| 853 |
just be postponed. */ |
| 854 |
if(bytes && !intflag) /* Previous piece could already be interrupted. */ |
| 855 |
if(audio_play(ao, playbuf, bytes) < bytes && !intflag) |
| 856 |
{ |
| 857 |
error("Deep trouble! Cannot flush to my output anymore!"); |
| 858 |
safe_exit(133); |
| 859 |
} |
| 860 |
} |
| 861 |
/* Special actions and errors. */ |
| 862 |
if(mc != MPG123_OK) |
| 863 |
{ |
| 864 |
if(mc == MPG123_ERR || mc == MPG123_DONE || mc == MPG123_NEED_MORE) |
| 865 |
{ |
| 866 |
if(!param.quiet && mc == MPG123_ERR) error1("...in decoding next frame: %s", mpg123_strerror(mh)); |
| 867 |
if(!param.quiet && mc == MPG123_NEED_MORE) |
| 868 |
error("The decoder expected more. Old libmpg123 that does this for non-feed readers?"); |
| 869 |
if(mc != MPG123_DONE && !got_played) |
| 870 |
got_played = -1; |
| 871 |
return 0; |
| 872 |
} |
| 873 |
if(mc == MPG123_NO_SPACE) |
| 874 |
{ |
| 875 |
error("I have not enough output space? I didn't plan for this."); |
| 876 |
if(!got_played) |
| 877 |
got_played = -1; |
| 878 |
return 0; |
| 879 |
} |
| 880 |
if(mc == MPG123_NEW_FORMAT) |
| 881 |
{ |
| 882 |
long rate; |
| 883 |
int channels; |
| 884 |
int encoding; |
| 885 |
play_prebuffer(); /* Make sure we got rid of old data. */ |
| 886 |
mpg123_getformat(mh, &rate, &channels, &encoding); |
| 887 |
/* A layer I frame duration at minimum for live outputs. */ |
| 888 |
if(output_propflags & OUT123_PROP_LIVE) |
| 889 |
minbytes = out123_encsize(encoding)*channels*384; |
| 890 |
else |
| 891 |
minbytes = 0; |
| 892 |
if(framenum && param.verbose) |
| 893 |
print_stat(mh,0,ao,0,¶m); |
| 894 |
if(param.verbose > 1) |
| 895 |
{ |
| 896 |
const char* encname = out123_enc_name(encoding); |
| 897 |
fprintf( stderr |
| 898 |
, "\nNote: New output format with %li Hz, %i channels, encoding %s.\n" |
| 899 |
, rate, channels, encname ? encname : "???" ); |
| 900 |
} |
| 901 |
new_header = TRUE; |
| 902 |
|
| 903 |
check_fatal_output(audio_prepare(ao, mh, rate, channels, encoding)); |
| 904 |
/* We may take some time feeding proper data, so pause by default. */ |
| 905 |
out123_pause(ao); |
| 906 |
} |
| 907 |
} |
| 908 |
if((param.verbose > 3 || new_header) && !param.quiet) |
| 909 |
{ |
| 910 |
new_header = FALSE; |
| 911 |
if(framenum) |
| 912 |
print_stat(mh,0,ao,0,¶m); |
| 913 |
fprintf(stderr, "\n"); |
| 914 |
if(param.verbose > 1) |
| 915 |
print_header(mh); |
| 916 |
else |
| 917 |
print_header_compact(mh); |
| 918 |
} |
| 919 |
|
| 920 |
return 1; |
| 921 |
} |
| 922 |
|
| 923 |
/* Return TRUE if we should continue (second interrupt happens quickly), skipping tracks, or FALSE if we should die. */ |
| 924 |
#if !defined(WIN32) && !defined(GENERIC) |
| 925 |
int skip_or_die(struct timeval *start_time) |
| 926 |
{ |
| 927 |
/* Death is fatal right away. */ |
| 928 |
if(deathflag) |
| 929 |
{ |
| 930 |
debug("The world wants me to die."); |
| 931 |
return FALSE; |
| 932 |
} |
| 933 |
/* |
| 934 |
* When HAVE_TERMIOS is defined, there is 'q' to terminate a list of songs, so |
| 935 |
* no pressing need to keep up this first second SIGINT hack that was too |
| 936 |
* often mistaken as a bug. [dk] |
| 937 |
* ThOr: Yep, I deactivated the Ctrl+C hack for active control modes. |
| 938 |
* Though, some sort of hack remains, still using intflag for track skip. |
| 939 |
*/ |
| 940 |
if(!param.term_ctrl) |
| 941 |
{ |
| 942 |
struct timeval now; |
| 943 |
unsigned long secdiff; |
| 944 |
gettimeofday (&now, NULL); |
| 945 |
secdiff = (now.tv_sec - start_time->tv_sec) * 1000; |
| 946 |
if(now.tv_usec >= start_time->tv_usec) |
| 947 |
secdiff += (now.tv_usec - start_time->tv_usec) / 1000; |
| 948 |
else |
| 949 |
secdiff -= (start_time->tv_usec - now.tv_usec) / 1000; |
| 950 |
if (secdiff < 1000) |
| 951 |
{ |
| 952 |
debug("got the second interrupt: out of here!"); |
| 953 |
return FALSE; |
| 954 |
} |
| 955 |
else |
| 956 |
{ |
| 957 |
debug("It's a track advancement message."); |
| 958 |
++skip_tracks; |
| 959 |
} |
| 960 |
} |
| 961 |
else if(skip_tracks == 0) |
| 962 |
{ |
| 963 |
debug("breaking up"); |
| 964 |
return FALSE; |
| 965 |
} |
| 966 |
return TRUE; /* Track advancement... no instant kill on generic/windows... */ |
| 967 |
} |
| 968 |
#else |
| 969 |
/* On generic systems and win32, there is no decision here... just TRUE. */ |
| 970 |
#define skip_or_die(a) TRUE |
| 971 |
#endif |
| 972 |
|
| 973 |
void formatcheck(void) |
| 974 |
{ |
| 975 |
if(mpg123_errcode(mh) == MPG123_BAD_OUTFORMAT) |
| 976 |
{ |
| 977 |
fprintf(stderr, "%s", "So, you have trouble getting an output format... this is the matrix of currently possible formats:\n"); |
| 978 |
print_capabilities(ao, mh); |
| 979 |
fprintf(stderr, "%s", "Somehow the input data and your choices don't allow one of these.\n"); |
| 980 |
} |
| 981 |
} |
| 982 |
|
| 983 |
int main(int sys_argc, char ** sys_argv) |
| 984 |
{ |
| 985 |
int result; |
| 986 |
char end_of_files = FALSE; |
| 987 |
long parr; |
| 988 |
char *fname; |
| 989 |
int libpar = 0; |
| 990 |
mpg123_pars *mp; |
| 991 |
int args_utf8 = FALSE; |
| 992 |
int pl_utf8 = FALSE; |
| 993 |
#if !defined(WIN32) && !defined(GENERIC) |
| 994 |
struct timeval start_time; |
| 995 |
#endif |
| 996 |
aux_out = stdout; /* Need to initialize here because stdout is not a constant?! */ |
| 997 |
#if defined (WANT_WIN32_UNICODE) |
| 998 |
if(win32_cmdline_utf8(&argc, &argv) != 0) |
| 999 |
{ |
| 1000 |
error("Cannot convert command line to UTF8!"); |
| 1001 |
safe_exit(76); |
| 1002 |
} |
| 1003 |
args_utf8 = TRUE; |
| 1004 |
#else |
| 1005 |
argv = sys_argv; |
| 1006 |
argc = sys_argc; |
| 1007 |
#endif |
| 1008 |
#if defined (WANT_WIN32_SOCKETS) |
| 1009 |
win32_net_init(); |
| 1010 |
#endif |
| 1011 |
|
| 1012 |
#ifdef WIN32 |
| 1013 |
/* Despite in Unicode form, the path munging backend is still in ANSI/ASCII |
| 1014 |
* so using _wpgmptr with unicode paths after UTF8 conversion is broken on Windows |
| 1015 |
*/ |
| 1016 |
|
| 1017 |
fullprogname = INT123_compat_strdup(_pgmptr); |
| 1018 |
#else |
| 1019 |
fullprogname = INT123_compat_strdup(argv[0]); |
| 1020 |
#endif |
| 1021 |
|
| 1022 |
if(!fullprogname) |
| 1023 |
{ |
| 1024 |
error("OOM"); /* Out Of Memory. Don't waste bytes on that error. */ |
| 1025 |
safe_exit(1); |
| 1026 |
} |
| 1027 |
/* Extract binary and path, take stuff before/after last / or \ . */ |
| 1028 |
if( (prgName = strrchr(fullprogname, '/')) |
| 1029 |
|| (prgName = strrchr(fullprogname, '\\'))) |
| 1030 |
{ |
| 1031 |
/* There is some explicit path. */ |
| 1032 |
prgName[0] = 0; /* End byte for path. */ |
| 1033 |
prgName++; |
| 1034 |
binpath = fullprogname; |
| 1035 |
} |
| 1036 |
else |
| 1037 |
{ |
| 1038 |
prgName = fullprogname; /* No path separators there. */ |
| 1039 |
binpath = NULL; /* No path at all. */ |
| 1040 |
} |
| 1041 |
|
| 1042 |
/* Need to initialize mpg123 lib here for default parameter values. */ |
| 1043 |
|
| 1044 |
result = mpg123_init(); |
| 1045 |
if(result != MPG123_OK) |
| 1046 |
{ |
| 1047 |
error1("Cannot initialize mpg123 library: %s", mpg123_plain_strerror(result)); |
| 1048 |
safe_exit(77); |
| 1049 |
} |
| 1050 |
cleanup_mpg123 = TRUE; |
| 1051 |
|
| 1052 |
mp = mpg123_new_pars(&result); /* This may get leaked on premature exit(), which is mainly a cosmetic issue... */ |
| 1053 |
if(mp == NULL) |
| 1054 |
{ |
| 1055 |
error1("Crap! Cannot get mpg123 parameters: %s", mpg123_plain_strerror(result)); |
| 1056 |
safe_exit(78); |
| 1057 |
} |
| 1058 |
|
| 1059 |
/* get default values */ |
| 1060 |
mpg123_getpar(mp, MPG123_DOWN_SAMPLE, &parr, NULL); |
| 1061 |
param.down_sample = (int) parr; |
| 1062 |
mpg123_getpar(mp, MPG123_RVA, ¶m.rva, NULL); |
| 1063 |
mpg123_getpar(mp, MPG123_DOWNSPEED, ¶m.halfspeed, NULL); |
| 1064 |
mpg123_getpar(mp, MPG123_UPSPEED, ¶m.doublespeed, NULL); |
| 1065 |
mpg123_getpar(mp, MPG123_OUTSCALE, ¶m.outscale, NULL); |
| 1066 |
mpg123_getpar(mp, MPG123_FLAGS, &parr, NULL); |
| 1067 |
mpg123_getpar(mp, MPG123_INDEX_SIZE, ¶m.index_size, NULL); |
| 1068 |
param.flags = (int) parr; |
| 1069 |
param.flags |= MPG123_SEEKBUFFER; /* Default on, for HTTP streams. */ |
| 1070 |
mpg123_getpar(mp, MPG123_RESYNC_LIMIT, ¶m.resync_limit, NULL); |
| 1071 |
mpg123_getpar(mp, MPG123_PREFRAMES, ¶m.preframes, NULL); |
| 1072 |
/* Also need proper default flags from libout123. */ |
| 1073 |
{ |
| 1074 |
out123_handle *paro = out123_new(); |
| 1075 |
out123_getparam_int(paro, OUT123_FLAGS, ¶m.output_flags); |
| 1076 |
out123_del(paro); |
| 1077 |
} |
| 1078 |
|
| 1079 |
#ifdef __OS2__ |
| 1080 |
_wildcard(&argc,&argv); |
| 1081 |
#endif |
| 1082 |
// If either stdin or stderr look like a terminal, we enable things. |
| 1083 |
// Actually checking for terminal properties is safer than calling ctermid() here. |
| 1084 |
int stderr_width = term_width(STDERR_FILENO); |
| 1085 |
int stdin_width = term_width(STDIN_FILENO); |
| 1086 |
stderr_is_term = stderr_width >= 0; |
| 1087 |
stdin_is_term = stdin_width >= 0; |
| 1088 |
stdout_is_term = term_width(STDOUT_FILENO) >= 0; |
| 1089 |
int term_ctrl_default = stdin_is_term || stdout_is_term || stderr_is_term; |
| 1090 |
param.term_ctrl = MAYBE; |
| 1091 |
while ((result = getlopt(argc, argv, opts))) |
| 1092 |
switch (result) { |
| 1093 |
case GLO_UNKNOWN: |
| 1094 |
print_outstr(stderr, prgName, 0, stderr_is_term); |
| 1095 |
fprintf(stderr, ": Unknown option \""); |
| 1096 |
print_outstr(stderr, loptarg, 0, stderr_is_term); |
| 1097 |
fprintf(stderr, "\".\n"); |
| 1098 |
usage(1); |
| 1099 |
case GLO_NOARG: |
| 1100 |
print_outstr(stderr, prgName, 0, stderr_is_term); |
| 1101 |
fprintf(stderr, ": Missing argument for option \"%s\".\n", loptarg); |
| 1102 |
usage(1); |
| 1103 |
case GLO_BADARG: |
| 1104 |
print_outstr(stderr, prgName, 0, stderr_is_term); |
| 1105 |
fprintf(stderr, ": Bad option argument \"%s\".\n", loptarg); |
| 1106 |
usage(1); |
| 1107 |
} |
| 1108 |
/* Do this _after_ parameter parsing. */ |
| 1109 |
utf8force = param.force_utf8; |
| 1110 |
check_locale(); /* Check/set locale; store if it uses UTF-8. */ |
| 1111 |
meta_show_lyrics = APPFLAG(MPG123APP_LYRICS); |
| 1112 |
|
| 1113 |
switch(runmode) |
| 1114 |
{ |
| 1115 |
case RUN_MAIN: |
| 1116 |
break; |
| 1117 |
case LIST_MODULES: |
| 1118 |
list_output_modules(); |
| 1119 |
case LIST_DEVICES: |
| 1120 |
list_output_devices(); |
| 1121 |
case LIST_CPU: |
| 1122 |
{ |
| 1123 |
const char **all_dec = mpg123_decoders(); |
| 1124 |
printf("Builtin decoders:"); |
| 1125 |
while(*all_dec != NULL){ printf(" %s", *all_dec); ++all_dec; } |
| 1126 |
printf("\n"); |
| 1127 |
mpg123_delete_pars(mp); |
| 1128 |
return 0; |
| 1129 |
} |
| 1130 |
case TEST_CPU: |
| 1131 |
{ |
| 1132 |
const char **all_dec = mpg123_supported_decoders(); |
| 1133 |
printf("Supported decoders:"); |
| 1134 |
while(*all_dec != NULL){ printf(" %s", *all_dec); ++all_dec; } |
| 1135 |
printf("\n"); |
| 1136 |
mpg123_delete_pars(mp); |
| 1137 |
return 0; |
| 1138 |
} |
| 1139 |
default: |
| 1140 |
merror("Invalid run mode %d", runmode); |
| 1141 |
safe_exit(79); |
| 1142 |
} |
| 1143 |
if(param.gain != -1) |
| 1144 |
{ |
| 1145 |
warning("The parameter -g is deprecated and may be removed in the future."); |
| 1146 |
} |
| 1147 |
|
| 1148 |
if (loptind >= argc && !param.listname && !param.remote) usage(1); |
| 1149 |
/* Init audio as early as possible. |
| 1150 |
If there is the buffer process to be spawned, it shouldn't carry the mpg123_handle with it. */ |
| 1151 |
|
| 1152 |
/* ========================================================================================================= */ |
| 1153 |
/* Enterning the leaking zone... we start messing with stuff here that should be taken care of when leaving. */ |
| 1154 |
/* Don't just exit() or return out... */ |
| 1155 |
/* ========================================================================================================= */ |
| 1156 |
|
| 1157 |
#if !defined(WIN32) && !defined(GENERIC) |
| 1158 |
if(param.remote && !param.verbose) |
| 1159 |
param.quiet = 1; |
| 1160 |
#endif |
| 1161 |
|
| 1162 |
/* Set the frame parameters from command line options */ |
| 1163 |
if(param.quiet) |
| 1164 |
{ |
| 1165 |
param.flags |= MPG123_QUIET; |
| 1166 |
param.output_flags |= OUT123_QUIET; |
| 1167 |
} |
| 1168 |
|
| 1169 |
#ifdef OPT_3DNOW |
| 1170 |
if(dnow != 0) param.cpu = (dnow == SET_3DNOW) ? "3dnow" : "i586"; |
| 1171 |
#endif |
| 1172 |
if(param.cpu != NULL && (!strcmp(param.cpu, "auto") || !strcmp(param.cpu, ""))) param.cpu = NULL; |
| 1173 |
if(!( MPG123_OK == (result = mpg123_par(mp, MPG123_VERBOSE, param.verbose, 0)) |
| 1174 |
&& ++libpar |
| 1175 |
&& MPG123_OK == (result = mpg123_par(mp, MPG123_FLAGS, param.flags, 0)) |
| 1176 |
&& ++libpar |
| 1177 |
&& MPG123_OK == (result = mpg123_par(mp, MPG123_DOWN_SAMPLE, param.down_sample, 0)) |
| 1178 |
&& ++libpar |
| 1179 |
&& MPG123_OK == (result = mpg123_par(mp, MPG123_RVA, param.rva, 0)) |
| 1180 |
&& ++libpar |
| 1181 |
&& MPG123_OK == (result = mpg123_par(mp, MPG123_DOWNSPEED, param.halfspeed, 0)) |
| 1182 |
&& ++libpar |
| 1183 |
&& MPG123_OK == (result = mpg123_par(mp, MPG123_UPSPEED, param.doublespeed, 0)) |
| 1184 |
&& ++libpar |
| 1185 |
&& MPG123_OK == (result = mpg123_par(mp, MPG123_ICY_INTERVAL, 0, 0)) |
| 1186 |
&& ++libpar |
| 1187 |
&& MPG123_OK == (result = mpg123_par(mp, MPG123_RESYNC_LIMIT, param.resync_limit, 0)) |
| 1188 |
&& ++libpar |
| 1189 |
&& MPG123_OK == (result = mpg123_par(mp, MPG123_TIMEOUT, param.timeout, 0)) |
| 1190 |
&& ++libpar |
| 1191 |
&& MPG123_OK == (result = mpg123_par(mp, MPG123_OUTSCALE, param.outscale, 0)) |
| 1192 |
&& ++libpar |
| 1193 |
&& MPG123_OK == (result = mpg123_par(mp, MPG123_PREFRAMES, param.preframes, 0)) |
| 1194 |
)) |
| 1195 |
{ |
| 1196 |
error2("Cannot set library parameter %i: %s", libpar, mpg123_plain_strerror(result)); |
| 1197 |
safe_exit(45); |
| 1198 |
} |
| 1199 |
if (!(param.listentry < 0) && !param.quiet) print_title(stderr); /* do not pollute stdout! */ |
| 1200 |
|
| 1201 |
{ |
| 1202 |
long default_index; |
| 1203 |
mpg123_getpar(mp, MPG123_INDEX_SIZE, &default_index, NULL); |
| 1204 |
if( param.index_size != default_index && (result = mpg123_par(mp, MPG123_INDEX_SIZE, param.index_size, 0.)) != MPG123_OK ) |
| 1205 |
error1("Setting of frame index size failed: %s", mpg123_plain_strerror(result)); |
| 1206 |
} |
| 1207 |
|
| 1208 |
if(param.force_rate && param.down_sample) |
| 1209 |
{ |
| 1210 |
error("Down sampling and fixed rate options not allowed together!"); |
| 1211 |
safe_exit(1); |
| 1212 |
} |
| 1213 |
|
| 1214 |
/* Now actually get an mpg123_handle. */ |
| 1215 |
mh = mpg123_parnew(mp, param.cpu, &result); |
| 1216 |
if(mh == NULL) |
| 1217 |
{ |
| 1218 |
error1("Crap! Cannot get a mpg123 handle: %s", mpg123_plain_strerror(result)); |
| 1219 |
safe_exit(77); |
| 1220 |
} |
| 1221 |
mpg123_delete_pars(mp); /* Don't need the parameters anymore ,they're in the handle now. */ |
| 1222 |
|
| 1223 |
load_equalizer(mh); |
| 1224 |
|
| 1225 |
#ifdef HAVE_SETPRIORITY |
| 1226 |
if(param.aggressive) { /* tst */ |
| 1227 |
int mypid = getpid(); |
| 1228 |
if(!param.quiet) fprintf(stderr,"Aggressively trying to increase priority.\n"); |
| 1229 |
if(setpriority(PRIO_PROCESS,mypid,-20)) |
| 1230 |
error("Failed to aggressively increase priority.\n"); |
| 1231 |
} |
| 1232 |
#endif |
| 1233 |
|
| 1234 |
#if defined (HAVE_SCHED_SETSCHEDULER) && !defined (__CYGWIN__) && !defined (HAVE_WINDOWS_H) |
| 1235 |
/* Cygwin --realtime seems to fail when accessing network, using win32 set priority instead */ |
| 1236 |
/* MinGW may have pthread installed, we prefer win32API */ |
| 1237 |
if (param.realtime) { /* Get real-time priority */ |
| 1238 |
struct sched_param sp; |
| 1239 |
fprintf(stderr,"Getting real-time priority\n"); |
| 1240 |
memset(&sp, 0, sizeof(struct sched_param)); |
| 1241 |
sp.sched_priority = sched_get_priority_min(SCHED_FIFO); |
| 1242 |
if (sched_setscheduler(0, SCHED_RR, &sp) == -1) |
| 1243 |
error("Can't get realtime priority\n"); |
| 1244 |
} |
| 1245 |
#endif |
| 1246 |
|
| 1247 |
/* make sure not Cygwin, it doesn't need it */ |
| 1248 |
#if defined(WIN32) && defined(HAVE_WINDOWS_H) |
| 1249 |
/* argument "3" is equivalent to realtime priority class */ |
| 1250 |
win32_set_priority( param.realtime ? 3 : param.w32_priority); |
| 1251 |
#endif |
| 1252 |
|
| 1253 |
/* TODO: There's some memory leaking on fatal safe_exits(). |
| 1254 |
This is a cosmetic issue, though. */ |
| 1255 |
|
| 1256 |
|
| 1257 |
/* Initializing output after the priority stuff, might influence |
| 1258 |
buffer process. */ |
| 1259 |
ao = out123_new(); |
| 1260 |
if(!ao) |
| 1261 |
{ |
| 1262 |
error("Failed to allocate output."); |
| 1263 |
safe_exit(97); |
| 1264 |
} |
| 1265 |
if |
| 1266 |
( 0 |
| 1267 |
|| out123_param_int(ao, OUT123_FLAGS, param.output_flags) |
| 1268 |
|| out123_param_float(ao, OUT123_PRELOAD, param.preload) |
| 1269 |
|| out123_param_int(ao, OUT123_GAIN, param.gain) |
| 1270 |
|| out123_param_int(ao, OUT123_VERBOSE, param.verbose) |
| 1271 |
|| out123_param_string(ao, OUT123_NAME, param.name) |
| 1272 |
|| out123_param_string(ao, OUT123_BINDIR, binpath) |
| 1273 |
|| out123_param_float(ao, OUT123_DEVICEBUFFER, param.device_buffer) |
| 1274 |
) |
| 1275 |
{ |
| 1276 |
error("Error setting output parameters. Do you need a usage reminder?"); |
| 1277 |
safe_exit(98); |
| 1278 |
} |
| 1279 |
check_fatal_output(out123_set_buffer(ao, param.usebuffer*1024)); |
| 1280 |
check_fatal_output(out123_open( ao |
| 1281 |
, param.output_module, param.output_device )); |
| 1282 |
out123_getparam_int(ao, OUT123_PROPFLAGS, &output_propflags); |
| 1283 |
|
| 1284 |
if(!param.remote) |
| 1285 |
prepare_playlist(argc, argv, args_utf8, &pl_utf8); |
| 1286 |
|
| 1287 |
if(param.verbose > 2) |
| 1288 |
fprintf(stderr, "Note: stderr terminal width: %i\n", stderr_width); |
| 1289 |
|
| 1290 |
#if !defined(WIN32) && !defined(GENERIC) |
| 1291 |
/* Remote mode is special... but normal console and terminal-controlled operation needs to catch the SIGINT. |
| 1292 |
For one it serves for track skip when not in terminal control mode. |
| 1293 |
The more important use being a graceful exit, including telling the buffer process what's going on. */ |
| 1294 |
if(!param.remote) |
| 1295 |
INT123_catchsignal(SIGINT, catch_interrupt); |
| 1296 |
/* Need to catch things to exit cleanly, not messing up the terminal. */ |
| 1297 |
INT123_catchsignal(SIGTERM, catch_fatal_term); |
| 1298 |
INT123_catchsignal(SIGPIPE, catch_fatal_pipe); |
| 1299 |
#endif |
| 1300 |
/* Now either check caps myself or query buffer for that. */ |
| 1301 |
if(audio_setup(ao, mh)) |
| 1302 |
{ |
| 1303 |
error("Failed to set up audio output."); |
| 1304 |
safe_exit(7); |
| 1305 |
} |
| 1306 |
|
| 1307 |
if(param.remote) { |
| 1308 |
int ret; |
| 1309 |
ret = control_generic(mh); |
| 1310 |
safe_exit(ret); |
| 1311 |
} |
| 1312 |
{ |
| 1313 |
int term_forced = param.term_ctrl == TRUE; |
| 1314 |
if(param.term_ctrl == MAYBE) |
| 1315 |
param.term_ctrl = term_ctrl_default; |
| 1316 |
if(term_init() && term_forced) |
| 1317 |
{ |
| 1318 |
error("Aborting since explicitly requested terminal control is not available."); |
| 1319 |
safe_exit(99); |
| 1320 |
} |
| 1321 |
} |
| 1322 |
if(APPFLAG(MPG123APP_CONTINUE)) frames_left = param.frame_number; |
| 1323 |
|
| 1324 |
while ((fname = get_next_file())) |
| 1325 |
{ |
| 1326 |
const char *dirname, *filename; |
| 1327 |
int newdir; |
| 1328 |
/* skip_tracks includes the previous one. */ |
| 1329 |
if(skip_tracks) --skip_tracks; |
| 1330 |
if(skip_tracks) |
| 1331 |
{ |
| 1332 |
debug("Skipping this track."); |
| 1333 |
continue; |
| 1334 |
} |
| 1335 |
if(param.delay > 0) |
| 1336 |
{ |
| 1337 |
// How much control do we want here? Jumping around would mean to get out of the |
| 1338 |
// delay phase and just mess everything up. Pause/unpause would be the only |
| 1339 |
// sensible playback controls. Maybe we can enforce that. |
| 1340 |
controlled_drain(); |
| 1341 |
if(param.verbose > 2) fprintf(stderr, "Note: pausing %i seconds before next track.\n", param.delay); |
| 1342 |
#ifdef WIN32 |
| 1343 |
Sleep(param.delay*1000); |
| 1344 |
#else |
| 1345 |
sleep(param.delay); |
| 1346 |
#endif |
| 1347 |
} |
| 1348 |
if(!APPFLAG(MPG123APP_CONTINUE)) frames_left = param.frame_number; |
| 1349 |
term_new_track(); |
| 1350 |
|
| 1351 |
debug1("Going to play %s", strcmp(fname, "-") ? fname : "standard input"); |
| 1352 |
// If a previous track did not cause error, we forget the success to |
| 1353 |
// catch an error in this track. |
| 1354 |
if(got_played > -1) |
| 1355 |
got_played = 0; |
| 1356 |
int open_track_ret = open_track(fname); |
| 1357 |
if(!open_track_ret) |
| 1358 |
got_played = -1; |
| 1359 |
if(intflag || !open_track_ret) |
| 1360 |
{ |
| 1361 |
/* We need the opportunity to cancel in case of --loop -1 . */ |
| 1362 |
if(param.term_ctrl) term_control(mh, ao); |
| 1363 |
else |
| 1364 |
/* No wait for a second interrupt before we started playing. */ |
| 1365 |
if(intflag) break; |
| 1366 |
|
| 1367 |
/* We already interrupted this cycle, start fresh with the next one. */ |
| 1368 |
intflag = FALSE; |
| 1369 |
continue; |
| 1370 |
} |
| 1371 |
|
| 1372 |
if(!param.quiet) fprintf(stderr, "\n"); |
| 1373 |
if(param.index) |
| 1374 |
{ |
| 1375 |
if(param.verbose) fprintf(stderr, "indexing...\r"); |
| 1376 |
if(mpg123_scan(mh) != MPG123_OK) |
| 1377 |
{ |
| 1378 |
error1("indexing failed: %s", mpg123_strerror(mh)); |
| 1379 |
formatcheck(); |
| 1380 |
mpg123_close(mh); |
| 1381 |
continue; |
| 1382 |
} |
| 1383 |
} |
| 1384 |
/* |
| 1385 |
Only trigger a seek if we do not want to start with the first frame. |
| 1386 |
Rationale: Because of libmpg123 sample accuracy, this could cause an unnecessary backwards seek, that even may fail on non-seekable streams. |
| 1387 |
For start frame of 0, we are already at the correct position! |
| 1388 |
*/ |
| 1389 |
framenum = 0; |
| 1390 |
if(param.start_frame > 0) |
| 1391 |
framenum = mpg123_seek_frame(mh, param.start_frame, SEEK_SET); |
| 1392 |
|
| 1393 |
if(APPFLAG(MPG123APP_CONTINUE)) param.start_frame = 0; |
| 1394 |
|
| 1395 |
if(framenum < 0) |
| 1396 |
{ |
| 1397 |
error1("Initial seek failed: %s", mpg123_strerror(mh)); |
| 1398 |
formatcheck(); |
| 1399 |
mpg123_close(mh); |
| 1400 |
continue; |
| 1401 |
} |
| 1402 |
|
| 1403 |
/* Prinout and xterm title need this, possibly independently. */ |
| 1404 |
newdir = split_dir_file(fname ? fname : "standard input", &dirname, &filename); |
| 1405 |
|
| 1406 |
if (!param.quiet) |
| 1407 |
{ |
| 1408 |
size_t plpos; |
| 1409 |
size_t plfill; |
| 1410 |
long plloop; |
| 1411 |
plpos = playlist_pos(&plfill, &plloop); |
| 1412 |
if(newdir) |
| 1413 |
{ |
| 1414 |
fprintf(stderr, "Directory: "); |
| 1415 |
print_outstr(stderr, dirname, 0, stderr_is_term); |
| 1416 |
fprintf(stderr, "\n"); |
| 1417 |
} |
| 1418 |
|
| 1419 |
/* Reminder about terminal usage. */ |
| 1420 |
if(param.term_ctrl) term_hint(); |
| 1421 |
|
| 1422 |
if(param.verbose) |
| 1423 |
{ |
| 1424 |
if(plloop < 0) |
| 1425 |
fprintf(stderr, "Repeating endlessly.\n"); |
| 1426 |
else if(plloop > 1) |
| 1427 |
fprintf( stderr, "Repeating %ld %s.\n" |
| 1428 |
, plloop-1, plloop > 2 ? "times" : "time" ); |
| 1429 |
} |
| 1430 |
fprintf(stderr, "Playing MPEG stream %zu of %zu: ", plpos, plfill); |
| 1431 |
print_outstr(stderr, filename, 0, stderr_is_term); |
| 1432 |
fprintf(stderr, " ...\n"); |
| 1433 |
if(filept->htd.icy_name.fill) |
| 1434 |
{ |
| 1435 |
fprintf(stderr, "ICY-NAME: "); |
| 1436 |
print_outstr(stderr, filept->htd.icy_name.p, 1, stderr_is_term); |
| 1437 |
fprintf(stderr, "\n"); |
| 1438 |
} |
| 1439 |
if(filept->htd.icy_url.fill) |
| 1440 |
{ |
| 1441 |
fprintf(stderr, "ICY-URL: "); |
| 1442 |
print_outstr(stderr, filept->htd.icy_url.p, 1, stderr_is_term); |
| 1443 |
fprintf(stderr, "\n"); |
| 1444 |
} |
| 1445 |
} |
| 1446 |
#if !defined(GENERIC) |
| 1447 |
{ |
| 1448 |
const char *term_type; |
| 1449 |
term_type = getenv("TERM"); |
| 1450 |
if(term_type && param.xterm_title) |
| 1451 |
{ |
| 1452 |
char *titlestring = NULL; |
| 1453 |
outstr(&titlestring, filename, pl_utf8, 1); |
| 1454 |
const char *ts = titlestring ? titlestring : "???"; |
| 1455 |
|
| 1456 |
if(!strncmp(term_type,"xterm",5) || !strncmp(term_type,"rxvt",4)) |
| 1457 |
fprintf(stderr, "\033]0;%s\007", ts); |
| 1458 |
else if(!strncmp(term_type,"screen",6)) |
| 1459 |
fprintf(stderr, "\033k%s\033\\", ts); |
| 1460 |
else if(!strncmp(term_type,"iris-ansi",9)) |
| 1461 |
fprintf(stderr, "\033P1.y %s\033\\\033P3.y%s\033\\", ts, ts); |
| 1462 |
|
| 1463 |
fflush(stderr); /* Paranoia: will the buffer buffer the escapes? */ |
| 1464 |
free(titlestring); |
| 1465 |
} |
| 1466 |
} |
| 1467 |
#endif |
| 1468 |
|
| 1469 |
/* Rethink that SIGINT logic... */ |
| 1470 |
#if !defined(WIN32) && !defined(GENERIC) |
| 1471 |
if(!param.term_ctrl) |
| 1472 |
gettimeofday (&start_time, NULL); |
| 1473 |
#endif |
| 1474 |
|
| 1475 |
while(!intflag) |
| 1476 |
{ |
| 1477 |
int meta; |
| 1478 |
if(param.frame_number > -1) |
| 1479 |
{ |
| 1480 |
debug1("frames left: %li", (long) frames_left); |
| 1481 |
if(!frames_left) |
| 1482 |
{ |
| 1483 |
if(APPFLAG(MPG123APP_CONTINUE)) end_of_files = TRUE; |
| 1484 |
|
| 1485 |
break; |
| 1486 |
} |
| 1487 |
} |
| 1488 |
if(!play_frame()) break; |
| 1489 |
// At least one successful frame makes the whole run successful, unless |
| 1490 |
// a previous run erred. |
| 1491 |
if(!got_played) |
| 1492 |
got_played = 1; |
| 1493 |
if(!param.quiet) |
| 1494 |
{ |
| 1495 |
meta = mpg123_meta_check(mh); |
| 1496 |
if(meta & (MPG123_NEW_ID3|MPG123_NEW_ICY)) |
| 1497 |
{ |
| 1498 |
if(framenum && param.verbose) |
| 1499 |
print_stat(mh,0,ao,0,¶m); |
| 1500 |
if(meta & MPG123_NEW_ID3) print_id3_tag( mh, param.long_id3 |
| 1501 |
, stderr, term_width(STDERR_FILENO) ); |
| 1502 |
if(meta & MPG123_NEW_ICY) print_icy(mh, stderr); |
| 1503 |
} |
| 1504 |
} |
| 1505 |
if(!fresh && param.verbose) |
| 1506 |
{ |
| 1507 |
if(param.verbose > 1 || !(framenum & 0x7)) print_stat(mh,0,ao,1,¶m); |
| 1508 |
} |
| 1509 |
if(!param.term_ctrl) continue; |
| 1510 |
else term_control(mh, ao); |
| 1511 |
} |
| 1512 |
|
| 1513 |
if(!param.smooth && !intflag) |
| 1514 |
controlled_drain(); |
| 1515 |
if(param.verbose) print_stat(mh,0,ao,0,¶m); |
| 1516 |
|
| 1517 |
if(!param.quiet) |
| 1518 |
{ |
| 1519 |
double secs = 0; |
| 1520 |
long frank; |
| 1521 |
fprintf(stderr, "\n"); |
| 1522 |
if(mpg123_getstate(mh, MPG123_FRANKENSTEIN, &frank, NULL) == MPG123_OK && frank) |
| 1523 |
fprintf(stderr, "This was a Frankenstein track.\n"); |
| 1524 |
|
| 1525 |
position_info(mh, 0, ao, NULL, NULL, &secs, NULL, NULL, NULL); |
| 1526 |
fprintf(stderr,"[%d:%02d] Decoding of ", (int)(secs / 60), ((int)secs) % 60); |
| 1527 |
print_outstr(stderr, filename, 0, stderr_is_term); |
| 1528 |
fprintf(stderr," finished.\n"); |
| 1529 |
} |
| 1530 |
else if(param.verbose) fprintf(stderr, "\n"); |
| 1531 |
|
| 1532 |
close_track(); |
| 1533 |
|
| 1534 |
if (intflag) |
| 1535 |
{ |
| 1536 |
if(!skip_or_die(&start_time)) break; |
| 1537 |
|
| 1538 |
intflag = FALSE; |
| 1539 |
|
| 1540 |
if(!param.smooth) |
| 1541 |
out123_drop(ao); |
| 1542 |
} |
| 1543 |
|
| 1544 |
if(end_of_files) break; |
| 1545 |
} /* end of loop over input files */ |
| 1546 |
|
| 1547 |
if(APPFLAG(MPG123APP_CONTINUE)) |
| 1548 |
{ |
| 1549 |
continue_msg("CONTINUE"); |
| 1550 |
} |
| 1551 |
|
| 1552 |
/* Free up memory used by playlist */ |
| 1553 |
if(!param.remote) free_playlist(); |
| 1554 |
|
| 1555 |
safe_exit(got_played < 0 ? 1 : 0); /* That closes output and restores terminal, too. */ |
| 1556 |
return -1; // Should never be reached. |
| 1557 |
} |
| 1558 |
|
| 1559 |
static void print_title(FILE *o) |
| 1560 |
{ |
| 1561 |
fprintf(o, "High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3\n"); |
| 1562 |
fprintf(o, "\tversion %s; written and copyright by Michael Hipp and others\n", PACKAGE_VERSION); |
| 1563 |
fprintf(o, "\tfree software (LGPL) without any warranty but with best wishes\n"); |
| 1564 |
} |
| 1565 |
|
| 1566 |
static void usage(int err) /* print syntax & exit */ |
| 1567 |
{ |
| 1568 |
FILE* o = stdout; |
| 1569 |
if(err) |
| 1570 |
{ |
| 1571 |
o = stderr; |
| 1572 |
fprintf(o, "You made some mistake in program usage... let me briefly remind you:\n\n"); |
| 1573 |
} |
| 1574 |
print_title(o); |
| 1575 |
fprintf(o,"\nusage: %s [option(s)] [file(s) | URL(s) | -]\n", prgName); |
| 1576 |
fprintf(o,"supported options [defaults in brackets]:\n"); |
| 1577 |
fprintf(o," -v increase verbosity level -q quiet (don't print title)\n"); |
| 1578 |
fprintf(o," -t testmode (no output) -s write to stdout\n"); |
| 1579 |
fprintf(o," -w f write output as WAV file\n"); |
| 1580 |
fprintf(o," -k n skip first n frames [0] -n n decode only n frames [all]\n"); |
| 1581 |
fprintf(o," -c check range violations -y DISABLE resync on errors\n"); |
| 1582 |
fprintf(o," -b n output buffer: n Kbytes [0] -f n change scalefactor [%li]\n", param.outscale); |
| 1583 |
fprintf(o," -r n set/force samplerate [auto]\n"); |
| 1584 |
fprintf(o," -o m select output module -a d set audio device\n"); |
| 1585 |
fprintf(o," -2 downsample 1:2 (22 kHz) -4 downsample 1:4 (11 kHz)\n"); |
| 1586 |
fprintf(o," -d n play every n'th frame only -h n play every frame n times\n"); |
| 1587 |
fprintf(o," -0 decode channel 0 (left) only -1 decode channel 1 (right) only\n"); |
| 1588 |
#ifdef NETWORK |
| 1589 |
fprintf(o," -m mix both channels (mono) -p p use HTTP proxy p [$HTTP_PROXY]\n"); |
| 1590 |
#else |
| 1591 |
fprintf(o," -m mix both channels (mono)\n"); |
| 1592 |
#endif |
| 1593 |
#ifdef HAVE_SCHED_SETSCHEDULER |
| 1594 |
fprintf(o," -@ f read filenames/URLs from f -T get realtime priority\n"); |
| 1595 |
#else |
| 1596 |
fprintf(o," -@ f read filenames/URLs from f\n"); |
| 1597 |
#endif |
| 1598 |
fprintf(o," -z shuffle play (with wildcards) -Z random play\n"); |
| 1599 |
fprintf(o," -u a HTTP authentication string -E f Equalizer, data from file\n"); |
| 1600 |
fprintf(o," -C enable control keys --no-gapless not skip junk/padding in mp3s\n"); |
| 1601 |
fprintf(o," -? this help --version print name + version\n"); |
| 1602 |
fprintf(o,"See the manpage "PACKAGE_NAME"(1) or call %s with --longhelp for more parameters and information.\n", prgName); |
| 1603 |
safe_exit(err); |
| 1604 |
} |
| 1605 |
|
| 1606 |
static void want_usage(char* arg, topt *opts) |
| 1607 |
{ |
| 1608 |
usage(0); |
| 1609 |
} |
| 1610 |
|
| 1611 |
static void long_usage(int err) |
| 1612 |
{ |
| 1613 |
mpg123_string *enclist; |
| 1614 |
FILE* o = stdout; |
| 1615 |
if(err) |
| 1616 |
{ |
| 1617 |
o = stderr; |
| 1618 |
fprintf(o, "You made some mistake in program usage... let me remind you:\n\n"); |
| 1619 |
} |
| 1620 |
enclist = audio_enclist(); |
| 1621 |
print_title(o); |
| 1622 |
fprintf(o,"\nusage: %s [option(s)] [file(s) | URL(s) | -]\n", prgName); |
| 1623 |
|
| 1624 |
fprintf(o,"\ninput options\n\n"); |
| 1625 |
fprintf(o," -k <n> --skip <n> skip n frames at beginning\n"); |
| 1626 |
fprintf(o," --skip-id3v2 skip ID3v2 tags without parsing\n"); |
| 1627 |
fprintf(o," -n --frames <n> play only <n> frames of every stream\n"); |
| 1628 |
fprintf(o," --fuzzy Enable fuzzy seeks (guessing byte offsets or using approximate seek points from Xing TOC)\n"); |
| 1629 |
fprintf(o," -y --no-resync DISABLES resync on error (--resync is deprecated)\n"); |
| 1630 |
fprintf(o," -F --no-frankenstein disable support for Frankenstein streams\n"); |
| 1631 |
#if defined(NETWORK) || defined(NET123) |
| 1632 |
fprintf(o," -p <f> --proxy <f> override proxy environemnt variable for plain HTTP\n"); |
| 1633 |
fprintf(o," --network <b> select network backend, available: auto"); |
| 1634 |
const char **nb = net123_backends; |
| 1635 |
while(*nb){ fprintf(o, " %s", *nb++); } |
| 1636 |
fprintf(o, "\n"); |
| 1637 |
fprintf(o," (auto meaning internal code for plain HTTP and the\n"); |
| 1638 |
fprintf(o," first external option for HTTPS)\n"); |
| 1639 |
fprintf(o," -u --auth set auth values for HTTP access\n"); |
| 1640 |
fprintf(o," --auth-file set auth values for HTTP access from given file\n"); |
| 1641 |
fprintf(o," --ignore-mime ignore HTTP MIME types (content-type)\n"); |
| 1642 |
#endif |
| 1643 |
fprintf(o," --no-seekbuffer disable seek buffer\n"); |
| 1644 |
fprintf(o," -@ <f> --list <f> play songs in playlist <f> (plain list, m3u, pls (shoutcast))\n"); |
| 1645 |
fprintf(o," -l <n> --listentry <n> play nth title in playlist; show whole playlist for n < 0\n"); |
| 1646 |
fprintf(o," --continue playlist continuation mode (see man page)\n"); |
| 1647 |
fprintf(o," --loop <n> loop track(s) <n> times, < 0 means infinite loop (not with --random!)\n"); |
| 1648 |
fprintf(o," --keep-open (--remote mode only) keep loaded file open after reaching end\n"); |
| 1649 |
fprintf(o," --timeout <n> Timeout in seconds before declaring a stream dead (if <= 0, wait forever)\n"); |
| 1650 |
fprintf(o," -z --shuffle shuffle song-list before playing\n"); |
| 1651 |
fprintf(o," -Z --random full random play\n"); |
| 1652 |
fprintf(o," --no-icy-meta Do not accept ICY meta data\n"); |
| 1653 |
fprintf(o," -i --index index / scan through the track before playback\n"); |
| 1654 |
fprintf(o," --index-size <n> change size of frame index\n"); |
| 1655 |
fprintf(o," --preframes <n> number of frames to decode in advance after seeking (to keep layer 3 bit reservoir happy)\n"); |
| 1656 |
fprintf(o," --resync-limit <n> Set number of bytes to search for valid MPEG data; <0 means search whole stream.\n"); |
| 1657 |
fprintf(o," --streamdump <f> Dump a copy of input data (as read by libmpg123) to given file.\n"); |
| 1658 |
fprintf(o," --icy-interval <n> Enforce ICY interval in bytes\n"); |
| 1659 |
fprintf(o," (if > 0, for playing a stream dump).\n"); |
| 1660 |
fprintf(o," --ignore-streamlength Ignore header info about length of MPEG streams.\n"); |
| 1661 |
fprintf(o,"\noutput/processing options\n\n"); |
| 1662 |
fprintf(o," -o <o> --output <o> select audio output module\n"); |
| 1663 |
fprintf(o," --list-modules list the available modules\n"); |
| 1664 |
fprintf(o," --list-devices list the available output devices for given output module\n"); |
| 1665 |
fprintf(o," -a <d> --audiodevice <d> select audio device (depending on chosen module)\n"); |
| 1666 |
fprintf(o," -s --stdout write raw audio to stdout (host native format)\n"); |
| 1667 |
fprintf(o," -O <f> --outfile <f> write raw audio to given file (- is stdout)\n"); |
| 1668 |
fprintf(o," -w <f> --wav <f> write samples as WAV file in <f> (- is stdout)\n"); |
| 1669 |
fprintf(o," --au <f> write samples as Sun AU file in <f> (- is stdout)\n"); |
| 1670 |
fprintf(o," --cdr <f> write samples as raw CD audio file in <f> (- is stdout)\n"); |
| 1671 |
fprintf(o," --reopen force close/open on audiodevice\n"); |
| 1672 |
#ifdef OPT_MULTI |
| 1673 |
fprintf(o," --cpu <string> set cpu optimization\n"); |
| 1674 |
fprintf(o," --test-cpu list optimizations possible with cpu and exit\n"); |
| 1675 |
fprintf(o," --list-cpu list builtin optimizations and exit\n"); |
| 1676 |
#endif |
| 1677 |
#ifdef OPT_3DNOW |
| 1678 |
fprintf(o," --test-3dnow display result of 3DNow! autodetect and exit (obsoleted by --cpu)\n"); |
| 1679 |
fprintf(o," --force-3dnow force use of 3DNow! optimized routine (obsoleted by --test-cpu)\n"); |
| 1680 |
fprintf(o," --no-3dnow force use of floating-pointer routine (obsoleted by --cpu)\n"); |
| 1681 |
#endif |
| 1682 |
fprintf(o," -g --gain [DEPRECATED] set audio hardware output gain\n"); |
| 1683 |
fprintf(o," -f <n> --scale <n> scale output samples (soft gain - based on 32768), default=%li)\n", param.outscale); |
| 1684 |
fprintf(o," --rva-mix,\n"); |
| 1685 |
fprintf(o," --rva-radio use RVA2/ReplayGain values for mix/radio mode\n"); |
| 1686 |
fprintf(o," --rva-album,\n"); |
| 1687 |
fprintf(o," --rva-audiophile use RVA2/ReplayGain values for album/audiophile mode\n"); |
| 1688 |
fprintf(o," -0 --left --single0 play only left channel\n"); |
| 1689 |
fprintf(o," -1 --right --single1 play only right channel\n"); |
| 1690 |
fprintf(o," -m --mono --mix mix stereo to mono\n"); |
| 1691 |
fprintf(o," --stereo duplicate mono channel\n"); |
| 1692 |
fprintf(o," -r --rate force a specific audio output rate\n"); |
| 1693 |
fprintf(o," --resample <s> choose resampling mode for forced rate:\n" |
| 1694 |
" NtoM, dirty, fine (default)\n"); |
| 1695 |
fprintf(o," -2 --2to1 2:1 downsampling\n"); |
| 1696 |
fprintf(o," -4 --4to1 4:1 downsampling\n"); |
| 1697 |
fprintf(o," --pitch <value> set pitch (speedup/down, 0 is neutral; 0.05 is 5%%)\n"); |
| 1698 |
fprintf(o," --8bit force 8 bit output\n"); |
| 1699 |
fprintf(o," --float force floating point output (internal precision)\n"); |
| 1700 |
fprintf(o," -e <c> --encoding <c> force a specific encoding (%s)\n" |
| 1701 |
, enclist != NULL ? enclist->p : "OOM!"); |
| 1702 |
fprintf(o," -d n --doublespeed n play only every nth frame\n"); |
| 1703 |
fprintf(o," -h n --halfspeed n play every frame n times\n"); |
| 1704 |
fprintf(o," --equalizer f scales freq. bands acrd. to given file\n"); |
| 1705 |
fprintf(o," --gapless remove padding/junk on mp3s (best with Lame tag)\n"); |
| 1706 |
fprintf(o," This is on by default when libmpg123 supports it.\n"); |
| 1707 |
fprintf(o," --no-gapless disable gapless mode, not remove padding/junk\n"); |
| 1708 |
fprintf(o," --no-infoframe disable parsing of Xing/Lame/VBR/Info frame\n"); |
| 1709 |
fprintf(o," -D n --delay n insert a delay of n seconds before each track\n"); |
| 1710 |
fprintf(o," -o h --headphones (aix/hp/sun) output on headphones\n"); |
| 1711 |
fprintf(o," -o s --speaker (aix/hp/sun) output on speaker\n"); |
| 1712 |
fprintf(o," -o l --lineout (aix/hp/sun) output to lineout\n"); |
| 1713 |
#ifndef NOXFERMEM |
| 1714 |
fprintf(o," -b <n> --buffer <n> set play buffer (\"output cache\")\n"); |
| 1715 |
fprintf(o," --preload <value> fraction of buffer to fill before playback\n"); |
| 1716 |
fprintf(o," --smooth keep buffer over track boundaries\n"); |
| 1717 |
#endif |
| 1718 |
fprintf(o," --devbuffer <s> set device buffer in seconds; <= 0 means default\n"); |
| 1719 |
|
| 1720 |
fprintf(o,"\nmisc options\n\n"); |
| 1721 |
fprintf(o," -t --test only decode, no output (benchmark)\n"); |
| 1722 |
fprintf(o," -c --check count and display clipped samples\n"); |
| 1723 |
fprintf(o," -v[*] --verbose increase verboselevel\n"); |
| 1724 |
fprintf(o," -q --quiet quiet mode\n"); |
| 1725 |
fprintf(o," -C --control enable terminal control keys (else auto detect)\n"); |
| 1726 |
fprintf(o," --no-control disable terminal control keys (disable auto detect)\n"); |
| 1727 |
fprintf(o," --no-visual disable visual enhancements in output (hide cursor,\n" |
| 1728 |
" reverse video), alternative to TERM=dumb\n"); |
| 1729 |
fprintf(o," --ctrlusr1 <c> control key (characer) to map to SIGUSR1\n"); |
| 1730 |
fprintf(o," (default is for stop/start)\n"); |
| 1731 |
fprintf(o," --ctrlusr2 <c> control key (characer) to map to SIGUSR2\n"); |
| 1732 |
fprintf(o," (default is for next track)\n"); |
| 1733 |
#ifndef GENERIC |
| 1734 |
fprintf(o," --title set terminal title to filename\n"); |
| 1735 |
#endif |
| 1736 |
fprintf(o," --presetloop <s> preset loop interval in (fractional) seconds\n"); |
| 1737 |
fprintf(o," --name <n> set instance name (used in various places)\n"); |
| 1738 |
fprintf(o," --long-tag spacy id3 display with every item on a separate line\n"); |
| 1739 |
fprintf(o," --lyrics show lyrics (from ID3v2 USLT frame)\n"); |
| 1740 |
fprintf(o," --utf8 Regardless of environment, print metadata in UTF-8.\n"); |
| 1741 |
fprintf(o," -R --remote generic remote interface\n"); |
| 1742 |
fprintf(o," --remote-err force use of stderr for generic remote interface\n"); |
| 1743 |
#ifdef FIFO |
| 1744 |
fprintf(o," --fifo <path> open a FIFO at <path> for commands instead of stdin\n"); |
| 1745 |
#endif |
| 1746 |
#ifdef HAVE_SETPRIORITY |
| 1747 |
fprintf(o," --aggressive tries to get higher priority (nice)\n"); |
| 1748 |
#endif |
| 1749 |
#if defined (HAVE_SCHED_SETSCHEDULER) || defined (HAVE_WINDOWS_H) |
| 1750 |
fprintf(o," -T --realtime tries to get realtime priority\n"); |
| 1751 |
#endif |
| 1752 |
#ifdef HAVE_WINDOWS_H |
| 1753 |
fprintf(o," --priority <n> use specified process priority\n"); |
| 1754 |
fprintf(o," accepts -2 to 3 as integer arguments\n"); |
| 1755 |
fprintf(o," -2 as idle, 0 as normal and 3 as realtime.\n"); |
| 1756 |
#endif |
| 1757 |
fprintf(o," -? --help give compact help\n"); |
| 1758 |
fprintf(o," --longhelp give this long help listing\n"); |
| 1759 |
fprintf(o," --version give name / version string\n"); |
| 1760 |
fprintf(o," --libversion give version info on mpg123 libraries\n"); |
| 1761 |
|
| 1762 |
fprintf(o,"\nSee the manpage "PACKAGE_NAME"(1) for more information.\n"); |
| 1763 |
mpg123_free_string(enclist); |
| 1764 |
free(enclist); |
| 1765 |
safe_exit(err); |
| 1766 |
} |
| 1767 |
|
| 1768 |
static void want_long_usage(char* arg, topt *opts) |
| 1769 |
{ |
| 1770 |
long_usage(0); |
| 1771 |
} |
| 1772 |
|
| 1773 |
static void give_version(char* arg, topt *opts) |
| 1774 |
{ |
| 1775 |
fprintf(stdout, PACKAGE_NAME " " MPG123_VERSION "\n"); |
| 1776 |
safe_exit(0); |
| 1777 |
} |
| 1778 |
|
| 1779 |
static void give_libversion(char* arg, topt *opts) |
| 1780 |
{ |
| 1781 |
unsigned int pl = 0; |
| 1782 |
unsigned int al = mpg123_libversion(&pl); |
| 1783 |
printf("libmpg123 from mpg123 %s, API version %u, patchlevel %u\n", mpg123_distversion(NULL, NULL, NULL), al, pl); |
| 1784 |
al = out123_libversion(&pl); |
| 1785 |
printf("libout123 from mpg123 %s, API version %u, patchlevel %u\n", out123_distversion(NULL, NULL, NULL), al, pl); |
| 1786 |
al = syn123_libversion(&pl); |
| 1787 |
printf("libsyn123 from mpg123 %s, API version %u, patchlevel %u\n", syn123_distversion(NULL, NULL, NULL), al, pl); |
| 1788 |
safe_exit(0); |
| 1789 |
} |
| 1790 |
|
| 1791 |
void continue_msg(const char *name) |
| 1792 |
{ |
| 1793 |
size_t tot = 0; |
| 1794 |
size_t pos = playlist_pos(&tot, NULL); |
| 1795 |
fprintf( aux_out, "\n[%s] track %zu frame %" PRIiMAX "\n", name |
| 1796 |
, pos, (intmax_t)(tot >= pos ? framenum : 0) ); |
| 1797 |
} |