diff --git a/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp b/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp index 9516f3780e..f0d808d6de 100644 --- a/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp +++ b/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp @@ -362,9 +362,8 @@ String getDeviceID (IMMDevice* device) static EDataFlow getDataFlow (const ComSmartPtr& device) { EDataFlow flow = eRender; - ComSmartPtr endPoint; - if (check (device.QueryInterface (endPoint))) - (void) check (endPoint->GetDataFlow (&flow)); + if (auto endpoint = device.getInterface()) + (void) check (endpoint->GetDataFlow (&flow)); return flow; } @@ -622,22 +621,12 @@ private: return true; } - static ComSmartPtr getClientAsVersion3 (ComSmartPtr& clientVersion1) - { - ComSmartPtr newClient; - - if (clientVersion1 != nullptr) - clientVersion1.QueryInterface (__uuidof (IAudioClient3), newClient); - - return newClient; - } - //============================================================================== void querySupportedBufferSizes (WAVEFORMATEXTENSIBLE format, ComSmartPtr& audioClient) { if (isLowLatencyMode (deviceMode)) { - if (auto audioClient3 = getClientAsVersion3 (audioClient)) + if (auto audioClient3 = audioClient.getInterface()) { UINT32 defaultPeriod = 0, fundamentalPeriod = 0, minPeriod = 0, maxPeriod = 0; @@ -793,7 +782,7 @@ private: bool initialiseLowLatencyClient (int bufferSizeSamples, WAVEFORMATEXTENSIBLE format) { - if (auto audioClient3 = getClientAsVersion3 (client)) + if (auto audioClient3 = client.getInterface()) return check (audioClient3->InitializeSharedAudioStream (getStreamFlags(), bufferSizeSamples, (WAVEFORMATEX*) &format, diff --git a/modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp index c7b6bdaf97..0ceefa3b62 100644 --- a/modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_WindowsMediaAudioFormat.cpp @@ -265,32 +265,23 @@ private: void scanFileForDetails() { - ComSmartPtr wmHeaderInfo; - HRESULT hr = wmSyncReader.QueryInterface (wmHeaderInfo); - - if (SUCCEEDED (hr)) + if (auto wmHeaderInfo = wmSyncReader.getInterface()) { QWORD lengthInNanoseconds = 0; WORD lengthOfLength = sizeof (lengthInNanoseconds); WORD streamNum = 0; WMT_ATTR_DATATYPE wmAttrDataType; - hr = wmHeaderInfo->GetAttributeByName (&streamNum, L"Duration", &wmAttrDataType, - (BYTE*) &lengthInNanoseconds, &lengthOfLength); + wmHeaderInfo->GetAttributeByName (&streamNum, L"Duration", &wmAttrDataType, + (BYTE*) &lengthInNanoseconds, &lengthOfLength); - ComSmartPtr wmProfile; - hr = wmSyncReader.QueryInterface (wmProfile); - - if (SUCCEEDED (hr)) + if (auto wmProfile = wmSyncReader.getInterface()) { ComSmartPtr wmStreamConfig; - hr = wmProfile->GetStream (0, wmStreamConfig.resetAndGetPointerAddress()); + auto hr = wmProfile->GetStream (0, wmStreamConfig.resetAndGetPointerAddress()); if (SUCCEEDED (hr)) { - ComSmartPtr wmMediaProperties; - hr = wmStreamConfig.QueryInterface (wmMediaProperties); - - if (SUCCEEDED (hr)) + if (auto wmMediaProperties = wmStreamConfig.getInterface()) { DWORD sizeMediaType; hr = wmMediaProperties->GetMediaType (0, &sizeMediaType); diff --git a/modules/juce_core/native/juce_win32_ComSmartPtr.h b/modules/juce_core/native/juce_win32_ComSmartPtr.h index 67846965d4..c9232c2e45 100644 --- a/modules/juce_core/native/juce_win32_ComSmartPtr.h +++ b/modules/juce_core/native/juce_win32_ComSmartPtr.h @@ -134,6 +134,17 @@ public: return this->QueryInterface (__uuidof (OtherComClass), destObject); } + template + ComSmartPtr getInterface() const + { + ComSmartPtr destObject; + + if (QueryInterface (destObject) == S_OK) + return destObject; + + return nullptr; + } + private: ComClass* p = nullptr; diff --git a/modules/juce_video/native/juce_win32_CameraDevice.h b/modules/juce_video/native/juce_win32_CameraDevice.h index f91ac025fa..fac85c8002 100644 --- a/modules/juce_video/native/juce_win32_CameraDevice.h +++ b/modules/juce_video/native/juce_win32_CameraDevice.h @@ -69,8 +69,8 @@ struct CameraDevice::Pimpl : public ChangeBroadcaster if (FAILED (hr)) return; - hr = graphBuilder.QueryInterface (mediaControl); - if (FAILED (hr)) + mediaControl = graphBuilder.getInterface(); + if (mediaControl == nullptr) return; { @@ -292,13 +292,10 @@ struct CameraDevice::Pimpl : public ChangeBroadcaster ComSmartPtr pin; if (getPin (filter, PINDIR_OUTPUT, pin)) { - ComSmartPtr pushSource; - HRESULT hr = pin.QueryInterface (pushSource); - - if (pushSource != nullptr) + if (auto pushSource = pin.getInterface()) { REFERENCE_TIME latency = 0; - hr = pushSource->GetLatency (&latency); + pushSource->GetLatency (&latency); firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency); } @@ -364,10 +361,7 @@ struct CameraDevice::Pimpl : public ChangeBroadcaster if (SUCCEEDED (hr)) { - ComSmartPtr fileSink; - hr = asfWriter.QueryInterface (fileSink); - - if (SUCCEEDED (hr)) + if (auto fileSink = asfWriter.getInterface()) { hr = fileSink->SetFileName (file.getFullPathName().toWideCharPointer(), 0); @@ -377,62 +371,63 @@ struct CameraDevice::Pimpl : public ChangeBroadcaster if (SUCCEEDED (hr)) { - ComSmartPtr asfConfig; - hr = asfWriter.QueryInterface (asfConfig); - asfConfig->SetIndexMode (true); - ComSmartPtr profileManager; - hr = WMCreateProfileManager (profileManager.resetAndGetPointerAddress()); - - // This gibberish is the DirectShow profile for a video-only wmv file. - String prof ("" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - ""); - - const int fps[] = { 10, 15, 30 }; - int maxFramesPerSecond = fps [jlimit (0, numElementsInArray (fps) - 1, quality & 0xff)]; - - if ((quality & 0xff000000) != 0) // (internal hacky way to pass explicit frame rates for testing) - maxFramesPerSecond = (quality >> 24) & 0xff; - - prof = prof.replace ("$WIDTH", String (width)) - .replace ("$HEIGHT", String (height)) - .replace ("$AVGTIMEPERFRAME", String (10000000 / maxFramesPerSecond)); - - ComSmartPtr currentProfile; - hr = profileManager->LoadProfileByData (prof.toWideCharPointer(), currentProfile.resetAndGetPointerAddress()); - hr = asfConfig->ConfigureFilterUsingProfile (currentProfile); - - if (SUCCEEDED (hr)) + if (auto asfConfig = asfWriter.getInterface()) { - ComSmartPtr asfWriterInputPin; + asfConfig->SetIndexMode (true); + ComSmartPtr profileManager; + hr = WMCreateProfileManager (profileManager.resetAndGetPointerAddress()); - if (getPin (asfWriter, PINDIR_INPUT, asfWriterInputPin, "Video Input 01")) + // This gibberish is the DirectShow profile for a video-only wmv file. + String prof ("" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ""); + + const int fps[] = { 10, 15, 30 }; + int maxFramesPerSecond = fps[jlimit (0, numElementsInArray (fps) - 1, quality & 0xff)]; + + if ((quality & 0xff000000) != 0) // (internal hacky way to pass explicit frame rates for testing) + maxFramesPerSecond = (quality >> 24) & 0xff; + + prof = prof.replace ("$WIDTH", String (width)) + .replace ("$HEIGHT", String (height)) + .replace ("$AVGTIMEPERFRAME", String (10000000 / maxFramesPerSecond)); + + ComSmartPtr currentProfile; + hr = profileManager->LoadProfileByData (prof.toWideCharPointer(), currentProfile.resetAndGetPointerAddress()); + hr = asfConfig->ConfigureFilterUsingProfile (currentProfile); + + if (SUCCEEDED (hr)) { - hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin); + ComSmartPtr asfWriterInputPin; - if (SUCCEEDED (hr) && openedSuccessfully && activeUsers > 0 - && SUCCEEDED (mediaControl->Run())) + if (getPin (asfWriter, PINDIR_INPUT, asfWriterInputPin, "Video Input 01")) { - previewMaxFPS = (quality < 2) ? 15 : 25; // throttle back the preview comps to try to leave the cpu free for encoding + hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin); - if ((quality & 0x00ff0000) != 0) // (internal hacky way to pass explicit frame rates for testing) - previewMaxFPS = (quality >> 16) & 0xff; + if (SUCCEEDED (hr) && openedSuccessfully && activeUsers > 0 + && SUCCEEDED (mediaControl->Run())) + { + previewMaxFPS = (quality < 2) ? 15 : 25; // throttle back the preview comps to try to leave the cpu free for encoding - return true; + if ((quality & 0x00ff0000) != 0) // (internal hacky way to pass explicit frame rates for testing) + previewMaxFPS = (quality >> 16) & 0xff; + + return true; + } } } }