multimediacommscontroller/mmcccontroller/inc/mcccamerahandler.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006 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 
       
    19 
       
    20 
       
    21 
       
    22 #ifndef MCCCAMERAHANDLER_H
       
    23 #define MCCCAMERAHANDLER_H
       
    24 
       
    25 //  INCLUDES
       
    26 
       
    27 #include <e32base.h>
       
    28 #include <ecam.h>
       
    29 #include <gdi.h>
       
    30 #include "mmccinterfacedef.h"
       
    31 #include "mccexpirationhandler.h"
       
    32 
       
    33 #ifdef MCC_CAMERAHANDLER_TEST
       
    34 #include <f32file.h>
       
    35 #include <fbs.h>
       
    36 #endif
       
    37 
       
    38 // CONSTANTS
       
    39 
       
    40 // MACROS
       
    41 
       
    42 // DATA TYPES
       
    43 
       
    44 // FUNCTION PROTOTYPES
       
    45 
       
    46 // FORWARD DECLARATIONS
       
    47 
       
    48 class CMccScreen;
       
    49 class MMccResources;
       
    50 class CFbsBitmap;
       
    51 
       
    52 // CLASS DECLARATION
       
    53 
       
    54 class MMccCameraHandlerObserver
       
    55     {
       
    56     public:
       
    57     
       
    58         virtual void CameraReady( TInt aError ) = 0;
       
    59     };
       
    60     
       
    61 class MMccCameraHandler
       
    62     {
       
    63     public:
       
    64     
       
    65         /**
       
    66         * Gets camera handle.
       
    67         */
       
    68         virtual TUint32 Handle() = 0;
       
    69         
       
    70         /**
       
    71         * Checks whether camera is ready to be used (resources reserved and
       
    72         * power on).
       
    73         */
       
    74         virtual TBool IsCameraReady() = 0;
       
    75         
       
    76         /**
       
    77         * Monitor camera reservation completion.
       
    78         * @param aForceCameraReserve, reserves camera resource forcefully if ETrue
       
    79         */
       
    80         virtual TInt MonitorCameraReservation( MMccCameraHandlerObserver& aObserver, 
       
    81                                                TBool aForceCameraReserve ) = 0;
       
    82         
       
    83         /**
       
    84         * Stop monitoring
       
    85         * @param aForceCameraRelease, releases camera resource if it was reserved
       
    86         *   just by forcing it via MonitorCameraReservation.
       
    87         */
       
    88         virtual TInt StopCameraMonitoring( MMccCameraHandlerObserver& aObserver,
       
    89                                            TBool aForceCameraRelease ) = 0;
       
    90     };
       
    91 
       
    92 
       
    93 
       
    94 /**
       
    95 *  
       
    96 */
       
    97 class CMccCameraHandler : 
       
    98     public CBase, 
       
    99     public MMccCameraHandler, 
       
   100     public MCameraObserver,
       
   101     public MCameraObserver2,
       
   102     public MMccExpirationHandler                       
       
   103     {
       
   104     public: // Constructors and destructor
       
   105 
       
   106         /**
       
   107         * Two-phased constructor.
       
   108         */
       
   109         static CMccCameraHandler* NewL( MMccResources& aResources,
       
   110                                         TInt aCameraIndex = 0, 
       
   111                                         TInt aPriority = 0 );
       
   112           
       
   113         /**
       
   114         * Destructor.
       
   115         */
       
   116         virtual ~CMccCameraHandler();
       
   117 
       
   118     public: // New functions
       
   119     
       
   120         static TInt GetNumOfCamerasL();
       
   121         
       
   122         inline TInt CameraIndex() const
       
   123             {
       
   124             return iCameraIndex;
       
   125             }	
       
   126     	
       
   127     	void EnableViewFinderL( TMccVideoSinkSetting& aSetting );
       
   128 
       
   129     	void DisableViewFinderL();
       
   130     	
       
   131     	TBool IsViewFinderEnabled() const;
       
   132     	
       
   133     	void GetViewFinderSettingsL( TMccVideoSinkSetting& aSetting );
       
   134 
       
   135         void GetCamInfoL( TCameraInfo& aInfo, TBool aForceCameraCreation = EFalse );
       
   136             
       
   137         void GetValueL( TUint32 aParam, TInt& aVal );
       
   138         
       
   139         void SetValueL( TUint32 aParam, TInt aVal );
       
   140         
       
   141         void GetValueL( TUint32 aParam, TReal& aVal );
       
   142         
       
   143         void SetValueL( TUint32 aParam, TReal aVal );
       
   144         
       
   145         void ReserveResourcesL( TInt aCameraIndex, TBool aForceCameraCreation = EFalse );
       
   146         
       
   147         void ReleaseResources();
       
   148 
       
   149     public: // Functions from MMccCameraHandler
       
   150     
       
   151         TUint32 Handle();
       
   152         
       
   153         TBool IsCameraReady();
       
   154         
       
   155         TInt MonitorCameraReservation( MMccCameraHandlerObserver& aObserver, 
       
   156                                        TBool aForceCameraReserve );
       
   157         
       
   158         TInt StopCameraMonitoring( MMccCameraHandlerObserver& aObserver,
       
   159                                    TBool aForceCameraRelease );
       
   160                                        
       
   161     public: // Functions from MCameraObserver
       
   162     
       
   163 		void ReserveComplete( TInt aError );
       
   164 
       
   165 		void PowerOnComplete( TInt aError );
       
   166 
       
   167 		void ViewFinderFrameReady( CFbsBitmap& aFrame );
       
   168 
       
   169 		void ImageReady( CFbsBitmap* aBitmap, HBufC8* aData, TInt aError );
       
   170 
       
   171 		void FrameBufferReady( MFrameBuffer* aFrameBuffer, TInt aError );
       
   172                                        
       
   173     public: // Functions from MCameraObserver2
       
   174     
       
   175         void HandleEvent( const TECAMEvent& aEvent );
       
   176 
       
   177 	    void ViewFinderReady( MCameraBuffer& aCameraBuffer,TInt aError );
       
   178 
       
   179 	    void ImageBufferReady( MCameraBuffer& aCameraBuffer,TInt aError );
       
   180 
       
   181 	    void VideoBufferReady( MCameraBuffer& aCameraBuffer,TInt aError );
       
   182 	
       
   183 	public: // Functions from MMccExpirationHandler
       
   184 	
       
   185 	    void TimerExpiredL( TMccTimerId aTimerId, TAny* aTimerParam );
       
   186 	    	
       
   187     private:
       
   188         
       
   189         void DoReserveComplete( TInt aError );
       
   190 
       
   191 		void DoPowerOnComplete( TInt aError );
       
   192 		
       
   193 		void DoViewFinderFrameReady( CFbsBitmap& aFrame );
       
   194 		
       
   195         void NotifyObservers( TInt aError );
       
   196         
       
   197         TBool SettingsChanged( const TMccVideoSinkSetting& aSetting ) const;
       
   198         
       
   199         void UpdateCameraSettingsL();
       
   200         
       
   201         CCamera* CreateCameraL();
       
   202         
       
   203         void DoReleaseScreen();
       
   204         
       
   205         void DoReleaseCamera();
       
   206               
       
   207         #ifdef MCC_CAMERAHANDLER_TEST
       
   208         
       
   209         void CreateDependencyFileL();
       
   210 		void RemoveDependencyFile();
       
   211 		
       
   212 		#endif
       
   213 		/* Re-Intiallize the internal member variables 
       
   214 		 * if camera index changed.
       
   215 		 */
       
   216         void ResetCameraHandler();
       
   217 		   
       
   218     private:
       
   219         /**
       
   220         * C++ default constructor.
       
   221         */
       
   222         CMccCameraHandler( MMccResources& aResources,
       
   223                            TInt aCameraIndex, 
       
   224                            TInt aPriority );
       
   225         
       
   226         /**
       
   227         * By default Symbian 2nd phase constructor is private.
       
   228         */
       
   229         void ConstructL();
       
   230 
       
   231 
       
   232     private: // Data
       
   233     
       
   234     	enum TCameraHandlerState
       
   235     		{
       
   236     		EInit = 0,
       
   237     		EReserving,
       
   238     		EReserved,
       
   239     		EPowered,
       
   240     		EFailed
       
   241     		};
       
   242             
       
   243         MMccResources& iResources;
       
   244 	
       
   245 		TCameraHandlerState iState;
       
   246 
       
   247         // Priority settings
       
   248         TInt iPriority;
       
   249 
       
   250         // index of camera device
       
   251         TInt iCameraIndex;
       
   252 
       
   253         // Camera handle shared by all components
       
   254 		CCamera* iCamera;
       
   255 		
       
   256 		//Screen for local camera view
       
   257 		CMccScreen* iScreen;
       
   258 		
       
   259 		TMccVideoSinkSetting iViewFinderSettings;
       
   260 		
       
   261 		TBool iViewFinderEnabled;
       
   262 		
       
   263 		RPointerArray<MMccCameraHandlerObserver> iObservers;
       
   264 		
       
   265 		TInt iZoom;
       
   266 		TInt iDigitalZoom;
       
   267 		TInt iContrast;
       
   268 		TInt iBrightness;
       
   269 		TInt iWhiteBalance;
       
   270 		TInt iExposure;
       
   271 		
       
   272 		TMccTimerId iTimerId;
       
   273 		
       
   274 		TBool iForcedResourceReservation;
       
   275 		
       
   276 		#ifdef MCC_CAMERAHANDLER_TEST
       
   277 		RFbsSession iFbsSession;
       
   278 		RFs iFsSession;
       
   279 		#endif
       
   280 		        
       
   281     	#ifdef TEST_EUNIT
       
   282     	friend class UT_CMccCameraHandler;
       
   283     	friend class UT_CMccResourceItem;
       
   284     	friend class UT_CMccResourcePool;
       
   285     	#endif
       
   286     };
       
   287 
       
   288 #endif