winrt: Wait for focus to finish when camera stopped
Change-Id: I53918a8f7c5f50331593ad09233cd737e040e650 Task-Id: QTBUG-49527 Reviewed-by: Andrew Knight <andrew.knight@intopalo.com> Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com> Reviewed-by: Matti Malinen <matti.malinen@digia.com> Reviewed-by: Maurice Kalinowski <maurice.kalinowski@theqtcompany.com>
This commit is contained in:
@@ -517,6 +517,7 @@ public:
|
||||
ComPtr<MediaSink> mediaSink;
|
||||
ComPtr<IFocusControl> focusControl;
|
||||
ComPtr<IRegionsOfInterestControl> regionsOfInterestControl;
|
||||
ComPtr<IAsyncAction> focusOperation;
|
||||
|
||||
QPointer<QWinRTCameraVideoRendererControl> videoRenderer;
|
||||
QPointer<QWinRTVideoDeviceSelectorControl> videoDeviceSelector;
|
||||
@@ -620,6 +621,11 @@ void QWinRTCameraControl::setState(QCamera::State state)
|
||||
case QCamera::UnloadedState: {
|
||||
// Stop the camera if it is running (transition to LoadedState)
|
||||
if (d->status == QCamera::ActiveStatus) {
|
||||
HRESULT hr;
|
||||
if (d->focusOperation) {
|
||||
hr = QWinRTFunctions::await(d->focusOperation);
|
||||
Q_ASSERT_SUCCEEDED(hr);
|
||||
}
|
||||
if (d->framesMapped > 0) {
|
||||
qWarning("%d QVideoFrame(s) mapped when closing down camera. Camera will wait for unmap before closing down.",
|
||||
d->framesMapped);
|
||||
@@ -1150,17 +1156,26 @@ bool QWinRTCameraControl::setFocusPoint(const QPointF &focusPoint)
|
||||
bool QWinRTCameraControl::focus()
|
||||
{
|
||||
Q_D(QWinRTCameraControl);
|
||||
if (!d->focusControl)
|
||||
HRESULT hr;
|
||||
AsyncStatus status = AsyncStatus::Completed;
|
||||
if (d->focusOperation) {
|
||||
ComPtr<IAsyncInfo> info;
|
||||
hr = d->focusOperation.As(&info);
|
||||
Q_ASSERT_SUCCEEDED(hr);
|
||||
info->get_Status(&status);
|
||||
}
|
||||
|
||||
if (!d->focusControl || status == AsyncStatus::Started)
|
||||
return false;
|
||||
ComPtr<IAsyncAction> op;
|
||||
HRESULT hr = d->focusControl->FocusAsync(&op);
|
||||
|
||||
hr = d->focusControl->FocusAsync(&d->focusOperation);
|
||||
const long errorCode = HRESULT_CODE(hr);
|
||||
if (errorCode == ERROR_OPERATION_IN_PROGRESS
|
||||
|| errorCode == ERROR_WRITE_PROTECT) {
|
||||
return false;
|
||||
}
|
||||
Q_ASSERT_SUCCEEDED(hr);
|
||||
hr = QWinRTFunctions::await(op, QWinRTFunctions::ProcessThreadEvents);
|
||||
hr = QWinRTFunctions::await(d->focusOperation, QWinRTFunctions::ProcessThreadEvents);
|
||||
Q_ASSERT_SUCCEEDED(hr);
|
||||
return hr == S_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user