aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-10-27 11:05:47 +0100
committerMax Kellermann <max@duempel.org>2015-10-27 11:05:47 +0100
commit94f850a5885c89e5255948f9274aaaa4197bc52b (patch)
tree5348c92cb0ed9a3dc409be922abac07eee4438de /src/decoder
parent3882c114505ea39e3707f27d91eb8ef363a8895b (diff)
parentdb9997a1068e00c5f78d4bb9834ce5a13e7b7a3b (diff)
downloadmpd-94f850a5885c89e5255948f9274aaaa4197bc52b.tar.gz
mpd-94f850a5885c89e5255948f9274aaaa4197bc52b.tar.xz
mpd-94f850a5885c89e5255948f9274aaaa4197bc52b.zip
Merge tag 'v0.19.11'
Diffstat (limited to 'src/decoder')
-rw-r--r--src/decoder/plugins/FfmpegIo.cxx16
-rw-r--r--src/decoder/plugins/FfmpegIo.hxx2
-rw-r--r--src/decoder/plugins/GmeDecoderPlugin.cxx23
3 files changed, 27 insertions, 14 deletions
diff --git a/src/decoder/plugins/FfmpegIo.cxx b/src/decoder/plugins/FfmpegIo.cxx
index 9603a131d..08fddffa5 100644
--- a/src/decoder/plugins/FfmpegIo.cxx
+++ b/src/decoder/plugins/FfmpegIo.cxx
@@ -28,7 +28,10 @@
AvioStream::~AvioStream()
{
- av_free(io);
+ if (io != nullptr) {
+ av_free(io->buffer);
+ av_free(io);
+ }
}
inline int
@@ -90,9 +93,18 @@ AvioStream::_Seek(void *opaque, int64_t pos, int whence)
bool
AvioStream::Open()
{
- io = avio_alloc_context(buffer, sizeof(buffer),
+ constexpr size_t BUFFER_SIZE = 8192;
+ auto buffer = (unsigned char *)av_malloc(BUFFER_SIZE);
+ if (buffer == nullptr)
+ return false;
+
+ io = avio_alloc_context(buffer, BUFFER_SIZE,
false, this,
_Read, nullptr,
input.IsSeekable() ? _Seek : nullptr);
+ /* If avio_alloc_context() fails, who frees the buffer? The
+ libavformat API documentation does not specify this, it
+ only says that AVIOContext.buffer must be freed in the end,
+ however no AVIOContext exists in that failure code path. */
return io != nullptr;
}
diff --git a/src/decoder/plugins/FfmpegIo.hxx b/src/decoder/plugins/FfmpegIo.hxx
index add4b40e7..2deb7fd38 100644
--- a/src/decoder/plugins/FfmpegIo.hxx
+++ b/src/decoder/plugins/FfmpegIo.hxx
@@ -37,8 +37,6 @@ struct AvioStream {
AVIOContext *io;
- uint8_t buffer[8192];
-
AvioStream(Decoder *_decoder, InputStream &_input)
:decoder(_decoder), input(_input), io(nullptr) {}
diff --git a/src/decoder/plugins/GmeDecoderPlugin.cxx b/src/decoder/plugins/GmeDecoderPlugin.cxx
index 693237f2f..cdaa68dcf 100644
--- a/src/decoder/plugins/GmeDecoderPlugin.cxx
+++ b/src/decoder/plugins/GmeDecoderPlugin.cxx
@@ -157,8 +157,11 @@ gme_file_decode(Decoder &decoder, Path path_fs)
return;
}
- const SignedSongTime song_len = ti->length > 0
- ? SignedSongTime::FromMS(ti->length)
+ const int length = ti->play_length;
+ gme_free_info(ti);
+
+ const SignedSongTime song_len = length > 0
+ ? SignedSongTime::FromMS(length)
: SignedSongTime::Negative();
/* initialize the MPD decoder */
@@ -169,7 +172,6 @@ gme_file_decode(Decoder &decoder, Path path_fs)
SampleFormat::S16, GME_CHANNELS,
error)) {
LogError(error);
- gme_free_info(ti);
gme_delete(emu);
return;
}
@@ -180,8 +182,8 @@ gme_file_decode(Decoder &decoder, Path path_fs)
if (gme_err != nullptr)
LogWarning(gme_domain, gme_err);
- if (ti->length > 0)
- gme_set_fade(emu, ti->length);
+ if (length > 0)
+ gme_set_fade(emu, length);
/* play */
DecoderCommand cmd;
@@ -197,16 +199,17 @@ gme_file_decode(Decoder &decoder, Path path_fs)
if (cmd == DecoderCommand::SEEK) {
unsigned where = decoder_seek_time(decoder).ToMS();
gme_err = gme_seek(emu, where);
- if (gme_err != nullptr)
+ if (gme_err != nullptr) {
LogWarning(gme_domain, gme_err);
- decoder_command_finished(decoder);
+ decoder_seek_error(decoder);
+ } else
+ decoder_command_finished(decoder);
}
if (gme_track_ended(emu))
break;
} while (cmd != DecoderCommand::STOP);
- gme_free_info(ti);
gme_delete(emu);
}
@@ -214,9 +217,9 @@ static void
ScanGmeInfo(const gme_info_t &info, unsigned song_num, int track_count,
const struct tag_handler *handler, void *handler_ctx)
{
- if (info.length > 0)
+ if (info.play_length > 0)
tag_handler_invoke_duration(handler, handler_ctx,
- SongTime::FromMS(info.length));
+ SongTime::FromMS(info.play_length));
if (info.song != nullptr) {
if (track_count > 1) {