Android: fix camera preview showing black frames after restarting it.

Clear the camera preview size when stopping the preview in order to
force it to be reset when starting it again.

Task-number: QTBUG-34346
Change-Id: I0edf8d996348745b9aa7cf0790c16b6cd813b33b
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
This commit is contained in:
Yoann Lopes
2013-10-25 15:07:02 +02:00
committed by The Qt Project
parent acbd998749
commit 30cf028fb1
3 changed files with 13 additions and 3 deletions

View File

@@ -238,6 +238,10 @@ void QAndroidCameraFocusControl::updateFocusZones(QCameraFocusZone::FocusZoneSta
return; return;
QSize viewportSize = m_session->camera()->previewSize(); QSize viewportSize = m_session->camera()->previewSize();
if (!viewportSize.isValid())
return;
QSizeF focusSize(50.f / viewportSize.width(), 50.f / viewportSize.height()); QSizeF focusSize(50.f / viewportSize.width(), 50.f / viewportSize.height());
float x = qBound(qreal(0), float x = qBound(qreal(0),
m_actualFocusPoint.x() - (focusSize.width() / 2), m_actualFocusPoint.x() - (focusSize.width() / 2),

View File

@@ -205,8 +205,11 @@ void QAndroidCameraSession::adjustViewfinderSize(const QSize &captureSize, bool
QSize viewfinderResolution = m_camera->previewSize(); QSize viewfinderResolution = m_camera->previewSize();
const qreal aspectRatio = qreal(captureSize.width()) / qreal(captureSize.height()); const qreal aspectRatio = qreal(captureSize.width()) / qreal(captureSize.height());
if (qFuzzyCompare(aspectRatio, qreal(viewfinderResolution.width()) / qreal(viewfinderResolution.height()))) if (viewfinderResolution.isValid() &&
qFuzzyCompare(aspectRatio,
qreal(viewfinderResolution.width()) / viewfinderResolution.height())) {
return; return;
}
QList<QSize> previewSizes = m_camera->getSupportedPreviewSizes(); QList<QSize> previewSizes = m_camera->getSupportedPreviewSizes();
for (int i = previewSizes.count() - 1; i >= 0; --i) { for (int i = previewSizes.count() - 1; i >= 0; --i) {
@@ -270,6 +273,7 @@ void QAndroidCameraSession::stopPreview()
JMultimediaUtils::enableOrientationListener(false); JMultimediaUtils::enableOrientationListener(false);
m_camera->stopPreview(); m_camera->stopPreview();
m_camera->setPreviewSize(QSize());
if (m_videoOutput) if (m_videoOutput)
m_videoOutput->stop(); m_videoOutput->stop();
m_previewStarted = false; m_previewStarted = false;

View File

@@ -261,8 +261,10 @@ void JCamera::setPreviewSize(const QSize &size)
m_previewSize = size; m_previewSize = size;
m_parameters.callMethod<void>("setPreviewSize", "(II)V", size.width(), size.height()); if (m_previewSize.isValid()) {
applyParameters(); m_parameters.callMethod<void>("setPreviewSize", "(II)V", size.width(), size.height());
applyParameters();
}
emit previewSizeChanged(); emit previewSizeChanged();
} }