2009-02-25 17:09:09 +01:00
|
|
|
/*
|
2011-01-29 10:13:54 +01:00
|
|
|
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
2009-02-25 17:09:09 +01:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* 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.
|
2009-02-25 17:09:09 +01:00
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2009-02-25 17:09:09 +01:00
|
|
|
#include "decoder_list.h"
|
|
|
|
#include "decoder_api.h"
|
2009-12-14 22:53:13 +01:00
|
|
|
#include "input_init.h"
|
2009-02-25 17:09:09 +01:00
|
|
|
#include "input_stream.h"
|
|
|
|
#include "audio_format.h"
|
|
|
|
#include "pcm_volume.h"
|
2009-11-01 15:44:56 +01:00
|
|
|
#include "idle.h"
|
2010-05-20 07:17:20 +02:00
|
|
|
#include "stdbin.h"
|
2009-02-25 17:09:09 +01:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2009-12-14 21:26:43 +01:00
|
|
|
static void
|
|
|
|
my_log_func(const gchar *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level,
|
|
|
|
const gchar *message, G_GNUC_UNUSED gpointer user_data)
|
|
|
|
{
|
|
|
|
if (log_domain != NULL)
|
|
|
|
g_printerr("%s: %s\n", log_domain, message);
|
|
|
|
else
|
|
|
|
g_printerr("%s\n", message);
|
|
|
|
}
|
|
|
|
|
2009-11-01 15:44:56 +01:00
|
|
|
/**
|
|
|
|
* No-op dummy.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
idle_add(G_GNUC_UNUSED unsigned flags)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-02-25 17:09:09 +01:00
|
|
|
/**
|
|
|
|
* No-op dummy.
|
|
|
|
*/
|
2009-03-02 09:42:16 +01:00
|
|
|
bool
|
2009-02-25 17:09:09 +01:00
|
|
|
pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED int length,
|
|
|
|
G_GNUC_UNUSED const struct audio_format *format,
|
|
|
|
G_GNUC_UNUSED int volume)
|
|
|
|
{
|
2009-03-02 09:42:16 +01:00
|
|
|
return true;
|
2009-02-25 17:09:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct decoder {
|
|
|
|
const char *uri;
|
|
|
|
|
|
|
|
const struct decoder_plugin *plugin;
|
|
|
|
|
|
|
|
bool initialized;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
decoder_initialized(struct decoder *decoder,
|
|
|
|
const struct audio_format *audio_format,
|
|
|
|
G_GNUC_UNUSED bool seekable,
|
|
|
|
G_GNUC_UNUSED float total_time)
|
|
|
|
{
|
2009-11-10 17:57:14 +01:00
|
|
|
struct audio_format_string af_string;
|
|
|
|
|
2009-02-25 17:09:09 +01:00
|
|
|
assert(!decoder->initialized);
|
|
|
|
assert(audio_format_valid(audio_format));
|
|
|
|
|
2009-11-10 17:57:14 +01:00
|
|
|
g_printerr("audio_format=%s\n",
|
|
|
|
audio_format_to_string(audio_format, &af_string));
|
2009-02-25 17:09:09 +01:00
|
|
|
|
|
|
|
decoder->initialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum decoder_command
|
|
|
|
decoder_get_command(G_GNUC_UNUSED struct decoder *decoder)
|
|
|
|
{
|
|
|
|
return DECODE_COMMAND_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void decoder_command_finished(G_GNUC_UNUSED struct decoder *decoder)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
double decoder_seek_where(G_GNUC_UNUSED struct decoder *decoder)
|
|
|
|
{
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void decoder_seek_error(G_GNUC_UNUSED struct decoder *decoder)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
decoder_read(G_GNUC_UNUSED struct decoder *decoder,
|
|
|
|
struct input_stream *is,
|
|
|
|
void *buffer, size_t length)
|
|
|
|
{
|
2009-11-14 23:53:04 +01:00
|
|
|
return input_stream_read(is, buffer, length, NULL);
|
2009-02-25 17:09:09 +01:00
|
|
|
}
|
|
|
|
|
2009-12-25 19:47:33 +01:00
|
|
|
void
|
|
|
|
decoder_timestamp(G_GNUC_UNUSED struct decoder *decoder,
|
|
|
|
G_GNUC_UNUSED double t)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-02-25 17:09:09 +01:00
|
|
|
enum decoder_command
|
|
|
|
decoder_data(G_GNUC_UNUSED struct decoder *decoder,
|
|
|
|
G_GNUC_UNUSED struct input_stream *is,
|
|
|
|
const void *data, size_t datalen,
|
2010-01-03 22:44:23 +01:00
|
|
|
G_GNUC_UNUSED uint16_t kbit_rate)
|
2009-02-25 17:09:09 +01:00
|
|
|
{
|
|
|
|
write(1, data, datalen);
|
|
|
|
return DECODE_COMMAND_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum decoder_command
|
|
|
|
decoder_tag(G_GNUC_UNUSED struct decoder *decoder,
|
|
|
|
G_GNUC_UNUSED struct input_stream *is,
|
|
|
|
G_GNUC_UNUSED const struct tag *tag)
|
|
|
|
{
|
|
|
|
return DECODE_COMMAND_NONE;
|
|
|
|
}
|
|
|
|
|
2010-05-08 09:19:44 +02:00
|
|
|
float
|
2010-01-03 22:44:23 +01:00
|
|
|
decoder_replay_gain(G_GNUC_UNUSED struct decoder *decoder,
|
2010-07-20 00:02:27 +02:00
|
|
|
const struct replay_gain_info *replay_gain_info)
|
2010-01-03 22:44:23 +01:00
|
|
|
{
|
2010-07-20 00:02:27 +02:00
|
|
|
const struct replay_gain_tuple *tuple =
|
|
|
|
&replay_gain_info->tuples[REPLAY_GAIN_ALBUM];
|
|
|
|
if (replay_gain_tuple_defined(tuple))
|
|
|
|
g_printerr("replay_gain[album]: gain=%f peak=%f\n",
|
|
|
|
tuple->gain, tuple->peak);
|
|
|
|
|
|
|
|
tuple = &replay_gain_info->tuples[REPLAY_GAIN_TRACK];
|
|
|
|
if (replay_gain_tuple_defined(tuple))
|
|
|
|
g_printerr("replay_gain[track]: gain=%f peak=%f\n",
|
|
|
|
tuple->gain, tuple->peak);
|
|
|
|
|
2010-05-08 09:19:44 +02:00
|
|
|
return 0.0;
|
2010-01-03 22:44:23 +01:00
|
|
|
}
|
|
|
|
|
2010-03-21 18:21:47 +01:00
|
|
|
void
|
|
|
|
decoder_mixramp(G_GNUC_UNUSED struct decoder *decoder,
|
2010-05-08 09:19:44 +02:00
|
|
|
G_GNUC_UNUSED float replay_gain_db,
|
2010-03-21 18:21:47 +01:00
|
|
|
char *mixramp_start, char *mixramp_end)
|
|
|
|
{
|
|
|
|
g_free(mixramp_start);
|
|
|
|
g_free(mixramp_end);
|
|
|
|
}
|
|
|
|
|
2009-02-25 17:09:09 +01:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2009-12-14 22:29:46 +01:00
|
|
|
GError *error = NULL;
|
2009-02-25 17:09:09 +01:00
|
|
|
const char *decoder_name;
|
|
|
|
struct decoder decoder;
|
|
|
|
|
|
|
|
if (argc != 3) {
|
|
|
|
g_printerr("Usage: run_decoder DECODER URI >OUT\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
decoder_name = argv[1];
|
|
|
|
decoder.uri = argv[2];
|
|
|
|
|
2009-12-14 21:26:43 +01:00
|
|
|
g_log_set_default_handler(my_log_func, NULL);
|
|
|
|
|
2009-12-14 22:29:46 +01:00
|
|
|
if (!input_stream_global_init(&error)) {
|
|
|
|
g_warning("%s", error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2009-02-25 17:09:09 +01:00
|
|
|
decoder_plugin_init_all();
|
|
|
|
|
|
|
|
decoder.plugin = decoder_plugin_from_name(decoder_name);
|
|
|
|
if (decoder.plugin == NULL) {
|
|
|
|
g_printerr("No such decoder: %s\n", decoder_name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-03-02 23:09:58 +01:00
|
|
|
decoder.initialized = false;
|
|
|
|
|
2009-02-25 17:09:09 +01:00
|
|
|
if (decoder.plugin->file_decode != NULL) {
|
|
|
|
decoder_plugin_file_decode(decoder.plugin, &decoder,
|
|
|
|
decoder.uri);
|
|
|
|
} else if (decoder.plugin->stream_decode != NULL) {
|
2009-12-30 23:27:37 +01:00
|
|
|
struct input_stream *is =
|
|
|
|
input_stream_open(decoder.uri, &error);
|
|
|
|
if (is == NULL) {
|
2009-11-14 23:53:04 +01:00
|
|
|
if (error != NULL) {
|
|
|
|
g_warning("%s", error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
} else
|
|
|
|
g_printerr("input_stream_open() failed\n");
|
|
|
|
|
2009-02-25 17:09:09 +01:00
|
|
|
return 1;
|
2009-11-14 23:53:04 +01:00
|
|
|
}
|
2009-02-25 17:09:09 +01:00
|
|
|
|
2009-12-30 23:27:37 +01:00
|
|
|
decoder_plugin_stream_decode(decoder.plugin, &decoder, is);
|
2009-02-25 17:09:09 +01:00
|
|
|
|
2009-12-30 23:27:37 +01:00
|
|
|
input_stream_close(is);
|
2009-02-25 17:09:09 +01:00
|
|
|
} else {
|
|
|
|
g_printerr("Decoder plugin is not usable\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
decoder_plugin_deinit_all();
|
2009-03-02 23:08:24 +01:00
|
|
|
input_stream_global_finish();
|
2009-02-25 17:09:09 +01:00
|
|
|
|
|
|
|
if (!decoder.initialized) {
|
|
|
|
g_printerr("Decoding failed\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|