camerauis/cameraxui/cxengine/src/cxezoomcontrolsymbian.cpp
branchRCL_3
changeset 53 61bc0f252b2b
equal deleted inserted replaced
50:f54ad444594d 53:61bc0f252b2b
       
     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 "cxezoomcontrolsymbian.h"
       
    19 #include "cxecameradevicecontrol.h"
       
    20 #include "cxefeaturemanager.h"
       
    21 #include "cxesettings.h"
       
    22 #include "cxutils.h"
       
    23 #include "cxenamespace.h"
       
    24 #include "cxestate.h"
       
    25 #include "cxeexception.h"
       
    26 
       
    27 #include "OstTraceDefinitions.h"
       
    28 #ifdef OST_TRACE_COMPILER_IN_USE
       
    29 #include "cxezoomcontrolsymbianTraces.h"
       
    30 #endif
       
    31 
       
    32 namespace
       
    33 {
       
    34     const int NOT_DEFINED = -1;
       
    35 }
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CxeZoomControlSymbian::CxeZoomControlSymbian
       
    39 //
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CxeZoomControlSymbian::CxeZoomControlSymbian(CxeCameraDevice &cameraDevice,
       
    43                                              CxeCameraDeviceControl &cameraDeviceControl,
       
    44                                              CxeSettings &settings,
       
    45                                              CxeFeatureManager &featureManager) :
       
    46     CxeStateMachine("CxeZoomControlSymbian"),
       
    47     mCameraDevice(cameraDevice),
       
    48     mCameraDeviceControl(cameraDeviceControl),
       
    49     mSettings(settings)
       
    50 {
       
    51     CX_DEBUG_ENTER_FUNCTION();
       
    52 
       
    53     qRegisterMetaType<CxeZoomControl::State> ();
       
    54 
       
    55     // Initialize states and member variables
       
    56     initializeStates();
       
    57 
       
    58     // getting still max zoom limits from feature manager
       
    59     featureManager.configuredValues(CxeVariationKeys::STILL_MAX_ZOOM_LIMITS, mStillMaxZoomLimits);
       
    60     featureManager.configuredValues(CxeVariationKeys::VIDEO_MAX_ZOOM_LIMITS, mVideoMaxZoomLimits);
       
    61 
       
    62     connect(&mCameraDevice,
       
    63             SIGNAL(prepareForCameraDelete()),
       
    64             this,
       
    65             SLOT(reset()));
       
    66 
       
    67     init();
       
    68 
       
    69     CX_DEBUG_EXIT_FUNCTION();
       
    70 }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CxeZoomControlSymbian::~CxeZoomControlSymbian
       
    74 //
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CxeZoomControlSymbian::~CxeZoomControlSymbian()
       
    78 {
       
    79     CX_DEBUG_ENTER_FUNCTION();
       
    80 
       
    81     // clean up
       
    82     mDigitalZoomValues.Close();
       
    83 
       
    84     CX_DEBUG_EXIT_FUNCTION();
       
    85 }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CxeZoomControlSymbian::min
       
    89 // Get the minimum zoom index
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 int CxeZoomControlSymbian::min() const
       
    93 {
       
    94     return mMinZoomLevel;
       
    95 }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CxeZoomControlSymbian::max
       
    99 // Get the maximum zoom index
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 int CxeZoomControlSymbian::max() const
       
   103 {
       
   104     return mMaxZoomLevel;
       
   105 }
       
   106 
       
   107 void CxeZoomControlSymbian::init()
       
   108 {
       
   109     CX_DEBUG_ENTER_FUNCTION();
       
   110 
       
   111     // Initialize the variables
       
   112     mMinZoomLevel = 0;
       
   113     mMaxZoomLevel = 0;
       
   114     mCurrentZoomLevel = 0;
       
   115     mDigitalZoomValues.Close();
       
   116 
       
   117     setState(Idle);
       
   118 
       
   119     CX_DEBUG_EXIT_FUNCTION();
       
   120 }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // CxeZoomControlSymbian::reset
       
   124 // Re-initializes the zoom control
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 void CxeZoomControlSymbian::reset()
       
   128 {
       
   129     CX_DEBUG_ENTER_FUNCTION();
       
   130 
       
   131     init();
       
   132     emit zoomLevelChanged(mCurrentZoomLevel);
       
   133 
       
   134     CX_DEBUG_EXIT_FUNCTION();
       
   135 }
       
   136 
       
   137 
       
   138 
       
   139 /*!
       
   140 * slot to prepare zoom control for still mode
       
   141 */
       
   142 void CxeZoomControlSymbian::prepareZoomForStill(int ecamStillResolutionIndex)
       
   143 {
       
   144     CX_DEBUG_ENTER_FUNCTION();
       
   145     OstTrace0(camerax_performance, CXEZOOMCONTROLSYMBIAN_PREPARESTILL_IN, "msg: e_CX_PREPARE_ZOOM 1");
       
   146 
       
   147     if (mCameraDeviceControl.state() == CxeCameraDeviceControl::Ready) {
       
   148         reset();
       
   149         // For image mode
       
   150         CCamera::TFormat format = CCamera::EFormatExif;
       
   151         TBool isInfluencePossible = EFalse;
       
   152         int error = KErrNone;
       
   153 
       
   154         // Get the zoom steps for image mode
       
   155         TRAP(error, mCameraDevice.advancedSettings()->GetDigitalZoomStepsForStillL (
       
   156                             mDigitalZoomValues,
       
   157                             mDigitalZoomValueInfo,
       
   158                             ecamStillResolutionIndex,
       
   159                             format,
       
   160                             isInfluencePossible));
       
   161 
       
   162 
       
   163         try {
       
   164             int imageQualityIndex = mSettings.get<int>(CxeSettingIds::IMAGE_QUALITY);
       
   165             if (mStillMaxZoomLimits.count() > 0 && imageQualityIndex < mStillMaxZoomLimits.count()) {
       
   166                 // fetching the zoom limit based on the image quality
       
   167                 mMaxZoomLevel = mStillMaxZoomLimits[imageQualityIndex];
       
   168             }
       
   169         } catch (CxeException &e) {
       
   170             mMaxZoomLevel = NOT_DEFINED;
       
   171         }
       
   172 
       
   173         finalizeZoomPreparation(error);
       
   174     }
       
   175 
       
   176     OstTrace0(camerax_performance, CXEZOOMCONTROLSYMBIAN_PREPARESTILL_OUT, "msg: e_CX_PREPARE_ZOOM 0");
       
   177     CX_DEBUG_EXIT_FUNCTION();
       
   178 }
       
   179 
       
   180 
       
   181 /*!
       
   182 * slot to prepare zoom control for video mode
       
   183 */
       
   184 void CxeZoomControlSymbian::prepareZoomForVideo()
       
   185 {
       
   186     CX_DEBUG_ENTER_FUNCTION();
       
   187     OstTrace0(camerax_performance, CXEZOOMCONTROLSYMBIAN_PREPAREVIDEO_IN, "msg: e_CX_PREPARE_ZOOM 1");
       
   188 
       
   189     if (mCameraDeviceControl.state() == CxeCameraDeviceControl::Ready) {
       
   190         reset();
       
   191         // if CxeCameraDeviceControl is ready, this pointer is valid
       
   192         CX_ASSERT_ALWAYS(mCameraDevice.advancedSettings());
       
   193         int error = KErrNone;
       
   194         TRAP(error,
       
   195                 mCameraDevice.advancedSettings()->GetDigitalZoomStepsL(mDigitalZoomValues, mDigitalZoomValueInfo);
       
   196             );
       
   197 
       
   198         if (mVideoMaxZoomLimits.count() > 0) {
       
   199             // fetching the zoom limit based on the video quality
       
   200             mMaxZoomLevel = mVideoMaxZoomLimits[0];
       
   201         } else {
       
   202             mMaxZoomLevel = NOT_DEFINED;
       
   203         }
       
   204 
       
   205         finalizeZoomPreparation(error);
       
   206     }
       
   207 
       
   208     OstTrace0(camerax_performance, CXEZOOMCONTROLSYMBIAN_PREPAREVIDEO_OUT, "msg: e_CX_PREPARE_ZOOM 0");
       
   209     CX_DEBUG_EXIT_FUNCTION();
       
   210 }
       
   211 
       
   212 
       
   213 
       
   214 /**
       
   215 * Completes zoom control preparation.
       
   216 */
       
   217 void CxeZoomControlSymbian::finalizeZoomPreparation(int error)
       
   218 {
       
   219     CX_DEBUG_ENTER_FUNCTION();
       
   220 
       
   221     CX_DEBUG(("Num digital zoom steps: %d", mDigitalZoomValues.Count()));
       
   222     CX_DEBUG(("Maximum zoom limit: %d", mMaxZoomLevel));
       
   223 
       
   224     if (!error) {
       
   225         // Note that this is called only after setting the resolution.
       
   226         TCameraInfo cameraInfo;
       
   227         mCameraDevice.camera()->CameraInfo(cameraInfo);
       
   228         CX_DEBUG(("cameraInfo.iMinZoom: %d, cameraInfo.iMaxDigitalZoom: %d, cameraInfo.iMaxZoom: %d",
       
   229                             cameraInfo.iMinZoom, cameraInfo.iMaxDigitalZoom, cameraInfo.iMaxZoom ));
       
   230 
       
   231         CX_DEBUG(("cameraInfo.iMaxDigitalZoomFactor: %d", cameraInfo.iMaxDigitalZoomFactor));
       
   232 
       
   233         mMinZoomLevel = cameraInfo.iMinZoom;
       
   234         if ( (mMaxZoomLevel == NOT_DEFINED) || mMaxZoomLevel > cameraInfo.iMaxDigitalZoom) {
       
   235             CX_DEBUG(("Fetching maximum zoom limit value from ecam"));
       
   236             mMaxZoomLevel = cameraInfo.iMaxDigitalZoom;
       
   237         }
       
   238         // change the state, since zoom is now ready
       
   239         setState(Ready);
       
   240 
       
   241         mCameraDevice.advancedSettings()->SetDigitalZoom(mDigitalZoomValues[mCurrentZoomLevel]);
       
   242 
       
   243         // emit the zoom changed signal so that clients can do any updates if necessary.
       
   244         emit zoomLevelChanged(mCurrentZoomLevel);
       
   245     }
       
   246 
       
   247     CX_DEBUG_EXIT_FUNCTION();
       
   248 }
       
   249 
       
   250 // ---------------------------------------------------------------------------
       
   251 // CxeZoomControlSymbian::zoomTo
       
   252 // Zooms to the level specified in the parameter.
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 void CxeZoomControlSymbian::zoomTo(int value)
       
   256 {
       
   257     CX_DEBUG_ENTER_FUNCTION();
       
   258 
       
   259     CX_DEBUG(("Zoom to: %d, current zoom: %d", value, mCurrentZoomLevel));
       
   260 
       
   261     // If not currently zooming and value falls between min & max
       
   262     // then zoom to the passed level. Also there's no need to zoom if new zoom
       
   263     // level is same as the current.
       
   264     if (state() == CxeZoomControl::Ready && (value <= mMaxZoomLevel)
       
   265             && (value >= mMinZoomLevel) && (mCurrentZoomLevel != value)) {
       
   266 
       
   267         // Set the appropriate zooming state
       
   268         if (value < mCurrentZoomLevel) {
       
   269             setState(CxeZoomControl::ZoomingOut);
       
   270         } else {
       
   271             setState(CxeZoomControl::ZoomingIn);
       
   272         }
       
   273 
       
   274         // Could also check the number of values in the array to avoid out of bounds indexing,
       
   275         // though this is done in alternate way by the min and max limits.
       
   276         mCameraDevice.advancedSettings()->SetDigitalZoom(mDigitalZoomValues[value]);
       
   277         mCurrentZoomLevel = value;
       
   278 
       
   279         //! @todo: Wait for zoom callback: ECamEventZoomStateChanged ?
       
   280         // set the state to idle.
       
   281         setState(CxeZoomControl::Ready);
       
   282 
       
   283         // Emit the zoom level change signal
       
   284         emit zoomLevelChanged(mCurrentZoomLevel);
       
   285     }
       
   286 
       
   287     CX_DEBUG_EXIT_FUNCTION();
       
   288 }
       
   289 
       
   290 CxeZoomControl::State CxeZoomControlSymbian::state() const
       
   291 {
       
   292     return static_cast<State> (stateId());
       
   293 }
       
   294 
       
   295 void CxeZoomControlSymbian::handleStateChanged(int newStateId,
       
   296                                                CxeError::Id error)
       
   297 {
       
   298     emit stateChanged(static_cast<State> (newStateId), error);
       
   299 }
       
   300 
       
   301 void CxeZoomControlSymbian::initializeStates()
       
   302 {
       
   303     // addState( id, name, allowed next states )
       
   304     addState(new CxeState(Idle, "Idle", Ready));
       
   305     addState(new CxeState(ZoomingIn, "ZoomingIn", Ready | ZoomingOut | Idle));
       
   306     addState(new CxeState(ZoomingOut, "ZoomingOut", Ready | ZoomingIn | Idle));
       
   307     addState(new CxeState(Ready, "Ready", Idle | ZoomingOut | ZoomingIn));
       
   308 
       
   309     setInitialState(Idle);
       
   310 }