2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2010-01-01 05:55:13 +01:00
|
|
|
* Copyright (C) 2003-2010 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-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2009-02-15 17:48:37 +01:00
|
|
|
#include "decoder_api.h"
|
2008-08-26 08:27:06 +02:00
|
|
|
#include "decoder_internal.h"
|
2008-08-26 08:44:19 +02:00
|
|
|
#include "decoder_control.h"
|
2008-08-26 08:44:38 +02:00
|
|
|
#include "player_control.h"
|
2008-08-26 08:27:06 +02:00
|
|
|
#include "audio.h"
|
2008-10-08 10:49:11 +02:00
|
|
|
#include "song.h"
|
2009-03-06 00:42:03 +01:00
|
|
|
#include "buffer.h"
|
2008-11-02 14:12:52 +01:00
|
|
|
#include "pipe.h"
|
2009-03-06 00:42:01 +01:00
|
|
|
#include "chunk.h"
|
2010-05-08 09:19:44 +02:00
|
|
|
#include "replay_gain_config.h"
|
2008-08-26 08:27:04 +02:00
|
|
|
|
2008-11-24 14:32:53 +01:00
|
|
|
#include <glib.h>
|
2008-10-08 10:49:29 +02:00
|
|
|
|
2009-01-03 14:51:28 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2009-03-01 10:31:47 +01:00
|
|
|
#undef G_LOG_DOMAIN
|
|
|
|
#define G_LOG_DOMAIN "decoder"
|
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
void
|
|
|
|
decoder_initialized(struct decoder *decoder,
|
|
|
|
const struct audio_format *audio_format,
|
|
|
|
bool seekable, float total_time)
|
2008-08-26 08:27:04 +02:00
|
|
|
{
|
2009-10-31 19:22:56 +01:00
|
|
|
struct decoder_control *dc = decoder->dc;
|
2009-11-10 17:57:14 +01:00
|
|
|
struct audio_format_string af_string;
|
2009-10-31 19:22:56 +01:00
|
|
|
|
|
|
|
assert(dc->state == DECODE_STATE_START);
|
|
|
|
assert(dc->pipe != NULL);
|
2008-11-10 15:02:26 +01:00
|
|
|
assert(decoder != NULL);
|
2009-01-03 23:29:45 +01:00
|
|
|
assert(decoder->stream_tag == NULL);
|
|
|
|
assert(decoder->decoder_tag == NULL);
|
2008-11-10 15:02:26 +01:00
|
|
|
assert(!decoder->seeking);
|
2008-10-29 17:29:03 +01:00
|
|
|
assert(audio_format != NULL);
|
2008-11-10 15:02:26 +01:00
|
|
|
assert(audio_format_defined(audio_format));
|
2008-11-21 20:27:30 +01:00
|
|
|
assert(audio_format_valid(audio_format));
|
2008-08-26 08:27:04 +02:00
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
dc->in_audio_format = *audio_format;
|
|
|
|
getOutputAudioFormat(audio_format, &dc->out_audio_format);
|
2008-08-26 08:27:05 +02:00
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
dc->seekable = seekable;
|
|
|
|
dc->total_time = total_time;
|
2008-08-26 08:27:05 +02:00
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
decoder_lock(dc);
|
|
|
|
dc->state = DECODE_STATE_DECODE;
|
|
|
|
decoder_unlock(dc);
|
2009-08-13 23:33:46 +02:00
|
|
|
|
2009-10-31 17:02:12 +01:00
|
|
|
player_lock_signal();
|
2009-03-01 10:31:47 +01:00
|
|
|
|
2009-11-10 17:57:14 +01:00
|
|
|
g_debug("audio_format=%s, seekable=%s",
|
|
|
|
audio_format_to_string(&dc->in_audio_format, &af_string),
|
2009-03-01 10:31:47 +01:00
|
|
|
seekable ? "true" : "false");
|
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
if (!audio_format_equals(&dc->in_audio_format,
|
|
|
|
&dc->out_audio_format))
|
2009-11-10 17:57:14 +01:00
|
|
|
g_debug("converting to %s",
|
|
|
|
audio_format_to_string(&dc->out_audio_format,
|
|
|
|
&af_string));
|
2008-08-26 08:27:04 +02:00
|
|
|
}
|
2008-08-26 08:27:05 +02:00
|
|
|
|
2011-09-21 23:17:34 +02:00
|
|
|
/**
|
|
|
|
* Returns the current decoder command. May return a "virtual"
|
|
|
|
* synthesized command, e.g. to seek to the beginning of the CUE
|
|
|
|
* track.
|
|
|
|
*/
|
|
|
|
G_GNUC_PURE
|
|
|
|
static enum decoder_command
|
|
|
|
decoder_get_virtual_command(struct decoder *decoder)
|
2008-08-26 08:27:07 +02:00
|
|
|
{
|
2009-10-31 19:22:56 +01:00
|
|
|
const struct decoder_control *dc = decoder->dc;
|
|
|
|
assert(dc->pipe != NULL);
|
2009-04-25 15:07:22 +02:00
|
|
|
|
2011-09-21 23:17:34 +02:00
|
|
|
if (decoder->initial_seek_running)
|
|
|
|
return DECODE_COMMAND_SEEK;
|
|
|
|
|
|
|
|
if (decoder->initial_seek_pending) {
|
|
|
|
if (dc->command == DECODE_COMMAND_NONE) {
|
|
|
|
decoder->initial_seek_pending = false;
|
|
|
|
decoder->initial_seek_running = true;
|
|
|
|
return DECODE_COMMAND_SEEK;
|
|
|
|
}
|
|
|
|
|
|
|
|
decoder->initial_seek_pending = false;
|
|
|
|
}
|
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
return dc->command;
|
2008-08-26 08:27:07 +02:00
|
|
|
}
|
|
|
|
|
2011-09-21 23:17:34 +02:00
|
|
|
enum decoder_command
|
|
|
|
decoder_get_command(struct decoder *decoder)
|
|
|
|
{
|
|
|
|
return decoder_get_virtual_command(decoder);
|
|
|
|
}
|
|
|
|
|
2009-12-25 19:47:33 +01:00
|
|
|
void
|
|
|
|
decoder_command_finished(struct decoder *decoder)
|
2008-08-26 08:27:07 +02:00
|
|
|
{
|
2009-10-31 19:22:56 +01:00
|
|
|
struct decoder_control *dc = decoder->dc;
|
2009-08-13 23:33:46 +02:00
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
decoder_lock(dc);
|
2008-08-26 08:27:07 +02:00
|
|
|
|
2011-09-21 23:17:34 +02:00
|
|
|
assert(dc->command != DECODE_COMMAND_NONE ||
|
|
|
|
decoder->initial_seek_running);
|
2009-10-31 19:22:56 +01:00
|
|
|
assert(dc->command != DECODE_COMMAND_SEEK ||
|
2011-09-21 23:17:34 +02:00
|
|
|
decoder->initial_seek_running ||
|
2009-10-31 19:22:56 +01:00
|
|
|
dc->seek_error || decoder->seeking);
|
|
|
|
assert(dc->pipe != NULL);
|
|
|
|
|
2011-09-21 23:17:34 +02:00
|
|
|
if (decoder->initial_seek_running) {
|
|
|
|
assert(!decoder->seeking);
|
|
|
|
assert(decoder->chunk == NULL);
|
|
|
|
assert(music_pipe_empty(dc->pipe));
|
|
|
|
|
|
|
|
decoder->initial_seek_running = false;
|
|
|
|
decoder->timestamp = dc->song->start_ms / 1000.;
|
|
|
|
decoder_unlock(dc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-26 01:10:23 +01:00
|
|
|
if (decoder->seeking) {
|
|
|
|
decoder->seeking = false;
|
|
|
|
|
2008-10-29 17:28:47 +01:00
|
|
|
/* delete frames from the old song position */
|
2009-03-06 00:42:01 +01:00
|
|
|
|
|
|
|
if (decoder->chunk != NULL) {
|
2009-10-31 19:22:56 +01:00
|
|
|
music_buffer_return(dc->buffer, decoder->chunk);
|
2009-03-06 00:42:01 +01:00
|
|
|
decoder->chunk = NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
music_pipe_clear(dc->pipe, dc->buffer);
|
2009-12-25 19:47:33 +01:00
|
|
|
|
|
|
|
decoder->timestamp = dc->seek_where;
|
2009-03-06 00:42:01 +01:00
|
|
|
}
|
2008-10-29 17:28:47 +01:00
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
dc->command = DECODE_COMMAND_NONE;
|
|
|
|
decoder_unlock(dc);
|
2009-08-13 23:33:46 +02:00
|
|
|
|
2009-10-31 17:02:12 +01:00
|
|
|
player_lock_signal();
|
2008-08-26 08:27:07 +02:00
|
|
|
}
|
|
|
|
|
2008-11-24 14:32:53 +01:00
|
|
|
double decoder_seek_where(G_GNUC_UNUSED struct decoder * decoder)
|
2008-08-26 08:27:07 +02:00
|
|
|
{
|
2009-10-31 19:22:56 +01:00
|
|
|
const struct decoder_control *dc = decoder->dc;
|
|
|
|
|
|
|
|
assert(dc->pipe != NULL);
|
2008-08-26 08:27:07 +02:00
|
|
|
|
2011-09-21 23:17:34 +02:00
|
|
|
if (decoder->initial_seek_running)
|
|
|
|
return dc->song->start_ms / 1000.;
|
|
|
|
|
|
|
|
assert(dc->command == DECODE_COMMAND_SEEK);
|
|
|
|
|
2008-10-08 11:03:39 +02:00
|
|
|
decoder->seeking = true;
|
2008-08-26 08:27:14 +02:00
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
return dc->seek_where;
|
2008-08-26 08:27:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void decoder_seek_error(struct decoder * decoder)
|
|
|
|
{
|
2009-10-31 19:22:56 +01:00
|
|
|
struct decoder_control *dc = decoder->dc;
|
|
|
|
|
|
|
|
assert(dc->pipe != NULL);
|
2008-08-26 08:27:07 +02:00
|
|
|
|
2011-10-04 22:07:01 +02:00
|
|
|
if (decoder->initial_seek_running) {
|
2011-09-21 23:17:34 +02:00
|
|
|
/* d'oh, we can't seek to the sub-song start position,
|
|
|
|
what now? - no idea, ignoring the problem for now. */
|
2011-10-04 22:07:01 +02:00
|
|
|
decoder->initial_seek_running = false;
|
2011-09-21 23:17:34 +02:00
|
|
|
return;
|
2011-10-04 22:07:01 +02:00
|
|
|
}
|
2011-09-21 23:17:34 +02:00
|
|
|
|
|
|
|
assert(dc->command == DECODE_COMMAND_SEEK);
|
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
dc->seek_error = true;
|
2009-12-26 01:10:23 +01:00
|
|
|
decoder->seeking = false;
|
|
|
|
|
2008-08-26 08:27:07 +02:00
|
|
|
decoder_command_finished(decoder);
|
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:14 +02:00
|
|
|
size_t decoder_read(struct decoder *decoder,
|
2008-11-03 17:56:41 +01:00
|
|
|
struct input_stream *is,
|
2008-08-26 08:27:14 +02:00
|
|
|
void *buffer, size_t length)
|
|
|
|
{
|
2009-11-01 15:34:12 +01:00
|
|
|
const struct decoder_control *dc =
|
|
|
|
decoder != NULL ? decoder->dc : NULL;
|
2009-11-14 23:53:04 +01:00
|
|
|
GError *error = NULL;
|
2008-08-26 08:27:14 +02:00
|
|
|
size_t nbytes;
|
|
|
|
|
2008-11-11 15:55:28 +01:00
|
|
|
assert(decoder == NULL ||
|
2009-10-31 19:22:56 +01:00
|
|
|
dc->state == DECODE_STATE_START ||
|
|
|
|
dc->state == DECODE_STATE_DECODE);
|
2008-11-03 17:56:41 +01:00
|
|
|
assert(is != NULL);
|
2008-08-26 08:27:14 +02:00
|
|
|
assert(buffer != NULL);
|
|
|
|
|
2008-11-15 19:27:30 +01:00
|
|
|
if (length == 0)
|
|
|
|
return 0;
|
|
|
|
|
2008-10-30 08:38:54 +01:00
|
|
|
while (true) {
|
2008-08-26 08:27:14 +02:00
|
|
|
/* XXX don't allow decoder==NULL */
|
2008-08-26 08:27:14 +02:00
|
|
|
if (decoder != NULL &&
|
2008-11-13 02:06:55 +01:00
|
|
|
/* ignore the SEEK command during initialization,
|
|
|
|
the plugin should handle that after it has
|
|
|
|
initialized successfully */
|
2009-10-31 19:22:56 +01:00
|
|
|
(dc->command != DECODE_COMMAND_SEEK ||
|
|
|
|
(dc->state != DECODE_STATE_START && !decoder->seeking)) &&
|
|
|
|
dc->command != DECODE_COMMAND_NONE)
|
2008-08-26 08:27:14 +02:00
|
|
|
return 0;
|
|
|
|
|
2009-11-14 23:53:04 +01:00
|
|
|
nbytes = input_stream_read(is, buffer, length, &error);
|
|
|
|
|
|
|
|
if (G_UNLIKELY(nbytes == 0 && error != NULL)) {
|
|
|
|
g_warning("%s", error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-03 17:56:41 +01:00
|
|
|
if (nbytes > 0 || input_stream_eof(is))
|
2008-08-26 08:27:14 +02:00
|
|
|
return nbytes;
|
|
|
|
|
|
|
|
/* sleep for a fraction of a second! */
|
|
|
|
/* XXX don't sleep, wait for an event instead */
|
2009-02-19 13:33:03 +01:00
|
|
|
g_usleep(10000);
|
2008-08-26 08:27:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-25 19:47:33 +01:00
|
|
|
void
|
|
|
|
decoder_timestamp(struct decoder *decoder, double t)
|
|
|
|
{
|
|
|
|
assert(decoder != NULL);
|
|
|
|
assert(t >= 0);
|
|
|
|
|
|
|
|
decoder->timestamp = t;
|
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:05 +02:00
|
|
|
/**
|
2009-03-06 00:42:01 +01:00
|
|
|
* Sends a #tag as-is to the music pipe. Flushes the current chunk
|
|
|
|
* (decoder.chunk) if there is one.
|
2008-08-26 08:27:05 +02:00
|
|
|
*/
|
2008-08-26 08:27:07 +02:00
|
|
|
static enum decoder_command
|
2009-03-06 00:42:01 +01:00
|
|
|
do_send_tag(struct decoder *decoder, struct input_stream *is,
|
|
|
|
const struct tag *tag)
|
2008-08-26 08:27:05 +02:00
|
|
|
{
|
2009-03-06 00:42:01 +01:00
|
|
|
struct music_chunk *chunk;
|
2008-08-26 08:27:05 +02:00
|
|
|
|
2009-03-06 00:42:01 +01:00
|
|
|
if (decoder->chunk != NULL) {
|
|
|
|
/* there is a partial chunk - flush it, we want the
|
|
|
|
tag in a new chunk */
|
2009-03-06 00:42:03 +01:00
|
|
|
decoder_flush_chunk(decoder);
|
2009-10-31 17:02:12 +01:00
|
|
|
player_lock_signal();
|
2009-01-03 23:28:51 +01:00
|
|
|
}
|
|
|
|
|
2009-03-06 00:42:01 +01:00
|
|
|
assert(decoder->chunk == NULL);
|
|
|
|
|
2009-03-06 00:42:03 +01:00
|
|
|
chunk = decoder_get_chunk(decoder, is);
|
|
|
|
if (chunk == NULL) {
|
2009-10-31 19:22:56 +01:00
|
|
|
assert(decoder->dc->command != DECODE_COMMAND_NONE);
|
|
|
|
return decoder->dc->command;
|
2009-03-06 00:42:03 +01:00
|
|
|
}
|
|
|
|
|
2009-03-06 00:42:01 +01:00
|
|
|
chunk->tag = tag_dup(tag);
|
2009-01-03 23:28:51 +01:00
|
|
|
return DECODE_COMMAND_NONE;
|
|
|
|
}
|
|
|
|
|
2009-01-03 23:29:45 +01:00
|
|
|
static bool
|
|
|
|
update_stream_tag(struct decoder *decoder, struct input_stream *is)
|
|
|
|
{
|
|
|
|
struct tag *tag;
|
|
|
|
|
2009-04-13 19:25:53 +02:00
|
|
|
tag = is != NULL
|
|
|
|
? input_stream_tag(is)
|
|
|
|
: NULL;
|
|
|
|
if (tag == NULL) {
|
|
|
|
tag = decoder->song_tag;
|
|
|
|
if (tag == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* no stream tag present - submit the song tag
|
|
|
|
instead */
|
|
|
|
decoder->song_tag = NULL;
|
|
|
|
}
|
2009-01-03 23:29:45 +01:00
|
|
|
|
|
|
|
if (decoder->stream_tag != NULL)
|
|
|
|
tag_free(decoder->stream_tag);
|
|
|
|
|
|
|
|
decoder->stream_tag = tag;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:07 +02:00
|
|
|
enum decoder_command
|
2008-10-17 17:53:48 +02:00
|
|
|
decoder_data(struct decoder *decoder,
|
2008-11-03 17:56:41 +01:00
|
|
|
struct input_stream *is,
|
2009-01-17 13:23:12 +01: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
|
|
|
{
|
2009-10-31 19:22:56 +01:00
|
|
|
struct decoder_control *dc = decoder->dc;
|
2009-01-17 13:11:16 +01:00
|
|
|
const char *data = _data;
|
2009-07-23 12:01:03 +02:00
|
|
|
GError *error = NULL;
|
2009-08-13 23:33:46 +02:00
|
|
|
enum decoder_command cmd;
|
2008-08-26 08:27:05 +02:00
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
assert(dc->state == DECODE_STATE_DECODE);
|
|
|
|
assert(dc->pipe != NULL);
|
|
|
|
assert(length % audio_format_frame_size(&dc->in_audio_format) == 0);
|
2008-11-10 15:02:26 +01:00
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
decoder_lock(dc);
|
2011-09-21 23:17:34 +02:00
|
|
|
cmd = decoder_get_virtual_command(decoder);
|
2009-10-31 19:22:56 +01:00
|
|
|
decoder_unlock(dc);
|
2009-08-13 23:33:46 +02:00
|
|
|
|
|
|
|
if (cmd == DECODE_COMMAND_STOP || cmd == DECODE_COMMAND_SEEK ||
|
2008-11-21 20:26:57 +01:00
|
|
|
length == 0)
|
2009-08-13 23:33:46 +02:00
|
|
|
return cmd;
|
2008-11-13 02:42:40 +01:00
|
|
|
|
2009-01-03 23:29:45 +01:00
|
|
|
/* send stream tags */
|
|
|
|
|
|
|
|
if (update_stream_tag(decoder, is)) {
|
|
|
|
if (decoder->decoder_tag != NULL) {
|
|
|
|
/* merge with tag from decoder plugin */
|
|
|
|
struct tag *tag;
|
|
|
|
|
2009-12-07 14:52:48 +01:00
|
|
|
tag = tag_merge(decoder->decoder_tag,
|
|
|
|
decoder->stream_tag);
|
2009-03-06 00:42:01 +01:00
|
|
|
cmd = do_send_tag(decoder, is, tag);
|
2009-01-03 23:29:45 +01:00
|
|
|
tag_free(tag);
|
|
|
|
} else
|
|
|
|
/* send only the stream tag */
|
2009-03-06 00:42:01 +01:00
|
|
|
cmd = do_send_tag(decoder, is, decoder->stream_tag);
|
2009-01-03 23:29:45 +01:00
|
|
|
|
|
|
|
if (cmd != DECODE_COMMAND_NONE)
|
|
|
|
return cmd;
|
2008-11-03 18:24:01 +01:00
|
|
|
}
|
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
if (!audio_format_equals(&dc->in_audio_format, &dc->out_audio_format)) {
|
2009-01-17 13:11:16 +01:00
|
|
|
data = pcm_convert(&decoder->conv_state,
|
2009-10-31 19:22:56 +01:00
|
|
|
&dc->in_audio_format, data, length,
|
|
|
|
&dc->out_audio_format, &length,
|
2009-07-23 12:01:03 +02:00
|
|
|
&error);
|
|
|
|
if (data == NULL) {
|
|
|
|
/* the PCM conversion has failed - stop
|
|
|
|
playback, since we have no better way to
|
|
|
|
bail out */
|
|
|
|
g_warning("%s", error->message);
|
|
|
|
return DECODE_COMMAND_STOP;
|
|
|
|
}
|
2008-08-26 08:27:05 +02:00
|
|
|
}
|
|
|
|
|
2008-11-03 17:56:41 +01:00
|
|
|
while (length > 0) {
|
2009-03-06 00:42:01 +01:00
|
|
|
struct music_chunk *chunk;
|
|
|
|
char *dest;
|
2009-01-17 13:11:10 +01:00
|
|
|
size_t nbytes;
|
2009-03-06 00:42:01 +01:00
|
|
|
bool full;
|
|
|
|
|
2009-03-06 00:42:03 +01:00
|
|
|
chunk = decoder_get_chunk(decoder, is);
|
|
|
|
if (chunk == NULL) {
|
2009-10-31 19:22:56 +01:00
|
|
|
assert(dc->command != DECODE_COMMAND_NONE);
|
|
|
|
return dc->command;
|
2009-03-06 00:42:03 +01:00
|
|
|
}
|
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
dest = music_chunk_write(chunk, &dc->out_audio_format,
|
2009-12-25 23:12:10 +01:00
|
|
|
decoder->timestamp -
|
|
|
|
dc->song->start_ms / 1000.0,
|
|
|
|
kbit_rate, &nbytes);
|
2009-01-17 13:11:10 +01:00
|
|
|
if (dest == NULL) {
|
2009-03-06 00:42:01 +01:00
|
|
|
/* the chunk is full, flush it */
|
2009-03-06 00:42:03 +01:00
|
|
|
decoder_flush_chunk(decoder);
|
2009-10-31 17:02:12 +01:00
|
|
|
player_lock_signal();
|
2009-01-17 13:11:10 +01:00
|
|
|
continue;
|
2008-08-26 08:27:05 +02:00
|
|
|
}
|
2009-01-17 13:11:10 +01:00
|
|
|
|
|
|
|
assert(nbytes > 0);
|
|
|
|
|
|
|
|
if (nbytes > length)
|
|
|
|
nbytes = length;
|
|
|
|
|
|
|
|
/* copy the buffer */
|
|
|
|
|
|
|
|
memcpy(dest, data, nbytes);
|
|
|
|
|
|
|
|
/* expand the music pipe chunk */
|
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
full = music_chunk_expand(chunk, &dc->out_audio_format, nbytes);
|
2009-03-06 00:42:01 +01:00
|
|
|
if (full) {
|
|
|
|
/* the chunk is full, flush it */
|
2009-03-06 00:42:03 +01:00
|
|
|
decoder_flush_chunk(decoder);
|
2009-10-31 17:02:12 +01:00
|
|
|
player_lock_signal();
|
2009-03-06 00:42:01 +01:00
|
|
|
}
|
2009-01-17 13:11:10 +01:00
|
|
|
|
|
|
|
data += nbytes;
|
|
|
|
length -= nbytes;
|
2009-12-25 19:47:33 +01:00
|
|
|
|
|
|
|
decoder->timestamp += (double)nbytes /
|
2010-03-17 18:26:36 +01:00
|
|
|
audio_format_time_to_size(&dc->out_audio_format);
|
2009-12-25 23:12:10 +01:00
|
|
|
|
|
|
|
if (dc->song->end_ms > 0 &&
|
|
|
|
decoder->timestamp >= dc->song->end_ms / 1000.0)
|
|
|
|
/* the end of this range has been reached:
|
|
|
|
stop decoding */
|
|
|
|
return DECODE_COMMAND_STOP;
|
2008-08-26 08:27:05 +02:00
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:07 +02:00
|
|
|
return DECODE_COMMAND_NONE;
|
2008-08-26 08:27:05 +02:00
|
|
|
}
|
2008-11-02 17:02:28 +01:00
|
|
|
|
|
|
|
enum decoder_command
|
2008-11-24 14:32:53 +01:00
|
|
|
decoder_tag(G_GNUC_UNUSED struct decoder *decoder, struct input_stream *is,
|
2008-11-02 17:02:28 +01:00
|
|
|
const struct tag *tag)
|
|
|
|
{
|
2009-12-14 23:22:51 +01:00
|
|
|
G_GNUC_UNUSED const struct decoder_control *dc = decoder->dc;
|
2009-01-03 23:28:51 +01:00
|
|
|
enum decoder_command cmd;
|
2008-11-03 18:24:01 +01:00
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
assert(dc->state == DECODE_STATE_DECODE);
|
|
|
|
assert(dc->pipe != NULL);
|
2009-01-03 23:29:45 +01:00
|
|
|
assert(tag != NULL);
|
|
|
|
|
|
|
|
/* save the tag */
|
|
|
|
|
|
|
|
if (decoder->decoder_tag != NULL)
|
|
|
|
tag_free(decoder->decoder_tag);
|
|
|
|
decoder->decoder_tag = tag_dup(tag);
|
|
|
|
|
|
|
|
/* check for a new stream tag */
|
2008-11-10 15:02:26 +01:00
|
|
|
|
2009-01-03 23:29:45 +01:00
|
|
|
update_stream_tag(decoder, is);
|
2008-11-03 18:24:01 +01:00
|
|
|
|
2009-01-03 23:29:45 +01:00
|
|
|
/* send tag to music pipe */
|
2008-11-02 17:02:28 +01:00
|
|
|
|
2009-01-03 23:29:45 +01:00
|
|
|
if (decoder->stream_tag != NULL) {
|
|
|
|
/* merge with tag from input stream */
|
|
|
|
struct tag *merged;
|
2008-11-03 18:24:01 +01:00
|
|
|
|
2009-01-03 23:29:45 +01:00
|
|
|
merged = tag_merge(decoder->stream_tag, decoder->decoder_tag);
|
2009-03-06 00:42:01 +01:00
|
|
|
cmd = do_send_tag(decoder, is, merged);
|
2009-01-03 23:29:45 +01:00
|
|
|
tag_free(merged);
|
|
|
|
} else
|
|
|
|
/* send only the decoder tag */
|
2009-03-06 00:42:01 +01:00
|
|
|
cmd = do_send_tag(decoder, is, tag);
|
2008-11-03 18:24:01 +01:00
|
|
|
|
2011-09-21 23:17:34 +02:00
|
|
|
if (cmd == DECODE_COMMAND_NONE)
|
|
|
|
cmd = decoder_get_virtual_command(decoder);
|
|
|
|
|
2009-01-03 23:28:51 +01:00
|
|
|
return cmd;
|
2008-11-02 17:02:28 +01:00
|
|
|
}
|
2010-01-03 22:44:23 +01:00
|
|
|
|
2010-05-08 09:19:44 +02:00
|
|
|
float
|
2010-01-03 22:44:23 +01:00
|
|
|
decoder_replay_gain(struct decoder *decoder,
|
|
|
|
const struct replay_gain_info *replay_gain_info)
|
|
|
|
{
|
2010-05-08 09:19:44 +02:00
|
|
|
float return_db = 0;
|
2010-01-03 22:44:23 +01:00
|
|
|
assert(decoder != NULL);
|
|
|
|
|
2010-02-14 17:04:39 +01:00
|
|
|
if (replay_gain_info != NULL) {
|
|
|
|
static unsigned serial;
|
|
|
|
if (++serial == 0)
|
|
|
|
serial = 1;
|
|
|
|
|
2010-05-08 09:19:44 +02:00
|
|
|
if (REPLAY_GAIN_OFF != replay_gain_mode) {
|
|
|
|
return_db = 20.0 * log10f(
|
|
|
|
replay_gain_tuple_scale(
|
2010-05-18 20:39:32 +02:00
|
|
|
&replay_gain_info->tuples[replay_gain_get_real_mode()],
|
2010-05-30 17:05:43 +02:00
|
|
|
replay_gain_preamp, replay_gain_missing_preamp,
|
|
|
|
replay_gain_limit));
|
2010-05-08 09:19:44 +02:00
|
|
|
}
|
|
|
|
|
2010-02-14 17:04:39 +01:00
|
|
|
decoder->replay_gain_info = *replay_gain_info;
|
|
|
|
decoder->replay_gain_serial = serial;
|
|
|
|
|
|
|
|
if (decoder->chunk != NULL) {
|
|
|
|
/* flush the current chunk because the new
|
|
|
|
replay gain values affect the following
|
|
|
|
samples */
|
|
|
|
decoder_flush_chunk(decoder);
|
|
|
|
player_lock_signal();
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
decoder->replay_gain_serial = 0;
|
2010-05-08 09:19:44 +02:00
|
|
|
|
|
|
|
return return_db;
|
2010-01-03 22:44:23 +01:00
|
|
|
}
|
2010-03-21 18:21:47 +01:00
|
|
|
|
|
|
|
void
|
2010-05-08 09:19:44 +02:00
|
|
|
decoder_mixramp(struct decoder *decoder, float replay_gain_db,
|
2010-03-21 18:21:47 +01:00
|
|
|
char *mixramp_start, char *mixramp_end)
|
|
|
|
{
|
|
|
|
assert(decoder != NULL);
|
|
|
|
struct decoder_control *dc = decoder->dc;
|
|
|
|
assert(dc != NULL);
|
|
|
|
|
2010-05-08 09:19:44 +02:00
|
|
|
dc->replay_gain_db = replay_gain_db;
|
2010-03-21 18:21:47 +01:00
|
|
|
dc_mixramp_start(dc, mixramp_start);
|
|
|
|
dc_mixramp_end(dc, mixramp_end);
|
|
|
|
}
|