camerauis/cameraxui/cxengine/src/cxeenginesymbian.cpp
branchRCL_3
changeset 24 bac7acad7cb3
parent 23 61bc0f252b2b
child 25 2c87b2808fd7
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
     1 /*
       
     2 * Copyright (c) 2009-2010 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 
       
    18 #include <xqserviceutil.h>
       
    19 
       
    20 #include "cxeenginesymbian.h"
       
    21 #include "cxecameradevicecontrolsymbian.h"
       
    22 #include "cxestillcapturecontrolsymbian.h"
       
    23 #include "cxevideocapturecontrolsymbian.h"
       
    24 #include "cxesettingscontrolsymbian.h"
       
    25 #include "cxeviewfindercontrolsymbian.h"
       
    26 #include "cxesnapshotcontrol.h"
       
    27 #include "cxefilenamegeneratorsymbian.h"
       
    28 #include "cxeautofocuscontrolsymbian.h"
       
    29 #include "cxezoomcontrolsymbian.h"
       
    30 #include "cxequalitypresetssymbian.h"
       
    31 #include "cxutils.h"
       
    32 #include "cxesettingsimp.h"
       
    33 #include "cxefeaturemanagerimp.h"
       
    34 #include "cxesettingscenrepstore.h"
       
    35 #include "cxesoundplayersymbian.h"
       
    36 #include "cxesensoreventhandlersymbian.h"
       
    37 #include "cxefilesavethread.h"
       
    38 #include "cxecameradevice.h"
       
    39 #include "cxememorymonitor.h"
       
    40 #include "cxediskmonitor.h"
       
    41 #include "cxegeotaggingtrail.h"
       
    42 #include "cxeexception.h"
       
    43 
       
    44 #include "OstTraceDefinitions.h"
       
    45 #ifdef OST_TRACE_COMPILER_IN_USE
       
    46 #include "cxeenginesymbianTraces.h"
       
    47 #endif
       
    48 
       
    49 
       
    50 //  Member Functions
       
    51 
       
    52 CxeEngineSymbian::CxeEngineSymbian()
       
    53     : mCameraDeviceControl(NULL),
       
    54       mCameraDevice(NULL),
       
    55       mViewfinderControl(NULL),
       
    56       mSnapshotControl(NULL),
       
    57       mStillCaptureControl(NULL),
       
    58       mVideoCaptureControl(NULL),
       
    59       mSettingsControl(NULL),
       
    60       mAutoFocusControl(NULL),
       
    61       mZoomControl(NULL),
       
    62       mSettings(NULL),
       
    63       mFeatureManager(NULL),
       
    64       mFilenameGenerator(NULL),
       
    65       mSensorEventHandler(NULL),
       
    66       mQualityPresets(NULL),
       
    67       mFileSaveThread(NULL),
       
    68       mDiskMonitor(NULL),
       
    69       mMemoryMonitor(NULL),
       
    70       mGeoTaggingTrail(NULL)
       
    71 {
       
    72     CX_DEBUG_IN_FUNCTION();
       
    73 }
       
    74 
       
    75 
       
    76 /*!
       
    77     Create all control classes and connect relevant signals
       
    78 */
       
    79 void CxeEngineSymbian::construct()
       
    80 {
       
    81     CX_DEBUG_ENTER_FUNCTION();
       
    82 
       
    83     createControls();
       
    84     connectSignals();
       
    85 
       
    86     CX_DEBUG_EXIT_FUNCTION();
       
    87 }
       
    88 
       
    89 
       
    90 /*!
       
    91     Create all control classes.
       
    92     Note: Throws an error, if free memory request by CxeMemoryMonitor constructor fails!
       
    93 */
       
    94 void CxeEngineSymbian::createControls()
       
    95 {
       
    96     CX_DEBUG_ENTER_FUNCTION();
       
    97 
       
    98     // Check we do this only once.
       
    99     if (!mSettings) {
       
   100         OstTrace0(camerax_performance, CXEENGINESYMBIAN_CREATECONTROLS_IN, "msg: e_CX_ENGINE_CREATE_CONTROLS 1");
       
   101 
       
   102         CxeCameraDeviceControlSymbian *deviceControl = new CxeCameraDeviceControlSymbian();
       
   103         mCameraDeviceControl = deviceControl;
       
   104         mCameraDevice = deviceControl->cameraDevice();
       
   105 
       
   106         CX_ASSERT_ALWAYS(mCameraDeviceControl);
       
   107         CX_ASSERT_ALWAYS(mCameraDevice);
       
   108 
       
   109         mCameraDeviceControl->init();
       
   110 
       
   111         CxeSettingsCenRepStore *settingsStore(NULL);
       
   112         if (XQServiceUtil::isService()) {
       
   113             settingsStore = new CxeSettingsLocalStore();
       
   114         } else {
       
   115             settingsStore = new CxeSettingsCenRepStore();
       
   116         }
       
   117 
       
   118         //ownership of settings store transferred to the settings
       
   119         mSettings = new CxeSettingsImp(settingsStore);
       
   120 
       
   121         // Loading current camera mode value from settings store and updating
       
   122 		// devicecontrol
       
   123         Cxe::CameraMode cameraMode = Cxe::ImageMode;
       
   124 
       
   125         try {
       
   126             cameraMode = mSettings->get<Cxe::CameraMode>(CxeSettingIds::CAMERA_MODE);
       
   127         } catch (CxeException &e) {
       
   128             CX_DEBUG(("Failed to read camera mode from settings, using image mode. Error code: %d", e.error()));
       
   129         }
       
   130 
       
   131         // set current camera mode to devicecontrol.
       
   132         mCameraDeviceControl->setMode(cameraMode);
       
   133 
       
   134         //! @todo a temporary hack to change the startup sequence to avoid GOOM problems
       
   135         static_cast<CxeSettingsImp*>(mSettings)->loadSettings(mode());
       
   136 
       
   137 
       
   138         // Connect P&S key updates to settings signal.
       
   139         connect(settingsStore, SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)),
       
   140                 mSettings, SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)));
       
   141 
       
   142         mFeatureManager = new CxeFeatureManagerImp(*mSettings);
       
   143 
       
   144         // Memory monitor needed as early as possible to request free memory.
       
   145         // Note: Throws error if enough memory cannot be freed!
       
   146         mMemoryMonitor = new CxeMemoryMonitor(*mFeatureManager);
       
   147 
       
   148         mDiskMonitor = new CxeDiskMonitor(*mSettings);
       
   149 
       
   150         mQualityPresets = new CxeQualityPresetsSymbian(*mSettings);
       
   151         CX_DEBUG_ASSERT(mQualityPresets);
       
   152 
       
   153         // sensor event handler initialization
       
   154         mSensorEventHandler = new CxeSensorEventHandlerSymbian();
       
   155 
       
   156         mFilenameGenerator = new CxeFilenameGeneratorSymbian(*mSettings,
       
   157             mode());
       
   158 
       
   159         mViewfinderControl = new CxeViewfinderControlSymbian(*mCameraDevice,
       
   160             *mCameraDeviceControl);
       
   161 
       
   162         mSnapshotControl = new CxeSnapshotControl(*mCameraDevice);
       
   163 
       
   164         mAutoFocusControl = new CxeAutoFocusControlSymbian(*mCameraDevice,
       
   165 		                            *mSettings);
       
   166 
       
   167         mFileSaveThread = CxeFileSaveThreadFactory::createFileSaveThread();
       
   168 
       
   169         mStillCaptureControl = new CxeStillCaptureControlSymbian(
       
   170             *mCameraDevice, *mViewfinderControl, *mSnapshotControl, *mCameraDeviceControl,
       
   171             *mFilenameGenerator, *mSensorEventHandler, *mAutoFocusControl,
       
   172             *mSettings, *mQualityPresets, *mFileSaveThread, *mDiskMonitor);
       
   173 
       
   174         mZoomControl = new CxeZoomControlSymbian(
       
   175             *mCameraDevice, *mCameraDeviceControl, *mSettings, *mFeatureManager);
       
   176 
       
   177         mVideoCaptureControl = new CxeVideoCaptureControlSymbian(
       
   178             *mCameraDevice, *mViewfinderControl, *mSnapshotControl, *mCameraDeviceControl,
       
   179             *mFilenameGenerator, *mSettings, *mQualityPresets, *mDiskMonitor);
       
   180 
       
   181         mSettingsControl = new CxeSettingsControlSymbian(*mCameraDevice, *mSettings);
       
   182 
       
   183         mGeoTaggingTrail = new CxeGeoTaggingTrail(*mStillCaptureControl,
       
   184                                                   *mVideoCaptureControl,
       
   185                                                   *mSettings);
       
   186 
       
   187         OstTrace0(camerax_performance, CXEENGINESYMBIAN_CREATECONTROLS_OUT, "msg: e_CX_ENGINE_CREATE_CONTROLS 0");
       
   188     }
       
   189 
       
   190     CX_DEBUG_EXIT_FUNCTION();
       
   191 }
       
   192 
       
   193 /*!
       
   194     Connect internal signals for control classes
       
   195 */
       
   196 void CxeEngineSymbian::connectSignals()
       
   197 {
       
   198     CX_DEBUG_ENTER_FUNCTION();
       
   199     OstTrace0(camerax_performance, CXEENGINESYMBIAN_CONNECTSIGNALS_IN, "msg: e_CX_ENGINE_CONNECT_SIGNALS 1");
       
   200 
       
   201     // enabling scene setting change callbacks to Autofocus control
       
   202     mSettings->listenForSetting(CxeSettingIds::IMAGE_SCENE_DATA, mAutoFocusControl, SLOT(handleSceneChanged(const QVariant&)));
       
   203     mSettings->listenForSetting(CxeSettingIds::VIDEO_SCENE_DATA, mAutoFocusControl, SLOT(handleSceneChanged(const QVariant&)));
       
   204 
       
   205     // connecting Autofocus state change callbacks to stillcapturecontrol
       
   206     connect(mAutoFocusControl,
       
   207             SIGNAL(stateChanged(CxeAutoFocusControl::State, CxeError::Id)),
       
   208             mStillCaptureControl,
       
   209             SLOT(handleAutofocusStateChanged(CxeAutoFocusControl::State,CxeError::Id)));
       
   210 
       
   211     // Connect signals for ECam events
       
   212     connect(mCameraDeviceControl,
       
   213             SIGNAL(cameraEvent(int,int)),
       
   214             mSnapshotControl,
       
   215             SLOT(handleCameraEvent(int,int)));
       
   216 
       
   217     connect(mCameraDeviceControl,
       
   218             SIGNAL(cameraEvent(int,int)),
       
   219             mAutoFocusControl,
       
   220             SLOT(handleCameraEvent(int,int)));
       
   221 
       
   222     connect(mCameraDeviceControl,
       
   223             SIGNAL(cameraEvent(int,int)),
       
   224             mStillCaptureControl,
       
   225             SLOT(handleCameraEvent(int,int)));
       
   226 
       
   227     // Connect signal for device ready events
       
   228     connect(mCameraDeviceControl,
       
   229             SIGNAL(deviceReady()),
       
   230             this,
       
   231             SLOT(doInit()));
       
   232 
       
   233     // Connect image and video init complete signals to
       
   234     // CameraDeviceControl initModeComplete
       
   235     connect(mStillCaptureControl,
       
   236             SIGNAL(imagePrepareComplete(CxeError::Id)),
       
   237             mCameraDeviceControl,
       
   238             SIGNAL(initModeComplete(CxeError::Id)));
       
   239 
       
   240     connect(mVideoCaptureControl,
       
   241             SIGNAL(videoPrepareComplete(CxeError::Id)),
       
   242             mCameraDeviceControl,
       
   243             SIGNAL(initModeComplete(CxeError::Id)));
       
   244 
       
   245     // Zoom is prepared once the image/video emits prepare zoom signals
       
   246     connect(mStillCaptureControl,
       
   247             SIGNAL(prepareZoomForStill(int)),
       
   248             mZoomControl,
       
   249             SLOT(prepareZoomForStill(int)));
       
   250 
       
   251     connect(mVideoCaptureControl,
       
   252             SIGNAL(prepareZoomForVideo()),
       
   253             mZoomControl,
       
   254             SLOT(prepareZoomForVideo()));
       
   255 
       
   256     // Connect file saving thread to snapshot signals and video saved signal.
       
   257     // Image saving it handles internally.
       
   258     connect(mStillCaptureControl,
       
   259             SIGNAL(snapshotReady(CxeError::Id, const QImage&, int)),
       
   260             mFileSaveThread,
       
   261             SLOT(handleSnapshotReady(CxeError::Id, const QImage&, int)));
       
   262     connect(mVideoCaptureControl,
       
   263             SIGNAL(videoComposed(CxeError::Id, const QString&)),
       
   264             mFileSaveThread,
       
   265             SLOT(handleVideoSaved(CxeError::Id, const QString&)));
       
   266     connect(mVideoCaptureControl,
       
   267             SIGNAL(snapshotReady(CxeError::Id, const QImage&, const QString&)),
       
   268             mFileSaveThread,
       
   269             SLOT(handleSnapshotReady(CxeError::Id, const QImage&, const QString&)));
       
   270 
       
   271     // stop location trail when releasing camera.
       
   272     connect(mCameraDevice,
       
   273             SIGNAL(prepareForRelease()),
       
   274             mGeoTaggingTrail,
       
   275             SLOT(stop()),
       
   276             Qt::UniqueConnection);
       
   277 
       
   278     // Use MCameraUseCaseHint API before calling Reserve()
       
   279     connect(mCameraDevice,
       
   280             SIGNAL(aboutToReserve()),
       
   281             mStillCaptureControl,
       
   282             SLOT(hintUseCase()),
       
   283             Qt::UniqueConnection);
       
   284     connect(mCameraDevice,
       
   285             SIGNAL(aboutToReserve()),
       
   286             mVideoCaptureControl,
       
   287             SLOT(hintUseCase()),
       
   288             Qt::UniqueConnection);
       
   289 
       
   290     // Start / stop geotagging based on mode.
       
   291     // Do this later to reduce startup time.
       
   292     connect(mStillCaptureControl,
       
   293             SIGNAL(imagePrepareComplete(CxeError::Id)),
       
   294             this,
       
   295             SLOT(initGeotagging()));
       
   296     connect(mVideoCaptureControl,
       
   297             SIGNAL(videoPrepareComplete(CxeError::Id)),
       
   298             this,
       
   299             SLOT(initGeotagging()));
       
   300 
       
   301     OstTrace0(camerax_performance, CXEENGINESYMBIAN_CONNECTSIGNALS_OUT, "msg: e_CX_ENGINE_CONNECT_SIGNALS 0");
       
   302 
       
   303     CX_DEBUG_EXIT_FUNCTION();
       
   304 }
       
   305 
       
   306 CxeEngineSymbian::~CxeEngineSymbian()
       
   307 {
       
   308     CX_DEBUG_ENTER_FUNCTION();
       
   309 
       
   310     // Saving current camera mode to cenrep
       
   311     saveMode();
       
   312 
       
   313     delete mGeoTaggingTrail;
       
   314     delete mAutoFocusControl;
       
   315     delete mZoomControl;
       
   316     delete mSettingsControl;
       
   317     delete mStillCaptureControl;
       
   318     delete mVideoCaptureControl;
       
   319     delete mSnapshotControl;
       
   320     delete mViewfinderControl;
       
   321     delete mFilenameGenerator;
       
   322     delete mDiskMonitor;
       
   323     delete mMemoryMonitor;
       
   324     delete mFeatureManager;
       
   325     delete mSettings;
       
   326     delete mCameraDeviceControl;
       
   327     delete mQualityPresets;
       
   328     delete mFileSaveThread;
       
   329 
       
   330     CX_DEBUG_EXIT_FUNCTION();
       
   331 }
       
   332 
       
   333 CxeCameraDeviceControl &CxeEngineSymbian::cameraDeviceControl()
       
   334 {
       
   335     return *mCameraDeviceControl;
       
   336 }
       
   337 
       
   338 CxeViewfinderControl &CxeEngineSymbian::viewfinderControl()
       
   339 {
       
   340     return *mViewfinderControl;
       
   341 }
       
   342 
       
   343 CxeSnapshotControl &CxeEngineSymbian::snapshotControl()
       
   344 {
       
   345     return *mSnapshotControl;
       
   346 }
       
   347 
       
   348 CxeStillCaptureControl &CxeEngineSymbian::stillCaptureControl()
       
   349 {
       
   350     return *mStillCaptureControl;
       
   351 }
       
   352 
       
   353 CxeVideoCaptureControl &CxeEngineSymbian::videoCaptureControl()
       
   354 {
       
   355     return *mVideoCaptureControl;
       
   356 }
       
   357 
       
   358 CxeAutoFocusControl &CxeEngineSymbian::autoFocusControl()
       
   359 {
       
   360     return *mAutoFocusControl;
       
   361 }
       
   362 
       
   363 CxeZoomControl &CxeEngineSymbian::zoomControl()
       
   364 {
       
   365     return *mZoomControl;
       
   366 }
       
   367 
       
   368 /*!
       
   369 Returns the settings handle
       
   370 */
       
   371 CxeSettings &CxeEngineSymbian::settings()
       
   372 {
       
   373     return *mSettings;
       
   374 }
       
   375 
       
   376 /*!
       
   377 Returns the sensor event  handle
       
   378 */
       
   379 CxeSensorEventHandler &CxeEngineSymbian::sensorEventHandler()
       
   380 {
       
   381     return *mSensorEventHandler;
       
   382 }
       
   383 
       
   384 
       
   385 CxeFeatureManager &CxeEngineSymbian::featureManager()
       
   386 {
       
   387     return *mFeatureManager;
       
   388 }
       
   389 
       
   390 /*!
       
   391 * Returns memory monitor utility handle.
       
   392 */
       
   393 CxeMemoryMonitor &CxeEngineSymbian::memoryMonitor()
       
   394 {
       
   395     return *mMemoryMonitor;
       
   396 }
       
   397 
       
   398 
       
   399 /*!
       
   400  Returns geotaggingtrail handle
       
   401  */
       
   402 CxeGeoTaggingTrail &CxeEngineSymbian::geoTaggingTrail()
       
   403 {
       
   404     return *mGeoTaggingTrail;
       
   405 }
       
   406 
       
   407 /*!
       
   408 * Returns true, if the engine is ready or else false.
       
   409 */
       
   410 bool CxeEngineSymbian::isEngineReady()
       
   411 {
       
   412     bool ready = false;
       
   413     if (mCameraDeviceControl->state() == CxeCameraDeviceControl::Ready &&
       
   414         mViewfinderControl->state() == CxeViewfinderControl::Running) {
       
   415         if (mode() == Cxe::ImageMode) {
       
   416             if (mStillCaptureControl->state() == CxeStillCaptureControl::Ready) {
       
   417                 ready = true;
       
   418             }
       
   419         } else if (mode() == Cxe::VideoMode) {
       
   420             if (mVideoCaptureControl->state() == CxeVideoCaptureControl::Ready) {
       
   421                 ready = true;
       
   422             }
       
   423         }
       
   424     }
       
   425     return ready;
       
   426 }
       
   427 
       
   428 /*!
       
   429     Prepare current capture control (CxeVideoCaptureControl in video mode,
       
   430     CxeStillCaptureControl in still image mode).
       
   431 */
       
   432 void CxeEngineSymbian::doInit()
       
   433 {
       
   434     CX_DEBUG_ENTER_FUNCTION();
       
   435     OstTrace0(camerax_performance, CXEENGINESYMBIAN_DOINIT_IN, "msg: e_CX_ENGINE_DO_INIT 1");
       
   436 
       
   437     mFilenameGenerator->init(mode());
       
   438     // load settings whenever we change mode or start camera or switch camera
       
   439     CxeSettingsImp *settingsImp = qobject_cast<CxeSettingsImp*>(mSettings);
       
   440     if (settingsImp) {
       
   441         settingsImp->loadSettings(mode());
       
   442     }
       
   443 
       
   444     if (mode() == Cxe::ImageMode) {
       
   445         mVideoCaptureControl->deinit();
       
   446         mStillCaptureControl->init();
       
   447     } else if (mode() == Cxe::VideoMode) {
       
   448         mStillCaptureControl->deinit();
       
   449         mVideoCaptureControl->init();
       
   450     }
       
   451 
       
   452     OstTrace0(camerax_performance, CXEENGINESYMBIAN_DOINIT_OUT, "msg: e_CX_ENGINE_DO_INIT 0");
       
   453 
       
   454     CX_DEBUG_EXIT_FUNCTION();
       
   455 }
       
   456 
       
   457 /*!
       
   458  * Returns camera mode.
       
   459  */
       
   460 Cxe::CameraMode CxeEngineSymbian::mode() const
       
   461 {
       
   462     return mCameraDeviceControl->mode();
       
   463 }
       
   464 
       
   465 /*!
       
   466  * Sets the camera mode.
       
   467  * \parama mode New camera mode
       
   468  */
       
   469 void CxeEngineSymbian::setMode(Cxe::CameraMode mode)
       
   470 {
       
   471     CX_DEBUG_ENTER_FUNCTION();
       
   472     mCameraDeviceControl->setMode(mode);
       
   473     CX_DEBUG_EXIT_FUNCTION();
       
   474 }
       
   475 /*!
       
   476     Check if we need to reserve camera.
       
   477 */
       
   478 bool CxeEngineSymbian::reserveNeeded()
       
   479 {
       
   480     // If camera device control is in Idle or pending release state,
       
   481     // we need to call reserve()
       
   482     return (mCameraDeviceControl->state() == CxeCameraDeviceControl::Idle ||
       
   483             mCameraDeviceControl->state() == CxeCameraDeviceControl::PendingRelease);
       
   484 }
       
   485 
       
   486 /*!
       
   487     Check if we need to prepare image/video capture.
       
   488 */
       
   489 bool CxeEngineSymbian::initNeeded()
       
   490 {
       
   491     bool result = false;
       
   492 
       
   493     if (mCameraDeviceControl->state() == CxeCameraDeviceControl::Ready) {
       
   494         if (mode() == Cxe::ImageMode) {
       
   495             if(mStillCaptureControl->state() == CxeStillCaptureControl::Uninitialized) {
       
   496                 // We're in still image mode, camera is reserved and ready, but
       
   497                 // we need to prepare still image control
       
   498                 result = true;
       
   499             }
       
   500         } else if (mode() == Cxe::VideoMode) {
       
   501             if (mVideoCaptureControl->state() == CxeVideoCaptureControl::Idle ||
       
   502                 mVideoCaptureControl->state() == CxeVideoCaptureControl::Initialized) {
       
   503                 // We're in video mode, camera is reserved and ready, but
       
   504                 // we need to prepare for video recording.
       
   505                 result = true;
       
   506             }
       
   507         }
       
   508     }
       
   509 
       
   510     return result;
       
   511 }
       
   512 
       
   513 /*!
       
   514     Check if we need to start viewfinder.
       
   515 */
       
   516 bool CxeEngineSymbian::startViewfinderNeeded()
       
   517 {
       
   518     bool result = false;
       
   519 
       
   520     if (mViewfinderControl->state() != CxeViewfinderControl::Running) {
       
   521         if (mode() == Cxe::ImageMode &&
       
   522             mStillCaptureControl->state() == CxeStillCaptureControl::Ready) {
       
   523             // We're in still image mode and ready for capturing... we just need to
       
   524             // start viewfinder.
       
   525             result = true;
       
   526         } else if (mode() == Cxe::VideoMode &&
       
   527                    mVideoCaptureControl->state() == CxeVideoCaptureControl::Ready) {
       
   528             // We're in video mode and ready for capturing... we just need to
       
   529             // start viewfinder.
       
   530             result = true;
       
   531         }
       
   532     }
       
   533 
       
   534     return result;
       
   535 }
       
   536 
       
   537 void CxeEngineSymbian::initMode(Cxe::CameraMode cameraMode)
       
   538 {
       
   539     CX_DEBUG_ENTER_FUNCTION();
       
   540     OstTrace0(camerax_performance, CXEENGINE_INITMODE_IN, "msg: e_CX_ENGINE_INIT_MODE 1");
       
   541 
       
   542     if (mode() == cameraMode) {
       
   543         CX_DEBUG(("initMode() called for current mode"));
       
   544 
       
   545         // We're already in the requested mode. However, it is possible
       
   546         // that we need to reserve and power on camera and/or prepare
       
   547         // the capture control.
       
   548         if (reserveNeeded()) {
       
   549             // Camera needs to be reserved. Initialization will continue
       
   550             // when we get the deviceReady() signal.
       
   551             CX_DEBUG(("initMode() - calling reserve()"));
       
   552             reserve();
       
   553         } else if (initNeeded()) {
       
   554             // Camera is reserved and ready, but we need to prepare still image control or
       
   555             // video capture control
       
   556             CX_DEBUG(("initMode() - calling doInit()"));
       
   557             doInit();
       
   558         } else if (startViewfinderNeeded()) {
       
   559             // Everything is ready and prepared, but we viewfinder is not yet running
       
   560             CX_DEBUG(("initMode() - calling viewfinder start()"));
       
   561             mViewfinderControl->start();
       
   562         } else {
       
   563             CX_DEBUG(("initMode() - no actions needed"));
       
   564             // Do nothing.
       
   565             // We are either already ready to capture or the we're pending
       
   566             // on prepare complete callback.
       
   567         }
       
   568     } else {
       
   569         CX_DEBUG(("initMode() called for mode switch"));
       
   570 
       
   571         // Mode switch
       
   572         mCameraDeviceControl->setMode(cameraMode);
       
   573         // stop the vf
       
   574         mViewfinderControl->stop();
       
   575 
       
   576         if (reserveNeeded()) {
       
   577             CX_DEBUG(("initMode() - calling reserve()"));
       
   578             reserve();
       
   579         } else if (mCameraDeviceControl->state() == CxeCameraDeviceControl::Ready) {
       
   580             CX_DEBUG(("initMode() - calling doInit()"));
       
   581             // Camera device is ready... we only need to prepare video or still
       
   582             // capture control, depending on current mode.
       
   583             doInit();
       
   584         } else {
       
   585             CX_DEBUG(("initMode() - no actions needed"));
       
   586             // Do nothing.
       
   587             // Camera device control is in Initializing state. Initialization will continue
       
   588             // when we get the deviceReady() callback.
       
   589         }
       
   590     }
       
   591 
       
   592     OstTrace0(camerax_performance, CXEENGINE_INITMODE_OUT, "msg: e_CX_ENGINE_INIT_MODE 0");
       
   593     CX_DEBUG_EXIT_FUNCTION();
       
   594 }
       
   595 
       
   596 void CxeEngineSymbian::reserve()
       
   597 {
       
   598     CX_DEBUG_ENTER_FUNCTION();
       
   599     // Start reserving camera HW.
       
   600     mCameraDeviceControl->reserve();
       
   601     emit reserveStarted();
       
   602     CX_DEBUG_EXIT_FUNCTION();
       
   603 }
       
   604 
       
   605 
       
   606 /*!
       
   607 * Saves current mode to the cenrep
       
   608 */
       
   609 void CxeEngineSymbian::saveMode()
       
   610 {
       
   611     CX_DEBUG_ENTER_FUNCTION();
       
   612 
       
   613     if (mCameraDeviceControl && mSettings) {
       
   614         try {
       
   615             mSettings->set(CxeSettingIds::CAMERA_MODE, mCameraDeviceControl->mode());
       
   616         } catch (CxeException &e) {
       
   617             CX_DEBUG(("Failed to save camera mode, error=%d", e.error()));
       
   618         }
       
   619     }
       
   620 
       
   621     CX_DEBUG_EXIT_FUNCTION();
       
   622 }
       
   623 
       
   624 
       
   625 /*!
       
   626 * Initialize geotagging.
       
   627 * Check if we are allowed to start the geotagging and if it's supported in current mode.
       
   628 */
       
   629 void CxeEngineSymbian::initGeotagging()
       
   630 {
       
   631     CX_DEBUG_ENTER_FUNCTION();
       
   632     OstTrace0(camerax_performance, CXEENGINE_START_GEO_IN, "msg: e_CX_ENGINE_START_GEOTAGGING 1");
       
   633 
       
   634     if (mGeoTaggingTrail && mSettings) {
       
   635         if (mode() == Cxe::ImageMode) {
       
   636             // Location trail is limited to image mode only for now.
       
   637             Cxe::GeoTaggingDisclaimer value =
       
   638                 mSettings->get<Cxe::GeoTaggingDisclaimer>(
       
   639                     CxeSettingIds::GEOTAGGING_DISCLAIMER, Cxe::GeoTaggingDisclaimerDisabled);
       
   640 
       
   641             // we start location trail only when Geotagging First-time-use note is accepted by user.
       
   642             if (value == Cxe::GeoTaggingDisclaimerDisabled) {
       
   643                 mGeoTaggingTrail->start();
       
   644             }
       
   645         } else {
       
   646             // Geotagging is not (yet) supported in video mode.
       
   647             mGeoTaggingTrail->stop();
       
   648         }
       
   649     }
       
   650 
       
   651     OstTrace0(camerax_performance, CXEENGINE_START_GEO_OUT, "msg: e_CX_ENGINE_START_GEOTAGGING 0");
       
   652     CX_DEBUG_EXIT_FUNCTION();
       
   653 }
       
   654 
       
   655 // End of file