]> git.ipfire.org Git - thirdparty/shairport-sync.git/blob - audio_stdout.c
Update check_classic_systemd_full.yml
[thirdparty/shairport-sync.git] / audio_stdout.c
1 /*
2 * stdout output driver. This file is part of Shairport Sync.
3 * Copyright (c) Mike Brady 2015
4 *
5 * Based on pipe output driver
6 * Copyright (c) James Laird 2013
7 * All rights reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or
14 * sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
28 */
29
30 #include "audio.h"
31 #include "common.h"
32 #include <errno.h>
33 #include <fcntl.h>
34 #include <memory.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <unistd.h>
38
39 static int fd = -1;
40 static int warned = 0;
41
42 static void start(__attribute__((unused)) int sample_rate,
43 __attribute__((unused)) int sample_format) {
44 fd = STDOUT_FILENO;
45 warned = 0;
46 }
47
48 static int play(void *buf, int samples, __attribute__((unused)) int sample_type,
49 __attribute__((unused)) uint32_t timestamp,
50 __attribute__((unused)) uint64_t playtime) {
51 char errorstring[1024];
52 int rc = write(fd, buf, samples * 4);
53 if ((rc < 0) && (warned == 0)) {
54 strerror_r(errno, (char *)errorstring, 1024);
55 warn("Error %d writing to stdout (fd: %d): \"%s\".", errno, fd, errorstring);
56 warned = 1;
57 }
58 return rc;
59 }
60
61 static void stop(void) {
62 // Do nothing when play stops
63 }
64
65 static int init(__attribute__((unused)) int argc, __attribute__((unused)) char **argv) {
66 // set up default values first
67 config.audio_backend_buffer_desired_length = 1.0;
68 config.audio_backend_latency_offset = 0;
69
70 // get settings from settings file
71 // do the "general" audio options. Note, these options are in the "general" stanza!
72 parse_general_audio_options();
73 return 0;
74 }
75
76 static void deinit(void) {
77 // don't close stdout
78 }
79
80 audio_output audio_stdout = {.name = "stdout",
81 .help = NULL,
82 .init = &init,
83 .deinit = &deinit,
84 .prepare = NULL,
85 .start = &start,
86 .stop = &stop,
87 .is_running = NULL,
88 .flush = NULL,
89 .delay = NULL,
90 .stats = NULL,
91 .play = &play,
92 .volume = NULL,
93 .parameters = NULL,
94 .mute = NULL};