aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2013-04-22 12:03:39 +0200
committerAnton Khirnov <anton@khirnov.net>2013-11-04 11:02:12 +0100
commitb834c83478ad0a70b1486b9f5f79e877228f6ab3 (patch)
treeab120614b864a8f96112e08d507dd714a7f0e55e
parentc96693ef12727f6af405c91363fab21b5f58e9b6 (diff)
ffmpeg_decoder_plugin: remove tabs
-rw-r--r--src/decoder/ffmpeg_decoder_plugin.c896
-rw-r--r--src/decoder/ffmpeg_metadata.c54
-rw-r--r--src/decoder/ffmpeg_metadata.h2
3 files changed, 476 insertions, 476 deletions
diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c
index 41f15989..a0cce6a2 100644
--- a/src/decoder/ffmpeg_decoder_plugin.c
+++ b/src/decoder/ffmpeg_decoder_plugin.c
@@ -48,82 +48,82 @@
static GLogLevelFlags
level_ffmpeg_to_glib(int level)
{
- if (level <= AV_LOG_FATAL)
- return G_LOG_LEVEL_CRITICAL;
+ if (level <= AV_LOG_FATAL)
+ return G_LOG_LEVEL_CRITICAL;
- if (level <= AV_LOG_ERROR)
- return G_LOG_LEVEL_WARNING;
+ if (level <= AV_LOG_ERROR)
+ return G_LOG_LEVEL_WARNING;
- if (level <= AV_LOG_INFO)
- return G_LOG_LEVEL_MESSAGE;
+ if (level <= AV_LOG_INFO)
+ return G_LOG_LEVEL_MESSAGE;
- return G_LOG_LEVEL_DEBUG;
+ return G_LOG_LEVEL_DEBUG;
}
static void
mpd_ffmpeg_log_callback(G_GNUC_UNUSED void *ptr, int level,
- const char *fmt, va_list vl)
+ const char *fmt, va_list vl)
{
- const AVClass * cls = NULL;
+ const AVClass * cls = NULL;
- if (ptr != NULL)
- cls = *(const AVClass *const*)ptr;
+ if (ptr != NULL)
+ cls = *(const AVClass *const*)ptr;
- if (cls != NULL) {
- char *domain = g_strconcat(G_LOG_DOMAIN, "/", cls->item_name(ptr), NULL);
- g_logv(domain, level_ffmpeg_to_glib(level), fmt, vl);
- g_free(domain);
- }
+ if (cls != NULL) {
+ char *domain = g_strconcat(G_LOG_DOMAIN, "/", cls->item_name(ptr), NULL);
+ g_logv(domain, level_ffmpeg_to_glib(level), fmt, vl);
+ g_free(domain);
+ }
}
struct mpd_ffmpeg_stream {
- struct decoder *decoder;
- struct input_stream *input;
+ struct decoder *decoder;
+ struct input_stream *input;
- AVIOContext *io;
- unsigned char buffer[8192];
+ AVIOContext *io;
+ unsigned char buffer[8192];
};
static int
mpd_ffmpeg_stream_read(void *opaque, uint8_t *buf, int size)
{
- struct mpd_ffmpeg_stream *stream = opaque;
+ struct mpd_ffmpeg_stream *stream = opaque;
- return decoder_read(stream->decoder, stream->input,
- (void *)buf, size);
+ return decoder_read(stream->decoder, stream->input,
+ (void *)buf, size);
}
static int64_t
mpd_ffmpeg_stream_seek(void *opaque, int64_t pos, int whence)
{
- struct mpd_ffmpeg_stream *stream = opaque;
+ struct mpd_ffmpeg_stream *stream = opaque;
- if (whence == AVSEEK_SIZE)
- return stream->input->size;
+ if (whence == AVSEEK_SIZE)
+ return stream->input->size;
- if (!input_stream_lock_seek(stream->input, pos, whence, NULL))
- return -1;
+ if (!input_stream_lock_seek(stream->input, pos, whence, NULL))
+ return -1;
- return stream->input->offset;
+ return stream->input->offset;
}
static struct mpd_ffmpeg_stream *
mpd_ffmpeg_stream_open(struct decoder *decoder, struct input_stream *input)
{
- struct mpd_ffmpeg_stream *stream = g_new(struct mpd_ffmpeg_stream, 1);
- stream->decoder = decoder;
- stream->input = input;
- stream->io = avio_alloc_context(stream->buffer, sizeof(stream->buffer),
- false, stream,
- mpd_ffmpeg_stream_read, NULL,
- input->seekable
- ? mpd_ffmpeg_stream_seek : NULL);
- if (stream->io == NULL) {
- g_free(stream);
- return NULL;
- }
-
- return stream;
+ struct mpd_ffmpeg_stream *stream = g_new(struct mpd_ffmpeg_stream, 1);
+ stream->decoder = decoder;
+ stream->input = input;
+ stream->io = avio_alloc_context(stream->buffer, sizeof(stream->buffer),
+ false, stream,
+ mpd_ffmpeg_stream_read, NULL,
+ input->seekable
+ ? mpd_ffmpeg_stream_seek : NULL);
+ if (stream->io == NULL) {
+ g_free(stream);
+ return NULL;
+ }
+
+ return stream;
}
/**
@@ -132,62 +132,62 @@ mpd_ffmpeg_stream_open(struct decoder *decoder, struct input_stream *input)
*/
static int
mpd_ffmpeg_open_input(AVFormatContext **ic_ptr,
- AVIOContext *pb,
- const char *filename,
- AVInputFormat *fmt)
+ AVIOContext *pb,
+ const char *filename,
+ AVInputFormat *fmt)
{
- AVFormatContext *context = avformat_alloc_context();
- if (context == NULL)
- return AVERROR(ENOMEM);
+ AVFormatContext *context = avformat_alloc_context();
+ if (context == NULL)
+ return AVERROR(ENOMEM);
- context->pb = pb;
- *ic_ptr = context;
- return avformat_open_input(ic_ptr, filename, fmt, NULL);
+ context->pb = pb;
+ *ic_ptr = context;
+ return avformat_open_input(ic_ptr, filename, fmt, NULL);
}
static void
mpd_ffmpeg_stream_close(struct mpd_ffmpeg_stream *stream)
{
- av_free(stream->io);
- g_free(stream);
+ av_free(stream->io);
+ g_free(stream);
}
static bool
ffmpeg_init(G_GNUC_UNUSED const struct config_param *param)
{
- av_log_set_callback(mpd_ffmpeg_log_callback);
+ av_log_set_callback(mpd_ffmpeg_log_callback);
- av_register_all();
- return true;
+ av_register_all();
+ return true;
}
static int
ffmpeg_find_audio_stream(const AVFormatContext *format_context)
{
- for (unsigned i = 0; i < format_context->nb_streams; ++i)
- if (format_context->streams[i]->codec->codec_type ==
- AVMEDIA_TYPE_AUDIO)
- return i;
+ for (unsigned i = 0; i < format_context->nb_streams; ++i)
+ if (format_context->streams[i]->codec->codec_type ==
+ AVMEDIA_TYPE_AUDIO)
+ return i;
- return -1;
+ return -1;
}
G_GNUC_CONST
static double
time_from_ffmpeg(int64_t t, const AVRational time_base)
{
- assert(t != (int64_t)AV_NOPTS_VALUE);
+ assert(t != (int64_t)AV_NOPTS_VALUE);
- return (double)av_rescale_q(t, time_base, (AVRational){1, 1024})
- / (double)1024;
+ return (double)av_rescale_q(t, time_base, (AVRational){1, 1024})
+ / (double)1024;
}
G_GNUC_CONST
static int64_t
time_to_ffmpeg(double t, const AVRational time_base)
{
- return av_rescale_q((int64_t)(t * 1024), (AVRational){1, 1024},
- time_base);
+ return av_rescale_q((int64_t)(t * 1024), (AVRational){1, 1024},
+ time_base);
}
/**
@@ -195,309 +195,309 @@ time_to_ffmpeg(double t, const AVRational time_base)
*/
static int
copy_interleave_frame(const AVCodecContext *codec_context,
- const AVFrame *frame,
- uint8_t *buffer, size_t buffer_size)
+ const AVFrame *frame,
+ uint8_t *buffer, size_t buffer_size)
{
- int plane_size;
- const int data_size =
- av_samples_get_buffer_size(&plane_size,
- codec_context->channels,
- frame->nb_samples,
- codec_context->sample_fmt, 1);
- if (buffer_size < (size_t)data_size)
- /* buffer is too small - shouldn't happen */
- return AVERROR(EINVAL);
-
- if (av_sample_fmt_is_planar(codec_context->sample_fmt) &&
- codec_context->channels > 1) {
- for (int i = 0, channels = codec_context->channels;
- i < channels; i++) {
- memcpy(buffer, frame->extended_data[i], plane_size);
- buffer += plane_size;
- }
- } else {
- memcpy(buffer, frame->extended_data[0], data_size);
- }
-
- return data_size;
+ int plane_size;
+ const int data_size =
+ av_samples_get_buffer_size(&plane_size,
+ codec_context->channels,
+ frame->nb_samples,
+ codec_context->sample_fmt, 1);
+ if (buffer_size < (size_t)data_size)
+ /* buffer is too small - shouldn't happen */
+ return AVERROR(EINVAL);
+
+ if (av_sample_fmt_is_planar(codec_context->sample_fmt) &&
+ codec_context->channels > 1) {
+ for (int i = 0, channels = codec_context->channels;
+ i < channels; i++) {
+ memcpy(buffer, frame->extended_data[i], plane_size);
+ buffer += plane_size;
+ }
+ } else {
+ memcpy(buffer, frame->extended_data[0], data_size);
+ }
+
+ return data_size;
}
static enum decoder_command
ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
- const AVPacket *packet,
- AVCodecContext *codec_context,
- const AVRational *time_base)
+ const AVPacket *packet,
+ AVCodecContext *codec_context,
+ const AVRational *time_base)
{
- if (packet->pts != (int64_t)AV_NOPTS_VALUE)
- decoder_timestamp(decoder,
- time_from_ffmpeg(packet->pts, *time_base));
+ if (packet->pts != (int64_t)AV_NOPTS_VALUE)
+ decoder_timestamp(decoder,
+ time_from_ffmpeg(packet->pts, *time_base));
- AVPacket packet2 = *packet;
+ AVPacket packet2 = *packet;
#define AVCODEC_MAX_AUDIO_FRAME_SIZE 50000
- uint8_t aligned_buffer[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2 + 16];
- const size_t buffer_size = sizeof(aligned_buffer);
-
- enum decoder_command cmd = DECODE_COMMAND_NONE;
- while (
- packet2.size > 0 &&
- cmd == DECODE_COMMAND_NONE) {
- int audio_size = buffer_size;
- AVFrame frame;
- int got_frame = 0;
- int len = avcodec_decode_audio4(codec_context,
- &frame, &got_frame,
- &packet2);
- if (len >= 0 && got_frame) {
- audio_size = copy_interleave_frame(codec_context,
- &frame,
- aligned_buffer,
- buffer_size);
- if (audio_size < 0)
- len = audio_size;
- } else if (len >= 0)
- len = -1;
-
- if (len < 0) {
- /* if error, we skip the frame */
- g_message("decoding failed, frame skipped\n");
- break;
- }
-
- packet2.data += len;
- packet2.size -= len;
-
- if (audio_size <= 0)
- continue;
-
- cmd = decoder_data(decoder, is,
- aligned_buffer, audio_size,
- codec_context->bit_rate / 1000);
- }
- return cmd;
+ uint8_t aligned_buffer[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2 + 16];
+ const size_t buffer_size = sizeof(aligned_buffer);
+
+ enum decoder_command cmd = DECODE_COMMAND_NONE;
+ while (
+ packet2.size > 0 &&
+ cmd == DECODE_COMMAND_NONE) {
+ int audio_size = buffer_size;
+ AVFrame frame;
+ int got_frame = 0;
+ int len = avcodec_decode_audio4(codec_context,
+ &frame, &got_frame,
+ &packet2);
+ if (len >= 0 && got_frame) {
+ audio_size = copy_interleave_frame(codec_context,
+ &frame,
+ aligned_buffer,
+ buffer_size);
+ if (audio_size < 0)
+ len = audio_size;
+ } else if (len >= 0)
+ len = -1;
+
+ if (len < 0) {
+ /* if error, we skip the frame */
+ g_message("decoding failed, frame skipped\n");
+ break;
+ }
+
+ packet2.data += len;
+ packet2.size -= len;
+
+ if (audio_size <= 0)
+ continue;
+
+ cmd = decoder_data(decoder, is,
+ aligned_buffer, audio_size,
+ codec_context->bit_rate / 1000);
+ }
+ return cmd;
}
static enum sample_format
ffmpeg_sample_format(G_GNUC_UNUSED const AVCodecContext *codec_context)
{
- switch (codec_context->sample_fmt) {
- case AV_SAMPLE_FMT_S16:
- return SAMPLE_FORMAT_S16;
-
- case AV_SAMPLE_FMT_S32:
- return SAMPLE_FORMAT_S32;
-
- default:
- g_warning("Unsupported libavcodec SampleFormat value: %d",
- codec_context->sample_fmt);
- return SAMPLE_FORMAT_UNDEFINED;
- }
+ switch (codec_context->sample_fmt) {
+ case AV_SAMPLE_FMT_S16:
+ return SAMPLE_FORMAT_S16;
+
+ case AV_SAMPLE_FMT_S32:
+ return SAMPLE_FORMAT_S32;
+
+ default:
+ g_warning("Unsupported libavcodec SampleFormat value: %d",
+ codec_context->sample_fmt);
+ return SAMPLE_FORMAT_UNDEFINED;
+ }
}
static AVInputFormat *
ffmpeg_probe(struct decoder *decoder, struct input_stream *is)
{
- enum {
- BUFFER_SIZE = 16384,
- PADDING = 16,
- };
-
- unsigned char *buffer = g_malloc(BUFFER_SIZE);
- size_t nbytes = decoder_read(decoder, is, buffer, BUFFER_SIZE);
- if (nbytes <= PADDING ||
- !input_stream_lock_seek(is, 0, SEEK_SET, NULL)) {
- g_free(buffer);
- return NULL;
- }
-
- /* some ffmpeg parsers (e.g. ac3_parser.c) read a few bytes
- beyond the declared buffer limit, which makes valgrind
- angry; this workaround removes some padding from the buffer
- size */
- nbytes -= PADDING;
-
- AVProbeData avpd = {
- .buf = buffer,
- .buf_size = nbytes,
- .filename = is->uri,
- };
-
- AVInputFormat *format = av_probe_input_format(&avpd, true);
- g_free(buffer);
-
- return format;
+ enum {
+ BUFFER_SIZE = 16384,
+ PADDING = 16,
+ };
+
+ unsigned char *buffer = g_malloc(BUFFER_SIZE);
+ size_t nbytes = decoder_read(decoder, is, buffer, BUFFER_SIZE);
+ if (nbytes <= PADDING ||
+ !input_stream_lock_seek(is, 0, SEEK_SET, NULL)) {
+ g_free(buffer);
+ return NULL;
+ }
+
+ /* some ffmpeg parsers (e.g. ac3_parser.c) read a few bytes
+ beyond the declared buffer limit, which makes valgrind
+ angry; this workaround removes some padding from the buffer
+ size */
+ nbytes -= PADDING;
+
+ AVProbeData avpd = {
+ .buf = buffer,
+ .buf_size = nbytes,
+ .filename = is->uri,
+ };
+
+ AVInputFormat *format = av_probe_input_format(&avpd, true);
+ g_free(buffer);
+
+ return format;
}
static void
ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
{
- AVInputFormat *input_format = ffmpeg_probe(decoder, input);
- if (input_format == NULL)
- return;
-
- g_debug("detected input format '%s' (%s)",
- input_format->name, input_format->long_name);
-
- struct mpd_ffmpeg_stream *stream =
- mpd_ffmpeg_stream_open(decoder, input);
- if (stream == NULL) {
- g_warning("Failed to open stream");
- return;
- }
-
- //ffmpeg works with ours "fileops" helper
- AVFormatContext *format_context = NULL;
- if (mpd_ffmpeg_open_input(&format_context, stream->io, input->uri,
- input_format) != 0) {
- g_warning("Open failed\n");
- mpd_ffmpeg_stream_close(stream);
- return;
- }
-
- const int find_result =
- avformat_find_stream_info(format_context, NULL);
- if (find_result < 0) {
- g_warning("Couldn't find stream info\n");
- avformat_close_input(&format_context);
- mpd_ffmpeg_stream_close(stream);
- return;
- }
-
- int audio_stream = ffmpeg_find_audio_stream(format_context);
- if (audio_stream == -1) {
- g_warning("No audio stream inside\n");
- avformat_close_input(&format_context);
- mpd_ffmpeg_stream_close(stream);
- return;
- }
-
- AVStream *av_stream = format_context->streams[audio_stream];
-
- AVCodecContext *codec_context = av_stream->codec;
- if (codec_context->codec_name[0] != 0)
- g_debug("codec '%s'", codec_context->codec_name);
-
- AVCodec *codec = avcodec_find_decoder(codec_context->codec_id);
-
- if (!codec) {
- g_warning("Unsupported audio codec\n");
- avformat_close_input(&format_context);
- mpd_ffmpeg_stream_close(stream);
- return;
- }
-
- GError *error = NULL;
- struct audio_format audio_format;
- if (!audio_format_init_checked(&audio_format,
- codec_context->sample_rate,
- ffmpeg_sample_format(codec_context),
- codec_context->channels, &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
- avformat_close_input(&format_context);
- mpd_ffmpeg_stream_close(stream);
- return;
- }
-
- /* the audio format must be read from AVCodecContext by now,
- because avcodec_open() has been demonstrated to fill bogus
- values into AVCodecContext.channels - a change that will be
- reverted later by avcodec_decode_audio3() */
-
- const int open_result = avcodec_open2(codec_context, codec, NULL);
- if (open_result < 0) {
- g_warning("Could not open codec\n");
- avformat_close_input(&format_context);
- mpd_ffmpeg_stream_close(stream);
- return;
- }
-
- int total_time = format_context->duration != (int64_t)AV_NOPTS_VALUE
- ? format_context->duration / AV_TIME_BASE
- : 0;
-
- decoder_initialized(decoder, &audio_format,
- input->seekable, total_time);
-
- enum decoder_command cmd;
- do {
- AVPacket packet;
- if (av_read_frame(format_context, &packet) < 0)
- /* end of file */
- break;
-
- if (packet.stream_index == audio_stream)
- cmd = ffmpeg_send_packet(decoder, input,
- &packet, codec_context,
- &av_stream->time_base);
- else
- cmd = decoder_get_command(decoder);
-
- av_free_packet(&packet);
-
- if (cmd == DECODE_COMMAND_SEEK) {
- int64_t where =
- time_to_ffmpeg(decoder_seek_where(decoder),
- av_stream->time_base);
-
- if (av_seek_frame(format_context, audio_stream, where,
- AV_TIME_BASE) < 0)
- decoder_seek_error(decoder);
- else {
- avcodec_flush_buffers(codec_context);
- decoder_command_finished(decoder);
- }
- }
- } while (cmd != DECODE_COMMAND_STOP);
-
- avcodec_close(codec_context);
- avformat_close_input(&format_context);
- mpd_ffmpeg_stream_close(stream);
+ AVInputFormat *input_format = ffmpeg_probe(decoder, input);
+ if (input_format == NULL)
+ return;
+
+ g_debug("detected input format '%s' (%s)",
+ input_format->name, input_format->long_name);
+
+ struct mpd_ffmpeg_stream *stream =
+ mpd_ffmpeg_stream_open(decoder, input);
+ if (stream == NULL) {
+ g_warning("Failed to open stream");
+ return;
+ }
+
+ //ffmpeg works with ours "fileops" helper
+ AVFormatContext *format_context = NULL;
+ if (mpd_ffmpeg_open_input(&format_context, stream->io, input->uri,
+ input_format) != 0) {
+ g_warning("Open failed\n");
+ mpd_ffmpeg_stream_close(stream);
+ return;
+ }
+
+ const int find_result =
+ avformat_find_stream_info(format_context, NULL);
+ if (find_result < 0) {
+ g_warning("Couldn't find stream info\n");
+ avformat_close_input(&format_context);
+ mpd_ffmpeg_stream_close(stream);
+ return;
+ }
+
+ int audio_stream = ffmpeg_find_audio_stream(format_context);
+ if (audio_stream == -1) {
+ g_warning("No audio stream inside\n");
+ avformat_close_input(&format_context);
+ mpd_ffmpeg_stream_close(stream);
+ return;
+ }
+
+ AVStream *av_stream = format_context->streams[audio_stream];
+
+ AVCodecContext *codec_context = av_stream->codec;
+ if (codec_context->codec_name[0] != 0)
+ g_debug("codec '%s'", codec_context->codec_name);
+
+ AVCodec *codec = avcodec_find_decoder(codec_context->codec_id);
+
+ if (!codec) {
+ g_warning("Unsupported audio codec\n");
+ avformat_close_input(&format_context);
+ mpd_ffmpeg_stream_close(stream);
+ return;
+ }
+
+ GError *error = NULL;
+ struct audio_format audio_format;
+ if (!audio_format_init_checked(&audio_format,
+ codec_context->sample_rate,
+ ffmpeg_sample_format(codec_context),
+ codec_context->channels, &error)) {
+ g_warning("%s", error->message);
+ g_error_free(error);
+ avformat_close_input(&format_context);
+ mpd_ffmpeg_stream_close(stream);
+ return;
+ }
+
+ /* the audio format must be read from AVCodecContext by now,
+ because avcodec_open() has been demonstrated to fill bogus
+ values into AVCodecContext.channels - a change that will be
+ reverted later by avcodec_decode_audio3() */
+
+ const int open_result = avcodec_open2(codec_context, codec, NULL);
+ if (open_result < 0) {
+ g_warning("Could not open codec\n");
+ avformat_close_input(&format_context);
+ mpd_ffmpeg_stream_close(stream);
+ return;
+ }
+
+ int total_time = format_context->duration != (int64_t)AV_NOPTS_VALUE
+ ? format_context->duration / AV_TIME_BASE
+ : 0;
+
+ decoder_initialized(decoder, &audio_format,
+ input->seekable, total_time);
+
+ enum decoder_command cmd;
+ do {
+ AVPacket packet;
+ if (av_read_frame(format_context, &packet) < 0)
+ /* end of file */
+ break;
+
+ if (packet.stream_index == audio_stream)
+ cmd = ffmpeg_send_packet(decoder, input,
+ &packet, codec_context,
+ &av_stream->time_base);
+ else
+ cmd = decoder_get_command(decoder);
+
+ av_free_packet(&packet);
+
+ if (cmd == DECODE_COMMAND_SEEK) {
+ int64_t where =
+ time_to_ffmpeg(decoder_seek_where(decoder),
+ av_stream->time_base);
+
+ if (av_seek_frame(format_context, audio_stream, where,
+ AV_TIME_BASE) < 0)
+ decoder_seek_error(decoder);
+ else {
+ avcodec_flush_buffers(codec_context);
+ decoder_command_finished(decoder);
+ }
+ }
+ } while (cmd != DECODE_COMMAND_STOP);
+
+ avcodec_close(codec_context);
+ avformat_close_input(&format_context);
+ mpd_ffmpeg_stream_close(stream);
}
//no tag reading in ffmpeg, check if playable
static bool
ffmpeg_scan_stream(struct input_stream *is,
- const struct tag_handler *handler, void *handler_ctx)
+ const struct tag_handler *handler, void *handler_ctx)
{
- AVInputFormat *input_format = ffmpeg_probe(NULL, is);
- if (input_format == NULL)
- return false;
-
- struct mpd_ffmpeg_stream *stream = mpd_ffmpeg_stream_open(NULL, is);
- if (stream == NULL)
- return false;
-
- AVFormatContext *f = NULL;
- if (mpd_ffmpeg_open_input(&f, stream->io, is->uri,
- input_format) != 0) {
- mpd_ffmpeg_stream_close(stream);
- return false;
- }
-
- const int find_result =
- avformat_find_stream_info(f, NULL);
- if (find_result < 0) {
- avformat_close_input(&f);
- mpd_ffmpeg_stream_close(stream);
- return false;
- }
-
- if (f->duration != (int64_t)AV_NOPTS_VALUE)
- tag_handler_invoke_duration(handler, handler_ctx,
- f->duration / AV_TIME_BASE);
-
-
- ffmpeg_scan_dictionary(f->metadata, handler, handler_ctx);
- int idx = ffmpeg_find_audio_stream(f);
- if (idx >= 0)
- ffmpeg_scan_dictionary(f->streams[idx]->metadata,
- handler, handler_ctx);
-
- avformat_close_input(&f);
- mpd_ffmpeg_stream_close(stream);
-
- return true;
+ AVInputFormat *input_format = ffmpeg_probe(NULL, is);
+ if (input_format == NULL)
+ return false;
+
+ struct mpd_ffmpeg_stream *stream = mpd_ffmpeg_stream_open(NULL, is);
+ if (stream == NULL)
+ return false;
+
+ AVFormatContext *f = NULL;
+ if (mpd_ffmpeg_open_input(&f, stream->io, is->uri,
+ input_format) != 0) {
+ mpd_ffmpeg_stream_close(stream);
+ return false;
+ }
+
+ const int find_result =
+ avformat_find_stream_info(f, NULL);
+ if (find_result < 0) {
+ avformat_close_input(&f);
+ mpd_ffmpeg_stream_close(stream);
+ return false;
+ }
+
+ if (f->duration != (int64_t)AV_NOPTS_VALUE)
+ tag_handler_invoke_duration(handler, handler_ctx,
+ f->duration / AV_TIME_BASE);
+
+
+ ffmpeg_scan_dictionary(f->metadata, handler, handler_ctx);
+ int idx = ffmpeg_find_audio_stream(f);
+ if (idx >= 0)
+ ffmpeg_scan_dictionary(f->streams[idx]->metadata,
+ handler, handler_ctx);
+
+ avformat_close_input(&f);
+ mpd_ffmpeg_stream_close(stream);
+
+ return true;
}
/**
@@ -507,118 +507,118 @@ ffmpeg_scan_stream(struct input_stream *is,
* more formats.
*/
static const char *const ffmpeg_suffixes[] = {
- "16sv", "3g2", "3gp", "4xm", "8svx", "aa3", "aac", "ac3", "afc", "aif",
- "aifc", "aiff", "al", "alaw", "amr", "anim", "apc", "ape", "asf",
- "atrac", "au", "aud", "avi", "avm2", "avs", "bap", "bfi", "c93", "cak",
- "cin", "cmv", "cpk", "daud", "dct", "divx", "dts", "dv", "dvd", "dxa",
- "eac3", "film", "flac", "flc", "fli", "fll", "flx", "flv", "g726",
- "gsm", "gxf", "iss", "m1v", "m2v", "m2t", "m2ts",
- "m4a", "m4b", "m4v",
- "mad",
- "mj2", "mjpeg", "mjpg", "mka", "mkv", "mlp", "mm", "mmf", "mov", "mp+",
- "mp1", "mp2", "mp3", "mp4", "mpc", "mpeg", "mpg", "mpga", "mpp", "mpu",
- "mve", "mvi", "mxf", "nc", "nsv", "nut", "nuv", "oga", "ogm", "ogv",
- "ogx", "oma", "ogg", "omg", "psp", "pva", "qcp", "qt", "r3d", "ra",
- "ram", "rl2", "rm", "rmvb", "roq", "rpl", "rvc", "shn", "smk", "snd",
- "sol", "son", "spx", "str", "swf", "tgi", "tgq", "tgv", "thp", "ts",
- "tsp", "tta", "xa", "xvid", "uv", "uv2", "vb", "vid", "vob", "voc",
- "vp6", "vmd", "wav", "webm", "wma", "wmv", "wsaud", "wsvga", "wv",
- "wve",
- NULL
+ "16sv", "3g2", "3gp", "4xm", "8svx", "aa3", "aac", "ac3", "afc", "aif",
+ "aifc", "aiff", "al", "alaw", "amr", "anim", "apc", "ape", "asf",
+ "atrac", "au", "aud", "avi", "avm2", "avs", "bap", "bfi", "c93", "cak",
+ "cin", "cmv", "cpk", "daud", "dct", "divx", "dts", "dv", "dvd", "dxa",
+ "eac3", "film", "flac", "flc", "fli", "fll", "flx", "flv", "g726",
+ "gsm", "gxf", "iss", "m1v", "m2v", "m2t", "m2ts",
+ "m4a", "m4b", "m4v",
+ "mad",
+ "mj2", "mjpeg", "mjpg", "mka", "mkv", "mlp", "mm", "mmf", "mov", "mp+",
+ "mp1", "mp2", "mp3", "mp4", "mpc", "mpeg", "mpg", "mpga", "mpp", "mpu",
+ "mve", "mvi", "mxf", "nc", "nsv", "nut", "nuv", "oga", "ogm", "ogv",
+ "ogx", "oma", "ogg", "omg", "psp", "pva", "qcp", "qt", "r3d", "ra",
+ "ram", "rl2", "rm", "rmvb", "roq", "rpl", "rvc", "shn", "smk", "snd",
+ "sol", "son", "spx", "str", "swf", "tgi", "tgq", "tgv", "thp", "ts",
+ "tsp", "tta", "xa", "xvid", "uv", "uv2", "vb", "vid", "vob", "voc",
+ "vp6", "vmd", "wav", "webm", "wma", "wmv", "wsaud", "wsvga", "wv",
+ "wve",
+ NULL
};
static const char *const ffmpeg_mime_types[] = {
- "application/m4a",
- "application/mp4",
- "application/octet-stream",
- "application/ogg",
- "application/x-ms-wmz",
- "application/x-ms-wmd",
- "application/x-ogg",
- "application/x-shockwave-flash",
- "application/x-shorten",
- "audio/8svx",
- "audio/16sv",
- "audio/aac",
- "audio/ac3",
- "audio/aiff"
- "audio/amr",
- "audio/basic",
- "audio/flac",
- "audio/m4a",
- "audio/mp4",
- "audio/mpeg",
- "audio/musepack",
- "audio/ogg",
- "audio/qcelp",
- "audio/vorbis",
- "audio/vorbis+ogg",
- "audio/x-8svx",
- "audio/x-16sv",
- "audio/x-aac",
- "audio/x-ac3",
- "audio/x-aiff"
- "audio/x-alaw",
- "audio/x-au",
- "audio/x-dca",
- "audio/x-eac3",
- "audio/x-flac",
- "audio/x-gsm",
- "audio/x-mace",
- "audio/x-matroska",
- "audio/x-monkeys-audio",
- "audio/x-mpeg",
- "audio/x-ms-wma",
- "audio/x-ms-wax",
- "audio/x-musepack",
- "audio/x-ogg",
- "audio/x-vorbis",
- "audio/x-vorbis+ogg",
- "audio/x-pn-realaudio",
- "audio/x-pn-multirate-realaudio",
- "audio/x-speex",
- "audio/x-tta"
- "audio/x-voc",
- "audio/x-wav",
- "audio/x-wma",
- "audio/x-wv",
- "video/anim",
- "video/quicktime",
- "video/msvideo",
- "video/ogg",
- "video/theora",
- "video/webm",
- "video/x-dv",
- "video/x-flv",
- "video/x-matroska",
- "video/x-mjpeg",
- "video/x-mpeg",
- "video/x-ms-asf",
- "video/x-msvideo",
- "video/x-ms-wmv",
- "video/x-ms-wvx",
- "video/x-ms-wm",
- "video/x-ms-wmx",
- "video/x-nut",
- "video/x-pva",
- "video/x-theora",
- "video/x-vid",
- "video/x-wmv",
- "video/x-xvid",
-
- /* special value for the "ffmpeg" input plugin: all streams by
- the "ffmpeg" input plugin shall be decoded by this
- plugin */
- "audio/x-mpd-ffmpeg",
-
- NULL
+ "application/m4a",
+ "application/mp4",
+ "application/octet-stream",
+ "application/ogg",
+ "application/x-ms-wmz",
+ "application/x-ms-wmd",
+ "application/x-ogg",
+ "application/x-shockwave-flash",
+ "application/x-shorten",
+ "audio/8svx",
+ "audio/16sv",
+ "audio/aac",
+ "audio/ac3",
+ "audio/aiff"
+ "audio/amr",
+ "audio/basic",
+ "audio/flac",
+ "audio/m4a",
+ "audio/mp4",
+ "audio/mpeg",
+ "audio/musepack",
+ "audio/ogg",
+ "audio/qcelp",
+ "audio/vorbis",
+ "audio/vorbis+ogg",
+ "audio/x-8svx",
+ "audio/x-16sv",
+ "audio/x-aac",
+ "audio/x-ac3",
+ "audio/x-aiff"
+ "audio/x-alaw",
+ "audio/x-au",
+ "audio/x-dca",
+ "audio/x-eac3",
+ "audio/x-flac",
+ "audio/x-gsm",
+ "audio/x-mace",
+ "audio/x-matroska",
+ "audio/x-monkeys-audio",
+ "audio/x-mpeg",
+ "audio/x-ms-wma",
+ "audio/x-ms-wax",
+ "audio/x-musepack",
+ "audio/x-ogg",
+ "audio/x-vorbis",
+ "audio/x-vorbis+ogg",
+ "audio/x-pn-realaudio",
+ "audio/x-pn-multirate-realaudio",
+ "audio/x-speex",
+ "audio/x-tta"
+ "audio/x-voc",
+ "audio/x-wav",
+ "audio/x-wma",
+ "audio/x-wv",
+ "video/anim",
+ "video/quicktime",
+ "video/msvideo",
+ "video/ogg",
+ "video/theora",
+ "video/webm",
+ "video/x-dv",
+ "video/x-flv",
+ "video/x-matroska",
+ "video/x-mjpeg",
+ "video/x-mpeg",
+ "video/x-ms-asf",
+ "video/x-msvideo",
+ "video/x-ms-wmv",
+ "video/x-ms-wvx",
+ "video/x-ms-wm",
+ "video/x-ms-wmx",
+ "video/x-nut",
+ "video/x-pva",
+ "video/x-theora",
+ "video/x-vid",
+ "video/x-wmv",
+ "video/x-xvid",
+
+ /* special value for the "ffmpeg" input plugin: all streams by
+ the "ffmpeg" input plugin shall be decoded by this
+ plugin */
+ "audio/x-mpd-ffmpeg",
+
+ NULL
};
const struct decoder_plugin ffmpeg_decoder_plugin = {
- .name = "ffmpeg",
- .init = ffmpeg_init,
- .stream_decode = ffmpeg_decode,
- .scan_stream = ffmpeg_scan_stream,
- .suffixes = ffmpeg_suffixes,
- .mime_types = ffmpeg_mime_types
+ .name = "ffmpeg",
+ .init = ffmpeg_init,
+ .stream_decode = ffmpeg_decode,
+ .scan_stream = ffmpeg_scan_stream,
+ .suffixes = ffmpeg_suffixes,
+ .mime_types = ffmpeg_mime_types
};
diff --git a/src/decoder/ffmpeg_metadata.c b/src/decoder/ffmpeg_metadata.c
index bc51363c..f1b1de59 100644
--- a/src/decoder/ffmpeg_metadata.c
+++ b/src/decoder/ffmpeg_metadata.c
@@ -26,52 +26,52 @@
#define G_LOG_DOMAIN "ffmpeg"
static const struct tag_table ffmpeg_tags[] = {
- { "year", TAG_DATE },
- { "author-sort", TAG_ARTIST_SORT },
- { "album_artist", TAG_ALBUM_ARTIST },
- { "album_artist-sort", TAG_ALBUM_ARTIST_SORT },
+ { "year", TAG_DATE },
+ { "author-sort", TAG_ARTIST_SORT },
+ { "album_artist", TAG_ALBUM_ARTIST },
+ { "album_artist-sort", TAG_ALBUM_ARTIST_SORT },
- /* sentinel */
- { NULL, TAG_NUM_OF_ITEM_TYPES }
+ /* sentinel */
+ { NULL, TAG_NUM_OF_ITEM_TYPES }
};
static void
ffmpeg_copy_metadata(enum tag_type type,
- AVDictionary *m, const char *name,
- const struct tag_handler *handler, void *handler_ctx)
+ AVDictionary *m, const char *name,
+ const struct tag_handler *handler, void *handler_ctx)
{
- AVDictionaryEntry *mt = NULL;
+ AVDictionaryEntry *mt = NULL;
- while ((mt = av_dict_get(m, name, mt, 0)) != NULL)
- tag_handler_invoke_tag(handler, handler_ctx,
- type, mt->value);
+ while ((mt = av_dict_get(m, name, mt, 0)) != NULL)
+ tag_handler_invoke_tag(handler, handler_ctx,
+ type, mt->value);
}
static void
ffmpeg_scan_pairs(AVDictionary *dict,
- const struct tag_handler *handler, void *handler_ctx)
+ const struct tag_handler *handler, void *handler_ctx)
{
- AVDictionaryEntry *i = NULL;
+ AVDictionaryEntry *i = NULL;
- while ((i = av_dict_get(dict, "", i, AV_DICT_IGNORE_SUFFIX)) != NULL)
- tag_handler_invoke_pair(handler, handler_ctx,
- i->key, i->value);
+ while ((i = av_dict_get(dict, "", i, AV_DICT_IGNORE_SUFFIX)) != NULL)
+ tag_handler_invoke_pair(handler, handler_ctx,
+ i->key, i->value);
}
void
ffmpeg_scan_dictionary(AVDictionary *dict,
- const struct tag_handler *handler, void *handler_ctx)
+ const struct tag_handler *handler, void *handler_ctx)
{
- for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
- ffmpeg_copy_metadata(i, dict, tag_item_names[i],
- handler, handler_ctx);
+ for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
+ ffmpeg_copy_metadata(i, dict, tag_item_names[i],
+ handler, handler_ctx);
- for (const struct tag_table *i = ffmpeg_tags;
- i->name != NULL; ++i)
- ffmpeg_copy_metadata(i->type, dict, i->name,
- handler, handler_ctx);
+ for (const struct tag_table *i = ffmpeg_tags;
+ i->name != NULL; ++i)
+ ffmpeg_copy_metadata(i->type, dict, i->name,
+ handler, handler_ctx);
- if (handler->pair != NULL)
- ffmpeg_scan_pairs(dict, handler, handler_ctx);
+ if (handler->pair != NULL)
+ ffmpeg_scan_pairs(dict, handler, handler_ctx);
}
diff --git a/src/decoder/ffmpeg_metadata.h b/src/decoder/ffmpeg_metadata.h
index 81255a66..a8ea6a6c 100644
--- a/src/decoder/ffmpeg_metadata.h
+++ b/src/decoder/ffmpeg_metadata.h
@@ -28,6 +28,6 @@ struct tag_handler;
void
ffmpeg_scan_dictionary(AVDictionary *dict,
- const struct tag_handler *handler, void *handler_ctx);
+ const struct tag_handler *handler, void *handler_ctx);
#endif