camerauis/cameraxui/cxengine/src/cxeautofocuscontrolsymbian.cpp
changeset 43 0e652f8f1fbd
parent 28 3075d9b614e6
child 45 24fd82631616
equal deleted inserted replaced
28:3075d9b614e6 43:0e652f8f1fbd
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    38 
    38 
    39 
    39 
    40 /*
    40 /*
    41 * CxeAutoFocusControlSymbian::CxeAutoFocusControlSymbian
    41 * CxeAutoFocusControlSymbian::CxeAutoFocusControlSymbian
    42 */
    42 */
    43 CxeAutoFocusControlSymbian::CxeAutoFocusControlSymbian(CxeCameraDevice &cameraDevice)
    43 CxeAutoFocusControlSymbian::CxeAutoFocusControlSymbian(CxeCameraDevice &cameraDevice,
       
    44                                                        CxeSettings &settings)
    44     : CxeStateMachine("CxeAutoFocusControlSymbian"),
    45     : CxeStateMachine("CxeAutoFocusControlSymbian"),
    45       mCameraDevice(cameraDevice),
    46       mCameraDevice(cameraDevice),
    46       mAdvancedSettings(NULL),
    47       mAdvancedSettings(NULL),
    47       mCancelled(false)
    48       mSettings(settings),
       
    49       mCancelled(false),
       
    50       mFaceTrackingOverride(false)
    48 {
    51 {
    49     CX_DEBUG_ENTER_FUNCTION();
    52     CX_DEBUG_ENTER_FUNCTION();
    50 
    53 
    51     qRegisterMetaType<CxeAutoFocusControl::State>();
    54     qRegisterMetaType<CxeAutoFocusControl::State>();
    52 
    55 
    63                       this,SLOT(handleCameraAllocated(CxeError::Id)) );
    66                       this,SLOT(handleCameraAllocated(CxeError::Id)) );
    64 
    67 
    65     QObject::connect( &cameraDevice,
    68     QObject::connect( &cameraDevice,
    66                       SIGNAL(prepareForRelease()),
    69                       SIGNAL(prepareForRelease()),
    67                       this,SLOT(prepareForRelease()) );
    70                       this,SLOT(prepareForRelease()) );
       
    71 
       
    72     // connect scene / setting change callbacks to settings control
       
    73     QObject::connect(&mSettings,
       
    74             SIGNAL(settingValueChanged(const QString&,QVariant)),
       
    75             this,
       
    76             SLOT(handleSettingValueChanged(const QString&,QVariant)));
       
    77 
    68     OstTrace0(camerax_performance, CXEAUTOFOCUSCONTROLSYMBIAN_CREATE_MID2, "msg: e_CX_ENGINE_CONNECT_SIGNALS 0");
    78     OstTrace0(camerax_performance, CXEAUTOFOCUSCONTROLSYMBIAN_CREATE_MID2, "msg: e_CX_ENGINE_CONNECT_SIGNALS 0");
    69 
    79 
    70     initializeResources();
    80     initializeResources();
    71 
    81 
    72     CX_DEBUG_EXIT_FUNCTION();
    82     CX_DEBUG_EXIT_FUNCTION();
    89 * \param soundEnabled False if the auto focus sound don't need to be played
    99 * \param soundEnabled False if the auto focus sound don't need to be played
    90 * Default value for soundEnabled is true
   100 * Default value for soundEnabled is true
    91 */
   101 */
    92 CxeError::Id CxeAutoFocusControlSymbian::start(bool soundEnabled)
   102 CxeError::Id CxeAutoFocusControlSymbian::start(bool soundEnabled)
    93 {
   103 {
       
   104     CX_ASSERT_ALWAYS(mAdvancedSettings);
       
   105 
    94     CX_DEBUG( ("CxeAutoFocusControlSymbian::start() <> state: %d, sound enabled: %d",
   106     CX_DEBUG( ("CxeAutoFocusControlSymbian::start() <> state: %d, sound enabled: %d",
    95                state(), soundEnabled ) );
   107                state(), soundEnabled ) );
       
   108 
    96     mSoundEnabled = soundEnabled;
   109     mSoundEnabled = soundEnabled;
    97     int err = KErrNone;
   110     CxeError::Id error = CxeError::None;
    98 
   111 
    99     CX_ASSERT_ALWAYS(mAdvancedSettings);
   112     if (!isFixedFocusMode(mode())) {
   100 
   113         if ( state() != CxeAutoFocusControl::InProgress && state() != CxeAutoFocusControl::Canceling  ) {
   101     if ( state() != CxeAutoFocusControl::InProgress && state() != CxeAutoFocusControl::Canceling  ) {
   114             CX_DEBUG(("CxeAutoFocusControlSymbian::start() calling SetAutoFocusType"));
   102         CX_DEBUG(("CxeAutoFocusControlSymbian::start() calling SetAutoFocusType"));
   115             mCancelled = false;
   103         mCancelled = false;
   116             setState(InProgress);
   104         setState(InProgress);
   117             setFocusRange(mAFRange);
   105         setFocusRange(mAFRange);
   118             setFocusType(CCamera::CCameraAdvancedSettings::EAutoFocusTypeSingle);
   106         setFocusType(CCamera::CCameraAdvancedSettings::EAutoFocusTypeSingle);
   119         } else { // AF was started earlier, can't start until it completes
   107     } else { // AF was started earlier, can't start until it completes
   120             error = CxeError::InUse;
   108         err = KErrInUse;
   121         }
   109     }
   122     }
   110 
   123 
   111     CX_DEBUG( ("CxeAutoFocusControlSymbian::start() <= err : %d", err ) );
   124     CX_DEBUG( ("CxeAutoFocusControlSymbian::start() <= error: %d", error ) );
   112     return CxeErrorHandlingSymbian::map(err);
   125     return error;
   113 }
   126 }
   114 
   127 
   115 
   128 
   116 
   129 
   117 /*
   130 /*
   121 {
   134 {
   122     CX_DEBUG( ("CxeAutoFocusControlSymbian::cancel <> state: %d", state() ) );
   135     CX_DEBUG( ("CxeAutoFocusControlSymbian::cancel <> state: %d", state() ) );
   123 
   136 
   124     CX_DEBUG_ASSERT(mAdvancedSettings);
   137     CX_DEBUG_ASSERT(mAdvancedSettings);
   125 
   138 
   126     if (!mCancelled) {
   139     if (!mCancelled && !isFixedFocusMode(mode())) {
   127         if (state() == CxeAutoFocusControl::InProgress) {
   140         if (state() == CxeAutoFocusControl::InProgress) {
   128             // Need to stop current AF first. Wait for AF event to proceed.
   141             // Need to stop current AF first. Wait for AF event to proceed.
   129             setState(CxeAutoFocusControl::Canceling);
   142             setState(CxeAutoFocusControl::Canceling);
   130             setFocusType(CCamera::CCameraAdvancedSettings::EAutoFocusTypeOff);
   143             setFocusType(CCamera::CCameraAdvancedSettings::EAutoFocusTypeOff);
   131 
   144 
   169 CxeAutoFocusControl::Mode CxeAutoFocusControlSymbian::mode() const
   182 CxeAutoFocusControl::Mode CxeAutoFocusControlSymbian::mode() const
   170 {
   183 {
   171     return mAfMode;
   184     return mAfMode;
   172 }
   185 }
   173 
   186 
       
   187 /**
       
   188 * Is the given mode a fixed focus mode?
       
   189 */
       
   190 bool CxeAutoFocusControlSymbian::isFixedFocusMode(CxeAutoFocusControl::Mode mode) const
       
   191 {
       
   192     return (mode == CxeAutoFocusControl::Hyperfocal
       
   193          || mode == CxeAutoFocusControl::Infinity);
       
   194 }
   174 
   195 
   175 /*
   196 /*
   176 * To check if Autofocus is supported
   197 * To check if Autofocus is supported
   177 */
   198 */
   178 bool CxeAutoFocusControlSymbian::supported() const
   199 bool CxeAutoFocusControlSymbian::supported() const
   387     // whenever scene mode is changed we set the state to unknown
   408     // whenever scene mode is changed we set the state to unknown
   388     setState(CxeAutoFocusControl::Unknown);
   409     setState(CxeAutoFocusControl::Unknown);
   389 
   410 
   390     // we are interested only in the AF range.
   411     // we are interested only in the AF range.
   391     if(scene.contains(CxeSettingIds::FOCAL_RANGE) && supported() ) {
   412     if(scene.contains(CxeSettingIds::FOCAL_RANGE) && supported() ) {
       
   413 
   392         setMode(static_cast<CxeAutoFocusControl::Mode>(scene[CxeSettingIds::FOCAL_RANGE].toInt()));
   414         setMode(static_cast<CxeAutoFocusControl::Mode>(scene[CxeSettingIds::FOCAL_RANGE].toInt()));
       
   415 
       
   416         if (isFixedFocusMode(mode())) {
       
   417             // Focus now if a fixed focus mode is used.
       
   418             setFocusType(CCamera::CCameraAdvancedSettings::EAutoFocusTypeSingle);
       
   419             // Set state to InProgress, so we know to set it ready in ECAM callback.
       
   420             setState(CxeAutoFocusControl::InProgress);
       
   421         }
   393     }
   422     }
   394 
   423 
   395     CX_DEBUG_EXIT_FUNCTION();
   424     CX_DEBUG_EXIT_FUNCTION();
   396 }
   425 }
   397 
   426 
   455 bool CxeAutoFocusControlSymbian::isSoundEnabled() const
   484 bool CxeAutoFocusControlSymbian::isSoundEnabled() const
   456 {
   485 {
   457     return mSoundEnabled;
   486     return mSoundEnabled;
   458 }
   487 }
   459 
   488 
       
   489 /*!
       
   490 * Handle new setting value.
       
   491 * New value is set to camera.
       
   492 * \param settingId The id of the updated setting
       
   493 * \param newValue A new value for the updated setting
       
   494 */
       
   495 void CxeAutoFocusControlSymbian::handleSettingValueChanged(const QString& settingId, QVariant newValue)
       
   496 {
       
   497     CX_DEBUG_ENTER_FUNCTION();
       
   498     if (settingId == CxeSettingIds::FACE_TRACKING) {
       
   499         // Updating AF mode when face tracking is activated
       
   500         // in scene mode which doesn't support face tracking
       
   501         if (newValue.toInt()) {
       
   502             //Face tracking enabled
       
   503             if(mAfMode == CxeAutoFocusControl::Infinity ||
       
   504                mAfMode == CxeAutoFocusControl::Hyperfocal) {
       
   505                 mPreviousAFMode = mAfMode;
       
   506                 setMode(CxeAutoFocusControl::Auto);
       
   507                 mFaceTrackingOverride = true;
       
   508             }
       
   509         } else {
       
   510             //Face tracking disabled
       
   511             if (mFaceTrackingOverride) {
       
   512                 mAfMode = mPreviousAFMode;
       
   513                 setMode(mAfMode);
       
   514                 mFaceTrackingOverride = false;
       
   515             }
       
   516         }
       
   517 
       
   518     } else {
       
   519         // do nothing
       
   520     }
       
   521 
       
   522     CX_DEBUG_EXIT_FUNCTION();
       
   523 }
       
   524 
   460 // end of file
   525 // end of file