]> git.ipfire.org Git - thirdparty/shairport-sync.git/blame - audio_pipe.c
Apply command line arguments _after_ sewttings from configuration file
[thirdparty/shairport-sync.git] / audio_pipe.c
CommitLineData
0129db08
JL
1/*
2 * pipe output driver. This file is part of Shairport.
3 * Copyright (c) James Laird 2013
4 * All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27#include <stdio.h>
28#include <unistd.h>
29#include <fcntl.h>
30#include <memory.h>
2e27c885 31#include <stdlib.h>
0129db08
JL
32#include "common.h"
33#include "audio.h"
34
28a5afc9 35static int fd = -1;
0129db08
JL
36
37char *pipename = NULL;
38
39static void start(int sample_rate) {
40 fd = open(pipename, O_WRONLY);
41 if (fd < 0) {
42 perror("open");
43 die("could not open specified pipe for writing");
44 }
45}
46
47static void play(short buf[], int samples) {
2e27c885 48 int ignore = write(fd, buf, samples*4);
0129db08
JL
49}
50
51static void stop(void) {
52 close(fd);
53}
54
e4804a57 55static int init(int argc, char **argv, config_t *cfgp) {
0129db08
JL
56 if (argc != 1)
57 die("bad argument(s) to pipe");
58
59 pipename = strdup(argv[0]);
60
61 // test open pipe so we error on startup if it's going to fail
62 start(44100);
63 stop();
64
65 return 0;
66}
67
68static void deinit(void) {
69 if (fd > 0)
70 close(fd);
71 if (pipename)
72 free(pipename);
73}
74
75static void help(void) {
a38a03ed 76 printf(" pipe takes 1 argument: the name of the FIFO to write to.\n");
0129db08
JL
77}
78
79audio_output audio_pipe = {
80 .name = "pipe",
81 .help = &help,
82 .init = &init,
83 .deinit = &deinit,
84 .start = &start,
85 .stop = &stop,
28a5afc9
MB
86 .flush = NULL,
87 .delay = NULL,
0129db08 88 .play = &play,
a2790fc1
MB
89 .volume = NULL,
90 .parameters = NULL
0129db08 91};