mmfenh/enhancedmediaclient/Plugins/ProgDLSource/src/ProgDLSource.cpp
changeset 0 71ca22bcf22a
child 30 ab526b8cacfb
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     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         delete request;
       
   750         iRequests.Remove(ii);
       
   751         ii--;
       
   752         }
       
   753     }
       
   754 
       
   755             
       
   756 /**
       
   757 Evaluates a given intent against the rights associated with the file.
       
   758 
       
   759 The rights are not updated by this function call.
       
   760 
       
   761 @param  aIntent
       
   762 The intent to evaluate.
       
   763 
       
   764   @return An error code indicating if the function call was successful. KErrNone on success, otherwise
       
   765   another of the system-wide error codes.
       
   766 */
       
   767 TInt CProgDLMultimediaSource::EvaluateIntent(ContentAccess::TIntent aIntent) const
       
   768     {
       
   769     if (!iFile)
       
   770         {
       
   771         return KErrNotReady;
       
   772         }
       
   773     
       
   774     return iFile->EvaluateIntent(aIntent);
       
   775     }
       
   776             
       
   777 /**
       
   778 Evaluates and executes a given intent against the rights associated with the file.
       
   779 
       
   780 The rights object is updated after calling this function.
       
   781 
       
   782 @param  aIntent
       
   783 The intent to evaluate.
       
   784 
       
   785 @return An error code indicating if the function call was successful. KErrNone on success, otherwise
       
   786 another of the system-wide error codes.
       
   787 */
       
   788 TInt CProgDLMultimediaSource::ExecuteIntent(ContentAccess::TIntent aIntent)
       
   789     {
       
   790     if (!iFile)
       
   791         {
       
   792         return KErrNotReady;
       
   793         }
       
   794     
       
   795     return iFile->ExecuteIntent(aIntent);
       
   796     }
       
   797             
       
   798 /**
       
   799 Returns whether the file is protected.
       
   800 
       
   801 @return A boolean indicating if the file is protected. ETrue if the file is protected.
       
   802 */
       
   803 TInt CProgDLMultimediaSource::GetDRMProtection(TBool& aIsProtected)
       
   804     {
       
   805     TInt err(KErrNone);	
       
   806     if (!iFile)
       
   807         {
       
   808         return KErrNotReady;
       
   809         }
       
   810     
       
   811     TRAP(err,aIsProtected = iFile->IsProtected());
       
   812     return err;
       
   813     }
       
   814             
       
   815 TInt CProgDLMultimediaSource::SetAgentProperty(ContentAccess::TAgentProperty aProperty, TInt aValue)
       
   816     {
       
   817     if (!iFile)
       
   818         {
       
   819         return KErrNotReady;
       
   820         }
       
   821     
       
   822     return iFile->SetAgentProperty(aProperty, aValue);
       
   823     }
       
   824             
       
   825 /*
       
   826 *	Returns ETrue if the request can safely be deleted.
       
   827 */
       
   828 TBool CReadWriteRequest::Completed() 
       
   829     {
       
   830     return iCompleted ;
       
   831     }
       
   832             
       
   833 TInt CReadWriteRequest::SetStatus(TBool aStatus)
       
   834     {
       
   835     iCompleted = aStatus;
       
   836     return KErrNone;
       
   837     }
       
   838 
       
   839 TBool CReadWriteRequest::SourceType() 
       
   840     {
       
   841     return iSourceType ;
       
   842     }
       
   843 
       
   844 
       
   845 /*
       
   846 *	Returns the data member of CMMFDataBuffer or CMMFTransferBuffer (as TPtr8)
       
   847 *  
       
   848 */
       
   849 TDes8& CReadWriteRequest::BufferDes()
       
   850     {
       
   851     if(iTransferBufferCopy)
       
   852         return iTransferBufferCopy->Des();
       
   853     else
       
   854         {
       
   855         //reset iBufferDes in case iBuffer has changed...
       
   856         iBufferDes = &(STATIC_CAST(CMMFDataBuffer*, iBuffer)->Data());
       
   857         return *iBufferDes;
       
   858         }
       
   859     }
       
   860 
       
   861 const TDesC8& CReadWriteRequest::BufferDesC()
       
   862     {
       
   863     if(iTransferBufferCopy)
       
   864         return iTransferBufferCopy->Des();
       
   865     else
       
   866         return BufferDes();
       
   867     }
       
   868 
       
   869 CMMFBuffer* CReadWriteRequest::Buffer()
       
   870     {
       
   871     return iBuffer;
       
   872     }
       
   873 
       
   874 TAny* CReadWriteRequest::GetSinkOrSource()
       
   875     {
       
   876     return iSinkOrSource;
       
   877     }
       
   878 
       
   879 /*
       
   880 *	Destructor.
       
   881 */
       
   882 CReadWriteRequest::~CReadWriteRequest() 
       
   883     {
       
   884     Cancel();
       
   885     if(iTransferBufferCopy)
       
   886         iTransferBufferCopy->SetInUse(EFalse);
       
   887     }
       
   888 
       
   889 /*
       
   890 *	Allows owning class access to SetActive()
       
   891 */
       
   892 void CReadWriteRequest::SetActive() 
       
   893     {
       
   894     CActive::SetActive() ;
       
   895     }
       
   896         
       
   897 /*
       
   898 *  For the moment at least...    Canceled requests may be deleted
       
   899 */
       
   900 void CReadWriteRequest::DoCancel() 
       
   901     {
       
   902     iCompleted = ETrue ;
       
   903     }
       
   904             
       
   905 /*
       
   906 *	Called when errors in RunL force Leave.  For the moment just mark the request deletable
       
   907 */
       
   908 TInt CReadWriteRequest::RunError( TInt aError ) 
       
   909     {
       
   910     //RunL can leave.
       
   911     iCompleted = ETrue ;
       
   912     iError = aError; //keep this error internally for now
       
   913     return KErrNone ;
       
   914     }
       
   915         
       
   916 /*
       
   917 *	On completion of read request call back to the MDataSink
       
   918 */
       
   919 void CReadRequest::RunL() 
       
   920     {
       
   921     //Copy the data from the normal buffer into the Transfer buffer
       
   922     if(iTransferBufferCopy)
       
   923         {
       
   924         //must specify the size here as the dest may be smaller than the source.
       
   925         TDes8& destDesc = STATIC_CAST(CMMFDataBuffer*, iBuffer)->Data();
       
   926         destDesc.Copy(iTransferBufferCopy->Des().Left(destDesc.MaxLength()));
       
   927     
       
   928         iTransferBufferCopy->SetInUse(EFalse);
       
   929         }
       
   930 
       
   931         STATIC_CAST(CProgDLMultimediaSource*,iParent)->ReadRequestStatus(STATIC_CAST(CReadWriteRequest*,this),iStatus);
       
   932     }
       
   933 
       
   934         // From CMultimediaDataSource begins
       
   935 TInt CProgDLMultimediaSource::SetObserver( MMultimediaDataSourceObserver& aObserver )
       
   936     {
       
   937     TInt status(KErrNone);
       
   938     iObserver = &aObserver;
       
   939     return status;
       
   940     }
       
   941         
       
   942 TInt CProgDLMultimediaSource::GetObserver( MMultimediaDataSourceObserver*& aObserver )
       
   943     {
       
   944     TInt status(KErrNone);
       
   945     aObserver = iObserver;
       
   946     return status;
       
   947     }
       
   948         
       
   949 void CProgDLMultimediaSource::Event( TUid aEvent )
       
   950     {
       
   951     if( aEvent == KMultimediaDataSourceEventBitRateChanged )
       
   952         {
       
   953         
       
   954         if(iObserver)
       
   955             {
       
   956                 iObserver->GetBitRate( iObserverBitRate ); 
       
   957                 if(iState == EBUFFERING)
       
   958                     CalculateBufferedDataSize();
       
   959             }
       
   960         }    
       
   961     
       
   962     }
       
   963         
       
   964 TInt CProgDLMultimediaSource::SetDataTypeCode(TFourCC aSourceFourCC )
       
   965     {
       
   966     TInt status(KErrNone);
       
   967     iSourceFourCC = aSourceFourCC;
       
   968     return status;
       
   969     }
       
   970         
       
   971 TInt CProgDLMultimediaSource::GetDataTypeCode(TFourCC& aSourceFourCC )
       
   972     {
       
   973     TInt status(KErrNone);
       
   974     aSourceFourCC = iSourceFourCC;
       
   975     return status;
       
   976     }
       
   977 
       
   978 TInt CProgDLMultimediaSource::GetSize( TUint& aSize )
       
   979     {
       
   980     TInt err = KErrNone;
       
   981     if (iDLFileSize >=0)
       
   982     	{
       
   983     	aSize = iDLFileSize;
       
   984     	}
       
   985     else
       
   986     	{
       
   987     	aSize = 0;
       
   988     	}
       
   989     return err;
       
   990     }
       
   991 
       
   992 TInt CProgDLMultimediaSource::Open()
       
   993     {
       
   994     TInt status(KErrNotReady);
       
   995     DEBPRN1(_L("CProgDLMultimediaSource::Open"));
       
   996     switch ( iState )
       
   997         {
       
   998         case ECLOSED:
       
   999             StateChanged(ESTOPPED);
       
  1000             status = KErrNone;
       
  1001             break;
       
  1002         case ESTOPPED:
       
  1003         case EPRIMED:
       
  1004         case EEXECUTING:
       
  1005         case EBUFFERING:
       
  1006         default:
       
  1007             DEBPRN2(_L("CProgDLMultimediaSource::Open[Illegal cmd on state[%d]]"), iState );
       
  1008             break;
       
  1009         };
       
  1010     return status;
       
  1011     }
       
  1012 
       
  1013 TInt CProgDLMultimediaSource::Close()
       
  1014     {
       
  1015     TInt status(KErrNone);
       
  1016     iHandle.Close();
       
  1017     iFsSession.Close();
       
  1018 
       
  1019     StateChanged(ECLOSED);
       
  1020     // Clear app buffers
       
  1021     EmptySinkQueue();
       
  1022     iSnkBytes = 0;
       
  1023     // Clear observer buffers
       
  1024     return status;
       
  1025     }
       
  1026 
       
  1027 TInt CProgDLMultimediaSource::Prime()
       
  1028     {
       
  1029     TInt status(KErrNotReady);
       
  1030     DEBPRN1(_L("CProgDLMultimediaSource::Prime"));
       
  1031     switch ( iState )
       
  1032         {
       
  1033         case ESTOPPED:
       
  1034             
       
  1035             // don't reopen file if already open
       
  1036             if (!iFile)
       
  1037                 {
       
  1038                 if (iFileHandle)
       
  1039                     {
       
  1040                     TRAPD(err,iFile = CContentFile::NewL(iHandle, UniqueId(), iCAFParameters->iEnableUI));
       
  1041                     if(err)
       
  1042                         return err;
       
  1043                     }
       
  1044                 else
       
  1045                     {
       
  1046                     // Open for read-only access
       
  1047                     TRAPD(err,iFile = CContentFile::NewL(iFsSession, iFullFileName, UniqueId(), EFileShareAny, iCAFParameters->iEnableUI));
       
  1048                     if(err)
       
  1049                         return err;                    
       
  1050                     }
       
  1051                 }
       
  1052             
       
  1053             if(iFile)
       
  1054                 {
       
  1055                 if(iFile->IsProtected())
       
  1056                     iFile->Size(iFileSize);
       
  1057                 else
       
  1058                     iFileSize = iDLFileSize;		          
       
  1059                 }												
       
  1060             
       
  1061             StateChanged(EPRIMED);
       
  1062             status = KErrNone;
       
  1063             break;
       
  1064         case EPRIMED:
       
  1065             status = KErrNone;
       
  1066             break;
       
  1067         case ECLOSED:
       
  1068         case EEXECUTING:
       
  1069         case EBUFFERING:
       
  1070         default:
       
  1071             DEBPRN2(_L("CProgDLMultimediaSource::Prime[Illegal cmd on state[%d]]"), iState );
       
  1072             break;
       
  1073         }
       
  1074     return status;
       
  1075     }
       
  1076 
       
  1077 TInt CProgDLMultimediaSource::Play()
       
  1078     {
       
  1079     TInt status(KErrNotReady);
       
  1080     DEBPRN1(_L("CProgDLMultimediaSource::Play"));
       
  1081     switch ( iState )
       
  1082         {
       
  1083         case EPRIMED:
       
  1084             CalculateBufferedDataSize();
       
  1085             StateChanged(EEXECUTING);
       
  1086             
       
  1087             while ( !iSinkQueue->IsEmpty() )
       
  1088                 {
       
  1089                 status = ServiceFillBuffer();
       
  1090                 }
       
  1091             
       
  1092             if(status == KErrUnderflow)
       
  1093                 {
       
  1094                 StateChanged(EBUFFERING);
       
  1095                 }
       
  1096             
       
  1097             status = KErrNone;	
       
  1098             break;
       
  1099         case EEXECUTING:
       
  1100         case EBUFFERING:
       
  1101             status = KErrNone;
       
  1102             // No op
       
  1103             break;
       
  1104         case ECLOSED:
       
  1105         case ESTOPPED:
       
  1106         default:
       
  1107             DEBPRN2(_L("CProgDLMultimediaSource::Play[Illegal cmd on state[%d]]"), iState );
       
  1108             break;
       
  1109         };
       
  1110     return status;
       
  1111     }
       
  1112         
       
  1113 TInt CProgDLMultimediaSource::Stop()
       
  1114     {
       
  1115     TInt status(KErrNotReady);
       
  1116     DEBPRN1(_L("CProgDLMultimediaSource::Stop"));
       
  1117     switch ( iState )
       
  1118         {
       
  1119         case EPRIMED:
       
  1120         case EEXECUTING:
       
  1121         case EBUFFERING:
       
  1122             {
       
  1123             TInt pos = 0;
       
  1124             CancelRequests();
       
  1125             delete iFile;
       
  1126             iFile = NULL;
       
  1127             //iDLFileSize = -1;
       
  1128             iSnkBytes=pos;
       
  1129             iBufferedDataSize = 0;
       
  1130             EmptySinkQueue();
       
  1131             StateChanged(ESTOPPED);
       
  1132             status = KErrNone;
       
  1133             }
       
  1134             break;
       
  1135         case ECLOSED:
       
  1136         default:
       
  1137             DEBPRN2(_L("CProgDLMultimediaSource::Stop[Illegal cmd on state[%d]]"), iState );
       
  1138             break;
       
  1139         };
       
  1140     return status;
       
  1141     }
       
  1142     
       
  1143     
       
  1144 TInt CProgDLMultimediaSource::FillBuffer( CMMFBuffer* aBuffer )
       
  1145     {
       
  1146     // Requires that iFile is open for read.
       
  1147     // Reads data from iFile into aBuffer
       
  1148     
       
  1149     TInt status(KErrNone);
       
  1150     DEBPRN2(_L("CProgDLMultimediaSource::FillBuffer[%x]]"), aBuffer );
       
  1151     if (!aBuffer)
       
  1152         return KErrArgument;
       
  1153     
       
  1154     if (!iFile)
       
  1155         return KErrNotReady;
       
  1156     
       
  1157     AppendBufferToSinkQueue(aBuffer,iObserver,NULL,EFalse);
       
  1158     
       
  1159     DEBPRN4(_L("CProgDLMultimediaSource::FillBuffer DLComplete[%d] ReOpenCAF[%d] RequestPending[%d]"), isDownloadComplete,iReOpenCAF,iReadRequestPending );
       
  1160     if(isDownloadComplete && !iReOpenCAF) 
       
  1161         {
       
  1162         if(!iReadRequestPending)
       
  1163             {
       
  1164             ReOpenCAF();                        
       
  1165             status = ServiceFillBuffer();
       
  1166             if(status == KErrUnderflow)
       
  1167                 {
       
  1168                 StateChanged(EBUFFERING);
       
  1169                 }
       
  1170             }
       
  1171         }
       
  1172     else
       
  1173         {
       
  1174         status = ServiceFillBuffer();
       
  1175         
       
  1176         if(status == KErrUnderflow)
       
  1177             {
       
  1178             StateChanged(EBUFFERING);
       
  1179             }
       
  1180         }        
       
  1181     return status; 	
       
  1182     }
       
  1183 
       
  1184     
       
  1185 TAny* CProgDLMultimediaSource::CustomInterface( TUid /*aInterfaceUid*/ )
       
  1186     {
       
  1187     return NULL;
       
  1188     }
       
  1189     
       
  1190 TInt CProgDLMultimediaSource::AppendBufferToSinkQueue( CMMFBuffer* aBuffer,
       
  1191                                                     MMultimediaDataSourceObserver* aObserver,
       
  1192                                                     MDataSink* aConsumer,TBool aTop )  
       
  1193     {
       
  1194     TInt status(KErrNone);
       
  1195     
       
  1196     DEBPRN2(_L("CProgDLMultimediaSource::AppendBufferToSinkQueue() Buffer[%x]"), aBuffer );				    
       
  1197     // Add observer buffer to queue
       
  1198     CMMFDataBuffer* dest = static_cast<CMMFDataBuffer*>( aBuffer );
       
  1199     TDes8& destBufferDes = dest->Data();
       
  1200     
       
  1201     CSinkQueueItem* request(NULL);
       
  1202     
       
  1203     TRAP( status, request = CSinkQueueItem::NewL( aBuffer, aObserver,aConsumer) );
       
  1204     if ( status == KErrNone )
       
  1205         {
       
  1206         if(aTop)
       
  1207             iSinkQueue->AddFirst(*request);
       
  1208         else  
       
  1209             iSinkQueue->AddLast(*request);
       
  1210         
       
  1211         iSnkItemsCount++;
       
  1212         
       
  1213         DEBPRN3(_L("CProgDLMultimediaSource::AppendBufferToQueue[ReqSize[%d]SnkItems[%d]]"), \
       
  1214             aBuffer->RequestSize(), iSnkItemsCount );
       
  1215         }
       
  1216     return status;
       
  1217     }
       
  1218     
       
  1219 void CProgDLMultimediaSource::SourceCustomCommand(TMMFMessage& aMessage)
       
  1220     {
       
  1221     TInt err(KErrNone);
       
  1222     switch ( aMessage.Function() )
       
  1223         {
       
  1224         
       
  1225         case ESetUpdateFileName:
       
  1226             {
       
  1227             // Read size info
       
  1228             TPckgBuf<TFileName> sizePckg;
       
  1229             err = aMessage.ReadData1FromClient(sizePckg);
       
  1230             if ( err == KErrNone )
       
  1231                 {
       
  1232                 iFullFileName = sizePckg();
       
  1233                 }
       
  1234             aMessage.Complete(KErrNone);			            
       
  1235             
       
  1236             }   
       
  1237             break;
       
  1238 
       
  1239         case EDownloadRate:
       
  1240             {
       
  1241             
       
  1242             // Read size info
       
  1243             TPckgBuf<TUint> sizePckg;
       
  1244             err = aMessage.ReadData1FromClient(sizePckg);
       
  1245             if ( err == KErrNone )
       
  1246                 {
       
  1247                 iTransferRate = sizePckg();
       
  1248                 }
       
  1249             aMessage.Complete(KErrNone);			            
       
  1250             DEBPRN2(_L("CProgDLMultimediaSource::SourceCustomCommand EDownloadRate[%u] "),iTransferRate);
       
  1251             if(iState == EBUFFERING /*&& !iSinkQueue->IsEmpty()*/)
       
  1252                 { 
       
  1253                 CalculateBufferedDataSize();
       
  1254                 }
       
  1255             }   
       
  1256             break;
       
  1257         case ESetDownloadState:
       
  1258             {
       
  1259             isDownloadComplete = ETrue;    
       
  1260             if(iFile)
       
  1261                 iFile->Size(iFileSize);
       
  1262             
       
  1263             if(iFileSize != iDLFileSize)
       
  1264                 iDLFileSize = iFileSize;
       
  1265             
       
  1266             iDownloadSize =  iFileSize;
       
  1267             iBufferedDataSize = 0;
       
  1268             aMessage.Complete(KErrNone);
       
  1269     
       
  1270             if(iObserver)
       
  1271                 iObserver->Event(KMultimediaDataSourceEventRandomSeekingSupportChanged);	
       
  1272             
       
  1273             if(iState == EBUFFERING )
       
  1274                 {
       
  1275                 if((iDownloadSize - iSnkBytes) > iBufferedDataSize)
       
  1276                     {
       
  1277                     StateChanged(EEXECUTING);
       
  1278                     while ( !iSinkQueue->IsEmpty() )
       
  1279                         {
       
  1280                         err = ServiceFillBuffer();
       
  1281                         if(err == KErrUnderflow)
       
  1282                             {
       
  1283                             StateChanged(EBUFFERING);
       
  1284                             break;
       
  1285                             }
       
  1286                         }
       
  1287                     }
       
  1288                 }
       
  1289             }
       
  1290             break;
       
  1291             
       
  1292         case ESetDownloadSize:
       
  1293             {
       
  1294             // Read size info
       
  1295             TPckgBuf<TInt> sizePckg;
       
  1296             err = aMessage.ReadData1FromClient(sizePckg);
       
  1297             if ( err == KErrNone )
       
  1298                 {
       
  1299                 iDownloadSize = sizePckg();
       
  1300                 }
       
  1301             aMessage.Complete(KErrNone);			
       
  1302             TInt size = 0;
       
  1303 
       
  1304             if(iFile)
       
  1305                 iFile->Size(size);
       
  1306             
       
  1307             DEBPRN4(_L("CProgDLMultimediaSource::SourceCustomCommand ********BufferedDataSize[%u] DownloadSize[%d] iSnkbytes[%d]"), iBufferedDataSize ,iDownloadSize, iSnkBytes ); 		            
       
  1308             DEBPRN4(_L("CProgDLMultimediaSource::SourceCustomCommand ********iDLFileSize[%d] iFileSize[%d]ActualSize[%d]"), iDLFileSize,iFileSize,size); 		            
       
  1309             if(iState == EBUFFERING )
       
  1310                 {
       
  1311                 if((iDownloadSize - iSnkBytes) > iBufferedDataSize)
       
  1312                     {
       
  1313                     StateChanged(EEXECUTING);
       
  1314                     while ( !iSinkQueue->IsEmpty() )
       
  1315                         {
       
  1316                         err = ServiceFillBuffer();
       
  1317                         if(err == KErrUnderflow)
       
  1318                             {
       
  1319                             StateChanged(EBUFFERING);
       
  1320                             break;
       
  1321                             }
       
  1322                         }
       
  1323                     }
       
  1324                 }			
       
  1325             }
       
  1326             break;
       
  1327                 
       
  1328         case ESetActualSize:
       
  1329             {
       
  1330             // Read size info
       
  1331             TPckgBuf<TInt> sizePckg;
       
  1332             err = aMessage.ReadData1FromClient(sizePckg);
       
  1333             if ( err == KErrNone )
       
  1334                 {
       
  1335                 iDLFileSize = sizePckg();
       
  1336                 }
       
  1337             aMessage.Complete(KErrNone);
       
  1338             
       
  1339             if(iFile)
       
  1340                 {
       
  1341                 if(iFile->IsProtected())
       
  1342                     iFile->Size(iFileSize);
       
  1343                 else
       
  1344                     iFileSize = iDLFileSize;		          
       
  1345                 }
       
  1346             DEBPRN3(_L("CProgDLMultimediaSource::SourceCustomCommand ActualSize********iDLFileSize[%d] iFileSize[%d]"), iDLFileSize,iFileSize); 		            
       
  1347             
       
  1348             if(iObserver)
       
  1349                 iObserver->Event(KMultimediaDataSourceObserverEventSourceSizeChanged);
       
  1350             
       
  1351             }
       
  1352             break;   
       
  1353                 
       
  1354         case EGetSourceState:
       
  1355             {
       
  1356             TPckgBuf<TState> statePckg;	
       
  1357             aMessage.ReadData1FromClient(statePckg);
       
  1358             DEBPRN3(_L("CProgDLMultimediaSource::SourceCustomCommand() Client State[%d] SourceState[%d]"), statePckg(), iState);
       
  1359             
       
  1360             if(iState != statePckg())
       
  1361                 {
       
  1362                 statePckg() = iState;	
       
  1363                 aMessage.WriteDataToClient(statePckg);
       
  1364                 aMessage.Complete(KErrNone);
       
  1365                 }
       
  1366             else
       
  1367                 iMessage = new(ELeave) TMMFMessage(aMessage);
       
  1368              }   
       
  1369             break;   
       
  1370 
       
  1371         case EGetBitRate:
       
  1372             {
       
  1373             TPckgBuf<TUint> bitRatePckg;	 
       
  1374             DEBPRN2(_L("CProgDLMultimediaSource::SourceCustomCommand() Client BitRateFromS[%d]"),iObserverBitRate);
       
  1375             bitRatePckg() = iObserverBitRate ;	
       
  1376             aMessage.WriteDataToClient(bitRatePckg);
       
  1377             aMessage.Complete(KErrNone);
       
  1378             }            
       
  1379             break;   
       
  1380 
       
  1381         case EGetPercentageBuffered:
       
  1382             {
       
  1383             TPckgBuf<TUint> perBufPckg; 
       
  1384             TUint perBuf = 0;
       
  1385             if(iState == EBUFFERING && iBufferedDataSize != 0)
       
  1386                 {
       
  1387                 CalculateBufferedDataSize();                    
       
  1388                 if ( iBufferedDataSize == 0 ) 
       
  1389                     {
       
  1390                     perBuf = 0; 
       
  1391                     }
       
  1392                 else
       
  1393                     {
       
  1394                     perBuf = (iDownloadSize - iSnkBytes) * 100 / iBufferedDataSize;
       
  1395                     }
       
  1396                 }
       
  1397             
       
  1398             RDebug::Print(_L(" Percentage Buffered [%d]"),perBuf);
       
  1399             perBufPckg() = perBuf;
       
  1400             aMessage.WriteDataToClient(perBufPckg);
       
  1401             aMessage.Complete(KErrNone);
       
  1402             }
       
  1403             break;   
       
  1404                 
       
  1405         default:
       
  1406             err = KErrArgument;
       
  1407             break;
       
  1408         }
       
  1409     }        
       
  1410 
       
  1411 TInt CProgDLMultimediaSource::ServiceFillBuffer()
       
  1412     {
       
  1413     
       
  1414     DEBPRN3(_L("CProgDLMultimediaSource::ServiceFillBuffer() state[%d] Download Size[%d]"), iState ,iDownloadSize );
       
  1415     
       
  1416     TInt status(KErrNone);
       
  1417     if ( iSinkQueue->IsEmpty() )
       
  1418         return KErrNone;
       
  1419     
       
  1420     CSinkQueueItem* tempsnkItem = iSinkQueue->First();
       
  1421     CMMFBuffer* tempbuffer = tempsnkItem->Buffer();
       
  1422     
       
  1423     TInt bufSize = tempbuffer->RequestSize();
       
  1424     
       
  1425     DEBPRN5(_L("CProgDLMultimediaSource::ServiceFillBuffer() ********BufferedDataSize[%u] DownloadSize[%d] iSnkbytes[%d] BufSize[%d]"), iBufferedDataSize ,iDownloadSize, iSnkBytes,bufSize ); 		            				
       
  1426     if((((iDownloadSize - iSnkBytes) > bufSize) && 
       
  1427         iState == EEXECUTING && 
       
  1428         iDownloadSize > iBufferedDataSize && ((iReadRequestPending + 1)*bufSize < (iDownloadSize - iSnkBytes))) || (iFileSize == iDownloadSize))
       
  1429         {
       
  1430         iReadRequestPending++;
       
  1431         CSinkQueueItem* snkItem = iSinkQueue->First();
       
  1432         iSinkQueue->Remove(*snkItem);
       
  1433         iSnkItemsCount--;
       
  1434         CMMFBuffer* buffer = snkItem->Buffer();
       
  1435         DEBPRN2(_L("CProgDLMultimediaSource::ServiceFillBuffer() Buffer[%x]"), buffer );				    
       
  1436         MMultimediaDataSourceObserver* observer = snkItem->Observer();
       
  1437         MDataSink* consumer = snkItem->Consumer();
       
  1438         delete snkItem;
       
  1439         
       
  1440         if (CMMFBuffer::IsSupportedDataBuffer(buffer->Type()))
       
  1441             {
       
  1442             CTransferBufferCopy* transBufCopy = NULL;
       
  1443             CReadRequest* request = NULL;
       
  1444             
       
  1445             TDes8& bufferDes = STATIC_CAST( CMMFDataBuffer*, buffer )->Data();
       
  1446             
       
  1447             TInt requestSize;
       
  1448             if(buffer->RequestSize())
       
  1449                 requestSize = buffer->RequestSize();
       
  1450             else
       
  1451                 requestSize = bufferDes.MaxLength();
       
  1452             
       
  1453             //check whether buffer is safe to send to file server
       
  1454             //if not, eg for a transfer buffer, then it needs to be copied
       
  1455             if (!CMMFBuffer::IsFileServerSafe(buffer->Type()))
       
  1456                 {
       
  1457                 //NB: failure in this method will NOT cause transBufCopy to leak as it will be 
       
  1458                 //inserted into iTransferBufferCopies by ObtainCopyOfTransferBufferL.
       
  1459                 TRAP(status,transBufCopy = ObtainCopyOfTransferBufferL(bufferDes.MaxLength()));
       
  1460                 
       
  1461                 if(consumer && !observer)
       
  1462                     request = new(ELeave) CReadRequest(this,STATIC_CAST(TAny*, consumer), buffer, transBufCopy, iSnkBytes, iDownloadSize, ETrue);
       
  1463                 else
       
  1464                     request = new(ELeave) CReadRequest(this,STATIC_CAST(TAny*, observer), buffer, transBufCopy, iSnkBytes, iDownloadSize, EFalse);					
       
  1465                 
       
  1466                 }
       
  1467             else
       
  1468                 {
       
  1469                 if(consumer && !observer)
       
  1470                     request = new(ELeave) CReadRequest(this,STATIC_CAST(TAny*, consumer), buffer, iSnkBytes, iDownloadSize, ETrue);
       
  1471                 else
       
  1472                     request = new(ELeave) CReadRequest(this,STATIC_CAST(TAny*, observer), buffer, iSnkBytes, iDownloadSize, EFalse);					
       
  1473                 }
       
  1474             
       
  1475             CleanupStack::PushL( request );
       
  1476             
       
  1477             TRAP_IGNORE(StoreRequestL(request)); // transfers ownership
       
  1478             CleanupStack::Pop() ; // request
       
  1479             
       
  1480             request->SetActive();
       
  1481             
       
  1482             //	iSnkBytes += requestSize;
       
  1483             
       
  1484             if ((iSnkBytes + request->Buffer()->RequestSize()) >= iDownloadSize && isDownloadComplete)
       
  1485                 {
       
  1486     	              request->Buffer()->SetLastBuffer(ETrue);
       
  1487                       DEBPRN1(_L("CProgDLMultimediaSource::ServiceFillBuffer() LastBuffer$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"));
       
  1488                 }
       
  1489             
       
  1490             iFile->Read(request->BufferDes(), requestSize, request->iStatus);
       
  1491             
       
  1492             }
       
  1493         else // if (CMMFBuffer::IsSupportedDataBuffer(buffer->Type()))
       
  1494             return KErrNotSupported;
       
  1495         }
       
  1496         /*else if(iDownloadSize == iSnkBytes)
       
  1497         {
       
  1498         Stop();
       
  1499     }*/
       
  1500     else
       
  1501         {
       
  1502         
       
  1503         //StateChanged(EBUFFERING);
       
  1504         return KErrUnderflow;
       
  1505         }
       
  1506     return status;
       
  1507     }
       
  1508 
       
  1509 TInt CProgDLMultimediaSource::EmptySinkQueue()
       
  1510     {
       
  1511     TInt status(KErrNone);
       
  1512     // Empty sink queue
       
  1513     CSinkQueueItem* snkItem;
       
  1514     while ( !iSinkQueue->IsEmpty() )
       
  1515         {
       
  1516         snkItem = iSinkQueue->First();
       
  1517         iSinkQueue->Remove(*snkItem);
       
  1518         delete snkItem;
       
  1519         }
       
  1520     
       
  1521     iSnkItemsCount = 0;
       
  1522     return status;
       
  1523     }
       
  1524 
       
  1525 void CProgDLMultimediaSource::CalculateBufferedDataSize()
       
  1526     {
       
  1527     DEBPRN1(_L("CProgDLMultimediaSource::CalculateBufferedDataSize()"));
       
  1528     iBufferedDataSize = 0;
       
  1529     
       
  1530     // Get the bit rate from observer
       
  1531     if(iObserver)
       
  1532         iObserver->GetBitRate( iObserverBitRate );
       
  1533     
       
  1534     // If we don't know observer bit rate
       
  1535     if(iDownloadSize == iDLFileSize)
       
  1536         {
       
  1537         iBufferedDataSize = 0;
       
  1538         return;
       
  1539         }   
       
  1540 
       
  1541     if(iObserverBitRate == 0 && (iSinkQueue->First() != NULL))
       
  1542         {
       
  1543             if(iPrimaryBufferingConfig.iType == TBufferingConfig::FIXEDDURATION
       
  1544             || iPrimaryBufferingConfig.iType == TBufferingConfig::DYNAMICDURATION)
       
  1545                 {
       
  1546                     if(iSecondaryBufferingConfig.iType == TBufferingConfig::FIXEDDURATION
       
  1547                     || iSecondaryBufferingConfig.iType == TBufferingConfig::DYNAMICDURATION)
       
  1548                         {
       
  1549                         iBufferedDataSize =  iDLFileSize * iInitialBufferingPercentage / 100;       
       
  1550                         }
       
  1551                     else
       
  1552                         {
       
  1553                         if(iDLFileSize < iSecondaryBufferingConfig.iAmount)
       
  1554                             {
       
  1555                             iBufferedDataSize = iDLFileSize;
       
  1556                             }
       
  1557                         else
       
  1558                             {
       
  1559                             iBufferedDataSize = iSecondaryBufferingConfig.iAmount;
       
  1560                             }
       
  1561                         }    
       
  1562                 }
       
  1563             else
       
  1564                 {
       
  1565                 if(iDLFileSize < iPrimaryBufferingConfig.iAmount)
       
  1566                     {
       
  1567                     iBufferedDataSize = iDLFileSize;
       
  1568                     }
       
  1569                 else
       
  1570                     {
       
  1571                     iBufferedDataSize = iPrimaryBufferingConfig.iAmount;
       
  1572                     }
       
  1573                 }                
       
  1574             
       
  1575         }
       
  1576      else
       
  1577         {
       
  1578             if(iPrimaryBufferingConfig.iType == TBufferingConfig::FIXEDDURATION
       
  1579             || iPrimaryBufferingConfig.iType == TBufferingConfig::DYNAMICDURATION)
       
  1580                 {
       
  1581                 TUint constantC = KMinPlaybackDuration * iObserverBitRate / 8;
       
  1582 
       
  1583                 // calculate time remaining
       
  1584                 //TInt64 timeRemaining = ( iDLFileSize - iSnkBytes ) * 8 / iObserverBitRate;
       
  1585                 TUint bytesRemaining = iDLFileSize - iSnkBytes;
       
  1586                 iBufferedDataSize = bytesRemaining < constantC ? bytesRemaining : constantC;
       
  1587 
       
  1588 //                timeRemaining = timeRemaining < 0 ? 0 : timeRemaining;
       
  1589 
       
  1590                 // calculate the value in a temporary variable
       
  1591 //                TInt64 bufferedDataSize = ((TInt64(iObserverBitRate)) - (TInt64(iTransferRate))) * timeRemaining / 8;
       
  1592 //                bufferedDataSize = bufferedDataSize < constantC ? bufferedDataSize : constantC;
       
  1593 
       
  1594 //                iBufferedDataSize = bufferedDataSize > KMaxTUint ? KMaxTUint : I64LOW(bufferedDataSize);
       
  1595                 }
       
  1596             else
       
  1597                 {
       
  1598                 iBufferedDataSize = iPrimaryBufferingConfig.iAmount;
       
  1599                 }                
       
  1600         }   
       
  1601 
       
  1602     DEBPRN5(_L("CProgDLMultimediaSource::CalculateBufferdDataSize[%u] ObserverBitRate[%d] SnkBytes[%u] TransferRate[%d]"), iBufferedDataSize,iObserverBitRate,iSnkBytes,iTransferRate );
       
  1603     }
       
  1604 
       
  1605 void CProgDLMultimediaSource::StateChanged(TState newState)
       
  1606     {
       
  1607     DEBPRN3(_L("CProgDLMultimediaSource::StateChanged OLD[%d] NEW[%d]"),iState, newState);        
       
  1608     if(iState != newState)
       
  1609         {
       
  1610         if(iMessage)
       
  1611             {
       
  1612             if(!iMessage->IsCompleted())
       
  1613                 {
       
  1614                 TPckgBuf<TState> statePckg(newState);	
       
  1615                 iMessage->WriteDataToClient(statePckg);
       
  1616                 iMessage->Complete(KErrNone);
       
  1617                 delete iMessage;
       
  1618                 iMessage = NULL;
       
  1619                 }
       
  1620             }
       
  1621         iState = newState;
       
  1622         }
       
  1623     }
       
  1624 
       
  1625 TInt CProgDLMultimediaSource::ReadRequestStatus(CReadWriteRequest* aRequest, TRequestStatus& aStatus)
       
  1626     {
       
  1627     
       
  1628     if(aStatus != KErrNone)
       
  1629         {
       
  1630         TMMFEvent event(KMMFErrorCategoryControllerGeneralError, aStatus.Int());
       
  1631         iEventHandler->SendEventToClient(event);
       
  1632         return KErrNone;
       
  1633         }
       
  1634     else
       
  1635         {
       
  1636         
       
  1637         DEBPRN4(_L("CProgDLMultimediaSource::ReadRequestStatus Buffer[%x] BufferSize[%d] RequestSize[%d]"),aRequest->Buffer(),aRequest->Buffer()->BufferSize(),aRequest->Buffer()->RequestSize());
       
  1638         DEBPRN3(_L("CProgDLMultimediaSource::ReadRequestStatus Buffer[%x] LastBuffer[%d]"),aRequest->Buffer(),aRequest->Buffer()->LastBuffer());
       
  1639         
       
  1640         TBool lastBuffer = aRequest->Buffer()->LastBuffer();
       
  1641         
       
  1642         if((aRequest->Buffer()->BufferSize() != aRequest->Buffer()->RequestSize()) && !lastBuffer)
       
  1643             {
       
  1644             if(aRequest->SourceType())
       
  1645                 {
       
  1646                 MDataSink* sinkOrSource = REINTERPRET_CAST(MDataSink*,aRequest->GetSinkOrSource());
       
  1647                 TUint position = aRequest->Buffer()->Position();
       
  1648                 TUint newPos = position - aRequest->Buffer()->BufferSize();
       
  1649                 aRequest->Buffer()->SetPosition(newPos);
       
  1650                 AppendBufferToSinkQueue(aRequest->Buffer(),(MMultimediaDataSourceObserver*)NULL,sinkOrSource,ETrue);
       
  1651                 //iSnkBytes -= aRequest->Buffer()->BufferSize();
       
  1652                 iFile->Seek(ESeekStart,iSnkBytes);
       
  1653                 StateChanged(EBUFFERING);
       
  1654                 }
       
  1655             else
       
  1656                 {
       
  1657                 MMultimediaDataSourceObserver* sinkOrSource = REINTERPRET_CAST(MMultimediaDataSourceObserver*,aRequest->GetSinkOrSource());
       
  1658                 TInt position = aRequest->Buffer()->Position();
       
  1659                 TInt newPos = position - aRequest->Buffer()->BufferSize();
       
  1660                 aRequest->Buffer()->SetPosition(newPos);
       
  1661                 AppendBufferToSinkQueue(aRequest->Buffer(),sinkOrSource,(MDataSink*)NULL,ETrue);
       
  1662                 //iSnkBytes -= aRequest->Buffer()->BufferSize();
       
  1663                 iFile->Seek(ESeekStart,iSnkBytes);
       
  1664                 StateChanged(EBUFFERING);
       
  1665                 }
       
  1666             }
       
  1667         else
       
  1668             {	
       
  1669             iSnkBytes += aRequest->Buffer()->BufferSize();
       
  1670             
       
  1671             
       
  1672             if(aRequest->SourceType())
       
  1673                     REINTERPRET_CAST(MDataSink*, aRequest->GetSinkOrSource())->BufferFilledL(aRequest->Buffer()) ; // callback to MDataSource/Sink
       
  1674             else
       
  1675                     REINTERPRET_CAST(MMultimediaDataSourceObserver*, aRequest->GetSinkOrSource())->BufferFilled(aRequest->Buffer()) ; // callback to MDataSource/Sink			
       
  1676                 
       
  1677                 
       
  1678             }
       
  1679             
       
  1680         iReadRequestPending--;
       
  1681         DEBPRN4(_L("CProgDLMultimediaSource::ReadRequestStatus iReadRequestPending[%d] isDownloadComplete[%d] iReOpenCAF[%d]"),iReadRequestPending,isDownloadComplete,iReOpenCAF);        
       
  1682         if(!iReadRequestPending && isDownloadComplete && !iReOpenCAF)
       
  1683             {
       
  1684             ReOpenCAF();
       
  1685             while ( !iSinkQueue->IsEmpty() )
       
  1686                 {
       
  1687                 TInt err = ServiceFillBuffer();
       
  1688                 if(err == KErrUnderflow)
       
  1689                     {
       
  1690                     StateChanged(EBUFFERING);
       
  1691                     break;
       
  1692                     }
       
  1693                 }
       
  1694             }
       
  1695         
       
  1696         aRequest->SetStatus(ETrue);
       
  1697         return KErrNone;		
       
  1698         }
       
  1699     }
       
  1700 
       
  1701 
       
  1702 TInt CProgDLMultimediaSource::ReOpenCAF()
       
  1703     {
       
  1704     TInt status(KErrNone);
       
  1705     DEBPRN2(_L("CProgDLMultimediaSource::StateChanged ReOpenCAF[%d]"),iSnkBytes);     
       
  1706     delete iFile;
       
  1707     iFile = NULL;
       
  1708     
       
  1709     if (!iFile)
       
  1710         {
       
  1711         if (iFileHandle)
       
  1712             {
       
  1713             TRAPD(status,iFile = CContentFile::NewL(iHandle, UniqueId(), iCAFParameters->iEnableUI));
       
  1714             if(status)
       
  1715                 return status;
       
  1716             }
       
  1717         else
       
  1718             {
       
  1719             // Open for read-only access
       
  1720             TRAPD(status,iFile = CContentFile::NewL(iFsSession, iFullFileName, UniqueId(), EFileShareAny, iCAFParameters->iEnableUI));
       
  1721             if(status)
       
  1722                 return status;                    
       
  1723             }
       
  1724             
       
  1725          if(!status)
       
  1726             iFile->Seek(ESeekCurrent,iSnkBytes);   
       
  1727         }
       
  1728     
       
  1729     if(iFile)
       
  1730         {
       
  1731         if(iFile->IsProtected())
       
  1732             {
       
  1733             iFile->Size(iFileSize);
       
  1734             iDownloadSize = iFileSize;
       
  1735             iDLFileSize = iFileSize;
       
  1736             
       
  1737 			if(iObserver)
       
  1738 				{
       
  1739 				iObserver->Event(KMultimediaDataSourceObserverEventSourceSizeChanged);
       
  1740 				}
       
  1741             }
       
  1742         else
       
  1743             {
       
  1744 			iFileSize = iDLFileSize;		          
       
  1745             }
       
  1746         }												
       
  1747 
       
  1748     iReOpenCAF = ETrue;
       
  1749     DEBPRN3(_L("CProgDLMultimediaSource::StateChanged Exit status[%d] iFileSize[%d]"),status,iFileSize);     
       
  1750     return status;    
       
  1751     }
       
  1752 
       
  1753 void CProgDLMultimediaSource::GetAudioConfiguration()
       
  1754     {
       
  1755     TInt bufType = 0;
       
  1756     TInt bufAmount = 0;
       
  1757     TInt bufPer = 0;
       
  1758     
       
  1759     iAudioConfigRepository->Get(KPDLPrimaryBufferingType,bufType);
       
  1760     iAudioConfigRepository->Get(KPDLPrimaryBufferingAmount,bufAmount);
       
  1761     
       
  1762     iPrimaryBufferingConfig.iType = TBufferingConfig::TBufferingType(bufType);
       
  1763     iPrimaryBufferingConfig.iAmount = bufAmount;
       
  1764     
       
  1765     iAudioConfigRepository->Get(KPDLSecondaryBufferingType,bufType);
       
  1766     iAudioConfigRepository->Get(KPDLSecondaryBufferingAmount,bufAmount);
       
  1767     
       
  1768     iSecondaryBufferingConfig.iType = TBufferingConfig::TBufferingType(bufType);
       
  1769     iSecondaryBufferingConfig.iAmount = bufAmount;
       
  1770     
       
  1771     iAudioConfigRepository->Get(KPDLInitialBufferingPercentage,bufPer);
       
  1772     iInitialBufferingPercentage = bufPer;
       
  1773     }
       
  1774 
       
  1775 TInt CProgDLMultimediaSource::Seek(TUint aPosInBytes)
       
  1776     {
       
  1777     DEBPRN2(_L("CProgDLMultimediaSource::Seek[%d]]"), aPosInBytes );
       
  1778     TInt status(KErrNone);
       
  1779     if(aPosInBytes <= iFileSize)
       
  1780         {
       
  1781         iSnkBytes = aPosInBytes;
       
  1782         status = iFile->Seek(ESeekStart,iSnkBytes);
       
  1783         }
       
  1784     else
       
  1785         {
       
  1786         status = KErrNotReady;        
       
  1787         }
       
  1788     return status;
       
  1789     }
       
  1790 
       
  1791 TInt CProgDLMultimediaSource::GetSeekingSupport( TBool& aSeekSupport )
       
  1792     {
       
  1793     aSeekSupport = ETrue;
       
  1794     return KErrNone;
       
  1795     }
       
  1796 
       
  1797 TInt CProgDLMultimediaSource::GetRandomSeekingSupport( TBool& aSeekSupport )
       
  1798     {
       
  1799     aSeekSupport = ETrue;
       
  1800     return KErrNone;
       
  1801     }
       
  1802 //End of File
       
  1803