DecoderAPI.hxx 6.09 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2015 The Music Player Daemon Project
3
 * http://www.musicpd.org
Max Kellermann's avatar
Max Kellermann committed
4 5 6 7 8 9 10 11 12 13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
14 15 16 17
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Max Kellermann's avatar
Max Kellermann committed
18 19
 */

20 21 22
/*! \file
 * \brief The MPD Decoder API
 *
Max Kellermann's avatar
Max Kellermann committed
23 24 25 26
 * This is the public API which is used by decoder plugins to
 * communicate with the mpd core.
 */

27 28
#ifndef MPD_DECODER_API_HXX
#define MPD_DECODER_API_HXX
29

30 31
// IWYU pragma: begin_exports

32
#include "check.h"
33 34
#include "DecoderCommand.hxx"
#include "DecoderPlugin.hxx"
35
#include "ReplayGainInfo.hxx"
36
#include "tag/Tag.hxx"
37
#include "AudioFormat.hxx"
38
#include "MixRampInfo.hxx"
39
#include "config/Block.hxx"
40
#include "Chrono.hxx"
41

42 43
// IWYU pragma: end_exports

44 45
#include <stdint.h>

46 47
class Error;

48 49 50
/**
 * Notify the player thread that it has finished initialization and
 * that it has read the song's meta data.
51 52 53 54 55
 *
 * @param decoder the decoder object
 * @param audio_format the audio format which is going to be sent to
 * decoder_data()
 * @param seekable true if the song is seekable
56 57
 * @param duration the total duration of this song; negative if
 * unknown
58
 */
59
void
60
decoder_initialized(Decoder &decoder,
61
		    AudioFormat audio_format,
62
		    bool seekable, SignedSongTime duration);
63

64 65 66 67
/**
 * Determines the pending decoder command.
 *
 * @param decoder the decoder object
68
 * @return the current command, or DecoderCommand::NONE if there is no
69 70
 * command pending
 */
71
gcc_pure
72
DecoderCommand
73
decoder_get_command(Decoder &decoder);
74

75 76 77 78
/**
 * Called by the decoder when it has performed the requested command
 * (dc->command).  This function resets dc->command and wakes up the
 * player thread.
79 80
 *
 * @param decoder the decoder object
81
 */
82
void
83
decoder_command_finished(Decoder &decoder);
84

85 86 87 88 89 90 91
/**
 * Call this when you have received the DecoderCommand::SEEK command.
 *
 * @param decoder the decoder object
 * @return the destination position for the seek in milliseconds
 */
gcc_pure
92 93
SongTime
decoder_seek_time(Decoder &decoder);
94

95 96 97 98 99 100 101 102 103 104
/**
 * Call this when you have received the DecoderCommand::SEEK command.
 *
 * @param decoder the decoder object
 * @return the destination position for the seek in frames
 */
gcc_pure
uint64_t
decoder_seek_where_frame(Decoder &decoder);

105
/**
106
 * Call this instead of decoder_command_finished() when seeking has
107 108 109 110 111
 * failed.
 *
 * @param decoder the decoder object
 */
void
112
decoder_seek_error(Decoder &decoder);
113

114 115 116 117 118 119 120 121
/**
 * Open a new #InputStream and wait until it's ready.  Can get
 * cancelled by DecoderCommand::STOP (returns nullptr without setting
 * #Error).
 */
InputStream *
decoder_open_uri(Decoder &decoder, const char *uri, Error &error);

Max Kellermann's avatar
Max Kellermann committed
122
/**
123 124 125 126 127 128 129 130
 * Blocking read from the input stream.
 *
 * @param decoder the decoder object
 * @param is the input stream to read from
 * @param buffer the destination buffer
 * @param length the maximum number of bytes to read
 * @return the number of bytes read, or 0 if one of the following
 * occurs: end of file; error; command (like SEEK or STOP).
Max Kellermann's avatar
Max Kellermann committed
131
 */
132
size_t
133
decoder_read(Decoder *decoder, InputStream &is,
134
	     void *buffer, size_t length);
Max Kellermann's avatar
Max Kellermann committed
135

136
static inline size_t
137
decoder_read(Decoder &decoder, InputStream &is,
138 139 140 141 142
	     void *buffer, size_t length)
{
	return decoder_read(&decoder, is, buffer, length);
}

143 144 145 146 147 148 149 150 151 152 153
/**
 * Blocking read from the input stream.  Attempts to fill the buffer
 * completely; there is no partial result.
 *
 * @return true on success, false on error or command or not enough
 * data
 */
bool
decoder_read_full(Decoder *decoder, InputStream &is,
		  void *buffer, size_t size);

154 155 156 157 158 159 160 161
/**
 * Skip data on the #InputStream.
 *
 * @return true on success, false on error or command
 */
bool
decoder_skip(Decoder *decoder, InputStream &is, size_t size);

162 163 164 165 166 167 168
/**
 * Sets the time stamp for the next data chunk [seconds].  The MPD
 * core automatically counts it up, and a decoder plugin only needs to
 * use this function if it thinks that adding to the time stamp based
 * on the buffer size won't work.
 */
void
169
decoder_timestamp(Decoder &decoder, double t);
170

Max Kellermann's avatar
Max Kellermann committed
171 172 173 174
/**
 * This function is called by the decoder plugin when it has
 * successfully decoded block of input data.
 *
175 176 177 178 179
 * @param decoder the decoder object
 * @param is an input stream which is buffering while we are waiting
 * for the player
 * @param data the source buffer
 * @param length the number of bytes in the buffer
180
 * @return the current command, or DecoderCommand::NONE if there is no
181
 * command pending
Max Kellermann's avatar
Max Kellermann committed
182
 */
183
DecoderCommand
184
decoder_data(Decoder &decoder, InputStream *is,
185
	     const void *data, size_t length,
186
	     uint16_t kbit_rate);
Max Kellermann's avatar
Max Kellermann committed
187

188 189 190 191 192 193 194 195
static inline DecoderCommand
decoder_data(Decoder &decoder, InputStream &is,
	     const void *data, size_t length,
	     uint16_t kbit_rate)
{
	return decoder_data(decoder, &is, data, length, kbit_rate);
}

196 197 198 199 200 201
/**
 * This function is called by the decoder plugin when it has
 * successfully decoded a tag.
 *
 * @param is an input stream which is buffering while we are waiting
 * for the player
202
 * @param tag the tag to send
203
 * @return the current command, or DecoderCommand::NONE if there is no
204
 * command pending
205
 */
206
DecoderCommand
207 208 209 210 211 212 213
decoder_tag(Decoder &decoder, InputStream *is, Tag &&tag);

static inline DecoderCommand
decoder_tag(Decoder &decoder, InputStream &is, Tag &&tag)
{
	return decoder_tag(decoder, &is, std::move(tag));
}
214

215 216 217
/**
 * Set replay gain values for the following chunks.
 *
Max Kellermann's avatar
Max Kellermann committed
218 219
 * @param replay_gain_info the replay_gain_info object; may be nullptr
 * to invalidate the previous replay gain values
220
 */
221
void
222
decoder_replay_gain(Decoder &decoder,
223
		    const ReplayGainInfo *replay_gain_info);
224

225 226 227 228
/**
 * Store MixRamp tags.
 */
void
229
decoder_mixramp(Decoder &decoder, MixRampInfo &&mix_ramp);
230

Max Kellermann's avatar
Max Kellermann committed
231
#endif