mmfenh/progressivedownload/ProgressiveDownloadUtility/src/EMCPdPlayUtility.cpp
changeset 0 71ca22bcf22a
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Progressive Download Utility
       
    15 *
       
    16 */
       
    17 
       
    18 #include <bautils.h>
       
    19 #include <utf.h>
       
    20 #include <mmfpaniccodes.h>
       
    21 #include "EMCPdPlayUtility.h"
       
    22 #include "EMCPdProperties.h"
       
    23 #include "MProgressiveDownloadUtility.h"
       
    24 #include <apgcli.h>
       
    25 #include <AudioPreference.h>
       
    26 #include <SCCustomInterfaceUIDs.h>
       
    27 #include <drmagents.h>
       
    28 #include <DRMConfigIntfc.h>
       
    29 #include <content.h>
       
    30 #include <data.h>
       
    31 #include <MetaDataFieldContainer.h>
       
    32 #include <MetaDataUtility.h>
       
    33 #include <mmfmeta.h>
       
    34 
       
    35 _LIT8(KWMAMimeType,"audio/x-ms-wma");
       
    36 
       
    37 using namespace ContentAccess;
       
    38 using namespace DRM;
       
    39 
       
    40 #ifdef _DEBUG
       
    41 #define DEBPRN1(str)        RDebug::Print(str);
       
    42 #define DEBPRN2(str, val1)   RDebug::Print(str, val1);
       
    43 #define DEBPRN3(str, val1, val2)   RDebug::Print(str, val1, val2);
       
    44 #define DEBPRN4(str, val1, val2, val3)   RDebug::Print(str, val1, val2, val3);
       
    45 #define DEBPRN5(str, val1, val2, val3, val4)   RDebug::Print(str, val1, val2, val3, val4);
       
    46 #else
       
    47 #define DEBPRN1(str)
       
    48 #define DEBPRN2(str, val1)
       
    49 #define DEBPRN3(str, val1, val2)
       
    50 #define DEBPRN4(str, val1, val2, val3)
       
    51 #define DEBPRN5(str, val1, val2, val3, val4)
       
    52 #endif // _DEBUG
       
    53 
       
    54 const TInt KNumberOfBuffers = 10;
       
    55 //const TUid KUidProgressiveDlSource	= {KProgressiveDownloadSourceUid};
       
    56 const TInt KBufferingAmount = 40960;
       
    57 
       
    58 void Panic(TInt aPanicCode)
       
    59 	{
       
    60 	_LIT(KProgressiveDownloadUtility, "ProgressiveDownloadUtility");
       
    61 	User::Panic(KProgressiveDownloadUtility, aPanicCode);
       
    62 	}
       
    63 
       
    64 CAudioPdPlayUtility* CAudioPdPlayUtility::NewL(MAudioPdPlayUtilityCallback& aCallback)
       
    65 	{
       
    66     CAudioPdPlayUtility* self = new(ELeave) CAudioPdPlayUtility();
       
    67 	CleanupStack::PushL(self);
       
    68 
       
    69  	self->iProperties = CAudioPdProperties::NewL(aCallback);
       
    70 	CleanupStack::Pop(self);
       
    71 	return self;
       
    72 	}
       
    73 
       
    74 CAudioPdPlayUtility::~CAudioPdPlayUtility()
       
    75 	{
       
    76 	delete iProperties;
       
    77 	}
       
    78 
       
    79 CAudioPdPlayUtility::CAudioPdPlayUtility()
       
    80 	{
       
    81 
       
    82 	}
       
    83 
       
    84 void CAudioPdPlayUtility::ConstructL()
       
    85 	{
       
    86 
       
    87 	}
       
    88 
       
    89 //For Download Status
       
    90 void CAudioPdPlayUtility::HandleDownloadEventL(TUint aTransactionID,
       
    91                                                TBrCtlDownloadEvent aEvent,
       
    92                                                TUint aValue)
       
    93 	{
       
    94     iProperties->HandleDownloadEventL(aTransactionID,aEvent,aValue);
       
    95 	}
       
    96 
       
    97 
       
    98 void CAudioPdPlayUtility::Play()
       
    99 	{
       
   100     iProperties->Play();
       
   101 	}
       
   102 void CAudioPdPlayUtility::Stop()
       
   103 	{
       
   104     iProperties->Stop();
       
   105 	}
       
   106 TInt CAudioPdPlayUtility::Pause()
       
   107 	{
       
   108     return iProperties->Pause();
       
   109 	}
       
   110 void CAudioPdPlayUtility::SetVolume(TInt aVolume)
       
   111 	{
       
   112     iProperties->SetVolume(aVolume);
       
   113 	}
       
   114 void CAudioPdPlayUtility::SetRepeats(TInt aRepeatNumberOfTimes, const TTimeIntervalMicroSeconds& aTrailingSilence)
       
   115 	{
       
   116     iProperties->SetRepeats(aRepeatNumberOfTimes,aTrailingSilence);
       
   117 	}
       
   118 void CAudioPdPlayUtility::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration)
       
   119 	{
       
   120     iProperties->SetVolumeRamp(aRampDuration);
       
   121 	}
       
   122 const TTimeIntervalMicroSeconds& CAudioPdPlayUtility::Duration()
       
   123 	{
       
   124 	return iProperties->Duration();
       
   125 	}
       
   126 TInt CAudioPdPlayUtility:: MaxVolume()
       
   127 	{
       
   128 	return iProperties->MaxVolume();
       
   129 	}
       
   130 void CAudioPdPlayUtility::Close()
       
   131 	{
       
   132     iProperties->Close();
       
   133 	}
       
   134 TInt CAudioPdPlayUtility::GetPosition(TTimeIntervalMicroSeconds& aPosition)
       
   135 	{
       
   136     return iProperties->GetPosition(aPosition);
       
   137 	}
       
   138 void CAudioPdPlayUtility::SetPosition(const TTimeIntervalMicroSeconds& aPosition)
       
   139 	{
       
   140     iProperties->SetPosition(aPosition);
       
   141 	}
       
   142 
       
   143 TInt CAudioPdPlayUtility::SetPriority(TInt aPriority, TMdaPriorityPreference aPref)
       
   144 	{
       
   145     return iProperties->SetPriority(aPriority,aPref);
       
   146 	}
       
   147 TInt CAudioPdPlayUtility::GetVolume(TInt& aVolume)
       
   148 	{
       
   149     return iProperties->GetVolume(aVolume);
       
   150 	}
       
   151 TInt CAudioPdPlayUtility::GetNumberOfMetaDataEntries(TInt& aNumEntries)
       
   152 	{
       
   153     return iProperties->GetNumberOfMetaDataEntries(aNumEntries);
       
   154 	}
       
   155 
       
   156 
       
   157 CMMFMetaDataEntry* CAudioPdPlayUtility::GetMetaDataEntryL(TInt aMetaDataIndex)
       
   158 	{
       
   159 	return iProperties->GetMetaDataEntryL(aMetaDataIndex);
       
   160 	}
       
   161 
       
   162 TInt CAudioPdPlayUtility::SetPlayWindow(const TTimeIntervalMicroSeconds& aStart,
       
   163 								const TTimeIntervalMicroSeconds& aEnd)
       
   164 	{
       
   165     return iProperties->SetPlayWindow(aStart,aEnd);
       
   166 	}
       
   167 
       
   168 TInt CAudioPdPlayUtility::ClearPlayWindow()
       
   169 	{
       
   170     return iProperties->ClearPlayWindow();
       
   171 	}
       
   172 TInt CAudioPdPlayUtility::SetBalance(TInt aBalance)
       
   173 	{
       
   174     return iProperties->SetBalance(aBalance);
       
   175 	}
       
   176 TInt CAudioPdPlayUtility::GetBalance(TInt& aBalance)
       
   177 	{
       
   178     return iProperties->GetBalance(aBalance);
       
   179 	}
       
   180 TInt CAudioPdPlayUtility::GetBitRate(TUint& aBitRate)
       
   181 	{
       
   182     return iProperties->GetBitRate(aBitRate);
       
   183 	}
       
   184 
       
   185 
       
   186 void CAudioPdPlayUtility::RegisterForAudioLoadingNotification(MAudioLoadingObserver& aCallback)
       
   187 	{
       
   188     iProperties->RegisterForAudioLoadingNotification(aCallback);
       
   189 	}
       
   190 
       
   191 void CAudioPdPlayUtility::GetAudioLoadingProgressL(TInt& aPercentageProgress)
       
   192 	{
       
   193     iProperties->GetAudioLoadingProgressL(aPercentageProgress);
       
   194 	}
       
   195 
       
   196 const CMMFControllerImplementationInformation& CAudioPdPlayUtility::ControllerImplementationInformationL()
       
   197 	{
       
   198 	return iProperties->ControllerImplementationInformationL();
       
   199 	}
       
   200 
       
   201 
       
   202 TInt CAudioPdPlayUtility::CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom)
       
   203 	{
       
   204     return iProperties->CustomCommandSync(aDestination, aFunction, aDataTo1, aDataTo2, aDataFrom);
       
   205 	}
       
   206 TInt CAudioPdPlayUtility::CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2)
       
   207 	{
       
   208     return iProperties->CustomCommandSync(aDestination, aFunction, aDataTo1, aDataTo2);
       
   209 	}
       
   210 void CAudioPdPlayUtility::CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom, TRequestStatus& aStatus)
       
   211 	{
       
   212 	iProperties->CustomCommandAsync(aDestination, aFunction, aDataTo1, aDataTo2, aDataFrom, aStatus);
       
   213 	}
       
   214 void CAudioPdPlayUtility::CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TRequestStatus& aStatus)
       
   215 	{
       
   216 	iProperties->CustomCommandAsync(aDestination, aFunction, aDataTo1, aDataTo2, aStatus);
       
   217 	}
       
   218 
       
   219 void CAudioPdPlayUtility::OpenFileL(const TDesC& aFileName)
       
   220 	{
       
   221 	iProperties->OpenFileL(aFileName);
       
   222 	}
       
   223 
       
   224 
       
   225 void CAudioPdPlayUtility::OpenFileL(const RFile& aFile)
       
   226 	{
       
   227 	RFile& file = const_cast<RFile&>(aFile);
       
   228 	iProperties->OpenFileL(file);
       
   229 	}
       
   230 
       
   231 void CAudioPdPlayUtility::DlCompleteOpenFileL(const TDesC& aFileName)
       
   232 	{
       
   233 	iProperties->DlCompleteOpenFileL(aFileName);
       
   234 	}
       
   235 
       
   236 TInt CAudioPdPlayUtility::GetFilePosition(TInt& aFilePosition)
       
   237 	{
       
   238 	return iProperties->GetFilePosition(aFilePosition);
       
   239 	}
       
   240 
       
   241 TInt CAudioPdPlayUtility::SetFileSize(TInt aFileSize)
       
   242 	{
       
   243 	return iProperties->SetFileSize(aFileSize);
       
   244 	}
       
   245 
       
   246 TInt CAudioPdPlayUtility::SetBytesDownloaded(TInt aBytesDownloaded, TBool aDownloadComplete)
       
   247 	{
       
   248 	return iProperties->SetBytesDownloaded(aBytesDownloaded,aDownloadComplete);
       
   249 	}
       
   250 
       
   251 MMMFDRMCustomCommand* CAudioPdPlayUtility::GetDRMCustomCommand()
       
   252 	{
       
   253 	//ASSERT(iProperties);
       
   254 	return iProperties->GetDRMCustomCommand();
       
   255 	}
       
   256 
       
   257 
       
   258 TInt CAudioPdPlayUtility::CheckAudioPlayerState()
       
   259 	{
       
   260 	return iProperties->CheckAudioPlayerState();
       
   261 	}
       
   262 
       
   263 
       
   264 //===============================================================
       
   265 // CAudioPdProperties implementation begins
       
   266 //
       
   267 //===============================================================
       
   268 CAudioPdProperties* CAudioPdProperties::NewL(MAudioPdPlayUtilityCallback& aCallback)
       
   269 	{
       
   270 	CAudioPdProperties* self = new(ELeave) CAudioPdProperties(aCallback);
       
   271 	CleanupStack::PushL(self);
       
   272 	self->ConstructL(aCallback);
       
   273 	CleanupStack::Pop(self);
       
   274 	return self;
       
   275 	}
       
   276 CAudioPdProperties* CAudioPdProperties::NewLC(MAudioPdPlayUtilityCallback& /*aCallback*/)
       
   277 	{
       
   278 	return NULL;
       
   279 	}
       
   280 
       
   281 CAudioPdProperties::~CAudioPdProperties()
       
   282 	{
       
   283 
       
   284     if(iMimeType)
       
   285         {
       
   286         delete iMimeType;
       
   287         iMimeType = NULL;
       
   288         }
       
   289 
       
   290     if(iBufferEmptiedEventAO->IsActive())
       
   291         {
       
   292         iBufferEmptiedEventAO->Cancel();
       
   293         }
       
   294 
       
   295     delete iBufferEmptiedEventAO;
       
   296 
       
   297     iFactory->DeleteStreamControl(iStreamControl);
       
   298 
       
   299     while(iBuffers.Count())
       
   300         {
       
   301         MDataBuffer* temp = iBuffers[0];
       
   302         iBuffers.Remove(0);
       
   303         iFactory->DeleteDataBuffer(temp);
       
   304         }
       
   305 
       
   306     if(iMDataBufferSource)
       
   307         {
       
   308         MSourceControl* objPtr = iMDataBufferSource;
       
   309         iFactory->DeleteSourceControl(objPtr);
       
   310         iMDataBufferSource = NULL;
       
   311         }
       
   312 
       
   313     MSinkControl* objPtr1 = iMAudioSink;
       
   314     iFactory->DeleteSinkControl(objPtr1);
       
   315 
       
   316 	if(iMVolumeControl)
       
   317 		{
       
   318 		MEffectControl* effectObj = iMVolumeControl;
       
   319 		iFactory->DeleteEffectControl(effectObj);
       
   320 		iMVolumeControl = NULL;
       
   321 		}
       
   322 
       
   323     if(iFileName)
       
   324         {
       
   325         delete iFileName;
       
   326         iFileName = NULL;
       
   327         }
       
   328 
       
   329     if (iMetaDataEntries.Count())
       
   330     	{
       
   331         iMetaDataEntries.ResetAndDestroy();
       
   332 		iMetaDataEntries.Close();
       
   333 		}
       
   334 
       
   335     delete iFile;
       
   336     iFile = NULL;
       
   337     iFs.Close();
       
   338     iBuffers.ResetAndDestroy();
       
   339     iBuffers.Close();
       
   340     iAvailable.Close();
       
   341 
       
   342  	delete iFactory;
       
   343 
       
   344 	delete iControllerImplementationInformation;
       
   345 	delete iAsyncCallBack;
       
   346 //	iController.Close();
       
   347 	}
       
   348 
       
   349 CAudioPdProperties::CAudioPdProperties(/*MMdaAudioPlayerCallback*/MAudioPdPlayUtilityCallback& aCallback):
       
   350 	iCallback(aCallback),
       
   351 	iAudioPlayDeviceCommands(iController),
       
   352 	iAudioPlayControllerCommands(iController),
       
   353 	iDRMCustomCommands(iController)
       
   354 	{
       
   355 	iState = EStopped;
       
   356 	iPrioritySettings.iPriority = KAudioPriorityRealOnePlayer;//80
       
   357 	iPrioritySettings.iPref =(TMdaPriorityPreference) KAudioPrefRealOneLocalPlayback;// 0x01420001;
       
   358 	iPlayStart = TTimeIntervalMicroSeconds(0);
       
   359 	iPlayEnd = TTimeIntervalMicroSeconds(0);
       
   360 	iPlayWindowSet = ENone;
       
   361 	iBuffering = EFalse;
       
   362 	iControllerPtr = NULL;
       
   363 	iStopCalled = EFalse;
       
   364 	iFileName = NULL;
       
   365 	}
       
   366 
       
   367 void CAudioPdProperties::ConstructL(MAudioPdPlayUtilityCallback& /*aCallback*/)
       
   368 	{
       
   369 	iAsyncCallBack = CMMFMdaAudioPlayerCallBack::NewL(iCallback);
       
   370     iBufferEmptiedEventAO = CBufferEmptiedEventAO::NewL(*this);
       
   371     iMimeType = HBufC8::NewL(20);
       
   372     TInt status = CMultimediaFactory::CreateFactory( iFactory );
       
   373 
       
   374     TInt err = iFactory->CreateStreamControl( KStreamControl, iStreamControl );
       
   375     User::LeaveIfError(err);
       
   376     iStreamControl->AddObserver( *this );
       
   377 
       
   378     MSinkControl* tempSinkCtrl(NULL);
       
   379     err = iFactory->CreateSinkControl( KMMFAudioOutputSinkControl, tempSinkCtrl );
       
   380     User::LeaveIfError(err);
       
   381 	iMAudioSink = tempSinkCtrl;
       
   382     iStreamControl->AddSink( *iMAudioSink );
       
   383 
       
   384     MSourceControl* tempCtrl(NULL);
       
   385     err = iFactory->CreateSourceControl( KDataBufferSourceControl, tempCtrl );
       
   386     User::LeaveIfError(err);
       
   387     CreateAudioBuffersL();
       
   388     iMDataBufferSource = static_cast<MDataBufferSource*>(tempCtrl);
       
   389     iMDataBufferSource->AddObserver( *this );
       
   390 
       
   391 	//Create Volume Control
       
   392 	MEffectControl* effectCtrl(NULL);
       
   393 	err = iFactory->CreateEffectControl( KVolumeEffectControl, effectCtrl );
       
   394 	User::LeaveIfError(err);
       
   395 
       
   396 	iMVolumeControl = static_cast<MVolumeControl*>(effectCtrl);
       
   397 	err = iStreamControl->AddEffect( *iMVolumeControl );
       
   398 	}
       
   399 
       
   400 void CAudioPdProperties::HandleDownloadEventL(TUint aTransactionID,
       
   401                                               TBrCtlDownloadEvent aEvent,
       
   402                                               TUint aValue)
       
   403 	{
       
   404 	iCallback.HandleDownloadEventL(aTransactionID,aEvent,aValue);
       
   405 	}
       
   406 
       
   407 
       
   408 void CAudioPdProperties::CreateAudioBuffersL()
       
   409     {
       
   410     MDataBuffer* buffer;
       
   411     iBuffers.ResetAndDestroy();
       
   412     iAvailable.Reset();
       
   413     for (int i = 0; i < KNumberOfBuffers; i++ )
       
   414         {
       
   415         iFactory->CreateDataBuffer(KDataBufferSourceControl,4096,buffer);
       
   416         User::LeaveIfError(iBuffers.Append(buffer));
       
   417         buffer = NULL;
       
   418         iAvailable.AppendL(ETrue);
       
   419         }
       
   420     }
       
   421 
       
   422 void CAudioPdProperties::DetermineFNMimeType(const TDesC& aFileName, TDes8& aMimeType)
       
   423     {
       
   424     RApaLsSession ls;
       
   425     TInt err;
       
   426     err=ls.Connect();
       
   427 
       
   428     TDataRecognitionResult result;
       
   429     err = ls.RecognizeData(aFileName,KNullDesC8(),result);
       
   430     if(!err && (result.iConfidence >= CApaDataRecognizerType::EProbable))
       
   431         {
       
   432         aMimeType.Copy(result.iDataType.Des8());
       
   433         }
       
   434     ls.Close();
       
   435     }
       
   436 
       
   437 void CAudioPdProperties::DetermineFHMimeType(const RFile& aFile, TDes8& aMimeType)
       
   438     {
       
   439     RApaLsSession ls;
       
   440     TInt err;
       
   441     err=ls.Connect();
       
   442 
       
   443     TDataRecognitionResult result;
       
   444     err = ls.RecognizeData(aFile,result);
       
   445     if(!err && (result.iConfidence >= CApaDataRecognizerType::EProbable))
       
   446         {
       
   447         aMimeType.Copy(result.iDataType.Des8());
       
   448         }
       
   449     ls.Close();
       
   450     }
       
   451 
       
   452 
       
   453 void CAudioPdProperties::OpenFileL(const TDesC& aFileName)
       
   454 	{
       
   455     TBuf8<20> mimeType;
       
   456     User::LeaveIfError(iFs.Connect());
       
   457 
       
   458     if(iFileName)
       
   459         {
       
   460         delete iFileName;
       
   461         iFileName = NULL;
       
   462         }
       
   463 
       
   464     iFileName = HBufC::NewL(aFileName.Length());
       
   465     TPtr des = iFileName->Des();
       
   466     des.Copy(aFileName);
       
   467 
       
   468 	TInt err = ExtractDRMRestrictionsL();
       
   469 	User::LeaveIfError(err);
       
   470     if(!isProtected)
       
   471         {
       
   472         DetermineFNMimeType(aFileName,mimeType);
       
   473         iMimeType->Des().Copy(mimeType);
       
   474         }
       
   475 
       
   476 
       
   477     if(iMimeType->Des().Length())
       
   478         {
       
   479         DEBPRN1(_L("CAudioPdProperties::OpenFileL() Before iFile Open "));
       
   480     	iFile =  CContentFile::NewL(iFs,aFileName, KNullDesC, EFileShareAny,EFalse);
       
   481         DEBPRN2(_L("CAudioPdProperties::OpenFileL() After iFile Open Error[%d]"),err);
       
   482         iStreamControl->AddSource(*iMDataBufferSource);
       
   483     	MDataBuffer* dataBuffer = NULL;
       
   484     	err = iMDataBufferSource->Open(*iMimeType,*dataBuffer);
       
   485     	User::LeaveIfError(err);
       
   486         SetPriority(iPrioritySettings.iPriority,(TMdaPriorityPreference)iPrioritySettings.iPref);
       
   487     	iStreamControl->Open();
       
   488         }
       
   489     else
       
   490         {
       
   491         User::Leave(KErrNotSupported);
       
   492         }
       
   493 	}
       
   494 
       
   495 
       
   496 void CAudioPdProperties::OpenFileL(const RFile& aFile)
       
   497 	{
       
   498     TBuf8<20> mimeType;
       
   499     iFileHandle = aFile;
       
   500 	TInt err = ExtractDRMRestrictionsL();
       
   501 	User::LeaveIfError(err);
       
   502     if(!isProtected)
       
   503         {
       
   504         DetermineFHMimeType(iFileHandle,mimeType);
       
   505         iMimeType->Des().Copy(mimeType);
       
   506         }
       
   507 
       
   508     iFile =  CContentFile::NewL(iFileHandle, KNullDesC ,EFalse);
       
   509 
       
   510     if(iMimeType->Des().Length())
       
   511         {
       
   512         MDataBuffer* dataBuffer = NULL;
       
   513     	TInt err = iMDataBufferSource->Open(*iMimeType,*dataBuffer);
       
   514     	User::LeaveIfError(err);
       
   515         SetPriority(iPrioritySettings.iPriority,(TMdaPriorityPreference)iPrioritySettings.iPref);
       
   516     	iStreamControl->Open();
       
   517         }
       
   518     else
       
   519         {
       
   520         User::Leave(KErrNotSupported);
       
   521         }
       
   522 	}
       
   523 
       
   524 void CAudioPdProperties::DlCompleteOpenFileL(const TDesC& aFileName)
       
   525 	{
       
   526 	OpenFileL(aFileName);
       
   527 	}
       
   528 
       
   529 
       
   530 void CAudioPdProperties::Play()
       
   531 	{
       
   532     DEBPRN2(_L("CAudioPdProperties::Play() enter iIsEOFReached[%d]"),iIsEOFReached);
       
   533 	if (iPlayWindowSet == ESet)
       
   534 		{
       
   535         iAudioPlayControllerCommands.SetPlaybackWindow(iPlayStart, iPlayEnd);
       
   536 		}
       
   537 	else if (iPlayWindowSet == EClear)
       
   538 		{
       
   539 		iAudioPlayControllerCommands.DeletePlaybackWindow();
       
   540 		iPlayWindowSet = ENone;	// assume window will stay cleared
       
   541 		}
       
   542 
       
   543     if(iIsEOFReached)
       
   544         {
       
   545         delete iFile;
       
   546         iFile = NULL;
       
   547         if(iFileName)
       
   548             {
       
   549             DEBPRN2(_L("CAudioPdProperties::Play() iIsEOFReached[%d] "),iIsEOFReached);
       
   550            	iFile =  CContentFile::NewL(iFs,*iFileName, KNullDesC, EFileShareAny,EFalse);
       
   551             }
       
   552         else
       
   553             {
       
   554             DEBPRN2(_L("CAudioPdProperties::Play() iIsEOFReached[%d] "),iIsEOFReached);
       
   555             iFile =  CContentFile::NewL(iFileHandle, KNullDesC ,EFalse);
       
   556             }
       
   557         iIsEOFReached = EFalse;
       
   558         }
       
   559 
       
   560     if(iState != EStopped)
       
   561         {
       
   562         FillSourceBuffers();
       
   563         }
       
   564 
       
   565     if(!iDisableAutoIntent && iFile)
       
   566         {
       
   567         iFile->ExecuteIntent((iState == EPaused) ? ContentAccess::EContinue : ContentAccess::EPlay);
       
   568         }
       
   569 
       
   570     iStreamControl->Start();
       
   571 	}
       
   572 
       
   573 void CAudioPdProperties::Stop()
       
   574 	{
       
   575     DEBPRN1(_L("CAudioPdProperties::Stop() enter"));
       
   576     iStopCalled = ETrue;
       
   577     iStreamControl->Stop();
       
   578 	}
       
   579 TInt CAudioPdProperties::Pause()
       
   580 	{
       
   581     TInt err = KErrNone;
       
   582     DEBPRN1(_L("CAudioPdProperties::Pause() enter"));
       
   583     if(!iDisableAutoIntent && iFile)
       
   584         {
       
   585         iFile->ExecuteIntent(ContentAccess::EPause);
       
   586         }
       
   587 
       
   588     err = iStreamControl->Pause();
       
   589 	return err;
       
   590 	}
       
   591 
       
   592 void CAudioPdProperties::SetVolume(TInt aVolume)
       
   593 	{
       
   594     if(iMVolumeControl)
       
   595 	    {
       
   596 	    iMVolumeControl->SetVolume(aVolume);
       
   597 	    iMVolumeControl->Apply();
       
   598         }
       
   599 	}
       
   600 
       
   601 void CAudioPdProperties::SetRepeats(TInt aRepeatNumberOfTimes, const TTimeIntervalMicroSeconds& aTrailingSilence)
       
   602 	{
       
   603 	iNumberOfTimesToRepeat = aRepeatNumberOfTimes;
       
   604 	iTrailingSilence = aTrailingSilence;
       
   605 	}
       
   606 
       
   607 void CAudioPdProperties::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration)
       
   608 	{
       
   609    	TInt curVol = 0;
       
   610    	MVolumeControl::TVolumeRampMode aMode= MVolumeControl::EIMMEDIATE;
       
   611    	TUint64 duration = aRampDuration.Int64();
       
   612    	TInt err = iMVolumeControl->GetVolume(curVol);
       
   613     if(iMVolumeControl)
       
   614     	{
       
   615      	iMVolumeControl->SetVolumeRamp(0,curVol,duration,
       
   616                                    aMode);
       
   617 		iMVolumeControl->Apply();
       
   618     	}
       
   619 	}
       
   620 const TTimeIntervalMicroSeconds& CAudioPdProperties::Duration()
       
   621 	{
       
   622 	TInt64 duration = 0;
       
   623 	TInt err = iStreamControl->GetDuration(duration);
       
   624 	iDuration = duration;
       
   625 	return iDuration;
       
   626 	}
       
   627 
       
   628 TInt CAudioPdProperties:: MaxVolume()
       
   629 	{
       
   630     TInt volume;
       
   631     if(iMVolumeControl)
       
   632     	iMVolumeControl->GetMaxVolume(volume);
       
   633     return volume;
       
   634 	}
       
   635 
       
   636 void CAudioPdProperties::Close()
       
   637 	{
       
   638 	// Reset the audio player state.
       
   639     DEBPRN1(_L("CAudioPdProperties::Close() enter"));
       
   640 	Stop();
       
   641     DEBPRN1(_L("CAudioPdProperties::Close() Before File Close "));
       
   642 	delete iFile;
       
   643 	iFile = NULL;
       
   644     DEBPRN1(_L("CAudioPdProperties::Close() After File Close "));
       
   645 	}
       
   646 
       
   647 TInt CAudioPdProperties::GetPosition(TTimeIntervalMicroSeconds& aPosition)
       
   648 	{
       
   649     TInt error = KErrNone;
       
   650     TInt64 position = 0;
       
   651 	error = iStreamControl->GetPosition(position);
       
   652 	aPosition = iPosition = position;
       
   653 	return error;
       
   654 	}
       
   655 
       
   656 void CAudioPdProperties::SetPosition(const TTimeIntervalMicroSeconds& aPosition)
       
   657 	{
       
   658 	TInt64 position = aPosition.Int64();
       
   659 	TTimeIntervalMicroSeconds currentPosition(0);
       
   660 	GetPosition(currentPosition);
       
   661 
       
   662 	// We only set the Position if the Current Position is different then the
       
   663     // the new Position
       
   664 	if(currentPosition != aPosition)
       
   665 	    {
       
   666 	    //iStreamControl->SetPosition(position);
       
   667 	    }
       
   668 	}
       
   669 
       
   670 TInt CAudioPdProperties::SetPriority(TInt aPriority, TMdaPriorityPreference aPref)
       
   671 	{
       
   672 	TInt err = iStreamControl->SetPriority(aPriority,aPref);
       
   673 	return err;
       
   674 	}
       
   675 
       
   676 TInt CAudioPdProperties::GetVolume(TInt& aVolume)
       
   677 	{
       
   678     TInt error = iAudioPlayDeviceCommands.GetVolume(aVolume);
       
   679 	return error;
       
   680 	}
       
   681 
       
   682 TInt CAudioPdProperties::GetNumberOfMetaDataEntries(TInt& aNumEntries)
       
   683 	{
       
   684     TInt status(KErrNotReady);
       
   685     if(!iMimeType->Des().Compare(KWMAMimeType()))
       
   686         {
       
   687         status = iController.GetNumberOfMetaDataEntries(aNumEntries);
       
   688         }
       
   689     else
       
   690         {
       
   691         if (!iMetaDataRead && iControllerLoaded)
       
   692             {
       
   693             CMetaDataUtility* metaDataUtility = CMetaDataUtility::NewL();
       
   694             CleanupStack::PushL(metaDataUtility);
       
   695 
       
   696     		RArray<TMetaDataFieldId> wantedFields;
       
   697     		CleanupClosePushL(wantedFields);
       
   698     		wantedFields.Append(EMetaDataSongTitle);
       
   699     		wantedFields.Append(EMetaDataArtist);
       
   700     		wantedFields.Append(EMetaDataAlbum);
       
   701     		wantedFields.Append(EMetaDataYear);
       
   702     		wantedFields.Append(EMetaDataComment);
       
   703     		wantedFields.Append(EMetaDataAlbumTrack);
       
   704     		wantedFields.Append(EMetaDataGenre);
       
   705     		wantedFields.Append(EMetaDataComposer);
       
   706     		wantedFields.Append(EMetaDataCopyright);
       
   707     		wantedFields.Append(EMetaDataOriginalArtist);
       
   708     		wantedFields.Append(EMetaDataUrl);
       
   709     		wantedFields.Append(EMetaDataJpeg);
       
   710     		wantedFields.Append(EMetaDataUserUrl);
       
   711 
       
   712 			if(iFileName)
       
   713 			    {
       
   714 			    TRAP(status,metaDataUtility->OpenFileL(*iFileName, wantedFields));
       
   715 			    }
       
   716 			else
       
   717 			    {
       
   718 			    TRAP(status,metaDataUtility->OpenFileL(iFileHandle, wantedFields));
       
   719 			    }
       
   720 
       
   721             if(status != KErrNone)
       
   722                 {
       
   723         		CleanupStack::PopAndDestroy(&wantedFields);	// wantedFields
       
   724         		CleanupStack::PopAndDestroy(metaDataUtility);	//metaDataUtility
       
   725                 return status;
       
   726                 }
       
   727             TInt count = metaDataUtility->MetaDataCount();
       
   728 
       
   729             if (count > 0)
       
   730     			{
       
   731     			const CMetaDataFieldContainer& container = metaDataUtility->MetaDataFieldsL();
       
   732     			TMetaDataFieldId id;
       
   733     			for (TInt i = 0; i < count; i++)
       
   734     				{
       
   735     				TPtrC content = container.At(i, id);
       
   736     				CMMFMetaDataEntry* metaData = NULL;
       
   737     				switch (id)
       
   738     					{
       
   739     					case EMetaDataSongTitle:
       
   740     						metaData = CMMFMetaDataEntry::NewL(KMMFMetaEntrySongTitle, content);
       
   741     						break;
       
   742     					case EMetaDataArtist:
       
   743     						metaData = CMMFMetaDataEntry::NewL(KMMFMetaEntryArtist, content);
       
   744     						break;
       
   745     					case EMetaDataAlbum:
       
   746     						metaData = CMMFMetaDataEntry::NewL(KMMFMetaEntryAlbum, content);
       
   747     						break;
       
   748     					case EMetaDataYear:
       
   749     						metaData = CMMFMetaDataEntry::NewL(KMMFMetaEntryYear, content);
       
   750     						break;
       
   751     					case EMetaDataComment:
       
   752     						metaData = CMMFMetaDataEntry::NewL(KMMFMetaEntryComment, content);
       
   753     						break;
       
   754     					case EMetaDataAlbumTrack:
       
   755     						metaData = CMMFMetaDataEntry::NewL(KMMFMetaEntryAlbumTrack, content);
       
   756     						break;
       
   757     					case EMetaDataGenre:
       
   758     						metaData = CMMFMetaDataEntry::NewL(KMMFMetaEntryGenre, content);
       
   759     						break;
       
   760     					case EMetaDataComposer:
       
   761     						metaData = CMMFMetaDataEntry::NewL(KMMFMetaEntryComposer, content);
       
   762     						break;
       
   763     					case EMetaDataCopyright:
       
   764     						metaData = CMMFMetaDataEntry::NewL(KMMFMetaEntryCopyright, content);
       
   765     						break;
       
   766     					case EMetaDataOriginalArtist:
       
   767     						metaData = CMMFMetaDataEntry::NewL(KMMFMetaEntryOriginalArtist, content);
       
   768     						break;
       
   769     					case EMetaDataUrl:
       
   770     						metaData = CMMFMetaDataEntry::NewL(KMMFMetaEntryWOAF, content);
       
   771     						break;
       
   772     					case EMetaDataJpeg:
       
   773     						metaData = CMMFMetaDataEntry::NewL(KMMFMetaEntryAPIC, content);
       
   774     						break;
       
   775     					case EMetaDataUserUrl:
       
   776     						metaData = CMMFMetaDataEntry::NewL(KMMFMetaEntryWXXX, content);
       
   777     						break;
       
   778     					default:	// Should never get here really...
       
   779     						break;
       
   780     					}
       
   781     				if (metaData)
       
   782     					{
       
   783     					CleanupStack::PushL(metaData);
       
   784     					User::LeaveIfError(iMetaDataEntries.Append(metaData));
       
   785     					CleanupStack::Pop(metaData);	// metaData
       
   786     					}
       
   787     				}
       
   788     			}
       
   789     		iMetaDataRead = ETrue;
       
   790     		CleanupStack::PopAndDestroy(&wantedFields);	// wantedFields
       
   791     		CleanupStack::PopAndDestroy(metaDataUtility);	//metaDataUtility
       
   792     		}
       
   793         aNumEntries = iMetaDataEntries.Count();
       
   794         status = KErrNone;
       
   795         }
       
   796     return status;
       
   797 	}
       
   798 
       
   799 
       
   800 CMMFMetaDataEntry* CAudioPdProperties::GetMetaDataEntryL(TInt aMetaDataIndex)
       
   801 	{
       
   802     if(!iMimeType->Des().Compare(KWMAMimeType()))
       
   803         {
       
   804         return iController.GetMetaDataEntryL(aMetaDataIndex);
       
   805         }
       
   806 	else
       
   807         {
       
   808         if (aMetaDataIndex > iMetaDataEntries.Count() - 1)
       
   809         	{
       
   810             User::Leave(KErrArgument);
       
   811     		}
       
   812 
       
   813         return CMMFMetaDataEntry::NewL(*iMetaDataEntries[aMetaDataIndex]);
       
   814         }
       
   815 	}
       
   816 
       
   817 TInt CAudioPdProperties::SetPlayWindow(const TTimeIntervalMicroSeconds& aPlayStart,
       
   818 								const TTimeIntervalMicroSeconds& aPlayEnd)
       
   819 	{
       
   820     TInt error = KErrNone;
       
   821 
       
   822 	if (aPlayStart >= TTimeIntervalMicroSeconds(0) &&
       
   823 		aPlayStart < iDuration &&
       
   824 			aPlayStart < aPlayEnd &&
       
   825 			aPlayEnd <= iDuration )
       
   826 		{
       
   827 		iPlayStart = aPlayStart;
       
   828 		iPlayEnd = aPlayEnd;
       
   829 		iPlayWindowSet = ESet;
       
   830 
       
   831 		if (iState==EPlaying)
       
   832 			error = iAudioPlayControllerCommands.SetPlaybackWindow(aPlayStart, aPlayEnd);
       
   833 		}
       
   834 	else
       
   835 		error = KErrArgument;
       
   836 
       
   837 	return error;
       
   838 	}
       
   839 
       
   840 TInt CAudioPdProperties::ClearPlayWindow()
       
   841 	{
       
   842     	// clear play window start - very important because this is assigned
       
   843 	// to iPosition when we stop & is used to set the position on the next Play()
       
   844 	iPosition = iPlayStart = iPlayEnd = TTimeIntervalMicroSeconds(0);
       
   845 
       
   846 	iPlayWindowSet = EClear;
       
   847 	TInt err = KErrNone;
       
   848 	if (iState==EPlaying)
       
   849 		err = iAudioPlayControllerCommands.DeletePlaybackWindow();
       
   850 	return err;
       
   851 	}
       
   852 
       
   853 TInt CAudioPdProperties::SetBalance(TInt aBalance)
       
   854 	{
       
   855     TInt err = iAudioPlayDeviceCommands.SetBalance(aBalance);
       
   856 	return err;
       
   857 	}
       
   858 
       
   859 TInt CAudioPdProperties::GetBalance(TInt& aBalance)
       
   860 	{
       
   861 	TInt err = iAudioPlayDeviceCommands.GetBalance(aBalance);
       
   862 	return err;
       
   863 	}
       
   864 
       
   865 TInt CAudioPdProperties::GetBitRate(TUint& aBitRate)
       
   866 	{
       
   867     TInt status = KErrNone;
       
   868     if(iMDataBufferSource)
       
   869         {
       
   870         status = iMDataBufferSource->GetBitRate(aBitRate);
       
   871         }
       
   872     return status;
       
   873 	}
       
   874 
       
   875 void CAudioPdProperties::RegisterForAudioLoadingNotification(MAudioLoadingObserver& aLoadingObserver)
       
   876 	{
       
   877     iLoadingObserver = &aLoadingObserver;
       
   878 	}
       
   879 
       
   880 void CAudioPdProperties::GetAudioLoadingProgressL(TInt& aPercentageProgress)
       
   881 	{
       
   882     User::LeaveIfError(iAudioPlayControllerCommands.GetLoadingProgress(aPercentageProgress));
       
   883 	}
       
   884 
       
   885 const CMMFControllerImplementationInformation& CAudioPdProperties::ControllerImplementationInformationL()
       
   886 	{
       
   887 	if (!iControllerImplementationInformation)
       
   888 		{
       
   889 		TUid* contUid = static_cast<TUid*>(iStreamControl->CustomInterface(KUidSCControllerUid));
       
   890 		iControllerUid = *contUid;
       
   891 		if (iControllerUid==KNullUid)
       
   892 			User::Leave(KErrNotReady);
       
   893 		iControllerImplementationInformation = CMMFControllerImplementationInformation::NewL(iControllerUid);
       
   894 		}
       
   895 	return *iControllerImplementationInformation;
       
   896 	}
       
   897 
       
   898 TInt CAudioPdProperties::CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom)
       
   899 	{
       
   900     return iController.CustomCommandSync(aDestination, aFunction, aDataTo1, aDataTo2, aDataFrom);
       
   901 	}
       
   902 TInt CAudioPdProperties::CustomCommandSync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2)
       
   903 	{
       
   904     return iController.CustomCommandSync(aDestination, aFunction, aDataTo1, aDataTo2);
       
   905 	}
       
   906 void CAudioPdProperties::CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom, TRequestStatus& aStatus)
       
   907 	{
       
   908 	iController.CustomCommandAsync(aDestination, aFunction, aDataTo1, aDataTo2, aDataFrom, aStatus);
       
   909 	}
       
   910 void CAudioPdProperties::CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TRequestStatus& aStatus)
       
   911 	{
       
   912     iController.CustomCommandAsync(aDestination, aFunction, aDataTo1, aDataTo2, aStatus);
       
   913 	}
       
   914 
       
   915 TInt CAudioPdProperties::GetFilePosition(TInt& /*aFilePosition*/)
       
   916 	{
       
   917     return KErrNone;
       
   918 	}
       
   919 
       
   920 TInt CAudioPdProperties::SetFileSize(TInt aFileSize)
       
   921 	{
       
   922     TInt status(KErrNone);
       
   923     if(!isProtected)
       
   924         {
       
   925         iFileSize = aFileSize;
       
   926         status = iMDataBufferSource->SetSize(aFileSize);
       
   927         }
       
   928     return status;
       
   929 	}
       
   930 
       
   931 TInt CAudioPdProperties::SetBytesDownloaded(TInt aBytesDownloaded, TBool aDownloadComplete)
       
   932 	{
       
   933     TInt status(KErrNone);
       
   934     iBytesDownloaded = aBytesDownloaded;
       
   935     iDownloadComplete = aDownloadComplete;
       
   936 
       
   937     if(iDownloadComplete && iFile)
       
   938         {
       
   939         ReOpenCAF();
       
   940         }
       
   941 
       
   942     if(iBuffering)
       
   943         {
       
   944         if(((aBytesDownloaded - iBytesReadFromFile) > KBufferingAmount)
       
   945             || ((iFileSize - aBytesDownloaded) < KBufferingAmount))
       
   946             {
       
   947             FillSourceBuffers();
       
   948             }
       
   949         }
       
   950     return status;
       
   951 	}
       
   952 
       
   953 
       
   954 MMMFDRMCustomCommand* CAudioPdProperties::GetDRMCustomCommand()
       
   955 	{
       
   956     return this;
       
   957 	}
       
   958 
       
   959 
       
   960 TInt CAudioPdProperties::DisableAutomaticIntent(TBool aDisableAutoIntent)
       
   961     {
       
   962 	if (iDRMCustomCommands.IsSupported())
       
   963 		{
       
   964         iDisableAutoIntent = aDisableAutoIntent;
       
   965         return KErrNone;
       
   966 		}
       
   967 	else
       
   968 		{
       
   969 		return KErrNotSupported;
       
   970 		}
       
   971     }
       
   972 
       
   973 TInt CAudioPdProperties::ExecuteIntent(ContentAccess::TIntent aIntent)
       
   974     {
       
   975 	if (iDRMCustomCommands.IsSupported())
       
   976 		{
       
   977 	    if(iFile)
       
   978 	        {
       
   979 	        return iFile->ExecuteIntent(aIntent);
       
   980 	        }
       
   981         else
       
   982             {
       
   983             return KErrNotReady;
       
   984             }
       
   985 		}
       
   986 	else
       
   987 		{
       
   988 		return KErrNotSupported;
       
   989 		}
       
   990     }
       
   991 
       
   992 TInt CAudioPdProperties::EvaluateIntent(ContentAccess::TIntent aIntent)
       
   993     {
       
   994 	if (iDRMCustomCommands.IsSupported())
       
   995 		{
       
   996 	    if(iFile)
       
   997 	        {
       
   998             return iFile->EvaluateIntent(aIntent);
       
   999 	        }
       
  1000         else
       
  1001             {
       
  1002             return KErrNotReady;
       
  1003             }
       
  1004 		}
       
  1005 	else
       
  1006 		{
       
  1007 		return KErrNotSupported;
       
  1008 		}
       
  1009     }
       
  1010 
       
  1011 TInt CAudioPdProperties::SetAgentProperty(ContentAccess::TAgentProperty aProperty, TInt aValue)
       
  1012     {
       
  1013 	if (iDRMCustomCommands.IsSupported())
       
  1014 		{
       
  1015 	    if(iFile)
       
  1016 	        {
       
  1017     		return iFile->SetAgentProperty(aProperty,aValue);
       
  1018 	        }
       
  1019         else
       
  1020             {
       
  1021             return KErrNotReady;
       
  1022             }
       
  1023 		}
       
  1024 	else
       
  1025 		{
       
  1026 		return KErrNotSupported;
       
  1027 		}
       
  1028     }
       
  1029 
       
  1030 TInt CAudioPdProperties::CheckAudioPlayerState()
       
  1031 	{
       
  1032 	return iState;
       
  1033 	}
       
  1034 
       
  1035 CRepeatTrailingSilenceTimer* CRepeatTrailingSilenceTimer::NewL(MRepeatTrailingSilenceTimerObs& aObs)
       
  1036 	{
       
  1037 	CRepeatTrailingSilenceTimer* s = new(ELeave) CRepeatTrailingSilenceTimer(aObs);
       
  1038 	CleanupStack::PushL(s);
       
  1039 	s->ConstructL();
       
  1040 	CleanupStack::Pop();
       
  1041 	return s;
       
  1042 	}
       
  1043 
       
  1044 void CRepeatTrailingSilenceTimer::RunL()
       
  1045 	{
       
  1046 	iObs.RepeatTrailingSilenceTimerComplete();
       
  1047 	}
       
  1048 
       
  1049 CRepeatTrailingSilenceTimer::CRepeatTrailingSilenceTimer(MRepeatTrailingSilenceTimerObs& aObs) :
       
  1050 	CTimer(EPriorityHigh),
       
  1051 	iObs(aObs)
       
  1052 	{
       
  1053 	CActiveScheduler::Add(this);
       
  1054 	}
       
  1055 
       
  1056 
       
  1057 CMMFMdaAudioPlayerCallBack* CMMFMdaAudioPlayerCallBack::NewL(MAudioPdPlayUtilityCallback& aCallback)
       
  1058 	{
       
  1059 	return new(ELeave) CMMFMdaAudioPlayerCallBack(aCallback);
       
  1060 	}
       
  1061 
       
  1062 CMMFMdaAudioPlayerCallBack::CMMFMdaAudioPlayerCallBack(MAudioPdPlayUtilityCallback& aCallback) :
       
  1063 	CActive(CActive::EPriorityHigh), iCallback(aCallback)
       
  1064 	{
       
  1065 	CActiveScheduler::Add(this);
       
  1066 	}
       
  1067 
       
  1068 CMMFMdaAudioPlayerCallBack::~CMMFMdaAudioPlayerCallBack()
       
  1069 	{
       
  1070 	Cancel();
       
  1071 	}
       
  1072 
       
  1073 void CMMFMdaAudioPlayerCallBack::InitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration)
       
  1074 	{
       
  1075 	iError = aError;
       
  1076 	iDuration = aDuration;
       
  1077 	iState = ECallbackInitComplete;
       
  1078 	if (!IsActive())
       
  1079 		{
       
  1080 		TRequestStatus* s = &iStatus;
       
  1081 		SetActive();
       
  1082 		User::RequestComplete(s, KErrNone);
       
  1083 		}
       
  1084 	}
       
  1085 
       
  1086 void CMMFMdaAudioPlayerCallBack::PlayComplete(TInt aError)
       
  1087 	{
       
  1088 	iError = aError;
       
  1089 	iState = ECallbackPlayComplete;
       
  1090 	if (!IsActive())
       
  1091 		{
       
  1092 		TRequestStatus* s = &iStatus;
       
  1093 		SetActive();
       
  1094 		User::RequestComplete(s, KErrNone);
       
  1095 		}
       
  1096 	}
       
  1097 
       
  1098 void CMMFMdaAudioPlayerCallBack::PlayingCallback()
       
  1099 	{
       
  1100 	iState = ECallbackPlaying;
       
  1101 	if (!IsActive())
       
  1102 		{
       
  1103 		TRequestStatus* s = &iStatus;
       
  1104 		SetActive();
       
  1105 		User::RequestComplete(s, KErrNone);
       
  1106 		}
       
  1107 	}
       
  1108 
       
  1109 void CMMFMdaAudioPlayerCallBack::PausedCallback()
       
  1110 	{
       
  1111 	iState = ECallbackPaused;
       
  1112 	if (!IsActive())
       
  1113 		{
       
  1114 		TRequestStatus* s = &iStatus;
       
  1115 		SetActive();
       
  1116 		User::RequestComplete(s, KErrNone);
       
  1117 		}
       
  1118 	}
       
  1119 
       
  1120 
       
  1121 void CMMFMdaAudioPlayerCallBack::RunL()
       
  1122 	{
       
  1123 	switch (iState)
       
  1124 		{
       
  1125 		case ECallbackInitComplete:
       
  1126 			iCallback.MapcInitComplete(iError, iDuration);
       
  1127 			break;
       
  1128 		case ECallbackPlayComplete:
       
  1129 			iCallback.MapcPlayComplete(iError);
       
  1130 			break;
       
  1131 		case ECallbackPlaying:
       
  1132 			iCallback.Playing();
       
  1133 			break;
       
  1134 		case ECallbackPaused:
       
  1135 			iCallback.Paused();
       
  1136 			break;
       
  1137 
       
  1138 		}
       
  1139 	}
       
  1140 
       
  1141 void CMMFMdaAudioPlayerCallBack::DoCancel()
       
  1142 	{
       
  1143 	// Nothing to cancel
       
  1144 	}
       
  1145 
       
  1146 void CAudioPdProperties::Event( MControl* /*aControl*/, TUint aEventType, TAny* aEventObject )
       
  1147     {
       
  1148     switch (aEventType)
       
  1149         {
       
  1150         case MStreamControlObserver::KStateChangedEvent:
       
  1151             {
       
  1152             //MStreamControl* control1 = (MStreamControl*)(aControl);
       
  1153             //MErrorCode* evt = (MErrorCode*)aEventObject;
       
  1154             MStateChangedEvent* evt = (MStateChangedEvent*)aEventObject;
       
  1155             DEBPRN1(_L("CAudioPdProperties::Event:EStateChanged"));
       
  1156             iStreamState = evt->GetState();
       
  1157             switch(evt->GetState())
       
  1158                 {
       
  1159                 case MStreamControl::CLOSED:
       
  1160                     iState = EStopped;
       
  1161                     iControllerLoaded = EFalse;
       
  1162                     DEBPRN1(_L("CAudioPdProperties::Event:EStateChanged[Closed]"));
       
  1163                     break;
       
  1164                 case MStreamControl::INITIALIZED:
       
  1165                     DEBPRN3(_L("CAudioPdProperties::Event:EStateChanged[Opened] [%d]StopCalled[%d]"),evt->GetErrorCode(),iStopCalled);
       
  1166                     iState = EOpening;
       
  1167                     if( evt->GetErrorCode() == KErrEof || iStopCalled)
       
  1168                         {
       
  1169                         iIsEOFReached = ETrue;
       
  1170                         iBytesReadFromFile = 0;
       
  1171                         DEBPRN1(_L("CAudioPdProperties::Event() Before File Close "));
       
  1172                         delete iFile;
       
  1173                         iFile = NULL;
       
  1174                         DEBPRN1(_L("CAudioPdProperties::Event() After File Close "));
       
  1175                         if(!iStopCalled)
       
  1176                             {
       
  1177                             iAsyncCallBack->PlayComplete(KErrNone);
       
  1178                             }
       
  1179                         iStopCalled = EFalse;
       
  1180                         }
       
  1181                     else if(evt->GetErrorCode() == KErrNone )
       
  1182                         {
       
  1183 
       
  1184                         iControllerPtr = static_cast<RMMFController*> (iStreamControl->CustomInterface(KUidSCControllerRef));
       
  1185                         iController = *iControllerPtr;
       
  1186                         iControllerLoaded = ETrue;
       
  1187                         if(iFileSize == -1 || isProtected)
       
  1188                             {
       
  1189                             iFile->Size(iFileSize);
       
  1190                             iMDataBufferSource->SetSize(iFileSize);
       
  1191                             }
       
  1192                         else
       
  1193                             {
       
  1194                             SetFileSize(iFileSize);
       
  1195                             }
       
  1196                         FillSourceBuffers();
       
  1197                         iStreamControl->Prime();
       
  1198                         }
       
  1199                     else
       
  1200                         {
       
  1201                         switch(evt->GetErrorCode())
       
  1202                             {
       
  1203                             case KErrNotSupported:
       
  1204                             case KErrPermissionDenied:
       
  1205                             case KErrCANoRights:
       
  1206                                 iAsyncCallBack->PlayComplete(evt->GetErrorCode());
       
  1207                                 iIsEOFReached = ETrue;
       
  1208                                 delete iFile;
       
  1209                                 iFile = NULL;
       
  1210                                 break;
       
  1211 
       
  1212                             case KErrDied:
       
  1213                                 Stop();
       
  1214                                 iAsyncCallBack->PlayComplete(evt->GetErrorCode());
       
  1215                                 iIsEOFReached = ETrue;
       
  1216                                 delete iFile;
       
  1217                                 iFile = NULL;
       
  1218                                 break;
       
  1219                             }
       
  1220                         }
       
  1221                     break;
       
  1222                 case MStreamControl::PRIMED:
       
  1223                     iState = EPrimed;
       
  1224                     DEBPRN1(_L("CAudioPdProperties::Event:EStateChanged[Primed]"));
       
  1225                     iAsyncCallBack->InitComplete(evt->GetErrorCode(), Duration());
       
  1226                     break;
       
  1227                 case MStreamControl::EXECUTING:
       
  1228                     DEBPRN1(_L("CAudioPdProperties::Event:EStateChanged[Playing]"));
       
  1229                     iStopCalled = EFalse;
       
  1230                     iState = EPlaying;
       
  1231                     iAsyncCallBack->PlayingCallback();
       
  1232                     break;
       
  1233                 case MStreamControl::BUFFERING:
       
  1234                     DEBPRN1(_L("CAudioPdProperties::Event:EStateChanged[Buffering]"));
       
  1235                     if(iBuffering)
       
  1236                         {
       
  1237                         iStreamControl->Pause();
       
  1238                         //iAsyncCallBack->PlayComplete(KErrDied);
       
  1239                         iAsyncCallBack->PlayComplete(KErrUnderflow);
       
  1240                         }
       
  1241                     iState = EBuffering;
       
  1242                     break;
       
  1243                 case MStreamControl::PAUSED:
       
  1244                     iState = EPaused;
       
  1245                     iAsyncCallBack->PausedCallback();
       
  1246                     DEBPRN2(_L("CAudioPdProperties::Event:EStateChanged[Paused] [%d]"),evt->GetErrorCode());
       
  1247                     break;
       
  1248                 default:
       
  1249                     break;
       
  1250                 };
       
  1251             }
       
  1252             break;
       
  1253 
       
  1254 
       
  1255         case MSourceControlObserver::KBufferProcessedEvent:
       
  1256             {
       
  1257             MBufferProcessedEvent* evt = (MBufferProcessedEvent*)aEventObject;
       
  1258             DEBPRN3(_L("CAudioPdProperties::Event:EBufferProcessed[AudioBuffer[0x%x]Reason[%d]]") , evt->GetDataBuffer(), evt->GetErrorCode() );
       
  1259             TInt index = iBuffers.Find( evt->GetDataBuffer() );
       
  1260             if ( index >= 0 )
       
  1261                 {
       
  1262                 iAvailable[index] = ETrue;
       
  1263                 }
       
  1264 
       
  1265             if(!iBufferEmptiedEventAO->IsActive() && !iIsEOFReached)
       
  1266                 {
       
  1267                 iBufferEmptiedEventAO->SetActive();
       
  1268                 iBufferEmptiedEventAO->SetBuffer(evt->GetDataBuffer());
       
  1269                 }
       
  1270 
       
  1271             if(iBufferEmptiedEventAO->IsActive())
       
  1272                 {
       
  1273                 TRequestStatus* status = &(iBufferEmptiedEventAO->iStatus);
       
  1274                 User::RequestComplete(status,evt->GetErrorCode());
       
  1275                 }
       
  1276             }
       
  1277             break;
       
  1278 
       
  1279         case MSourceControlObserver::KBitRateChangedEvent:
       
  1280             {
       
  1281             //TUint rate = 0;
       
  1282             //DEBPRN2(_L("CAudioPdProperties::Event:BitRateChanged[%d]"),rate);
       
  1283             }
       
  1284             break;
       
  1285 
       
  1286         case MStreamControlObserver::KDurationChangedEvent:
       
  1287             break;
       
  1288         default:
       
  1289             break;
       
  1290         };
       
  1291     }
       
  1292 
       
  1293 TInt CAudioPdProperties::ReadFromFileAndWriteToStream(TInt aIndex)
       
  1294     {
       
  1295     MDataBuffer* buffer = iBuffers[aIndex];
       
  1296     buffer->GetBufferPtr().FillZ();
       
  1297     // Read data into CAudioBuffer
       
  1298     TInt filePos = 0;
       
  1299     iFile->Seek(ESeekCurrent,filePos);
       
  1300 
       
  1301     DEBPRN4(_L("CAudioPdProperties::ReadFromFileAndWriteToStream \
       
  1302     BytesDL[%d] filePos[%d] MaxLength[%d]"),iBytesDownloaded,filePos, buffer->GetBufferPtr().MaxLength());
       
  1303     TInt err1(KErrNone);
       
  1304     if(iBytesDownloaded - filePos > buffer->GetBufferPtr().MaxLength() || iDownloadComplete)
       
  1305         {
       
  1306         err1 = iFile->Read( buffer->GetBufferPtr(),  buffer->GetBufferPtr().MaxLength());
       
  1307         }
       
  1308     else
       
  1309         {
       
  1310         iBuffering =  ETrue;
       
  1311         return KErrUnderflow;
       
  1312         }
       
  1313     DEBPRN2(_L("CAudioPdProperties::ReadFromFileAndWriteToStream File Read Error [%d]"),err1);
       
  1314     User::LeaveIfError(err1);
       
  1315     iBytesReadFromFile += buffer->GetBufferPtr().Length();
       
  1316 
       
  1317     DEBPRN3(_L("CAudioPdProperties::ReadFromFileAndWriteToStream\
       
  1318     bufferReadLen[%d] Buf Len[%d]"),buffer->GetBufferPtr().Length(),buffer->GetBufferPtr().MaxLength() );
       
  1319 
       
  1320     if (buffer->GetBufferPtr().Length() < buffer->GetBufferPtr().MaxLength() && (iBytesReadFromFile < iFileSize))
       
  1321         {
       
  1322 
       
  1323         iBytesReadFromFile = iBytesReadFromFile - buffer->GetBufferPtr().Length();
       
  1324         TInt seekOffset = -(buffer->GetBufferPtr().Length());
       
  1325         iFile->Seek( ESeekCurrent, seekOffset );
       
  1326         iBuffering =  ETrue;
       
  1327         DEBPRN3(_L("CAudioPdProperties::ReadFromFileAndWriteToStream\
       
  1328         BytesReadFromFile[%d] seekOffset[%d]"),iBytesReadFromFile,seekOffset );
       
  1329         return KErrOverflow;
       
  1330         }
       
  1331     else if(buffer->GetBufferPtr().Length() < buffer->GetBufferPtr().MaxLength())
       
  1332         {
       
  1333         buffer->SetLastBuffer( ETrue );
       
  1334         iIsEOFReached = ETrue;
       
  1335         //iFile.Close();
       
  1336         }
       
  1337     else
       
  1338         {
       
  1339         buffer->SetLastBuffer( EFalse );
       
  1340         }
       
  1341 
       
  1342     // Write data into iMDataBufferSource
       
  1343     DEBPRN4(_L("CAudioPdProperties::ReadFromFileAndWriteToStream\
       
  1344     [AudioBuffer[0x%x]FileSize[%d]BytesRead[%d]]") , buffer, iFileSize, iBytesReadFromFile );
       
  1345 
       
  1346     TInt err(KErrNone);
       
  1347     err = iMDataBufferSource->WriteData( *buffer );
       
  1348 
       
  1349     if (err == KErrNone)
       
  1350         {
       
  1351         iAvailable[aIndex] = EFalse;
       
  1352         }
       
  1353     else if ( err == KErrOverflow )
       
  1354         {
       
  1355         // There isn't enough memory in the player to buffer the data.
       
  1356         // reset the file pos
       
  1357         TInt size = -(buffer->GetBufferPtr().Length());
       
  1358         iFile->Seek( ESeekCurrent, size );
       
  1359         iBytesReadFromFile -= size;
       
  1360         }
       
  1361     return err;
       
  1362     }
       
  1363 
       
  1364 
       
  1365 void CAudioPdProperties::BufferEmptiedBySource()
       
  1366     {
       
  1367     TInt i = 0;
       
  1368     if (!iIsEOFReached &&
       
  1369         ( iBufferEmptiedEventAO->Error() == KErrNone) )
       
  1370         {
       
  1371 
       
  1372         for(i=0; i < iAvailable.Count(); i++)
       
  1373             {
       
  1374             if(iAvailable[i])
       
  1375                 break;
       
  1376             }
       
  1377 
       
  1378         if(!iBuffering)
       
  1379             {
       
  1380             TInt err = ReadFromFileAndWriteToStream( i );
       
  1381             if ( err != KErrNone)
       
  1382                 {
       
  1383                 // Do Something..
       
  1384                 }
       
  1385             }
       
  1386         }
       
  1387     else if (iBufferEmptiedEventAO->Error() == KErrCancel)
       
  1388         {
       
  1389 
       
  1390         /*if(!iStopCalled)
       
  1391             {
       
  1392             MDataBuffer* buffer = iBufferEmptiedEventAO->GetBuffer();
       
  1393             iBytesReadFromFile = iBytesReadFromFile - buffer->GetBufferPtr().Length();
       
  1394             TInt seekOffset = -(buffer->GetBufferPtr().Length());
       
  1395             iFile.Seek( ESeekCurrent, seekOffset );
       
  1396 
       
  1397             TInt filePos = 0;
       
  1398             iFile.Seek(ESeekCurrent,filePos);
       
  1399 
       
  1400             DEBPRN4(_L("CAudioPdProperties::BufferEmptiedBySource() \
       
  1401             BytesReadFromFile[%d] filePos[%d] MaxLength[%d]"),iBytesReadFromFile,filePos, buffer->GetBufferPtr().MaxLength());
       
  1402             }*/
       
  1403         }
       
  1404     }
       
  1405 
       
  1406 void CAudioPdProperties::FillSourceBuffers()
       
  1407     {
       
  1408     DEBPRN1(_L("CAudioPdProperties::FillSourceBuffers() enter"));
       
  1409     TInt index = iAvailable.Find(ETrue);
       
  1410     DEBPRN2(_L("CAudioPdProperties::FillSourceBuffers() index[%d]"),index);
       
  1411     while ( (index != KErrNotFound ) && (!iIsEOFReached))
       
  1412         {
       
  1413         TInt err = ReadFromFileAndWriteToStream( index );
       
  1414         if(err)
       
  1415             {
       
  1416             iBuffering = ETrue;
       
  1417             break;
       
  1418             }
       
  1419         else
       
  1420             {
       
  1421             iBuffering = EFalse;
       
  1422             }
       
  1423         // Exit the loop if file EOF.
       
  1424         if ( !iIsEOFReached )
       
  1425             {
       
  1426             // Get the next free buffer
       
  1427             index = iAvailable.Find(ETrue);
       
  1428             }
       
  1429         }
       
  1430     DEBPRN2(_L("CAudioPdProperties::FillSourceBuffers() exit Buffering[%d]"), iBuffering);
       
  1431     }
       
  1432 
       
  1433 TInt CAudioPdProperties::ExtractDRMRestrictionsL()
       
  1434     {
       
  1435     DEBPRN1(_L("CAudioPdProperties::ExtractDRMRestrictionsL() enter"));
       
  1436     TInt status(KErrNone);
       
  1437 
       
  1438     ContentAccess::CContent* content(NULL);
       
  1439 	ContentAccess::CData* data(NULL);
       
  1440 	CDRMConfigIntfc* drmConfigIntfc(NULL);
       
  1441 
       
  1442 
       
  1443     if(iFileName)
       
  1444         {
       
  1445 	    content = CContent::NewL(*iFileName, EContentShareReadWrite) ;
       
  1446         }
       
  1447     else
       
  1448         {
       
  1449         content = CContent::NewL(iFileHandle);
       
  1450         }
       
  1451 	data = content->OpenContentL(EPeek,EContentShareReadWrite);
       
  1452 
       
  1453 	status = data->GetAttribute(EIsProtected, isProtected);
       
  1454 
       
  1455 	if(!isProtected)
       
  1456 	    {
       
  1457         DEBPRN2(_L("CAudioPdProperties::ExtractDRMRestrictionsL() isProtected[%d]"),isProtected);
       
  1458         delete data;
       
  1459         delete content;
       
  1460         return status;
       
  1461 	    }
       
  1462 
       
  1463     TInt value = 0;
       
  1464     content->GetAttribute(EDrmAllowedOutputs,value);
       
  1465     TPtr8 des = iMimeType->Des();
       
  1466     data->GetMimeTypeL(des);
       
  1467 
       
  1468     TAny* intfc(NULL);
       
  1469     TVersion ver(KDRMConfigIntfcMajorVer1, KDRMConfigIntfcMinorVer1, KDRMConfigIntfcBuildVer1);
       
  1470     status = iMDataBufferSource->GetInterface(KDRMConfigIntfc,
       
  1471                                                   ver,
       
  1472                                                   intfc);
       
  1473     if (status == KErrNone)
       
  1474         {
       
  1475         drmConfigIntfc = (CDRMConfigIntfc*)intfc;
       
  1476         }
       
  1477     else
       
  1478         {
       
  1479         delete data;
       
  1480         delete content;
       
  1481         return status;
       
  1482         }
       
  1483 
       
  1484     if(value & EDrmAllowAudioAnalog)
       
  1485         {
       
  1486         drmConfigIntfc->AppendAllowedOutputDevice(EAudioAllowAnalog);
       
  1487         }
       
  1488     if(value & EDrmAllowAudioFmTransmitter)
       
  1489         {
       
  1490         drmConfigIntfc->AppendAllowedOutputDevice(EAudioAllowFMTx);
       
  1491         }
       
  1492     if(value & EDrmAllowAudioBluetooth)
       
  1493         {
       
  1494         drmConfigIntfc->AppendAllowedOutputDevice(EAudioAllowBTA2DP);
       
  1495         drmConfigIntfc->AppendAllowedOutputDevice(EAudioAllowBTHFPHSP);
       
  1496         }
       
  1497     if(value & EDrmAllowAudioUplink)
       
  1498         {
       
  1499         drmConfigIntfc->AppendAllowedOutputDevice(EAudioAllowUplink);
       
  1500         }
       
  1501     if(value & EDrmAllowVideoAnalog)
       
  1502         {
       
  1503         drmConfigIntfc->AppendAllowedOutputDevice(EVideoAllowAnalog);
       
  1504         }
       
  1505     if(value & EDrmAllowVideoMacroVision)
       
  1506         {
       
  1507         drmConfigIntfc->AppendAllowedOutputDevice(EVideoAllowMacroVision);
       
  1508         }
       
  1509 
       
  1510     if(value == EDrmAllowAll)
       
  1511         {
       
  1512         drmConfigIntfc->AppendAllowedOutputDevice(EAudioAllowAll);
       
  1513         }
       
  1514     /**
       
  1515 	* RIM CR 417-7642: HDMI with HDCP to Resctricted Audio Output API
       
  1516 	* Due to addition of new ENUMs to CRestrictedAudioOutput::TAllowedOutputPreference for HDMI and HDCP
       
  1517 	* EAllowAudioHDMI and EAllowAudioHdmiHdcpRequired,the same is matched by adding
       
  1518 	* EAudioAllowHDMI and EAudioAllowHdmiHdcpRequired. These ENUM values are matched for the values from drmagents.h
       
  1519 	*/
       
  1520 
       
  1521     if(value == EDrmAllowAudioHdmi)
       
  1522         {
       
  1523         drmConfigIntfc->AppendAllowedOutputDevice(EAudioAllowHDMI);
       
  1524         }
       
  1525     if(value == EDrmAllowAudioHdmiHdcpRequired)
       
  1526         {
       
  1527         drmConfigIntfc->AppendAllowedOutputDevice(EAudioAllowHdmiHdcpRequired);
       
  1528         }
       
  1529 
       
  1530     delete data;
       
  1531     delete content;
       
  1532     delete drmConfigIntfc;
       
  1533 
       
  1534     return status;
       
  1535 
       
  1536     }
       
  1537 
       
  1538 TInt CAudioPdProperties::ReOpenCAF()
       
  1539     {
       
  1540     TInt status(KErrNone);
       
  1541     DEBPRN1(_L("CAudioPdProperties::ReOpenCAF"));
       
  1542 
       
  1543     // Read data into CAudioBuffer
       
  1544     TInt filePos = 0;
       
  1545     iFile->Seek(ESeekCurrent,filePos);
       
  1546 
       
  1547     delete iFile;
       
  1548     iFile = NULL;
       
  1549 
       
  1550     if(iFileName)
       
  1551         {
       
  1552        	iFile =  CContentFile::NewL(iFs,*iFileName, KNullDesC, EFileShareAny,EFalse);
       
  1553         }
       
  1554     else
       
  1555         {
       
  1556         iFile =  CContentFile::NewL(iFileHandle, KNullDesC ,EFalse);
       
  1557         }
       
  1558 
       
  1559     if(iFile)
       
  1560         {
       
  1561         status = iFile->Seek(ESeekStart,filePos);
       
  1562         if(isProtected)
       
  1563             {
       
  1564             iFile->Size(iFileSize);
       
  1565             SetFileSize(iFileSize);
       
  1566             }
       
  1567         }
       
  1568 
       
  1569     DEBPRN3(_L("CAudioPdProperties::ReOpenCAF Exit status[%d] iFileSize[%d]"),status,iFileSize);
       
  1570     return status;
       
  1571     }
       
  1572 
       
  1573 // End of File