]> git.ipfire.org Git - thirdparty/shairport-sync.git/blob - audio_dummy.c
Update check_classic_systemd_full.yml
[thirdparty/shairport-sync.git] / audio_dummy.c
1 /*
2 * dummy output driver. This file is part of Shairport.
3 * Copyright (c) James Laird 2013
4 * All rights reserved.
5 *
6 * Modifications for audio synchronisation
7 * and related work, copyright (c) Mike Brady 2014 -- 2022
8 * All rights reserved.
9 *
10 * Permission is hereby granted, free of charge, to any person
11 * obtaining a copy of this software and associated documentation
12 * files (the "Software"), to deal in the Software without
13 * restriction, including without limitation the rights to use,
14 * copy, modify, merge, publish, distribute, sublicense, and/or
15 * sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31 #include "audio.h"
32 #include "common.h"
33 #include <inttypes.h> // for PRId64 and friends
34 #include <stdio.h>
35 #include <sys/time.h>
36 #include <unistd.h>
37
38 static int init(__attribute__((unused)) int argc, __attribute__((unused)) char **argv) { return 0; }
39
40 static void deinit(void) {}
41
42 static void start(int sample_rate, __attribute__((unused)) int sample_format) {
43 debug(1, "dummy audio output started at %d frames per second.", sample_rate);
44 }
45 // clang-format off
46 // Here is a brief explanation of the parameters:
47 // sample_type is 'play_samples_are_untimed' or 'play_samples_are_timed' defined in audio.h.
48 // untimed samples are typically silence used by Shairport Sync itself to set up synchronisation or to fill for missing packets of audio -- the timestamp and playtime are zero.
49 // timed samples come from the client.
50 // timestamp is the RTP timestamp given to the first frame by the client
51 // playtime is when the first frame should to be played. It is given in "local time".
52 // local time is CLOCK_MONOTONIC_RAW if available, or CLOCK_MONOTONIC otherwise, expressed in nanoseconds as an unsigned 64-bit integer (See get_absolute_time_in_ns() in common.c)
53 // clang-format on
54
55 static int play(__attribute__((unused)) void *buf, __attribute__((unused)) int samples,
56 int sample_type, uint32_t timestamp, uint64_t playtime) {
57
58 // sample code using some of the extra information
59 if (sample_type == play_samples_are_timed) {
60 int64_t lead_time = playtime - get_absolute_time_in_ns();
61 debug(2, "leadtime for frame %u is %" PRId64 " nanoseconds, i.e. %f seconds.", timestamp,
62 lead_time, 0.000000001 * lead_time);
63 }
64
65 return 0;
66 }
67
68 static void stop(void) { debug(1, "dummy audio stopped\n"); }
69
70 audio_output audio_dummy = {.name = "dummy",
71 .help = NULL,
72 .init = &init,
73 .deinit = &deinit,
74 .prepare = NULL,
75 .start = &start,
76 .stop = &stop,
77 .is_running = NULL,
78 .flush = NULL,
79 .delay = NULL,
80 .stats = NULL,
81 .play = &play,
82 .volume = NULL,
83 .parameters = NULL,
84 .mute = NULL};