From ddc028333902bccd0b12f3834fdb63c4307ed530 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 5 Oct 2012 14:52:30 +0200 Subject: decoder/ffmpeg: remove duplicate sample format error message --- src/decoder/ffmpeg_decoder_plugin.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/decoder') diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index b6309440..cbc23f54 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -485,11 +485,16 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) return; } + const enum sample_format sample_format = + ffmpeg_sample_format(codec_context); + if (sample_format == SAMPLE_FORMAT_UNDEFINED) + 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), + sample_format, codec_context->channels, &error)) { g_warning("%s", error->message); g_error_free(error); -- cgit v1.2.3 From 9d728b365da7693c906f9eb95744e282bb4e834a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 5 Oct 2012 15:14:57 +0200 Subject: decoder/ffmpeg: pass AVSampleFormat to ffmpeg_sample_format() API simplification. --- src/decoder/ffmpeg_decoder_plugin.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index cbc23f54..c9389b86 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -352,10 +352,15 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is, return cmd; } +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52, 94, 1) +#define AVSampleFormat SampleFormat +#endif + +G_GNUC_CONST static enum sample_format -ffmpeg_sample_format(G_GNUC_UNUSED const AVCodecContext *codec_context) +ffmpeg_sample_format(enum AVSampleFormat sample_fmt) { - switch (codec_context->sample_fmt) { + switch (sample_fmt) { #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 94, 1) case AV_SAMPLE_FMT_S16: #else @@ -372,7 +377,7 @@ ffmpeg_sample_format(G_GNUC_UNUSED const AVCodecContext *codec_context) default: g_warning("Unsupported libavcodec SampleFormat value: %d", - codec_context->sample_fmt); + sample_fmt); return SAMPLE_FORMAT_UNDEFINED; } } @@ -486,7 +491,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) } const enum sample_format sample_format = - ffmpeg_sample_format(codec_context); + ffmpeg_sample_format(codec_context->sample_fmt); if (sample_format == SAMPLE_FORMAT_UNDEFINED) return; -- cgit v1.2.3 From fd016f45074cc5afd114163fb2d9390022e2e7d5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 5 Oct 2012 14:55:19 +0200 Subject: decoder/ffmpeg: show unsupported sample format name Use av_get_sample_fmt_string() to obtain a human-readable string. --- src/decoder/ffmpeg_decoder_plugin.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index c9389b86..bab6968e 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -376,10 +376,21 @@ ffmpeg_sample_format(enum AVSampleFormat sample_fmt) return SAMPLE_FORMAT_S32; default: + break; + } + +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 94, 1) + char buffer[64]; + const char *name = av_get_sample_fmt_string(buffer, sizeof(buffer), + sample_fmt); + if (name != NULL) + g_warning("Unsupported libavcodec SampleFormat value: %s (%d)", + name, sample_fmt); + else +#endif g_warning("Unsupported libavcodec SampleFormat value: %d", sample_fmt); - return SAMPLE_FORMAT_UNDEFINED; - } + return SAMPLE_FORMAT_UNDEFINED; } static AVInputFormat * -- cgit v1.2.3 From e39382dedd224a97a896034c43772fa3da924b15 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 5 Oct 2012 16:35:45 +0200 Subject: decoder/ffmpeg: ignore negative time stamps Works around assertion failure in decoder_timestamp(). --- NEWS | 2 ++ src/decoder/ffmpeg_decoder_plugin.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src/decoder') diff --git a/NEWS b/NEWS index b280e616..34d5f95a 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ ver 0.17.3 (2012/??/??) - recorder: fix I/O error check - shout: fix memory leak in error handler - recorder, shout: support Ogg packets that span more than one page +* decoder: + - ffmpeg: ignore negative time stamps ver 0.17.2 (2012/09/30) * protocol: diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index bab6968e..64227b85 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -273,7 +273,7 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is, AVCodecContext *codec_context, const AVRational *time_base) { - if (packet->pts != (int64_t)AV_NOPTS_VALUE) + if (packet->pts >= 0 && packet->pts != (int64_t)AV_NOPTS_VALUE) decoder_timestamp(decoder, time_from_ffmpeg(packet->pts, *time_base)); -- cgit v1.2.3 From 230a3eb4005702ef00040eb3cdda11ba7d19ac3e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 5 Oct 2012 16:29:40 +0200 Subject: decoder/ffmpeg: move code to copy_interleave_frame2() --- src/decoder/ffmpeg_decoder_plugin.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index 64227b85..54a574b4 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -234,6 +234,17 @@ time_to_ffmpeg(double t, const AVRational time_base) } #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,25,0) + +static void +copy_interleave_frame2(uint8_t *dest, const uint8_t *const*src, + unsigned nchannels, size_t plane_size) +{ + for (unsigned channel = 0; channel < nchannels; ++channel) { + memcpy(dest, src[channel], plane_size); + dest += plane_size; + } +} + /** * Copy PCM data from a AVFrame to an interleaved buffer. */ @@ -254,11 +265,9 @@ copy_interleave_frame(const AVCodecContext *codec_context, 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; - } + copy_interleave_frame2(buffer, + (const uint8_t *const*)frame->extended_data, + codec_context->channels, plane_size); } else { memcpy(buffer, frame->extended_data[0], data_size); } -- cgit v1.2.3 From 1dc27be015622118a216284351915d7d7cceb153 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 5 Oct 2012 16:38:41 +0200 Subject: decoder/ffmpeg: fix playback of planar PCM data Interleaving was completely wrong. This code was never used, so it didn't have an effect. --- src/decoder/ffmpeg_decoder_plugin.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index 54a574b4..59a6632d 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -236,12 +236,16 @@ time_to_ffmpeg(double t, const AVRational time_base) #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,25,0) static void -copy_interleave_frame2(uint8_t *dest, const uint8_t *const*src, - unsigned nchannels, size_t plane_size) +copy_interleave_frame2(uint8_t *dest, uint8_t **src, + unsigned nframes, unsigned nchannels, + unsigned sample_size) { - for (unsigned channel = 0; channel < nchannels; ++channel) { - memcpy(dest, src[channel], plane_size); - dest += plane_size; + for (unsigned frame = 0; frame < nframes; ++frame) { + for (unsigned channel = 0; channel < nchannels; ++channel) { + memcpy(dest, src[channel] + frame * sample_size, + sample_size); + dest += sample_size; + } } } @@ -265,9 +269,10 @@ copy_interleave_frame(const AVCodecContext *codec_context, if (av_sample_fmt_is_planar(codec_context->sample_fmt) && codec_context->channels > 1) { - copy_interleave_frame2(buffer, - (const uint8_t *const*)frame->extended_data, - codec_context->channels, plane_size); + copy_interleave_frame2(buffer, frame->extended_data, + frame->nb_samples, + codec_context->channels, + av_get_bytes_per_sample(codec_context->sample_fmt)); } else { memcpy(buffer, frame->extended_data[0], data_size); } -- cgit v1.2.3 From d4b5699403b60c5143e213c4239d11cd3497abb6 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 5 Oct 2012 15:27:04 +0200 Subject: decoder/ffmpeg: support planar audio Implements Mantis feature request 3582. --- NEWS | 1 + src/decoder/ffmpeg_decoder_plugin.c | 6 ++++++ 2 files changed, 7 insertions(+) (limited to 'src/decoder') diff --git a/NEWS b/NEWS index 34d5f95a..fb910e52 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ ver 0.17.3 (2012/??/??) - recorder, shout: support Ogg packets that span more than one page * decoder: - ffmpeg: ignore negative time stamps + - ffmpeg: support planar audio ver 0.17.2 (2012/09/30) * protocol: diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index 59a6632d..72a5ff34 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -377,6 +377,9 @@ ffmpeg_sample_format(enum AVSampleFormat sample_fmt) switch (sample_fmt) { #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 94, 1) case AV_SAMPLE_FMT_S16: +#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,17,0) + case AV_SAMPLE_FMT_S16P: +#endif #else case SAMPLE_FMT_S16: #endif @@ -384,6 +387,9 @@ ffmpeg_sample_format(enum AVSampleFormat sample_fmt) #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 94, 1) case AV_SAMPLE_FMT_S32: +#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,17,0) + case AV_SAMPLE_FMT_S32P: +#endif #else case SAMPLE_FMT_S32: #endif -- cgit v1.2.3