mmfenh/enhancedmediaclient/Plugins/ProgDLSource/src/ProgDLSource.cpp
branchRCL_3
changeset 20 0ac9a5310753
equal deleted inserted replaced
19:095bea5f582e 20:0ac9a5310753
       
     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 ProgDLSource.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <f32file.h>
       
    20 #include <e32std.h>
       
    21 #include <mmfdatabuffer.h>
       
    22 #include <mmfutilities.h>
       
    23 #include <mmf/common/mmfcontroller.h>
       
    24 #include <mmfpaniccodes.h>
       
    25 #include "ProgDLDataSource.h"
       
    26 #include "ProgDLMultimediaSource.h"
       
    27 #include "MmffilePriv.h"
       
    28 #include "FileAccess.h"
       
    29 #include "SinkQueueItem.h"
       
    30 #include "ProgDLSourceCustomCommands.h"
       
    31 #include <MultimediaDataSourceEvents.h>
       
    32 #include "ProgDLSourceUid.h"
       
    33 #include "AudioConfigurationPrivateCRKeys.h"
       
    34 
       
    35 #ifdef _DEBUG
       
    36 #define DEBPRN1(str)        RDebug::Print(str);
       
    37 #define DEBPRN2(str, val1)   RDebug::Print(str, val1);
       
    38 #define DEBPRN3(str, val1, val2)   RDebug::Print(str, val1, val2);
       
    39 #define DEBPRN4(str, val1, val2, val3)   RDebug::Print(str, val1, val2, val3);
       
    40 #define DEBPRN5(str, val1, val2, val3, val4)   RDebug::Print(str, val1, val2, val3, val4);
       
    41 #else
       
    42 #define DEBPRN1(str)
       
    43 #define DEBPRN2(str, val1)
       
    44 #define DEBPRN3(str, val1, val2)
       
    45 #define DEBPRN4(str, val1, val2, val3)
       
    46 #define DEBPRN5(str, val1, val2, val3, val4)
       
    47 #endif // _DEBUG
       
    48 
       
    49 const TUint KMinPlaybackDuration = 15; // 15 second
       
    50 
       
    51 void Panic(TMMFFilePanicCode aPanicCode)
       
    52     {
       
    53     _LIT(KMMFFilePanicCategory, "MMFFile");
       
    54     User::Panic(KMMFFilePanicCategory, aPanicCode);
       
    55     }
       
    56 
       
    57     /**
       
    58     * Constructs a CTransferBufferCopy
       
    59     *
       
    60     * @return CTransferBufferCopy*
       
    61 */
       
    62 CTransferBufferCopy* CTransferBufferCopy::NewL(TInt aMaxLength)
       
    63     {
       
    64     CTransferBufferCopy* self = new (ELeave) CTransferBufferCopy(aMaxLength);
       
    65     CleanupStack::PushL(self);
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop(self);
       
    68     return self;
       
    69     }
       
    70 
       
    71     /**
       
    72     * Second phase constructor for CTransferBufferCopy
       
    73     *
       
    74     * @return void
       
    75 */
       
    76 void CTransferBufferCopy::ConstructL()
       
    77     {
       
    78     iBuffer = static_cast<TUint8*>(User::AllocL(iMaxLength));
       
    79     iBufferDes.Set(iBuffer,0,iMaxLength);
       
    80     }
       
    81 
       
    82 /************************/
       
    83 CProgDLSource* CProgDLSource::NewL(TUid aType )
       
    84     {
       
    85     DEBPRN1(_L("CProgDLSource::NewL"));
       
    86     CProgDLSource* self = new (ELeave) CProgDLSource(aType);
       
    87     CleanupStack::PushL(self);
       
    88     self->ConstructL();
       
    89     CleanupStack::Pop(self);
       
    90     return self;
       
    91     }
       
    92 
       
    93 CProgDLSource::CProgDLSource(TUid aType)
       
    94 : MDataSource(aType)
       
    95     {
       
    96     iInitData = NULL;
       
    97     }
       
    98 
       
    99 CProgDLSource::~CProgDLSource(void)
       
   100     {
       
   101     delete iInitData;
       
   102     iInitData = NULL;        
       
   103     }
       
   104 
       
   105 void CProgDLSource::ConstructL (void)
       
   106     {
       
   107     }
       
   108 
       
   109 // From MDataSource begins
       
   110 TUid CProgDLSource::DataSourceType() const
       
   111     {
       
   112     return KMmfProgDLSource;
       
   113     }
       
   114 
       
   115 
       
   116 TFourCC CProgDLSource::SourceDataTypeCode(TMediaId /*aMediaId*/ )
       
   117     {
       
   118     TFourCC fourCC;        
       
   119     return iMultiMediaSource->GetDataTypeCode(fourCC);
       
   120     }
       
   121 
       
   122 TInt CProgDLSource::SetSourceDataTypeCode(TFourCC aSourceFourCC,
       
   123                                                   TMediaId /*aMediaId*/ )
       
   124     {
       
   125     iMultiMediaSource->SetDataTypeCode(aSourceFourCC);
       
   126     return KErrNone;
       
   127     }
       
   128 
       
   129 void CProgDLSource::FillBufferL(CMMFBuffer* aBuffer,
       
   130                                         MDataSink* aConsumer,
       
   131                                         TMediaId aMediaId )
       
   132     {
       
   133     iMultiMediaSource->FillBufferL(aBuffer,aConsumer,aMediaId);
       
   134     }
       
   135 
       
   136 void CProgDLSource::BufferEmptiedL(CMMFBuffer* /*aBuffer*/ )
       
   137     {
       
   138     User::Leave(KErrUnknown);
       
   139     }
       
   140 
       
   141 TBool CProgDLSource::CanCreateSourceBuffer()
       
   142     {
       
   143     return EFalse;
       
   144     }
       
   145 
       
   146 CMMFBuffer* CProgDLSource::CreateSourceBufferL(TMediaId /*aMediaId*/,
       
   147                                                        TBool &/*aReference*/ )
       
   148     {
       
   149     return NULL;
       
   150     }
       
   151 
       
   152 TInt CProgDLSource::SourceThreadLogon( MAsyncEventHandler& /*aEventHandler*/ )
       
   153     {
       
   154     return iMultiMediaSource->Open();
       
   155     }
       
   156 
       
   157 void CProgDLSource::SourceThreadLogoff()
       
   158     {
       
   159     iMultiMediaSource->Close();
       
   160     }
       
   161 
       
   162 void CProgDLSource::SourcePrimeL()
       
   163     {
       
   164     DEBPRN1(_L("CProgDLSource::SourcePrimeL"));
       
   165     User::LeaveIfError(iMultiMediaSource->Prime());
       
   166     }
       
   167 
       
   168 void CProgDLSource::SourcePlayL()
       
   169     {
       
   170     DEBPRN1(_L("CProgDLSource::SourcePlayL"));
       
   171     User::LeaveIfError(iMultiMediaSource->Play());
       
   172     }
       
   173 
       
   174 void CProgDLSource::SourceStopL()
       
   175     {
       
   176     DEBPRN1(_L("CProgDLSource::SourceStopL"));
       
   177     User::LeaveIfError(iMultiMediaSource->Stop());
       
   178     }
       
   179 
       
   180 
       
   181 void CProgDLSource::ConstructSourceL(const TDesC8& aInitData )
       
   182     {
       
   183     if(iInitData)
       
   184         {
       
   185         delete iInitData;
       
   186         iInitData = NULL;        
       
   187         }
       
   188     iInitData = aInitData.AllocL();        
       
   189     }
       
   190 
       
   191 void CProgDLSource::SourceCustomCommand(TMMFMessage& aMessage)
       
   192     {
       
   193     iMultiMediaSource->SourceCustomCommand(aMessage);        
       
   194     }
       
   195 
       
   196 void CProgDLSource::SetMultimediaSource(CProgDLMultimediaSource& aMultimediaSource)
       
   197     {
       
   198     iMultiMediaSource = &aMultimediaSource;   
       
   199     }
       
   200 
       
   201 TDesC8& CProgDLSource::GetInitData()
       
   202     {
       
   203     return *iInitData;    
       
   204     }
       
   205 /****************************/
       
   206 
       
   207 
       
   208 EXPORT_C CProgDLMultimediaSource* CProgDLMultimediaSource::NewL(MDataSource& aDataSource)
       
   209     {
       
   210     DEBPRN1(_L("CProgDLMultimediaSource::NewL"));
       
   211     CProgDLMultimediaSource* self = new (ELeave) CProgDLMultimediaSource(aDataSource);
       
   212     CleanupStack::PushL(self);
       
   213     self->ConstructL();
       
   214     CleanupStack::Pop(self);
       
   215     return self;
       
   216     }
       
   217 
       
   218     /**
       
   219     Destructor.
       
   220 */
       
   221 CProgDLMultimediaSource::~CProgDLMultimediaSource() 
       
   222     {
       
   223     DEBPRN1(_L("CProgDLMultimediaSource::~CProgDLMultimediaSource() "));    
       
   224     delete iInitData;
       
   225     delete iFile;
       
   226     EmptySinkQueue();
       
   227     iHandle.Close();
       
   228     iFsSession.Close();
       
   229     delete iFileName;
       
   230     delete iFileExt;
       
   231     delete iFilePath;
       
   232     delete iFileDrive;
       
   233     
       
   234     
       
   235     delete iCAFParameters;
       
   236     delete iSinkQueue;
       
   237     delete iAudioConfigRepository;
       
   238     
       
   239     if(iMessage)
       
   240         {
       
   241         if(!iMessage->IsCompleted())
       
   242             {
       
   243             iMessage->Complete(KErrDied);
       
   244             delete iMessage;
       
   245             iMessage = NULL;
       
   246             }
       
   247         }
       
   248     // Get rid of everything in RArray's & close them.
       
   249     iRequests.ResetAndDestroy();
       
   250     iTransferBufferCopies.ResetAndDestroy();
       
   251     DEBPRN1(_L("CProgDLMultimediaSource::~CProgDLMultimediaSource() exit"));   
       
   252     }
       
   253 
       
   254     /**
       
   255     Protected constructor.
       
   256     
       
   257       The default implementation is empty.
       
   258 */
       
   259 CProgDLMultimediaSource::CProgDLMultimediaSource(MDataSource& aDataSource)
       
   260                                        : iSnkItemsCount(0),
       
   261                                        iSnkBytes(0),
       
   262                                        iDownloadSize(0),
       
   263                                        iTransferRate(0),
       
   264                                        //iConsumer(NULL),
       
   265                                        iBufferedDataSize(0),
       
   266                                        iDLFileSize(0),
       
   267                                        isDownloadComplete(EFalse),
       
   268                                        iFileSize(0),
       
   269                                        iParentDataSource(&aDataSource)
       
   270     {
       
   271     iMessage = NULL;
       
   272     iFile = NULL;
       
   273     iState = ECLOSED;
       
   274     iObserver = NULL;
       
   275     iReadRequestPending = 0;
       
   276     iReOpenCAF = EFalse;
       
   277     iObserverBitRate = 0;
       
   278     }
       
   279 
       
   280     /**
       
   281     Constructs an CProgDLMultimediaSource MDataSource.
       
   282     
       
   283       @return A pointer to the new CProgDLMultimediaSource data source.
       
   284 */
       
   285 /*MDataSource* CProgDLMultimediaSource::NewSourceL() 
       
   286 {
       
   287 CProgDLMultimediaSource* self = new (ELeave) CProgDLMultimediaSource( KMmfProgDLSource ) ;
       
   288 return STATIC_CAST( MDataSource*, self ) ;
       
   289     }*/
       
   290 
       
   291 
       
   292     /**
       
   293     Perform source construction dependant on the source construction
       
   294     initialisation data aInitData.
       
   295     
       
   296       @param  aInitData
       
   297       The TPckg<TMMFFileParams> descriptor package containing the file name and full path.
       
   298 */
       
   299 void CProgDLMultimediaSource::ConstructL() 
       
   300     {
       
   301     CProgDLSource* progDLSource = static_cast<CProgDLSource*>(iParentDataSource);    
       
   302     iInitData = (progDLSource->GetInitData()).AllocL();
       
   303     progDLSource->SetMultimediaSource(*this);
       
   304     ConstructL(*iInitData, ESourceMode);
       
   305     iSinkQueue = new(ELeave) TSglQue<CSinkQueueItem>(_FOFF(CSinkQueueItem, iLink));
       
   306     }
       
   307 
       
   308 
       
   309     /**
       
   310     Protected constructor.
       
   311     
       
   312       Extracts the initialisation data provided by the calling functions: ConstructSourceL() and 
       
   313       ConstructSinkL(). Creates a file server session and sets up file name. If there is a file name and 
       
   314       it cannot be found this function leaves. If there is no file name the function leaves. Does not 
       
   315       attempt to open the file or check whether the file exists.
       
   316       
       
   317         If aInitData contains a TMMFFileHandleParams instead of TMMFFileParams, the source/sink is constructed from 
       
   318         the file handle provided by the caller
       
   319         
       
   320           @param  aInitData
       
   321           Initialisation data packaged in a TMMFFileParams or in a TMMFFileHandleParams (File Handle)
       
   322 */
       
   323 void CProgDLMultimediaSource::ConstructL(const TDesC8& aInitData,TMMFileMode aFileMode)
       
   324     {
       
   325     User::LeaveIfError(iFsSession.Connect());
       
   326     // on IPCv2 we auto attach
       
   327     User::LeaveIfError(iFsSession.ShareAuto());
       
   328     
       
   329     User::LeaveIfError(iFsSession.ShareProtected());
       
   330     
       
   331     TBool fileInit = EFalse;
       
   332     HBufC* filename = NULL; 
       
   333     TBool filenamePushed = EFalse;
       
   334     
       
   335     iCAFParameters = new (ELeave) CCAFParameters;
       
   336     TBool drmContent = EFalse;
       
   337     RDesReadStream stream(aInitData);
       
   338     CleanupClosePushL(stream);
       
   339 
       
   340     iAudioConfigRepository = CRepository::NewL(KCRUidAudioConfiguration);
       
   341 
       
   342     // From Central Repository
       
   343     GetAudioConfiguration();
       
   344     
       
   345     TUid initUid;
       
   346     
       
   347     initUid = TUid::Uid(stream.ReadInt32L());
       
   348     
       
   349     if (initUid == KMMFileHandleSourceUid)
       
   350         {
       
   351         TPckgBuf<RFile*> fileptr;
       
   352         stream.ReadL(fileptr);
       
   353         
       
   354         iHandle.Duplicate(*fileptr());
       
   355         
       
   356         TInt length;
       
   357         length = stream.ReadInt32L();
       
   358         if (length>0)
       
   359             {
       
   360             iCAFParameters->iUniqueId = HBufC::NewL(length);
       
   361             TPtr16 ptr = iCAFParameters->iUniqueId->Des();
       
   362             stream.ReadL(ptr, length);
       
   363             }
       
   364         iFileHandle = ETrue;
       
   365         filename = HBufC::NewMaxL(KMaxFileName);
       
   366         TPtr ptr = filename->Des();
       
   367         iHandle.Name(ptr);
       
   368         fileInit = ETrue;
       
   369         drmContent = ETrue;
       
   370         
       
   371         iCAFParameters->iEnableUI = stream.ReadInt32L();
       
   372         }
       
   373     
       
   374     else if (initUid == KMMFileSourceUid)
       
   375         {
       
   376         TInt length;
       
   377         length = stream.ReadInt32L();
       
   378         filename = HBufC::NewMaxLC(length);
       
   379         TPtr ptr = filename->Des();
       
   380         stream.ReadL(ptr, length);
       
   381         
       
   382         length = stream.ReadInt32L();
       
   383         if (length>0)
       
   384             {
       
   385             iCAFParameters->iUniqueId = HBufC::NewMaxL(length);
       
   386             ptr.Set(iCAFParameters->iUniqueId->Des());
       
   387             stream.ReadL(ptr, length);
       
   388             }
       
   389         CleanupStack::Pop(filename);
       
   390         
       
   391         fileInit = ETrue;
       
   392         drmContent = ETrue;
       
   393         iFileHandle = EFalse; 
       
   394         iCAFParameters->iEnableUI = stream.ReadInt32L();
       
   395         }
       
   396     else
       
   397         {
       
   398         //		TODO If the UID is unknown we should reject, but  currently
       
   399         //		code also used for older calls that just supply filename.
       
   400         //		User::Leave(KErrNotSupported);
       
   401         }
       
   402     
       
   403     CleanupStack::PopAndDestroy(&stream);
       
   404     
       
   405     if (!fileInit && aInitData.Length() == sizeof(TMMFFileHandleParams))
       
   406         {
       
   407         TMMFFileHandleParams params;
       
   408         TPckgC<TMMFFileHandleParams> config(params);
       
   409         config.Set(aInitData);
       
   410         params = config();
       
   411         
       
   412         
       
   413         if (params.iUid == KFileHandleUid)
       
   414             {
       
   415             fileInit = ETrue;
       
   416             User::LeaveIfError(iHandle.Duplicate(*params.iFile));
       
   417             TInt pos = 0;
       
   418             // make sure the duplicate handle is at the start of the file - the usage of the file handle really requires this
       
   419             User::LeaveIfError(iHandle.Seek(ESeekStart, pos));
       
   420             iFileHandle = ETrue;
       
   421             filename = HBufC::NewMaxLC(KMaxFileName);
       
   422             filenamePushed = ETrue;
       
   423             TPtr ptr = filename->Des();
       
   424             User::LeaveIfError(iHandle.Name(ptr));
       
   425             }
       
   426         }
       
   427     
       
   428     if (!fileInit) // do old case as last resort
       
   429         {
       
   430         TMMFFileParams params;
       
   431         TPckgC<TMMFFileParams> config(params);
       
   432         config.Set(aInitData);
       
   433         params = config();
       
   434         
       
   435         filename = params.iPath.AllocL();
       
   436         fileInit = ETrue;
       
   437         }
       
   438     
       
   439     if (!filenamePushed)
       
   440         {
       
   441         // from now on it is assumed pushed.
       
   442         CleanupStack::PushL(filename);
       
   443         }
       
   444     
       
   445     TParse parser ;
       
   446     User::LeaveIfError(parser.Set(*filename, NULL, NULL));
       
   447     CleanupStack::PopAndDestroy(filename);
       
   448     if ( !( parser.NamePresent() ) && !( parser.ExtPresent() ) )
       
   449         User::Leave( KErrBadName ) ;
       
   450     
       
   451     iFullFileName.Copy( parser.FullName() ) ;	
       
   452     iFileName = parser.Name().AllocL() ;
       
   453     iFileExt = parser.Ext().AllocL() ;
       
   454     iFilePath = parser.Path().AllocL() ;
       
   455     iFileDrive = parser.Drive().AllocL() ;
       
   456     
       
   457     // in order to simulate old behaviour we are not passing error out
       
   458     // but will try to create Content again during PrimeL()
       
   459     if (fileInit && drmContent && aFileMode==ESourceMode)
       
   460         {
       
   461         TInt contentError;
       
   462         if (iFileHandle)
       
   463             {
       
   464             TRAP(contentError, 
       
   465                 iFile = CContentFile::NewL(iHandle, UniqueId(), iCAFParameters->iEnableUI);
       
   466             );
       
   467             }
       
   468         else
       
   469             {
       
   470             // Open for read-only access
       
   471             TRAP(contentError,
       
   472                 iFile = CContentFile::NewL(iFsSession, iFullFileName, UniqueId(), EFileShareAny, iCAFParameters->iEnableUI);
       
   473             );
       
   474             }
       
   475         }
       
   476     }
       
   477     
       
   478     
       
   479 /**
       
   480 @deprecated
       
   481 
       
   482 Returns an RFile handle to the current file.
       
   483 
       
   484 If there is no current file, one is created. If the file exists then it is opened with read access 
       
   485 if it is read only, write access otherwise. If the file does not exist then it is opened with
       
   486 write access.
       
   487 
       
   488 @leave KErrNotReady
       
   489 The file is not open.
       
   490 
       
   491 @return A handle to the current file.
       
   492 */
       
   493 RFile& CProgDLMultimediaSource::FileL()
       
   494     {
       
   495     if (!iFile)
       
   496         User::Leave(KErrNotReady);
       
   497     if (iFileHandle)
       
   498         return iHandle;
       
   499     else
       
   500         return iFile->FileL();
       
   501     }
       
   502             
       
   503 /** 
       
   504 Returns the file name of the current file.
       
   505 
       
   506   Note: This will give the wrong answer if the file is renamed!
       
   507   
       
   508     @return The FileName (without extension).
       
   509 */
       
   510 const TDesC& CProgDLMultimediaSource::FileName() const
       
   511     {
       
   512     return *iFileName ;
       
   513     }
       
   514             
       
   515 /**
       
   516 Returns the extension of the current file.
       
   517 
       
   518 Note: This will give the wrong answer if the file is renamed!
       
   519 
       
   520 @return The File Extension.
       
   521 */
       
   522 const TDesC& CProgDLMultimediaSource::Extension() const 
       
   523     {
       
   524     return *iFileExt ;
       
   525     }
       
   526             
       
   527 /** 
       
   528 Returns the path of the current file.
       
   529 
       
   530 Note: This will give the wrong answer if the file is renamed!
       
   531 
       
   532 @return The FilePath (without filename and extension)
       
   533 */
       
   534 const TDesC& CProgDLMultimediaSource::FilePath() const 
       
   535     {
       
   536     return *iFilePath ;
       
   537     }
       
   538 
       
   539 /** 
       
   540 Returns the drive on which the current file is located.
       
   541 
       
   542 Note: This will give the wrong answer if the file is renamed!
       
   543 
       
   544 @return The FileDrive (drive letter only, without path, filename and extension).
       
   545 */
       
   546 const TDesC& CProgDLMultimediaSource::FileDrive() const 
       
   547     {
       
   548     return *iFileDrive ;
       
   549     }
       
   550 
       
   551 /** 
       
   552 Returns the full name of the current file.
       
   553 
       
   554 Note: This will give the wrong answer if the file is renamed!
       
   555 
       
   556 @return The file name (full filename including drive letter, without path, filename and extension).
       
   557 */
       
   558 const TFileName CProgDLMultimediaSource::FullName() const
       
   559     {
       
   560     return iFullFileName;
       
   561     }
       
   562             
       
   563 /** 
       
   564 Returns the uniqueID associated with this content. If no uniqueID has been provided, a null
       
   565 descriptor will be provided
       
   566 
       
   567 @return The UniqueID
       
   568 */
       
   569 const TDesC& CProgDLMultimediaSource::UniqueId() const
       
   570     {
       
   571     if (iCAFParameters->iUniqueId)
       
   572         return *(iCAFParameters->iUniqueId);
       
   573     else
       
   574         return KNullDesC;
       
   575     }
       
   576             
       
   577 /**
       
   578 Obtains a CTransferBufferCopy from iTransferBufferCopies that is
       
   579 at least as big as that required.
       
   580 
       
   581 There is no need to put the pointer returned by this method onto the CleanupStack
       
   582 as it will have already been placed into iTransferBufferCopies.
       
   583 
       
   584 @param  aMaxLength
       
   585 The size required.
       
   586 
       
   587 @return A pointer to a valid CTransferBufferCopy.
       
   588 */
       
   589 CTransferBufferCopy* CProgDLMultimediaSource::ObtainCopyOfTransferBufferL(TInt aMaxLength)
       
   590     {
       
   591     //find a free transfer buffer copy of the right size
       
   592     TInt firstFree = -1;
       
   593     CTransferBufferCopy* transBufCopyToUse = NULL;
       
   594     
       
   595     for(TInt cnt=0; cnt < iTransferBufferCopies.Count(); cnt++)
       
   596         {
       
   597         if(!iTransferBufferCopies[cnt]->InUse())
       
   598             {
       
   599             //record the first free entry, we may remove this
       
   600             //if entries in iTransferBufferCopies > KAcceptableTransferBufferCopiesSize
       
   601             if(firstFree == -1) 
       
   602                 firstFree = cnt;
       
   603             
       
   604             if(iTransferBufferCopies[cnt]->MaxLength() >= aMaxLength)
       
   605                 {
       
   606                 transBufCopyToUse = iTransferBufferCopies[cnt];
       
   607                 
       
   608                 //Set the MaxLength. This will ensure that the copy acts the same as
       
   609                 //the original Transfer buffer, eg. file server will throw KErrOverflow
       
   610                 transBufCopyToUse->ReUse(aMaxLength);
       
   611                 break;
       
   612                 }
       
   613             }
       
   614         }
       
   615     
       
   616     //If we failed to find a suitable entry, we need to create a new one
       
   617     if(!transBufCopyToUse)
       
   618         {
       
   619         //Firstly, should we re-cycle an existing entry?
       
   620         //There must be entries in the array, a free entry must have been found,
       
   621         //the size of the array must be beyond the water mark where we want to start
       
   622         //cycling free entries.
       
   623         if((iTransferBufferCopies.Count() > 0) &&
       
   624             (firstFree != -1) &&
       
   625             (iTransferBufferCopies.Count() > KAcceptableTransferBufferCopiesSize))
       
   626             {
       
   627             delete iTransferBufferCopies[firstFree];
       
   628             iTransferBufferCopies.Remove(firstFree);
       
   629             
       
   630             transBufCopyToUse = CTransferBufferCopy::NewL(aMaxLength);
       
   631             CleanupStack::PushL(transBufCopyToUse);
       
   632             User::LeaveIfError(iTransferBufferCopies.Insert(transBufCopyToUse,firstFree));
       
   633             
       
   634             CleanupStack::Pop();
       
   635             }
       
   636         else
       
   637             {
       
   638     #ifdef _DEBUG
       
   639             if(iTransferBufferCopies.Count() > KMaximumTransferBufferCopiesSize)
       
   640                 {
       
   641                 User::Panic(_L("iTransferBufferCopies grew too large in CProgDLMultimediaSource"),KErrTooBig);
       
   642                 }
       
   643     #endif
       
   644             
       
   645             transBufCopyToUse = CTransferBufferCopy::NewL(aMaxLength);
       
   646             CleanupStack::PushL(transBufCopyToUse);
       
   647             User::LeaveIfError(iTransferBufferCopies.Append(transBufCopyToUse));
       
   648             
       
   649             CleanupStack::Pop();
       
   650             }
       
   651         }
       
   652     
       
   653     return transBufCopyToUse;
       
   654     }
       
   655             
       
   656             
       
   657             
       
   658 /** 
       
   659 Loads aBuffer from iFile.
       
   660 
       
   661 The file must already be open for reading. File read is asynchronous. CReadRequest is created to 
       
   662 respond to completion.
       
   663 
       
   664 @param  aBuffer
       
   665 The buffer to be filled from the file.
       
   666 @param  aConsumer
       
   667 The data sink consumer of the buffer.
       
   668 */
       
   669 void CProgDLMultimediaSource::FillBufferL( CMMFBuffer* aBuffer, MDataSink* aConsumer, TMediaId /*aMediaId*/ )
       
   670     {
       
   671     // Requires that iFile is open for read.
       
   672     // Reads data from iFile into aBuffer
       
   673     TInt status(KErrNone);
       
   674     DEBPRN2(_L("CProgDLMultimediaSource::FillBuffer[%x]]"), aBuffer );
       
   675     if ((!aConsumer) || (!aBuffer))
       
   676         User::Leave(KErrArgument);
       
   677     
       
   678     if (!iFile)
       
   679         User::Leave(KErrNotReady);
       
   680     
       
   681     AppendBufferToSinkQueue(aBuffer,NULL,aConsumer,EFalse);
       
   682     DEBPRN4(_L("CProgDLMultimediaSource::FillBuffer DLComplete[%d] ReOpenCAF[%d] RequestPending[%d]"), isDownloadComplete,iReOpenCAF,iReadRequestPending );
       
   683     if(isDownloadComplete && !iReOpenCAF) 
       
   684         {
       
   685         if(!iReadRequestPending)
       
   686             {
       
   687             ReOpenCAF();
       
   688             status = ServiceFillBuffer();
       
   689             if(status == KErrUnderflow)
       
   690                 {
       
   691                 StateChanged(EBUFFERING);
       
   692                 }
       
   693             }
       
   694         }
       
   695     else
       
   696         {
       
   697         status = ServiceFillBuffer();
       
   698         
       
   699         if(status == KErrUnderflow)
       
   700             {
       
   701             StateChanged(EBUFFERING);
       
   702             }
       
   703         }        
       
   704     }
       
   705             
       
   706 /**
       
   707 Stores a request in an array.
       
   708 
       
   709 CReadWriteRequests are stored in the array iRequests.
       
   710 This function takes ownership and places the request in the array.
       
   711 It also checks the array for completed requests and removes them.
       
   712 
       
   713 @param  aRequest
       
   714 The request to store.
       
   715 */
       
   716 void CProgDLMultimediaSource::StoreRequestL( CReadWriteRequest* aRequest )
       
   717     {
       
   718     // add aRequest to iRequests
       
   719     User::LeaveIfError( iRequests.Append( aRequest ) ) ;
       
   720     
       
   721     // Clear out any completed requests
       
   722     for ( TInt ii = 0 ; ii < iRequests.Count() ; ii++ )
       
   723         {
       
   724         if (iRequests[ii]->Completed())
       
   725             {
       
   726             CReadWriteRequest* request = iRequests[ii];
       
   727             delete request;
       
   728             
       
   729             iRequests.Remove(ii);
       
   730             ii--;
       
   731             }
       
   732         }
       
   733     }
       
   734 
       
   735 
       
   736 /**
       
   737 Cancels outstanding requests.
       
   738 
       
   739 CReadWriteRequests are stored in the array iRequests.
       
   740 This function cancels any outstanding requests and removes them
       
   741 from iRequests.
       
   742 */
       
   743 void CProgDLMultimediaSource::CancelRequests()
       
   744     {
       
   745     // Clear out any completed requests
       
   746     for ( TInt ii = 0 ; ii < iRequests.Count() ; ii++ )
       
   747         {
       
   748         CReadWriteRequest* request = iRequests[ii];
       
   749         if(!request->Processing())
       
   750             {
       
   751             delete request;
       
   752             iRequests.Remove(ii);
       
   753             ii--;
       
   754             }
       
   755         }
       
   756     }
       
   757 
       
   758             
       
   759 /**
       
   760 Evaluates a given intent against the rights associated with the file.
       
   761 
       
   762 The rights are not updated by this function call.
       
   763 
       
   764 @param  aIntent
       
   765 The intent to evaluate.
       
   766 
       
   767   @return An error code indicating if the function call was successful. KErrNone on success, otherwise
       
   768   another of the system-wide error codes.
       
   769 */
       
   770 TInt CProgDLMultimediaSource::EvaluateIntent(ContentAccess::TIntent aIntent)
       
   771     {
       
   772     if (!iFile)
       
   773         {
       
   774         return KErrNotReady;
       
   775         }
       
   776     
       
   777     return iFile->EvaluateIntent(aIntent);
       
   778     }
       
   779             
       
   780 /**
       
   781 Evaluates and executes a given intent against the rights associated with the file.
       
   782 
       
   783 The rights object is updated after calling this function.
       
   784 
       
   785 @param  aIntent
       
   786 The intent to evaluate.
       
   787 
       
   788 @return An error code indicating if the function call was successful. KErrNone on success, otherwise
       
   789 another of the system-wide error codes.
       
   790 */
       
   791 TInt CProgDLMultimediaSource::ExecuteIntent(ContentAccess::TIntent aIntent)
       
   792     {
       
   793     if (!iFile)
       
   794         {
       
   795         return KErrNotReady;
       
   796         }
       
   797     
       
   798     return iFile->ExecuteIntent(aIntent);
       
   799     }
       
   800             
       
   801 /**
       
   802 Returns whether the file is protected.
       
   803 
       
   804 @return A boolean indicating if the file is protected. ETrue if the file is protected.
       
   805 */
       
   806 TInt CProgDLMultimediaSource::GetDRMProtection(TBool& aIsProtected)
       
   807     {
       
   808     TInt err(KErrNone);	
       
   809     if (!iFile)
       
   810         {
       
   811         return KErrNotReady;
       
   812         }
       
   813     
       
   814     TRAP(err,aIsProtected = iFile->IsProtected());
       
   815     return err;
       
   816     }
       
   817             
       
   818 TInt CProgDLMultimediaSource::SetAgentProperty(ContentAccess::TAgentProperty aProperty, TInt aValue)
       
   819     {
       
   820     if (!iFile)
       
   821         {
       
   822         return KErrNotReady;
       
   823         }
       
   824     
       
   825     return iFile->SetAgentProperty(aProperty, aValue);
       
   826     }
       
   827             
       
   828 
       
   829 TBool CReadWriteRequest::SourceType() 
       
   830     {
       
   831     return iSourceType ;
       
   832     }
       
   833 
       
   834 
       
   835 /*
       
   836 *	Returns the data member of CMMFDataBuffer or CMMFTransferBuffer (as TPtr8)
       
   837 *  
       
   838 */
       
   839 TDes8& CReadWriteRequest::BufferDes()
       
   840     {
       
   841     if(iTransferBufferCopy)
       
   842         return iTransferBufferCopy->Des();
       
   843     else
       
   844         {
       
   845         //reset iBufferDes in case iBuffer has changed...
       
   846         iBufferDes = &(STATIC_CAST(CMMFDataBuffer*, iBuffer)->Data());
       
   847         return *iBufferDes;
       
   848         }
       
   849     }
       
   850 
       
   851 const TDesC8& CReadWriteRequest::BufferDesC()
       
   852     {
       
   853     if(iTransferBufferCopy)
       
   854         return iTransferBufferCopy->Des();
       
   855     else
       
   856         return BufferDes();
       
   857     }
       
   858 
       
   859 CMMFBuffer* CReadWriteRequest::Buffer()
       
   860     {
       
   861     return iBuffer;
       
   862     }
       
   863 
       
   864 TAny* CReadWriteRequest::GetSinkOrSource()
       
   865     {
       
   866     return iSinkOrSource;
       
   867     }
       
   868 
       
   869 /*
       
   870 *	Destructor.
       
   871 */
       
   872 CReadWriteRequest::~CReadWriteRequest() 
       
   873     {
       
   874     Cancel();
       
   875     if(iTransferBufferCopy)
       
   876         iTransferBufferCopy->SetInUse(EFalse);
       
   877     }
       
   878 
       
   879 /*
       
   880 *	Allows owning class access to SetActive()
       
   881 */
       
   882 void CReadWriteRequest::SetActive() 
       
   883     {
       
   884     CActive::SetActive() ;
       
   885     }
       
   886         
       
   887 /*
       
   888 *  For the moment at least...    Canceled requests may be deleted
       
   889 */
       
   890 void CReadWriteRequest::DoCancel() 
       
   891     {
       
   892     iState = ECompleted;
       
   893     }
       
   894             
       
   895 /*
       
   896 *	Called when errors in RunL force Leave.  For the moment just mark the request deletable
       
   897 */
       
   898 TInt CReadWriteRequest::RunError( TInt aError ) 
       
   899     {
       
   900     //RunL can leave.
       
   901     iState = ECompleted;
       
   902     iError = aError; //keep this error internally for now
       
   903     return KErrNone ;
       
   904     }
       
   905         
       
   906 /*
       
   907 *	On completion of read request call back to the MDataSink
       
   908 */
       
   909 void CReadRequest::RunL() 
       
   910     {
       
   911     iState = EProcessing;
       
   912     //Copy the data from the normal buffer into the Transfer buffer
       
   913     if(iTransferBufferCopy)
       
   914         {
       
   915         //must specify the size here as the dest may be smaller than the source.
       
   916         TDes8& destDesc = STATIC_CAST(CMMFDataBuffer*, iBuffer)->Data();
       
   917         destDesc.Copy(iTransferBufferCopy->Des().Left(destDesc.MaxLength()));
       
   918     
       
   919         iTransferBufferCopy->SetInUse(EFalse);
       
   920         }
       
   921 
       
   922         STATIC_CAST(CProgDLMultimediaSource*,iParent)->ReadRequestStatus(STATIC_CAST(CReadWriteRequest*,this),iStatus);
       
   923     iState = ECompleted;
       
   924     }
       
   925 
       
   926         // From CMultimediaDataSource begins
       
   927 TInt CProgDLMultimediaSource::SetObserver( MMultimediaDataSourceObserver& aObserver )
       
   928     {
       
   929     TInt status(KErrNone);
       
   930     iObserver = &aObserver;
       
   931     return status;
       
   932     }
       
   933         
       
   934 TInt CProgDLMultimediaSource::GetObserver( MMultimediaDataSourceObserver*& aObserver )
       
   935     {
       
   936     TInt status(KErrNone);
       
   937     aObserver = iObserver;
       
   938     return status;
       
   939     }
       
   940         
       
   941 void CProgDLMultimediaSource::Event( TUid aEvent )
       
   942     {
       
   943     if( aEvent == KMultimediaDataSourceEventBitRateChanged )
       
   944         {
       
   945         
       
   946         if(iObserver)
       
   947             {
       
   948                 iObserver->GetBitRate( iObserverBitRate ); 
       
   949                 if(iState == EBUFFERING)
       
   950                     CalculateBufferedDataSize();
       
   951             }
       
   952         }    
       
   953     
       
   954     }
       
   955         
       
   956 TInt CProgDLMultimediaSource::SetDataTypeCode(TFourCC aSourceFourCC )
       
   957     {
       
   958     TInt status(KErrNone);
       
   959     iSourceFourCC = aSourceFourCC;
       
   960     return status;
       
   961     }
       
   962         
       
   963 TInt CProgDLMultimediaSource::GetDataTypeCode(TFourCC& aSourceFourCC )
       
   964     {
       
   965     TInt status(KErrNone);
       
   966     aSourceFourCC = iSourceFourCC;
       
   967     return status;
       
   968     }
       
   969 
       
   970 TInt CProgDLMultimediaSource::GetSize( TUint& aSize )
       
   971     {
       
   972     TInt err = KErrNone;
       
   973     if (iDLFileSize >=0)
       
   974     	{
       
   975     	aSize = iDLFileSize;
       
   976     	}
       
   977     else
       
   978     	{
       
   979     	aSize = 0;
       
   980     	}
       
   981     return err;
       
   982     }
       
   983 
       
   984 TInt CProgDLMultimediaSource::Open()
       
   985     {
       
   986     TInt status(KErrNotReady);
       
   987     DEBPRN1(_L("CProgDLMultimediaSource::Open"));
       
   988     switch ( iState )
       
   989         {
       
   990         case ECLOSED:
       
   991             StateChanged(ESTOPPED);
       
   992             status = KErrNone;
       
   993             break;
       
   994         case ESTOPPED:
       
   995         case EPRIMED:
       
   996         case EEXECUTING:
       
   997         case EBUFFERING:
       
   998         default:
       
   999             DEBPRN2(_L("CProgDLMultimediaSource::Open[Illegal cmd on state[%d]]"), iState );
       
  1000             break;
       
  1001         };
       
  1002     return status;
       
  1003     }
       
  1004 
       
  1005 TInt CProgDLMultimediaSource::Close()
       
  1006     {
       
  1007     TInt status(KErrNone);
       
  1008     iHandle.Close();
       
  1009     iFsSession.Close();
       
  1010 
       
  1011     StateChanged(ECLOSED);
       
  1012     // Clear app buffers
       
  1013     EmptySinkQueue();
       
  1014     iSnkBytes = 0;
       
  1015     // Clear observer buffers
       
  1016     return status;
       
  1017     }
       
  1018 
       
  1019 TInt CProgDLMultimediaSource::Prime()
       
  1020     {
       
  1021     TInt status(KErrNotReady);
       
  1022     DEBPRN1(_L("CProgDLMultimediaSource::Prime"));
       
  1023     switch ( iState )
       
  1024         {
       
  1025         case ESTOPPED:
       
  1026             
       
  1027             // don't reopen file if already open
       
  1028             if (!iFile)
       
  1029                 {
       
  1030                 if (iFileHandle)
       
  1031                     {
       
  1032                     TRAPD(err,iFile = CContentFile::NewL(iHandle, UniqueId(), iCAFParameters->iEnableUI));
       
  1033                     if(err)
       
  1034                         return err;
       
  1035                     }
       
  1036                 else
       
  1037                     {
       
  1038                     // Open for read-only access
       
  1039                     TRAPD(err,iFile = CContentFile::NewL(iFsSession, iFullFileName, UniqueId(), EFileShareAny, iCAFParameters->iEnableUI));
       
  1040                     if(err)
       
  1041                         return err;                    
       
  1042                     }
       
  1043                 }
       
  1044             
       
  1045             if(iFile)
       
  1046                 {
       
  1047                 if(iFile->IsProtected())
       
  1048                     iFile->Size(iFileSize);
       
  1049                 else
       
  1050                     iFileSize = iDLFileSize;		          
       
  1051                 }												
       
  1052             
       
  1053             StateChanged(EPRIMED);
       
  1054             status = KErrNone;
       
  1055             break;
       
  1056         case EPRIMED:
       
  1057             status = KErrNone;
       
  1058             break;
       
  1059         case ECLOSED:
       
  1060         case EEXECUTING:
       
  1061         case EBUFFERING:
       
  1062         default:
       
  1063             DEBPRN2(_L("CProgDLMultimediaSource::Prime[Illegal cmd on state[%d]]"), iState );
       
  1064             break;
       
  1065         }
       
  1066     return status;
       
  1067     }
       
  1068 
       
  1069 TInt CProgDLMultimediaSource::Play()
       
  1070     {
       
  1071     TInt status(KErrNotReady);
       
  1072     DEBPRN1(_L("CProgDLMultimediaSource::Play"));
       
  1073     switch ( iState )
       
  1074         {
       
  1075         case EPRIMED:
       
  1076             CalculateBufferedDataSize();
       
  1077             StateChanged(EEXECUTING);
       
  1078             
       
  1079             while ( !iSinkQueue->IsEmpty() )
       
  1080                 {
       
  1081                 status = ServiceFillBuffer();
       
  1082                 }
       
  1083             
       
  1084             if(status == KErrUnderflow)
       
  1085                 {
       
  1086                 StateChanged(EBUFFERING);
       
  1087                 }
       
  1088             
       
  1089             status = KErrNone;	
       
  1090             break;
       
  1091         case EEXECUTING:
       
  1092         case EBUFFERING:
       
  1093             status = KErrNone;
       
  1094             // No op
       
  1095             break;
       
  1096         case ECLOSED:
       
  1097         case ESTOPPED:
       
  1098         default:
       
  1099             DEBPRN2(_L("CProgDLMultimediaSource::Play[Illegal cmd on state[%d]]"), iState );
       
  1100             break;
       
  1101         };
       
  1102     return status;
       
  1103     }
       
  1104         
       
  1105 TInt CProgDLMultimediaSource::Stop()
       
  1106     {
       
  1107     TInt status(KErrNotReady);
       
  1108     DEBPRN1(_L("CProgDLMultimediaSource::Stop"));
       
  1109     switch ( iState )
       
  1110         {
       
  1111         case EPRIMED:
       
  1112         case EEXECUTING:
       
  1113         case EBUFFERING:
       
  1114             {
       
  1115             TInt pos = 0;
       
  1116             CancelRequests();
       
  1117             if (iFile)
       
  1118                 iFile->Seek(ESeekStart,0);
       
  1119             // Since the requests will not be deleted if it is still inside RunL() (iState is EProcessing), 
       
  1120             // iReadRequestPending should not be initialized to 0 always
       
  1121             iReadRequestPending = iRequests.Count();
       
  1122             //iDLFileSize = -1;
       
  1123             iSnkBytes=pos;
       
  1124             iBufferedDataSize = 0;
       
  1125             EmptySinkQueue();
       
  1126             StateChanged(ESTOPPED);
       
  1127             status = KErrNone;
       
  1128             }
       
  1129             break;
       
  1130         case ECLOSED:
       
  1131         default:
       
  1132             DEBPRN2(_L("CProgDLMultimediaSource::Stop[Illegal cmd on state[%d]]"), iState );
       
  1133             break;
       
  1134         };
       
  1135     return status;
       
  1136     }
       
  1137     
       
  1138     
       
  1139 TInt CProgDLMultimediaSource::FillBuffer( CMMFBuffer* aBuffer )
       
  1140     {
       
  1141     // Requires that iFile is open for read.
       
  1142     // Reads data from iFile into aBuffer
       
  1143     
       
  1144     TInt status(KErrNone);
       
  1145     DEBPRN2(_L("CProgDLMultimediaSource::FillBuffer[%x]]"), aBuffer );
       
  1146     if (!aBuffer)
       
  1147         return KErrArgument;
       
  1148     
       
  1149     if (!iFile)
       
  1150         return KErrNotReady;
       
  1151     
       
  1152     AppendBufferToSinkQueue(aBuffer,iObserver,NULL,EFalse);
       
  1153     
       
  1154     DEBPRN4(_L("CProgDLMultimediaSource::FillBuffer DLComplete[%d] ReOpenCAF[%d] RequestPending[%d]"), isDownloadComplete,iReOpenCAF,iReadRequestPending );
       
  1155     if(isDownloadComplete && !iReOpenCAF) 
       
  1156         {
       
  1157         if(!iReadRequestPending)
       
  1158             {
       
  1159             ReOpenCAF();                        
       
  1160             status = ServiceFillBuffer();
       
  1161             if(status == KErrUnderflow)
       
  1162                 {
       
  1163                 StateChanged(EBUFFERING);
       
  1164                 }
       
  1165             }
       
  1166         }
       
  1167     else
       
  1168         {
       
  1169         status = ServiceFillBuffer();
       
  1170         
       
  1171         if(status == KErrUnderflow)
       
  1172             {
       
  1173             StateChanged(EBUFFERING);
       
  1174             }
       
  1175         }        
       
  1176     return status; 	
       
  1177     }
       
  1178 
       
  1179     
       
  1180 TAny* CProgDLMultimediaSource::CustomInterface( TUid /*aInterfaceUid*/ )
       
  1181     {
       
  1182     return NULL;
       
  1183     }
       
  1184     
       
  1185 TInt CProgDLMultimediaSource::AppendBufferToSinkQueue( CMMFBuffer* aBuffer,
       
  1186                                                     MMultimediaDataSourceObserver* aObserver,
       
  1187                                                     MDataSink* aConsumer,TBool aTop )  
       
  1188     {
       
  1189     TInt status(KErrNone);
       
  1190     
       
  1191     DEBPRN2(_L("CProgDLMultimediaSource::AppendBufferToSinkQueue() Buffer[%x]"), aBuffer );				    
       
  1192     // Add observer buffer to queue
       
  1193     CMMFDataBuffer* dest = static_cast<CMMFDataBuffer*>( aBuffer );
       
  1194     TDes8& destBufferDes = dest->Data();
       
  1195     
       
  1196     CSinkQueueItem* request(NULL);
       
  1197     
       
  1198     TRAP( status, request = CSinkQueueItem::NewL( aBuffer, aObserver,aConsumer) );
       
  1199     if ( status == KErrNone )
       
  1200         {
       
  1201         if(aTop)
       
  1202             iSinkQueue->AddFirst(*request);
       
  1203         else  
       
  1204             iSinkQueue->AddLast(*request);
       
  1205         
       
  1206         iSnkItemsCount++;
       
  1207         
       
  1208         DEBPRN3(_L("CProgDLMultimediaSource::AppendBufferToQueue[ReqSize[%d]SnkItems[%d]]"), \
       
  1209             aBuffer->RequestSize(), iSnkItemsCount );
       
  1210         }
       
  1211     return status;
       
  1212     }
       
  1213     
       
  1214 void CProgDLMultimediaSource::SourceCustomCommand(TMMFMessage& aMessage)
       
  1215     {
       
  1216     TInt err(KErrNone);
       
  1217     switch ( aMessage.Function() )
       
  1218         {
       
  1219         
       
  1220         case ESetUpdateFileName:
       
  1221             {
       
  1222             // Read size info
       
  1223             TPckgBuf<TFileName> sizePckg;
       
  1224             err = aMessage.ReadData1FromClient(sizePckg);
       
  1225             if ( err == KErrNone )
       
  1226                 {
       
  1227                 iFullFileName = sizePckg();
       
  1228                 if (iFile)
       
  1229                 {
       
  1230                     delete iFile;
       
  1231                     iFile = NULL;
       
  1232                 }
       
  1233                 if (iFileHandle)
       
  1234                     {
       
  1235                     TRAPD(err,iFile = CContentFile::NewL(iHandle, UniqueId(), iCAFParameters->iEnableUI));
       
  1236                     }
       
  1237                 else
       
  1238                     {
       
  1239                     // Open for read-only access
       
  1240                     TRAPD(err,iFile = CContentFile::NewL(iFsSession, iFullFileName, UniqueId(), EFileShareAny, iCAFParameters->iEnableUI));
       
  1241                     }
       
  1242                 }
       
  1243             aMessage.Complete(KErrNone);			            
       
  1244             
       
  1245             }   
       
  1246             break;
       
  1247 
       
  1248         case EDownloadRate:
       
  1249             {
       
  1250             
       
  1251             // Read size info
       
  1252             TPckgBuf<TUint> sizePckg;
       
  1253             err = aMessage.ReadData1FromClient(sizePckg);
       
  1254             if ( err == KErrNone )
       
  1255                 {
       
  1256                 iTransferRate = sizePckg();
       
  1257                 }
       
  1258             aMessage.Complete(KErrNone);			            
       
  1259             DEBPRN2(_L("CProgDLMultimediaSource::SourceCustomCommand EDownloadRate[%u] "),iTransferRate);
       
  1260             if(iState == EBUFFERING /*&& !iSinkQueue->IsEmpty()*/)
       
  1261                 { 
       
  1262                 CalculateBufferedDataSize();
       
  1263                 }
       
  1264             }   
       
  1265             break;
       
  1266         case ESetDownloadState:
       
  1267             {
       
  1268             isDownloadComplete = ETrue;    
       
  1269             if(iFile)
       
  1270                 iFile->Size(iFileSize);
       
  1271             
       
  1272             if(iFileSize != iDLFileSize)
       
  1273                 iDLFileSize = iFileSize;
       
  1274             
       
  1275             iDownloadSize =  iFileSize;
       
  1276             iBufferedDataSize = 0;
       
  1277             aMessage.Complete(KErrNone);
       
  1278     
       
  1279             if(iObserver)
       
  1280                 iObserver->Event(KMultimediaDataSourceEventRandomSeekingSupportChanged);	
       
  1281             
       
  1282             if(iState == EBUFFERING )
       
  1283                 {
       
  1284                 if((iDownloadSize - iSnkBytes) > iBufferedDataSize)
       
  1285                     {
       
  1286                     StateChanged(EEXECUTING);
       
  1287                     while ( !iSinkQueue->IsEmpty() )
       
  1288                         {
       
  1289                         err = ServiceFillBuffer();
       
  1290                         if(err == KErrUnderflow)
       
  1291                             {
       
  1292                             StateChanged(EBUFFERING);
       
  1293                             break;
       
  1294                             }
       
  1295                         }
       
  1296                     }
       
  1297                 }
       
  1298             }
       
  1299             break;
       
  1300             
       
  1301         case ESetDownloadSize:
       
  1302             {
       
  1303             // Read size info
       
  1304             TPckgBuf<TInt> sizePckg;
       
  1305             err = aMessage.ReadData1FromClient(sizePckg);
       
  1306             if ( err == KErrNone )
       
  1307                 {
       
  1308                 iDownloadSize = sizePckg();
       
  1309                 }
       
  1310             aMessage.Complete(KErrNone);			
       
  1311             TInt size = 0;
       
  1312 
       
  1313             if(iFile)
       
  1314                 iFile->Size(size);
       
  1315             
       
  1316             DEBPRN4(_L("CProgDLMultimediaSource::SourceCustomCommand ********BufferedDataSize[%u] DownloadSize[%d] iSnkbytes[%d]"), iBufferedDataSize ,iDownloadSize, iSnkBytes ); 		            
       
  1317             DEBPRN4(_L("CProgDLMultimediaSource::SourceCustomCommand ********iDLFileSize[%d] iFileSize[%d]ActualSize[%d]"), iDLFileSize,iFileSize,size); 		            
       
  1318             if(iState == EBUFFERING )
       
  1319                 {
       
  1320                 if((iDownloadSize - iSnkBytes) > iBufferedDataSize)
       
  1321                     {
       
  1322                     StateChanged(EEXECUTING);
       
  1323                     while ( !iSinkQueue->IsEmpty() )
       
  1324                         {
       
  1325                         err = ServiceFillBuffer();
       
  1326                         if(err == KErrUnderflow)
       
  1327                             {
       
  1328                             StateChanged(EBUFFERING);
       
  1329                             break;
       
  1330                             }
       
  1331                         }
       
  1332                     }
       
  1333                 }			
       
  1334             }
       
  1335             break;
       
  1336                 
       
  1337         case ESetActualSize:
       
  1338             {
       
  1339             // Read size info
       
  1340             TPckgBuf<TInt> sizePckg;
       
  1341             err = aMessage.ReadData1FromClient(sizePckg);
       
  1342             if ( err == KErrNone )
       
  1343                 {
       
  1344                 iDLFileSize = sizePckg();
       
  1345                 }
       
  1346             aMessage.Complete(KErrNone);
       
  1347             
       
  1348             if(iFile)
       
  1349                 {
       
  1350                 if(iFile->IsProtected())
       
  1351                     iFile->Size(iFileSize);
       
  1352                 else
       
  1353                     iFileSize = iDLFileSize;		          
       
  1354                 }
       
  1355             DEBPRN3(_L("CProgDLMultimediaSource::SourceCustomCommand ActualSize********iDLFileSize[%d] iFileSize[%d]"), iDLFileSize,iFileSize); 		            
       
  1356             
       
  1357             if(iObserver)
       
  1358                 iObserver->Event(KMultimediaDataSourceObserverEventSourceSizeChanged);
       
  1359             
       
  1360             }
       
  1361             break;   
       
  1362                 
       
  1363         case EGetSourceState:
       
  1364             {
       
  1365             TPckgBuf<TState> statePckg;	
       
  1366             aMessage.ReadData1FromClient(statePckg);
       
  1367             DEBPRN3(_L("CProgDLMultimediaSource::SourceCustomCommand() Client State[%d] SourceState[%d]"), statePckg(), iState);
       
  1368             
       
  1369             if(iState != statePckg())
       
  1370                 {
       
  1371                 statePckg() = iState;	
       
  1372                 aMessage.WriteDataToClient(statePckg);
       
  1373                 aMessage.Complete(KErrNone);
       
  1374                 }
       
  1375             else
       
  1376                 iMessage = new(ELeave) TMMFMessage(aMessage);
       
  1377              }   
       
  1378             break;   
       
  1379 
       
  1380         case EGetBitRate:
       
  1381             {
       
  1382             TPckgBuf<TUint> bitRatePckg;	 
       
  1383             DEBPRN2(_L("CProgDLMultimediaSource::SourceCustomCommand() Client BitRateFromS[%d]"),iObserverBitRate);
       
  1384             bitRatePckg() = iObserverBitRate ;	
       
  1385             aMessage.WriteDataToClient(bitRatePckg);
       
  1386             aMessage.Complete(KErrNone);
       
  1387             }            
       
  1388             break;   
       
  1389 
       
  1390         case EGetPercentageBuffered:
       
  1391             {
       
  1392             TPckgBuf<TUint> perBufPckg; 
       
  1393             TUint perBuf = 0;
       
  1394             if(iState == EBUFFERING && iBufferedDataSize != 0)
       
  1395                 {
       
  1396                 CalculateBufferedDataSize();                    
       
  1397                 if ( iBufferedDataSize == 0 ) 
       
  1398                     {
       
  1399                     perBuf = 0; 
       
  1400                     }
       
  1401                 else
       
  1402                     {
       
  1403                     perBuf = (iDownloadSize - iSnkBytes) * 100 / iBufferedDataSize;
       
  1404                     }
       
  1405                 }
       
  1406             
       
  1407             RDebug::Print(_L(" Percentage Buffered [%d]"),perBuf);
       
  1408             perBufPckg() = perBuf;
       
  1409             aMessage.WriteDataToClient(perBufPckg);
       
  1410             aMessage.Complete(KErrNone);
       
  1411             }
       
  1412             break;
       
  1413         case ESetFileMoving:
       
  1414             {
       
  1415             if (iFile)
       
  1416                 {
       
  1417                 delete iFile;
       
  1418                 iFile = NULL;
       
  1419                 }
       
  1420             aMessage.Complete(KErrNone);
       
  1421             }
       
  1422             break;    
       
  1423         default:
       
  1424             err = KErrArgument;
       
  1425             break;
       
  1426         }
       
  1427     }        
       
  1428 
       
  1429 TInt CProgDLMultimediaSource::ServiceFillBuffer()
       
  1430     {
       
  1431     
       
  1432     DEBPRN3(_L("CProgDLMultimediaSource::ServiceFillBuffer() state[%d] Download Size[%d]"), iState ,iDownloadSize );
       
  1433     
       
  1434     TInt status(KErrNone);
       
  1435     if ( iSinkQueue->IsEmpty() )
       
  1436         return KErrNone;
       
  1437     
       
  1438     CSinkQueueItem* tempsnkItem = iSinkQueue->First();
       
  1439     CMMFBuffer* tempbuffer = tempsnkItem->Buffer();
       
  1440     
       
  1441     TInt bufSize = tempbuffer->RequestSize();
       
  1442     
       
  1443     DEBPRN5(_L("CProgDLMultimediaSource::ServiceFillBuffer() ********BufferedDataSize[%u] DownloadSize[%d] iSnkbytes[%d] BufSize[%d]"), iBufferedDataSize ,iDownloadSize, iSnkBytes,bufSize ); 		            				
       
  1444     if((((iDownloadSize - iSnkBytes) > bufSize) && 
       
  1445         iState == EEXECUTING && 
       
  1446         iDownloadSize > iBufferedDataSize && ((iReadRequestPending + 1)*bufSize < (iDownloadSize - iSnkBytes))) || (iFileSize == iDownloadSize))
       
  1447         {
       
  1448         iReadRequestPending++;
       
  1449         CSinkQueueItem* snkItem = iSinkQueue->First();
       
  1450         iSinkQueue->Remove(*snkItem);
       
  1451         iSnkItemsCount--;
       
  1452         CMMFBuffer* buffer = snkItem->Buffer();
       
  1453         DEBPRN2(_L("CProgDLMultimediaSource::ServiceFillBuffer() Buffer[%x]"), buffer );				    
       
  1454         MMultimediaDataSourceObserver* observer = snkItem->Observer();
       
  1455         MDataSink* consumer = snkItem->Consumer();
       
  1456         delete snkItem;
       
  1457         
       
  1458         if (CMMFBuffer::IsSupportedDataBuffer(buffer->Type()))
       
  1459             {
       
  1460             CTransferBufferCopy* transBufCopy = NULL;
       
  1461             CReadRequest* request = NULL;
       
  1462             
       
  1463             TDes8& bufferDes = STATIC_CAST( CMMFDataBuffer*, buffer )->Data();
       
  1464             
       
  1465             TInt requestSize;
       
  1466             if(buffer->RequestSize())
       
  1467                 requestSize = buffer->RequestSize();
       
  1468             else
       
  1469                 requestSize = bufferDes.MaxLength();
       
  1470             
       
  1471             //check whether buffer is safe to send to file server
       
  1472             //if not, eg for a transfer buffer, then it needs to be copied
       
  1473             if (!CMMFBuffer::IsFileServerSafe(buffer->Type()))
       
  1474                 {
       
  1475                 //NB: failure in this method will NOT cause transBufCopy to leak as it will be 
       
  1476                 //inserted into iTransferBufferCopies by ObtainCopyOfTransferBufferL.
       
  1477                 TRAP(status,transBufCopy = ObtainCopyOfTransferBufferL(bufferDes.MaxLength()));
       
  1478                 
       
  1479                 if(consumer && !observer)
       
  1480                     request = new(ELeave) CReadRequest(this,STATIC_CAST(TAny*, consumer), buffer, transBufCopy, iSnkBytes, iDownloadSize, ETrue);
       
  1481                 else
       
  1482                     request = new(ELeave) CReadRequest(this,STATIC_CAST(TAny*, observer), buffer, transBufCopy, iSnkBytes, iDownloadSize, EFalse);					
       
  1483                 
       
  1484                 }
       
  1485             else
       
  1486                 {
       
  1487                 if(consumer && !observer)
       
  1488                     request = new(ELeave) CReadRequest(this,STATIC_CAST(TAny*, consumer), buffer, iSnkBytes, iDownloadSize, ETrue);
       
  1489                 else
       
  1490                     request = new(ELeave) CReadRequest(this,STATIC_CAST(TAny*, observer), buffer, iSnkBytes, iDownloadSize, EFalse);					
       
  1491                 }
       
  1492             
       
  1493             CleanupStack::PushL( request );
       
  1494             
       
  1495             TRAP_IGNORE(StoreRequestL(request)); // transfers ownership
       
  1496             CleanupStack::Pop() ; // request
       
  1497             
       
  1498             request->SetActive();
       
  1499             
       
  1500             //	iSnkBytes += requestSize;
       
  1501             request->Buffer()->SetLastBuffer(EFalse);
       
  1502             iFile->Read(request->BufferDes(), requestSize, request->iStatus);
       
  1503             
       
  1504             }
       
  1505         else // if (CMMFBuffer::IsSupportedDataBuffer(buffer->Type()))
       
  1506             return KErrNotSupported;
       
  1507         }
       
  1508         /*else if(iDownloadSize == iSnkBytes)
       
  1509         {
       
  1510         Stop();
       
  1511     }*/
       
  1512     else
       
  1513         {
       
  1514         
       
  1515         //StateChanged(EBUFFERING);
       
  1516         return KErrUnderflow;
       
  1517         }
       
  1518     return status;
       
  1519     }
       
  1520 
       
  1521 TInt CProgDLMultimediaSource::EmptySinkQueue()
       
  1522     {
       
  1523     TInt status(KErrNone);
       
  1524     // Empty sink queue
       
  1525     CSinkQueueItem* snkItem;
       
  1526     while ( !iSinkQueue->IsEmpty() )
       
  1527         {
       
  1528         snkItem = iSinkQueue->First();
       
  1529         iSinkQueue->Remove(*snkItem);
       
  1530         delete snkItem;
       
  1531         }
       
  1532     
       
  1533     iSnkItemsCount = 0;
       
  1534     return status;
       
  1535     }
       
  1536 
       
  1537 void CProgDLMultimediaSource::CalculateBufferedDataSize()
       
  1538     {
       
  1539     DEBPRN1(_L("CProgDLMultimediaSource::CalculateBufferedDataSize()"));
       
  1540     iBufferedDataSize = 0;
       
  1541     
       
  1542     // Get the bit rate from observer
       
  1543     if(iObserver)
       
  1544         iObserver->GetBitRate( iObserverBitRate );
       
  1545     
       
  1546     // If we don't know observer bit rate
       
  1547     if(iDownloadSize == iDLFileSize)
       
  1548         {
       
  1549         iBufferedDataSize = 0;
       
  1550         return;
       
  1551         }   
       
  1552 
       
  1553     if(iObserverBitRate == 0 && (iSinkQueue->First() != NULL))
       
  1554         {
       
  1555             if(iPrimaryBufferingConfig.iType == TBufferingConfig::FIXEDDURATION
       
  1556             || iPrimaryBufferingConfig.iType == TBufferingConfig::DYNAMICDURATION)
       
  1557                 {
       
  1558                     if(iSecondaryBufferingConfig.iType == TBufferingConfig::FIXEDDURATION
       
  1559                     || iSecondaryBufferingConfig.iType == TBufferingConfig::DYNAMICDURATION)
       
  1560                         {
       
  1561                         iBufferedDataSize =  iDLFileSize * iInitialBufferingPercentage / 100;       
       
  1562                         }
       
  1563                     else
       
  1564                         {
       
  1565                         if(iDLFileSize < iSecondaryBufferingConfig.iAmount)
       
  1566                             {
       
  1567                             iBufferedDataSize = iDLFileSize;
       
  1568                             }
       
  1569                         else
       
  1570                             {
       
  1571                             iBufferedDataSize = iSecondaryBufferingConfig.iAmount;
       
  1572                             }
       
  1573                         }    
       
  1574                 }
       
  1575             else
       
  1576                 {
       
  1577                 if(iDLFileSize < iPrimaryBufferingConfig.iAmount)
       
  1578                     {
       
  1579                     iBufferedDataSize = iDLFileSize;
       
  1580                     }
       
  1581                 else
       
  1582                     {
       
  1583                     iBufferedDataSize = iPrimaryBufferingConfig.iAmount;
       
  1584                     }
       
  1585                 }                
       
  1586             
       
  1587         }
       
  1588      else
       
  1589         {
       
  1590             if(iPrimaryBufferingConfig.iType == TBufferingConfig::FIXEDDURATION
       
  1591             || iPrimaryBufferingConfig.iType == TBufferingConfig::DYNAMICDURATION)
       
  1592                 {
       
  1593                 TUint constantC = KMinPlaybackDuration * iObserverBitRate / 8;
       
  1594 
       
  1595                 // calculate time remaining
       
  1596                 //TInt64 timeRemaining = ( iDLFileSize - iSnkBytes ) * 8 / iObserverBitRate;
       
  1597                 TUint bytesRemaining = iDLFileSize - iSnkBytes;
       
  1598                 iBufferedDataSize = bytesRemaining < constantC ? bytesRemaining : constantC;
       
  1599 
       
  1600 //                timeRemaining = timeRemaining < 0 ? 0 : timeRemaining;
       
  1601 
       
  1602                 // calculate the value in a temporary variable
       
  1603 //                TInt64 bufferedDataSize = ((TInt64(iObserverBitRate)) - (TInt64(iTransferRate))) * timeRemaining / 8;
       
  1604 //                bufferedDataSize = bufferedDataSize < constantC ? bufferedDataSize : constantC;
       
  1605 
       
  1606 //                iBufferedDataSize = bufferedDataSize > KMaxTUint ? KMaxTUint : I64LOW(bufferedDataSize);
       
  1607                 }
       
  1608             else
       
  1609                 {
       
  1610                 iBufferedDataSize = iPrimaryBufferingConfig.iAmount;
       
  1611                 }                
       
  1612         }   
       
  1613 
       
  1614     DEBPRN5(_L("CProgDLMultimediaSource::CalculateBufferdDataSize[%u] ObserverBitRate[%d] SnkBytes[%u] TransferRate[%d]"), iBufferedDataSize,iObserverBitRate,iSnkBytes,iTransferRate );
       
  1615     }
       
  1616 
       
  1617 void CProgDLMultimediaSource::StateChanged(TState newState)
       
  1618     {
       
  1619     DEBPRN3(_L("CProgDLMultimediaSource::StateChanged OLD[%d] NEW[%d]"),iState, newState);        
       
  1620     if(iState != newState)
       
  1621         {
       
  1622         if(iMessage)
       
  1623             {
       
  1624             if(!iMessage->IsCompleted())
       
  1625                 {
       
  1626                 TPckgBuf<TState> statePckg(newState);	
       
  1627                 iMessage->WriteDataToClient(statePckg);
       
  1628                 iMessage->Complete(KErrNone);
       
  1629                 delete iMessage;
       
  1630                 iMessage = NULL;
       
  1631                 }
       
  1632             }
       
  1633         iState = newState;
       
  1634         }
       
  1635     }
       
  1636 
       
  1637 TInt CProgDLMultimediaSource::ReadRequestStatus(CReadWriteRequest* aRequest, TRequestStatus& aStatus)
       
  1638     {
       
  1639     
       
  1640     if(aStatus != KErrNone)
       
  1641         {
       
  1642         TMMFEvent event(KMMFErrorCategoryControllerGeneralError, aStatus.Int());
       
  1643         //TODO: Need to send this error back to client. Currently removing this as iEventHandler is never set.
       
  1644         //iEventHandler->SendEventToClient(event);
       
  1645         return KErrNone;
       
  1646         }
       
  1647     else
       
  1648         {
       
  1649         
       
  1650         DEBPRN4(_L("CProgDLMultimediaSource::ReadRequestStatus Buffer[%x] BufferSize[%d] RequestSize[%d]"),aRequest->Buffer(),aRequest->Buffer()->BufferSize(),aRequest->Buffer()->RequestSize());
       
  1651         DEBPRN3(_L("CProgDLMultimediaSource::ReadRequestStatus Buffer[%x] LastBuffer[%d]"),aRequest->Buffer(),aRequest->Buffer()->LastBuffer());
       
  1652         
       
  1653         //Moved from CProgDLMultimediaSource::ServiceFillBuffer to handle deadlock situations
       
  1654         if ((iSnkBytes + aRequest->Buffer()->RequestSize()) >= iDownloadSize && isDownloadComplete)
       
  1655             {
       
  1656 	              aRequest->Buffer()->SetLastBuffer(ETrue);
       
  1657                 DEBPRN1(_L("CProgDLMultimediaSource::ReadRequestStatus() LastBuffer$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"));
       
  1658             }
       
  1659 
       
  1660         TBool lastBuffer = aRequest->Buffer()->LastBuffer();
       
  1661         
       
  1662         if((aRequest->Buffer()->BufferSize() != aRequest->Buffer()->RequestSize()) && !lastBuffer)
       
  1663             {
       
  1664             if(aRequest->SourceType())
       
  1665                 {
       
  1666                 MDataSink* sinkOrSource = REINTERPRET_CAST(MDataSink*,aRequest->GetSinkOrSource());
       
  1667                 TUint position = aRequest->Buffer()->Position();
       
  1668                 TUint newPos = position - aRequest->Buffer()->BufferSize();
       
  1669                 aRequest->Buffer()->SetPosition(newPos);
       
  1670                 AppendBufferToSinkQueue(aRequest->Buffer(),(MMultimediaDataSourceObserver*)NULL,sinkOrSource,ETrue);
       
  1671                 //iSnkBytes -= aRequest->Buffer()->BufferSize();
       
  1672                 iFile->Seek(ESeekStart,iSnkBytes);
       
  1673                 StateChanged(EBUFFERING);
       
  1674                 }
       
  1675             else
       
  1676                 {
       
  1677                 MMultimediaDataSourceObserver* sinkOrSource = REINTERPRET_CAST(MMultimediaDataSourceObserver*,aRequest->GetSinkOrSource());
       
  1678                 TInt position = aRequest->Buffer()->Position();
       
  1679                 TInt newPos = position - aRequest->Buffer()->BufferSize();
       
  1680                 aRequest->Buffer()->SetPosition(newPos);
       
  1681                 AppendBufferToSinkQueue(aRequest->Buffer(),sinkOrSource,(MDataSink*)NULL,ETrue);
       
  1682                 //iSnkBytes -= aRequest->Buffer()->BufferSize();
       
  1683                 iFile->Seek(ESeekStart,iSnkBytes);
       
  1684                 StateChanged(EBUFFERING);
       
  1685                 }
       
  1686             }
       
  1687         else
       
  1688             {	
       
  1689             iSnkBytes += aRequest->Buffer()->BufferSize();
       
  1690             
       
  1691             
       
  1692             if(aRequest->SourceType())
       
  1693                     REINTERPRET_CAST(MDataSink*, aRequest->GetSinkOrSource())->BufferFilledL(aRequest->Buffer()) ; // callback to MDataSource/Sink
       
  1694             else
       
  1695                     REINTERPRET_CAST(MMultimediaDataSourceObserver*, aRequest->GetSinkOrSource())->BufferFilled(aRequest->Buffer()) ; // callback to MDataSource/Sink			
       
  1696                 
       
  1697                 
       
  1698             }
       
  1699             
       
  1700         iReadRequestPending--;
       
  1701         DEBPRN4(_L("CProgDLMultimediaSource::ReadRequestStatus iReadRequestPending[%d] isDownloadComplete[%d] iReOpenCAF[%d]"),iReadRequestPending,isDownloadComplete,iReOpenCAF);        
       
  1702         if(!iReadRequestPending && isDownloadComplete && !iReOpenCAF)
       
  1703             {
       
  1704             ReOpenCAF();
       
  1705             while ( !iSinkQueue->IsEmpty() )
       
  1706                 {
       
  1707                 TInt err = ServiceFillBuffer();
       
  1708                 if(err == KErrUnderflow)
       
  1709                     {
       
  1710                     StateChanged(EBUFFERING);
       
  1711                     break;
       
  1712                     }
       
  1713                 }
       
  1714             }
       
  1715         
       
  1716         return KErrNone;		
       
  1717         }
       
  1718     }
       
  1719 
       
  1720 
       
  1721 TInt CProgDLMultimediaSource::ReOpenCAF()
       
  1722     {
       
  1723     TInt status(KErrNone);
       
  1724     DEBPRN2(_L("CProgDLMultimediaSource::ReOpenCAF ReOpenCAF[%d]"),iSnkBytes);     
       
  1725     delete iFile;
       
  1726     iFile = NULL;
       
  1727     
       
  1728     if (!iFile)
       
  1729         {
       
  1730         if (iFileHandle)
       
  1731             {
       
  1732             TRAPD(status,iFile = CContentFile::NewL(iHandle, UniqueId(), iCAFParameters->iEnableUI));
       
  1733             if(status)
       
  1734                 return status;
       
  1735             }
       
  1736         else
       
  1737             {
       
  1738             // Open for read-only access
       
  1739             TRAPD(status,iFile = CContentFile::NewL(iFsSession, iFullFileName, UniqueId(), EFileShareAny, iCAFParameters->iEnableUI));
       
  1740             if(status)
       
  1741                 return status;                    
       
  1742             }
       
  1743             
       
  1744          if(!status)
       
  1745             iFile->Seek(ESeekCurrent,iSnkBytes);   
       
  1746         }
       
  1747     
       
  1748     if(iFile)
       
  1749         {
       
  1750         if(iFile->IsProtected())
       
  1751             {
       
  1752             iFile->Size(iFileSize);
       
  1753             iDownloadSize = iFileSize;
       
  1754             iDLFileSize = iFileSize;
       
  1755             
       
  1756 			if(iObserver)
       
  1757 				{
       
  1758 				iObserver->Event(KMultimediaDataSourceObserverEventSourceSizeChanged);
       
  1759 				}
       
  1760             }
       
  1761         else
       
  1762             {
       
  1763 			iFileSize = iDLFileSize;		          
       
  1764             }
       
  1765         }												
       
  1766 
       
  1767     iReOpenCAF = ETrue;
       
  1768     DEBPRN3(_L("CProgDLMultimediaSource::ReOpenCAF Exit status[%d] iFileSize[%d]"),status,iFileSize);     
       
  1769     return status;    
       
  1770     }
       
  1771 
       
  1772 void CProgDLMultimediaSource::GetAudioConfiguration()
       
  1773     {
       
  1774     TInt bufType = 0;
       
  1775     TInt bufAmount = 0;
       
  1776     TInt bufPer = 0;
       
  1777     
       
  1778     iAudioConfigRepository->Get(KPDLPrimaryBufferingType,bufType);
       
  1779     iAudioConfigRepository->Get(KPDLPrimaryBufferingAmount,bufAmount);
       
  1780     
       
  1781     iPrimaryBufferingConfig.iType = TBufferingConfig::TBufferingType(bufType);
       
  1782     iPrimaryBufferingConfig.iAmount = bufAmount;
       
  1783     
       
  1784     iAudioConfigRepository->Get(KPDLSecondaryBufferingType,bufType);
       
  1785     iAudioConfigRepository->Get(KPDLSecondaryBufferingAmount,bufAmount);
       
  1786     
       
  1787     iSecondaryBufferingConfig.iType = TBufferingConfig::TBufferingType(bufType);
       
  1788     iSecondaryBufferingConfig.iAmount = bufAmount;
       
  1789     
       
  1790     iAudioConfigRepository->Get(KPDLInitialBufferingPercentage,bufPer);
       
  1791     iInitialBufferingPercentage = bufPer;
       
  1792     }
       
  1793 
       
  1794 TInt CProgDLMultimediaSource::Seek(TUint aPosInBytes)
       
  1795     {
       
  1796     DEBPRN2(_L("CProgDLMultimediaSource::Seek[%d]]"), aPosInBytes );
       
  1797     TInt status(KErrNone);
       
  1798     if(aPosInBytes <= iFileSize)
       
  1799         {
       
  1800         iSnkBytes = aPosInBytes;
       
  1801         status = iFile->Seek(ESeekStart,iSnkBytes);
       
  1802         }
       
  1803     else
       
  1804         {
       
  1805         status = KErrNotReady;        
       
  1806         }
       
  1807     return status;
       
  1808     }
       
  1809 
       
  1810 TInt CProgDLMultimediaSource::GetSeekingSupport( TBool& aSeekSupport )
       
  1811     {
       
  1812     aSeekSupport = ETrue;
       
  1813     return KErrNone;
       
  1814     }
       
  1815 
       
  1816 TInt CProgDLMultimediaSource::GetRandomSeekingSupport( TBool& aSeekSupport )
       
  1817     {
       
  1818     aSeekSupport = ETrue;
       
  1819     return KErrNone;
       
  1820     }
       
  1821 //End of File
       
  1822