From a9e351e00d023829a5bb7def60208eef826b2ef3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 6 Mar 2014 13:12:39 +0100 Subject: decoder/gme: fix memory leak in container_scan() --- src/decoder/GmeDecoderPlugin.cxx | 1 + 1 file changed, 1 insertion(+) (limited to 'src/decoder') diff --git a/src/decoder/GmeDecoderPlugin.cxx b/src/decoder/GmeDecoderPlugin.cxx index 815fd8d69..d67ee4b42 100644 --- a/src/decoder/GmeDecoderPlugin.cxx +++ b/src/decoder/GmeDecoderPlugin.cxx @@ -117,6 +117,7 @@ gme_container_scan(const char *path_fs, const unsigned int tnum) } const unsigned num_songs = gme_track_count(emu); + gme_delete(emu); /* if it only contains a single tune, don't treat as container */ if (num_songs < 2) return nullptr; -- cgit v1.2.3 From 8e39cf62e7f84eca6f8b431bf721281d50653892 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 18 Mar 2014 09:10:36 +0100 Subject: decoder/ffmpeg: pass AVSEEK_FLAG_ANY to av_seek_frame() This corrects a major mistake from commit 724a59aa - there was one small thing that commit was supposed to do, and it failed. AV_TIME_BASE is not a seek flag. --- src/decoder/FfmpegDecoderPlugin.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/decoder') diff --git a/src/decoder/FfmpegDecoderPlugin.cxx b/src/decoder/FfmpegDecoderPlugin.cxx index 593f42d39..e1e848bf3 100644 --- a/src/decoder/FfmpegDecoderPlugin.cxx +++ b/src/decoder/FfmpegDecoderPlugin.cxx @@ -496,7 +496,7 @@ ffmpeg_decode(Decoder &decoder, InputStream &input) av_stream->start_time; if (av_seek_frame(format_context, audio_stream, where, - AV_TIME_BASE) < 0) + AVSEEK_FLAG_ANY) < 0) decoder_seek_error(decoder); else { avcodec_flush_buffers(codec_context); -- cgit v1.2.3 From ce18c36ed9328b4b5d376562594d8acb13a6723d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 18 Mar 2014 08:19:05 +0100 Subject: decoder/ffmpeg: handle unknown stream start time --- src/decoder/FfmpegDecoderPlugin.cxx | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/FfmpegDecoderPlugin.cxx b/src/decoder/FfmpegDecoderPlugin.cxx index e1e848bf3..bcb1ae3c9 100644 --- a/src/decoder/FfmpegDecoderPlugin.cxx +++ b/src/decoder/FfmpegDecoderPlugin.cxx @@ -197,6 +197,29 @@ time_to_ffmpeg(double t, const AVRational time_base) time_base); } +/** + * Replace #AV_NOPTS_VALUE with the given fallback. + */ +static constexpr int64_t +timestamp_fallback(int64_t t, int64_t fallback) +{ + return gcc_likely(t != int64_t(AV_NOPTS_VALUE)) + ? t + : fallback; +} + +/** + * Accessor for AVStream::start_time that replaces AV_NOPTS_VALUE with + * zero. We can't use AV_NOPTS_VALUE in calculations, and we simply + * assume that the stream's start time is zero, which appears to be + * the best way out of that situation. + */ +static int64_t +start_time_fallback(const AVStream &stream) +{ + return timestamp_fallback(stream.start_time, 0); +} + static void copy_interleave_frame2(uint8_t *dest, uint8_t **src, unsigned nframes, unsigned nchannels, @@ -263,7 +286,7 @@ ffmpeg_send_packet(Decoder &decoder, InputStream &is, { if (packet->pts >= 0 && packet->pts != (int64_t)AV_NOPTS_VALUE) decoder_timestamp(decoder, - time_from_ffmpeg(packet->pts - stream->start_time, + time_from_ffmpeg(packet->pts - start_time_fallback(*stream), stream->time_base)); AVPacket packet2 = *packet; @@ -493,7 +516,7 @@ ffmpeg_decode(Decoder &decoder, InputStream &input) int64_t where = time_to_ffmpeg(decoder_seek_where(decoder), av_stream->time_base) + - av_stream->start_time; + start_time_fallback(*av_stream); if (av_seek_frame(format_context, audio_stream, where, AVSEEK_FLAG_ANY) < 0) -- cgit v1.2.3 From 95ac6071b9fdaa543bd0c8ab7665d262db708683 Mon Sep 17 00:00:00 2001 From: Marcello Desantis Date: Wed, 9 Apr 2014 23:58:56 +0200 Subject: decoder/sndfile: work around libsndfile bug on partial read --- src/decoder/SndfileDecoderPlugin.cxx | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/SndfileDecoderPlugin.cxx b/src/decoder/SndfileDecoderPlugin.cxx index 3360cd1bf..77b132962 100644 --- a/src/decoder/SndfileDecoderPlugin.cxx +++ b/src/decoder/SndfileDecoderPlugin.cxx @@ -55,14 +55,28 @@ sndfile_vio_read(void *ptr, sf_count_t count, void *user_data) { InputStream &is = *(InputStream *)user_data; + sf_count_t total_bytes = 0; Error error; - size_t nbytes = is.LockRead(ptr, count, error); - if (nbytes == 0 && error.IsDefined()) { - LogError(error); - return -1; - } - return nbytes; + /* this loop is necessary because libsndfile chokes on partial + reads */ + + do { + size_t nbytes = is.LockRead((char *)ptr + total_bytes, + count - total_bytes, error); + if (nbytes == 0) { + if (error.IsDefined()) { + LogError(error); + return -1; + } + + break; + } + + total_bytes += nbytes; + } while (total_bytes < count); + + return total_bytes; } static sf_count_t -- cgit v1.2.3