camerauis/cameraxui/cxengine/src/cxestillcapturecontrolsymbian.cpp
changeset 46 c826656d6714
parent 42 feebad15db8c
child 55 0da2a5b56583
equal deleted inserted replaced
42:feebad15db8c 46:c826656d6714
    20 #include <exception>
    20 #include <exception>
    21 #include <QPixmap>
    21 #include <QPixmap>
    22 #include <coemain.h>
    22 #include <coemain.h>
    23 #include <ECamOrientationCustomInterface2.h>
    23 #include <ECamOrientationCustomInterface2.h>
    24 #include <ecamfacetrackingcustomapi.h>
    24 #include <ecamfacetrackingcustomapi.h>
       
    25 #include <ecamusecasehintcustomapi.h>
    25 
    26 
    26 #include "cxestillcapturecontrolsymbian.h"
    27 #include "cxestillcapturecontrolsymbian.h"
    27 #include "cxeimagedataqueuesymbian.h"
    28 #include "cxeimagedataqueuesymbian.h"
    28 #include "cxefilenamegenerator.h"
    29 #include "cxefilenamegenerator.h"
    29 #include "cxefilesavethread.h"
    30 #include "cxefilesavethread.h"
    41 #include "cxeautofocuscontrol.h"
    42 #include "cxeautofocuscontrol.h"
    42 #include "cxesensoreventhandler.h"
    43 #include "cxesensoreventhandler.h"
    43 #include "cxesensoreventhandler.h"
    44 #include "cxesensoreventhandler.h"
    44 #include "cxequalitypresetssymbian.h"
    45 #include "cxequalitypresetssymbian.h"
    45 #include "cxediskmonitor.h"
    46 #include "cxediskmonitor.h"
       
    47 #include "cxeexception.h"
    46 
    48 
    47 #include "OstTraceDefinitions.h"
    49 #include "OstTraceDefinitions.h"
    48 #ifdef OST_TRACE_COMPILER_IN_USE
    50 #ifdef OST_TRACE_COMPILER_IN_USE
    49 #include "cxestillcapturecontrolsymbianTraces.h"
    51 #include "cxestillcapturecontrolsymbianTraces.h"
    50 #endif
    52 #endif
   246         return;
   248         return;
   247     }
   249     }
   248 
   250 
   249     OstTrace0(camerax_performance, CXESTILLCAPTURECONTROL_PREPARE_IN, "msg: e_CX_STILLCAPCONT_PREPARE 1");
   251     OstTrace0(camerax_performance, CXESTILLCAPTURECONTROL_PREPARE_IN, "msg: e_CX_STILLCAPCONT_PREPARE 1");
   250 
   252 
   251     int err = KErrNone;
   253     CxeError::Id status(CxeError::None);
   252     CxeError::Id cxErr = getImageQualityDetails(mCurrentImageDetails);
   254 
   253     int ecamStillResolutionIndex = 0;
   255     try {
   254 
   256         // Update capture parameters
   255     if (cxErr == CxeError::None) {
   257         updateStillCaptureParameters();
   256         int imageWidth =  mCurrentImageDetails.mWidth;
       
   257         int imageHeight = mCurrentImageDetails.mHeight;
       
   258         CX_DEBUG(("CxeStillCaptureControlSymbian::prepare <> resolution = (%d, %d)", imageWidth, imageHeight));
       
   259 
       
   260         TSize imageSize;
       
   261         imageSize.SetSize(imageWidth, imageHeight);
       
   262 
       
   263         if (mECamSupportedImageResolutions.count() > 0) {
       
   264             ecamStillResolutionIndex = mECamSupportedImageResolutions.indexOf(imageSize);
       
   265         }
       
   266 
       
   267         if (ecamStillResolutionIndex < 0) {
       
   268             CX_DEBUG(("CxeStillCaptureControlSymbian::prepare - WARNING! resolution not supported, falling back to index 0"));
       
   269             ecamStillResolutionIndex = 0;
       
   270         }
       
   271 
   258 
   272         // Prepare Image capture
   259         // Prepare Image capture
   273         CCamera::TFormat imgFormat = supportedStillFormat(mCameraDeviceControl.cameraIndex());
   260         CX_DEBUG(("Calling PrepareImageCaptureL, resolution index = %d", mSizeIndex));
   274         OstTrace0(camerax_performance, CXESTILLCAPTURECONTROL_PREPARE_MID1, "msg: e_CX_PREPARE_IMAGE_CAPTURE 1");
   261         OstTrace0(camerax_performance, CXESTILLCAPTURECONTROL_PREPARE_MID1, "msg: e_CX_PREPARE_IMAGE_CAPTURE 1");
   275         TRAP(err, mCameraDevice.camera()->PrepareImageCaptureL(imgFormat, ecamStillResolutionIndex));
   262         QT_TRAP_THROWING(mCameraDevice.camera()->PrepareImageCaptureL(mCaptureFormat, mSizeIndex));
   276         OstTrace0(camerax_performance, CXESTILLCAPTURECONTROL_PREPARE_MID2, "msg: e_CX_PREPARE_IMAGE_CAPTURE 0");
   263         OstTrace0(camerax_performance, CXESTILLCAPTURECONTROL_PREPARE_MID2, "msg: e_CX_PREPARE_IMAGE_CAPTURE 0");
   277 
   264 
   278         CX_DEBUG(("PrepareImageCaptureL done, err=%d, resolution index = %d", err, ecamStillResolutionIndex));
       
   279 
       
   280         if (!err) {
       
   281             // still capture prepare went fine, try preparing snapshot
       
   282             err = prepareStillSnapshot();
       
   283         }
       
   284     } else {
       
   285         err = KErrNotFound;
       
   286     }
       
   287 
       
   288     if (!err) {
       
   289         // Start viewfinder before claiming to be ready,
   265         // Start viewfinder before claiming to be ready,
   290         // as e.g. pending capture might be started by state change,
   266         // as e.g. pending capture might be started by state change,
   291         // and viewfinder start might have problems with just started capturing.
   267         // and viewfinder start might have problems with just started capturing.
   292         // If viewfinder is already running, this call does nothing.
   268         // If viewfinder is already running, this call does nothing.
   293         mViewfinderControl.start();
   269         mViewfinderControl.start();
   294 
   270 
       
   271         // Prepare snapshot
       
   272         prepareSnapshot();
       
   273 
   295         // Start monitoring disk space.
   274         // Start monitoring disk space.
   296         mDiskMonitor.start();
   275         mDiskMonitor.start();
   297         connect(&mDiskMonitor, SIGNAL(diskSpaceChanged()), this, SLOT(handleDiskSpaceChanged()));
   276         connect(&mDiskMonitor, SIGNAL(diskSpaceChanged()), this, SLOT(handleDiskSpaceChanged()));
   298 
       
   299 
   277 
   300         // Enable AF reticule drawing by adaptation
   278         // Enable AF reticule drawing by adaptation
   301         MCameraFaceTracking *faceTracking = mCameraDevice.faceTracking();
   279         MCameraFaceTracking *faceTracking = mCameraDevice.faceTracking();
   302         if (faceTracking) {
   280         if (faceTracking) {
   303             TRAP_IGNORE(faceTracking->EnableFaceIndicatorsL(ETrue));
   281             TRAP_IGNORE(faceTracking->EnableFaceIndicatorsL(ETrue));
   306         // Still capture and still snapshot are OK.
   284         // Still capture and still snapshot are OK.
   307         // We can safely set state to READY.
   285         // We can safely set state to READY.
   308         setState(Ready);
   286         setState(Ready);
   309 
   287 
   310         // inform zoom control to prepare zoom
   288         // inform zoom control to prepare zoom
   311         emit prepareZoomForStill(ecamStillResolutionIndex);
   289         emit prepareZoomForStill(mSizeIndex);
   312     } else {
   290 
   313         CX_DEBUG(("Image Prepare FAILED! symbian error = %d", err));
   291     } catch (const std::exception &e) {
   314         // release resources
   292         // Exception encountered, free resources.
       
   293         CX_DEBUG(("Image Prepare FAILED! symbian error = %d", qt_symbian_exception2Error(e)));
       
   294         status = CxeErrorHandlingSymbian::map(qt_symbian_exception2Error(e));
   315         deinit();
   295         deinit();
   316     }
   296     }
   317 
   297 
   318     // Inform interested parties that image mode has been prepared for capture
   298     // Inform interested parties that image mode has been prepared for capture
   319     emit imagePrepareComplete(CxeErrorHandlingSymbian::map(err));
   299     emit imagePrepareComplete(status);
   320 
   300 
   321     OstTrace0(camerax_performance, CXESTILLCAPTURECONTROL_GOTOSTILL, "msg: e_CX_GO_TO_STILL_MODE 0");
   301     OstTrace0(camerax_performance, CXESTILLCAPTURECONTROL_GOTOSTILL, "msg: e_CX_GO_TO_STILL_MODE 0");
   322     OstTrace0(camerax_performance, CXESTILLCAPTURECONTROL_PREPARE_OUT, "msg: e_CX_STILLCAPCONT_PREPARE 0");
   302     OstTrace0(camerax_performance, CXESTILLCAPTURECONTROL_PREPARE_OUT, "msg: e_CX_STILLCAPCONT_PREPARE 0");
   323 
       
   324     CX_DEBUG_EXIT_FUNCTION();
   303     CX_DEBUG_EXIT_FUNCTION();
   325 }
   304 }
   326 
   305 
   327 
   306 
   328 
   307 
   329 /*!
   308 /*!
   330  Prepare still snapshot
   309  Prepare still snapshot
   331  Returns symbian error code.
   310  Throws exception on error.
   332  */
   311  */
   333 int CxeStillCaptureControlSymbian::prepareStillSnapshot()
   312 void CxeStillCaptureControlSymbian::prepareSnapshot()
   334 {
   313 {
   335     CX_DEBUG_ENTER_FUNCTION();
   314     CX_DEBUG_ENTER_FUNCTION();
   336     OstTrace0( camerax_performance, CXESTILLCAPTURECONTROL_PREPARESNAP_1, "msg: e_CX_PREPARE_SNAPSHOT 1" );
   315     OstTrace0( camerax_performance, CXESTILLCAPTURECONTROL_PREPARESNAP_1, "msg: e_CX_PREPARE_SNAPSHOT 1" );
   337 
   316 
   338     int status(KErrNone);
   317     QSize snapshotSize = mSnapshotControl.calculateSnapshotSize(
   339     try {
   318                             mViewfinderControl.deviceDisplayResolution(),
   340         QSize snapshotSize = mSnapshotControl.calculateSnapshotSize(
   319                             mCurrentImageDetails.mAspectRatio);
   341                                 mViewfinderControl.deviceDisplayResolution(),
   320     mSnapshotControl.start(snapshotSize);
   342                                 mCurrentImageDetails.mAspectRatio);
   321 
   343         mSnapshotControl.start(snapshotSize);
       
   344     } catch (...) {
       
   345         status = KErrGeneral;
       
   346     }
       
   347     OstTrace0( camerax_performance, CXESTILLCAPTURECONTROL_PREPARESNAP_2, "msg: e_CX_PREPARE_SNAPSHOT 0" );
   322     OstTrace0( camerax_performance, CXESTILLCAPTURECONTROL_PREPARESNAP_2, "msg: e_CX_PREPARE_SNAPSHOT 0" );
   348 
   323     CX_DEBUG_EXIT_FUNCTION();
   349     CX_DEBUG_EXIT_FUNCTION();
   324 }
   350     return status;
   325 
   351 }
   326 
   352 
   327 /*!
   353 
   328     Update image capture parameters. mCurrentImageDetails, mCaptureFormat and
   354 /*!
   329     mSizeIndex are updated based on the current settings.
   355  imageInfo contains image qualities details
   330 */
   356  Returns CxeError error code.
   331 void CxeStillCaptureControlSymbian::updateStillCaptureParameters()
   357  */
   332 {
   358 CxeError::Id CxeStillCaptureControlSymbian::getImageQualityDetails(CxeImageDetails &imageInfo)
   333     CX_DEBUG_ENTER_FUNCTION();
   359 {
   334     OstTrace0( camerax_performance, CXESTILLCAPTURECONTROL_UPDATESTILLCAPTUREPARAMETERS_1, "msg: e_CX_UPDATE_STILL_CAPTURE_PARAMETERS 1" );
   360     CX_DEBUG_ENTER_FUNCTION();
       
   361     OstTrace0( camerax_performance, CXESTILLCAPTURECONTROL_GETQUALITYDETAILS_1, "msg: e_CX_GET_QUALITY_DETAILS 1" );
       
   362 
   335 
   363     int imageQuality = 0;
   336     int imageQuality = 0;
   364     CxeError::Id err = CxeError::None;
   337     CxeError::Id err = CxeError::None;
   365     if (mCameraDeviceControl.cameraIndex() == Cxe::PrimaryCameraIndex) {
   338     if (mCameraDeviceControl.cameraIndex() == Cxe::PrimaryCameraIndex) {
   366         err = mSettings.get(CxeSettingIds::IMAGE_QUALITY, imageQuality);
   339         try {
   367 
   340             imageQuality = mSettings.get<int>(CxeSettingIds::IMAGE_QUALITY);
   368         bool validQuality = (imageQuality >= 0 && imageQuality < mIcmSupportedImageResolutions.count());
   341 
   369 
   342             bool validQuality = (imageQuality >= 0 &&
   370         if (err == CxeError::None && validQuality ) {
   343                                  imageQuality < mIcmSupportedImageResolutions.count());
   371             // get image quality details
   344 
   372             imageInfo = mIcmSupportedImageResolutions.at(imageQuality);
   345             if (validQuality ) {
   373         } else {
   346                 // get image quality details
   374             err = CxeError::NotFound;
   347                 mCurrentImageDetails = mIcmSupportedImageResolutions.at(imageQuality);
   375             CX_DEBUG(("Invalid ImageQuality = %d", imageQuality));
   348             } else {
       
   349                 err = CxeError::NotFound;
       
   350                 CX_DEBUG(("Invalid ImageQuality = %d", imageQuality));
       
   351             }
       
   352         } catch (CxeException &e) {
       
   353             err = (CxeError::Id) e.error();
   376         }
   354         }
   377     } else {
   355     } else {
   378         // we are in secondary camera
   356         // we are in secondary camera
   379         // get secondary camera image quality details
   357         // get secondary camera image quality details
   380        imageInfo = mIcmSupportedImageResolutions.at(imageQuality);
   358        mCurrentImageDetails = mIcmSupportedImageResolutions.at(imageQuality);
   381     }
   359     }
   382 
   360 
   383     OstTrace0( camerax_performance, CXESTILLCAPTURECONTROL_GETQUALITYDETAILS_2, "msg: e_CX_GET_QUALITY_DETAILS 0" );
   361     mSizeIndex = 0;
   384     CX_DEBUG_EXIT_FUNCTION();
   362 
   385     return err;
   363     if (err == CxeError::None) {
       
   364         int imageWidth = mCurrentImageDetails.mWidth;
       
   365         int imageHeight = mCurrentImageDetails.mHeight;
       
   366         CX_DEBUG(("CxeStillCaptureControlSymbian::updateStillCaptureParameters <> resolution = (%d, %d)", imageWidth, imageHeight));
       
   367 
       
   368         TSize imageSize;
       
   369         imageSize.SetSize(imageWidth, imageHeight);
       
   370 
       
   371         if (mECamSupportedImageResolutions.count() > 0) {
       
   372             mSizeIndex = mECamSupportedImageResolutions.indexOf(imageSize);
       
   373         }
       
   374 
       
   375         if (mSizeIndex < 0) {
       
   376             CX_DEBUG(("CxeStillCaptureControlSymbian::updateStillCaptureParameters - WARNING! resolution not supported, falling back to index 0"));
       
   377             mSizeIndex = 0;
       
   378         }
       
   379 
       
   380         mCaptureFormat = supportedStillFormat(mCameraDeviceControl.cameraIndex());
       
   381     }
       
   382 
       
   383     OstTrace0( camerax_performance, CXESTILLCAPTURECONTROL_UPDATESTILLCAPTUREPARAMETERS_2, "msg: e_CX_UPDATE_STILL_CAPTURE_PARAMETERS 0" );
       
   384     CX_DEBUG_EXIT_FUNCTION();
   386 }
   385 }
   387 
   386 
   388 /*!
   387 /*!
   389  * Command to start image capture now.
   388  * Command to start image capture now.
   390  * @sa handleCameraEvent
   389  * @sa handleCameraEvent
   545         //! @todo: this does a deep copy... we want to avoid this for performance/memory consumption reasons
   544         //! @todo: this does a deep copy... we want to avoid this for performance/memory consumption reasons
   546         QByteArray byteArray( reinterpret_cast<const char*>( data->Ptr() ), data->Size() );
   545         QByteArray byteArray( reinterpret_cast<const char*>( data->Ptr() ), data->Size() );
   547         data = NULL;
   546         data = NULL;
   548 
   547 
   549         // get geotagging setting value and check if we have to add location trail to image data.
   548         // get geotagging setting value and check if we have to add location trail to image data.
   550         int value = Cxe::GeoTaggingOff;
   549         Cxe::GeoTagging value = mSettings.get<Cxe::GeoTagging>(CxeSettingIds::GEOTAGGING, Cxe::GeoTaggingOff);
   551         mSettings.get(CxeSettingIds::GEOTAGGING, value);
   550 
   552 
   551 
   553         // Save the image data
   552         // Save the image data
   554         CxeImageDataItemSymbian* dataItem = mImageDataQueue->startSave(byteArray,
   553         CxeImageDataItemSymbian* dataItem = mImageDataQueue->startSave(byteArray,
   555                                                                        stillImage->filename(),
   554                                                                        stillImage->filename(),
   556                                                                        stillImage->id(),
   555                                                                        stillImage->id(),
   866     CX_DEBUG_EXIT_FUNCTION();
   865     CX_DEBUG_EXIT_FUNCTION();
   867 }
   866 }
   868 
   867 
   869 
   868 
   870 /*!
   869 /*!
       
   870     Use ECam Use Case Hint Custom API to inform ECam of our intended use case
       
   871     before calling Reserve().
       
   872 */
       
   873 void CxeStillCaptureControlSymbian::hintUseCase()
       
   874 {
       
   875     CX_DEBUG_ENTER_FUNCTION();
       
   876 
       
   877     // Make sure ECam knows we're doing still image capture so it can prepare
       
   878     // for the correct use case.
       
   879     if (mCameraDeviceControl.mode() == Cxe::ImageMode) {
       
   880         MCameraUseCaseHint *useCaseHintApi = mCameraDevice.useCaseHintApi();
       
   881         if (useCaseHintApi) {
       
   882             updateStillCaptureParameters();
       
   883             TRAP_IGNORE(useCaseHintApi->HintStillCaptureL(mCaptureFormat,
       
   884                                                           mSizeIndex));
       
   885         }
       
   886     }
       
   887 
       
   888     CX_DEBUG_EXIT_FUNCTION();
       
   889 }
       
   890 
       
   891 /*!
   871 * Returns supported image qualities based on the camera index
   892 * Returns supported image qualities based on the camera index
   872 * (primary/secondary).
   893 * (primary/secondary).
   873 */
   894 */
   874 QList<CxeImageDetails> CxeStillCaptureControlSymbian::supportedImageQualities()
   895 QList<CxeImageDetails> CxeStillCaptureControlSymbian::supportedImageQualities()
   875 {
   896 {