MPD  0.20.6
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 
57 
64  bool initial_seek_running = false;
65 
70  bool seeking = false;
71 
78 
80  Tag *stream_tag = nullptr;
81 
83  Tag *decoder_tag = nullptr;
84 
87 
89 
94  unsigned replay_gain_serial = 0;
95 
100  std::exception_ptr error;
101 
102  DecoderBridge(DecoderControl &_dc, bool _initial_seek_pending,
103  Tag *_tag)
104  :dc(_dc),
105  initial_seek_pending(_initial_seek_pending),
106  song_tag(_tag) {}
107 
108  ~DecoderBridge();
109 
116  gcc_pure
117  bool CheckCancelRead() const;
118 
125  MusicChunk *GetChunk();
126 
132  void FlushChunk();
133 
134  /* virtual methods from DecoderClient */
135  void Ready(AudioFormat audio_format,
136  bool seekable, SignedSongTime duration) override;
137  DecoderCommand GetCommand() override;
138  void CommandFinished() override;
139  SongTime GetSeekTime() override;
140  uint64_t GetSeekFrame() override;
141  void SeekError() override;
142  InputStreamPtr OpenUri(const char *uri) override;
143  size_t Read(InputStream &is, void *buffer, size_t length) override;
144  void SubmitTimestamp(double t) override;
146  const void *data, size_t length,
147  uint16_t kbit_rate) override;
148  DecoderCommand SubmitTag(InputStream *is, Tag &&tag) override ;
149  void SubmitReplayGain(const ReplayGainInfo *replay_gain_info) override;
150  void SubmitMixRamp(MixRampInfo &&mix_ramp) override;
151 
152 private:
157  bool PrepareInitialSeek();
158 
164  DecoderCommand GetVirtualCommand();
165  DecoderCommand LockGetVirtualCommand();
166 
171  DecoderCommand DoSendTag(const Tag &tag);
172 
173  bool UpdateStreamTag(InputStream *is);
174 };
175 
176 #endif
gcc_pure bool CheckCancelRead() const
Should be read operation be cancelled? That is the case when the player thread has sent a command suc...
DecoderCommand GetCommand() override
Determines the pending decoder command.
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()
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:83
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:56
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:88
DecoderBridge(DecoderControl &_dc, bool _initial_seek_pending, Tag *_tag)
Definition: Bridge.hxx:102
MusicChunk * current_chunk
the chunk currently being written to
Definition: Bridge.hxx:86
std::exception_ptr error
An error has occurred (in DecoderAPI.cxx), and the plugin will be asked to stop.
Definition: Bridge.hxx:100
unsigned replay_gain_serial
A positive serial number for checking if replay gain info has changed since the last check...
Definition: Bridge.hxx:94
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:70
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:64
SongTime GetSeekTime() override
Call this when you have received the DecoderCommand::SEEK command.
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:80
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:77
#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
uint64_t GetSeekFrame() override
Call this when you have received the DecoderCommand::SEEK command.
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's meta data...
const Storage const char * uri
A bridge between the DecoderClient interface and the MPD core (DecoderControl, MusicPipe etc...
Definition: Bridge.hxx:37
InputStreamPtr OpenUri(const char *uri) override
Open a new InputStream and wait until it's ready.