upnpmpxplugins/upnpplaybackplugins/inc/upnptrack.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 containing and obtaining music track-specific
       
    15 *                data from media server
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 #ifndef C_UPNPTRACK_H
       
    25 #define C_UPNPTRACK_H
       
    26 
       
    27 // INCLUDES
       
    28 #include <e32base.h>
       
    29 #include "upnpitemresolverobserver.h"
       
    30 #include "upnpresourceselector.h"
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 class TMPXAttribute;
       
    34 class TMPXAttributeData;
       
    35 class MUPnPAVController;
       
    36 class MUPnPAVBrowsingSession;
       
    37 class MUPnPTrackObserver;
       
    38 class MMPXPlaybackPluginObserver;
       
    39 class CUpnpItem;
       
    40 class MUPnPItemResolver;
       
    41 
       
    42 // CONSTANTS
       
    43 const TInt KMaxElementSize = 256;
       
    44 
       
    45 
       
    46 /**
       
    47  *  A helper class for containing and obtaining music track-specific data
       
    48  *  from media server
       
    49  *
       
    50  *  @lib upnpmusicplugins.lib
       
    51  *  @since S60 v3.1
       
    52  */
       
    53 class CUPnPTrack
       
    54     : public CBase
       
    55     , public MUPnPItemResolverObserver
       
    56     {
       
    57 
       
    58 public: // datatypes 
       
    59 
       
    60     /**
       
    61      * Defines direction of playback
       
    62      *
       
    63      * EDirectionRemote  - Used in local to remote and remote to remote
       
    64      *                     playback cases 
       
    65      * EDirectionLocal   - Used only in remote to local case.
       
    66      * 
       
    67      */
       
    68     enum TPlaybackDirection
       
    69         {
       
    70         EDirectionRemote = 0,
       
    71         EDirectionLocal
       
    72         };
       
    73 public:
       
    74 
       
    75     /**
       
    76      * static constructor
       
    77      *
       
    78      * @param aAvController AVController
       
    79      * @return a new CUPnPTrack instance
       
    80      * @since Series 60 3.1
       
    81      */
       
    82     static CUPnPTrack* NewL( MUPnPAVController& aAvController );
       
    83 
       
    84     /**
       
    85      * Destructor
       
    86      *
       
    87      * @since Series 60 3.1
       
    88      */
       
    89     virtual ~CUPnPTrack();
       
    90 
       
    91     /**
       
    92      * Parse and saves the song path from given descriptor
       
    93      *
       
    94      * @param aCodedTrackUri track URI that may be coded
       
    95      * @param atrackObserver observer to notify when resolve is complete
       
    96      * @param aPlaybackDirection direction of playback
       
    97      * @since Series 60 3.1
       
    98      */
       
    99     void ResolveURIL( const TDesC& aCodedTrackUri,
       
   100         MUPnPTrackObserver& aTrackObserver, 
       
   101         TPlaybackDirection aPlaybackDirection );
       
   102 
       
   103     /**
       
   104      * Returns the original URI given in initialisation
       
   105      *
       
   106      * @return TDesC URI
       
   107      * @since Series 60 3.1
       
   108      */
       
   109     const TDesC& URI() const;
       
   110 
       
   111     /**
       
   112      * Returns the true UPNP URI of a remote track
       
   113      *
       
   114      * @return TDesC8 URI
       
   115      * @since Series 60 3.1
       
   116      */
       
   117     const TDesC8& UpnpURI() const;
       
   118 
       
   119     /**
       
   120      * Returns the remote upnp item that represents the track
       
   121      *
       
   122      * @return CUpnpItem the item reference
       
   123      * @since Series 60 3.1
       
   124      */
       
   125     const CUpnpItem& UpnpItem() const;
       
   126     
       
   127     /**
       
   128      * Returns the file path of local item 
       
   129      *
       
   130      * @return TDesC file path
       
   131      * @since Series 60 3.1
       
   132      */
       
   133     const TDesC& FilePath() const;
       
   134 
       
   135     /**
       
   136      * Return location of track. ETrue = remote. EFalse = local
       
   137      *
       
   138      * @return TBool location of track
       
   139      * @since Series 60 3.1
       
   140      */
       
   141     TBool IsRemote() const;
       
   142 
       
   143     /**
       
   144      * Get metadata information for track from media server
       
   145      * 
       
   146      * @param aAttrs list of wanted media propeties
       
   147      * @param aObs the plugin observer that will receive the metadata
       
   148      * @since Series 60 3.1
       
   149      */
       
   150     void GetMetaDataL( const TArray<TMPXAttribute>& aAttrs,
       
   151         MMPXPlaybackPluginObserver& aObs );
       
   152 
       
   153     /**
       
   154      * Delivers media changed event to playback framework
       
   155      * @param aObs the plugin observer
       
   156      */
       
   157     void SendMediaChangedEventL(
       
   158         MMPXPlaybackPluginObserver& aObs );
       
   159 
       
   160     /**
       
   161      * current track duration
       
   162      * @return track duration in milliseconds
       
   163      */
       
   164     TInt TrackDuration();
       
   165 
       
   166     /**
       
   167      * overrides current track duration. Normally a track can provide
       
   168      * duration information for current remote track. However sometimes
       
   169      * the data is missing. In this case it can be set using this method.
       
   170      * @param aMilliseconds the duration in milliseconds
       
   171      */
       
   172     void SetTrackDuration( TInt aMilliseconds );
       
   173 
       
   174     /**
       
   175      * 
       
   176      */
       
   177     void Delete();
       
   178     
       
   179 protected: // MUPnPItemResolverObserver
       
   180 
       
   181     /**
       
   182      * See MUPnPItemResolverObserver
       
   183      */
       
   184     void ResolveComplete( const MUPnPItemResolver& aResolver, TInt aError );
       
   185 
       
   186 private:
       
   187 
       
   188     /**
       
   189      * Default constructor
       
   190      *
       
   191      * @param aAvController AVController
       
   192      * @since Series 60 3.1
       
   193      */
       
   194     CUPnPTrack( MUPnPAVController& aAvController );
       
   195 
       
   196     /**
       
   197      * 2nd phase constructor
       
   198      *
       
   199      * @since Series 60 3.1
       
   200      */
       
   201     void ConstructL();
       
   202     
       
   203     /**
       
   204      * Parse and save HttpURI, media server id and object id from 
       
   205      * given descriptor
       
   206      *
       
   207      * @since Series 60 3.1
       
   208      * @param aSong descriptor to be parsed
       
   209      */
       
   210     void ParsePiecesL( const TDesC& aSong );
       
   211     
       
   212     /**
       
   213      * See MUPnPAVBrowsingSessionObserver
       
   214      *
       
   215      * @since Series 60 3.1
       
   216      */
       
   217     void BrowseResponseL( const TDesC8& aBrowseResponse, TInt aError );
       
   218 
       
   219     /**
       
   220      * Starts a browsing session within the object
       
   221      */
       
   222     void StartBrowsingSessionL();
       
   223 
       
   224     /**
       
   225      * Stops a browsing session within the object
       
   226      */
       
   227     void StopBrowsingSession();
       
   228 
       
   229     /**
       
   230      * Delivers metadata to observer
       
   231      * @param aAttrs list of wanted media propeties
       
   232      * @param aObs the plugin observer that will receive the metadata
       
   233      * @param aError error code to be delivered to client
       
   234      */
       
   235     void DeliverMedataL( const TArray<TMPXAttribute>& aAttrs,
       
   236         MMPXPlaybackPluginObserver& aObs, TInt aError = KErrNone );
       
   237 
       
   238     /**
       
   239      * Fills item metadata into given MediaL object
       
   240      * @param aMedia the MPX media object to fill metadata into
       
   241      * @param aAttrs list of metadata elements to fill
       
   242      */
       
   243     void FillMediaFromItemL( CMPXMedia& aMedia,
       
   244         const TArray<TMPXAttribute>& aAttrs );
       
   245 
       
   246     /**
       
   247      * Tests if given attribute exists in the attribute array
       
   248      * returns true if it is found.
       
   249      * @param aAttrs the attribute array
       
   250      * @param aAttrData the attribute to look for
       
   251      * @return ETrue if it was found, EFalse otherwise
       
   252      */
       
   253     TBool Exists( const TArray<TMPXAttribute>& aAttrs,
       
   254         const TMPXAttributeData& aAttrData ) const;
       
   255 
       
   256     /**
       
   257      * A helper method that converts text from 8-bit to 16-bit.
       
   258      * Note that a member buffer is used that has static length.
       
   259      */
       
   260     const HBufC16* CUPnPTrack::To16LC( const TDesC8& aText );
       
   261 
       
   262 private: // data
       
   263 
       
   264     /**
       
   265      * Defines location of track
       
   266      *
       
   267      * @since Series 60 3.1
       
   268      */   
       
   269     enum TTrackLocation
       
   270         {
       
   271         ETrackLocationLocal = 0,
       
   272         ETrackLocationRemote
       
   273         };
       
   274     
       
   275     /**
       
   276      * Defines track state
       
   277      *
       
   278      * @since Series 60 3.2
       
   279      */  
       
   280     enum TTrackState
       
   281         {
       
   282         EStateIdle,
       
   283         EStateResolving,
       
   284         EStateSelfDestruct,
       
   285         EStateReady
       
   286         };
       
   287         
       
   288 
       
   289     /**
       
   290      * Location of track
       
   291      */
       
   292     TTrackLocation                      iTrackLocation;
       
   293 
       
   294     /**
       
   295      * URI for local track
       
   296      */
       
   297     HBufC*                              iOriginalURI;
       
   298 
       
   299     /**
       
   300      * Media server name 
       
   301      */
       
   302     HBufC8*                             iMediaServer;
       
   303 
       
   304     /**
       
   305      * Object id
       
   306      */
       
   307     HBufC8*                             iObjectId;
       
   308 
       
   309     /**
       
   310      * The AV Controller resource
       
   311      */
       
   312     MUPnPAVController&                  iAvController;
       
   313 
       
   314     /**
       
   315      * The rendering session
       
   316      */
       
   317     MUPnPAVBrowsingSession*             iBrowsingSession;
       
   318 
       
   319     /**
       
   320      * Track observer during resolving phase
       
   321      */
       
   322     MUPnPTrackObserver*                 iTrackObserver;
       
   323 
       
   324     /**
       
   325      * Observer for metadata queries
       
   326      * Stored in case metadata is not ready yet when queried
       
   327      */
       
   328     MMPXPlaybackPluginObserver*         iMetadataObserver;
       
   329 
       
   330     /**
       
   331      * Attributes in metadata query
       
   332      */
       
   333     RArray<TMPXAttribute>               iQueriedAttributes;
       
   334 
       
   335     /**
       
   336      * temp buffer used in 8->16 -bit conversion
       
   337      */
       
   338     TBuf16<KMaxElementSize>             iTempBuf;
       
   339 
       
   340     /**
       
   341      * track duration in milliseconds (from some other source)
       
   342      */
       
   343     TInt                                iTrackDuration;
       
   344 
       
   345     /**
       
   346      * Resolver for remote or local item (Owned).  
       
   347      */
       
   348     MUPnPItemResolver*                  iItemResolver;
       
   349     
       
   350     /**
       
   351      * Selectors for remote item.
       
   352      */
       
   353     TUPnPSelectDefaultResource          iDefaultSelector;
       
   354     
       
   355     /**
       
   356      * Selectors for local item.
       
   357      */
       
   358     TUPnPSelectFirstResource            iFirstSelector;
       
   359     
       
   360     /**
       
   361      * Tells is resolve item completed.
       
   362      */
       
   363     TBool                               iIsItemSolved;
       
   364     
       
   365     /**
       
   366      * Current track state
       
   367      */
       
   368     TTrackState                         iState;
       
   369     };
       
   370 
       
   371 
       
   372 #endif // C_UPNPTRACK_H