aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2010-01-17 02:35:15 +0100
committerMax Kellermann <max@duempel.org>2010-01-17 02:36:07 +0100
commit1b441837f1b51d2504256b730129e0fe92d64375 (patch)
tree6657b9206704c0ff8186dbc3189504f370ff0077
parente43bf52cbbb5fc9685587d8afcd51537b2b51723 (diff)
downloadmpd-1b441837f1b51d2504256b730129e0fe92d64375.tar.gz
mpd-1b441837f1b51d2504256b730129e0fe92d64375.tar.xz
mpd-1b441837f1b51d2504256b730129e0fe92d64375.zip
decoder/ffmpeg: append file name suffix to virtual stream URL
To allow libavformat to detect the format of the input file, append the suffix of the input file to the URL of the virtual stream. This specifically enables the "shorten" codec, which is supported by libavformat/raw.c, detected only by the suffix.
-rw-r--r--NEWS1
-rw-r--r--src/decoder/ffmpeg_plugin.c32
2 files changed, 29 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index 70eeb3deb..f5dcecbd9 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ ver 0.15.8 (2009/??/??)
- curl: allow rewinding with Icy-Metadata
* decoders:
- ffmpeg, flac, vorbis: added more flac/vorbis MIME types
+ - ffmpeg: enabled libavformat's file name extension detection
* dbUtils: return empty tag value only if no value was found
* decoder_thread: fix CUE track playback
* queue: don't repeat current song in consume mode
diff --git a/src/decoder/ffmpeg_plugin.c b/src/decoder/ffmpeg_plugin.c
index d2bd642fd..0e15d99c1 100644
--- a/src/decoder/ffmpeg_plugin.c
+++ b/src/decoder/ffmpeg_plugin.c
@@ -55,7 +55,7 @@ struct ffmpeg_context {
struct ffmpeg_stream {
/** hack - see url_to_struct() */
- char url[8];
+ char url[64];
struct decoder *decoder;
struct input_stream *input;
@@ -140,8 +140,28 @@ ffmpeg_find_audio_stream(const AVFormatContext *format_context)
return -1;
}
+/**
+ * Append the suffix of the original URI to the virtual stream URI.
+ * Without this, libavformat cannot detect some of the codecs
+ * (e.g. "shorten").
+ */
+static void
+append_uri_suffix(struct ffmpeg_stream *stream, const char *uri)
+{
+ assert(stream != NULL);
+ assert(uri != NULL);
+
+ char *base = g_path_get_basename(uri);
+
+ const char *suffix = strrchr(base, '.');
+ if (suffix != NULL && suffix[1] != 0)
+ g_strlcat(stream->url, suffix, sizeof(stream->url));
+
+ g_free(base);
+}
+
static bool
-ffmpeg_helper(struct input_stream *input,
+ffmpeg_helper(const char *uri, struct input_stream *input,
bool (*callback)(struct ffmpeg_context *ctx),
struct ffmpeg_context *ctx)
{
@@ -154,6 +174,9 @@ ffmpeg_helper(struct input_stream *input,
};
bool ret;
+ if (uri != NULL)
+ append_uri_suffix(&stream, uri);
+
stream.input = input;
if (ctx && ctx->decoder) {
stream.decoder = ctx->decoder; //are we in decoding loop ?
@@ -349,7 +372,8 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
ctx.input = input;
ctx.decoder = decoder;
- ffmpeg_helper(input, ffmpeg_decode_internal, &ctx);
+ ffmpeg_helper(decoder_get_uri(decoder), input,
+ ffmpeg_decode_internal, &ctx);
}
#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0)
@@ -426,7 +450,7 @@ static struct tag *ffmpeg_tag(const char *file)
ctx.decoder = NULL;
ctx.tag = tag_new();
- ret = ffmpeg_helper(&input, ffmpeg_tag_internal, &ctx);
+ ret = ffmpeg_helper(file, &input, ffmpeg_tag_internal, &ctx);
if (!ret) {
tag_free(ctx.tag);
ctx.tag = NULL;