khronosfws/openmax_al/src/mmf_adaptation/cmmfbackendengine.h
branchRCL_3
changeset 45 095bea5f582e
equal deleted inserted replaced
41:a36789189b53 45:095bea5f582e
       
     1 /*
       
     2  * Copyright (c) 2009 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: MMF Backend Engine Header
       
    15  *
       
    16  */
       
    17 
       
    18 #ifndef CMMFBackendEngine_H
       
    19 #define CMMFBackendEngine_H
       
    20 
       
    21 #define ENABLE_GRAPHICS_SURFACE_INTEGRATION
       
    22 
       
    23 #include "openmaxalwrapper.h"
       
    24 
       
    25 #ifdef __cplusplus
       
    26 
       
    27 #include <e32base.h>
       
    28 #include <mdaaudiosampleplayer.h>  
       
    29 #include <f32file.h>
       
    30 #include <videoplayer.h>
       
    31 #include <videoplayer2.h>
       
    32 #include <e32std.h>
       
    33 #include <mmf/common/mmferrors.h>
       
    34 #include <mmf/common/mmfbase.h>
       
    35 #include <MMFMetadataEventConfigConstants.h>
       
    36 #include <mmf/common/mmfstandardcustomcommands.h>
       
    37 #ifdef ENABLE_GRAPHICS_SURFACE_INTEGRATION
       
    38 #include <graphics/surface.h> //TSurfaceId
       
    39 #include <mmf/common/mmfvideo.h> //TVideoAspectRatio
       
    40 #include <mediaclientvideodisplay.h>
       
    41 #include <surfaceeventhandler.h>
       
    42 #include <mdaaudiosampleeditor.h>
       
    43 #include <AudioInput.h>
       
    44 #include "sfmrlocaltimer.h"
       
    45 #endif
       
    46 
       
    47 // MetaDataWrite Custom Command UID
       
    48 const TUid KUidMetaDataWriteCustomCommand =
       
    49     {
       
    50     0x10207af9
       
    51     };
       
    52 
       
    53 #define MAX_EXTENSION_SIZE 10
       
    54 
       
    55 class CMarkerPositionTimer;
       
    56 class CPositionUpdateTimer;
       
    57 NONSHARABLE_CLASS(CMMFBackendEngine) : public CBase,
       
    58         public MVideoPlayerUtilityObserver,
       
    59         public MVideoLoadingObserver,
       
    60         public MMdaAudioPlayerCallback,
       
    61         public MMdaObjectStateChangeObserver
       
    62     {
       
    63 public:
       
    64     enum TFuncInUse
       
    65         {
       
    66                 EPlay = 0, 
       
    67                 ERecord
       
    68         };
       
    69 
       
    70     enum TUriType
       
    71         {
       
    72                 ELocal = 0, 
       
    73                 EStreaming
       
    74         };
       
    75 
       
    76     enum TMMFUtiltyInUse
       
    77         {
       
    78         ENoUtility,
       
    79         EVideoPlayerUtility,
       
    80         EAudioPlayerUtility,
       
    81         EAudioRecorderUtility
       
    82         };
       
    83 
       
    84     enum TRecorderState
       
    85         {
       
    86                 ERecorderNotReady = 0, 
       
    87                 ERecorderOpen, 
       
    88                 ERecorderRecording
       
    89         };
       
    90 
       
    91 public:
       
    92 
       
    93     static CMMFBackendEngine* NewL();
       
    94     ~CMMFBackendEngine();
       
    95 
       
    96     TInt SetFileName(char* uri, XAuint32 format, TFuncInUse func);
       
    97     void Close();
       
    98     void Destroy();
       
    99     TInt SetRecorderState(TRecorderState state, XAboolean stopCalled);
       
   100     TInt GetRecordPosition(XAuint64* position);
       
   101     TInt SetPositionUpdatePerioed(XAmillisecond period);
       
   102     TInt SetAdaptContext(void* adaptcontext);
       
   103     TInt GetCodecId(XAuint32* encoderId);
       
   104     TInt GetBitRate(XAuint32* bitrate);
       
   105     TInt GetSampleRate(XAmilliHertz* samplerate);
       
   106     TInt GetChannels(XAuint32* channels);
       
   107     TInt SetDestinationBitRate(XAuint32* bitrate);
       
   108     TInt SetDestinationSampleRate(XAmilliHertz* samplerate);
       
   109     TInt SetDestinationChannels(XAuint32* channels);
       
   110 
       
   111     XAresult CreateAndConfigureWindowL();
       
   112     XAresult SetNativeDisplayInformation(void* display_info);
       
   113     XAresult ResumePlayback();
       
   114     XAresult PausePlayback();
       
   115     XAresult StopPlayback();
       
   116     XAresult GetPlayState(XAuint32 *pState);
       
   117     XAresult GetDuration(XAmillisecond *pMsec);
       
   118     XAresult GetPosition(XAmillisecond *pMsec);
       
   119     XAresult SetPlayAdaptContext(void * adaptcontext);
       
   120     XAresult RegisterCallback(xaPlayCallback cbFunction);
       
   121     XAresult SetCallbackEventsMask(XAuint32 eventflags);
       
   122     XAresult SetMarkerPosition(XAmillisecond mSec);
       
   123     XAresult ClearMarkerPosition();
       
   124     XAresult SetPositionUpdatePeriod(XAmillisecond mSec);
       
   125 
       
   126     XAresult SetPosition(XAmillisecond pMsec);
       
   127     XAresult SetRepeats(XAboolean repeat);
       
   128     XAresult SetPlayWindow(XAmillisecond start, XAmillisecond end);
       
   129 
       
   130     XAresult GetNumStreams(XAuint32* numstreams);
       
   131     XAresult GetStreamInfo(XAuint32 streamindex, XAuint32* streamtype);
       
   132     XAresult GetVideoFrameSize(XAuint32* height, XAuint32* width,
       
   133             XAuint32* frameRate);
       
   134     XAresult SetActiveState(XAuint32 streamindex, XAboolean active);
       
   135 
       
   136     XAresult SetVolume(XAuint32 volume);
       
   137     XAresult GetVolume(XAuint32* volume);
       
   138     XAresult GetMaxVolume(XAuint32* maxvolume);
       
   139 
       
   140     XAresult SetPlaybackRate(XAint16 rate);
       
   141     XAresult GetPlaybackRateCapabilities(XAboolean* forward, XAboolean* backward);
       
   142 
       
   143 public:
       
   144 
       
   145     // MMdaObjectStateChangeObserver
       
   146     void MoscoStateChangeEvent(CBase* aObject, TInt aPreviousState,
       
   147             TInt aCurrentState, TInt aErrorcCode);
       
   148 
       
   149     //MMdaAudioPlayerCallback
       
   150     void MapcInitComplete(TInt aError,
       
   151             const TTimeIntervalMicroSeconds& aDuration);
       
   152     void MapcPlayComplete(TInt aError);
       
   153 
       
   154     //From MVidePlayerUtilityObserver
       
   155     void MvpuoOpenComplete(TInt aError);
       
   156     void MvpuoPrepareComplete(TInt aError);
       
   157     void MvpuoFrameReady(CFbsBitmap& aFrame, TInt aError);
       
   158     void MvpuoPlayComplete(TInt aError);
       
   159     void MvpuoEvent(const TMMFEvent& aEvent);
       
   160 
       
   161     // From MRebufferCallback
       
   162     void MvloLoadingStarted();
       
   163     void MvloLoadingComplete();
       
   164 
       
   165 private:
       
   166     enum TPlayerState
       
   167         {
       
   168         EPlayerClosed,
       
   169         EPlayerOpened,
       
   170         EPlayerPrepared,
       
   171         EPlayerPaused,
       
   172         EPlayerPlaying,
       
   173         };
       
   174 
       
   175 private:
       
   176     CMMFBackendEngine();
       
   177     void ConstructL();
       
   178     void InitAudioRecorderUtilityL();
       
   179     void InitAudioPlayerUtilityL();
       
   180     void InitVideoPlayerUtilityL();
       
   181     void InitPlayerTimersL();
       
   182     TInt DetermineAPIToUse(char *uri, TFuncInUse aFunc);
       
   183     XAresult DoHandlePlayItfAttributesChanged();
       
   184     void DoPostEvent(XAuint32 event);
       
   185     TInt InitializeURIForMMFUtil(char *uri);
       
   186 
       
   187 private:
       
   188     CVideoPlayerUtility2* iVideoPlayer;
       
   189     CBase* iBaseVideoPlayer;
       
   190     CMdaAudioPlayerUtility* iAudioPlayer;
       
   191     CBase* iBaseAudioPlayer;
       
   192     CMdaAudioRecorderUtility* iAudioRecorder;
       
   193     CBase* iBaseAudioRecorder;
       
   194     TFileName iFileName;
       
   195     TInt iAPIBeingUsed;
       
   196     TInt iPreviousRecordState;
       
   197     TInt iCurrentRecordState;
       
   198     TInt iErrorCode;
       
   199     TRecorderState iRecordState;
       
   200     LocalTimer* iPositionUpdateTimer;
       
   201     TUint64 iTimerDelay;
       
   202     void* iAdaptContext;
       
   203     XAuint32 iFileFormat;
       
   204     TInt iPauseSupportMP4;
       
   205     CActiveSchedulerWait* iActiveSchedulerWait;
       
   206     CAudioInput* iAudioInputRecord;
       
   207 #ifdef USE_LOCAL_WINDOW_RESOURCES
       
   208     CMediaClientVideoDisplay* iMediaClientVideoDisplay;
       
   209     TRect m_clipRect;
       
   210     TRect m_videoExtent;
       
   211     TRect m_cropRegion;
       
   212     TVideoAspectRatio m_pixelAspectRatio;
       
   213     RWindow m_Window;
       
   214     TRect m_cropRect;
       
   215     TSurfaceId m_surfaceId;
       
   216     TVideoRotation m_rotation;
       
   217     TReal32 m_scaleWidth;
       
   218     TReal32 m_scaleHeight;
       
   219     TInt m_horizPos;
       
   220     TInt m_vertPos;
       
   221     TInt m_displayId;
       
   222     /*TBool m_bWindowReferencePassed;*/
       
   223     RWsSession m_ws;
       
   224 #endif /* USE_LOCAL_WINDOW_RESOURCES */
       
   225 
       
   226     /* Holds duration of the media clip opend for playback */
       
   227     TTimeIntervalMicroSeconds iMediaDuration;
       
   228     /* Holds the playback position to be used for next play command */
       
   229     TTimeIntervalMicroSeconds iPlaybackHead;
       
   230     /* Holds current XA state of media player object */
       
   231     XAuint32 iMediaPlayerState;
       
   232     /* Owns */
       
   233     CMarkerPositionTimer* iMarkerPositionTimer;
       
   234     CPositionUpdateTimer* iPlayItfPositionUpdateTimer;
       
   235     /* Owns */
       
   236     CWsScreenDevice* m_pScr;
       
   237     /* Holds mmf state of media player object */
       
   238     TPlayerState iMMFPlayerState;
       
   239 
       
   240     /* Property set by client */
       
   241     XAuint32 iPlayItfEventFlags;
       
   242     /* Property set by client */
       
   243     xaPlayCallback iPlayItfCBFunction;
       
   244     /* Property set by client */
       
   245     XAmillisecond iMarkerPosition;
       
   246     /* Property set by client */
       
   247     XAmillisecond iPositionUpdatePeriod;
       
   248     /* Property set by client (for file without file:///) */
       
   249     HBufC* iUri; /* owns */
       
   250     TPtr iUriPtr;
       
   251     TUriType iUriType;
       
   252     /* Property set by client */
       
   253     RWsSession* m_pWs;
       
   254     /* Property set by client */
       
   255     RWindow* m_pWindow;
       
   256     };
       
   257 
       
   258 #else  /* __cplusplus */
       
   259 
       
   260 extern int mmf_backend_engine_init(void** engine);
       
   261 extern int mmf_backend_engine_deinit(void* engine);
       
   262 
       
   263 extern int mmf_set_recorder_uri(void* context, char* uri, XAuint32 format);
       
   264 
       
   265 extern void mmf_close(void* context);
       
   266 
       
   267 extern int mmf_set_adapt_context(void* context, void* adaptcontext);
       
   268 
       
   269 extern int mmf_start_recording(void* context);
       
   270 
       
   271 extern int mmf_stop_recording(void* context, XAboolean stopCalled);
       
   272 
       
   273 extern int mmf_get_record_position(void* context, XAuint64* position);
       
   274 
       
   275 extern int mmf_set_record_position_update_period(void* context, XAmillisecond msec);
       
   276 
       
   277 extern int mmf_get_codec_id(void* context, XAuint32* encoderId);
       
   278 extern int mmf_get_channels(void* context, XAuint32* channelsIn);
       
   279 extern int mmf_get_samplerate(void* context, XAmilliHertz* sampleRate);
       
   280 extern int mmf_get_bitrate(void* context, XAuint32* bitRate);
       
   281 extern int mmf_set_destination_channels(void* context, XAuint32* channelsIn);
       
   282 extern int mmf_set_destination_samplerate(void* context, XAmilliHertz* sampleRate);
       
   283 extern int mmf_set_destination_bitrate(void* context, XAuint32* bitRate);
       
   284 
       
   285 extern XAresult mmf_set_play_adapt_context(void * context, void * adaptcontext);
       
   286 extern XAresult mmf_set_player_uri(void * context, char * uri, XAuint32 format);
       
   287 /*extern XAresult mmf_set_window_handle(void * context, void * display_infos);*/
       
   288 extern XAresult mmf_setup_native_display(void * context, void * display_info);
       
   289 
       
   290 /*Functions for XAPlayItf*/
       
   291 extern XAresult mmf_playitf_resume_playback(void * context);
       
   292 extern XAresult mmf_playitf_pause_playback(void * context);
       
   293 extern XAresult mmf_playitf_stop_playback(void * context);
       
   294 extern XAresult mmf_playitf_get_play_state(void * context, XAuint32 * pState);
       
   295 extern XAresult mmf_playitf_get_duration(void * context, XAmillisecond * pMsec);
       
   296 extern XAresult mmf_playitf_get_position(void * context, XAmillisecond * pMsec);
       
   297 extern XAresult mmf_playitf_register_callback(void * context, xaPlayCallback callback);
       
   298 extern XAresult mmf_playitf_set_callback_events_mask(void * context, XAuint32 eventflags);
       
   299 extern XAresult mmf_playitf_set_marker_position(void * context, XAmillisecond mSec);
       
   300 extern XAresult mmf_playitf_clear_marker_position(void * context);
       
   301 extern XAresult mmf_playitf_set_position_update_period(void * context, XAmillisecond mSec);
       
   302 
       
   303 extern XAresult mmf_seekitf_set_position(void * context, XAmillisecond mSec);
       
   304 extern XAresult mmf_seekitf_set_playwindow(void * context, XAmillisecond start, XAmillisecond end);
       
   305 extern XAresult mmf_seekitf_set_repeats(void * context, XAboolean repeat);
       
   306 
       
   307 extern XAresult mmf_streaminformationitf_get_numstreams(void * context, XAuint32* numstreams);
       
   308 extern XAresult mmf_streaminformationitf_get_streaminfo(void * context, XAuint32 streamindex,
       
   309         XAuint32* streamtype);
       
   310 extern XAresult mmf_streaminformationitf_get_videoframesize(void * context, XAuint32* height,
       
   311         XAuint32* width, XAuint32* frameRate);
       
   312 extern XAresult mmf_streaminformationitf_set_activestream(void * context, XAuint32 streamindex,
       
   313         XAboolean active);
       
   314 
       
   315 extern XAresult mmf_volumeitf_set_volume(void * context, XAuint32 volume);
       
   316 extern XAresult mmf_volumeitf_get_volume(void * context, XAuint32* volume);
       
   317 extern XAresult mmf_volumeitf_get_maxvolume(void * context, XAuint32* volume);
       
   318 extern XAresult mmf_playbackrateitf_set_playbackrate(void * context, XAint16 rate);
       
   319 extern XAresult mmf_playbackrateitf_get_playbackratecaps(void * context,
       
   320                                 XAboolean* forward, XAboolean* backward);
       
   321 
       
   322 #endif /* __cplusplus */
       
   323 
       
   324 #endif /* CMMFBackendEngine_H */