2009-03-13 18:43:16 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003-2009 The Music Player Daemon Project
|
|
|
|
* 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-08-26 08:27:04 +02:00
|
|
|
|
2008-08-26 08:27:05 +02:00
|
|
|
#include "normalize.h"
|
2008-11-02 14:12:52 +01:00
|
|
|
#include "pipe.h"
|
2009-03-06 00:42:01 +01:00
|
|
|
#include "chunk.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
|
|
|
|
2009-01-04 19:09:34 +01:00
|
|
|
char *decoder_get_uri(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);
|
2009-04-25 15:07:22 +02:00
|
|
|
|
2009-11-03 20:02:19 +01:00
|
|
|
return song_get_uri(dc->song);
|
2008-08-26 08:27:07 +02:00
|
|
|
}
|
|
|
|
|
2008-11-24 14:32:53 +01:00
|
|
|
enum decoder_command decoder_get_command(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);
|
2009-04-25 15:07:22 +02:00
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
return dc->command;
|
2008-08-26 08:27:07 +02:00
|
|
|
}
|
|
|
|
|
2008-11-24 14:32:53 +01:00
|
|
|
void decoder_command_finished(G_GNUC_UNUSED 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
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
assert(dc->command != DECODE_COMMAND_NONE);
|
|
|
|
assert(dc->command != DECODE_COMMAND_SEEK ||
|
|
|
|
dc->seek_error || decoder->seeking);
|
|
|
|
assert(dc->pipe != NULL);
|
|
|
|
|
|
|
|
if (dc->command == DECODE_COMMAND_SEEK) {
|
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-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->command == DECODE_COMMAND_SEEK);
|
|
|
|
assert(dc->pipe != NULL);
|
2008-08-26 08:27:07 +02:00
|
|
|
|
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->command == DECODE_COMMAND_SEEK);
|
|
|
|
assert(dc->pipe != NULL);
|
2008-08-26 08:27:07 +02:00
|
|
|
|
2009-10-31 19:22:56 +01:00
|
|
|
dc->seek_error = true;
|
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;
|
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;
|
|
|
|
|
2008-11-03 17:56:41 +01:00
|
|
|
nbytes = input_stream_read(is, buffer, length);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
2008-09-29 15:49:29 +02:00
|
|
|
float data_time, uint16_t bitRate,
|
2008-11-11 15:55:34 +01:00
|
|
|
struct replay_gain_info *replay_gain_info)
|
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);
|
|
|
|
cmd = dc->command;
|
|
|
|
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-03-06 00:42:01 +01:00
|
|
|
data_time, bitRate, &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);
|
|
|
|
|
|
|
|
/* apply replay gain or normalization */
|
|
|
|
|
2009-06-19 09:02:12 +02:00
|
|
|
if (replay_gain_mode != REPLAY_GAIN_OFF)
|
2009-01-17 13:11:10 +01:00
|
|
|
replay_gain_apply(replay_gain_info, dest, nbytes,
|
2009-10-31 19:22:56 +01:00
|
|
|
&dc->out_audio_format);
|
2009-01-17 13:11:10 +01:00
|
|
|
else if (normalizationEnabled)
|
2009-10-31 19:22:56 +01:00
|
|
|
normalizeData(dest, nbytes, &dc->out_audio_format);
|
2009-01-17 13:11:10 +01:00
|
|
|
|
|
|
|
/* 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;
|
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
|
|
|
|
2009-01-03 23:28:51 +01:00
|
|
|
return cmd;
|
2008-11-02 17:02:28 +01:00
|
|
|
}
|