mpx/playbackframework/playbackengine/inc/mpxplaybackinitializer.h
changeset 0 a2952bb97e68
child 15 d240f0a77280
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     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:  Initialize a file before playback
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CMPXPLAYBACKINITIALIZER_H
       
    20 #define CMPXPLAYBACKINITIALIZER_H
       
    21 
       
    22 #include <mpxplaybackframeworkdefs.h>
       
    23 #include <mpxplaybackpluginobserver.h>
       
    24 #include <mpxpluginhandlerobserver.h>
       
    25 #include <mpxcollectionobserver.h>
       
    26 
       
    27 class CMPXPlaybackPluginHandler;
       
    28 class CMPXCollectionPlaylist;
       
    29 class CMPXPlaybackEngine;
       
    30 class CMPXPlaybackPluginHandler;
       
    31 class CMPXPlaybackPlugin;
       
    32 class CMPXPlaybackMediaHelper;
       
    33 
       
    34 /**
       
    35 *  Initializes playlist to be played. This class is a friend
       
    36 *  of CMPXPlaybackEngine
       
    37 *
       
    38 *  The use of this class is intended to be as follows by the
       
    39 *  playback engine:
       
    40 *  1) The Engine creates initializer class and initializes it with a
       
    41 *     CMPXCollectionPlaylist.
       
    42 *  2) This initializer will then request the media.
       
    43 *  3) The Engine then calls SetActive(), which means the Engine is now
       
    44 *     active, so that means the resultant media request will be forwarded
       
    45 *     directly to the Engine.
       
    46 *  4) The Engine can then call Next() anytime afterwards.  This will
       
    47 *     make the initializer call request media on the next item in the playlist.
       
    48 *  5) Once the media returns to the initializer, it will create a playback
       
    49 *     plugin and initialize the file
       
    50 *  6) Once initialized, the plugin stays in the initialized state.  If the
       
    51 *     Engine then calls SetActive() again, the plugin and all data will
       
    52 *     be swapped, and then the Engine can start playing immediately.
       
    53 *
       
    54 *  At anytime during the process (e.g. during request media, during
       
    55 *  initialization, etc), the Engine can interrupt the process and call
       
    56 *  SetActive(), which will swap any plugins or data appropriately, depending
       
    57 *  on the current state.
       
    58 *
       
    59 */
       
    60 class CMPXPlaybackInitializer : public CBase,
       
    61                                 public MMPXPlaybackPluginObserver,
       
    62                                 public MMPXPluginHandlerObserver
       
    63     {
       
    64 public:
       
    65     /**
       
    66      *  Two-phased constructor.
       
    67      *
       
    68      *  @param aEngine reference to engine
       
    69      *  @param aMediaHelper Media helper object
       
    70      *  @return Constructed object
       
    71      */
       
    72     static CMPXPlaybackInitializer* NewL(
       
    73         CMPXPlaybackEngine& aEngine,
       
    74         CMPXPlaybackMediaHelper& aMediaHelper );
       
    75 
       
    76     /**
       
    77      *  Destructor
       
    78      */
       
    79     ~CMPXPlaybackInitializer();
       
    80 
       
    81     /**
       
    82     * Start intializing first media in the playlist.
       
    83     * Clears any current playlist being processed
       
    84     */
       
    85     void Init(CMPXCollectionPlaylist& aPlaylist);
       
    86 
       
    87     /**
       
    88     * Initializes next track in playlist. Discards current
       
    89     * track being processed
       
    90     */
       
    91     TBool Next();
       
    92 
       
    93     /**
       
    94     * Set the playlist active in the engine. Subsequently,
       
    95     * the next track or a new playlist can be initialized
       
    96     */
       
    97     void SetActiveL();
       
    98 
       
    99     /**
       
   100     * Close the initializer
       
   101     */
       
   102     void Close();
       
   103 
       
   104     /**
       
   105     * Return the TMPXItemId of the current file in the initializer
       
   106     */
       
   107     TMPXItemId CurrentInitItemId();
       
   108 
       
   109     /**
       
   110      * Implementation uid of the plugin of pre-initialzer
       
   111      */
       
   112     TUid PluginUid();
       
   113     
       
   114 private:
       
   115     /**
       
   116     *  C++ constructor
       
   117     *
       
   118     *  @param aEngine reference to engine
       
   119     *  @param aMediaHelper Media helper object
       
   120     */
       
   121     CMPXPlaybackInitializer(
       
   122         CMPXPlaybackEngine& aEngine,
       
   123         CMPXPlaybackMediaHelper& aMediaHelper );
       
   124 
       
   125     /**
       
   126     *  2nd phase contructor
       
   127     */
       
   128     void ConstructL();
       
   129 
       
   130     /**
       
   131     * Resets such that next media can be initialised
       
   132     */
       
   133     void Reset();
       
   134 
       
   135     /**
       
   136     * Get the Media from the collection - the callback triggers
       
   137     * the initialization
       
   138     */
       
   139     void RequestMediaL();
       
   140 
       
   141     /**
       
   142     * Updates the forwarding variable
       
   143     * to send the media to the engine if a media has been requested.
       
   144     */
       
   145     void UpdateMediaForwarding();
       
   146 
       
   147     /**
       
   148     * Swaps the plugin being handled in the initializer to the
       
   149     * engine, which takes over in whatever state it currently is in.
       
   150     */
       
   151     void SwapPluginL();
       
   152 
       
   153     /**
       
   154     * Swaps the item uri in the engine
       
   155     * Only in the EPbStateInitialising and EPbStateStopped states
       
   156     */
       
   157     void SwapUriL();
       
   158 
       
   159     /**
       
   160     * Swaps the item db flag in the engine
       
   161     * Only in the EPbStateInitialising and EPbStateStopped states
       
   162     */
       
   163     void SwapFlag();
       
   164 
       
   165     /**
       
   166     * Is this playlist the one currently being processed?
       
   167     * @param aPlaylist Playlist to check if it is already initialized
       
   168     */
       
   169     TBool IsInitializing(const CMPXCollectionPlaylist& aPlaylist);
       
   170 
       
   171     /**
       
   172     * Initializes a track
       
   173     * @param aMedia CMPXMedia object to initialize
       
   174     * @param aError Error returned from media request
       
   175     */
       
   176     void InitL(const CMPXMedia& aMedia,TInt aError);
       
   177 
       
   178     /**
       
   179     * Cancels the pre-init timer
       
   180     */
       
   181     void CancelPreInitTimer();
       
   182 
       
   183     /**
       
   184     * Handle pre-init timer callback
       
   185     */
       
   186     void HandlePreInitTimerCallback();
       
   187 
       
   188     /**
       
   189     * Callback for pre-init timer.
       
   190     */
       
   191     static TInt PreInitTimerCallback(TAny* aPtr);
       
   192 
       
   193     /**
       
   194      * Initialize streaming
       
   195      */
       
   196     void InitL(const TDesC& aUri, const TDesC8& aType, TInt aAccessPoint);
       
   197     
       
   198 private:
       
   199     /**
       
   200      *  From MMPXPlaybackPluginObserver
       
   201      *  Handle plugin event
       
   202      *
       
   203      *  @param aEvent the event type
       
   204      *  @param aData optional data
       
   205      *  @param aError error code of the event
       
   206      */
       
   207     void HandlePluginEvent(TEvent aEvent,TInt aData,TInt aError);
       
   208 
       
   209     /**
       
   210      *  Leaving version of CMPXPlaybackInitializer::HandlePluginEvent
       
   211      */
       
   212     void HandlePluginEventL(TEvent aEvent,TInt aData,TInt aError);
       
   213 
       
   214     /**
       
   215      * From MMPXPlaybackPluginObserver
       
   216      * Handle message from plug-in
       
   217      *
       
   218      * @param aMsg, message from the plug-in. Ownership not transferred.
       
   219      * @param aErr system error code. if aErr is not KErrNone, aMsg will not be
       
   220      *        used/dereferenced at playback engine.
       
   221      */
       
   222     void HandlePlaybackMessage(CMPXMessage* aMsg, TInt aErr);
       
   223 
       
   224     /**
       
   225      *  From MMPXPlaybackPluginObserver
       
   226      *  Async response for Value request
       
   227      *
       
   228      *  @param aProperty property key
       
   229      *  @param aValue property value
       
   230      *  @param aError error code
       
   231      */
       
   232     void HandleProperty(TMPXPlaybackProperty aProperty,
       
   233                          TInt aValue,TInt aError);
       
   234 
       
   235     /**
       
   236      *  From MMPXPlaybackPluginObserver
       
   237      *  Async response for subplayer request
       
   238      *
       
   239      *  @param aPlayer UID of the subplayer
       
   240      *  @param aSubPlayers array of subplayers
       
   241      *  @param aComplete ETrue, completed, EFalse, not completed
       
   242      *  @param aError error code
       
   243      */
       
   244     void HandleSubPlayerNames(TUid aPlayer,const MDesCArray* aSubPlayers,
       
   245                                TBool aComplete,TInt aError);
       
   246 
       
   247     /**
       
   248      *  From MMPXPlaybackPluginObserver
       
   249      *  Async response for ExtendedMediaProperties request
       
   250      *
       
   251      *  @param aMedia property object
       
   252      *  @param aError error code
       
   253      */
       
   254     void HandleMedia(const CMPXMedia& aProperties,TInt aError);
       
   255 
       
   256     ///////////////////////////////////////////////////////////////////////////
       
   257     // From MMPXPluginHandlerObserver
       
   258 
       
   259     /*
       
   260     * @see MMPXPluginHandlerObserver
       
   261     */
       
   262     void HandlePluginHandlerEvent(TPluginHandlerEvents aEvent,
       
   263         const TUid& aPluginUid, TBool aLoaded, TInt aData);
       
   264 
       
   265 private:
       
   266     TMPXPlaybackState iState; // State of playlist
       
   267     CMPXPlaybackPluginHandler* iHandler;
       
   268     CMPXPlaybackEngine& iEngine;
       
   269     CMPXPlaybackMediaHelper& iMediaHelper;  // not owned
       
   270 
       
   271     TInt iPathIndex;
       
   272     TInt iInitPlaylistCount;
       
   273     TBool iMediaToEngine;
       
   274     TBool iMediaRequested;
       
   275 
       
   276     TInt iDuration;
       
   277     TInt iError;
       
   278     CMPXMedia* iMedia;
       
   279     CMPXMessage* iMediaMessage; // media update message from plugin
       
   280     TInt iErrorOfMediaMessage; // error along with media update message
       
   281     CPeriodic* iTimer;
       
   282     };
       
   283 
       
   284 #endif // CMPXPLAYBACKINITIALIZER_H