Example #1
0
int CCamera::Start()
{
    if(m_pCamera)
    {
        Stop();
    }

    m_pCamera = new QCamera(m_CameraPosition);
    if(!m_pCamera)
    {
        LOG_MODEL_WARNING("Video", "Open carmera fail");
        return -1;
    }

    m_pCamera->setCaptureMode(QCamera::CaptureVideo);
    m_CaptureVideoFrame.setSource(m_pCamera);

    connect(m_pCamera, SIGNAL(stateChanged(QCamera::State)), SLOT(updateCameraState(QCamera::State)));
    connect(m_pCamera, SIGNAL(error(QCamera::Error)), SLOT(displayCameraError(QCamera::Error)));

    m_pCamera->start();
    return 0;
}
Example #2
0
void Camera::setCamera(const QCameraInfo& cameraInfo)
{
    // ------------------------------------------------------------------------
    // QCamera
    // ------------------------------------------------------------------------
    m_camera = QSharedPointer<QCamera>(new QCamera(cameraInfo));
    connect(m_camera.data(), &QCamera::stateChanged,
            this, &Camera::updateCameraState);
    // QCamera::error is overloaded.
    // Disambiguate like this:
    void (QCamera::*camera_error)(QCamera::Error) = &QCamera::error;
    connect(m_camera.data(), camera_error,
            this, &Camera::displayCameraError);
    // QCamera::lockStatusChanged is overloaded.
    // Disambiguate like this:
    void (QCamera::*camera_lockstatus)(
                QCamera::LockStatus,
                QCamera::LockChangeReason) = &QCamera::lockStatusChanged;
    connect(m_camera.data(), camera_lockstatus,
            this, &Camera::updateLockStatus);

    // ------------------------------------------------------------------------
    // QCameraImageCapture
    // ------------------------------------------------------------------------
    m_capture = QSharedPointer<QCameraImageCapture>(
                new QCameraImageCapture(m_camera.data()));

    updateCameraState(m_camera->state());

    connect(m_capture.data(), &QCameraImageCapture::readyForCaptureChanged,
            this, &Camera::readyForCapture);
    connect(m_capture.data(), &QCameraImageCapture::imageSaved,
            this, &Camera::imageSaved);
    connect(m_capture.data(), &QCameraImageCapture::imageAvailable,
            this, &Camera::imageAvailable);
    // QCameraImageCapture::error is overloaded.
    // Disambiguate like this:
    void (QCameraImageCapture::*capture_error)(
                int,
                QCameraImageCapture::Error,
                const QString&) = &QCameraImageCapture::error;
    connect(m_capture.data(), capture_error,
            this, &Camera::displayCaptureError);

    bool use_buffer = m_capture->isCaptureDestinationSupported(
                QCameraImageCapture::CaptureToBuffer);
    // use_buffer = false;
    if (use_buffer) {
        qDebug() << Q_FUNC_INFO << "Capturing to buffer";
        m_capture->setCaptureDestination(QCameraImageCapture::CaptureToBuffer);
    } else {
        qDebug() << Q_FUNC_INFO << "Capturing to file";
        m_capture->setCaptureDestination(QCameraImageCapture::CaptureToFile);
    }

    // ------------------------------------------------------------------------
    // QCameraViewfinder
    // ------------------------------------------------------------------------
    m_camera->setViewfinder(m_viewfinder);

    // ------------------------------------------------------------------------
    // Set up; let's go.
    // ------------------------------------------------------------------------
    if (m_camera->isCaptureModeSupported(QCamera::CaptureStillImage)) {
        m_camera->setCaptureMode(QCamera::CaptureStillImage);
    } else {
        qWarning() << Q_FUNC_INFO
                   << "Camera does not support QCamera::CaptureStillImage";
    }
    updateLockStatus(m_camera->lockStatus(),
                     QCamera::LockChangeReason::UserRequest);
    readyForCapture(m_capture->isReadyForCapture());
    m_camera->start();
}