コード例 #1
0
void tst_QCameraBackend::testCameraStates()
{
    QCamera camera;
    QCameraImageCapture imageCapture(&camera);

    QSignalSpy errorSignal(&camera, SIGNAL(error(QCamera::Error)));
    QSignalSpy stateChangedSignal(&camera, SIGNAL(stateChanged(QCamera::State)));
    QSignalSpy statusChangedSignal(&camera, SIGNAL(statusChanged(QCamera::Status)));

    QCOMPARE(camera.state(), QCamera::UnloadedState);
    QCOMPARE(camera.status(), QCamera::UnloadedStatus);

    camera.load();
    QCOMPARE(camera.state(), QCamera::LoadedState);
    QCOMPARE(stateChangedSignal.count(), 1);
    QCOMPARE(stateChangedSignal.last().first().value<QCamera::State>(), QCamera::LoadedState);
    QVERIFY(stateChangedSignal.count() > 0);

    QTRY_COMPARE(camera.status(), QCamera::LoadedStatus);
    QCOMPARE(statusChangedSignal.last().first().value<QCamera::Status>(), QCamera::LoadedStatus);

    camera.unload();
    QCOMPARE(camera.state(), QCamera::UnloadedState);
    QCOMPARE(stateChangedSignal.last().first().value<QCamera::State>(), QCamera::UnloadedState);
    QTRY_COMPARE(camera.status(), QCamera::UnloadedStatus);
    QCOMPARE(statusChangedSignal.last().first().value<QCamera::Status>(), QCamera::UnloadedStatus);

#ifdef Q_WS_MAEMO_6
    //resource policy doesn't work correctly when resource is released and immediately requested again.
    QTest::qWait(250);
#endif

    camera.start();
    QCOMPARE(camera.state(), QCamera::ActiveState);
    QCOMPARE(stateChangedSignal.last().first().value<QCamera::State>(), QCamera::ActiveState);
    QTRY_COMPARE(camera.status(), QCamera::ActiveStatus);
    QCOMPARE(statusChangedSignal.last().first().value<QCamera::Status>(), QCamera::ActiveStatus);

    camera.stop();
    QCOMPARE(camera.state(), QCamera::LoadedState);
    QCOMPARE(stateChangedSignal.last().first().value<QCamera::State>(), QCamera::LoadedState);
    QTRY_COMPARE(camera.status(), QCamera::LoadedStatus);
    QCOMPARE(statusChangedSignal.last().first().value<QCamera::Status>(), QCamera::LoadedStatus);

    camera.unload();
    QCOMPARE(camera.state(), QCamera::UnloadedState);
    QCOMPARE(stateChangedSignal.last().first().value<QCamera::State>(), QCamera::UnloadedState);
    QTRY_COMPARE(camera.status(), QCamera::UnloadedStatus);
    QCOMPARE(statusChangedSignal.last().first().value<QCamera::Status>(), QCamera::UnloadedStatus);

    QCOMPARE(camera.errorString(), QString());
    QCOMPARE(errorSignal.count(), 0);
}
コード例 #2
0
ファイル: main.cpp プロジェクト: dhamp/QDSLRCamera
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QList<QByteArray> devices = QCamera::availableDevices();


   // QGPhotoServicePlugin s;

   // devices = s.devices(Q_MEDIASERVICE_CAMERA);


    for (QList<QByteArray>::Iterator i = devices.begin(); i != devices.end(); i ++) {
        QByteArray current = *i;

        cout << QString(current).toStdString() << "\n";
    }

    cout << "### New camera\n";
    cout.flush();

    QCamera *camera = new QCamera(devices[1]);

    cout << "### Camera device description\n";
    cout.flush();
    QString description = camera->deviceDescription(devices.at(1)); //
    std::cout << description.toStdString() << "\n";


    QCameraImageCapture *imageCapture = new QCameraImageCapture(camera); // Object to take pictures
    camera->setCaptureMode(QCamera::CaptureStillImage); // Set the camera mode

    cout << "### Start camera\n";
    cout.flush();


    camera->start();
/*
    camera->searchAndLock();
    imageCapture->capture(QString('/tmp/test.jpg')); // Method to take a picture. Arg: path to save the picture

    camera->unlock();
*/

  //  imageCapture->capture(QString("/tmp/capture.nef"));


    qDebug() << camera->exposure()->supportedApertures();
    qDebug() << camera->exposure()->supportedIsoSensitivities();
    qDebug() << camera->exposure()->supportedShutterSpeeds();

    qDebug() << "Aperture = " << camera->exposure()->aperture();
    qDebug() << "Shutter speed = " << camera->exposure()->shutterSpeed();
    qDebug() << "ISO = " << camera->exposure()->isoSensitivity();

    camera->exposure()->setManualAperture(5.6);
    camera->exposure()->setManualShutterSpeed(10.0);
    camera->exposure()->setManualIsoSensitivity(800);


    cout << "### Stop camera\n";
    cout.flush();
    camera->stop();


    delete imageCapture;
    delete camera;

    return a.exec();
}
コード例 #3
0
void tst_QCameraBackend::testCaptureMode()
{
    QCamera camera;

    QSignalSpy errorSignal(&camera, SIGNAL(error(QCamera::Error)));
    QSignalSpy stateChangedSignal(&camera, SIGNAL(stateChanged(QCamera::State)));
    QSignalSpy captureModeSignal(&camera, SIGNAL(captureModeChanged(QCamera::CaptureModes)));

    QCOMPARE(camera.captureMode(), QCamera::CaptureStillImage);

    if (!camera.isCaptureModeSupported(QCamera::CaptureVideo)) {
        camera.setCaptureMode(QCamera::CaptureVideo);
        QCOMPARE(camera.captureMode(), QCamera::CaptureStillImage);
        QSKIP("Video capture not supported");
    }

    camera.setCaptureMode(QCamera::CaptureVideo);
    QCOMPARE(camera.captureMode(), QCamera::CaptureVideo);
    QTRY_COMPARE(captureModeSignal.size(), 1);
    QCOMPARE(captureModeSignal.last().first().value<QCamera::CaptureModes>(), QCamera::CaptureVideo);
    captureModeSignal.clear();

    camera.load();
    QTRY_COMPARE(camera.status(), QCamera::LoadedStatus);
    //capture mode should still be video
    QCOMPARE(camera.captureMode(), QCamera::CaptureVideo);

    //it should be possible to switch capture mode in Loaded state
    camera.setCaptureMode(QCamera::CaptureStillImage);
    QTRY_COMPARE(captureModeSignal.size(), 1);
    QCOMPARE(captureModeSignal.last().first().value<QCamera::CaptureModes>(), QCamera::CaptureStillImage);
    captureModeSignal.clear();

    camera.setCaptureMode(QCamera::CaptureVideo);
    QTRY_COMPARE(captureModeSignal.size(), 1);
    QCOMPARE(captureModeSignal.last().first().value<QCamera::CaptureModes>(), QCamera::CaptureVideo);
    captureModeSignal.clear();

    camera.start();
    QTRY_COMPARE(camera.status(), QCamera::ActiveStatus);
    //capture mode should still be video
    QCOMPARE(camera.captureMode(), QCamera::CaptureVideo);

    stateChangedSignal.clear();
    //it should be possible to switch capture mode in Active state
    camera.setCaptureMode(QCamera::CaptureStillImage);
    //camera may leave Active status, but should return to Active
    QTest::qWait(10); //camera may leave Active status async
    QTRY_COMPARE(camera.status(), QCamera::ActiveStatus);
    QCOMPARE(camera.captureMode(), QCamera::CaptureStillImage);
    QVERIFY2(stateChangedSignal.isEmpty(), "camera should not change the state during capture mode changes");

    QCOMPARE(captureModeSignal.size(), 1);
    QCOMPARE(captureModeSignal.last().first().value<QCamera::CaptureModes>(), QCamera::CaptureStillImage);
    captureModeSignal.clear();

    camera.setCaptureMode(QCamera::CaptureVideo);
    //camera may leave Active status, but should return to Active
    QTest::qWait(10); //camera may leave Active status async
    QTRY_COMPARE(camera.status(), QCamera::ActiveStatus);
    QCOMPARE(camera.captureMode(), QCamera::CaptureVideo);

    QVERIFY2(stateChangedSignal.isEmpty(), "camera should not change the state during capture mode changes");

    QCOMPARE(captureModeSignal.size(), 1);
    QCOMPARE(captureModeSignal.last().first().value<QCamera::CaptureModes>(), QCamera::CaptureVideo);
    captureModeSignal.clear();

    camera.stop();
    QCOMPARE(camera.captureMode(), QCamera::CaptureVideo);
    camera.unload();
    QCOMPARE(camera.captureMode(), QCamera::CaptureVideo);

    QVERIFY2(errorSignal.isEmpty(), QString("Camera error: %1").arg(camera.errorString()).toLocal8Bit());
}