videoplayback/videohelix/src/mpxvideodlmgrif.cpp
changeset 0 96612d01cf9f
child 6 7d91903f795f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     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:  Implementation of CMPXVideoDownloadMgrInterface class.
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version: 21 %
       
    19 
       
    20 
       
    21 #include <MMFROPCustomCommandConstants.h>
       
    22 #include <mmf/common/mmfcontrollerframework.h>
       
    23 #include <mpxplaybackpluginobserver.h>
       
    24 #include <mpxmessagegeneraldefs.h>
       
    25 #include <mpxcommandgeneraldefs.h>
       
    26 #include <pathinfo.h>
       
    27 #include <f32file.h>
       
    28 
       
    29 #ifdef RD_MULTIPLE_DRIVE
       
    30 #include <driveinfo.h>
       
    31 #endif  //RD_MULTIPLE_DRIVE
       
    32 
       
    33 #include "mpxvideoplaybackcontroller.h"
       
    34 #include "mpxvideodlmgrif.h"
       
    35 #include "mpxvideodrmhelper.h"
       
    36 #include <mpxvideoplaybackdefs.h>
       
    37 #include "mpxvideo_debug.h"
       
    38 
       
    39 
       
    40 CMPXVideoDlMgrIf*
       
    41 CMPXVideoDlMgrIf::NewL( CMPXVideoPlaybackController* aController )
       
    42 {
       
    43     MPX_ENTER_EXIT(_L("CMPXVideoDlMgrIf::NewL()"));
       
    44 
       
    45     CMPXVideoDlMgrIf* self = new (ELeave) CMPXVideoDlMgrIf();
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL( aController );
       
    48     CleanupStack::Pop();
       
    49     return self;
       
    50 }
       
    51 
       
    52 
       
    53 void CMPXVideoDlMgrIf::ConstructL( CMPXVideoPlaybackController* aController )
       
    54 {
       
    55     iController = aController;
       
    56     iUpdateDownload = CIdle::NewL( CActive::EPriorityLow );
       
    57 }
       
    58 
       
    59 CMPXVideoDlMgrIf::CMPXVideoDlMgrIf()
       
    60     : iDlId(KErrNotFound)
       
    61 {
       
    62 }
       
    63 
       
    64 CMPXVideoDlMgrIf::~CMPXVideoDlMgrIf()
       
    65 {
       
    66     MPX_ENTER_EXIT(_L("CMPXVideoDlMgrIf::~CMPXVideoDlMgrIf()"));
       
    67 
       
    68     //
       
    69     //  Check if we need to move the clip or remove PDL flag from download
       
    70     //
       
    71     HandleClose();
       
    72 
       
    73     //
       
    74     //  Close the connection to the Download Manager
       
    75     //  if one has been established
       
    76     //
       
    77     if ( iDlMgrConnected )
       
    78     {
       
    79         iDlMgr.Close();
       
    80         iDlMgrConnected = EFalse;
       
    81     }
       
    82 
       
    83     if ( iUpdateDownload->IsActive() )
       
    84     {
       
    85         iUpdateDownload->Cancel();
       
    86     }
       
    87 
       
    88     delete iUpdateDownload;
       
    89 
       
    90     if ( iClipName )
       
    91     {
       
    92         delete iClipName;
       
    93         iClipName = NULL;
       
    94     }
       
    95 }
       
    96 
       
    97 
       
    98 void CMPXVideoDlMgrIf::ConnectToDownloadL( CMPXCommand& aCmd )
       
    99 {
       
   100     MPX_ENTER_EXIT(_L("CMPXVideoDlMgrIf::ConnectToDownloadL()"));
       
   101 
       
   102     //
       
   103     //  Retrieve the download id from the message
       
   104     //
       
   105     TInt downloadId = *aCmd.Value<TInt>( KMPXCommandPlaybackPDTransactionID );
       
   106     TPtrC fileName( aCmd.ValueText( KMPXMediaVideoPlaybackFileName ) );
       
   107     iMovePdlFile = *aCmd.Value<TInt>( KMPXMediaVideoMovePdlFile );
       
   108 
       
   109     MPX_DEBUG(_L("CMPXVideoDlMgrIf::ConnectToDownloadL(%S, %d)"), &fileName, downloadId );
       
   110 
       
   111     if ( iClipName )
       
   112     {
       
   113         delete iClipName;
       
   114         iClipName = NULL;
       
   115     }
       
   116 
       
   117     iClipName = fileName.AllocL();
       
   118 
       
   119     //
       
   120     //  A new download id has been sent.  Reset member variables
       
   121     //
       
   122     iMoveNeeded    = EFalse;
       
   123     iCurrentDl     = NULL;
       
   124     iDlId          = downloadId;
       
   125     iPlayerOpened  = EFalse;
       
   126     iDlTotalSize   = 0;
       
   127     iDownloadProgress = 0;
       
   128     iCodDownload   = EFalse;
       
   129 
       
   130     if ( iDlMgrConnected )
       
   131     {
       
   132         iDlMgr.Close();
       
   133         iDlMgrConnected = EFalse;
       
   134     }
       
   135 
       
   136     if ( iDlId != KErrNotFound )
       
   137     {
       
   138         const TUid KUidLWPlayer = { 0x102824CD };
       
   139 
       
   140         //
       
   141         //  Connect to the Download Manager
       
   142         //
       
   143         iDlMgr.ConnectL( KUidLWPlayer, *this, EFalse );
       
   144         iDlMgrConnected = ETrue;
       
   145 
       
   146         //
       
   147         //  Attach to the download id
       
   148         //
       
   149         RHttpDownload& newDownload = iDlMgr.AttachToDownloadL( iDlId );
       
   150 
       
   151         //
       
   152         //  Update the members with the current download info
       
   153         //
       
   154         iCurrentDl = &newDownload;
       
   155 
       
   156         //
       
   157         //  Set the progressive download attribute on the download
       
   158         //
       
   159         iCurrentDl->SetBoolAttribute( EDlAttrProgressive, ETrue );
       
   160 
       
   161         iCurrentDl->SetBoolAttribute( EDlAttrSilent, EFalse );
       
   162 
       
   163         //a temp hack until dl manager has a fix for this
       
   164         TInt32 activeDownload( 0 );
       
   165         iCurrentDl->GetIntAttribute( EDlAttrActiveDownload, activeDownload );
       
   166         iCurrentDl->SetIntAttribute( EDlAttrActivePlayedDownload, activeDownload );
       
   167 
       
   168         //
       
   169         //  Set the Local File attribute
       
   170         //
       
   171         iCurrentDl->SetStringAttribute( EDlAttrLocalFileName, iClipName->Des() );
       
   172 
       
   173         TInt32 dlState;
       
   174 
       
   175         //
       
   176         //  Get the state, downloaded and total size of the download and save it
       
   177         //
       
   178         iCurrentDl->GetIntAttribute( EDlAttrLength, iDlTotalSize );
       
   179         iCurrentDl->GetIntAttribute( EDlAttrDownloadedSize, iDownloadProgress );
       
   180         iCurrentDl->GetIntAttribute( EDlAttrState, dlState );
       
   181 
       
   182         MPX_DEBUG(_L("   dlSize = %d, currentSize = %d, state = %d"),
       
   183             iDlTotalSize, iDownloadProgress, dlState );
       
   184 
       
   185         ConvertDMgrStatetoMpxState( dlState );
       
   186 
       
   187         if ( iDownloadState == EPbDlStateDownloadCompleted )
       
   188         {
       
   189             HandleDownloadComplete();
       
   190         }
       
   191 
       
   192         MPX_DEBUG(_L("CMPXVideoDlMgrIf::ConnectToDownloadL() Download State = %d Total Size=%d"),
       
   193             iDownloadState, iDlTotalSize);
       
   194     }
       
   195 }
       
   196 
       
   197 void
       
   198 CMPXVideoDlMgrIf::HandleDMgrEventL( RHttpDownload& aDownload, THttpDownloadEvent aEvent )
       
   199 {
       
   200     MPX_ENTER_EXIT(_L("CMPXVideoDlMgrIf::HandleDMgrEventL()"),
       
   201                    _L("iDownloadState = %d iProgressState = %d"),
       
   202                     aEvent.iDownloadState, aEvent.iProgressState );
       
   203 
       
   204     TMPXPlaybackPdDownloadState prevDownloadState = iDownloadState;
       
   205 
       
   206     if ( &aDownload == iCurrentDl )
       
   207     {
       
   208         switch ( aEvent.iDownloadState )
       
   209         {
       
   210             case EHttpDlInprogress:
       
   211             {
       
   212                 iDownloadState = EPbDlStateDownloading;
       
   213 
       
   214                 switch ( aEvent.iProgressState )
       
   215                 {
       
   216                     case EHttpProgResponseBodyReceived:
       
   217                     {
       
   218                         if ( ! iUpdateDownload->IsActive() )
       
   219                         {
       
   220                             iUpdateDownload->Start(
       
   221                                     TCallBack( CMPXVideoDlMgrIf::UpdateDownloadProgress, this ) );
       
   222                         }
       
   223                         break;
       
   224                     }
       
   225                     case EHttpProgCodLoadEnd:
       
   226                     {
       
   227                         //
       
   228                         //  Set the member variable identifying this
       
   229                         //  as a COD download and handle the completion
       
   230                         //  of the download
       
   231                         //
       
   232                         iCodDownload = ETrue;
       
   233 
       
   234                         HandleDownloadComplete();
       
   235 
       
   236                         break;
       
   237                     }
       
   238                     case EHttpProgMovingContentFile:
       
   239                     {
       
   240                         //
       
   241                         //   Moving Started
       
   242                         //
       
   243                         MPX_DEBUG( _L("    Moving of file started"));
       
   244                         break;
       
   245                     }
       
   246                     case EHttpProgContentFileMoved:
       
   247                     case EHttpProgContentFileMovedAndDestFNChanged:
       
   248                     {
       
   249                         //
       
   250                         //  Move has completed, check error status
       
   251                         //
       
   252                         CheckForMoveError();
       
   253 
       
   254                         break;
       
   255                     }
       
   256                 }
       
   257 
       
   258                 break;
       
   259             }
       
   260             case EHttpDlPaused:
       
   261             {
       
   262                 iDownloadState = EPbDlStateDownloadPaused;
       
   263                 break;
       
   264             }
       
   265             case EHttpDlCompleted:
       
   266             {
       
   267                 iDownloadState = EPbDlStateDownloadCompleted;
       
   268 
       
   269                 switch ( aEvent.iProgressState )
       
   270                 {
       
   271                     case EHttpProgNone:
       
   272                     {
       
   273                         //
       
   274                         //  Ignore this event since COD downloads send this
       
   275                         //  event after we have already moved the file.
       
   276                         //
       
   277                         if ( ! iCodDownload )
       
   278                         {
       
   279                             HandleDownloadComplete();
       
   280                         }
       
   281 
       
   282                         break;
       
   283                     }
       
   284                     case EHttpProgMovingContentFile:
       
   285                     {
       
   286                         //
       
   287                         //   Moving Started
       
   288                         //
       
   289                         MPX_DEBUG( _L("    Moving of file started"));
       
   290                         break;
       
   291                     }
       
   292                     case EHttpProgContentFileMoved:
       
   293                     case EHttpProgContentFileMovedAndDestFNChanged:
       
   294                     {
       
   295                         //
       
   296                         //  Move has completed, check error status
       
   297                         //
       
   298                         CheckForMoveError();
       
   299 
       
   300                         break;
       
   301                     }
       
   302                 }
       
   303 
       
   304                 break;
       
   305             }
       
   306             case EHttpDlFailed:
       
   307             case EHttpDlMediaRemoved:
       
   308             case EHttpDlDeleted:
       
   309             case EHttpDlDeleting:
       
   310             {
       
   311                 iDownloadState = EPbDlStateDownloadCanceled;
       
   312 
       
   313                 //
       
   314                 //  Disconnect from the current download and Download Manager
       
   315                 //
       
   316                 iCurrentDl = NULL;
       
   317                 iDlId = 0;
       
   318 
       
   319                 break;
       
   320             }
       
   321             case EHttpDlMoved:
       
   322             case EHttpDlCreated:
       
   323             case EHttpContentTypeReceived:
       
   324             case EHttpDlMediaInserted:
       
   325             case EHttpDlPausable:
       
   326             case EHttpDlNonPausable:
       
   327             case EHttpDlAlreadyRunning:
       
   328             default:
       
   329                 break;
       
   330         };
       
   331 
       
   332         if ( prevDownloadState != iDownloadState )
       
   333         {
       
   334             //
       
   335             //  Signal the view that the download state has changed
       
   336             //
       
   337             iController->iMPXPluginObs->HandlePluginEvent(
       
   338                 MMPXPlaybackPluginObserver::EPDownloadStateChanged,
       
   339                 iDownloadState,
       
   340                 KErrNone );
       
   341         }
       
   342     }
       
   343     else
       
   344     {
       
   345         MPX_DEBUG(_L("CMPXVideoDlMgrIf::HandleDMgrEventL() Message for different Download"));
       
   346     }
       
   347 }
       
   348 
       
   349 void
       
   350 CMPXVideoDlMgrIf::DoUpdateDownloadProgress()
       
   351 {
       
   352     MPX_ENTER_EXIT(_L("CMPXVideoDlMgrIf::DoUpdateDownloadProgress()"));
       
   353 
       
   354     //
       
   355     //  Check if the current download is valid before updating
       
   356     //
       
   357     if ( iCurrentDl )
       
   358     {
       
   359         iCurrentDl->GetIntAttribute( EDlAttrDownloadedSize, iDownloadProgress );
       
   360 
       
   361         MPX_DEBUG(_L("   dlSize = %d, currentSize = %d"), iDlTotalSize, iDownloadProgress );
       
   362 
       
   363         //
       
   364         //  Update the size once the controller is initialized
       
   365         //
       
   366         if ( iController->iState->IsInitialized() )
       
   367         {
       
   368             iController->iMPXPluginObs->HandlePluginEvent(
       
   369                 MMPXPlaybackPluginObserver::EPDownloadPositionChanged,
       
   370                 iDownloadProgress,
       
   371                 KErrNone );
       
   372 
       
   373             //
       
   374             //  Update the playback engine with the current downloaded size
       
   375             //  Helix needs this to handle reading past current file size
       
   376             //
       
   377             HandleCustomCommand( EMMFROPControllerSetDownloadSize, iDownloadProgress );
       
   378         }
       
   379     }
       
   380 }
       
   381 
       
   382 void
       
   383 CMPXVideoDlMgrIf::DoHandleOpenComplete()
       
   384 {
       
   385     MPX_ENTER_EXIT(_L("CMPXVideoDlMgrIf::DoHandleOpenComplete()"));
       
   386 
       
   387     if ( iCurrentDl )
       
   388     {
       
   389         //
       
   390         //  Set the player opened flag so messages can be sent to the
       
   391         //  video playback engine
       
   392         //
       
   393         iPlayerOpened = ETrue;
       
   394 
       
   395         //
       
   396         //  Do not enable progressive download on the playback engine
       
   397         //  if the download isn't active
       
   398         //
       
   399         if ( iDownloadState == EPbDlStateDownloading || iDownloadState == EPbDlStateDownloadPaused )
       
   400         {
       
   401             //
       
   402             //  Send the download id to Helix to trigger progressive
       
   403             //  download mode for the Helix engine
       
   404             //
       
   405             TInt error = HandleCustomCommand( EMMFROPControllerSetDownloadID, iDlId );
       
   406 
       
   407             if ( error == KErrNone )
       
   408             {
       
   409                 iCurrentDl->GetIntAttribute( EDlAttrDownloadedSize, iDownloadProgress );
       
   410 
       
   411                 //
       
   412                 //  Update Helix with the current downloaded size
       
   413                 //  Helix needs this to handle reading past current file size
       
   414                 //
       
   415                 error = HandleCustomCommand( EMMFROPControllerSetDownloadSize, iDownloadProgress );
       
   416             }
       
   417 
       
   418             //
       
   419             //  Update download size for DRM protected clips
       
   420             //
       
   421             MPX_TRAPD( updateError, UpdateDownloadSizeL() );
       
   422         }
       
   423     }
       
   424 }
       
   425 
       
   426 void
       
   427 CMPXVideoDlMgrIf::CheckForMoveError()
       
   428 {
       
   429     MPX_ENTER_EXIT(_L("CMPXVideoDlMgrIf::CheckForMoveError()"));
       
   430 
       
   431     TInt32 errorId = KErrNone;
       
   432     TInt32 globalErrorId = KErrNone;
       
   433 
       
   434     iCurrentDl->GetIntAttribute( EDlAttrErrorId, errorId );
       
   435     iCurrentDl->GetIntAttribute( EDlAttrGlobalErrorId, globalErrorId );
       
   436 
       
   437     MPX_DEBUG(_L("    Moving complete - error = %d global error = %d"), errorId, globalErrorId );
       
   438 
       
   439     //
       
   440     //  Move Complete
       
   441     //
       
   442     iMoveNeeded = EFalse;
       
   443     iDownloadState = EPbDlStateNotDownloading;
       
   444 }
       
   445 
       
   446 TInt CMPXVideoDlMgrIf::HandleCustomCommand( TUint32 aCommand, TUint32 aCmdValue )
       
   447 {
       
   448     MPX_ENTER_EXIT(_L("CMPXVideoDlMgrIf::HandleCustomCommand()"),
       
   449                    _L(" aCommand = %d, aCmdValue = %d)"), aCommand, aCmdValue );
       
   450 
       
   451     TUint result = KErrNone;
       
   452 
       
   453     //
       
   454     //  Block custom commands for progressive download if the player has not been opened
       
   455     //
       
   456     if ( iPlayerOpened )
       
   457     {
       
   458         TPckgBuf<TUint> cmdValue( aCmdValue );
       
   459 
       
   460         const TMMFMessageDestinationPckg dest( KUidInterfaceMMFROPController );
       
   461         TPckgBuf<TMMFMessageDestination> message( dest );
       
   462 
       
   463         result = iController->iPlayer->CustomCommandSync( dest, aCommand, cmdValue, KNullDesC8 );
       
   464 
       
   465         MPX_DEBUG(_L("    Engine CustomCommand retCode = %d"), result);
       
   466     }
       
   467 
       
   468     return result;
       
   469 }
       
   470 
       
   471 void CMPXVideoDlMgrIf::HandleDownloadComplete()
       
   472 {
       
   473     MPX_ENTER_EXIT(_L("CMPXVideoDlMgrIf::HandleDownloadComplete()"));
       
   474 
       
   475     iDownloadState = EPbDlStateDownloadCompleted;
       
   476 
       
   477     //
       
   478     //  Since the download is complete, download should be moved
       
   479     //
       
   480     if ( iMovePdlFile )
       
   481     {
       
   482         iMoveNeeded = ETrue;
       
   483     }
       
   484     else
       
   485     {
       
   486         //
       
   487         //  Disconnect from the current download since move is not required
       
   488         //
       
   489         iCurrentDl = NULL;
       
   490         iDlId = 0;
       
   491     }
       
   492 
       
   493     //
       
   494     //  If the update CIdle object is active, cancel it since the download
       
   495     //  is complete and we are updating the values.
       
   496     //
       
   497     if ( iUpdateDownload->IsActive() )
       
   498     {
       
   499         iUpdateDownload->Cancel();
       
   500     }
       
   501 
       
   502     //
       
   503     //  Notify the player and the UI view that the download is complete
       
   504     //
       
   505     HandleCustomCommand( EMMFROPControllerSetDownloadComplete, ETrue );
       
   506 }
       
   507 
       
   508 // -------------------------------------------------------------------------------------------------
       
   509 //  CMPXVideoDlMgrIf::UpdateDownloadProgress
       
   510 // -------------------------------------------------------------------------------------------------
       
   511 //
       
   512 TInt CMPXVideoDlMgrIf::UpdateDownloadProgress( TAny* aPtr )
       
   513 {
       
   514     MPX_DEBUG(_L("CMPXVideoDlMgrIf::UpdateDownloadProgress()"));
       
   515 
       
   516     static_cast<CMPXVideoDlMgrIf*>(aPtr)->DoUpdateDownloadProgress();
       
   517 
       
   518     return KErrNone;
       
   519 }
       
   520 
       
   521 // -------------------------------------------------------------------------------------------------
       
   522 //  CMPXVideoDlMgrIf::GetPdlStatusL
       
   523 // -------------------------------------------------------------------------------------------------
       
   524 //
       
   525 void CMPXVideoDlMgrIf::GetPdlStatusL( CMPXCommand& aCmd )
       
   526 {
       
   527     MPX_DEBUG(_L("CMPXVideoDlMgrIf::GetPdlStatusL()"));
       
   528 
       
   529     if ( iCurrentDl )
       
   530     {
       
   531         iCurrentDl->GetIntAttribute( EDlAttrDownloadedSize, iDownloadProgress );
       
   532     }
       
   533 
       
   534     aCmd.SetTObjectValueL<TMPXPlaybackPdDownloadState>( KMPXCommandPlaybackPDState,
       
   535                                                         iDownloadState );
       
   536 
       
   537     //
       
   538     //  If download is complete, ensure that the size is 100%
       
   539     //
       
   540     if ( iDownloadState == EPbDlStateDownloadCompleted )
       
   541     {
       
   542         aCmd.SetTObjectValueL<TInt>( KMPXCommandPlaybackPDDownloadedBytes, iDlTotalSize );
       
   543     }
       
   544     else
       
   545     {
       
   546         aCmd.SetTObjectValueL<TInt>( KMPXCommandPlaybackPDDownloadedBytes, iDownloadProgress );
       
   547     }
       
   548 
       
   549     aCmd.SetTObjectValueL<TInt>( KMPXCommandPlaybackPDTotalBytes, iDlTotalSize );
       
   550 }
       
   551 
       
   552 // -------------------------------------------------------------------------------------------------
       
   553 //   CMPXVideoDlMgrIf::CalculateDestinationFileNameL()
       
   554 // -------------------------------------------------------------------------------------------------
       
   555 //
       
   556 void CMPXVideoDlMgrIf::CalculateDestinationFileNameL()
       
   557 {
       
   558     MPX_DEBUG(_L("CMPXVideoDlMgrIf::CalculateDestinationFileNameL()"));
       
   559 
       
   560     //
       
   561     //  We will try to move the file to the video path of the same
       
   562     //  drive where the download manager has saved it
       
   563     //
       
   564     TParsePtrC origFilePath( iClipName->Des() );
       
   565 
       
   566 #ifdef RD_MULTIPLE_DRIVE
       
   567     DriveInfo::TDriveArray driveArray;
       
   568     TInt drive = 0;
       
   569 
       
   570     RFs::CharToDrive( origFilePath.Drive()[0], drive );
       
   571 
       
   572     User::LeaveIfError( PathInfo::GetFullPath( iDestinationFileName, drive, PathInfo::EVideosPath ) );
       
   573 #else  //RD_MULTIPLE_DRIVE
       
   574     TParsePtrC phoneRoot( PathInfo::PhoneMemoryRootPath() );
       
   575     TParsePtrC mmcRoot( PathInfo::MemoryCardRootPath() );
       
   576 
       
   577     if ( origFilePath.Drive() == phoneRoot.Drive() )
       
   578     {
       
   579         iDestinationFileName = phoneRoot.DriveAndPath();
       
   580     }
       
   581     else
       
   582     {
       
   583         iDestinationFileName = mmcRoot.DriveAndPath();
       
   584     }
       
   585 
       
   586     iDestinationFileName += PathInfo::VideosPath();
       
   587 #endif  //RD_MULTIPLE_DRIVE
       
   588 
       
   589     iDestinationFileName += origFilePath.NameAndExt();
       
   590 }
       
   591 
       
   592 // -------------------------------------------------------------------------------------------------
       
   593 //   CMPXVideoDlMgrIf::HandleClose
       
   594 // -------------------------------------------------------------------------------------------------
       
   595 //
       
   596 void CMPXVideoDlMgrIf::HandleClose()
       
   597 {
       
   598     MPX_ENTER_EXIT(_L("CMPXVideoDlMgrIf::HandleClose()"));
       
   599 
       
   600     //
       
   601     //  Before we move any files, the controller in uninitialized.
       
   602     //  Set the player opened to false
       
   603     //
       
   604     iPlayerOpened  = EFalse;
       
   605 
       
   606     TInt errorCode = KErrNone;
       
   607 
       
   608     //
       
   609     //  Download may have already been moved.  Check for a current download.
       
   610     //
       
   611     if ( iCurrentDl )
       
   612     {
       
   613         //
       
   614         //  Check if the plugin should move the file and a move is needed
       
   615         //
       
   616         if ( iMoveNeeded )
       
   617         {
       
   618             MPX_TRAPD(err, CalculateDestinationFileNameL());
       
   619 
       
   620             if (err == KErrNone)
       
   621             {
       
   622                 errorCode =
       
   623                     iCurrentDl->SetStringAttribute( EDlAttrDestFilename, iDestinationFileName );
       
   624 
       
   625                 MPX_DEBUG(_L(
       
   626                     "CMPXVideoDlMgrIf::MoveDownloadedFile() SetStringAtt err = %d"), errorCode );
       
   627 
       
   628                 if ( errorCode == KErrNone )
       
   629                 {
       
   630                     errorCode = iCurrentDl->Move();
       
   631                 }
       
   632 
       
   633                 MPX_DEBUG(_L("CMPXVideoDlMgrIf::MoveDownloadedFile() Move err = %d"), errorCode );
       
   634             }
       
   635 
       
   636             MPX_DEBUG(_L("CMPXVideoDlMgrIf::MoveDownloadedFile() Calc Dest Filename err = %d"), err );
       
   637         }
       
   638         else
       
   639         {
       
   640             //
       
   641             //  Move has been called but we have not completed downloading
       
   642             //  the file.  We are going to clear the progressive download
       
   643             //  flag and the current download variable
       
   644             //
       
   645             errorCode = iCurrentDl->SetBoolAttribute( EDlAttrProgressive, EFalse );
       
   646             iCurrentDl = NULL;
       
   647 
       
   648             MPX_DEBUG(_L(
       
   649                 "CMPXVideoDlMgrIf::MoveDownloadedFile() Removing PD attr retCode=%d"), errorCode);
       
   650         }
       
   651     }
       
   652 }
       
   653 
       
   654 // -------------------------------------------------------------------------------------------------
       
   655 //   CMPXVideoDlMgrIf::GetDownloadRatio
       
   656 // -------------------------------------------------------------------------------------------------
       
   657 //
       
   658 TReal CMPXVideoDlMgrIf::GetDownloadRatio()
       
   659 {
       
   660     TReal downloadRatio = (TReal)iDownloadProgress / (TReal)iDlTotalSize;
       
   661     MPX_DEBUG(_L("CMPXVideoDlMgrIf::GetDownloadRatio(%f)"), downloadRatio);
       
   662 
       
   663     return downloadRatio;
       
   664 }
       
   665 
       
   666 // -------------------------------------------------------------------------------------------------
       
   667 //   CMPXVideoDlMgrIf::IsDownloadPaused
       
   668 // -------------------------------------------------------------------------------------------------
       
   669 //
       
   670 TBool CMPXVideoDlMgrIf::IsDownloadPaused()
       
   671 {
       
   672     TBool paused = ( iDownloadState == EPbDlStateDownloadPaused );
       
   673 
       
   674     MPX_DEBUG(_L("CMPXVideoDlMgrIf::GetDownloadRatio(%d)"), paused);
       
   675 
       
   676     return paused;
       
   677 }
       
   678 
       
   679 // -------------------------------------------------------------------------------------------------
       
   680 //   CMPXVideoDlMgrIf::ConvertDMgrStatetoMpxState
       
   681 // -------------------------------------------------------------------------------------------------
       
   682 //
       
   683 void CMPXVideoDlMgrIf::ConvertDMgrStatetoMpxState( TInt32 aDMgrState )
       
   684 {
       
   685     MPX_DEBUG(_L("CMPXVideoDlMgrIf::ConvertDMgrStatetoMpxState(%d)"), aDMgrState);
       
   686 
       
   687     switch ( aDMgrState )
       
   688     {
       
   689         case EHttpDlInprogress:
       
   690         case EHttpDlCreated:
       
   691         {
       
   692             iDownloadState = EPbDlStateDownloading;
       
   693             break;
       
   694         }
       
   695         case EHttpDlPaused:
       
   696         case EHttpDlNonPausableNetworkLoss:
       
   697         {
       
   698             iDownloadState = EPbDlStateDownloadPaused;
       
   699             break;
       
   700         }
       
   701         case EHttpDlCompleted:
       
   702         {
       
   703             iDownloadState = EPbDlStateDownloadCompleted;
       
   704             break;
       
   705         }
       
   706         case EHttpDlFailed:
       
   707         {
       
   708             iDownloadState = EPbDlStateDownloadError;
       
   709             break;
       
   710         }
       
   711         case EHttpDlDeleted:
       
   712         case EHttpDlDeleting:
       
   713         {
       
   714             iDownloadState = EPbDlStateDownloadCanceled;
       
   715             break;
       
   716         }
       
   717         case EHttpDlMoved:
       
   718         case EHttpDlMediaRemoved:
       
   719         case EHttpDlMediaInserted:
       
   720         case EHttpDlPausable:
       
   721         case EHttpDlNonPausable:
       
   722         case EHttpDlAlreadyRunning:
       
   723         case EHttpDlCancelTransaction:
       
   724         default:
       
   725         {
       
   726             iDownloadState = EPbDlStateNotDownloading;
       
   727             break;
       
   728         }
       
   729     }
       
   730 }
       
   731 
       
   732 // -------------------------------------------------------------------------------------------------
       
   733 //   CMPXVideoDlMgrIf::UpdateDownloadSizeL
       
   734 // -------------------------------------------------------------------------------------------------
       
   735 //
       
   736 void CMPXVideoDlMgrIf::UpdateDownloadSizeL()
       
   737 {
       
   738     MPX_ENTER_EXIT(_L("CMPXVideoDlMgrIf::UpdateDownloadSizeL()"));
       
   739 
       
   740     if ( iController->iDrmHelper->IsProtected( iController->iFileHandle ) )
       
   741     {
       
   742         MPX_DEBUG(_L("CMPXVideoDlMgrIf::UpdateDownloadSizeL() download is DRM protected"));
       
   743 
       
   744         ContentAccess::CContent* content =
       
   745             ContentAccess::CContent::NewLC( iController->iFileHandle );
       
   746 
       
   747         ContentAccess::CData* data = content->OpenContentL( ContentAccess::EPeek );
       
   748 
       
   749         CleanupStack::PushL( data );
       
   750 
       
   751         TInt drmSize;
       
   752         data->DataSizeL( drmSize );
       
   753 
       
   754         MPX_DEBUG(_L("CMPXVideoDlMgrIf::UpdateDownloadSizeL()    DlMgr Size = %d, DRM Size = %d"),
       
   755             iDlTotalSize, drmSize );
       
   756 
       
   757         iDlTotalSize = drmSize;
       
   758 
       
   759         CleanupStack::PopAndDestroy( 2 );  // data & content
       
   760     }
       
   761 }
       
   762 
       
   763 //  EOF