camerauis/cameraxui/cxengine/src/cxestillcapturecontrolsymbian.cpp
changeset 37 64817133cd1d
parent 36 b12f3922a74f
child 48 42ba2d16bf40
equal deleted inserted replaced
36:b12f3922a74f 37:64817133cd1d
    54 namespace
    54 namespace
    55 {
    55 {
    56     const TInt64 KMinRequiredSpaceImage = 2000000;
    56     const TInt64 KMinRequiredSpaceImage = 2000000;
    57 }
    57 }
    58 
    58 
    59 /**
    59 /*!
    60  * Constructor.
    60  * Constructor.
    61  */
    61  */
    62 CxeStillCaptureControlSymbian::CxeStillCaptureControlSymbian(
    62 CxeStillCaptureControlSymbian::CxeStillCaptureControlSymbian(
    63     CxeCameraDevice &cameraDevice,
    63     CxeCameraDevice &cameraDevice,
    64     CxeViewfinderControl &viewfinderControl,
    64     CxeViewfinderControl &viewfinderControl,
   116 
   116 
   117     // Connect ECam image buffer ready event
   117     // Connect ECam image buffer ready event
   118     connect(&mCameraDeviceControl, SIGNAL(imageBufferReady(MCameraBuffer*,int)),
   118     connect(&mCameraDeviceControl, SIGNAL(imageBufferReady(MCameraBuffer*,int)),
   119             this, SLOT(handleImageData(MCameraBuffer*,int)));
   119             this, SLOT(handleImageData(MCameraBuffer*,int)));
   120     // connect snapshot ready signal
   120     // connect snapshot ready signal
   121     connect(&mSnapshotControl, SIGNAL(snapshotReady(CxeError::Id, const QPixmap&)),
   121     connect(&mSnapshotControl, SIGNAL(snapshotReady(CxeError::Id, const QImage&)),
   122             this, SLOT(handleSnapshotReady(CxeError::Id, const QPixmap&)));
   122             this, SLOT(handleSnapshotReady(CxeError::Id, const QImage&)));
   123 
   123 
   124     OstTrace0(camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_CREATE_MID2, "msg: e_CX_ENGINE_CONNECT_SIGNALS 0");
   124     OstTrace0(camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_CREATE_MID2, "msg: e_CX_ENGINE_CONNECT_SIGNALS 0");
   125 
   125 
   126     mImageDataQueue = new CxeImageDataQueueSymbian();
   126     mImageDataQueue = new CxeImageDataQueueSymbian();
   127     mAutoFocusSoundPlayer = new CxeSoundPlayerSymbian(CxeSoundPlayerSymbian::AutoFocus);
   127     mAutoFocusSoundPlayer = new CxeSoundPlayerSymbian(CxeSoundPlayerSymbian::AutoFocus, mSettings);
   128     mCaptureSoundPlayer = new CxeSoundPlayerSymbian(CxeSoundPlayerSymbian::StillCapture);
   128     mCaptureSoundPlayer = new CxeSoundPlayerSymbian(CxeSoundPlayerSymbian::StillCapture, mSettings);
   129 
   129 
   130     OstTrace0(camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_CREATE_OUT, "msg: e_CX_STILLCAPTURECONTROL_NEW 0");
   130     OstTrace0(camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_CREATE_OUT, "msg: e_CX_STILLCAPTURECONTROL_NEW 0");
   131     CX_DEBUG_EXIT_FUNCTION();
   131     CX_DEBUG_EXIT_FUNCTION();
   132 }
   132 }
   133 
   133 
   134 /**
   134 /*!
   135  * Destructor.
   135  * Destructor.
   136  */
   136  */
   137 CxeStillCaptureControlSymbian::~CxeStillCaptureControlSymbian()
   137 CxeStillCaptureControlSymbian::~CxeStillCaptureControlSymbian()
   138 {
   138 {
   139     CX_DEBUG_ENTER_FUNCTION();
   139     CX_DEBUG_ENTER_FUNCTION();
   147     delete mAutoFocusSoundPlayer;
   147     delete mAutoFocusSoundPlayer;
   148 
   148 
   149     CX_DEBUG_EXIT_FUNCTION();
   149     CX_DEBUG_EXIT_FUNCTION();
   150 }
   150 }
   151 
   151 
   152 /**
   152 /*!
   153  * Return the current state.
   153  * Return the current state.
   154  */
   154  */
   155 CxeStillCaptureControl::State CxeStillCaptureControlSymbian::state() const
   155 CxeStillCaptureControl::State CxeStillCaptureControlSymbian::state() const
   156 {
   156 {
   157     return static_cast<CxeStillCaptureControl::State>( stateId() );
   157     return static_cast<CxeStillCaptureControl::State>( stateId() );
   158 }
   158 }
   159 
   159 
   160 /**
   160 /*!
   161  * Handle state changed event. Normally just emits the signal
   161  * Handle state changed event. Normally just emits the signal
   162  * for observers to react appropriately.
   162  * for observers to react appropriately.
   163  */
   163  */
   164 void CxeStillCaptureControlSymbian::handleStateChanged( int newStateId, CxeError::Id error )
   164 void CxeStillCaptureControlSymbian::handleStateChanged( int newStateId, CxeError::Id error )
   165 {
   165 {
   166     emit stateChanged( static_cast<State>( newStateId ), error );
   166     emit stateChanged( static_cast<State>( newStateId ), error );
   167 }
   167 }
   168 
   168 
   169 /**
   169 /*!
   170  * Initialize the control states.
   170  * Initialize the control states.
   171  */
   171  */
   172 void CxeStillCaptureControlSymbian::initializeStates()
   172 void CxeStillCaptureControlSymbian::initializeStates()
   173 {
   173 {
   174     // addState( id, name, allowed next states )
   174     // addState( id, name, allowed next states )
   177     addState(new CxeState( Capturing , "Capturing", Uninitialized | Ready));
   177     addState(new CxeState( Capturing , "Capturing", Uninitialized | Ready));
   178 
   178 
   179     setInitialState(Uninitialized);
   179     setInitialState(Uninitialized);
   180 }
   180 }
   181 
   181 
   182 /**
   182 /*!
   183  * Initialize the still image capture control.
   183  * Initialize the still image capture control.
   184  */
   184  */
   185 void CxeStillCaptureControlSymbian::init()
   185 void CxeStillCaptureControlSymbian::init()
   186 {
   186 {
   187     CX_DEBUG_ENTER_FUNCTION();
   187     CX_DEBUG_ENTER_FUNCTION();
   195 
   195 
   196     OstTrace0(camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_INIT_OUT, "msg: e_CX_STILL_CAPCONT_INIT 0");
   196     OstTrace0(camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_INIT_OUT, "msg: e_CX_STILL_CAPCONT_INIT 0");
   197     CX_DEBUG_EXIT_FUNCTION();
   197     CX_DEBUG_EXIT_FUNCTION();
   198 }
   198 }
   199 
   199 
   200 /**
   200 /*!
   201  * Un-initialize the image mode.
   201  * Un-initialize the image mode.
   202  */
   202  */
   203 void CxeStillCaptureControlSymbian::deinit()
   203 void CxeStillCaptureControlSymbian::deinit()
   204 {
   204 {
   205     CX_DEBUG_ENTER_FUNCTION();
   205     CX_DEBUG_ENTER_FUNCTION();
   232     OstTrace0( camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_DEINIT_OUT, "msg: e_CX_STILL_CAPCONT_DEINIT 0" );
   232     OstTrace0( camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_DEINIT_OUT, "msg: e_CX_STILL_CAPCONT_DEINIT 0" );
   233     CX_DEBUG_EXIT_FUNCTION();
   233     CX_DEBUG_EXIT_FUNCTION();
   234 }
   234 }
   235 
   235 
   236 
   236 
   237 /**!
   237 /*!
   238  * Prepare still capture mode.
   238  * Prepare still capture mode.
   239  */
   239  */
   240 void CxeStillCaptureControlSymbian::prepare()
   240 void CxeStillCaptureControlSymbian::prepare()
   241 {
   241 {
   242     CX_DEBUG_ENTER_FUNCTION();
   242     CX_DEBUG_ENTER_FUNCTION();
   323     CX_DEBUG_EXIT_FUNCTION();
   323     CX_DEBUG_EXIT_FUNCTION();
   324 }
   324 }
   325 
   325 
   326 
   326 
   327 
   327 
   328 /**!
   328 /*!
   329  Prepare still snapshot
   329  Prepare still snapshot
   330  Returns symbian error code.
   330  Returns symbian error code.
   331  */
   331  */
   332 int CxeStillCaptureControlSymbian::prepareStillSnapshot()
   332 int CxeStillCaptureControlSymbian::prepareStillSnapshot()
   333 {
   333 {
   336 
   336 
   337     int status(KErrNone);
   337     int status(KErrNone);
   338     try {
   338     try {
   339         QSize snapshotSize = mSnapshotControl.calculateSnapshotSize(
   339         QSize snapshotSize = mSnapshotControl.calculateSnapshotSize(
   340                                 mViewfinderControl.deviceDisplayResolution(),
   340                                 mViewfinderControl.deviceDisplayResolution(),
   341                                 QSize(mCurrentImageDetails.mWidth, mCurrentImageDetails.mHeight));
   341                                 mCurrentImageDetails.mAspectRatio);
   342         mSnapshotControl.start(snapshotSize);
   342         mSnapshotControl.start(snapshotSize);
   343     } catch (...) {
   343     } catch (...) {
   344         status = KErrGeneral;
   344         status = KErrGeneral;
   345     }
   345     }
   346     OstTrace0( camerax_performance, DUP5_CXESTILLCAPTURECONTROLSYMBIAN_PREPARE, "msg: e_CX_PREPARE_SNAPSHOT 0" );
   346     OstTrace0( camerax_performance, DUP5_CXESTILLCAPTURECONTROLSYMBIAN_PREPARE, "msg: e_CX_PREPARE_SNAPSHOT 0" );
   348     CX_DEBUG_EXIT_FUNCTION();
   348     CX_DEBUG_EXIT_FUNCTION();
   349     return status;
   349     return status;
   350 }
   350 }
   351 
   351 
   352 
   352 
   353 /**!
   353 /*!
   354  imageInfo contains image qualities details
   354  imageInfo contains image qualities details
   355  Returns CxeError error code.
   355  Returns CxeError error code.
   356  */
   356  */
   357 CxeError::Id CxeStillCaptureControlSymbian::getImageQualityDetails(CxeImageDetails &imageInfo)
   357 CxeError::Id CxeStillCaptureControlSymbian::getImageQualityDetails(CxeImageDetails &imageInfo)
   358 {
   358 {
   420 
   420 
   421     CX_DEBUG_EXIT_FUNCTION();
   421     CX_DEBUG_EXIT_FUNCTION();
   422 }
   422 }
   423 
   423 
   424 
   424 
   425 /* !
   425 /*!
   426 @Param cameraIndex indicates which camera we are in use, primary/secondary
   426 @Param cameraIndex indicates which camera we are in use, primary/secondary
   427 Returns the format we use for specific camera index.
   427 Returns the format we use for specific camera index.
   428 */
   428 */
   429 CCamera::TFormat CxeStillCaptureControlSymbian::supportedStillFormat(Cxe::CameraIndex cameraIndex)
   429 CCamera::TFormat CxeStillCaptureControlSymbian::supportedStillFormat(Cxe::CameraIndex cameraIndex)
   430 {
   430 {
   437     CX_DEBUG_EXIT_FUNCTION();
   437     CX_DEBUG_EXIT_FUNCTION();
   438 
   438 
   439     return imgFormat;
   439     return imgFormat;
   440 }
   440 }
   441 
   441 
   442 /**
   442 /*!
   443  * Snapshot ready notification. Ask the snapshot from snapshot interface.
   443  * Snapshot ready notification. Ask the snapshot from snapshot interface.
   444  * NB: Typically snapshot arrives before image data but can be in reverse
   444  * NB: Typically snapshot arrives before image data but can be in reverse
   445  * order as well.
   445  * order as well.
   446  */
   446  *
   447 void CxeStillCaptureControlSymbian::handleSnapshotReady(CxeError::Id status, const QPixmap& snapshot)
   447  * @param status Status of snapshot creation. CxeError::None if no error, otherwise contains the error code.
       
   448  * @param snapshot Snapshot as QImage
       
   449  */
       
   450 void CxeStillCaptureControlSymbian::handleSnapshotReady(CxeError::Id status, const QImage &snapshot)
   448 {
   451 {
   449     CX_DEBUG_ENTER_FUNCTION();
   452     CX_DEBUG_ENTER_FUNCTION();
   450     if (mCameraDeviceControl.mode() == Cxe::ImageMode) {
   453     if (mCameraDeviceControl.mode() == Cxe::ImageMode) {
   451 
   454 
   452         OstTrace0( camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_HANDLESNAPSHOTEVENT, "msg: e_CX_HANDLE_SNAPSHOT 1" );
   455         OstTrace0( camerax_performance, CXESTILLCAPTURECONTROLSYMBIAN_HANDLESNAPSHOTEVENT, "msg: e_CX_HANDLE_SNAPSHOT 1" );
   453 
   456 
       
   457         QPixmap ss = QPixmap::fromImage(snapshot);
   454         // Get image container for current snapshot index.
   458         // Get image container for current snapshot index.
   455         // Remember to increment counter.
   459         // Remember to increment counter.
   456         CxeStillImageSymbian* stillImage = getImageForIndex(mNextSnapshotIndex++);
   460         CxeStillImageSymbian* stillImage = getImageForIndex(mNextSnapshotIndex++);
   457         if (status == CxeError::None) {
   461         if (status == CxeError::None) {
   458             stillImage->setSnapshot(snapshot);
   462             stillImage->setSnapshot(ss);
   459         }
   463         }
   460 
   464 
   461         // Emit snapshotReady signal in all cases (error or not)
   465         // Emit snapshotReady signal in all cases (error or not)
   462         emit snapshotReady(status, snapshot, stillImage->id());
   466         emit snapshotReady(status, snapshot, stillImage->id());
   463 
   467 
   488         }
   492         }
   489     }
   493     }
   490 }
   494 }
   491 
   495 
   492 
   496 
   493 /**
   497 /*!
   494  * handleImageData: Image data received from ECam
   498  * handleImageData: Image data received from ECam
   495  */
   499  */
   496 void CxeStillCaptureControlSymbian::handleImageData(MCameraBuffer* cameraBuffer, int error)
   500 void CxeStillCaptureControlSymbian::handleImageData(MCameraBuffer* cameraBuffer, int error)
   497 {
   501 {
   498     CX_DEBUG_ENTER_FUNCTION();
   502     CX_DEBUG_ENTER_FUNCTION();
   537     if (!symbErr) {
   541     if (!symbErr) {
   538         //! @todo: this does a deep copy... we want to avoid this for performance/memory consumption reasons
   542         //! @todo: this does a deep copy... we want to avoid this for performance/memory consumption reasons
   539         QByteArray byteArray( reinterpret_cast<const char*>( data->Ptr() ), data->Size() );
   543         QByteArray byteArray( reinterpret_cast<const char*>( data->Ptr() ), data->Size() );
   540         data = NULL;
   544         data = NULL;
   541 
   545 
       
   546         // get geotagging setting value and check if we have to add location trail to image data.
       
   547         int value = Cxe::GeoTaggingOff;
       
   548         mSettings.get(CxeSettingIds::GEOTAGGING, value);
       
   549 
   542         // Save the image data
   550         // Save the image data
   543         CxeImageDataItemSymbian* dataItem = mImageDataQueue->startSave(byteArray, stillImage->filename(), stillImage->id());
   551         CxeImageDataItemSymbian* dataItem = mImageDataQueue->startSave(byteArray,
       
   552                                                                        stillImage->filename(),
       
   553                                                                        stillImage->id(),
       
   554                                                                        value == Cxe::GeoTaggingOn);
   544         stillImage->setDataItem(dataItem);
   555         stillImage->setDataItem(dataItem);
   545         mFileSaveThread.save(dataItem); // Saving thread takes ownership of dataItem.
   556         mFileSaveThread.save(dataItem); // Saving thread takes ownership of dataItem.
   546     }
   557     }
   547 
   558 
   548     // ECam Camera buffer should always be released
   559     // ECam Camera buffer should always be released
   559 
   570 
   560     CX_DEBUG_EXIT_FUNCTION();
   571     CX_DEBUG_EXIT_FUNCTION();
   561 }
   572 }
   562 
   573 
   563 
   574 
   564 /**
   575 /*!
   565  * Settings changed, needs updated
   576  * Settings changed, needs updated
   566  */
   577  */
   567 void CxeStillCaptureControlSymbian::handleSettingValueChanged(const QString& settingId, QVariant newValue)
   578 void CxeStillCaptureControlSymbian::handleSettingValueChanged(const QString& settingId, QVariant newValue)
   568 {
   579 {
   569     CX_DEBUG_ENTER_FUNCTION();
   580     CX_DEBUG_ENTER_FUNCTION();
   604     }
   615     }
   605 
   616 
   606     CX_DEBUG_EXIT_FUNCTION();
   617     CX_DEBUG_EXIT_FUNCTION();
   607 }
   618 }
   608 
   619 
   609 /**
   620 /*!
   610  * ECam reference changing, release resources
   621  * ECam reference changing, release resources
   611  */
   622  */
   612 void CxeStillCaptureControlSymbian::prepareForCameraDelete()
   623 void CxeStillCaptureControlSymbian::prepareForCameraDelete()
   613 {
   624 {
   614     CX_DEBUG_ENTER_FUNCTION();
   625     CX_DEBUG_ENTER_FUNCTION();
   615     deinit();
   626     deinit();
   616     CX_DEBUG_EXIT_FUNCTION();
   627     CX_DEBUG_EXIT_FUNCTION();
   617 }
   628 }
   618 
   629 
   619 /**
   630 /*!
   620  * Camera being released. Cancel ongoing capture, if any.
   631  * Camera being released. Cancel ongoing capture, if any.
   621  */
   632  */
   622 void CxeStillCaptureControlSymbian::prepareForRelease()
   633 void CxeStillCaptureControlSymbian::prepareForRelease()
   623 {
   634 {
   624     CX_DEBUG_ENTER_FUNCTION();
   635     CX_DEBUG_ENTER_FUNCTION();
   625     deinit();
   636     deinit();
   626     CX_DEBUG_EXIT_FUNCTION();
   637     CX_DEBUG_EXIT_FUNCTION();
   627 }
   638 }
   628 
   639 
   629 /**
   640 /*!
   630  *  New camera available,
   641  *  New camera available,
   631  */
   642  */
   632 void CxeStillCaptureControlSymbian::handleCameraAllocated(CxeError::Id error)
   643 void CxeStillCaptureControlSymbian::handleCameraAllocated(CxeError::Id error)
   633 {
   644 {
   634     CX_DEBUG_ENTER_FUNCTION();
   645     CX_DEBUG_ENTER_FUNCTION();
   658     }
   669     }
   659 
   670 
   660     CX_DEBUG_EXIT_FUNCTION();
   671     CX_DEBUG_EXIT_FUNCTION();
   661 }
   672 }
   662 
   673 
   663 /**
   674 /*!
   664  * Return number of images captured (during current capture operation only).
   675  * Return number of images captured (during current capture operation only).
   665  */
   676  */
   666 int CxeStillCaptureControlSymbian::imageCount() const
   677 int CxeStillCaptureControlSymbian::imageCount() const
   667 {
   678 {
   668     return mImages.count();
   679     return mImages.count();
   669 }
   680 }
   670 
   681 
   671 /**
   682 /*!
   672  * Reset the image array.
   683  * Reset the image array.
   673  */
   684  */
   674 void CxeStillCaptureControlSymbian::reset()
   685 void CxeStillCaptureControlSymbian::reset()
   675 {
   686 {
   676     CX_DEBUG_ENTER_FUNCTION();
   687     CX_DEBUG_ENTER_FUNCTION();
   682     mNextImageDataIndex = 0;
   693     mNextImageDataIndex = 0;
   683 
   694 
   684     CX_DEBUG_EXIT_FUNCTION();
   695     CX_DEBUG_EXIT_FUNCTION();
   685 }
   696 }
   686 
   697 
   687 /**
   698 /*!
   688  * This should cancel any ongoing image captures.
   699  * This should cancel any ongoing image captures.
   689  */
   700  */
   690 void CxeStillCaptureControlSymbian::cancelAll()
   701 void CxeStillCaptureControlSymbian::cancelAll()
   691 {
   702 {
   692     mImageDataQueue->clear();
   703     mImageDataQueue->clear();
   693     reset();
   704     reset();
   694 }
   705 }
   695 
   706 
   696 /**
   707 /*!
   697  * Sets the current capture mode: SingleImageCapture / BurstCapture.
   708  * Sets the current capture mode: SingleImageCapture / BurstCapture.
   698  */
   709  */
   699 void CxeStillCaptureControlSymbian::setMode( CaptureMode mode )
   710 void CxeStillCaptureControlSymbian::setMode( CaptureMode mode )
   700 {
   711 {
   701     mMode = mode;
   712     mMode = mode;
   702 }
   713 }
   703 
   714 
   704 /**
   715 /*!
   705  * Returns the current capture mode.
   716  * Returns the current capture mode.
   706  */
   717  */
   707 CxeStillCaptureControl::CaptureMode CxeStillCaptureControlSymbian::mode() const
   718 CxeStillCaptureControl::CaptureMode CxeStillCaptureControlSymbian::mode() const
   708 {
   719 {
   709     return mMode;
   720     return mMode;
   710 }
   721 }
   711 
   722 
   712 /**
   723 /*!
   713  * Operator [] - returns the indexed image from capture array.
   724  * Operator [] - returns the indexed image from capture array.
   714  */
   725  */
   715 CxeStillImage &CxeStillCaptureControlSymbian::operator[]( int index )
   726 CxeStillImage &CxeStillCaptureControlSymbian::operator[]( int index )
   716 {
   727 {
   717     return *mImages[ index ];
   728     return *mImages[ index ];
   718 }
   729 }
   719 
   730 
   720 /**
   731 /*!
   721  * Getter for image data queue.
   732  * Getter for image data queue.
   722  */
   733  */
   723 CxeImageDataQueue &CxeStillCaptureControlSymbian::imageDataQueue()
   734 CxeImageDataQueue &CxeStillCaptureControlSymbian::imageDataQueue()
   724 {
   735 {
   725     return *mImageDataQueue;
   736     return *mImageDataQueue;
   726 }
   737 }
   727 
   738 
   728 /**
   739 /*!
   729  * Generates a filename and sets it in the still image object.
   740  * Generates a filename and sets it in the still image object.
   730  * Skips the process if filename already copied exists in the object. This
   741  * Skips the process if filename already copied exists in the object. This
   731  * behaviour is required in rare cases where image data arrives before snapshot.
   742  * behaviour is required in rare cases where image data arrives before snapshot.
   732  */
   743  */
   733 CxeError::Id
   744 CxeError::Id
   786     }
   797     }
   787 
   798 
   788     CX_DEBUG_EXIT_FUNCTION();
   799     CX_DEBUG_EXIT_FUNCTION();
   789 }
   800 }
   790 
   801 
   791 /**
   802 /*!
   792  * Get the image container at given index or create a new one if needed.
   803  * Get the image container at given index or create a new one if needed.
   793  */
   804  */
   794 CxeStillImageSymbian* CxeStillCaptureControlSymbian::getImageForIndex(int index)
   805 CxeStillImageSymbian* CxeStillCaptureControlSymbian::getImageForIndex(int index)
   795 {
   806 {
   796     CxeStillImageSymbian* image(NULL);
   807     CxeStillImageSymbian* image(NULL);