MPD: output/Wrapper.hxx Source File

MPD 0.20.15

Wrapper.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MPD_OUTPUT_WRAPPER_HXX
21 #define MPD_OUTPUT_WRAPPER_HXX
22
23 #include "util/Cast.hxx"
24
25 #include <chrono>
26
27 struct ConfigBlock;
28
29 template<class T>
30 struct AudioOutputWrapper {
31 static T &Cast(AudioOutput &ao) {
32 return ContainerCast(ao, &T::base);
33 }
34
35 static AudioOutput *Init(const ConfigBlock &block) {
36 T *t = T::Create(block);
37 return &t->base;
38 }
39
40 static void Finish(AudioOutput *ao) {
41 T *t = &Cast(*ao);
42 delete t;
43 }
44
45 static void Enable(AudioOutput *ao) {
46 T &t = Cast(*ao);
47 t.Enable();
48 }
49
50 static void Disable(AudioOutput *ao) {
51 T &t = Cast(*ao);
52 t.Disable();
53 }
54
55 static void Open(AudioOutput *ao, AudioFormat &audio_format) {
56 T &t = Cast(*ao);
57 t.Open(audio_format);
58 }
59
60 static void Close(AudioOutput *ao) {
61 T &t = Cast(*ao);
62 t.Close();
63 }
64
65 gcc_pure
66 static std::chrono::steady_clock::duration Delay(AudioOutput *ao) noexcept {
67 T &t = Cast(*ao);
68 return t.Delay();
69 }
70
71 static void SendTag(AudioOutput *ao, const Tag &tag) {
72 T &t = Cast(*ao);
73 t.SendTag(tag);
74 }
75
76 static size_t Play(AudioOutput *ao, const void *chunk, size_t size) {
77 T &t = Cast(*ao);
78 return t.Play(chunk, size);
79 }
80
81 static void Drain(AudioOutput *ao) {
82 T &t = Cast(*ao);
83 t.Drain();
84 }
85
86 static void Cancel(AudioOutput *ao) {
87 T &t = Cast(*ao);
88 t.Cancel();
89 }
90
91 static bool Pause(AudioOutput *ao) {
92 T &t = Cast(*ao);
93 return t.Pause();
94 }
95 };
96
97 #endif
AudioOutputWrapper::Play
static size_t Play(AudioOutput *ao, const void *chunk, size_t size)
Definition: Wrapper.hxx:76
AudioFormat
This structure describes the format of a raw PCM stream.
Definition: AudioFormat.hxx:37
AudioOutput
Definition: Internal.hxx:45
Tag
The meta information about a song file.
Definition: Tag.hxx:34
AudioOutputWrapper::Pause
static bool Pause(AudioOutput *ao)
Definition: Wrapper.hxx:91
AudioOutputWrapper::Close
static void Close(AudioOutput *ao)
Definition: Wrapper.hxx:60
AudioOutputWrapper::Enable
static void Enable(AudioOutput *ao)
Definition: Wrapper.hxx:45
ContainerCast
static C & ContainerCast(A &a, A C::*member)
Cast the given pointer to a struct member to its parent structure.
Definition: Cast.hxx:91
ConfigBlock
Definition: Block.hxx:54
AudioOutputWrapper::SendTag
static void SendTag(AudioOutput *ao, const Tag &tag)
Definition: Wrapper.hxx:71
AudioOutputWrapper::Open
static void Open(AudioOutput *ao, AudioFormat &audio_format)
Definition: Wrapper.hxx:55
AudioOutputWrapper::Cancel
static void Cancel(AudioOutput *ao)
Definition: Wrapper.hxx:86
AudioOutputWrapper::Cast
static T & Cast(AudioOutput &ao)
Definition: Wrapper.hxx:31
Cast.hxx
AudioOutputWrapper::Finish
static void Finish(AudioOutput *ao)
Definition: Wrapper.hxx:40
AudioOutputWrapper::Init
static AudioOutput * Init(const ConfigBlock &block)
Definition: Wrapper.hxx:35
AudioOutputWrapper::Delay
static gcc_pure std::chrono::steady_clock::duration Delay(AudioOutput *ao) noexcept
Definition: Wrapper.hxx:66
AudioOutputWrapper::Drain
static void Drain(AudioOutput *ao)
Definition: Wrapper.hxx:81
AudioOutputWrapper
Definition: Wrapper.hxx:30
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
AudioOutputWrapper::Disable
static void Disable(AudioOutput *ao)
Definition: Wrapper.hxx:50