diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-06-19 15:36:43 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-06-19 15:36:43 +1000 |
| commit | acccd822f0147147dd8b16f059578df073c088c2 (patch) | |
| tree | 59a96429e6be01d8fdceabed5b1ea5786429e995 /src/codecs/mad.cpp | |
| parent | 0c81c3e1f6768dc2c024ea81aecc2abc6dbe9fe9 (diff) | |
| download | tangara-fw-acccd822f0147147dd8b16f059578df073c088c2.tar.gz | |
back to back flac playback is working :)
Diffstat (limited to 'src/codecs/mad.cpp')
| -rw-r--r-- | src/codecs/mad.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp index 8b9897eb..f3f3cffe 100644 --- a/src/codecs/mad.cpp +++ b/src/codecs/mad.cpp @@ -44,6 +44,7 @@ MadMp3Decoder::~MadMp3Decoder() { } auto MadMp3Decoder::GetInputPosition() -> std::size_t { + assert(stream_.next_frame >= stream_.buffer); return stream_.next_frame - stream_.buffer; } @@ -51,7 +52,7 @@ auto MadMp3Decoder::BeginStream(const cpp::span<const std::byte> input) -> Result<OutputFormat> { mad_stream_buffer(&stream_, reinterpret_cast<const unsigned char*>(input.data()), - input.size()); + input.size_bytes()); // Whatever was last synthesized is now invalid, so ensure we don't try to // send it. current_sample_ = -1; @@ -65,11 +66,11 @@ auto MadMp3Decoder::BeginStream(const cpp::span<const std::byte> input) // Recoverable errors are usually malformed parts of the stream. // We can recover from them by just retrying the decode. continue; - } else { - // Don't bother checking for other errors; if the first part of the stream - // doesn't even contain a header then something's gone wrong. - return {GetInputPosition(), cpp::fail(Error::kMalformedData)}; } + if (stream_.error == MAD_ERROR_BUFLEN) { + return {GetInputPosition(), cpp::fail(Error::kOutOfInput)}; + } + return {GetInputPosition(), cpp::fail(Error::kMalformedData)}; } uint8_t channels = MAD_NCHANNELS(&header); |
