upnpmpxplugins/upnpplaybackplugins/inc/upnpplaybackstatemachine.h
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2008 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:      Class for retrieving and selecting media renderers
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #ifndef C_UPNPPLAYBACKSTATEMACHINE_H
       
    24 #define C_UPNPPLAYBACKSTATEMACHINE_H
       
    25 
       
    26 // INCLUDES
       
    27 #include <e32base.h>
       
    28 #include "upnpmusicperiodizer.h"
       
    29 
       
    30 // FORWARD DECLARATIONS
       
    31 class CUPnPMusicPlayer;
       
    32 class MUPnPPlayBackObserver;
       
    33 class MUPnPAVRenderingSession;
       
    34 
       
    35 /**
       
    36  * Class for handling playback state machine functionality
       
    37  *
       
    38  * @lib upnpmusicplugins.lib
       
    39  * @since S60 v3.1
       
    40  */
       
    41 class CUPnPPlaybackStateMachine : public CBase, 
       
    42                                   public MUPnPMusicPeriodizerObserver
       
    43     {
       
    44 
       
    45 public:
       
    46 
       
    47     /**
       
    48      * Static 1st phase constructor
       
    49      *
       
    50      * @since Series 60 3.1
       
    51      * @param aParent the parent plugin instance
       
    52      * @param aRenderingSession for playback commands
       
    53      */
       
    54     static CUPnPPlaybackStateMachine* NewL( 
       
    55         CUPnPMusicPlayer& aParent,
       
    56         MUPnPAVRenderingSession& aRenderingSession );
       
    57 
       
    58     
       
    59     /**
       
    60      * 2nd phase constructor
       
    61      *
       
    62      * @since Series 60 3.1
       
    63      */   
       
    64     void ConstructL();
       
    65     
       
    66     /**
       
    67      * Destructor
       
    68      *
       
    69      * @since Series 60 3.1
       
    70      */
       
    71     virtual ~CUPnPPlaybackStateMachine();
       
    72 
       
    73     /** 
       
    74      * Executes a command on the selected song
       
    75      *
       
    76      * @param aCmd a command
       
    77      * @since Series 60 3.1
       
    78      */
       
    79     void CommandL( TMPXPlaybackCommand aCmd );
       
    80 
       
    81     /**
       
    82      * Sets the playback position within the current track
       
    83      * @param aPosition position in milliseconds
       
    84      */
       
    85     void PositionL( TInt aPosition );
       
    86 
       
    87     /**
       
    88      * Stops playback, does not provide any ACK event
       
    89      */
       
    90     void SilentStopL();
       
    91 
       
    92     /**
       
    93      * Cancels any ongoing operation
       
    94      * (actually it just resets the state so the result will be ignored
       
    95      * and not reported)
       
    96      */
       
    97     void Cancel();
       
    98 
       
    99     /**
       
   100      * Indicates that the requested interaction operation (play, stop, etc.)
       
   101      * is complete.
       
   102      *
       
   103      * @since Series 60 3.1
       
   104      * @param aErrorCode TInt error code
       
   105      * @param aOperation TInt operation (TAVInteractOperation)
       
   106      * @return None
       
   107      */
       
   108     void InteractOperationComplete( TInt aErrorCode, 
       
   109         TUPnPAVInteractOperation aOperation );
       
   110 
       
   111     /**
       
   112      * End any ongoing operation
       
   113      * (actually it just resets the state so the result will play next song
       
   114      */
       
   115     void PlayOvertimeEnd(); 
       
   116 
       
   117 private:
       
   118 
       
   119     /**
       
   120      * Private default constructor
       
   121      *
       
   122      * @since Series 60 3.1
       
   123      * @param aParent the parent plugin instance
       
   124      * @param aRenderingSession for playback commands
       
   125      */
       
   126     CUPnPPlaybackStateMachine(
       
   127         CUPnPMusicPlayer& aParent,
       
   128         MUPnPAVRenderingSession& aRenderingSession );
       
   129 
       
   130 public: // datatypes used in this class
       
   131 
       
   132     /**
       
   133      * Defines internal state
       
   134      *
       
   135      * @since Series 60 3.1
       
   136      */   
       
   137     enum TState
       
   138         {
       
   139         EStateStopped,
       
   140         EStatePlaying,
       
   141         EStatePaused,
       
   142         EStateUnknown,  // this state entered if a command fails.
       
   143                         // every state transition is accepted.
       
   144         };
       
   145 
       
   146     /**
       
   147      * current type of operation
       
   148      */
       
   149     enum TOperationType
       
   150         {
       
   151         EOperationNone, // no pending operations
       
   152         EOperationCommand, // executing a command
       
   153         EOperationPositionToZero, // adjusting position to zero
       
   154         EOperationPositionToZeroDuringPause, // ...during pause state
       
   155         EOperationSilentStop // stop without ack
       
   156         };
       
   157 
       
   158     /**
       
   159      * An internal operation class
       
   160      */
       
   161     class TOperation
       
   162         {
       
   163         public:
       
   164         /** construction */
       
   165         TOperation( TOperationType aType )
       
   166             : iType( aType ) {}
       
   167         TOperation( TMPXPlaybackCommand aCmd )
       
   168             : iType( EOperationCommand ), iCmd( aCmd ) {}
       
   169         /** setters */
       
   170         void operator=( TOperationType aType )
       
   171             {
       
   172             iType = aType;
       
   173             }
       
   174         void operator=( TMPXPlaybackCommand aCmd )
       
   175             {
       
   176             iType = EOperationCommand; iCmd = aCmd;
       
   177             }
       
   178         void Reset()
       
   179             {
       
   180             iType = EOperationNone;
       
   181             }
       
   182         /** comparision */
       
   183         TBool operator==( TOperationType aType )
       
   184             {
       
   185             return ( iType == aType );
       
   186             }
       
   187         TBool operator==( TMPXPlaybackCommand aCmd )
       
   188             {
       
   189             return ( iType == EOperationCommand && iCmd == aCmd );
       
   190             }
       
   191         TBool None()
       
   192             {
       
   193             return ( iType == EOperationNone );
       
   194             }
       
   195         /** identifies the operation type */
       
   196         TOperationType iType;
       
   197         /** in case the operation is a command, the command */
       
   198         TMPXPlaybackCommand iCmd;
       
   199         };
       
   200 
       
   201 protected: // internal methods
       
   202 
       
   203     /**
       
   204      * Handles the close command internally
       
   205      */
       
   206     void HandleCloseL();
       
   207 
       
   208     /**
       
   209      * Checks if operations are in the queue, and executes
       
   210      */
       
   211     void CheckOperationInQueueL();
       
   212 
       
   213     /**
       
   214      * Handle timers when playback start
       
   215      */
       
   216     void TimePlay();
       
   217 
       
   218     /**
       
   219      * Handle timers when pause
       
   220      */
       
   221     void TimePause();
       
   222 
       
   223     /**
       
   224      * Handle timers when continuing from pause
       
   225      */
       
   226     void TimeContinue();
       
   227 
       
   228     /**
       
   229      * Handle timers when stopped
       
   230      * Guesses if playback was completed or stopped by user.
       
   231      * This is estimated by comparing track play time and track duration.
       
   232      * @return ETrue if we guess the track playback was completed
       
   233      */
       
   234     TBool TimeStop();
       
   235 
       
   236     /**
       
   237      * Changes the internal state
       
   238      * @param aNewState the state to enter
       
   239      */
       
   240     void ChangeState( TState aNewState );
       
   241 
       
   242     /**
       
   243      * textual representation of a state
       
   244      */
       
   245     const TDesC* State( TState aState );
       
   246 
       
   247 protected: // From MUPnPPeriodizerObserver
       
   248 
       
   249     /**
       
   250      * See MUPnPMusicPeriodizerObserver
       
   251      */
       
   252     void HandlePeriod();
       
   253     
       
   254    /**
       
   255      * See MUPnPMusicPeriodizerObserver
       
   256      */ 
       
   257     void HandlePeriodForEnd();  
       
   258 
       
   259 private: // data
       
   260 
       
   261     /**
       
   262      * Parent plugin instance
       
   263      */ 
       
   264     CUPnPMusicPlayer&           iParent;
       
   265 
       
   266     /**
       
   267      * Rendering session
       
   268      */ 
       
   269     MUPnPAVRenderingSession&    iRendererSession;
       
   270 
       
   271     /**
       
   272      * Playback state
       
   273      */ 
       
   274     TState                      iState;
       
   275 
       
   276     /**
       
   277      * currently ongoing operation
       
   278      */
       
   279     TOperation                  iCurrentOperation;
       
   280 
       
   281     /**
       
   282      * queue of operations pending
       
   283      */
       
   284     RArray<TOperation>          iOperationQueue;
       
   285 
       
   286     /**
       
   287      * time when playback started
       
   288      */
       
   289     TTime                       iPlayMark;
       
   290 
       
   291     /**
       
   292      * time when pause started
       
   293      */
       
   294     TTime                       iPauseMark;
       
   295 
       
   296     /**
       
   297      * total time spent in pause (in milliseconds)
       
   298      */
       
   299     TInt                        iPausetime;
       
   300     
       
   301     /**
       
   302      * Timer support
       
   303      * Own.
       
   304      */
       
   305     CUPnPMusicPeriodizer*       iPeriodizer;
       
   306 
       
   307      /**
       
   308      * Timer support
       
   309      * Own.
       
   310      */
       
   311     CUPnPMusicPeriodizer*       iPeriodizerEnd;
       
   312 
       
   313     };
       
   314 
       
   315 
       
   316 #endif // C_UPNPPLAYBACKSTATEMACHINE_H
       
   317