Skip to content

Commit ae7513f

Browse files
authored
Merge pull request #29 from music-assistant/26-specify-file-name-for-metadatacommands-named-pipe-as-a-command-line-argument
Command/Metadata named pipe filename via argument
2 parents 6838bf1 + c679b80 commit ae7513f

File tree

4 files changed

+58
-46
lines changed

4 files changed

+58
-46
lines changed

src/cliap2.c

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct event_base *evbase_main;
7979
static struct event *sig_event;
8080
static int main_exit;
8181
ap2_device_info_t ap2_device_info;
82-
char* gnamed_pipe = NULL;
82+
mass_named_pipes_t mass_named_pipes = {0, 0};
8383

8484
static inline void
8585
timespec_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();

src/cliap2.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef __CLIAP2_H__
22
#define __CLIAP2_H__
33

4+
#define METADATA_NAMED_PIPE_DEFAULT_SUFFIX ".metadata"
5+
46
typedef struct ap2_device_info
57
{
68
const char *name;
@@ -15,4 +17,10 @@ typedef struct ap2_device_info
1517
int volume;
1618
} ap2_device_info_t;
1719

20+
typedef struct mass_named_pipes
21+
{
22+
char *audio_pipe; // receives raw pcm audio to be streamed
23+
char *metadata_pipe; // receives metadata and commands
24+
} mass_named_pipes_t;
25+
1826
#endif /* !__CLIAP2_H__ */

src/mass.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
#define MASS_METADATA_ACTION_KEY "ACTION"
9595

9696
/* from cliap2.c */
97-
extern char* gnamed_pipe;
97+
extern mass_named_pipes_t mass_named_pipes;
9898
extern struct event_base *evbase_main;
9999

100100
/* from player.c */
@@ -1325,7 +1325,7 @@ pipe_metadata_watch_add(void *arg)
13251325
char path[PATH_MAX];
13261326
int ret;
13271327

1328-
ret = snprintf(path, sizeof(path), "%s.metadata", base_path);
1328+
ret = snprintf(path, sizeof(path), "%s", base_path);
13291329
if ((ret < 0) || (ret > sizeof(path)))
13301330
return;
13311331

@@ -1390,9 +1390,9 @@ pipelist_create(void)
13901390
int id;
13911391
int ret;
13921392

1393-
DPRINTF(E_DBG, L_PLAYER, "Adding %s to the pipelist\n", gnamed_pipe);
1393+
DPRINTF(E_DBG, L_PLAYER, "Adding %s to the pipelist\n", mass_named_pipes.audio_pipe);
13941394
head = NULL;
1395-
pipe = pipe_create(gnamed_pipe, 1, PIPE_PCM, pipe_read_cb);
1395+
pipe = pipe_create(mass_named_pipes.audio_pipe, 1, PIPE_PCM, pipe_read_cb);
13961396
pipelist_add(&head, pipe);
13971397

13981398
return head;
@@ -1450,7 +1450,9 @@ setup(struct input_source *source)
14501450
pipe->fd = fd;
14511451
pipe->is_autostarted = (source->id == pipe_autostart_id);
14521452

1453-
worker_execute(pipe_metadata_watch_add, source->path, strlen(source->path) + 1, 0);
1453+
// We override default owntones behaviour and allow specification of the metadata named pipe
1454+
worker_execute(pipe_metadata_watch_add, mass_named_pipes.metadata_pipe, strlen(mass_named_pipes.metadata_pipe) + 1, 0);
1455+
// worker_execute(pipe_metadata_watch_add, source->path, strlen(source->path) + 1, 0);
14541456

14551457
source->input_ctx = pipe;
14561458

src/wrappers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#define AIRPLAY_SERVICE_TYPE "_airplay._tcp"
3636

3737
extern ap2_device_info_t ap2_device_info;
38-
extern char* gnamed_pipe;
38+
extern mass_named_pipes_t mass_named_pipes;
3939

4040
/*
4141
* Wrappers for db.c
@@ -309,7 +309,7 @@ db_queue_add_by_query(struct query_params *qp, char reshuffle, uint32_t item_id,
309309
item->shuffle_pos = 1;
310310
item->data_kind = DATA_KIND_PIPE; // this is all we support for the moment
311311
item->media_kind = MEDIA_KIND_MUSIC; // we only support audio
312-
item->path = gnamed_pipe;
312+
item->path = mass_named_pipes.audio_pipe;
313313
item->bitrate = 0; // I don't think value matters for us.
314314
item->samplerate = cfg_getint(cfg_getsec(cfg, "mass"), "pcm_sample_rate");
315315
item->channels = 2;

0 commit comments

Comments
 (0)