void CameraModeControl::setDevice(const QString &device) { if(device != m_device) { m_device = device; if(m_camera) { QMediaObject *mediaObject = m_camera ? qobject_cast<QMediaObject *>(m_camera->property("mediaObject").value<QObject*>()) : nullptr; if(mediaObject) { QVideoDeviceSelectorControl *videoDevice = mediaObject->service()->requestControl<QVideoDeviceSelectorControl*>(); if(videoDevice) { const int value = ("primary" == device) ? 0 : 1; if(videoDevice->selectedDevice() != value) { videoDevice->setSelectedDevice(value); } } } } emit deviceChanged(m_device); } }
void QDeclarativeCamera::setupDevice(const QString &deviceName) { QMediaService *service = m_camera->service(); if (!service) return; QVideoDeviceSelectorControl *deviceControl = qobject_cast<QVideoDeviceSelectorControl*>(service->requestControl(QVideoDeviceSelectorControl_iid)); if (!deviceControl) return; int deviceIndex = -1; if (deviceName.isEmpty()) { deviceIndex = deviceControl->defaultDevice(); } else { for (int i = 0; i < deviceControl->deviceCount(); ++i) { if (deviceControl->deviceName(i) == deviceName) { deviceIndex = i; break; } } } if (deviceIndex == -1) return; State previousState = cameraState(); setCameraState(UnloadedState); deviceControl->setSelectedDevice(deviceIndex); QCameraInfo oldCameraInfo = m_currentCameraInfo; m_currentCameraInfo = QCameraInfo(*m_camera); emit deviceIdChanged(); if (oldCameraInfo.description() != m_currentCameraInfo.description()) emit displayNameChanged(); if (oldCameraInfo.position() != m_currentCameraInfo.position()) emit positionChanged(); if (oldCameraInfo.orientation() != m_currentCameraInfo.orientation()) emit orientationChanged(); setCameraState(previousState); }