summaryrefslogtreecommitdiffstats
path: root/Whisper/MF/MediaFoundation.cpp
diff options
context:
space:
mode:
authorKonstantin <const@const.me>2023-01-19 17:10:24 +0100
committerKonstantin <const@const.me>2023-01-19 17:10:24 +0100
commit9df2ee2ead4ce23d06351a6cdb4fea588f79e429 (patch)
treed365bc24b192e3929801a4ede5b26e74a6c9e77f /Whisper/MF/MediaFoundation.cpp
parent06643094c166b0e80fb8f5f506f5e9d42a90c2bf (diff)
Workaround for the Microsoft’s bug in their MP3 decoder MFT
Diffstat (limited to 'Whisper/MF/MediaFoundation.cpp')
-rw-r--r--Whisper/MF/MediaFoundation.cpp21
1 files changed, 20 insertions, 1 deletions
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 <mfreadwrite.h>
#include "mfUtils.h"
#include "AudioCapture.h"
+#include <mfapi.h>
namespace Whisper
{
@@ -15,6 +16,7 @@ namespace Whisper
CComPtr<IMFSourceReader> reader;
bool wantStereo;
CComPtr<iMediaFoundation> 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<const AudioReader*>( ar );
+ r->setPreciseSamplesCount( count );
+ }
+
class MediaFoundation : public ComLight::ObjectRoot<iMediaFoundation>
{
MfStartupRaii raii;