camerauis/cameraxui/cxui/tsrc/cxuifakeengine.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 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 "cxuifakeengine.h"                // CxeEngineSymbian
       
    18 #include "cxecameradevicecontrolsymbian.h"  // CxeCameraDeviceControlSymbian
       
    19 #include "cxuifakestillcapturecontrol.h"
       
    20 #include "cxevideocapturecontrolsymbian.h"
       
    21 #include "cxestillcapturecontrolsymbian.h"
       
    22 #include "cxuifakeviewfindercontrol.h"
       
    23 #include "cxezoomcontrolsymbian.h"
       
    24 #include "cxutils.h"
       
    25 #include "cxesettingsimp.h"
       
    26 #include "cxefeaturemanagerimp.h"
       
    27 #include "cxesettingsmodel.h"
       
    28 #include "cxesoundplayersymbian.h"
       
    29 #include "cxuifakeautofocuscontrol.h"
       
    30 
       
    31 //  Member Functions
       
    32 
       
    33 CxuiFakeEngine::CxuiFakeEngine()
       
    34  :  mViewfinderControl( NULL ),
       
    35     mFakeStillCaptureControl( NULL ),
       
    36     mVideoCaptureControl( NULL ),
       
    37     mZoomControl( NULL ),
       
    38     mSettings( NULL )
       
    39 {
       
    40     CX_DEBUG_ENTER_FUNCTION();
       
    41 
       
    42     // Create all control classes
       
    43     mFakeCameraDeviceControl = new CxuiFakeCameraDeviceControl();
       
    44 
       
    45     CxeCameraDevice* cameraDevice = mFakeCameraDeviceControl->cameraDevice();
       
    46 
       
    47     mSettingsModel = new CxeSettingsModel();
       
    48     mSettings = new CxeSettingsImp(*mSettingsModel);
       
    49     mFeatureManager = new CxeFeatureManagerImp(*mSettingsModel);
       
    50     mSoundPlayer = new CxeSoundPlayerSymbian(*mFakeCameraDeviceControl);
       
    51     mFilenameGenerator = new CxeFilenameGeneratorSymbian(*mSettings, mode());
       
    52 
       
    53     mViewfinderControl = new CxuiFakeViewfinderControl(*cameraDevice, *mFakeCameraDeviceControl);
       
    54 
       
    55     mFakeStillCaptureControl = new CxuiFakeStillCaptureControl(
       
    56             *cameraDevice,
       
    57             *mViewfinderControl,
       
    58             *mFakeCameraDeviceControl,
       
    59             *mSoundPlayer,
       
    60             *mFilenameGenerator);
       
    61 
       
    62     mFakeAutoFocusControl = new CxuiFakeAutoFocusControl(*cameraDevice);
       
    63 
       
    64     mVideoCaptureControl = new CxeVideoCaptureControlSymbian(
       
    65             *cameraDevice,
       
    66             *mViewfinderControl,
       
    67             *mFakeCameraDeviceControl,
       
    68             *mSoundPlayer,
       
    69             *mFilenameGenerator);
       
    70 
       
    71     // connecting camera mode changes to updating capture sounds
       
    72     connect(mFakeCameraDeviceControl, SIGNAL(initModeComplete(CxeError::Id)),
       
    73             mSoundPlayer, SLOT(updateCaptureSound()));
       
    74 
       
    75     // connecting scene setting change callbacks to ViewfinderControl
       
    76     connect(mSettings, SIGNAL(settingValueChanged(const QString&,QVariant)),
       
    77             mViewfinderControl, SLOT(handleSettingValueChanged(const QString&,QVariant)));
       
    78 
       
    79     connect(mSettings, SIGNAL(sceneChanged(CxeScene&)),
       
    80             mViewfinderControl, SLOT(handleSceneChanged(CxeScene&)));
       
    81 
       
    82     // enabling scene setting change callbacks to stillcapturecontrol
       
    83     connect(mSettings, SIGNAL(settingValueChanged(const QString&,QVariant)),
       
    84             mFakeStillCaptureControl, SLOT(handleSettingValueChanged(const QString&,QVariant)));
       
    85 
       
    86     connect(mSettings, SIGNAL(sceneChanged(CxeScene&)),
       
    87             mFakeStillCaptureControl, SLOT(handleSceneChanged(CxeScene&)));
       
    88 
       
    89     // enabling scene setting change callbacks to videocapturecontrol
       
    90     connect(mSettings, SIGNAL(settingValueChanged(const QString&,QVariant)),
       
    91             mVideoCaptureControl, SLOT(handleSettingValueChanged(const QString&,QVariant)));
       
    92 
       
    93     connect(mSettings, SIGNAL(sceneChanged(CxeScene&)),
       
    94             mVideoCaptureControl, SLOT(handleSceneChanged(CxeScene&)));
       
    95 
       
    96 
       
    97     // enabling callbacks to Autofocus control
       
    98     connect(mSettings, SIGNAL(sceneChanged(CxeScene&)),
       
    99             mFakeAutoFocusControl, SLOT(handleSceneChanged(CxeScene&)) );
       
   100 
       
   101     // Connect signals for ECam events
       
   102     // TJ
       
   103     connect( mFakeCameraDeviceControl, SIGNAL(cameraEvent(int,int)),
       
   104              mFakeStillCaptureControl, SLOT(handleCameraEvent(int,int)) );
       
   105     connect( mFakeCameraDeviceControl, SIGNAL(cameraEvent(int,int)),
       
   106             mVideoCaptureControl, SLOT(handleCameraEvent(int,int)) );
       
   107     connect( mFakeCameraDeviceControl, SIGNAL(cameraEvent(int,int)),
       
   108             mFakeAutoFocusControl, SLOT(handleCameraEvent(int,int)) );
       
   109 
       
   110     // Connect signal for device ready events
       
   111     connect( mFakeCameraDeviceControl, SIGNAL(deviceReady()),
       
   112              this, SLOT(doInit()) );
       
   113 
       
   114     // Connect ECam image buffer ready event
       
   115     connect( mFakeCameraDeviceControl, SIGNAL(imageBufferReady(MCameraBuffer*,int)),
       
   116             mFakeStillCaptureControl, SLOT(handleImageData(MCameraBuffer*,int)) );
       
   117 
       
   118     // Connect ECam VF frame ready event
       
   119     connect( mFakeCameraDeviceControl, SIGNAL(vfFrameReady(MCameraBuffer*,int)),
       
   120              mViewfinderControl, SLOT(handleVfFrame(MCameraBuffer*,int)) );
       
   121 
       
   122     // Connect image and video init complete signals to CameraDeviceControl initModeComplete
       
   123     connect(mFakeStillCaptureControl, SIGNAL(imagePrepareComplete(CxeError::Id)),
       
   124              mFakeCameraDeviceControl, SIGNAL(initModeComplete(CxeError::Id)) );
       
   125 
       
   126     connect(mVideoCaptureControl, SIGNAL(videoPrepareComplete(CxeError::Id)),
       
   127              mFakeCameraDeviceControl, SIGNAL(initModeComplete(CxeError::Id)) );
       
   128 
       
   129     CX_DEBUG_EXIT_FUNCTION();
       
   130 }
       
   131 
       
   132 CxuiFakeEngine::~CxuiFakeEngine()
       
   133 {
       
   134     CX_DEBUG_ENTER_FUNCTION();
       
   135 
       
   136     delete mViewfinderControl;
       
   137     delete mZoomControl;
       
   138     delete mVideoCaptureControl;
       
   139     delete mSoundPlayer;
       
   140     delete mFilenameGenerator;
       
   141 
       
   142     CX_DEBUG_EXIT_FUNCTION();
       
   143 }
       
   144 
       
   145 CxeCameraDeviceControl &CxuiFakeEngine::cameraDeviceControl()
       
   146 {
       
   147     return *mFakeCameraDeviceControl;
       
   148 }
       
   149 
       
   150 CxeViewfinderControl &CxuiFakeEngine::viewfinderControl()
       
   151 {
       
   152     return *mViewfinderControl;
       
   153 }
       
   154 
       
   155 CxeStillCaptureControlSymbian &CxuiFakeEngine::stillCaptureControl()
       
   156 {
       
   157     return *mFakeStillCaptureControl;
       
   158 }
       
   159 
       
   160 CxeVideoCaptureControlSymbian &CxuiFakeEngine::videoCaptureControl()
       
   161 {
       
   162     return *mVideoCaptureControl;
       
   163 }
       
   164 
       
   165 CxeAutoFocusControlSymbian &CxuiFakeEngine::autoFocusControl()
       
   166 {
       
   167     return *mFakeAutoFocusControl;
       
   168 }
       
   169 
       
   170 CxeZoomControlSymbian &CxuiFakeEngine::zoomControl()
       
   171 {
       
   172     return *mZoomControl;
       
   173 }
       
   174 
       
   175 // Get the settings handle
       
   176 CxeSettings &CxuiFakeEngine::settings()
       
   177 {
       
   178     return *mSettings;
       
   179 }
       
   180 
       
   181 CxeFeatureManager& CxuiFakeEngine::featureManager()
       
   182 {
       
   183     return *mFeatureManager;
       
   184 }
       
   185 
       
   186 void CxuiFakeEngine::doInit()
       
   187 {
       
   188     CX_DEBUG_ENTER_FUNCTION();
       
   189     // load settings whenever we change mode or start camera or switch camera
       
   190     //static_cast<CxeSettingsImp*>(mSettings)->loadSettings(mode());
       
   191     mFilenameGenerator->init(mode());
       
   192 
       
   193     if ( mode() == Cxe::ImageMode ) {
       
   194         mFakeStillCaptureControl->init();
       
   195     } else if ( mode() == Cxe::VideoMode ) {
       
   196         mFakeStillCaptureControl->deinit();
       
   197         mVideoCaptureControl->init();
       
   198     }
       
   199 }
       
   200 
       
   201 Cxe::CameraMode CxuiFakeEngine::mode() const
       
   202 {
       
   203     return mFakeCameraDeviceControl->mode();
       
   204 }
       
   205 
       
   206 void CxuiFakeEngine::initModeFake(Cxe::CameraMode cameraMode)
       
   207 {
       
   208     mFakeCameraDeviceControl->setMode( cameraMode );
       
   209     if( cameraMode == Cxe::ImageMode) {
       
   210         mFakeStillCaptureControl->setFakeState(CxeStillCaptureControl::Ready);
       
   211     }
       
   212 
       
   213 }
       
   214 
       
   215 void CxuiFakeEngine::initMode(Cxe::CameraMode cameraMode)
       
   216 {
       
   217     CX_DEBUG_ENTER_FUNCTION();
       
   218 
       
   219       if (mode() == cameraMode) {
       
   220           CX_DEBUG(("initMode() called for current mode"));
       
   221 
       
   222           // We're already in the requested mode. However, it is possible
       
   223           // that we need to reserve and power on camera and/or prepare
       
   224           // the capture control.
       
   225           if (reserveNeeded()) {
       
   226               // Camera needs to be reserved. Initialization will continue
       
   227               // when we get the deviceReady() signal.
       
   228               CX_DEBUG(("initMode() - calling reserve()"));
       
   229               mFakeCameraDeviceControl->reserve();
       
   230           } else if (initNeeded()) {
       
   231               // Camera is reserved and ready, but we need to prepare still image control or
       
   232               // video capture control
       
   233               CX_DEBUG(("initMode() - calling doInit()"));
       
   234               doInit();
       
   235           } else if (startViewfinderNeeded()) {
       
   236               // Everything is ready and prepared, but we viewfinder is not yet running
       
   237               CX_DEBUG(("initMode() - calling viewfinder start()"));
       
   238               mViewfinderControl->start();
       
   239           } else {
       
   240               CX_DEBUG(("initMode() - no actions needed"));
       
   241               // Do nothing.
       
   242               // We are either already ready to capture or the we're pending
       
   243               // on prepare complete callback.
       
   244           }
       
   245       } else {
       
   246           CX_DEBUG(("initMode() called for mode switch"));
       
   247 
       
   248           // Mode switch
       
   249           mFakeCameraDeviceControl->setMode(cameraMode);
       
   250 
       
   251           if (reserveNeeded()) {
       
   252               CX_DEBUG(("initMode() - calling reserve()"));
       
   253               mFakeCameraDeviceControl->reserve();
       
   254           } else if ( mFakeCameraDeviceControl->state() == CxeCameraDeviceControl::Ready ) {
       
   255               CX_DEBUG(("initMode() - calling doInit()"));
       
   256               // Camera device is ready... we only need to prepare video or still
       
   257               // capture control, depending on current mode.
       
   258               doInit();
       
   259           } else {
       
   260               CX_DEBUG(("initMode() - no actions needed"));
       
   261               // Do nothing.
       
   262               // Camera device control is in Initializing state. Initialization will continue
       
   263               // when we get the deviceReady() callback.
       
   264           }
       
   265       }
       
   266 
       
   267       CX_DEBUG_EXIT_FUNCTION();
       
   268 }
       
   269 
       
   270 bool CxuiFakeEngine::initNeeded()
       
   271 {
       
   272     bool result = false;
       
   273 
       
   274     if (mode() == Cxe::ImageMode &&
       
   275             mFakeCameraDeviceControl->state() == CxeCameraDeviceControl::Ready &&
       
   276         mFakeStillCaptureControl->state() == CxeStillCaptureControl::Uninitialized) {
       
   277         // We're in still image mode, camera is reserved and ready, but
       
   278         // we need to prepare still image control
       
   279         result = true;
       
   280     } else if (mode() == Cxe::VideoMode &&
       
   281             mFakeCameraDeviceControl->state() == CxeCameraDeviceControl::Ready) {
       
   282         if (mVideoCaptureControl->state() == CxeVideoCaptureControl::Open ||
       
   283             mVideoCaptureControl->state() == CxeVideoCaptureControl::Idle) {
       
   284             // We're in video mode, camera is reserved and ready, but
       
   285             // we need to open and prepare video recorder.
       
   286             result = true;
       
   287         }
       
   288     }
       
   289 
       
   290     return result;
       
   291 }
       
   292 
       
   293 bool CxuiFakeEngine::startViewfinderNeeded()
       
   294 {
       
   295     bool result = false;
       
   296 
       
   297     if (mViewfinderControl->state() != CxeViewfinderControl::Running) {
       
   298         if (mode() == Cxe::ImageMode &&
       
   299                 mFakeStillCaptureControl->state() == CxeStillCaptureControl::Ready) {
       
   300             // We're in still image mode and ready for capturing... we just need to
       
   301             // start viewfinder.
       
   302             result = true;
       
   303         } else if (mode() == Cxe::VideoMode &&
       
   304                    mVideoCaptureControl->state() == CxeVideoCaptureControl::Ready) {
       
   305             // We're in video mode and ready for capturing... we just need to
       
   306             // start viewfinder.
       
   307             result = true;
       
   308         }
       
   309     }
       
   310 
       
   311     return result;
       
   312 }
       
   313 
       
   314 bool CxuiFakeEngine::reserveNeeded()
       
   315 {
       
   316     CX_DEBUG_ENTER_FUNCTION();
       
   317     // If camera device control is in Idle state, we need to call reserve()
       
   318     return (mFakeCameraDeviceControl->state() == CxeCameraDeviceControl::Idle);
       
   319 }
       
   320 
       
   321 // This should be the only exported method
       
   322 CxuiFakeEngine *CxuiFakeEngine::createFakeEngine()
       
   323     {
       
   324     CX_DEBUG_ENTER_FUNCTION();
       
   325 
       
   326     CxuiFakeEngine* res = new CxuiFakeEngine();
       
   327 
       
   328     CX_DEBUG_EXIT_FUNCTION();
       
   329     return res;
       
   330     }
       
   331 
       
   332 
       
   333 CxuiFakeStillCaptureControl &CxuiFakeEngine::fakeStillCaptureControl()
       
   334 {
       
   335     return *mFakeStillCaptureControl;
       
   336 }
       
   337 
       
   338 // End of file