Example #1
0
void QMediaRecorderPrivate::restartCamera()
{
    //restart camera if it can't apply new settings in the Active state
    QCamera *camera = qobject_cast<QCamera*>(mediaObject);
    if (camera && camera->captureMode() == QCamera::CaptureVideo) {
        QMetaObject::invokeMethod(camera,
                                  "_q_preparePropertyChange",
                                  Qt::DirectConnection,
                                  Q_ARG(int, QCameraControl::VideoEncodingSettings));
    }
void tst_QCameraBackend::testCtorWithDevice()
{
    if (QCamera::availableDevices().isEmpty())
        QSKIP("Camera selection not supported");

    QCamera *camera = new QCamera(QCamera::availableDevices().first());
    QCOMPARE(camera->error(), QCamera::NoError);
    delete camera;

    //loading non existing camera should fail
    camera = new QCamera(QUuid::createUuid().toByteArray());
    QCOMPARE(camera->error(), QCamera::ServiceMissingError);

    delete camera;
}
void tst_QCameraBackend::testCameraCapture()
{
    QCamera camera;
    QCameraImageCapture imageCapture(&camera);
    //prevents camera to flash during the test
    camera.exposure()->setFlashMode(QCameraExposure::FlashOff);

    QVERIFY(!imageCapture.isReadyForCapture());

    QSignalSpy capturedSignal(&imageCapture, SIGNAL(imageCaptured(int,QImage)));
    QSignalSpy savedSignal(&imageCapture, SIGNAL(imageSaved(int,QString)));
    QSignalSpy errorSignal(&imageCapture, SIGNAL(error(int, QCameraImageCapture::Error,QString)));

    imageCapture.capture();
    QTRY_COMPARE(errorSignal.size(), 1);
    QCOMPARE(imageCapture.error(), QCameraImageCapture::NotReadyError);
    QCOMPARE(capturedSignal.size(), 0);
    errorSignal.clear();

    camera.start();

    QTRY_VERIFY(imageCapture.isReadyForCapture());
    QCOMPARE(camera.status(), QCamera::ActiveStatus);
    QCOMPARE(errorSignal.size(), 0);

    int id = imageCapture.capture();

    QTRY_VERIFY(!savedSignal.isEmpty());

    QCOMPARE(capturedSignal.size(), 1);
    QCOMPARE(capturedSignal.last().first().toInt(), id);
    QCOMPARE(errorSignal.size(), 0);
    QCOMPARE(imageCapture.error(), QCameraImageCapture::NoError);

    QCOMPARE(savedSignal.last().first().toInt(), id);
    QString location = savedSignal.last().last().toString();
    QVERIFY(!location.isEmpty());
    QVERIFY(QFileInfo(location).exists());
    QImageReader reader(location);
    reader.setScaledSize(QSize(320,240));
    QVERIFY(!reader.read().isNull());

    QFile(location).remove();
}
Example #4
0
void MainWindow::initDoorSetup()
{

    connect(m_door,&Door::initialize,this,&MainWindow::onDoorInitialize);
    connect(m_door,&Door::personApproved,this, &MainWindow::onDoorAccessGranted);
    connect(m_door,&Door::personNotApproved,this, &MainWindow::onDoorAccessDenied);
    connect(m_door,&Door::noAnswer,this, &MainWindow::onDoorNoAnswer);

    QCamera* doorCamera = dynamic_cast<QCamera*>(m_configControl.getSensorByName(DOORCAMERA_NAME));

    if (doorCamera != nullptr)
    {
        doorCamera->enableFaceDetection(true);
        connect(m_door,&Door::imageWithFaceIsAvailable, this, &MainWindow::onDoorImageWithFaceIsAvailable);
        m_door->init();
    }
    else
    {
        qCritical () << "DoorCamera not found";
    }
}
void tst_QCameraBackend::testCameraCaptureMetadata()
{
#ifndef Q_WS_MAEMO_6
    QSKIP("Capture metadata is supported only on harmattan");
#endif

    QCamera camera;
    QCameraImageCapture imageCapture(&camera);
    camera.exposure()->setFlashMode(QCameraExposure::FlashOff);

    QSignalSpy metadataSignal(&imageCapture, SIGNAL(imageMetadataAvailable(int,QString,QVariant)));
    QSignalSpy savedSignal(&imageCapture, SIGNAL(imageSaved(int,QString)));

    camera.start();

    QTRY_VERIFY(imageCapture.isReadyForCapture());

    int id = imageCapture.capture(QString::fromLatin1("/dev/null"));
    QTRY_VERIFY(!savedSignal.isEmpty());
    QVERIFY(!metadataSignal.isEmpty());
    QCOMPARE(metadataSignal.first().first().toInt(), id);
}
void tst_QCameraBackend::testExposureMode()
{
#if !defined(Q_WS_MAEMO_6)
    QSKIP("Capture exposure parameters are supported only on mobile platforms");
#endif

    QCamera camera;
    QCameraExposure *exposure = camera.exposure();

#ifdef Q_WS_MAEMO_6
    QEXPECT_FAIL("", "Camerabin reports Manual exposure instead of Auto", Continue);
#endif
    QCOMPARE(exposure->exposureMode(), QCameraExposure::ExposureAuto);

    // Night
    exposure->setExposureMode(QCameraExposure::ExposureNight);
    QCOMPARE(exposure->exposureMode(), QCameraExposure::ExposureNight);
    camera.start();
    QTRY_COMPARE(camera.status(), QCamera::ActiveStatus);
    QCOMPARE(exposure->exposureMode(), QCameraExposure::ExposureNight);

    camera.unload();
    QTRY_COMPARE(camera.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

    // Auto
    exposure->setExposureMode(QCameraExposure::ExposureAuto);
    QCOMPARE(exposure->exposureMode(), QCameraExposure::ExposureAuto);
    camera.start();
    QTRY_COMPARE(camera.status(), QCamera::ActiveStatus);
    QCOMPARE(exposure->exposureMode(), QCameraExposure::ExposureAuto);
}
void tst_QCameraBackend::testExposureCompensation()
{
#if !defined(Q_WS_MAEMO_6)
    QSKIP("Capture exposure parameters are supported only on mobile platforms");
#endif

    QCamera camera;
    QCameraExposure *exposure = camera.exposure();

    QSignalSpy exposureCompensationSignal(exposure, SIGNAL(exposureCompensationChanged(qreal)));

    //it should be possible to set exposure parameters in Unloaded state
    QCOMPARE(exposure->exposureCompensation()+1.0, 1.0);
    exposure->setExposureCompensation(1.0);
    QCOMPARE(exposure->exposureCompensation(), 1.0);
    QTRY_COMPARE(exposureCompensationSignal.count(), 1);
    QCOMPARE(exposureCompensationSignal.last().first().toReal(), 1.0);

    //exposureCompensationChanged should not be emitted when value is not changed
    exposure->setExposureCompensation(1.0);
    QTest::qWait(50);
    QCOMPARE(exposureCompensationSignal.count(), 1);

    //exposure compensation should be preserved during load/start
    camera.load();
    QTRY_COMPARE(camera.status(), QCamera::LoadedStatus);

    QCOMPARE(exposure->exposureCompensation(), 1.0);

    exposureCompensationSignal.clear();
    exposure->setExposureCompensation(-1.0);
    QCOMPARE(exposure->exposureCompensation(), -1.0);
    QTRY_COMPARE(exposureCompensationSignal.count(), 1);
    QCOMPARE(exposureCompensationSignal.last().first().toReal(), -1.0);

    camera.start();
    QTRY_COMPARE(camera.status(), QCamera::ActiveStatus);

    QCOMPARE(exposure->exposureCompensation(), -1.0);

    exposureCompensationSignal.clear();
    exposure->setExposureCompensation(1.0);
    QCOMPARE(exposure->exposureCompensation(), 1.0);
    QTRY_COMPARE(exposureCompensationSignal.count(), 1);
    QCOMPARE(exposureCompensationSignal.last().first().toReal(), 1.0);
}
Example #8
0
int main(){ // the argument list is not used
  // but there is provision for it.

  printf("Welcome to the FIREBALL Guider. Please wait while we configure\n");

    fflush(NULL);

  StartLog();
  GtoM_StartCount(); 
  GtoT_StartCount();
  ResetReceivedMessageCounters();

  trackpointEL = CHIPHEIGHT/2;
  trackpointCE = CHIPWIDTH/2;

  QCamera camera; // open the camera.

  //  UniversalTime();
  //  printf("The Local Sidereal Time is: %lf\n",LST(31.761, -95.63));

  /*
  double ra1, ra2;
  double dec1, dec2;
  double alt1, alt2;
  double az1, az2;
  double del, dce;
  double lat, lon;
  */ 

  GtoT_CameraError(0);

  SetLatLon(31.761,-95.64);

  /*  lat = 31.761;
  lon = -95.64;
  ra1 = 0.50;
  ra2 = 0.51;
  dec1 = 0.41;
  dec2 = 0.41;
  RADEC_to_ALTAZ(ra1,dec1, lat,lon, &alt1,&az1);
  printf("the first alt-az I have found: %lf %lf\n",alt1,az1);
  RADEC_to_ALTAZ(ra2,dec2, lat,lon, &alt2,&az2);
  printf("the second alt-az I have found: %lf %lf\n",alt2,az2);
  ALTAZ_to_ELCE(alt1,az1,alt2,az2,&del,&dce); 
  printf("The difference I have found is: %lf %lf\n",del,dce);
  */
  InitDAC(); // prepare the dac.

  InitializeLEDs(); // turn off the Lamp.

  if(!ComSetup()) GtoT_TextError("COM working");


  //  RunSillyProg();

  StartDisplay(); // begin the display.

  turnOnGps();
  

  // starts some of the statistic quantities. Defaulting to 100 frames -- 10s in full chip mode, 3s in ROI mode. 





  InitMode.setCallback(InitModeCallback);
  AutocollimationMode.setCallback(AutocollimationModeCallback);
  AlignmentMode.setCallback(AlignmentModeCallback);
  AlignmentSubMode.setCallback(AlignmentModeCallback);
  SlewingMode.setCallback(SlewPointModeCallback);
  PointingMode.setCallback(SlewPointModeCallback);
  PointingModeRoi.setCallback(SlewPointModeCallback);
 
  camera.prepSettings(InitMode,0,0);
  if(camera.LoadQCamState()){
    switch(camera.nextMode.getModeID()){
    case INITMODE:{
      camera.nextMode.setCallback(InitModeCallback);
      break;
    };
    case ALIGNMENTMODE:{
      camera.nextMode.setCallback(AlignmentModeCallback);
      alignmentMD.winx = camera.getWinX();
      alignmentMD.winy = camera.getWinY();
      alignmentMD.wind = camera.getWinDX();
      WriteToLog("Stuff","%d %d %d",alignmentMD.winx,alignmentMD.winy,alignmentMD.wind);
      break;
    };
    case SLEWINGMODE:{
      camera.nextMode.setCallback(SlewPointModeCallback);
      break;
    };
    case POINTINGMODE:{
      camera.nextMode.setCallback(SlewPointModeCallback);
      break;
    };
    case AUTOCOLLIMATIONMODE:{
      camera.nextMode.setCallback(AutocollimationModeCallback);
      break;
    };  
    default:
      break;
    };
  };
  //  camera.prepSettings(SlewingMode,0,0);
  //  camera.prepSettings(PointingMode,0,0);
  //  camera.nowMode.setEqual(AlignmentMode);
 
  //    HomeCamera();
  
    //MoveStage(30000);

  // periodicmessages.h/c contains the variables and calls needed to 
  // set up periodic messages that have to be sent to the MPF and the 
  // ground in various modes. 
#include "periodicmessages.h"
  
  // processmessages.h/c contains the variables and calls needed to 
  // process the messages from the MPF and the ground.
#include "processmessages.h"


  //for every change of mode there will be a goto mainloop command
  //to exit a program there will be a goto loopexit command. 

  FillRSquared();
  //  if(camera.getActiveSensor() == GUIDERSENSOR){
  //    GtoM_SwitchingGuiderRequest();
  //  };
  //  HelloDither.DitherPattern1(10);
 MainLoop:
  
  camera.stopStreaming();  // stop camera streaming


  camera.changeSettings(); // adjust camera parameters, including 
                           // the trigger time.

  modeID = camera.getModeID();

  camera.startStreaming(); // restart camera streaming. 


  //  WriteToLog("Got Here! B ");
  loopcounter = 0;

  if(camera.getModeID() == POINTINGMODE || (camera.getModeID()==ALIGNMENTMODE && camera.getSubModeID()==ALIGNTRACKROI)){
    ClearScreen();
    FontOverwrite();
  } else {
    FontMask();
  };
  
  //  WriteToLog("Got Here A !");

  if(camera.getModeID()==ALIGNMENTMODE && (camera.getSubModeID() == ALIGNTRACKROI || camera.getSubModeID() == ALIGNTRACKFULLCHIP || camera.getSubModeID() == ALIGNDRAGFULLCHIP)){
    //    GtoM_SwitchingGuiderRequest();
    //    camera.setActiveSensor(GUIDERSENSOR);
  } else {
    //    GtoM_SwitchingDTURequest();
    //    camera.setActiveSensor(OTHERSENSOR);
  }

  //    WriteToLog("Got Here!");
  //    WriteToLog("FLOOD","%d %d %d" ,camera.getRoiX(), camera.getRoiY(),camera.getRoiDX());
  do{

    #include "periodicmessages.cpp"
    #include "processmessages.cpp"

    camera.queueFrame();
    


  } while(1);
  

  camera.~QCamera();
  CloseLog();

  return 0;
};
Example #9
0
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();
}
void tst_QCameraBackend::initTestCase()
{
    QCamera camera;
    if (!camera.isAvailable())
        QSKIP("Camera is not available");
}
Example #11
0
void tst_QCameraBackend::testCaptureToBuffer()
{
    QCamera camera;
    QCameraImageCapture imageCapture(&camera);
    camera.exposure()->setFlashMode(QCameraExposure::FlashOff);

    camera.load();

#ifdef Q_WS_MAEMO_6
    QVERIFY(imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToBuffer));
#endif

    if (!imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToBuffer))
        QSKIP("Buffer capture not supported");

    QTRY_COMPARE(camera.status(), QCamera::LoadedStatus);

    QCOMPARE(imageCapture.bufferFormat(), QVideoFrame::Format_Jpeg);

    QVERIFY(imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToFile));
    QVERIFY(imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToBuffer));
    QVERIFY(imageCapture.isCaptureDestinationSupported(
                QCameraImageCapture::CaptureToBuffer | QCameraImageCapture::CaptureToFile));

    QSignalSpy destinationChangedSignal(&imageCapture, SIGNAL(captureDestinationChanged(QCameraImageCapture::CaptureDestinations)));

    QCOMPARE(imageCapture.captureDestination(), QCameraImageCapture::CaptureToFile);
    imageCapture.setCaptureDestination(QCameraImageCapture::CaptureToBuffer);
    QCOMPARE(imageCapture.captureDestination(), QCameraImageCapture::CaptureToBuffer);
    QCOMPARE(destinationChangedSignal.size(), 1);
    QCOMPARE(destinationChangedSignal.first().first().value<QCameraImageCapture::CaptureDestinations>(),
             QCameraImageCapture::CaptureToBuffer);

    QSignalSpy capturedSignal(&imageCapture, SIGNAL(imageCaptured(int,QImage)));
    QSignalSpy imageAvailableSignal(&imageCapture, SIGNAL(imageAvailable(int,QVideoFrame)));
    QSignalSpy savedSignal(&imageCapture, SIGNAL(imageSaved(int,QString)));
    QSignalSpy errorSignal(&imageCapture, SIGNAL(error(int, QCameraImageCapture::Error,QString)));

    camera.start();
    QTRY_VERIFY(imageCapture.isReadyForCapture());

    int id = imageCapture.capture();
    QTRY_VERIFY(!imageAvailableSignal.isEmpty());

    QVERIFY(errorSignal.isEmpty());
    QVERIFY(!capturedSignal.isEmpty());
    QVERIFY(!imageAvailableSignal.isEmpty());

    QTest::qWait(2000);
    QVERIFY(savedSignal.isEmpty());

    QCOMPARE(capturedSignal.first().first().toInt(), id);
    QCOMPARE(imageAvailableSignal.first().first().toInt(), id);

    QVideoFrame frame = imageAvailableSignal.first().last().value<QVideoFrame>();
    QVERIFY(frame.isValid());
    QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_Jpeg);
    QVERIFY(!frame.size().isEmpty());
    QVERIFY(frame.map(QAbstractVideoBuffer::ReadOnly));
    QByteArray data((const char *)frame.bits(), frame.mappedBytes());
    frame.unmap();
    frame = QVideoFrame();

    QVERIFY(!data.isEmpty());
    QBuffer buffer;
    buffer.setData(data);
    buffer.open(QIODevice::ReadOnly);
    QImageReader reader(&buffer, "JPG");
    reader.setScaledSize(QSize(640,480));
    QImage img(reader.read());
    QVERIFY(!img.isNull());

    capturedSignal.clear();
    imageAvailableSignal.clear();
    savedSignal.clear();

    //Capture to yuv buffer
#ifdef Q_WS_MAEMO_6
    QVERIFY(imageCapture.supportedBufferFormats().contains(QVideoFrame::Format_UYVY));
#endif

    if (imageCapture.supportedBufferFormats().contains(QVideoFrame::Format_UYVY)) {
        imageCapture.setBufferFormat(QVideoFrame::Format_UYVY);
        QCOMPARE(imageCapture.bufferFormat(), QVideoFrame::Format_UYVY);

        id = imageCapture.capture();
        QTRY_VERIFY(!imageAvailableSignal.isEmpty());

        QVERIFY(errorSignal.isEmpty());
        QVERIFY(!capturedSignal.isEmpty());
        QVERIFY(!imageAvailableSignal.isEmpty());
        QVERIFY(savedSignal.isEmpty());

        QTest::qWait(2000);
        QVERIFY(savedSignal.isEmpty());

        frame = imageAvailableSignal.first().last().value<QVideoFrame>();
        QVERIFY(frame.isValid());

        qDebug() << frame.pixelFormat();
        QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_UYVY);
        QVERIFY(!frame.size().isEmpty());
        frame = QVideoFrame();

        capturedSignal.clear();
        imageAvailableSignal.clear();
        savedSignal.clear();

        imageCapture.setBufferFormat(QVideoFrame::Format_Jpeg);
        QCOMPARE(imageCapture.bufferFormat(), QVideoFrame::Format_Jpeg);
    }

    //Try to capture to both buffer and file
#ifdef Q_WS_MAEMO_6
    QVERIFY(imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToBuffer | QCameraImageCapture::CaptureToFile));
#endif
    if (imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToBuffer | QCameraImageCapture::CaptureToFile)) {
        imageCapture.setCaptureDestination(QCameraImageCapture::CaptureToBuffer | QCameraImageCapture::CaptureToFile);

        int oldId = id;
        id = imageCapture.capture();
        QVERIFY(id != oldId);
        QTRY_VERIFY(!savedSignal.isEmpty());

        QVERIFY(errorSignal.isEmpty());
        QVERIFY(!capturedSignal.isEmpty());
        QVERIFY(!imageAvailableSignal.isEmpty());
        QVERIFY(!savedSignal.isEmpty());

        QCOMPARE(capturedSignal.first().first().toInt(), id);
        QCOMPARE(imageAvailableSignal.first().first().toInt(), id);

        frame = imageAvailableSignal.first().last().value<QVideoFrame>();
        QVERIFY(frame.isValid());
        QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_Jpeg);
        QVERIFY(!frame.size().isEmpty());

        QString fileName = savedSignal.first().last().toString();
        QVERIFY(QFileInfo(fileName).exists());
    }
}
Example #12
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());
}
Example #13
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);
}