MPD: decoder/Bridge.hxx Source File

MPD 0.20.18

Bridge.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_DECODER_BRIDGE_HXX
21 #define MPD_DECODER_BRIDGE_HXX
22
23 #include "Client.hxx"
24 #include "ReplayGainInfo.hxx"
25
26 #include <exception>
27
28 class PcmConvert;
29 struct MusicChunk;
30 struct DecoderControl;
31 struct Tag;
32
37 class DecoderBridge final : public DecoderClient {
38 public:
39 DecoderControl &dc;
40
45 PcmConvert *convert = nullptr;
46
50 double timestamp = 0;
51
55 uint64_t absolute_frame = 0;
56
61 bool initial_seek_pending;
62
69 bool initial_seek_running = false;
70
75 bool seeking = false;
76
82 Tag *song_tag;
83
85 Tag *stream_tag = nullptr;
86
88 Tag *decoder_tag = nullptr;
89
91 MusicChunk *current_chunk = nullptr;
92
93 ReplayGainInfo replay_gain_info;
94
99 unsigned replay_gain_serial = 0;
100
105 std::exception_ptr error;
106
107 DecoderBridge(DecoderControl &_dc, bool _initial_seek_pending,
108 Tag *_tag)
109 :dc(_dc),
110 initial_seek_pending(_initial_seek_pending),
111 song_tag(_tag) {}
112
113 ~DecoderBridge();
114
121 gcc_pure
122 bool CheckCancelRead() const noexcept;
123
130 MusicChunk *GetChunk() noexcept;
131
137 void FlushChunk();
138
139 /* virtual methods from DecoderClient */
140 void Ready(AudioFormat audio_format,
141 bool seekable, SignedSongTime duration) override;
142 DecoderCommand GetCommand() noexcept override;
143 void CommandFinished() override;
144 SongTime GetSeekTime() noexcept override;
145 uint64_t GetSeekFrame() noexcept override;
146 void SeekError() override;
147 InputStreamPtr OpenUri(const char *uri) override;
148 size_t Read(InputStream &is, void *buffer, size_t length) override;
149 void SubmitTimestamp(double t) override;
150 DecoderCommand SubmitData(InputStream *is,
151 const void *data, size_t length,
152 uint16_t kbit_rate) override;
153 DecoderCommand SubmitTag(InputStream *is, Tag &&tag) override ;
154 void SubmitReplayGain(const ReplayGainInfo *replay_gain_info) override;
155 void SubmitMixRamp(MixRampInfo &&mix_ramp) override;
156
157 private:
162 bool PrepareInitialSeek();
163
169 DecoderCommand GetVirtualCommand() noexcept;
170 DecoderCommand LockGetVirtualCommand() noexcept;
171
176 DecoderCommand DoSendTag(const Tag &tag);
177
178 bool UpdateStreamTag(InputStream *is);
179 };
180
181 #endif
DecoderBridge::absolute_frame
uint64_t absolute_frame
The time stamp of the next data chunk, in PCM frames.
Definition: Bridge.hxx:55
DecoderClient
An interface between the decoder plugin and the MPD core.
Definition: Client.hxx:39
AudioFormat
This structure describes the format of a raw PCM stream.
Definition: AudioFormat.hxx:37
DecoderBridge::GetChunk
MusicChunk * GetChunk() noexcept
Returns the current chunk the decoder writes to, or allocates a new chunk if there is none...
DecoderBridge::decoder_tag
Tag * decoder_tag
the last tag received from the decoder plugin
Definition: Bridge.hxx:88
DecoderBridge::initial_seek_pending
bool initial_seek_pending
Is the initial seek (to the start position of the sub-song) pending, or has it been performed already...
Definition: Bridge.hxx:61
Tag
The meta information about a song file.
Definition: Tag.hxx:34
SongTime
A time stamp within a song.
Definition: Chrono.hxx:31
DecoderBridge::convert
PcmConvert * convert
For converting input data to the configured audio format.
Definition: Bridge.hxx:45
DecoderBridge::~DecoderBridge
~DecoderBridge()
InputStream
Definition: InputStream.hxx:36
DecoderBridge::FlushChunk
void FlushChunk()
Flushes the current chunk.
DecoderBridge::SeekError
void SeekError() override
Call this instead of CommandFinished() when seeking has failed.
DecoderControl
Definition: DecoderControl.hxx:63
MixRampInfo
Definition: MixRampInfo.hxx:28
MusicChunk
A chunk of music data.
Definition: MusicChunk.hxx:43
DecoderBridge::replay_gain_info
ReplayGainInfo replay_gain_info
Definition: Bridge.hxx:93
DecoderBridge::DecoderBridge
DecoderBridge(DecoderControl &_dc, bool _initial_seek_pending, Tag *_tag)
Definition: Bridge.hxx:107
DecoderBridge::current_chunk
MusicChunk * current_chunk
the chunk currently being written to
Definition: Bridge.hxx:91
DecoderBridge::error
std::exception_ptr error
An error has occurred (in DecoderAPI.cxx), and the plugin will be asked to stop.
Definition: Bridge.hxx:105
DecoderBridge::GetCommand
DecoderCommand GetCommand() noexcept override
Determines the pending decoder command.
DecoderBridge::replay_gain_serial
unsigned replay_gain_serial
A positive serial number for checking if replay gain info has changed since the last check...
Definition: Bridge.hxx:99
DecoderBridge::SubmitData
DecoderCommand SubmitData(InputStream *is, const void *data, size_t length, uint16_t kbit_rate) override
This function is called by the decoder plugin when it has successfully decoded block of input data...
Client.hxx
DecoderBridge::seeking
bool seeking
This flag is set by GetSeekTime(), and checked by CommandFinished().
Definition: Bridge.hxx:75
ReplayGainInfo
Definition: ReplayGainInfo.hxx:46
DecoderBridge::timestamp
double timestamp
The time stamp of the next data chunk, in seconds.
Definition: Bridge.hxx:50
DecoderBridge::Read
size_t Read(InputStream &is, void *buffer, size_t length) override
Blocking read from the input stream.
DecoderBridge::SubmitTimestamp
void SubmitTimestamp(double t) override
Sets the time stamp for the next data chunk [seconds].
DecoderBridge::CommandFinished
void CommandFinished() override
Called by the decoder when it has performed the requested command (dc->command).
InputStreamPtr
std::unique_ptr< InputStream > InputStreamPtr
Definition: Ptr.hxx:25
DecoderBridge::SubmitMixRamp
void SubmitMixRamp(MixRampInfo &&mix_ramp) override
Store MixRamp tags.
ReplayGainInfo.hxx
DecoderBridge::initial_seek_running
bool initial_seek_running
Is the initial seek currently running? During this time, the decoder command is SEEK.
Definition: Bridge.hxx:69
DecoderCommand
DecoderCommand
Definition: DecoderCommand.hxx:25
SignedSongTime
A variant of SongTime that is based on a signed integer.
Definition: Chrono.hxx:115
DecoderBridge::stream_tag
Tag * stream_tag
the last tag received from the stream
Definition: Bridge.hxx:85
DecoderBridge::dc
DecoderControl & dc
Definition: Bridge.hxx:39
DecoderBridge::SubmitReplayGain
void SubmitReplayGain(const ReplayGainInfo *replay_gain_info) override
Set replay gain values for the following chunks.
DecoderBridge::SubmitTag
DecoderCommand SubmitTag(InputStream *is, Tag &&tag) override
This function is called by the decoder plugin when it has successfully decoded a tag.
DecoderBridge::song_tag
Tag * song_tag
The tag from the song object.
Definition: Bridge.hxx:82
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
PcmConvert
This object is statically allocated (within another struct), and holds buffer allocations and the sta...
Definition: PcmConvert.hxx:40
DecoderBridge::Ready
void Ready(AudioFormat audio_format, bool seekable, SignedSongTime duration) override
Notify the client that it has finished initialization and that it has read the song&#39;s meta data...
uri
const Storage const char * uri
Definition: DatabasePlaylist.hxx:31
DecoderBridge::CheckCancelRead
gcc_pure bool CheckCancelRead() const noexcept
Should be read operation be cancelled? That is the case when the player thread has sent a command suc...
DecoderBridge::GetSeekTime
SongTime GetSeekTime() noexcept override
Call this when you have received the DecoderCommand::SEEK command.
DecoderBridge
A bridge between the DecoderClient interface and the MPD core (DecoderControl, MusicPipe etc...
Definition: Bridge.hxx:37
DecoderBridge::GetSeekFrame
uint64_t GetSeekFrame() noexcept override
Call this when you have received the DecoderCommand::SEEK command.
DecoderBridge::OpenUri
InputStreamPtr OpenUri(const char *uri) override
Open a new InputStream and wait until it&#39;s ready.