Android: don't start camera preview until the viewfinder is ready.
If no video output is set for a camera, don't try to start the camera and report an error. If the video output is not ready, delay starting until it is. Change-Id: Id08e31a4e795b71ac036a6532e9499ca5670d790 Reviewed-by: Christian Stromme <christian.stromme@digia.com>
This commit is contained in:
committed by
The Qt Project
parent
cf4aba93e4
commit
a3a6670172
@@ -168,10 +168,12 @@ void QAndroidCameraSession::setState(QCamera::State state)
|
|||||||
emit error(QCamera::CameraError, QStringLiteral("Failed to open camera"));
|
emit error(QCamera::CameraError, QStringLiteral("Failed to open camera"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (state == QCamera::ActiveState)
|
if (state == QCamera::ActiveState) {
|
||||||
startPreview();
|
if (!startPreview())
|
||||||
else if (state == QCamera::LoadedState)
|
return;
|
||||||
|
} else if (state == QCamera::LoadedState) {
|
||||||
stopPreview();
|
stopPreview();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,10 +318,23 @@ void QAndroidCameraSession::adjustViewfinderSize(const QSize &captureSize, bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QAndroidCameraSession::startPreview()
|
bool QAndroidCameraSession::startPreview()
|
||||||
{
|
{
|
||||||
if (!m_camera || m_previewStarted)
|
if (!m_camera)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
|
if (!m_videoOutput) {
|
||||||
|
Q_EMIT error(QCamera::InvalidRequestError, tr("Camera cannot be started without a viewfinder."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_previewStarted)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (m_videoOutput->isReady())
|
||||||
|
m_camera->setPreviewTexture(m_videoOutput->surfaceTexture());
|
||||||
|
else
|
||||||
|
return true; // delay starting until the video output is ready
|
||||||
|
|
||||||
m_status = QCamera::StartingStatus;
|
m_status = QCamera::StartingStatus;
|
||||||
emit statusChanged(m_status);
|
emit statusChanged(m_status);
|
||||||
@@ -327,13 +342,12 @@ void QAndroidCameraSession::startPreview()
|
|||||||
applyImageSettings();
|
applyImageSettings();
|
||||||
adjustViewfinderSize(m_imageSettings.resolution());
|
adjustViewfinderSize(m_imageSettings.resolution());
|
||||||
|
|
||||||
if (m_videoOutput && m_videoOutput->isReady())
|
|
||||||
onVideoOutputReady(true);
|
|
||||||
|
|
||||||
AndroidMultimediaUtils::enableOrientationListener(true);
|
AndroidMultimediaUtils::enableOrientationListener(true);
|
||||||
|
|
||||||
m_camera->startPreview();
|
m_camera->startPreview();
|
||||||
m_previewStarted = true;
|
m_previewStarted = true;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QAndroidCameraSession::stopPreview()
|
void QAndroidCameraSession::stopPreview()
|
||||||
@@ -683,8 +697,8 @@ QImage QAndroidCameraSession::prepareImageFromPreviewData(const QByteArray &data
|
|||||||
|
|
||||||
void QAndroidCameraSession::onVideoOutputReady(bool ready)
|
void QAndroidCameraSession::onVideoOutputReady(bool ready)
|
||||||
{
|
{
|
||||||
if (m_camera && m_videoOutput && ready)
|
if (ready && m_state == QCamera::ActiveState)
|
||||||
m_camera->setPreviewTexture(m_videoOutput->surfaceTexture());
|
startPreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QAndroidCameraSession::onApplicationStateChanged(Qt::ApplicationState state)
|
void QAndroidCameraSession::onApplicationStateChanged(Qt::ApplicationState state)
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ private:
|
|||||||
bool open();
|
bool open();
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
void startPreview();
|
bool startPreview();
|
||||||
void stopPreview();
|
void stopPreview();
|
||||||
|
|
||||||
void applyImageSettings();
|
void applyImageSettings();
|
||||||
|
|||||||
Reference in New Issue
Block a user