summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Srebrny <piotr.srebrny@qt.io>2022-08-24 07:57:16 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-08-25 11:14:17 +0000
commit65e4b74bca1ec4d17105abdadd0499934df2d137 (patch)
tree7628f18a26d42146388e27ccef07d3fb76222c18
parent14053806740b07f06056ff245c165571d853ef82 (diff)
downloadqtmultimedia-65e4b74bca1ec4d17105abdadd0499934df2d137.tar.gz
Don't list video formats of a camera that are not supported
There is no need to list camera video formats that cannot be used. This breaks tests that expect all enlisted formats to be valid. This patch fixes a memory leak on the mediaFormat variable that was released only once after the whole loop was run. Change-Id: I6b3322a0547318a989067fea40ccc96b7d43cdcf Reviewed-by: André de la Rocha <andre.rocha@qt.io> (cherry picked from commit 920b27fad2bac874c70deae01a546c6412dd1470) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/plugins/multimedia/windows/qwindowsvideodevices.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/plugins/multimedia/windows/qwindowsvideodevices.cpp b/src/plugins/multimedia/windows/qwindowsvideodevices.cpp
index 08f50214b..a6f933bd9 100644
--- a/src/plugins/multimedia/windows/qwindowsvideodevices.cpp
+++ b/src/plugins/multimedia/windows/qwindowsvideodevices.cpp
@@ -6,6 +6,7 @@
#include <private/qcameradevice_p.h>
#include <private/qwindowsmfdefs_p.h>
#include <private/qwindowsmultimediautils_p.h>
+#include <private/qwindowsiupointer_p.h>
#include <Dbt.h>
@@ -146,8 +147,6 @@ QList<QCameraDevice> QWindowsVideoDevices::videoDevices() const
QList<QSize> photoResolutions;
QList<QCameraFormat> videoFormats;
- DWORD dwMediaTypeIndex = 0;
- IMFMediaType *mediaFormat = NULL;
GUID subtype = GUID_NULL;
HRESULT mediaFormatResult = S_OK;
@@ -157,11 +156,12 @@ QList<QCameraDevice> QWindowsVideoDevices::videoDevices() const
UINT32 width = 0u;
UINT32 height = 0u;
- while (SUCCEEDED(mediaFormatResult)) {
+ for (DWORD mediaTypeIndex = 0; SUCCEEDED(mediaFormatResult); ++mediaTypeIndex) {
// Loop through the supported formats for the video device
+ QWindowsIUPointer<IMFMediaType> mediaFormat;
mediaFormatResult = reader->GetNativeMediaType(
- (DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM, dwMediaTypeIndex,
- &mediaFormat);
+ (DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM, mediaTypeIndex,
+ mediaFormat.address());
if (mediaFormatResult == MF_E_NO_MORE_TYPES)
break;
else if (SUCCEEDED(mediaFormatResult)) {
@@ -173,17 +173,22 @@ QList<QCameraDevice> QWindowsVideoDevices::videoDevices() const
if (SUCCEEDED(mediaFormat->GetGUID(MF_MT_SUBTYPE, &subtype)))
pixelFormat = QWindowsMultimediaUtils::pixelFormatFromMediaSubtype(subtype);
- if (SUCCEEDED(MFGetAttributeSize(mediaFormat, MF_MT_FRAME_SIZE, &width,
+ if (pixelFormat == QVideoFrameFormat::Format_Invalid)
+ continue;
+
+ if (SUCCEEDED(MFGetAttributeSize(mediaFormat.get(), MF_MT_FRAME_SIZE, &width,
&height))) {
resolution.rheight() = (int)height;
resolution.rwidth() = (int)width;
photoResolutions << resolution;
+ } else {
+ continue;
}
- if (SUCCEEDED(MFGetAttributeRatio(mediaFormat, MF_MT_FRAME_RATE_RANGE_MIN,
+ if (SUCCEEDED(MFGetAttributeRatio(mediaFormat.get(), MF_MT_FRAME_RATE_RANGE_MIN,
&frameRateMin, &denominator)))
minFr = qreal(frameRateMin) / denominator;
- if (SUCCEEDED(MFGetAttributeRatio(mediaFormat, MF_MT_FRAME_RATE_RANGE_MAX,
+ if (SUCCEEDED(MFGetAttributeRatio(mediaFormat.get(), MF_MT_FRAME_RATE_RANGE_MAX,
&frameRateMax, &denominator)))
maxFr = qreal(frameRateMax) / denominator;
@@ -191,10 +196,7 @@ QList<QCameraDevice> QWindowsVideoDevices::videoDevices() const
resolution, minFr, maxFr };
videoFormats << f->create();
}
- ++dwMediaTypeIndex;
}
- if (mediaFormat)
- mediaFormat->Release();
info->videoFormats = videoFormats;
info->photoResolutions = photoResolutions;