From 385ed457dd4f78717b00a3673ef40def324021ae Mon Sep 17 00:00:00 2001 From: Robert Kausch Date: Sat, 22 Jan 2022 12:40:24 +0100 Subject: [PATCH] Fix Apple Lossless MD5 calculation. --- components/decoder/alac/alac.cpp | 10 ++++++++++ components/decoder/alac/alac.h | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/components/decoder/alac/alac.cpp b/components/decoder/alac/alac.cpp index d17b90ad..107b0e4c 100644 --- a/components/decoder/alac/alac.cpp +++ b/components/decoder/alac/alac.cpp @@ -166,6 +166,7 @@ BoCA::DecoderALAC::DecoderALAC() sampleId = 1; skipSamples = 0; + samplesLeft = 0; } BoCA::DecoderALAC::~DecoderALAC() @@ -183,6 +184,8 @@ Bool BoCA::DecoderALAC::Activate() driver->Seek(0); + samplesLeft = track.length; + /* Get codec configuration. */ unsigned char *ascBuffer = NIL; @@ -221,6 +224,7 @@ Bool BoCA::DecoderALAC::Seek(Int64 samplePosition) sampleId = ex_MP4GetSampleIdFromTime(mp4File, mp4Track, time, true); skipSamples = time - ex_MP4GetSampleTime(mp4File, mp4Track, sampleId); + samplesLeft = track.length - samplePosition; return True; } @@ -267,6 +271,12 @@ Int BoCA::DecoderALAC::ReadData(Buffer &data) skipSamples -= samplesToSkip; } + /* Cut data buffer on last frame. + */ + data.Resize(Math::Min(data.Size(), samplesLeft * bytesPerSample)); + + samplesLeft -= data.Size() / bytesPerSample; + /* Change to default channel order. */ if (format.channels == 3) Utilities::ChangeChannelOrder(data, format, Channel::AAC_3_0, Channel::Default_3_0); diff --git a/components/decoder/alac/alac.h b/components/decoder/alac/alac.h index 4241ff0a..84794fdd 100644 --- a/components/decoder/alac/alac.h +++ b/components/decoder/alac/alac.h @@ -1,5 +1,5 @@ /* BoCA - BonkEnc Component Architecture - * Copyright (C) 2007-2021 Robert Kausch + * Copyright (C) 2007-2022 Robert Kausch * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -29,6 +29,7 @@ namespace BoCA MP4SampleId sampleId; UnsignedInt skipSamples; + UnsignedInt64 samplesLeft; Buffer dataBuffer;