javauis/mmapi_qt/baseline/inc/cmmaplayer.h
changeset 23 98ccebc37403
child 47 f40128debb5d
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  This class is base class for all players.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CMMAPLAYER_H
       
    20 #define CMMAPLAYER_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include "cmmacontrol.h"
       
    24 #include "cmmasourcestream.h"
       
    25 #include "cmmaplayerevent.h"
       
    26 #include "mmmasourcestreamlistener.h"
       
    27 #include "mmmaplayerstatelistener.h"
       
    28 
       
    29 //  FORWARD DECLARATIONS
       
    30 class CMMADurationUpdater;
       
    31 
       
    32 //  CONTANTS
       
    33 
       
    34 // Not enough stream to realize to player
       
    35 const TInt KErrNotEnoughStreams = -7002;
       
    36 
       
    37 /**
       
    38  * Used in set loop count to indicate forever loop.
       
    39  */
       
    40 const TInt KJavaRepeatForever = -1;
       
    41 
       
    42 /**
       
    43  * Returned to Java if duration or mediatime is unknown.
       
    44  */
       
    45 const TInt KTimeUnknown = -1;
       
    46 
       
    47 //  CLASS DECLARATION
       
    48 /**
       
    49 *   This class is base class for all players.
       
    50 *
       
    51 *
       
    52 */
       
    53 
       
    54 class CMMAPlayer : public CBase,
       
    55         public MMMASourceStreamListener
       
    56 
       
    57 {
       
    58 public:
       
    59     /**
       
    60      * Player state. Same that in Java side.
       
    61      */
       
    62     enum TPlayerState
       
    63     {
       
    64         EClosed = 0,
       
    65         EUnrealized = 100,
       
    66         ERealized = 200,
       
    67         EPrefetched = 300,
       
    68         EStarted = 400
       
    69     };
       
    70 
       
    71 public:
       
    72     /**
       
    73      * Deletes all owned members.
       
    74      */
       
    75     virtual ~CMMAPlayer();
       
    76 protected:
       
    77     /**
       
    78      * Initializes member variables to defaults.
       
    79      */
       
    80     CMMAPlayer();
       
    81 
       
    82     /**
       
    83      * Second phase construct.
       
    84      */
       
    85     void ConstructL();
       
    86 
       
    87 public: // static methods
       
    88     /**
       
    89      * Creates and adds source stream to the player. New stream will be
       
    90      * owned by this player.
       
    91      *
       
    92      * @param aJniEnv Used to create source stream.
       
    93      * @param aPlayer Player to use.
       
    94      * @param aEventSource Used to create source stream.
       
    95      * @param aReader Java side stream object.
       
    96      * @param aSourceStream New stream's pointer will be set to this.
       
    97      */
       
    98     static void StaticAddSourceStreamL(JNIEnv* aJniEnv,
       
    99                                        CMMAPlayer* aPlayer,
       
   100                                        MMAFunctionServer* aEventSource,
       
   101                                        jobject aReader,
       
   102                                        CMMASourceStream** aSourceStream);
       
   103 
       
   104     /**
       
   105      * Sets Java listener object that will be used to post player events
       
   106      * and control specific events.
       
   107      *
       
   108      * @param aPlayer Player to use.
       
   109      * @param aListenerObject Java side listener object.
       
   110      * @param aJni Used to get method ids.
       
   111      * @param aPoster Used to post events.
       
   112      */
       
   113     static void StaticSetPlayerListenerObjectL(CMMAPlayer* aPlayer,
       
   114     				MMAFunctionServer* aEventsource,
       
   115             jobject aListenerObject,
       
   116             JNIEnv* aJni,
       
   117             MMMAEventPoster* aPoster);
       
   118 
       
   119     /**
       
   120      * Initializes action completed callbacks.
       
   121      *
       
   122      * @param aPlayer Player to use.
       
   123      * @param aPlayerObject Java side Player object.
       
   124      * @param aJni Used to get method id.
       
   125      */
       
   126     static void StaticInitPlayerL(CMMAPlayer* aPlayer,
       
   127     															MMAFunctionServer* aEventsource,
       
   128                                   jobject aPlayerObject,
       
   129                                   JNIEnv* aJni);
       
   130 
       
   131     /**
       
   132      * Static getter for control objects.
       
   133      *
       
   134      * @param aPlayer Player to use.
       
   135      * @param aIndex Control's index.
       
   136      */
       
   137     IMPORT_C static CMMAControl* StaticControl(CMMAPlayer* aPlayer,
       
   138             TInt aIndex);
       
   139 
       
   140 public: // New methods
       
   141 
       
   142     /**
       
   143      * Realizes the player. Implementations do not necessarily add
       
   144      * functionality in this method. If successful player is in
       
   145      * ERealized state.
       
   146      */
       
   147     virtual void RealizeL();
       
   148 
       
   149     /**
       
   150      * Prefetches data. Usually data from source stream will be read. When
       
   151      * prefetch completes action completed event will be delivered. If
       
   152      * successful player is in EPrefetched state.
       
   153      */
       
   154     virtual void PrefetchL() = 0;
       
   155 
       
   156     /**
       
   157      * Start playing. Started event will be posted. If there is no error
       
   158      * player will be in EStarted state.
       
   159      */
       
   160     virtual void StartL() = 0;
       
   161 
       
   162     /**
       
   163      * Stops playing. After this player may be restarted with StartL method.
       
   164      * After this player is in EPrefetched state.
       
   165      *
       
   166      * @param aPostEvent Indicates if java be informed.
       
   167      */
       
   168     virtual void StopL(TBool aPostEvent) = 0;
       
   169 
       
   170     /**
       
   171      * Releases resources. Player state can be changed.
       
   172      */
       
   173     virtual void DeallocateL() = 0;
       
   174 
       
   175     /**
       
   176      * Close the Player and release its resources. After this player is in
       
   177      * EClosed state and cannot be used anymore.
       
   178      */
       
   179     virtual void CloseL();
       
   180 
       
   181     /**
       
   182      * Gets duration.
       
   183      *
       
   184      * @param aDuration Duration or KTimeUnknown if not specified.
       
   185      */
       
   186     virtual void GetDuration(TInt64* aDuration);
       
   187 
       
   188     /**
       
   189      * Sets media time.
       
   190      *
       
   191      * @param aTime Time to set. When method returns parameter contains
       
   192      *              actual media time set.
       
   193      */
       
   194     virtual void SetMediaTimeL(TInt64* aTime);
       
   195 
       
   196     /**
       
   197      * Gets media time.
       
   198      *
       
   199      * @param aMediaTime When method returns parameter contains the media
       
   200      * time.
       
   201      */
       
   202     virtual void GetMediaTime(TInt64* aMediaTime);
       
   203 
       
   204     /**
       
   205      * Sets loop count.
       
   206      *
       
   207      * @param aCount Indicates the number of times the content will be
       
   208      *               played. KJavaRepeatForever indicates looping
       
   209      *               indefintely.
       
   210      */
       
   211     IMPORT_C virtual void SetLoopCount(TInt aCount);
       
   212 
       
   213     /**
       
   214      * Get the content type of the media that's being played back by this
       
   215      * Player.
       
   216      * @return The content type being played back by this Player. NULL if
       
   217      * content type is not available.
       
   218      */
       
   219     HBufC* ContentType() const;
       
   220 
       
   221 public: // new methods
       
   222     /**
       
   223      * Sets Java listener object that will be used to post player events
       
   224      * and control specific events.
       
   225      *
       
   226      * @param aListenerObject Java side listener object.
       
   227      * @param aJni Used to get method ids.
       
   228      * @param aPoster Used to post events.
       
   229      */
       
   230     virtual void SetPlayerListenerObjectL(jobject aListenerObject,
       
   231                                           JNIEnv* aJni,
       
   232                                           MMMAEventPoster* aPoster);
       
   233 
       
   234     /**
       
   235      * Returns total count of the controls owned by this player.
       
   236      *
       
   237      * @return Count of the controls.
       
   238      */
       
   239     IMPORT_C TInt ControlCount();
       
   240 
       
   241     /**
       
   242      * Gets control. Ownership is not tranferred.
       
   243      *
       
   244      * @param aIndex Control index.
       
   245      */
       
   246     IMPORT_C CMMAControl* Control(TInt aIndex);
       
   247 
       
   248     /**
       
   249      * Adds new control. Ownership is transferred to this class.
       
   250      *
       
   251      * @param aControl New control.
       
   252      */
       
   253     IMPORT_C virtual void AddControlL(CMMAControl* aControl);
       
   254 
       
   255     /**
       
   256      * Adds listener. All listeners will informed when player state changes.
       
   257      *
       
   258      * @param aListener New listener.
       
   259      */
       
   260     IMPORT_C void AddStateListenerL(MMMAPlayerStateListener* aListener);
       
   261 
       
   262     /**
       
   263      * Removes a player state listener.
       
   264      *
       
   265      * @param aListener Listener to be removed.
       
   266      */
       
   267     IMPORT_C void RemoveStateListener(MMMAPlayerStateListener* aListener);
       
   268 
       
   269     /**
       
   270      * @return Player's state.
       
   271      */
       
   272     inline TInt State();
       
   273 
       
   274     /**
       
   275      * Returns player's type. Player types are defined in derived player
       
   276      * headers.
       
   277      * @return Player type.
       
   278      */
       
   279     virtual const TDesC& Type();
       
   280 
       
   281     /**
       
   282      * Sets player's content type, which can be queried with ContentType
       
   283      * method. Ownership is transfered.
       
   284      * @param aContentType Player's content type.
       
   285      */
       
   286     void SetContentType(HBufC* aContentType);
       
   287 
       
   288     /**
       
   289      * Reset all source streams.
       
   290      */
       
   291     void ResetSourceStreams();
       
   292 
       
   293     /**
       
   294      * Refresh all the controls.
       
   295      */
       
   296     void RefreshControls();
       
   297     /**
       
   298     * delete all the controls.
       
   299     */
       
   300     void DeleteControls();
       
   301 
       
   302 public: // methods for informing java player listeners
       
   303 
       
   304     /**
       
   305      * Post event which event data will be Long java object.
       
   306      *
       
   307      * @param aEventType Event's type specified in CMMAPlayerEvent.
       
   308      * @param aLongEventData Event data context.
       
   309      */
       
   310     void PostLongEvent(CMMAPlayerEvent::TEventType aEventType,
       
   311                        const TInt64& aLongEventData);
       
   312 
       
   313     /**
       
   314      * Post event which event data will be string.
       
   315      *
       
   316      * @param aEventType Event's type specified in CMMAPlayerEvent.
       
   317      * @param aStringEventData Event data context.
       
   318      */
       
   319     IMPORT_C void PostStringEvent(CMMAPlayerEvent::TEventType aEventType,
       
   320                                   const TDesC& aStringEventData);
       
   321 
       
   322     /**
       
   323      * Post event which event data will be a java object.
       
   324      *
       
   325      * @param aEventType Event's type specified in CMMAPlayerEvent.
       
   326      * @param aEventData Java object.
       
   327      */
       
   328     IMPORT_C void PostObjectEvent(CMMAPlayerEvent::TEventType aEventType,
       
   329                                   const jobject aEventData);
       
   330 
       
   331     /**
       
   332      * Completes action and allows Java side to continue.
       
   333      *
       
   334      * @param aError of the action or KErrNone.
       
   335      */
       
   336     IMPORT_C void PostActionCompleted(TInt aError);
       
   337     
       
   338     IMPORT_C void PostActionCompletedFile();   //LC work for S60 3.2
       
   339     
       
   340     IMPORT_C void PostActionCompletedStart();
       
   341 protected: // new methods
       
   342     /**
       
   343      * @see StaticAddSourceStreamL
       
   344      */
       
   345     IMPORT_C virtual CMMASourceStream* AddSourceStreamL(JNIEnv* aJniEnv,
       
   346             MMAFunctionServer* aEventSource,
       
   347             jobject aReader);
       
   348 
       
   349     /**
       
   350      * Changes player's state and informs all MMMAPlayerStateListeners.
       
   351      *
       
   352      * @param aState New state.
       
   353      */
       
   354     void ChangeState(TPlayerState aState);
       
   355 
       
   356 public: // from MMMASourceStreamListener
       
   357     virtual void ReadCompletedL(TInt aStatus, const TDesC8& aData);
       
   358 
       
   359 protected: // Memeber data
       
   360     /**
       
   361      * Array of controls. All controls are owned by this class.
       
   362      */
       
   363     RPointerArray< CMMAControl > iControls;
       
   364 
       
   365     /**
       
   366      * Array of streams. All streams are owned by this class.
       
   367      */
       
   368     RPointerArray< CMMASourceStream > iSourceStreams;
       
   369 
       
   370 
       
   371     /**
       
   372      * Array of listeners. Not owned.
       
   373      */
       
   374     RPointerArray< MMMAPlayerStateListener > iStateListeners;
       
   375 
       
   376     /**
       
   377      * Used to inform java side of completion.
       
   378      * Owned.
       
   379      */
       
   380     CMMAEvent* iActionCompletedEvent;
       
   381     
       
   382     /**
       
   383      * Used to inform java side of completion.
       
   384      * Owned.
       
   385      */
       
   386     CMMAEvent* iActionCompletedFileEvent;    
       
   387     
       
   388     CMMAEvent* iActionCompletedStartEvent;      
       
   389   
       
   390     /**
       
   391      * Player state listener object.
       
   392      */
       
   393     jobject iListenerObject;
       
   394 
       
   395     /**
       
   396      * java method postEvent(String,Object)
       
   397      */
       
   398     jmethodID iPostEvent;
       
   399     /**
       
   400      * java method postObjectEvent(int,Object)
       
   401      */
       
   402     jmethodID iPostObjectEvent;
       
   403 
       
   404     /**
       
   405      * java method postLongEvent(int,long)
       
   406      */
       
   407     jmethodID iPostLongEvent;
       
   408 
       
   409     /**
       
   410      * java method postStringEvent(int,String)
       
   411      */
       
   412     jmethodID iPostStringEvent;
       
   413 
       
   414     /**
       
   415      * java method postControlEvent(int,String)
       
   416      */
       
   417     jmethodID iPostControlEvent;
       
   418 
       
   419     /**
       
   420      * Not owned.
       
   421      */
       
   422     MMMAEventPoster* iEventPoster;
       
   423 
       
   424     /**
       
   425      * Total number of wanted loops.
       
   426      */
       
   427     TInt iRepeatNumberOfTimes;
       
   428 
       
   429     /**
       
   430      * Indicates if looping indefintely.
       
   431      */
       
   432     TBool iRepeatForever;
       
   433 
       
   434     /**
       
   435      * Current loop count.
       
   436      */
       
   437     TInt iRepeatCount;
       
   438 
       
   439     /**
       
   440      * Content duration in microseconds.
       
   441      */
       
   442     TInt64 iDuration;
       
   443 
       
   444     /**
       
   445      * Current state of the player.
       
   446      */
       
   447     TPlayerState iState;
       
   448 
       
   449     /**
       
   450      * Event for notificating Java that memory allocation has failed.
       
   451      * Owned.
       
   452      */
       
   453     CMMAPlayerEvent* iOOMErrorEvent;
       
   454 
       
   455     /**
       
   456      * The content type being played back by this Player.
       
   457      * Owned. May be NULL until type is available.
       
   458      */
       
   459     HBufC* iContentType;
       
   460 
       
   461     /**
       
   462      * Player state listener that sends duration update event to Java
       
   463      * if duration has changed when player state changes.
       
   464      */
       
   465     CMMADurationUpdater* iDurationUpdater;
       
   466 
       
   467 };
       
   468 
       
   469 
       
   470 inline TInt CMMAPlayer::State()
       
   471 {
       
   472     return iState;
       
   473 }
       
   474 
       
   475 #endif // CMMAPLAYER_H