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.
This commit is contained in:
parent
e43bf52cbb
commit
1b441837f1
1
NEWS
1
NEWS
|
@ -3,6 +3,7 @@ ver 0.15.8 (2009/??/??)
|
||||||
- curl: allow rewinding with Icy-Metadata
|
- curl: allow rewinding with Icy-Metadata
|
||||||
* decoders:
|
* decoders:
|
||||||
- ffmpeg, flac, vorbis: added more flac/vorbis MIME types
|
- 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
|
* dbUtils: return empty tag value only if no value was found
|
||||||
* decoder_thread: fix CUE track playback
|
* decoder_thread: fix CUE track playback
|
||||||
* queue: don't repeat current song in consume mode
|
* queue: don't repeat current song in consume mode
|
||||||
|
|
|
@ -55,7 +55,7 @@ struct ffmpeg_context {
|
||||||
|
|
||||||
struct ffmpeg_stream {
|
struct ffmpeg_stream {
|
||||||
/** hack - see url_to_struct() */
|
/** hack - see url_to_struct() */
|
||||||
char url[8];
|
char url[64];
|
||||||
|
|
||||||
struct decoder *decoder;
|
struct decoder *decoder;
|
||||||
struct input_stream *input;
|
struct input_stream *input;
|
||||||
|
@ -140,8 +140,28 @@ ffmpeg_find_audio_stream(const AVFormatContext *format_context)
|
||||||
return -1;
|
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
|
static bool
|
||||||
ffmpeg_helper(struct input_stream *input,
|
ffmpeg_helper(const char *uri, struct input_stream *input,
|
||||||
bool (*callback)(struct ffmpeg_context *ctx),
|
bool (*callback)(struct ffmpeg_context *ctx),
|
||||||
struct ffmpeg_context *ctx)
|
struct ffmpeg_context *ctx)
|
||||||
{
|
{
|
||||||
|
@ -154,6 +174,9 @@ ffmpeg_helper(struct input_stream *input,
|
||||||
};
|
};
|
||||||
bool ret;
|
bool ret;
|
||||||
|
|
||||||
|
if (uri != NULL)
|
||||||
|
append_uri_suffix(&stream, uri);
|
||||||
|
|
||||||
stream.input = input;
|
stream.input = input;
|
||||||
if (ctx && ctx->decoder) {
|
if (ctx && ctx->decoder) {
|
||||||
stream.decoder = ctx->decoder; //are we in decoding loop ?
|
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.input = input;
|
||||||
ctx.decoder = decoder;
|
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)
|
#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.decoder = NULL;
|
||||||
ctx.tag = tag_new();
|
ctx.tag = tag_new();
|
||||||
|
|
||||||
ret = ffmpeg_helper(&input, ffmpeg_tag_internal, &ctx);
|
ret = ffmpeg_helper(file, &input, ffmpeg_tag_internal, &ctx);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
tag_free(ctx.tag);
|
tag_free(ctx.tag);
|
||||||
ctx.tag = NULL;
|
ctx.tag = NULL;
|
||||||
|
|
Loading…
Reference in New Issue