From 67cac1524f56af09289eb76b5e2a38ca6d2a78c6 Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Tue, 22 Sep 2020 13:04:44 +0200 Subject: DirectShow: Use also pin category when negotiating The pin should be negotiated once and use PIN_CATEGORY_CAPTURE. The same logic is implemented in chromium. Change-Id: I89ac13c1a7e982c1011b2a872e853ee5bc2036b2 Reviewed-by: Andy Shaw (cherry picked from commit bf82ab669c53c4b9abb724e197252a788323095e) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/directshow/camera/dscamerasession.cpp | 66 ++++++++++------------- 1 file changed, 29 insertions(+), 37 deletions(-) (limited to 'src/plugins/directshow/camera/dscamerasession.cpp') diff --git a/src/plugins/directshow/camera/dscamerasession.cpp b/src/plugins/directshow/camera/dscamerasession.cpp index 7703aa498..e47142be1 100644 --- a/src/plugins/directshow/camera/dscamerasession.cpp +++ b/src/plugins/directshow/camera/dscamerasession.cpp @@ -428,6 +428,7 @@ bool DSCameraSession::unload() SAFE_RELEASE(m_nullRendererFilter); SAFE_RELEASE(m_filterGraph); SAFE_RELEASE(m_graphBuilder); + SAFE_RELEASE(m_outputPin); setStatus(QCamera::UnloadedStatus); @@ -781,6 +782,9 @@ bool DSCameraSession::createFilterGraph() goto failed; } + if (!DirectShowUtils::getPin(m_sourceFilter, PINDIR_OUTPUT, PIN_CATEGORY_CAPTURE, &m_outputPin, &hr)) + qWarning() << "Failed to get the pin for the video control:" << hr; + // Sample grabber filter if (!m_previewSampleGrabber) { m_previewSampleGrabber = new DirectShowSampleGrabber(this); @@ -1055,24 +1059,18 @@ void DSCameraSession::updateSourceCapabilities() reinterpret_cast(&pVideoControl)); if (FAILED(hr)) { qWarning() << "Failed to get the video control"; - } else { - IPin *pPin = nullptr; - if (!DirectShowUtils::getPin(m_sourceFilter, PINDIR_OUTPUT, &pPin, &hr)) { - qWarning() << "Failed to get the pin for the video control"; - } else { - long supportedModes; - hr = pVideoControl->GetCaps(pPin, &supportedModes); - if (FAILED(hr)) { - qWarning() << "Failed to get the supported modes of the video control"; - } else if (supportedModes & VideoControlFlag_FlipHorizontal) { - long mode; - hr = pVideoControl->GetMode(pPin, &mode); - if (FAILED(hr)) - qWarning() << "Failed to get the mode of the video control"; - else if (supportedModes & VideoControlFlag_FlipHorizontal) - m_needsHorizontalMirroring = (mode & VideoControlFlag_FlipHorizontal); - } - pPin->Release(); + } else if (m_outputPin) { + long supportedModes; + hr = pVideoControl->GetCaps(m_outputPin, &supportedModes); + if (FAILED(hr)) { + qWarning() << "Failed to get the supported modes of the video control"; + } else if (supportedModes & VideoControlFlag_FlipHorizontal) { + long mode; + hr = pVideoControl->GetMode(m_outputPin, &mode); + if (FAILED(hr)) + qWarning() << "Failed to get the mode of the video control"; + else if (supportedModes & VideoControlFlag_FlipHorizontal) + m_needsHorizontalMirroring = (mode & VideoControlFlag_FlipHorizontal); } pVideoControl->Release(); } @@ -1107,28 +1105,22 @@ void DSCameraSession::updateSourceCapabilities() QList frameRateRanges; - if (pVideoControl) { - IPin *pPin = nullptr; - if (!DirectShowUtils::getPin(m_sourceFilter, PINDIR_OUTPUT, &pPin, &hr)) { - qWarning() << "Failed to get the pin for the video control"; - } else { - long listSize = 0; - LONGLONG *frameRates = nullptr; - SIZE size = { resolution.width(), resolution.height() }; - hr = pVideoControl->GetFrameRateList(pPin, iIndex, size, &listSize, &frameRates); - if (hr == S_OK && listSize > 0 && frameRates) { - for (long i = 0; i < listSize; ++i) { - qreal fr = qreal(10000000) / frameRates[i]; - frameRateRanges.append(QCamera::FrameRateRange(fr, fr)); - } - - // Make sure higher frame rates come first - std::sort(frameRateRanges.begin(), frameRateRanges.end(), qt_frameRateRangeGreaterThan); + if (pVideoControl && m_outputPin) { + long listSize = 0; + LONGLONG *frameRates = nullptr; + SIZE size = { resolution.width(), resolution.height() }; + hr = pVideoControl->GetFrameRateList(m_outputPin, iIndex, size, &listSize, &frameRates); + if (hr == S_OK && listSize > 0 && frameRates) { + for (long i = 0; i < listSize; ++i) { + qreal fr = qreal(10000000) / frameRates[i]; + frameRateRanges.append(QCamera::FrameRateRange(fr, fr)); } - CoTaskMemFree(frameRates); - pPin->Release(); + // Make sure higher frame rates come first + std::sort(frameRateRanges.begin(), frameRateRanges.end(), qt_frameRateRangeGreaterThan); } + + CoTaskMemFree(frameRates); } if (frameRateRanges.isEmpty()) { -- cgit v1.2.3