mpx/playbackframework/playbackengine/src/mpxplaybackmediahelper.cpp
changeset 0 a2952bb97e68
child 50 762d760dcfdf
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:  Implementation of playback engine media helper
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <mpxtaskqueue.h>
       
    20 #include <mpxcollectionutility.h>
       
    21 #include <mpxcommandgeneraldefs.h>
       
    22 #include <mpxlog.h>
       
    23 #include "mpxplaybackengine.h"
       
    24 #include "mpxplaybackmediahelper.h"
       
    25 
       
    26 // CONSTANTS
       
    27 const TInt KTaskMediaWithAttributeSpec = 0;
       
    28 
       
    29 // ----------------------------------------------------------------------------
       
    30 // Two-phased constructor
       
    31 // ----------------------------------------------------------------------------
       
    32 //
       
    33 CMPXPlaybackMediaHelper* CMPXPlaybackMediaHelper::NewL(
       
    34     CMPXPlaybackEngine& aEngine )
       
    35     {
       
    36     CMPXPlaybackMediaHelper* p= new (ELeave) CMPXPlaybackMediaHelper( aEngine );
       
    37     CleanupStack::PushL(p);
       
    38     p->ConstructL();
       
    39     CleanupStack::Pop(p);
       
    40     return p;
       
    41     }
       
    42 
       
    43 // ----------------------------------------------------------------------------
       
    44 // Constructor.
       
    45 // ----------------------------------------------------------------------------
       
    46 //
       
    47 CMPXPlaybackMediaHelper::CMPXPlaybackMediaHelper(
       
    48     CMPXPlaybackEngine& aEngine )
       
    49     : iEngine( aEngine )
       
    50     {
       
    51     }
       
    52 
       
    53 // ----------------------------------------------------------------------------
       
    54 // 2nd phase constructor.
       
    55 // ----------------------------------------------------------------------------
       
    56 //
       
    57 void CMPXPlaybackMediaHelper::ConstructL()
       
    58     {
       
    59     iCollectionUtility = MMPXCollectionUtility::NewL( this );
       
    60 
       
    61 #ifdef __USE_MESSAGE_SUBSCRIPTION
       
    62     // This class does not care about collection messages
       
    63     iCollectionUtility->Collection().ClearSubscriptionsL();
       
    64 #endif
       
    65     iTaskQueue = CMPXActiveTaskQueue::NewL();
       
    66     }
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // Destructor
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 CMPXPlaybackMediaHelper::~CMPXPlaybackMediaHelper()
       
    73     {
       
    74     if ( iCollectionUtility )
       
    75         {
       
    76         iCollectionUtility->Close();
       
    77         }
       
    78     if ( iTaskQueue )
       
    79         {
       
    80         iTaskQueue->CancelRequests();
       
    81         delete iTaskQueue;
       
    82         }
       
    83     }
       
    84 
       
    85 // ----------------------------------------------------------------------------
       
    86 // Retrieves the media given the current path, and upon return,
       
    87 // either calls back the observer, or broadcasts the message to
       
    88 // the given client list
       
    89 // ----------------------------------------------------------------------------
       
    90 void CMPXPlaybackMediaHelper::MediaL(
       
    91     const CMPXCollectionPath& aPath,
       
    92     CMPXCommand* aCmd,
       
    93     MMPXPlaybackEngineObserver* aObserver,
       
    94     TBool aBroadcast /*= EFalse */,
       
    95     CMPXClientList* aClientList /*= NULL */ )
       
    96     {
       
    97     MPX_DEBUG1("CMPXPlaybackMediaHelper::MediaL(): Entering");
       
    98 
       
    99     CMPXCollectionPath* path( CMPXCollectionPath::NewL( aPath ) );
       
   100     CleanupStack::PushL( path );
       
   101     CleanupStack::PushL( aCmd );
       
   102 
       
   103     if ( aBroadcast )
       
   104         {
       
   105         iTaskQueue->AddTaskL( KTaskMediaWithAttributeSpec,
       
   106                               aClientList,
       
   107                               this,
       
   108                               ETrue,
       
   109                               NULL,
       
   110                               NULL,
       
   111                               path,
       
   112                               aCmd );
       
   113         }
       
   114     else
       
   115         {
       
   116         iTaskQueue->AddTaskL( KTaskMediaWithAttributeSpec,
       
   117                               aObserver,
       
   118                               this,
       
   119                               EFalse,
       
   120                               NULL,
       
   121                               NULL,
       
   122                               path,
       
   123                               aCmd );
       
   124         }
       
   125     // Ownership of aAttrs and path passed to the task queue
       
   126     CleanupStack::Pop( aCmd );
       
   127     CleanupStack::Pop( path );
       
   128 
       
   129     MPX_DEBUG1("CMPXPlaybackMediaHelper::MediaL(): Exiting");
       
   130     }
       
   131 
       
   132 // ----------------------------------------------------------------------------
       
   133 // Cancels all outstanding requests
       
   134 // ----------------------------------------------------------------------------
       
   135 void CMPXPlaybackMediaHelper::CancelRequests()
       
   136     {
       
   137     MPX_FUNC_EX("CMPXPlaybackMediaHelper::CancelRequests()");
       
   138     if ( iCollectionUtility )
       
   139         {
       
   140         iCollectionUtility->Collection().CancelRequest();
       
   141         }
       
   142     if ( iTaskQueue )
       
   143         {
       
   144         iTaskQueue->CancelRequests();
       
   145         }
       
   146     }
       
   147 
       
   148 // ----------------------------------------------------------------------------
       
   149 // From MMPXTaskQueueObserver
       
   150 // Executes task
       
   151 // ----------------------------------------------------------------------------
       
   152 void CMPXPlaybackMediaHelper::ExecuteTask(
       
   153     TInt aTask,
       
   154     TInt aParamData,
       
   155     TAny* aPtrData,
       
   156     const CBufBase& aBuf,
       
   157     TAny* aCallback,
       
   158     CBase* aCObject1,
       
   159     CBase* aCObject2)
       
   160     {
       
   161     MPX_DEBUG1("CMPXPlaybackMediaHelper::ExecuteTask(): Entering");
       
   162 
       
   163     TRAPD( err, DoExecuteTaskL( aTask, aParamData, aPtrData,
       
   164                                 aBuf, aCallback, aCObject1, aCObject2 ));
       
   165     if ( KErrNone != err )
       
   166         {
       
   167         TRAP_IGNORE(
       
   168             CMPXMedia* dummy( CMPXMedia::NewL() );
       
   169             CleanupStack::PushL( dummy );
       
   170             HandleCollectionMediaL( *dummy, err );
       
   171             CleanupStack::PopAndDestroy( dummy );
       
   172             )
       
   173         }
       
   174 
       
   175     MPX_DEBUG1("CMPXPlaybackMediaHelper::ExecuteTask(): Exiting");
       
   176     }
       
   177 
       
   178 // ----------------------------------------------------------------------------
       
   179 // CMPXPlaybackMediaHelper::HandleTaskError
       
   180 // ----------------------------------------------------------------------------
       
   181 void CMPXPlaybackMediaHelper::HandleTaskError(
       
   182     TInt /* aTask */,
       
   183     TAny* /*aPtrData*/,
       
   184     TAny* /*aCallback*/,
       
   185     TInt /* aError */)
       
   186     {
       
   187     // do nothing, queued tasks are not canceled
       
   188     }
       
   189 
       
   190 // ----------------------------------------------------------------------------
       
   191 // From MMPXCollectionObserver
       
   192 // ----------------------------------------------------------------------------
       
   193 void CMPXPlaybackMediaHelper::HandleCollectionMessage(
       
   194     CMPXMessage* /*aMsg*/,
       
   195     TInt /*aErr*/)
       
   196     {
       
   197     MPX_DEBUG1("CMPXPlaybackMediaHelper::HandleCollectionMessageL(CMPXMessage): Entering");
       
   198     MPX_DEBUG1("CMPXPlaybackMediaHelper::HandleCollectionMessageL(CMPXMessage): Exiting");
       
   199     }
       
   200 
       
   201 // ----------------------------------------------------------------------------
       
   202 // From MMPXCollectionObserver
       
   203 // ----------------------------------------------------------------------------
       
   204 void CMPXPlaybackMediaHelper::HandleOpenL(
       
   205     const CMPXMedia& /*aEntries*/,
       
   206     TInt /*aIndex*/,
       
   207     TBool /*aComplete*/,
       
   208     TInt /*aError*/ )
       
   209     {
       
   210     MPX_DEBUG1("CMPXPlaybackMediaHelper::HandleOpenL(): Entering");
       
   211     MPX_DEBUG1("CMPXPlaybackMediaHelper::HandleOpenL(): Exiting");
       
   212     }
       
   213 
       
   214 // ----------------------------------------------------------------------------
       
   215 // From MMPXCollectionObserver
       
   216 // ----------------------------------------------------------------------------
       
   217 void CMPXPlaybackMediaHelper::HandleOpenL(
       
   218     const CMPXCollectionPlaylist& /*aPlaylist*/,
       
   219     TInt /*aError*/ )
       
   220     {
       
   221     MPX_DEBUG1("CMPXPlaybackMediaHelper::HandleOpenL(): Entering");
       
   222     MPX_DEBUG1("CMPXPlaybackMediaHelper::HandleOpenL(): Exiting");
       
   223     }
       
   224 
       
   225 // ----------------------------------------------------------------------------
       
   226 // From MMPXCollectionObserver
       
   227 // ----------------------------------------------------------------------------
       
   228 void CMPXPlaybackMediaHelper::HandleCommandComplete(
       
   229     CMPXCommand* /*aCommandResult*/,
       
   230     TInt /*aError*/ )
       
   231     {
       
   232     MPX_DEBUG1("CMPXPlaybackMediaHelper::HandleCommandComplete(): Entering");
       
   233     MPX_DEBUG1("CMPXPlaybackMediaHelper::HandleCommandComplete(): Exiting");
       
   234     }
       
   235 
       
   236 // ----------------------------------------------------------------------------
       
   237 // From MMPXCollectionmediaObserver
       
   238 // ----------------------------------------------------------------------------
       
   239 //
       
   240 void CMPXPlaybackMediaHelper::HandleCollectionMediaL(
       
   241     const CMPXMedia& aMedia,
       
   242     TInt aError )
       
   243     {
       
   244     MPX_FUNC_EX("CMPXPlaybackMediaHelper::HandleCollectionMediaL");
       
   245     MPX_DEBUG2("CMPXPlaybackMediaHelper::HandleCollectionMediaL(): error %d", aError);
       
   246 
       
   247     // First check if media attributes supported, if not, need to retrieve
       
   248     // from playback plugin
       
   249     TBool mediaOk( ETrue );
       
   250     // Note: The following block is for uPnP remote playlist which does not contain
       
   251     // metadata in the remote playlist. However, uPnP update to gurantee that titles
       
   252     // are available in the collection plugin. If KMPXMediaColDetailMediaNotAvailable
       
   253     // returned, UI can at least update title anyway anyway.
       
   254     //
       
   255     // We could not call MediaFromPluginL before the plugin initiliazed. uPnP made
       
   256     // changes so that it will call back media after the new track is initialized.
       
   257     // So we don't need call plugin API MediaL.
       
   258     /*if ( KErrNone == aError )
       
   259         { // media object is ok
       
   260         if ( aMedia.IsSupported( KMPXMediaColDetailMediaNotAvailable ))
       
   261             {
       
   262             TBool mediaNotSupported(
       
   263                     aMedia.ValueTObjectL<TBool>( KMPXMediaColDetailMediaNotAvailable ));
       
   264             MPX_DEBUG2("HandleCollectionMediaL media not inCollection %d",
       
   265                         mediaNotSupported);
       
   266             if ( mediaNotSupported)
       
   267                 { // It must be uPnP remote playlist, media request can only be
       
   268                   // sent to plugin at initialising, playing & pause state
       
   269                 mediaOk = EFalse;
       
   270                 // need to create a copy of buf since that will be delete when
       
   271                 // this task is completed
       
   272                 const TDesC8& data( iTaskQueue->BufData() );
       
   273                 CBufBase* buf( MPXUser::CreateBufferLC( data.Size() ));
       
   274                 buf->Write( 0, data );
       
   275                 iEngine.MediaFromPluginL(
       
   276                          static_cast<MMPXPlaybackEngineObserver*>(
       
   277                                                     iTaskQueue->Callback() ),
       
   278                          buf );
       
   279                 CleanupStack::Pop( buf );
       
   280                 } //otherwise, just send uri to clients.
       
   281             }
       
   282         }*/
       
   283 
       
   284     if ( mediaOk || aError )
       
   285         {
       
   286         MPX_DEBUG2("CMPXPlaybackMediaHelper::HandleCollectionMediaL task %d",
       
   287                    iTaskQueue->Task());
       
   288 
       
   289         if ( iTaskQueue->Param() )
       
   290             {
       
   291             // Broadcast
       
   292             CMPXMessage* msg( CMPXMessage::NewL() );
       
   293             CleanupStack::PushL( msg );
       
   294             msg->SetTObjectValueL<TMPXMessageId>( KMPXMessageGeneralId,
       
   295                                                   KMPXMessagePbMediaChanged );
       
   296             msg->SetCObjectValueL<CMPXMedia>( KMPXMessagePbMedia,
       
   297                                               const_cast<CMPXMedia*>( &aMedia ));
       
   298             CMPXClientList* clientList(
       
   299                 static_cast<CMPXClientList*>( iTaskQueue->Callback() ));
       
   300             clientList->SendMsg(msg, KErrNone);
       
   301             CleanupStack::PopAndDestroy( msg );
       
   302             }
       
   303         else
       
   304             {
       
   305             // Callback
       
   306             MPX_DEBUG2("CMPXPlaybackMediaHelper::HandleCollectionMediaL task cb 0x%08x",
       
   307                        iTaskQueue->Callback());
       
   308             MMPXPlaybackEngineObserver* callback(
       
   309                 static_cast<MMPXPlaybackEngineObserver*>( iTaskQueue->Callback() ));
       
   310             callback->HandleMedia( aMedia, aError );
       
   311             }
       
   312         }
       
   313     MPX_DEBUG1("CMPXPlaybackMediaHelper::HandleCollectionMediaL complete task");
       
   314     iTaskQueue->CompleteTask();
       
   315     }
       
   316 
       
   317 // ----------------------------------------------------------------------------
       
   318 // Executes task, leaving method
       
   319 // ----------------------------------------------------------------------------
       
   320 //
       
   321 void CMPXPlaybackMediaHelper::DoExecuteTaskL(
       
   322     TInt aTask,
       
   323     TInt /*aParamData*/,
       
   324     TAny* /*aPtrData*/,
       
   325     const CBufBase& /*aBuf*/,
       
   326     TAny* /*aCallback*/,
       
   327     CBase* aCObject1,
       
   328     CBase* aCObject2)
       
   329     {
       
   330     MPX_DEBUG1("CMPXPlaybackMediaHelper::DoExcuteTaskL(): Entering");
       
   331 
       
   332     if ( KTaskMediaWithAttributeSpec == aTask )
       
   333         {
       
   334         CMPXCollectionPath* path( static_cast<CMPXCollectionPath*>(aCObject1));
       
   335         CMPXMedia* media( static_cast<CMPXMedia*>(aCObject2));
       
   336 
       
   337         CMPXAttributeSpecs* specs =
       
   338                 media->Value<CMPXAttributeSpecs>( KMPXCommandMediaAttributeSpecs );
       
   339 
       
   340         const TDesC& attr = media->ValueText( KMPXCommandMediaAttribute );
       
   341         TPtrC8 ptr = MPXUser::Ptr( attr );
       
   342         RDesReadStream readStream( ptr );
       
   343         CleanupClosePushL( readStream );
       
   344         // Internalize attributes
       
   345         RArray<TMPXAttribute> attrs;
       
   346         CleanupClosePushL( attrs );
       
   347         ::InternalizeL( attrs, readStream );
       
   348         iCollectionUtility->Collection().MediaL(*path,
       
   349                                                 attrs.Array(),
       
   350                                                 specs );
       
   351 
       
   352         CleanupStack::PopAndDestroy( &attrs );
       
   353         CleanupStack::PopAndDestroy( &readStream );
       
   354         }
       
   355     else
       
   356         {
       
   357         iTaskQueue->CompleteTask();
       
   358         }
       
   359 
       
   360     MPX_DEBUG1("CMPXPlaybackMediaHelper::DoExcuteTaskL(): Exiting");
       
   361     }
       
   362 
       
   363 //End of file