]>
Commit | Line | Data |
---|---|---|
cf8401db JL |
1 | /* |
2 | * dummy output driver. This file is part of Shairport. | |
3 | * Copyright (c) James Laird 2013 | |
4 | * All rights reserved. | |
5 | * | |
d7d7bc13 | 6 | * Modifications for audio synchronisation |
fd880056 | 7 | * and related work, copyright (c) Mike Brady 2014 -- 2022 |
d7d7bc13 MB |
8 | * All rights reserved. |
9 | * | |
cf8401db JL |
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 | ||
064bd293 MB |
31 | #include "audio.h" |
32 | #include "common.h" | |
fd880056 | 33 | #include <inttypes.h> // for PRId64 and friends |
a2fb5d21 | 34 | #include <stdio.h> |
a2fb5d21 | 35 | #include <sys/time.h> |
064bd293 | 36 | #include <unistd.h> |
a2fb5d21 | 37 | |
0cd8a2ce | 38 | static int init(__attribute__((unused)) int argc, __attribute__((unused)) char **argv) { return 0; } |
a2fb5d21 | 39 | |
87a0475c | 40 | static void deinit(void) {} |
a2fb5d21 | 41 | |
0cd8a2ce | 42 | static void start(int sample_rate, __attribute__((unused)) int sample_format) { |
9079dea9 | 43 | debug(1, "dummy audio output started at %d frames per second.", sample_rate); |
a2fb5d21 | 44 | } |
fd880056 MB |
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(); | |
a0e99ed5 | 61 | debug(2, "leadtime for frame %u is %" PRId64 " nanoseconds, i.e. %f seconds.", timestamp, |
fd880056 MB |
62 | lead_time, 0.000000001 * lead_time); |
63 | } | |
a2fb5d21 | 64 | |
76c5dd92 MB |
65 | return 0; |
66 | } | |
a2fb5d21 | 67 | |
87a0475c | 68 | static void stop(void) { debug(1, "dummy audio stopped\n"); } |
a2fb5d21 | 69 | |
87a0475c | 70 | audio_output audio_dummy = {.name = "dummy", |
552218ab | 71 | .help = NULL, |
87a0475c MB |
72 | .init = &init, |
73 | .deinit = &deinit, | |
83c0405d | 74 | .prepare = NULL, |
87a0475c MB |
75 | .start = &start, |
76 | .stop = &stop, | |
8cabb16f | 77 | .is_running = NULL, |
87a0475c MB |
78 | .flush = NULL, |
79 | .delay = NULL, | |
cd9da86f | 80 | .stats = NULL, |
87a0475c MB |
81 | .play = &play, |
82 | .volume = NULL, | |
4c70223f MB |
83 | .parameters = NULL, |
84 | .mute = NULL}; |