X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/c593cf7c8a1ea63fc107b810bdb167487f71380e..a7e9570adf37c18f12f6b1dfed0184b70343575e:/clients/playrtp.c diff --git a/clients/playrtp.c b/clients/playrtp.c index 1be801f..0b5bc04 100644 --- a/clients/playrtp.c +++ b/clients/playrtp.c @@ -76,6 +76,7 @@ #include "vector.h" #include "heap.h" #include "timeval.h" +#include "client.h" #include "playrtp.h" #define readahead linux_headers_are_borked @@ -161,9 +162,9 @@ pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; /** @brief Condition variable signalled whenever @ref packets is changed */ pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -#if API_ALSA +#if HAVE_ALSA_ASOUNDLIB_H # define DEFAULT_BACKEND playrtp_alsa -#elif HAVE_SYS_SOUNDCARD_H +#elif HAVE_SYS_SOUNDCARD_H || EMPEG_HOST # define DEFAULT_BACKEND playrtp_oss #elif HAVE_COREAUDIO_AUDIOHARDWARE_H # define DEFAULT_BACKEND playrtp_coreaudio @@ -186,15 +187,16 @@ static const struct option options[] = { { "buffer", required_argument, 0, 'b' }, { "rcvbuf", required_argument, 0, 'R' }, { "multicast", required_argument, 0, 'M' }, -#if HAVE_SYS_SOUNDCARD_H +#if HAVE_SYS_SOUNDCARD_H || EMPEG_HOST { "oss", no_argument, 0, 'o' }, #endif -#if API_ALSA +#if HAVE_ALSA_ASOUNDLIB_H { "alsa", no_argument, 0, 'a' }, #endif #if HAVE_COREAUDIO_AUDIOHARDWARE_H { "core-audio", no_argument, 0, 'c' }, #endif + { "config", required_argument, 0, 'C' }, { 0, 0, 0, 0 } }; @@ -407,10 +409,11 @@ static void help(void) { " --max, -x FRAMES Buffer maximum size\n" " --rcvbuf, -R BYTES Socket receive buffer size\n" " --multicast, -M GROUP Join multicast group\n" -#if API_ALSA + " --config, -C PATH Set configuration file\n" +#if HAVE_ALSA_ASOUNDLIB_H " --alsa, -a Use ALSA to play audio\n" #endif -#if HAVE_SYS_SOUNDCARD_H +#if HAVE_SYS_SOUNDCARD_H || EMPEG_HOST " --oss, -o Use OSS to play audio\n" #endif #if HAVE_COREAUDIO_AUDIOHARDWARE_H @@ -440,6 +443,8 @@ int main(int argc, char **argv) { char *multicast_group = 0; struct ip_mreq mreq; struct ipv6_mreq mreq6; + disorder_client *c; + char *address, *port; static const struct addrinfo prefs = { AI_PASSIVE, @@ -454,7 +459,7 @@ int main(int argc, char **argv) { mem_init(); if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); - while((n = getopt_long(argc, argv, "hVdD:m:b:x:L:R:M:aoc", options, 0)) >= 0) { + while((n = getopt_long(argc, argv, "hVdD:m:b:x:L:R:M:aocC:", options, 0)) >= 0) { switch(n) { case 'h': help(); case 'V': version(); @@ -466,31 +471,45 @@ int main(int argc, char **argv) { case 'L': logfp = fopen(optarg, "w"); break; case 'R': target_rcvbuf = atoi(optarg); break; case 'M': multicast_group = optarg; break; -#if API_ALSA +#if HAVE_ALSA_ASOUNDLIB_H case 'a': backend = playrtp_alsa; break; #endif -#if 0 -#if HAVE_SYS_SOUNDCARD_H +#if HAVE_SYS_SOUNDCARD_H || EMPEG_HOST case 'o': backend = playrtp_oss; break; #endif #if HAVE_COREAUDIO_AUDIOHARDWARE_H case 'c': backend = playrtp_coreaudio; break; #endif -#endif + case 'C': configfile = optarg; break; default: fatal(0, "invalid option"); } } + if(config_read(0)) fatal(0, "cannot read configuration"); if(!maxbuffer) maxbuffer = 4 * readahead; argc -= optind; argv += optind; - if(argc < 1 || argc > 2) - fatal(0, "usage: disorder-playrtp [OPTIONS] ADDRESS [PORT]"); - sl.n = argc; - sl.s = argv; + switch(argc) { + case 0: + case 1: + if(!(c = disorder_new(1))) exit(EXIT_FAILURE); + if(disorder_connect(c)) exit(EXIT_FAILURE); + if(disorder_rtp_address(c, &address, &port)) exit(EXIT_FAILURE); + sl.n = 1; + sl.s = &port; + /* set multicast_group if address is a multicast address */ + break; + case 2: + sl.n = argc; + sl.s = argv; + break; + default: + fatal(0, "usage: disorder-playrtp [OPTIONS] [ADDRESS [PORT]]"); + } /* Listen for inbound audio data */ if(!(res = get_address(&sl, &prefs, &sockname))) exit(1); + info("listening on %s", sockname); if((rtpfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0)