From 47600fab8639005c3c05c2b3ec929389260cca0e Mon Sep 17 00:00:00 2001 From: wuggy Date: Tue, 8 Sep 2026 12:57:31 -0700 Subject: [PATCH] Fix DirectShow compile errors --- dom/media/directshow/AudioSinkInputPin.cpp | 3 +- dom/media/directshow/DirectShowReader.cpp | 48 +++------------------- dom/media/directshow/DirectShowReader.h | 6 --- dom/media/directshow/DirectShowUtils.cpp | 11 +++-- dom/media/directshow/SourceFilter.cpp | 1 - dom/media/directshow/moz.build | 1 + toolkit/library/moz.build | 2 + 7 files changed, 14 insertions(+), 58 deletions(-) diff --git a/dom/media/directshow/AudioSinkInputPin.cpp b/dom/media/directshow/AudioSinkInputPin.cpp index 9599c99439..c1ff9d55ea 100644 --- a/dom/media/directshow/AudioSinkInputPin.cpp +++ b/dom/media/directshow/AudioSinkInputPin.cpp @@ -70,8 +70,7 @@ AudioSinkInputPin::CheckMediaType(const MediaType* aMediaType) GUID majorType = *aMediaType->Type(); if (majorType == MEDIATYPE_Video && - (*aMediaType->Subtype() == MEDIASUBTYPE_YUY2 || - *aMediaType->Subtype() == MEDIASUBTYPE_I420) && + *aMediaType->Subtype() == MEDIASUBTYPE_YUY2 && *aMediaType->FormatType() == FORMAT_VideoInfo) { if (aMediaType->cbFormat >= sizeof(VIDEOINFOHEADER)) { memcpy(&mVideoInfo, aMediaType->pbFormat, sizeof(VIDEOINFOHEADER)); diff --git a/dom/media/directshow/DirectShowReader.cpp b/dom/media/directshow/DirectShowReader.cpp index 54364405c2..1e3a2cceed 100644 --- a/dom/media/directshow/DirectShowReader.cpp +++ b/dom/media/directshow/DirectShowReader.cpp @@ -28,7 +28,6 @@ static LazyLogModule gDirectShowLog("DirectShowDecoder"); DirectShowReader::DirectShowReader(AbstractMediaDecoder* aDecoder) : MediaDecoderReader(aDecoder), - mMP3FrameParser(aDecoder->GetResource()->GetLength()), #ifdef DIRECTSHOW_REGISTER_GRAPH mRotRegister(0), #endif @@ -53,34 +52,6 @@ DirectShowReader::~DirectShowReader() #endif } -// Try to parse the MP3 stream to make sure this is indeed an MP3, get the -// estimated duration of the stream, and find the offset of the actual MP3 -// frames in the stream, as DirectShow doesn't like large ID3 sections. -static nsresult -ParseMP3Headers(MP3FrameParser *aParser, MediaResource *aResource) -{ - const uint32_t MAX_READ_SIZE = 4096; - - uint64_t offset = 0; - while (aParser->NeedsData() && !aParser->ParsedHeaders()) { - uint32_t bytesRead; - char buffer[MAX_READ_SIZE]; - nsresult rv = aResource->ReadAt(offset, buffer, - MAX_READ_SIZE, &bytesRead); - NS_ENSURE_SUCCESS(rv, rv); - - if (!bytesRead) { - // End of stream. - return NS_ERROR_FAILURE; - } - - aParser->Parse(reinterpret_cast(buffer), bytesRead, offset); - offset += bytesRead; - } - - return aParser->IsMP3() ? NS_OK : NS_ERROR_FAILURE; -} - nsresult DirectShowReader::ReadMetadata(MediaInfo* aInfo, MetadataTags** aTags) @@ -114,9 +85,6 @@ DirectShowReader::ReadMetadata(MediaInfo* aInfo, return ReadH264Metadata(aInfo, aTags); } - rv = ParseMP3Headers(&mMP3FrameParser, mDecoder->GetResource()); - NS_ENSURE_SUCCESS(rv, rv); - // Build the graph. Create the filters we need, and connect them. We // build the entire graph ourselves to prevent other decoders installed // on the system being created and used. @@ -125,7 +93,7 @@ DirectShowReader::ReadMetadata(MediaInfo* aInfo, mSourceFilter = new SourceFilter(MEDIATYPE_Stream, MEDIASUBTYPE_MPEG1Audio); NS_ENSURE_TRUE(mSourceFilter, NS_ERROR_FAILURE); - rv = mSourceFilter->Init(mDecoder->GetResource(), mMP3FrameParser.GetMP3Offset()); + rv = mSourceFilter->Init(mDecoder->GetResource(), 0); NS_ENSURE_SUCCESS(rv, rv); hr = mGraph->AddFilter(mSourceFilter, L"MozillaDirectShowSource"); @@ -189,16 +157,11 @@ DirectShowReader::ReadMetadata(MediaInfo* aInfo, hr = mMediaSeeking->GetCapabilities(&seekCaps); mInfo.mMediaSeekable = SUCCEEDED(hr) && (AM_SEEKING_CanSeekAbsolute & seekCaps); - int64_t duration = mMP3FrameParser.GetDuration(); - if (SUCCEEDED(hr)) { - mInfo.mMetadataDuration.emplace(TimeUnit::FromMicroseconds(duration)); - } - LOG("Successfully initialized DirectShow MP3 decoder."); LOG("Channels=%u Hz=%u duration=%lld bytesPerSample=%d", mInfo.mAudio.mChannels, mInfo.mAudio.mRate, - RefTimeToUsecs(duration), + 0LL, mBytesPerSample); *aInfo = mInfo; @@ -378,10 +341,9 @@ DirectShowReader::DecodeVideoFrame(bool &aKeyframeSkip, nsTArray y; nsTArray u; nsTArray v; - NS_ENSURE_TRUE(y.SetLength(width * height) && - u.SetLength((width / 2) * (height / 2)) && - v.SetLength((width / 2) * (height / 2)), - Finish(E_OUTOFMEMORY)); + y.SetLength(width * height); + u.SetLength((width / 2) * (height / 2)); + v.SetLength((width / 2) * (height / 2)); for (int32_t row = 0; row < height; ++row) { const uint8_t* src = data + row * stride; for (int32_t x = 0; x < width; x += 2) { diff --git a/dom/media/directshow/DirectShowReader.h b/dom/media/directshow/DirectShowReader.h index e5dd23fac2..32972517a2 100644 --- a/dom/media/directshow/DirectShowReader.h +++ b/dom/media/directshow/DirectShowReader.h @@ -11,7 +11,6 @@ #include "MediaDecoderReader.h" #include "MediaResource.h" #include "mozilla/RefPtr.h" -#include "MP3FrameParser.h" // Add the graph to the Running Object Table so that we can connect // to this graph with GraphEdit/GraphStudio. Note: you must @@ -85,11 +84,6 @@ private: RefPtr mAudioSinkFilter; bool mIsH264; - // Some MP3s are variable bitrate, so DirectShow's duration estimation - // can make its duration estimation based on the wrong bitrate. So we parse - // the MP3 frames to get a more accuate estimate of the duration. - MP3FrameParser mMP3FrameParser; - #ifdef DIRECTSHOW_REGISTER_GRAPH // Used to add/remove the filter graph to the Running Object Table. You can // connect GraphEdit/GraphStudio to the graph to observe and/or debug its diff --git a/dom/media/directshow/DirectShowUtils.cpp b/dom/media/directshow/DirectShowUtils.cpp index 55092645b3..e76b1b2b24 100644 --- a/dom/media/directshow/DirectShowUtils.cpp +++ b/dom/media/directshow/DirectShowUtils.cpp @@ -309,8 +309,7 @@ CanDecodeH264UsingDirectShow() RefPtr devEnum; HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, nullptr, CLSCTX_INPROC_SERVER, - IID_ICreateDevEnum, - reinterpret_cast(getter_AddRefs(devEnum))); + IID_ICreateDevEnum, getter_AddRefs(devEnum)); if (FAILED(hr)) { return false; } @@ -326,9 +325,9 @@ CanDecodeH264UsingDirectShow() ULONG fetched = 0; while (filters->Next(1, getter_AddRefs(moniker), &fetched) == S_OK) { RefPtr bag; - if (SUCCEEDED(moniker->BindToStorage(nullptr, nullptr, + if (SUCCEEDED(moniker->BindToStorage(nullptr, nullptr, IID_IPropertyBag, - reinterpret_cast(getter_AddRefs(bag))))) { + getter_AddRefs(bag)))) { VARIANT value; VariantInit(&value); if (SUCCEEDED(bag->Read(L"FriendlyName", &value, nullptr)) && @@ -354,7 +353,7 @@ AddH264DecoderFilter(IGraphBuilder* aGraph, IBaseFilter** aOutFilter) RefPtr devEnum; HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, nullptr, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, - reinterpret_cast(getter_AddRefs(devEnum))); + getter_AddRefs(devEnum)); NS_ENSURE_TRUE(SUCCEEDED(hr), hr); RefPtr filters; hr = devEnum->CreateClassEnumerator(CLSID_LegacyAmFilterCategory, @@ -368,7 +367,7 @@ AddH264DecoderFilter(IGraphBuilder* aGraph, IBaseFilter** aOutFilter) VariantInit(&value); bool h264 = false; if (SUCCEEDED(moniker->BindToStorage(nullptr, nullptr, IID_IPropertyBag, - reinterpret_cast(getter_AddRefs(bag)))) && + getter_AddRefs(bag))) && SUCCEEDED(bag->Read(L"FriendlyName", &value, nullptr)) && value.vt == VT_BSTR && value.bstrVal) { h264 = wcsstr(value.bstrVal, L"H264") || diff --git a/dom/media/directshow/SourceFilter.cpp b/dom/media/directshow/SourceFilter.cpp index 4c5a0882c3..f5ef11ec78 100644 --- a/dom/media/directshow/SourceFilter.cpp +++ b/dom/media/directshow/SourceFilter.cpp @@ -8,7 +8,6 @@ #include "MediaResource.h" #include "mozilla/RefPtr.h" #include "DirectShowUtils.h" -#include "MP3FrameParser.h" #include "mozilla/Logging.h" #include diff --git a/dom/media/directshow/moz.build b/dom/media/directshow/moz.build index 8a9b762000..06cae45fff 100644 --- a/dom/media/directshow/moz.build +++ b/dom/media/directshow/moz.build @@ -37,5 +37,6 @@ if not CONFIG['MOZ_WEBRTC']: FINAL_LIBRARY = 'xul' LOCAL_INCLUDES += [ + '/dom/media', '/media/webrtc/trunk/webrtc/modules/video_capture/windows', ] diff --git a/toolkit/library/moz.build b/toolkit/library/moz.build index 15c3bcd35a..470f10124b 100644 --- a/toolkit/library/moz.build +++ b/toolkit/library/moz.build @@ -174,6 +174,8 @@ if CONFIG['OS_ARCH'] == 'WINNT': 'shell32', 'ole32', 'strmiids', + 'dmoguids', + 'msdmo', 'version', 'winspool', ]