@@ -79,7 +79,7 @@ struct event_base *evbase_main;
7979static struct event * sig_event ;
8080static int main_exit ;
8181ap2_device_info_t ap2_device_info ;
82- char * gnamed_pipe = NULL ;
82+ mass_named_pipes_t mass_named_pipes = { 0 , 0 } ;
8383
8484static inline void
8585timespec_to_ntp (struct timespec * ts , struct ntp_timestamp * ns )
@@ -144,22 +144,23 @@ usage(char *program)
144144 printf ("\n" );
145145 printf ("Usage: %s [options]\n\n" , program );
146146 printf ("Options:\n" );
147- printf (" --loglevel <number> Log level (0-5)\n" );
148- printf (" --logfile <filename> Log filename. Not supplying this argument will result in logging to stderr only.\n" );
149- printf (" --logdomains <dom,dom..> Log domains\n" );
150- printf (" --config <file> Use <file> as the configuration file\n" );
151- printf (" --name <name> Name of the airplay 2 device. Mandatory in absence of --ntpstart.\n" );
152- printf (" --hostname <hostname> Hostname of AirPlay 2 device. Mandatory in absence of --ntpstart.\n" );
153- printf (" --address <address> IP address to bind to for AirPlay 2 service. Mandatory in absence of --ntpstart.\n" );
154- printf (" --port <port> Port number to bind to for AirPlay 2 service. Mandatory in absence of --ntpstart.\n" );
155- printf (" --txt <txt> txt keyvals returned in mDNS for AirPlay 2 service. Mandatory in absence of --ntpstart.\n" );
156- printf (" --pipe filename of named pipe to read streamed audio. Mandatory in absence of --ntpstart.\n" );
157- printf (" --ntp Print current NTP time and exit.\n" );
158- printf (" --wait Start playback after <wait> milliseconds\n" );
159- printf (" --ntpstart Start playback at NTP <start> + <wait>. Mandatory in absence of --ntpstart.\n" );
160- printf (" --latency Latency to apply in frames\n" );
161- printf (" --volume Initial volume (0-100). Mandatory in absence of --ntpstart.\n" );
162- printf (" -v, --version Display version information and exit\n" );
147+ printf (" --loglevel <number> Log level (0-5)\n" );
148+ printf (" --logfile <filename> Log filename. Not supplying this argument will result in logging to stderr only.\n" );
149+ printf (" --logdomains <dom,dom..> Log domains\n" );
150+ printf (" --config <file> Use <file> as the configuration file\n" );
151+ printf (" --name <name> Name of the airplay 2 device. Mandatory in absence of --ntpstart.\n" );
152+ printf (" --hostname <hostname> Hostname of AirPlay 2 device. Mandatory in absence of --ntpstart.\n" );
153+ printf (" --address <address> IP address to bind to for AirPlay 2 service. Mandatory in absence of --ntpstart.\n" );
154+ printf (" --port <port> Port number to bind to for AirPlay 2 service. Mandatory in absence of --ntpstart.\n" );
155+ printf (" --txt <txt> txt keyvals returned in mDNS for AirPlay 2 service. Mandatory in absence of --ntpstart.\n" );
156+ printf (" --pipe <audio_filename> filename of named pipe to read streamed audio. Mandatory in absence of --ntpstart.\n" );
157+ printf (" --command_pipe <command_filename> filename of named pipe to read commands and metadata. Defaults to <audio_filename>.metadata\n" );
158+ printf (" --ntp Print current NTP time and exit.\n" );
159+ printf (" --wait Start playback after <wait> milliseconds\n" );
160+ printf (" --ntpstart Start playback at NTP <start> + <wait>. Mandatory in absence of --ntpstart.\n" );
161+ printf (" --latency Latency to apply in frames. Not yet implemented.\n" );
162+ printf (" --volume Initial volume (0-100). Mandatory in absence of --ntpstart.\n" );
163+ printf (" -v, --version Display version information and exit\n" );
163164 printf ("\n\n" );
164165 printf ("Available log domains:\n" );
165166 logger_domains ();
@@ -367,24 +368,6 @@ int check_pipe(const char *pipe_path)
367368 return 0 ;
368369}
369370
370- // Check for valid named pipe(s).
371- // @param name the filename of the audio streaming named pipe
372- // @returns 0 on success, -1 on failure
373- static
374- int check_pipes (const char * pipe_path )
375- {
376- if (check_pipe (pipe_path ) == 0 ) {
377- int ret ;
378- char * metadata_path = NULL ;
379-
380- asprintf (& metadata_path , "%s.metadata" , pipe_path );
381- ret = check_pipe (metadata_path );
382- free (metadata_path );
383- return ret ;
384- }
385- return -1 ;
386- }
387-
388371// Create named pipe.
389372// @param name the filename of the named pipe
390373// @returns 0 on success, -1 on failure
@@ -496,6 +479,7 @@ main(int argc, char **argv)
496479 bool mdns_no_cname = true;
497480 bool mdns_no_web = true;
498481 bool mdns_no_mpd = true;
482+ bool metadata_pipe_defaulted = false;
499483 int loglevel = -1 ;
500484 char * logdomains = NULL ;
501485 char * logfile = NULL ;
@@ -539,6 +523,7 @@ main(int argc, char **argv)
539523 { "version" , 0 , NULL , 513 },
540524 { "testrun" , 0 , NULL , 514 }, // Used for CI, not documented to user
541525 { "pipe" , 1 , NULL , 515 },
526+ { "command_pipe" , 1 , NULL , 517 },
542527
543528 { NULL , 0 , NULL , 0 }
544529 };
@@ -637,7 +622,11 @@ main(int argc, char **argv)
637622 break ;
638623
639624 case 515 : // named pipe filename
640- gnamed_pipe = optarg ;
625+ mass_named_pipes .audio_pipe = optarg ;
626+ break ;
627+
628+ case 517 : // command/metadata named pipe filename
629+ mass_named_pipes .metadata_pipe = optarg ;
641630 break ;
642631
643632 default :
@@ -655,7 +644,7 @@ main(int argc, char **argv)
655644 hostname == (char * )NULL ||
656645 address == (char * )NULL ||
657646 txt == (char * )NULL ||
658- gnamed_pipe == (char * )NULL ||
647+ mass_named_pipes . audio_pipe == (char * )NULL ||
659648 ntpstart == 0 ||
660649 volume == 0
661650 )
@@ -702,11 +691,20 @@ main(int argc, char **argv)
702691 remove_pipes (TESTRUN_PIPE );
703692 return EXIT_FAILURE ;
704693 }
705- gnamed_pipe = TESTRUN_PIPE ;
694+ mass_named_pipes . audio_pipe = TESTRUN_PIPE ;
706695 }
707696 else {
708697 // Check that named pipe exists for audio streaming. Metadata one too?
709- ret = check_pipes (gnamed_pipe );
698+ ret = check_pipe (mass_named_pipes .audio_pipe );
699+ if (ret < 0 ) {
700+ return EXIT_FAILURE ;
701+ }
702+ if (!mass_named_pipes .metadata_pipe ) {
703+ // Adopt the default
704+ metadata_pipe_defaulted = true;
705+ asprintf (& mass_named_pipes .metadata_pipe , "%s%s" , mass_named_pipes .audio_pipe , METADATA_NAMED_PIPE_DEFAULT_SUFFIX );
706+ }
707+ ret = check_pipe (mass_named_pipes .metadata_pipe );
710708 if (ret < 0 ) {
711709 return EXIT_FAILURE ;
712710 }
@@ -955,6 +953,10 @@ main(int argc, char **argv)
955953 txt_fail :
956954 if (txt_kv ) keyval_clear (txt_kv );
957955
956+ if (metadata_pipe_defaulted ) {
957+ free (mass_named_pipes .metadata_pipe );
958+ }
959+
958960 DPRINTF (E_LOG , L_MAIN , "Exiting.\n" );
959961 conffile_unload ();
960962 logger_deinit ();
0 commit comments