]> git.ipfire.org Git - thirdparty/shairport-sync.git/blame - audio_stdout.c
Update check_classic_systemd_full.yml
[thirdparty/shairport-sync.git] / audio_stdout.c
CommitLineData
38281dd1 1/*
c65211a2
MB
2 * stdout output driver. This file is part of Shairport Sync.
3 * Copyright (c) Mike Brady 2015
50d96b65 4 *
c65211a2 5 * Based on pipe output driver
38281dd1
MB
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
064bd293
MB
30#include "audio.h"
31#include "common.h"
32#include <errno.h>
38281dd1
MB
33#include <fcntl.h>
34#include <memory.h>
064bd293 35#include <stdio.h>
38281dd1 36#include <stdlib.h>
064bd293 37#include <unistd.h>
38281dd1
MB
38
39static int fd = -1;
14b3fc4d
MB
40static int warned = 0;
41
0cd8a2ce
MB
42static void start(__attribute__((unused)) int sample_rate,
43 __attribute__((unused)) int sample_format) {
44 fd = STDOUT_FILENO;
d6536a8e 45 warned = 0;
0cd8a2ce 46}
38281dd1 47
fd880056
MB
48static int play(void *buf, int samples, __attribute__((unused)) int sample_type,
49 __attribute__((unused)) uint32_t timestamp,
50 __attribute__((unused)) uint64_t playtime) {
8ab4f305 51 char errorstring[1024];
e513e533
MB
52 int rc = write(fd, buf, samples * 4);
53 if ((rc < 0) && (warned == 0)) {
54 strerror_r(errno, (char *)errorstring, 1024);
14b3fc4d 55 warn("Error %d writing to stdout (fd: %d): \"%s\".", errno, fd, errorstring);
8ab4f305
MB
56 warned = 1;
57 }
ea20840d 58 return rc;
8ab4f305 59}
38281dd1
MB
60
61static void stop(void) {
c1f973dd 62 // Do nothing when play stops
38281dd1
MB
63}
64
0cd8a2ce 65static int init(__attribute__((unused)) int argc, __attribute__((unused)) char **argv) {
b7864b4e 66 // set up default values first
ae84366e 67 config.audio_backend_buffer_desired_length = 1.0;
38281dd1 68 config.audio_backend_latency_offset = 0;
e513e533
MB
69
70 // get settings from settings file
b7864b4e
MB
71 // do the "general" audio options. Note, these options are in the "general" stanza!
72 parse_general_audio_options();
38281dd1
MB
73 return 0;
74}
75
76static void deinit(void) {
77 // don't close stdout
78}
79
38281dd1 80audio_output audio_stdout = {.name = "stdout",
552218ab 81 .help = NULL,
064bd293
MB
82 .init = &init,
83 .deinit = &deinit,
83c0405d 84 .prepare = NULL,
064bd293
MB
85 .start = &start,
86 .stop = &stop,
8cabb16f 87 .is_running = NULL,
064bd293
MB
88 .flush = NULL,
89 .delay = NULL,
cd9da86f 90 .stats = NULL,
064bd293
MB
91 .play = &play,
92 .volume = NULL,
93 .parameters = NULL,
94 .mute = NULL};