AVFoundation: fix crash when no camera is available on the system.
Change-Id: I0b473babae4d1fae605667957deca21ba1dc0c09 Reviewed-by: Andy Nichols <andy.nichols@digia.com>
This commit is contained in:
committed by
The Qt Project
parent
175bdda347
commit
024c841415
@@ -66,7 +66,7 @@ int AVFVideoDeviceControl::deviceCount() const
|
|||||||
QString AVFVideoDeviceControl::deviceName(int index) const
|
QString AVFVideoDeviceControl::deviceName(int index) const
|
||||||
{
|
{
|
||||||
const QList<QByteArray> &devices = AVFCameraSession::availableCameraDevices();
|
const QList<QByteArray> &devices = AVFCameraSession::availableCameraDevices();
|
||||||
if (index >= devices.count())
|
if (index < 0 || index >= devices.count())
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
return QString::fromUtf8(devices.at(index));
|
return QString::fromUtf8(devices.at(index));
|
||||||
@@ -75,7 +75,7 @@ QString AVFVideoDeviceControl::deviceName(int index) const
|
|||||||
QString AVFVideoDeviceControl::deviceDescription(int index) const
|
QString AVFVideoDeviceControl::deviceDescription(int index) const
|
||||||
{
|
{
|
||||||
const QList<QByteArray> &devices = AVFCameraSession::availableCameraDevices();
|
const QList<QByteArray> &devices = AVFCameraSession::availableCameraDevices();
|
||||||
if (index >= devices.count())
|
if (index < 0 || index >= devices.count())
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
return AVFCameraSession::cameraDeviceInfo(devices.at(index)).description;
|
return AVFCameraSession::cameraDeviceInfo(devices.at(index)).description;
|
||||||
@@ -93,7 +93,9 @@ int AVFVideoDeviceControl::selectedDevice() const
|
|||||||
|
|
||||||
void AVFVideoDeviceControl::setSelectedDevice(int index)
|
void AVFVideoDeviceControl::setSelectedDevice(int index)
|
||||||
{
|
{
|
||||||
if (index != m_selectedDevice) {
|
if (index >= 0 &&
|
||||||
|
index < deviceCount() &&
|
||||||
|
index != m_selectedDevice) {
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
m_selectedDevice = index;
|
m_selectedDevice = index;
|
||||||
Q_EMIT selectedDeviceChanged(index);
|
Q_EMIT selectedDeviceChanged(index);
|
||||||
|
|||||||
Reference in New Issue
Block a user