winrt: Fix crash when initializing certain cameras
Some cameras return video properties when querying for MediaStreamType_Photo, ie. Surface Book. This caused an assert. Instead when asking for photo resolutions, only query the available image resolutions and skip results not of type image. Change-Id: Ia1886a11f47676d6713eec86f3a80c664871a968 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
@@ -101,6 +101,7 @@ HRESULT getMediaStreamResolutions(IMediaDeviceController *device,
|
|||||||
ComPtr<IMediaEncodingProperties> properties;
|
ComPtr<IMediaEncodingProperties> properties;
|
||||||
hr = (*propertiesList)->GetAt(index, &properties);
|
hr = (*propertiesList)->GetAt(index, &properties);
|
||||||
Q_ASSERT_SUCCEEDED(hr);
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
if (type == MediaStreamType_VideoRecord || type == MediaStreamType_VideoPreview) {
|
||||||
ComPtr<IVideoEncodingProperties> videoProperties;
|
ComPtr<IVideoEncodingProperties> videoProperties;
|
||||||
hr = properties.As(&videoProperties);
|
hr = properties.As(&videoProperties);
|
||||||
Q_ASSERT_SUCCEEDED(hr);
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
@@ -110,6 +111,20 @@ HRESULT getMediaStreamResolutions(IMediaDeviceController *device,
|
|||||||
hr = videoProperties->get_Height(&height);
|
hr = videoProperties->get_Height(&height);
|
||||||
Q_ASSERT_SUCCEEDED(hr);
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
resolutions->append(QSize(width, height));
|
resolutions->append(QSize(width, height));
|
||||||
|
} else if (type == MediaStreamType_Photo) {
|
||||||
|
ComPtr<IImageEncodingProperties> imageProperties;
|
||||||
|
hr = properties.As(&imageProperties);
|
||||||
|
// Asking for Photo also returns video resolutions in addition
|
||||||
|
// We skip those, as we are only interested in image Type
|
||||||
|
if (FAILED(hr) || !imageProperties)
|
||||||
|
continue;
|
||||||
|
UINT32 width, height;
|
||||||
|
hr = imageProperties->get_Width(&width);
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
hr = imageProperties->get_Height(&height);
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
resolutions->append(QSize(width, height));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return resolutions->isEmpty() ? MF_E_INVALID_FORMAT : hr;
|
return resolutions->isEmpty() ? MF_E_INVALID_FORMAT : hr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user