From 9df2ee2ead4ce23d06351a6cdb4fea588f79e429 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 19 Jan 2023 17:10:24 +0100 Subject: Workaround for the Microsoft’s bug in their MP3 decoder MFT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Whisper/MF/MediaFoundation.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'Whisper/MF/MediaFoundation.cpp') diff --git a/Whisper/MF/MediaFoundation.cpp b/Whisper/MF/MediaFoundation.cpp index 4a4f6a2..df6990c 100644 --- a/Whisper/MF/MediaFoundation.cpp +++ b/Whisper/MF/MediaFoundation.cpp @@ -7,6 +7,7 @@ #include #include "mfUtils.h" #include "AudioCapture.h" +#include namespace Whisper { @@ -15,6 +16,7 @@ namespace Whisper CComPtr reader; bool wantStereo; CComPtr mediaFoundation; + mutable int64_t preciseSamplesCount = 0; HRESULT COMLIGHTCALL getReader( IMFSourceReader** pp ) const noexcept override final { @@ -31,7 +33,14 @@ namespace Whisper HRESULT COMLIGHTCALL getDuration( int64_t& rdi ) const noexcept override final { if( reader ) - return getStreamDuration( reader, rdi ); + { + if( 0 == preciseSamplesCount ) + return getStreamDuration( reader, rdi ); + else + { rdi = MFllMulDiv( preciseSamplesCount, 10'000'000, SAMPLE_RATE, 0 ); + return S_OK; + } + } return OLE_E_BLANK; } public: @@ -48,8 +57,18 @@ namespace Whisper logDebug16( L"Created source reader from the file \"%s\"", path ); return S_OK; } + void setPreciseSamplesCount( int64_t count ) const + { + preciseSamplesCount = count; + } }; + void setPreciseSamplesCount( const iAudioReader* ar, int64_t count ) + { + const AudioReader* r = static_cast( ar ); + r->setPreciseSamplesCount( count ); + } + class MediaFoundation : public ComLight::ObjectRoot { MfStartupRaii raii; -- cgit v1.2.3