qtmobility/plugins/multimedia/symbian/camera/s60camerasession.h
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef S60CAMERASESSION_H
       
    43 #define S60CAMERASESSION_H
       
    44 
       
    45 #include <QtCore/qobject.h>
       
    46 #include <QTime>
       
    47 #include <QUrl>
       
    48 #include <QtGui/qicon.h>
       
    49 #include <QList>
       
    50 #include <QtMultimedia/qvideoframe.h>
       
    51 #include <QMultiMap>
       
    52 
       
    53 #include "qcamera.h"
       
    54 #include "qstillimagecapture.h"
       
    55 #include "s60camerasettings.h"
       
    56 #include <e32base.h>
       
    57 #include <cameraengine.h>
       
    58 #include <cameraengineobserver.h>
       
    59 
       
    60 #include <VideoRecorder.h>
       
    61 
       
    62 QTM_USE_NAMESPACE
       
    63 
       
    64 class MVFProcessor
       
    65 
       
    66 {
       
    67 public:
       
    68       virtual void ViewFinderFrameReady(const QImage& image) = 0;
       
    69 };
       
    70 
       
    71 struct VideoControllerData
       
    72 {
       
    73     int controllerUid;
       
    74     int formatUid;
       
    75     QString formatDescription;
       
    76 };
       
    77 
       
    78 class S60CameraService;
       
    79 
       
    80 class S60CameraSession : public QObject,
       
    81     public MCameraEngineObserver,
       
    82     public MVideoRecorderUtilityObserver
       
    83 {
       
    84     Q_OBJECT
       
    85 public:
       
    86 
       
    87     enum Error {
       
    88         NoError = 0,
       
    89         OutOfMemoryError,
       
    90         InUseError,
       
    91         NotReadyError,
       
    92         UnknownError = -1
       
    93     };
       
    94     
       
    95     enum EcamErrors {
       
    96         KErrECamCameraDisabled = -12100, // The camera has been disabled, hence calls do not succeed 
       
    97         KErrECamSettingDisabled = -12101, //  This parameter or operation is supported, but presently is disabled. 
       
    98         KErrECamParameterNotInRange = -12102, //  This value is out of range. 
       
    99         KErrECamSettingNotSupported = -12103, //  This parameter or operation is not supported. 
       
   100         KErrECamNotOptimalFocus = -12104 // The optimum focus is lost  
       
   101     };
       
   102 
       
   103     S60CameraSession(QObject *parent = 0);
       
   104     ~S60CameraSession();
       
   105     
       
   106     CCamera::TFormat defaultCodec();
       
   107     void setError(TInt aError);
       
   108     QCamera::Error fromSymbianErrorToMultimediaError(int aError);
       
   109 
       
   110     bool deviceReady();
       
   111     
       
   112     S60CameraSettings* advancedSettings();
       
   113     
       
   114 
       
   115     qreal framerate();
       
   116     void setFrameRate(qreal rate);
       
   117 
       
   118     QList<QVideoFrame::PixelFormat> supportedPixelFormats();
       
   119     QVideoFrame::PixelFormat pixelFormat() const;
       
   120     void setPixelFormat(QVideoFrame::PixelFormat fmt);
       
   121     QList<QSize> supportedVideoResolutions();
       
   122     QList<qreal> supportedVideoFrameRates();
       
   123 
       
   124 
       
   125     // media control
       
   126     bool setOutputLocation(const QUrl &sink);
       
   127     QUrl outputLocation() const;
       
   128     qint64 position();
       
   129     int state() const;    
       
   130 
       
   131     //added based on s60 camera needs
       
   132     void releaseImageBuffer();
       
   133     void startCamera();
       
   134     void stopCamera();
       
   135     void capture(const QString &fileName);
       
   136 
       
   137 
       
   138     // for mediacontrol
       
   139     void startRecording();
       
   140     void pauseRecording();
       
   141     void stopRecording();
       
   142 
       
   143     //videodevicecontrol
       
   144     static int deviceCount();
       
   145     static QString name(const int index);
       
   146     static QString description(const int index);
       
   147     int defaultDevice() const;
       
   148     int selectedDevice() const;
       
   149     void setSelectedDevice(int index);
       
   150 
       
   151     //imageencodercontrol
       
   152     QSize captureSize() const;
       
   153     QSize minimumCaptureSize();
       
   154     QSize maximumCaptureSize();
       
   155     QList<QSize> supportedCaptureSizesForCodec(const QString &codecName);
       
   156     void setCaptureSize(const QSize &size);
       
   157     QStringList supportedImageCaptureCodecs();
       
   158     QString imageCaptureCodec();
       
   159     void setImageCaptureCodec(const QString &codecName);
       
   160     QString imageCaptureCodecDescription(const QString &codecName);
       
   161     QtMedia::EncodingQuality captureQuality() const;
       
   162     void setCaptureQuality(QtMedia::EncodingQuality);
       
   163 
       
   164     void setVideoRenderer(QObject *renderer);
       
   165     void updateImageCaptureCodecs();
       
   166 
       
   167     QStringList supportedVideoCaptureCodecs();
       
   168     QString videoCaptureCodec();
       
   169     void setVideoCaptureCodec(const QString &codecName);
       
   170     bool isSupportedVideoCaptureCodec(const QString &codecName);
       
   171     int bitrate();
       
   172     void setBitrate(const int &bitrate);
       
   173     QSize videoResolution();
       
   174     void setVideoResolution(const QSize &resolution);
       
   175     QString videoCaptureCodecDescription(const QString &codecName);    
       
   176     void saveVideoEncoderSettings(QVideoEncoderSettings &videoSettings);
       
   177     void getCurrentVideoEncoderSettings(QVideoEncoderSettings &videoSettings);    
       
   178     QtMedia::EncodingQuality videoCaptureQuality() const;    
       
   179     void setVideoCaptureQuality(QtMedia::EncodingQuality quality);
       
   180     
       
   181     //camerafocuscontrol
       
   182     void startFocus();
       
   183     void cancelFocus();
       
   184     int maximumZoom();
       
   185     int minZoom();
       
   186     int maxDigitalZoom();
       
   187     void setZoomFactor(qreal optical, qreal digital);
       
   188     int zoomFactor();
       
   189     int digitalZoomFactor();
       
   190 
       
   191     //cameraexposurecontrol
       
   192     void setFlashMode(QCamera::FlashMode mode);
       
   193     void setExposureMode(QCamera::ExposureMode mode);
       
   194     QCamera::ExposureMode exposureMode();
       
   195     QCamera::ExposureModes supportedExposureModes();
       
   196     QCamera::FlashModes supportedFlashModes();
       
   197     QCamera::FlashMode flashMode();
       
   198     
       
   199     //cameraimageprocessingcontrol
       
   200     qreal contrast() const;
       
   201     void setContrast(qreal value);
       
   202     QCamera::WhiteBalanceMode whiteBalanceMode();
       
   203     void setWhiteBalanceMode(QCamera::WhiteBalanceMode mode);
       
   204     QCamera::WhiteBalanceModes supportedWhiteBalanceModes();
       
   205 
       
   206 protected: // From MCameraEngineObserver
       
   207     void MceoCameraReady();
       
   208     void MceoFocusComplete();
       
   209     void MceoCapturedDataReady(TDesC8* aData);
       
   210     void MceoCapturedBitmapReady(CFbsBitmap* aBitmap);
       
   211     void MceoViewFinderFrameReady(CFbsBitmap& aFrame);
       
   212     void MceoHandleError(TCameraEngineError aErrorType, TInt aError);
       
   213 
       
   214 private:
       
   215     bool queryCurrentCameraInfo();
       
   216     QMap<QString, int> formatMap();
       
   217     QMap<QString, int> formatDescMap();
       
   218     
       
   219     void setWhiteBalanceModeL(QCamera::WhiteBalanceMode mode);
       
   220     void commitVideoEncoderSettings();
       
   221     void setVideoFrameRateFixed(bool fixed);
       
   222     void resetCamera();
       
   223 
       
   224     //from  MVideoRecorderUtilityObserver
       
   225     void MvruoOpenComplete(TInt aError);
       
   226     void MvruoPrepareComplete(TInt aError);
       
   227     void MvruoRecordComplete(TInt aError);
       
   228     void MvruoEvent(const TMMFEvent& aEvent);
       
   229 
       
   230     void updateVideoCaptureCodecs();
       
   231     void updateVideoCaptureCodecsL();
       
   232     void initializeVideoCaptureSettings();
       
   233 
       
   234 Q_SIGNALS:
       
   235     void stateChanged(QCamera::State);
       
   236     // for capture control
       
   237     void error(int error, const QString &errorString);
       
   238     void readyForCaptureChanged(bool);
       
   239     void imageCaptured(const QString &fileName, const QImage &preview);
       
   240     void imageSaved(const QString &fileName);
       
   241     //for focuscontrol
       
   242     void focusStatusChanged(QCamera::FocusStatus);
       
   243     void opticalZoomChanged(qreal opticalZoom);
       
   244     void digitalZoomChanged(qreal digitalZoom);
       
   245         
       
   246         
       
   247 
       
   248 private:
       
   249     CCameraEngine *m_cameraEngine;
       
   250     S60CameraSettings *m_advancedSettings;
       
   251     MVFProcessor *m_VFProcessor;
       
   252     int m_imageQuality;
       
   253     int m_videoQuality;
       
   254     QSize m_captureSize;
       
   255     QCamera::State m_state;
       
   256     QVideoFrame::PixelFormat m_pixelF;
       
   257     TInt m_deviceIndex; //index indication chosen camera device
       
   258     mutable int m_error;
       
   259     CCamera::TFormat m_currentcodec;
       
   260     QTime m_timeStamp;
       
   261     QUrl m_sink;
       
   262     QList<QSize> m_resolutions;
       
   263     QList<uint> m_formats;
       
   264     QSize m_VFWidgetSize;
       
   265     TSize m_VFSize;
       
   266     QString m_stillCaptureFileName;
       
   267 
       
   268     mutable TCameraInfo m_info; // information about camera
       
   269 
       
   270     CVideoRecorderUtility* m_videoUtility;
       
   271     QHash<QString, VideoControllerData> m_videoControllerMap;
       
   272     QString m_videoCodec;
       
   273     QVideoEncoderSettings m_videoSettings;
       
   274     
       
   275     enum TVideoCaptureState
       
   276     {
       
   277         ENotInitialized = 0,
       
   278         EInitialized,
       
   279         EOpenCompelete,
       
   280         ERecording,
       
   281         EPaused,
       
   282         ERecordComplete
       
   283     };
       
   284     
       
   285     TVideoCaptureState m_captureState;
       
   286 
       
   287 };
       
   288 
       
   289 #endif