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:
40 
45  PcmConvert *convert = nullptr;
46 
50  double timestamp = 0;
51 
55  uint64_t absolute_frame = 0;
56 
62 
69  bool initial_seek_running = false;
70 
75  bool seeking = false;
76 
83 
85  Tag *stream_tag = nullptr;
86 
88  Tag *decoder_tag = nullptr;
89 
92 
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;
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
uint64_t absolute_frame
The time stamp of the next data chunk, in PCM frames.
Definition: Bridge.hxx:55
An interface between the decoder plugin and the MPD core.
Definition: Client.hxx:39
This structure describes the format of a raw PCM stream.
Definition: AudioFormat.hxx:37
MusicChunk * GetChunk() noexcept
Returns the current chunk the decoder writes to, or allocates a new chunk if there is none...
Tag * decoder_tag
the last tag received from the decoder plugin
Definition: Bridge.hxx:88
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
The meta information about a song file.
Definition: Tag.hxx:34
A time stamp within a song.
Definition: Chrono.hxx:31
PcmConvert * convert
For converting input data to the configured audio format.
Definition: Bridge.hxx:45
void FlushChunk()
Flushes the current chunk.
void SeekError() override
Call this instead of CommandFinished() when seeking has failed.
A chunk of music data.
Definition: MusicChunk.hxx:43
ReplayGainInfo replay_gain_info
Definition: Bridge.hxx:93
DecoderBridge(DecoderControl &_dc, bool _initial_seek_pending, Tag *_tag)
Definition: Bridge.hxx:107
MusicChunk * current_chunk
the chunk currently being written to
Definition: Bridge.hxx:91
std::exception_ptr error
An error has occurred (in DecoderAPI.cxx), and the plugin will be asked to stop.
Definition: Bridge.hxx:105
DecoderCommand GetCommand() noexcept override
Determines the pending decoder command.
unsigned replay_gain_serial
A positive serial number for checking if replay gain info has changed since the last check...
Definition: Bridge.hxx:99
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...
bool seeking
This flag is set by GetSeekTime(), and checked by CommandFinished().
Definition: Bridge.hxx:75
double timestamp
The time stamp of the next data chunk, in seconds.
Definition: Bridge.hxx:50
size_t Read(InputStream &is, void *buffer, size_t length) override
Blocking read from the input stream.
void SubmitTimestamp(double t) override
Sets the time stamp for the next data chunk [seconds].
void CommandFinished() override
Called by the decoder when it has performed the requested command (dc->command).
std::unique_ptr< InputStream > InputStreamPtr
Definition: Ptr.hxx:25
void SubmitMixRamp(MixRampInfo &&mix_ramp) override
Store MixRamp tags.
bool initial_seek_running
Is the initial seek currently running? During this time, the decoder command is SEEK.
Definition: Bridge.hxx:69
DecoderCommand
A variant of SongTime that is based on a signed integer.
Definition: Chrono.hxx:115
Tag * stream_tag
the last tag received from the stream
Definition: Bridge.hxx:85
DecoderControl & dc
Definition: Bridge.hxx:39
void SubmitReplayGain(const ReplayGainInfo *replay_gain_info) override
Set replay gain values for the following chunks.
DecoderCommand SubmitTag(InputStream *is, Tag &&tag) override
This function is called by the decoder plugin when it has successfully decoded a tag.
Tag * song_tag
The tag from the song object.
Definition: Bridge.hxx:82
#define gcc_pure
Definition: Compiler.h:116
This object is statically allocated (within another struct), and holds buffer allocations and the sta...
Definition: PcmConvert.hxx:40
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...
const Storage const char * uri
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...
SongTime GetSeekTime() noexcept override
Call this when you have received the DecoderCommand::SEEK command.
A bridge between the DecoderClient interface and the MPD core (DecoderControl, MusicPipe etc...
Definition: Bridge.hxx:37
uint64_t GetSeekFrame() noexcept override
Call this when you have received the DecoderCommand::SEEK command.
InputStreamPtr OpenUri(const char *uri) override
Open a new InputStream and wait until it&#39;s ready.