2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2015-01-01 19:48:13 +01:00
|
|
|
* Copyright (C) 2003-2015 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2008-08-26 08:27:04 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2008-08-26 08:27:04 +02:00
|
|
|
*/
|
|
|
|
|
2009-10-08 15:39:45 +02:00
|
|
|
/*! \file
|
|
|
|
* \brief The MPD Decoder API
|
|
|
|
*
|
2008-08-26 08:27:04 +02:00
|
|
|
* This is the public API which is used by decoder plugins to
|
|
|
|
* communicate with the mpd core.
|
|
|
|
*/
|
|
|
|
|
2013-07-28 13:18:48 +02:00
|
|
|
#ifndef MPD_DECODER_API_HXX
|
|
|
|
#define MPD_DECODER_API_HXX
|
2009-10-08 15:39:45 +02:00
|
|
|
|
2013-11-28 11:50:54 +01:00
|
|
|
// IWYU pragma: begin_exports
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "check.h"
|
2013-07-28 13:18:48 +02:00
|
|
|
#include "DecoderCommand.hxx"
|
|
|
|
#include "DecoderPlugin.hxx"
|
2013-10-02 12:22:12 +02:00
|
|
|
#include "ReplayGainInfo.hxx"
|
2013-09-05 18:22:02 +02:00
|
|
|
#include "tag/Tag.hxx"
|
2013-08-03 21:00:50 +02:00
|
|
|
#include "AudioFormat.hxx"
|
2013-10-26 14:19:34 +02:00
|
|
|
#include "MixRampInfo.hxx"
|
2015-01-21 22:13:44 +01:00
|
|
|
#include "config/Block.hxx"
|
2014-08-26 21:52:28 +02:00
|
|
|
#include "Chrono.hxx"
|
2008-08-26 08:27:06 +02:00
|
|
|
|
2013-11-28 11:50:54 +01:00
|
|
|
// IWYU pragma: end_exports
|
|
|
|
|
2014-08-26 11:27:41 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2014-05-22 11:10:41 +02:00
|
|
|
class Error;
|
|
|
|
|
2008-08-26 08:27:04 +02:00
|
|
|
/**
|
|
|
|
* Notify the player thread that it has finished initialization and
|
|
|
|
* that it has read the song's meta data.
|
2009-10-08 15:39:45 +02:00
|
|
|
*
|
|
|
|
* @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
|
2014-08-29 20:52:39 +02:00
|
|
|
* @param duration the total duration of this song; negative if
|
|
|
|
* unknown
|
2008-08-26 08:27:04 +02:00
|
|
|
*/
|
2009-10-08 15:39:45 +02:00
|
|
|
void
|
2013-10-21 21:12:37 +02:00
|
|
|
decoder_initialized(Decoder &decoder,
|
2013-08-03 21:00:50 +02:00
|
|
|
AudioFormat audio_format,
|
2014-08-29 20:52:39 +02:00
|
|
|
bool seekable, SignedSongTime duration);
|
2008-08-26 08:27:04 +02:00
|
|
|
|
2009-10-08 15:39:45 +02:00
|
|
|
/**
|
|
|
|
* Determines the pending decoder command.
|
|
|
|
*
|
|
|
|
* @param decoder the decoder object
|
2013-09-27 12:11:37 +02:00
|
|
|
* @return the current command, or DecoderCommand::NONE if there is no
|
2009-10-08 15:39:45 +02:00
|
|
|
* command pending
|
|
|
|
*/
|
2013-10-24 19:43:39 +02:00
|
|
|
gcc_pure
|
2013-09-27 12:11:37 +02:00
|
|
|
DecoderCommand
|
2013-10-21 21:12:37 +02:00
|
|
|
decoder_get_command(Decoder &decoder);
|
2008-08-26 08:27:07 +02:00
|
|
|
|
2008-08-26 08:27:07 +02:00
|
|
|
/**
|
|
|
|
* Called by the decoder when it has performed the requested command
|
|
|
|
* (dc->command). This function resets dc->command and wakes up the
|
|
|
|
* player thread.
|
2009-10-08 15:39:45 +02:00
|
|
|
*
|
|
|
|
* @param decoder the decoder object
|
2008-08-26 08:27:07 +02:00
|
|
|
*/
|
2009-10-08 15:39:45 +02:00
|
|
|
void
|
2013-10-21 21:12:37 +02:00
|
|
|
decoder_command_finished(Decoder &decoder);
|
2008-08-26 08:27:07 +02:00
|
|
|
|
2014-08-26 11:02:02 +02:00
|
|
|
/**
|
|
|
|
* 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
|
2014-08-26 21:52:28 +02:00
|
|
|
SongTime
|
|
|
|
decoder_seek_time(Decoder &decoder);
|
2014-08-26 11:02:02 +02:00
|
|
|
|
2014-08-26 11:27:41 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2009-10-08 15:39:45 +02:00
|
|
|
/**
|
2012-02-11 12:36:31 +01:00
|
|
|
* Call this instead of decoder_command_finished() when seeking has
|
2009-10-08 15:39:45 +02:00
|
|
|
* failed.
|
|
|
|
*
|
|
|
|
* @param decoder the decoder object
|
|
|
|
*/
|
|
|
|
void
|
2013-10-21 21:12:37 +02:00
|
|
|
decoder_seek_error(Decoder &decoder);
|
2008-08-26 08:27:07 +02:00
|
|
|
|
2014-05-22 11:10:41 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2008-08-26 08:27:14 +02:00
|
|
|
/**
|
2009-10-08 15:39:45 +02:00
|
|
|
* 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).
|
2008-08-26 08:27:14 +02:00
|
|
|
*/
|
2009-10-08 15:39:45 +02:00
|
|
|
size_t
|
2013-10-23 22:08:59 +02:00
|
|
|
decoder_read(Decoder *decoder, InputStream &is,
|
2009-10-08 15:39:45 +02:00
|
|
|
void *buffer, size_t length);
|
2008-08-26 08:27:14 +02:00
|
|
|
|
2013-10-21 21:12:37 +02:00
|
|
|
static inline size_t
|
2013-10-23 22:08:59 +02:00
|
|
|
decoder_read(Decoder &decoder, InputStream &is,
|
2013-10-21 21:12:37 +02:00
|
|
|
void *buffer, size_t length)
|
|
|
|
{
|
|
|
|
return decoder_read(&decoder, is, buffer, length);
|
|
|
|
}
|
|
|
|
|
2013-12-14 12:43:06 +01:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2013-12-14 12:21:23 +01:00
|
|
|
/**
|
|
|
|
* Skip data on the #InputStream.
|
|
|
|
*
|
|
|
|
* @return true on success, false on error or command
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
decoder_skip(Decoder *decoder, InputStream &is, size_t size);
|
|
|
|
|
2009-12-25 19:47:33 +01:00
|
|
|
/**
|
|
|
|
* 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
|
2013-10-21 21:12:37 +02:00
|
|
|
decoder_timestamp(Decoder &decoder, double t);
|
2009-12-25 19:47:33 +01:00
|
|
|
|
2008-08-26 08:27:05 +02:00
|
|
|
/**
|
|
|
|
* This function is called by the decoder plugin when it has
|
|
|
|
* successfully decoded block of input data.
|
|
|
|
*
|
2009-10-08 15:39:45 +02:00
|
|
|
* @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
|
2013-09-27 12:11:37 +02:00
|
|
|
* @return the current command, or DecoderCommand::NONE if there is no
|
2009-10-08 15:39:45 +02:00
|
|
|
* command pending
|
2008-08-26 08:27:05 +02:00
|
|
|
*/
|
2013-09-27 12:11:37 +02:00
|
|
|
DecoderCommand
|
2013-10-23 22:08:59 +02:00
|
|
|
decoder_data(Decoder &decoder, InputStream *is,
|
2009-10-08 15:39:45 +02:00
|
|
|
const void *data, size_t length,
|
2010-01-03 22:44:23 +01:00
|
|
|
uint16_t kbit_rate);
|
2008-08-26 08:27:05 +02:00
|
|
|
|
2013-10-23 22:08:59 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-11-02 17:02:28 +01:00
|
|
|
/**
|
|
|
|
* 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
|
2009-10-08 15:39:45 +02:00
|
|
|
* @param tag the tag to send
|
2013-09-27 12:11:37 +02:00
|
|
|
* @return the current command, or DecoderCommand::NONE if there is no
|
2009-10-08 15:39:45 +02:00
|
|
|
* command pending
|
2008-11-02 17:02:28 +01:00
|
|
|
*/
|
2013-09-27 12:11:37 +02:00
|
|
|
DecoderCommand
|
2013-10-23 22:08:59 +02:00
|
|
|
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));
|
|
|
|
}
|
2008-11-02 17:02:28 +01:00
|
|
|
|
2010-01-03 22:44:23 +01:00
|
|
|
/**
|
|
|
|
* Set replay gain values for the following chunks.
|
|
|
|
*
|
2015-03-17 11:21:29 +01:00
|
|
|
* @param replay_gain_info the replay_gain_info object; may be nullptr
|
|
|
|
* to invalidate the previous replay gain values
|
2010-01-03 22:44:23 +01:00
|
|
|
*/
|
2013-01-05 02:05:50 +01:00
|
|
|
void
|
2013-10-21 21:12:37 +02:00
|
|
|
decoder_replay_gain(Decoder &decoder,
|
2013-10-25 19:09:22 +02:00
|
|
|
const ReplayGainInfo *replay_gain_info);
|
2010-01-03 22:44:23 +01:00
|
|
|
|
2010-03-21 18:21:47 +01:00
|
|
|
/**
|
|
|
|
* Store MixRamp tags.
|
|
|
|
*/
|
|
|
|
void
|
2013-10-26 14:19:34 +02:00
|
|
|
decoder_mixramp(Decoder &decoder, MixRampInfo &&mix_ramp);
|
2010-03-21 18:21:47 +01:00
|
|
|
|
2008-08-26 08:27:04 +02:00
|
|
|
#endif
|