decoder_api.h 5.07 KB
Newer Older
1
/*
2
 * Copyright (C) 2003-2010 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 29
#ifndef MPD_DECODER_API_H
#define MPD_DECODER_API_H

30
#include "check.h"
31
#include "decoder_command.h"
32
#include "decoder_plugin.h"
33
#include "input_stream.h"
34
#include "replay_gain_info.h"
35
#include "tag.h"
36
#include "audio_format.h"
37
#include "conf.h"
38

39
#include <stdbool.h>
40

41 42 43
/**
 * Notify the player thread that it has finished initialization and
 * that it has read the song's meta data.
44 45 46 47 48 49
 *
 * @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
 * @param total_time the total number of seconds in this song; -1 if unknown
50
 */
51 52 53 54
void
decoder_initialized(struct decoder *decoder,
		    const struct audio_format *audio_format,
		    bool seekable, float total_time);
55

56 57 58 59 60 61 62 63 64
/**
 * Determines the pending decoder command.
 *
 * @param decoder the decoder object
 * @return the current command, or DECODE_COMMAND_NONE if there is no
 * command pending
 */
enum decoder_command
decoder_get_command(struct decoder *decoder);
65

66 67 68 69
/**
 * Called by the decoder when it has performed the requested command
 * (dc->command).  This function resets dc->command and wakes up the
 * player thread.
70 71
 *
 * @param decoder the decoder object
72
 */
73 74
void
decoder_command_finished(struct decoder *decoder);
75

76 77 78 79 80 81 82 83
/**
 * Call this when you have received the DECODE_COMMAND_SEEK command.
 *
 * @param decoder the decoder object
 * @return the destination position for the week
 */
double
decoder_seek_where(struct decoder *decoder);
84

85 86 87 88 89 90 91 92
/**
 * Call this right before decoder_command_finished() when seeking has
 * failed.
 *
 * @param decoder the decoder object
 */
void
decoder_seek_error(struct decoder *decoder);
93

Max Kellermann's avatar
Max Kellermann committed
94
/**
95 96 97 98 99 100 101 102
 * 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
103
 */
104 105 106
size_t
decoder_read(struct decoder *decoder, struct input_stream *is,
	     void *buffer, size_t length);
Max Kellermann's avatar
Max Kellermann committed
107

108 109 110 111 112 113 114 115 116
/**
 * 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
decoder_timestamp(struct decoder *decoder, double t);

Max Kellermann's avatar
Max Kellermann committed
117 118 119 120
/**
 * This function is called by the decoder plugin when it has
 * successfully decoded block of input data.
 *
121 122 123 124 125 126 127
 * @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
 * @return the current command, or DECODE_COMMAND_NONE if there is no
 * command pending
Max Kellermann's avatar
Max Kellermann committed
128
 */
129
enum decoder_command
130 131
decoder_data(struct decoder *decoder, struct input_stream *is,
	     const void *data, size_t length,
132
	     uint16_t kbit_rate);
Max Kellermann's avatar
Max Kellermann committed
133

134 135 136 137
/**
 * This function is called by the decoder plugin when it has
 * successfully decoded a tag.
 *
138
 * @param decoder the decoder object
139 140
 * @param is an input stream which is buffering while we are waiting
 * for the player
141 142 143
 * @param tag the tag to send
 * @return the current command, or DECODE_COMMAND_NONE if there is no
 * command pending
144 145 146 147 148
 */
enum decoder_command
decoder_tag(struct decoder *decoder, struct input_stream *is,
	    const struct tag *tag);

149 150 151 152 153 154
/**
 * Set replay gain values for the following chunks.
 *
 * @param decoder the decoder object
 * @param rgi the replay_gain_info object; may be NULL to invalidate
 * the previous replay gain values
155
 * @return the replay gain adjustment used
156
 */
157
float
158 159 160
decoder_replay_gain(struct decoder *decoder,
		    const struct replay_gain_info *replay_gain_info);

161 162 163 164
/**
 * Store MixRamp tags.
 *
 * @param decoder the decoder object
165
 * @param replay_gain_db the ReplayGain adjustment used for this song
166 167 168 169
 * @param mixramp_start the mixramp_start tag; may be NULL to invalidate
 * @param mixramp_end the mixramp_end tag; may be NULL to invalidate
 */
void
170
decoder_mixramp(struct decoder *decoder, float replay_gain_db,
171 172
		char *mixramp_start, char *mixramp_end);

Max Kellermann's avatar
Max Kellermann committed
173
#endif