camerauis/cameraxui/cxengine/src/cxeenginesymbian.cpp
changeset 19 d9aefe59d544
child 21 fa6d9f75d6a6
child 28 3075d9b614e6
equal deleted inserted replaced
3:8b2d6d0384b0 19:d9aefe59d544
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #include "cxeenginesymbian.h"
       
    18 #include "cxecameradevicecontrolsymbian.h"
       
    19 #include "cxestillcapturecontrolsymbian.h"
       
    20 #include "cxevideocapturecontrolsymbian.h"
       
    21 #include "cxesettingscontrolsymbian.h"
       
    22 #include "cxeviewfindercontrolsymbian.h"
       
    23 #include "cxefilenamegeneratorsymbian.h"
       
    24 #include "cxeautofocuscontrolsymbian.h"
       
    25 #include "cxezoomcontrolsymbian.h"
       
    26 #include "cxequalitypresetssymbian.h"
       
    27 #include "cxutils.h"
       
    28 #include "cxesettingsimp.h"
       
    29 #include "cxefeaturemanagerimp.h"
       
    30 #include "cxesettingsmodelimp.h"
       
    31 #include "cxesettingscenrepstore.h"
       
    32 #include "cxesoundplayersymbian.h"
       
    33 #include "cxesensoreventhandlersymbian.h"
       
    34 #include "cxefilesavethread.h"
       
    35 #include "cxecameradevice.h"
       
    36 
       
    37 #include "OstTraceDefinitions.h"
       
    38 #ifdef OST_TRACE_COMPILER_IN_USE
       
    39 #include "cxeenginesymbianTraces.h"
       
    40 #endif
       
    41 #include <xqserviceutil.h>
       
    42 
       
    43 //  Member Functions
       
    44 
       
    45 CxeEngineSymbian::CxeEngineSymbian()
       
    46     : mCameraDeviceControl(NULL),
       
    47       mViewfinderControl(NULL),
       
    48       mStillCaptureControl(NULL),
       
    49       mVideoCaptureControl(NULL),
       
    50       mSettingsControl(NULL),
       
    51       mAutoFocusControl(NULL),
       
    52       mZoomControl(NULL),
       
    53       mSettings(NULL),
       
    54       mFeatureManager(NULL),
       
    55       mSettingsModel(NULL),
       
    56       mFilenameGenerator(NULL),
       
    57       mSensorEventHandler(NULL),
       
    58       mQualityPresets(NULL),
       
    59       mFileSaveThread(NULL)
       
    60 {
       
    61     CX_DEBUG_IN_FUNCTION();
       
    62 }
       
    63 
       
    64 
       
    65 /*!
       
    66     Create all control classes and connect relevant signals
       
    67 */
       
    68 void CxeEngineSymbian::construct()
       
    69 {
       
    70     CX_DEBUG_ENTER_FUNCTION();
       
    71 
       
    72     createControls();
       
    73     connectSignals();
       
    74 
       
    75     CX_DEBUG_EXIT_FUNCTION();
       
    76 }
       
    77 
       
    78 
       
    79 /*!
       
    80     Create all control classes
       
    81 */
       
    82 void CxeEngineSymbian::createControls()
       
    83 {
       
    84     CX_DEBUG_ENTER_FUNCTION();
       
    85 
       
    86     if (!mVideoCaptureControl) {
       
    87         CxeCameraDeviceControlSymbian *deviceControl =
       
    88                 new CxeCameraDeviceControlSymbian();
       
    89 
       
    90         mCameraDeviceControl = deviceControl;
       
    91         CxeCameraDevice *cameraDevice = deviceControl->cameraDevice();
       
    92 
       
    93         CxeSettingsCenRepStore *settingsStore;
       
    94 
       
    95         if (XQServiceUtil::isService()) {
       
    96             settingsStore = new CxeSettingsLocalStore();
       
    97         } else {
       
    98             settingsStore = new CxeSettingsCenRepStore();
       
    99         }
       
   100 
       
   101         //ownership of settings store transferred to the settings model.
       
   102         mSettingsModel = new CxeSettingsModelImp(
       
   103                 settingsStore);
       
   104 
       
   105         // assert if settings model fails to intialize
       
   106         CX_DEBUG_ASSERT(mSettingsModel);
       
   107         mSettings = new CxeSettingsImp(*mSettingsModel);
       
   108 
       
   109         connect(settingsStore, SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)),
       
   110                 mSettings, SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)));
       
   111 
       
   112         mQualityPresets = new CxeQualityPresetsSymbian(*mSettings);
       
   113         CX_DEBUG_ASSERT(mQualityPresets);
       
   114 
       
   115         mFeatureManager = new CxeFeatureManagerImp(*mSettingsModel);
       
   116 
       
   117         // sensor event handler initialization
       
   118         mSensorEventHandler = new CxeSensorEventHandlerSymbian();
       
   119 
       
   120         mFilenameGenerator = new CxeFilenameGeneratorSymbian(*mSettings,
       
   121             mode());
       
   122 
       
   123         mViewfinderControl = new CxeViewfinderControlSymbian(*cameraDevice,
       
   124             *deviceControl);
       
   125 
       
   126         mAutoFocusControl = new CxeAutoFocusControlSymbian(*cameraDevice);
       
   127 
       
   128         mFileSaveThread = CxeFileSaveThreadFactory::createFileSaveThread();
       
   129 
       
   130         mStillCaptureControl = new CxeStillCaptureControlSymbian(
       
   131             *cameraDevice, *mViewfinderControl, *deviceControl,
       
   132             *mFilenameGenerator, *mSensorEventHandler, *mAutoFocusControl,
       
   133             *mSettings, *mQualityPresets, *mFileSaveThread);
       
   134 
       
   135         mZoomControl = new CxeZoomControlSymbian( *cameraDevice,
       
   136             *deviceControl, *mSettings, *mFeatureManager);
       
   137 
       
   138         mVideoCaptureControl = new CxeVideoCaptureControlSymbian(
       
   139             *cameraDevice, *mViewfinderControl, *deviceControl,
       
   140             *mFilenameGenerator, *mSettings, *mQualityPresets);
       
   141 
       
   142         mSettingsControl = new CxeSettingsControlSymbian(*cameraDevice, *mSettings);
       
   143     }
       
   144 
       
   145     CX_DEBUG_EXIT_FUNCTION();
       
   146 }
       
   147 
       
   148 /*!
       
   149     Connect internal signals for control classes
       
   150 */
       
   151 void CxeEngineSymbian::connectSignals()
       
   152 {
       
   153     CX_DEBUG_ENTER_FUNCTION();
       
   154 
       
   155     // enabling scene setting change callbacks to Autofocus control
       
   156     connect(mSettings,
       
   157             SIGNAL(sceneChanged(CxeScene&)),
       
   158             mAutoFocusControl,
       
   159             SLOT(handleSceneChanged(CxeScene&)));
       
   160 
       
   161     // connecting Autofocus state change callbacks to stillcapturecontrol
       
   162     connect(mAutoFocusControl,
       
   163             SIGNAL(stateChanged(CxeAutoFocusControl::State, CxeError::Id)),
       
   164             mStillCaptureControl,
       
   165             SLOT(handleAutofocusStateChanged(CxeAutoFocusControl::State,CxeError::Id)));
       
   166 
       
   167     // Connect signals for ECam events
       
   168     connect(mCameraDeviceControl,
       
   169             SIGNAL(cameraEvent(int,int)),
       
   170             mVideoCaptureControl,
       
   171             SLOT(handleCameraEvent(int,int)));
       
   172 
       
   173     connect(mCameraDeviceControl,
       
   174             SIGNAL(cameraEvent(int,int)),
       
   175             mAutoFocusControl,
       
   176             SLOT(handleCameraEvent(int,int)));
       
   177 
       
   178     // Connect signal for device ready events
       
   179     connect(mCameraDeviceControl,
       
   180             SIGNAL(deviceReady()),
       
   181             this,
       
   182             SLOT(doInit()));
       
   183 
       
   184     // Connect image and video init complete signals to
       
   185     // CameraDeviceControl initModeComplete
       
   186     connect(mStillCaptureControl,
       
   187             SIGNAL(imagePrepareComplete(CxeError::Id)),
       
   188             mCameraDeviceControl,
       
   189             SIGNAL(initModeComplete(CxeError::Id)));
       
   190 
       
   191     connect(mVideoCaptureControl,
       
   192             SIGNAL(videoPrepareComplete(CxeError::Id)),
       
   193             mCameraDeviceControl,
       
   194             SIGNAL(initModeComplete(CxeError::Id)));
       
   195 
       
   196     // Zoom is prepared once the image/video emits prepare zoom signals
       
   197     connect(mStillCaptureControl,
       
   198             SIGNAL(prepareZoomForStill(int)),
       
   199             mZoomControl,
       
   200             SLOT(prepareZoomForStill(int)));
       
   201 
       
   202     connect(mVideoCaptureControl,
       
   203             SIGNAL(prepareZoomForVideo()),
       
   204             mZoomControl,
       
   205             SLOT(prepareZoomForVideo()));
       
   206 
       
   207     // Connect file saving thread to snapshot signals and video saved signal.
       
   208     // Image saving it handles internally.
       
   209     connect(mStillCaptureControl,
       
   210             SIGNAL(snapshotReady(CxeError::Id, const QPixmap&, int)),
       
   211             mFileSaveThread,
       
   212             SLOT(handleSnapshotReady(CxeError::Id, const QPixmap&, int)));
       
   213     connect(mVideoCaptureControl,
       
   214             SIGNAL(videoComposed(CxeError::Id, const QString&)),
       
   215             mFileSaveThread,
       
   216             SLOT(handleVideoSaved(CxeError::Id, const QString&)));
       
   217     connect(mVideoCaptureControl,
       
   218             SIGNAL(snapshotReady(CxeError::Id, const QPixmap&, const QString&)),
       
   219             mFileSaveThread,
       
   220             SLOT(handleSnapshotReady(CxeError::Id, const QPixmap&, const QString&)));
       
   221 
       
   222 
       
   223 
       
   224     // init camera device control. We init the camera device control
       
   225     // when all necessary engine classes are constructed.
       
   226     mCameraDeviceControl->init();
       
   227 
       
   228     CX_DEBUG_EXIT_FUNCTION();
       
   229 }
       
   230 
       
   231 CxeEngineSymbian::~CxeEngineSymbian()
       
   232 {
       
   233     CX_DEBUG_ENTER_FUNCTION();
       
   234 
       
   235     delete mAutoFocusControl;
       
   236     delete mZoomControl;
       
   237     delete mSettingsControl;
       
   238     delete mStillCaptureControl;
       
   239     delete mVideoCaptureControl;
       
   240     delete mViewfinderControl;
       
   241     delete mFilenameGenerator;
       
   242     delete mFeatureManager;
       
   243     delete mSettings;
       
   244     delete mSettingsModel;
       
   245     delete mCameraDeviceControl;
       
   246     delete mQualityPresets;
       
   247     delete mFileSaveThread;
       
   248 
       
   249     CX_DEBUG_EXIT_FUNCTION();
       
   250 }
       
   251 
       
   252 CxeCameraDeviceControl &CxeEngineSymbian::cameraDeviceControl()
       
   253 {
       
   254     return *mCameraDeviceControl;
       
   255 }
       
   256 
       
   257 CxeViewfinderControl &CxeEngineSymbian::viewfinderControl()
       
   258 {
       
   259     return *mViewfinderControl;
       
   260 }
       
   261 
       
   262 CxeStillCaptureControl &CxeEngineSymbian::stillCaptureControl()
       
   263 {
       
   264     return *mStillCaptureControl;
       
   265 }
       
   266 
       
   267 CxeVideoCaptureControl &CxeEngineSymbian::videoCaptureControl()
       
   268 {
       
   269     return *mVideoCaptureControl;
       
   270 }
       
   271 
       
   272 CxeAutoFocusControl &CxeEngineSymbian::autoFocusControl()
       
   273 {
       
   274     return *mAutoFocusControl;
       
   275 }
       
   276 
       
   277 CxeZoomControl &CxeEngineSymbian::zoomControl()
       
   278 {
       
   279     return *mZoomControl;
       
   280 }
       
   281 
       
   282 // Get the settings handle
       
   283 CxeSettings &CxeEngineSymbian::settings()
       
   284 {
       
   285     return *mSettings;
       
   286 }
       
   287 
       
   288 // Get the sensor event  handle
       
   289 CxeSensorEventHandler &CxeEngineSymbian::sensorEventHandler()
       
   290 {
       
   291     return *mSensorEventHandler;
       
   292 }
       
   293 
       
   294 
       
   295 CxeFeatureManager& CxeEngineSymbian::featureManager()
       
   296 {
       
   297     return *mFeatureManager;
       
   298 }
       
   299 
       
   300 /*
       
   301 * Returns true, if the engine is ready or else false.
       
   302 */
       
   303 bool CxeEngineSymbian::isEngineReady()
       
   304 {
       
   305     bool ready = false;
       
   306     if (mCameraDeviceControl->state() == CxeCameraDeviceControl::Ready &&
       
   307         mViewfinderControl->state() == CxeViewfinderControl::Running) {
       
   308         if (mode() == Cxe::ImageMode) {
       
   309             if (mStillCaptureControl->state() == CxeStillCaptureControl::Ready) {
       
   310                 ready = true;
       
   311             }
       
   312         } else if (mode() == Cxe::VideoMode) {
       
   313             if (mVideoCaptureControl->state() == CxeVideoCaptureControl::Ready) {
       
   314                 ready = true;
       
   315             }
       
   316         }
       
   317     }
       
   318     return ready;
       
   319 }
       
   320 
       
   321 /*!
       
   322     Prepare current capture control (CxeVideoCaptureControl in video mode,
       
   323     CxeStillCaptureControl in still image mode).
       
   324 */
       
   325 void CxeEngineSymbian::doInit()
       
   326 {
       
   327     CX_DEBUG_ENTER_FUNCTION();
       
   328     OstTrace0(camerax_performance, CXEENGINESYMBIAN_DOINIT, "e_CX_ENGINE_DO_INIT 1");
       
   329 
       
   330     mFilenameGenerator->init(mode());
       
   331     // load settings whenever we change mode or start camera or switch camera
       
   332     CxeSettingsImp *settingsImp = qobject_cast<CxeSettingsImp*>(mSettings);
       
   333     if (settingsImp) {
       
   334         settingsImp->loadSettings(mode());
       
   335     }
       
   336 
       
   337 
       
   338     if (mode() == Cxe::ImageMode) {
       
   339         mVideoCaptureControl->deinit();
       
   340         mStillCaptureControl->init();
       
   341     } else if (mode() == Cxe::VideoMode) {
       
   342         mStillCaptureControl->deinit();
       
   343         mVideoCaptureControl->init();
       
   344     }
       
   345 
       
   346     OstTrace0(camerax_performance, DUP1_CXEENGINESYMBIAN_DOINIT, "e_CX_ENGINE_DO_INIT 0");
       
   347 
       
   348     CX_DEBUG_EXIT_FUNCTION();
       
   349 }
       
   350 
       
   351 Cxe::CameraMode CxeEngineSymbian::mode() const
       
   352 {
       
   353     return mCameraDeviceControl->mode();
       
   354 }
       
   355 
       
   356 /*!
       
   357     Check if we need to reserve camera.
       
   358 */
       
   359 bool CxeEngineSymbian::reserveNeeded()
       
   360 {
       
   361     // If camera device control is in Idle or pending release state,
       
   362     // we need to call reserve()
       
   363     return (mCameraDeviceControl->state() == CxeCameraDeviceControl::Idle ||
       
   364             mCameraDeviceControl->state() == CxeCameraDeviceControl::PendingRelease);
       
   365 }
       
   366 
       
   367 /*!
       
   368     Check if we need to prepare image/video capture.
       
   369 */
       
   370 bool CxeEngineSymbian::initNeeded()
       
   371 {
       
   372     bool result = false;
       
   373 
       
   374     if (mCameraDeviceControl->state() == CxeCameraDeviceControl::Ready) {
       
   375         if (mode() == Cxe::ImageMode) {
       
   376             if(mStillCaptureControl->state() == CxeStillCaptureControl::Uninitialized) {
       
   377                 // We're in still image mode, camera is reserved and ready, but
       
   378                 // we need to prepare still image control
       
   379                 result = true;
       
   380             }
       
   381         } else if (mode() == Cxe::VideoMode) {
       
   382             if (mVideoCaptureControl->state() == CxeVideoCaptureControl::Idle ||
       
   383                 mVideoCaptureControl->state() == CxeVideoCaptureControl::Initialized) {
       
   384                 // We're in video mode, camera is reserved and ready, but
       
   385                 // we need to prepare for video recording.
       
   386                 result = true;
       
   387             }
       
   388         }
       
   389     }
       
   390 
       
   391     return result;
       
   392 }
       
   393 
       
   394 /*!
       
   395     Check if we need to start viewfinder.
       
   396 */
       
   397 bool CxeEngineSymbian::startViewfinderNeeded()
       
   398 {
       
   399     bool result = false;
       
   400 
       
   401     if (mViewfinderControl->state() != CxeViewfinderControl::Running) {
       
   402         if (mode() == Cxe::ImageMode &&
       
   403             mStillCaptureControl->state() == CxeStillCaptureControl::Ready) {
       
   404             // We're in still image mode and ready for capturing... we just need to
       
   405             // start viewfinder.
       
   406             result = true;
       
   407         } else if (mode() == Cxe::VideoMode &&
       
   408                    mVideoCaptureControl->state() == CxeVideoCaptureControl::Ready) {
       
   409             // We're in video mode and ready for capturing... we just need to
       
   410             // start viewfinder.
       
   411             result = true;
       
   412         }
       
   413     }
       
   414 
       
   415     return result;
       
   416 }
       
   417 
       
   418 void CxeEngineSymbian::initMode(Cxe::CameraMode cameraMode)
       
   419 {
       
   420     CX_DEBUG_ENTER_FUNCTION();
       
   421 
       
   422     if (mode() == cameraMode) {
       
   423         CX_DEBUG(("initMode() called for current mode"));
       
   424 
       
   425         // We're already in the requested mode. However, it is possible
       
   426         // that we need to reserve and power on camera and/or prepare
       
   427         // the capture control.
       
   428         if (reserveNeeded()) {
       
   429             // Camera needs to be reserved. Initialization will continue
       
   430             // when we get the deviceReady() signal.
       
   431             CX_DEBUG(("initMode() - calling reserve()"));
       
   432             mCameraDeviceControl->reserve();
       
   433         } else if (initNeeded()) {
       
   434             // Camera is reserved and ready, but we need to prepare still image control or
       
   435             // video capture control
       
   436             CX_DEBUG(("initMode() - calling doInit()"));
       
   437             doInit();
       
   438         } else if (startViewfinderNeeded()) {
       
   439             // Everything is ready and prepared, but we viewfinder is not yet running
       
   440             CX_DEBUG(("initMode() - calling viewfinder start()"));
       
   441             mViewfinderControl->start();
       
   442         } else {
       
   443             CX_DEBUG(("initMode() - no actions needed"));
       
   444             // Do nothing.
       
   445             // We are either already ready to capture or the we're pending
       
   446             // on prepare complete callback.
       
   447         }
       
   448     } else {
       
   449         CX_DEBUG(("initMode() called for mode switch"));
       
   450 
       
   451         // Mode switch
       
   452         mCameraDeviceControl->setMode(cameraMode);
       
   453         // stop the vf
       
   454         mViewfinderControl->stop();
       
   455 
       
   456         if (reserveNeeded()) {
       
   457             CX_DEBUG(("initMode() - calling reserve()"));
       
   458             mCameraDeviceControl->reserve();
       
   459         } else if (mCameraDeviceControl->state() == CxeCameraDeviceControl::Ready) {
       
   460             CX_DEBUG(("initMode() - calling doInit()"));
       
   461             // Camera device is ready... we only need to prepare video or still
       
   462             // capture control, depending on current mode.
       
   463             doInit();
       
   464         } else {
       
   465             CX_DEBUG(("initMode() - no actions needed"));
       
   466             // Do nothing.
       
   467             // Camera device control is in Initializing state. Initialization will continue
       
   468             // when we get the deviceReady() callback.
       
   469         }
       
   470     }
       
   471 
       
   472     CX_DEBUG_EXIT_FUNCTION();
       
   473 }
       
   474 
       
   475 // End of file