src/ext/amaretto/camera/inc/cameramodule.h
changeset 0 ca70ae20a155
equal deleted inserted replaced
-1:000000000000 0:ca70ae20a155
       
     1 /** 
       
     2  * ====================================================================
       
     3  * cameramodule.cpp
       
     4  *
       
     5  * Modified from "miso" (HIIT) and video example available Forum Nokia. 
       
     6  *
       
     7  * Copyright 2005 Helsinki Institute for Information Technology (HIIT)
       
     8  * and the authors.  All rights reserved.
       
     9  * Authors: Tero Hasu <tero.hasu@hut.fi>
       
    10  *
       
    11  * Portions Copyright (c) 2005-2007 Nokia Corporation 
       
    12  * 
       
    13  * Permission is hereby granted, free of charge, to any person
       
    14  * obtaining a copy of this software and associated documentation files
       
    15  * (the "Software"), to deal in the Software without restriction,
       
    16  * including without limitation the rights to use, copy, modify, merge,
       
    17  * publish, distribute, sublicense, and/or sell copies of the Software,
       
    18  * and to permit persons to whom the Software is furnished to do so,
       
    19  * subject to the following conditions:
       
    20  *
       
    21  * The above copyright notice and this permission notice shall be
       
    22  * included in all copies or substantial portions of the Software.
       
    23  * 
       
    24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
       
    25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
       
    26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
       
    27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
       
    28  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
       
    29  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
       
    30  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
       
    31  * SOFTWARE.
       
    32  *
       
    33  * ====================================================================
       
    34  */
       
    35  
       
    36 #include <ecam.h>
       
    37 #include <fbs.h>
       
    38 #include <e32std.h>
       
    39 #include <w32std.h>
       
    40 #include <bitdev.h>
       
    41 #include <VideoRecorder.h>
       
    42 
       
    43 #include "Python.h"
       
    44 #include "symbian_python_ext_util.h"
       
    45 
       
    46 //////////////CLASS DEFINITIONS CAMERA
       
    47 
       
    48 class TPyCamCallBack
       
    49   {
       
    50   public:
       
    51     TInt NewViewFinderFrameReady(CFbsBitmap* aFrame);
       
    52   public:
       
    53     PyObject* iCb; // Not owned.
       
    54   };
       
    55 
       
    56 #ifndef EKA2
       
    57 class CMisoPhotoTaker : public CBase, public MCameraObserver
       
    58 #else
       
    59 NONSHARABLE_CLASS (CMisoPhotoTaker) : public CBase, 
       
    60                                       public MCameraObserver
       
    61 #endif
       
    62 {
       
    63 public:
       
    64   static CMisoPhotoTaker* NewL(TInt aPosition);
       
    65   void ConstructL();
       
    66   ~CMisoPhotoTaker();
       
    67 private:
       
    68   CMisoPhotoTaker();
       
    69 public:
       
    70   void TakePhotoL(TInt aMode, TInt aSize, 
       
    71                          TInt aZoom, TInt aFlash, 
       
    72                          TInt aExp, TInt aWhite); // synchronous
       
    73   void StartViewFinder(TInt aXSize, TInt aYSize);
       
    74   void StopViewFinder();
       
    75   void SetCallBack(TPyCamCallBack &aCb);
       
    76   void UnSetCallBack();  
       
    77   
       
    78   void Release() const;
       
    79   
       
    80   // accessors:
       
    81   TBool TakingPhoto() const;
       
    82   TBool ViewFinderOn() const;
       
    83   TInt GetImageModes() const;
       
    84   TInt GetImageSizeMax() const;
       
    85   void GetImageSize(TSize& aSize, 
       
    86                     TInt aSizeIndex, 
       
    87                     CCamera::TFormat aFormat) const;
       
    88   TInt GetMaxZoom() const;
       
    89   TInt GetFlashModes() const;
       
    90   TInt GetExpModes() const;
       
    91   TInt GetWhiteModes() const;
       
    92   TInt GetHandle() const;
       
    93   
       
    94   CFbsBitmap* GetBitmap() const;
       
    95   HBufC8* GetJpg() const;
       
    96   
       
    97   enum TFinderState
       
    98     {
       
    99     EFinderInactive = 0,
       
   100     EFinderInitializing,
       
   101     EFinderFailed,
       
   102     EFinderActive
       
   103     };
       
   104 private:
       
   105   CActiveSchedulerWait* iLoop;
       
   106 private:
       
   107   void MakeTakePhotoRequest();
       
   108   void CapturePhoto();
       
   109   //CCamera::TFormat ImageFormatMax() const;
       
   110   void SetSettingsL();
       
   111 private:
       
   112   CCamera* iCamera;
       
   113   
       
   114   // The first one is for the bitmap pictures and the second
       
   115   // one for the JPEG and other formats
       
   116   CFbsBitmap* iBitMap;
       
   117   HBufC8* iData;
       
   118   
       
   119   TInt iStatus;
       
   120   TBool iTakingPhoto;
       
   121   TFinderState iViewFinderStatus;
       
   122   TCameraInfo iInfo;
       
   123   CCamera::TFormat iMode;
       
   124   TInt iSize;
       
   125   TInt iZoom;
       
   126   CCamera::TFlash iFlash;
       
   127   CCamera::TExposure iExp;
       
   128   CCamera::TWhiteBalance iWhite;
       
   129   TInt iPosition;
       
   130   TSize iViewFinderSize;
       
   131      
       
   132 private:
       
   133   TPyCamCallBack iCallMe;
       
   134   TInt iErrorState;
       
   135   TBool iCallBackSet;
       
   136 private: // MCameraObserver
       
   137   void ReserveComplete(TInt aError);
       
   138   void PowerOnComplete(TInt aError);
       
   139   void ViewFinderFrameReady(CFbsBitmap& aFrame);
       
   140   void ImageReady(CFbsBitmap* aBitmap, HBufC8* aData, TInt aError);
       
   141   void FrameBufferReady(MFrameBuffer* aFrameBuffer, TInt aError);
       
   142 };
       
   143 
       
   144 //////////////CLASS DEFINITIONS VIDEO CAMERA
       
   145 
       
   146 class TPyVidCallBack
       
   147   {
       
   148   public:
       
   149     TInt VideoCameraEvent(TInt aError, TInt aStatus);
       
   150   public:
       
   151     PyObject* iCb; // Not owned.
       
   152   };
       
   153 
       
   154 #ifndef EKA2
       
   155 class CVideoCamera : public CBase, public MVideoRecorderUtilityObserver
       
   156 #else
       
   157 NONSHARABLE_CLASS (CVideoCamera) : public CBase, 
       
   158                                    public MVideoRecorderUtilityObserver
       
   159 #endif
       
   160 {
       
   161 public:
       
   162   static CVideoCamera* NewL();
       
   163   void ConstructL();
       
   164   ~CVideoCamera();
       
   165 private:
       
   166   CVideoCamera();
       
   167 public:
       
   168   void StartRecordL(TInt aHandle, const TDesC& aFileName);
       
   169   void StopRecord();
       
   170   void SetCallBack(TPyVidCallBack &aCb);
       
   171   void UnSetCallBack();
       
   172   enum TObserverEvents
       
   173     {
       
   174     EOpenComplete = 0xFA0,
       
   175     EPrepareComplete,
       
   176     ERecordComplete
       
   177     };
       
   178 private:
       
   179   CVideoRecorderUtility* iVideo;
       
   180   TUid iControllerUid;
       
   181   TUid iFormatUid;
       
   182   TPyVidCallBack iCallMe;
       
   183   TInt iErrorState;
       
   184   TBool iCallBackSet;
       
   185 private: // from MVideoRecorderUtilityObserver
       
   186   void MvruoEvent(const TMMFEvent &aEvent);
       
   187   void MvruoOpenComplete(TInt aError);
       
   188   void MvruoPrepareComplete(TInt aError);
       
   189   void MvruoRecordComplete(TInt aError);
       
   190 };
       
   191 
       
   192 //////////////TYPE DEFINITIONS
       
   193 
       
   194 #define CAM_type ((PyTypeObject*)SPyGetGlobalString("CAMType"))
       
   195 
       
   196 struct CAM_object {
       
   197   PyObject_VAR_HEAD
       
   198   CMisoPhotoTaker* camera;
       
   199   TBool cameraUsed;
       
   200   TPyCamCallBack myCallBack;
       
   201   TBool callBackSet;
       
   202 };
       
   203 
       
   204 #define VID_type ((PyTypeObject*)SPyGetGlobalString("VIDType"))
       
   205 
       
   206 struct VID_object {
       
   207   PyObject_VAR_HEAD
       
   208   CVideoCamera* video;
       
   209   TPyVidCallBack myCallBack;
       
   210   TBool callBackSet;
       
   211 };