mmfenh/advancedaudiocontroller/audiocontrollerpluginsvariant/AdvancedAudioController/Src/AdvancedAudioPlayControllerExt.cpp
changeset 0 71ca22bcf22a
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:  This file contains the base class from which specific audio
       
    15 *                play controllers are derived. This class encapsulates common
       
    16 *                behavior for all audio play controllers.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "AdvancedAudioPlayController.h"
       
    23 #include "AdvancedAudioResource.h"
       
    24 #include "DebugMacros.h"
       
    25 
       
    26 #include <AudioOutput.h>
       
    27 #include <MetaDataFieldContainer.h>
       
    28 #include <MetaDataUtility.h>
       
    29 #include <mmfformatimplementationuids.hrh>
       
    30 #include <mmfmeta.h>
       
    31 #include <MultimediaDataSourceEvents.h>
       
    32 #include <MultimediaDataSourceFactory.h>
       
    33 #include <oma2dcf.h>
       
    34 #include <DRMConfigIntfc.h>
       
    35 #include <AudioOutputControlUtility.h>
       
    36 
       
    37 // CONSTANTS
       
    38 
       
    39 // ============================= LOCAL FUNCTIONS ===============================
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CAdvancedAudioPlayController::MacSetSinkSampleRateL
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 EXPORT_C void CAdvancedAudioPlayController::MacSetSinkSampleRateL(
       
    48 	TUint aSampleRate)
       
    49     {
       
    50     if (!iDataSink || !iDataSource)
       
    51 		{
       
    52         User::Leave(KErrNotReady);
       
    53 		}
       
    54 
       
    55     if (iDataSink->DataSinkType() != KUidMmfFileSink)
       
    56         {
       
    57         User::Leave(KErrNotSupported);
       
    58         }
       
    59 
       
    60     switch (aSampleRate)
       
    61         {
       
    62 /*
       
    63 		case KAAPSampleRate8000Hz:
       
    64         case KAAPSampleRate11025Hz:
       
    65         case KAAPSampleRate12000Hz:
       
    66         case KAAPSampleRate16000Hz:
       
    67         case KAAPSampleRate22050Hz:
       
    68         case KAAPSampleRate24000Hz:
       
    69         case KAAPSampleRate32000Hz:
       
    70         case KAAPSampleRate44100Hz:
       
    71         case KAAPSampleRate48000Hz:
       
    72         case KAAPSampleRate64000Hz:
       
    73         case KAAPSampleRate88200Hz:
       
    74         case KAAPSampleRate96000Hz:
       
    75             if ((TInt)aSampleRate > iSampleRate)
       
    76                 {
       
    77                 // Only allow downsampling
       
    78                 User::Leave(KErrNotSupported);
       
    79                 }
       
    80             else
       
    81                 {
       
    82                 iSinkSampleRate = aSampleRate;
       
    83                 }
       
    84 			break;
       
    85 //For future use...
       
    86 */
       
    87         case KAAPSampleRate8000Hz:
       
    88             if ((TUint)iSampleRate == KAAPSampleRate8000Hz ||
       
    89                  (TUint)iSampleRate == KAAPSampleRate16000Hz)
       
    90                 {
       
    91                 iSinkSampleRate = aSampleRate;
       
    92                 }
       
    93             else
       
    94                 {
       
    95                 // Very limited due to Symbian conversion limitations...
       
    96                 User::Leave(KErrNotSupported);
       
    97                 }
       
    98             break;
       
    99         case KAAPSampleRate16000Hz:
       
   100             if ((TUint)iSampleRate == KAAPSampleRate16000Hz)
       
   101                 {
       
   102                 iSinkSampleRate = aSampleRate;
       
   103                 }
       
   104             else
       
   105                 {
       
   106                 // Very limited due to Symbian conversion limitations...
       
   107                 User::Leave(KErrNotSupported);
       
   108                 }
       
   109             break;
       
   110         default:
       
   111             User::Leave(KErrNotSupported);
       
   112         }
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CAdvancedAudioPlayController::MacGetSinkBitRateL
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 EXPORT_C void CAdvancedAudioPlayController::MacSetSinkBitRateL(
       
   120 	TUint aRate)
       
   121     {
       
   122     if (!iDataSink || !iDataSource)
       
   123 		{
       
   124         User::Leave(KErrNotReady);
       
   125 		}
       
   126 
       
   127     if (iDataSink->DataSinkType() != KUidMmfFileSink ||
       
   128 		(TInt)aRate != iBitRate)
       
   129         {
       
   130         User::Leave(KErrNotSupported);
       
   131         }
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CAdvancedAudioPlayController::MacSetSinkNumChannelsL
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 EXPORT_C void CAdvancedAudioPlayController::MacSetSinkNumChannelsL(
       
   139 	TUint aNumChannels)
       
   140 	{
       
   141     if (!iDataSink)
       
   142 		{
       
   143         User::Leave(KErrNotReady);
       
   144 		}
       
   145 
       
   146     if (iDataSink->DataSinkType() != KUidMmfFileSink)
       
   147         {
       
   148         User::Leave(KErrNotSupported);
       
   149         }
       
   150 
       
   151     if (aNumChannels <= 2)
       
   152         {
       
   153         iSinkNumChannels = aNumChannels;
       
   154         }
       
   155     else
       
   156         {
       
   157         User::Leave(KErrNotSupported);
       
   158         }
       
   159 	}
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CAdvancedAudioPlayController::MacSetSinkFormatL
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 EXPORT_C void CAdvancedAudioPlayController::MacSetSinkFormatL(
       
   166 	TUid aFormatUid)
       
   167     {
       
   168     DP1(_L("CAdvancedAudioPlayController::MacSetSinkFormatL[%x]"), aFormatUid);
       
   169 
       
   170     if (aFormatUid != TUid::Uid(KMmfUidFormatRAWWrite))
       
   171         {
       
   172         User::Leave(KErrNotSupported);
       
   173         }
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CAdvancedAudioPlayController::MacSetSinkDataTypeL
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 EXPORT_C void CAdvancedAudioPlayController::MacSetSinkDataTypeL(
       
   181 	TFourCC aDataType)
       
   182 	{
       
   183     if (!iDataSink)
       
   184 		{
       
   185         User::Leave(KErrNotReady);
       
   186 		}
       
   187 
       
   188     if (iDataSink->DataSinkType() != KUidMmfFileSink ||
       
   189 		 aDataType != KMMFFourCCCodePCM16)
       
   190         {
       
   191         User::Leave(KErrNotSupported);
       
   192         }
       
   193 	}
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CAdvancedAudioPlayController::MacGetSourceSampleRateL
       
   197 // Returns the sampling rate obtrained from the source.
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 EXPORT_C void CAdvancedAudioPlayController::MacGetSourceSampleRateL(
       
   201 	TUint& aRate)
       
   202     {
       
   203     if (!iDataSource)
       
   204 		{
       
   205         User::Leave(KErrNotReady);
       
   206 		}
       
   207     aRate = iSampleRate;
       
   208     }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CAdvancedAudioPlayController::MacGetSourceBitRateL
       
   212 // Returns the bit rate obtained from the source.
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 EXPORT_C void CAdvancedAudioPlayController::MacGetSourceBitRateL(
       
   216 	TUint& aRate)
       
   217     {
       
   218     if (!iDataSource)
       
   219 		{
       
   220         User::Leave(KErrNotReady);
       
   221 		}
       
   222 		
       
   223 	// bit rate might be changed implicitly within a Controller's Utility
       
   224 //    UpdateBitRate();
       
   225     aRate = iBitRate;
       
   226 	DP1(_L("CAdvancedAudioPlayController::MacGetSourceBitRateL[%d]"), iBitRate);
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CAdvancedAudioPlayController::MacGetSourceNumChannelsL
       
   231 // Returns the number of channels from the source.
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 EXPORT_C void CAdvancedAudioPlayController::MacGetSourceNumChannelsL(
       
   235 	TUint& aNumChannels)
       
   236     {
       
   237     if (!iDataSource)
       
   238 		{
       
   239         User::Leave(KErrNotReady);
       
   240 		}
       
   241     aNumChannels = iChannels;
       
   242     }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CAdvancedAudioPlayController::MacGetSourceFormatL
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 EXPORT_C void CAdvancedAudioPlayController::MacGetSourceFormatL(
       
   249 	TUid& aFormat)
       
   250     {
       
   251     aFormat = iSourceFormat;
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CAdvancedAudioPlayController::MacGetSourceDataTypeL
       
   256 // Returns the data type from the source.
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 EXPORT_C void CAdvancedAudioPlayController::MacGetSourceDataTypeL(
       
   260 	TFourCC& aDataType)
       
   261     {
       
   262     if (!iDataSource)
       
   263     	{
       
   264         User::Leave(KErrNotReady);
       
   265 		}
       
   266     aDataType = iDataType;
       
   267     }
       
   268 
       
   269 // -----------------------------------------------------------------------------
       
   270 // CAdvancedAudioPlayController::MacGetSinkSampleRateL
       
   271 // Returns the sample rates configured in the audio output.
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 EXPORT_C void CAdvancedAudioPlayController::MacGetSinkSampleRateL(
       
   275 	TUint& aRate)
       
   276     {
       
   277     if (!iDataSink)
       
   278     	{
       
   279         User::Leave(KErrNotReady);
       
   280 		}
       
   281 
       
   282     RArray<TUint> rates;
       
   283     CleanupClosePushL(rates);
       
   284     iAudioOutput->ConfigRatesL(rates);
       
   285 
       
   286     ASSERT(rates.Count() == 1);
       
   287     aRate = rates[0];
       
   288     CleanupStack::PopAndDestroy(&rates);	// rates
       
   289     }
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // CAdvancedAudioPlayController::MacGetSinkBitRateL
       
   293 // Default implementation.
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 EXPORT_C void CAdvancedAudioPlayController::MacGetSinkBitRateL(
       
   297 	TUint& aRate)
       
   298     {
       
   299     if (!iDataSink || !iDataSource)
       
   300 		{
       
   301         User::Leave(KErrNotReady);
       
   302 		}
       
   303 
       
   304     if (iDataSink->DataSinkType() != KUidMmfFileSink)
       
   305         {
       
   306         User::Leave(KErrNotSupported);
       
   307         }
       
   308 
       
   309     aRate = iBitRate;
       
   310     }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CAdvancedAudioPlayController::MacGetSinkNumChannelsL
       
   314 // Returns the number of channels configured in the audio output.
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 EXPORT_C void CAdvancedAudioPlayController::MacGetSinkNumChannelsL(
       
   318 	TUint& aNumChannels)
       
   319     {
       
   320     if (!iDataSink)
       
   321      	{
       
   322 		User::Leave(KErrNotReady);
       
   323 		}
       
   324 
       
   325     RArray<TUint> channels;
       
   326     CleanupClosePushL(channels);
       
   327 	iAudioOutput->ConfigChannelsL(channels);
       
   328 
       
   329     ASSERT(channels.Count() == 1);
       
   330     aNumChannels = channels[0];
       
   331     CleanupStack::PopAndDestroy(&channels);	// channels
       
   332     }
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // CAdvancedAudioPlayController::MacGetSinkFormatL
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 EXPORT_C void CAdvancedAudioPlayController::MacGetSinkFormatL(
       
   339 	TUid& aFormat)
       
   340     {
       
   341     aFormat = TUid::Uid(KMmfUidFormatRAWWrite);
       
   342     }
       
   343 
       
   344 // -----------------------------------------------------------------------------
       
   345 // CAdvancedAudioPlayController::MacGetSinkDataTypeL
       
   346 // Returns the data types configured in the audio output.
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 EXPORT_C void CAdvancedAudioPlayController::MacGetSinkDataTypeL(
       
   350 	TFourCC& aDataType)
       
   351     {
       
   352     if (!iDataSink)
       
   353     	{
       
   354 		User::Leave(KErrNotReady);
       
   355 		}
       
   356 
       
   357     RArray<TFourCC> dataTypes;
       
   358     CleanupClosePushL(dataTypes);
       
   359     iAudioOutput->ConfigDataTypesL(dataTypes);
       
   360 
       
   361     ASSERT(dataTypes.Count() == 1);
       
   362     aDataType = dataTypes[0];
       
   363     CleanupStack::PopAndDestroy(&dataTypes);	// dataTypes
       
   364     }
       
   365 
       
   366 // -----------------------------------------------------------------------------
       
   367 // CAdvancedAudioPlayController::MacGetSupportedSourceSampleRatesL
       
   368 // Returns the supported sample rates.
       
   369 // -----------------------------------------------------------------------------
       
   370 //
       
   371 EXPORT_C void CAdvancedAudioPlayController::MacGetSupportedSourceSampleRatesL(
       
   372 	RArray<TUint>& aSupportedRates)
       
   373     {
       
   374     if (!iDataSource)
       
   375     	{
       
   376         User::Leave(KErrNotReady);
       
   377 		}
       
   378 
       
   379     aSupportedRates.Reset();
       
   380     User::LeaveIfError(aSupportedRates.Append(iSampleRate));
       
   381     }
       
   382 
       
   383 // -----------------------------------------------------------------------------
       
   384 // CAdvancedAudioPlayController::MacGetSupportedSourceBitRatesL
       
   385 // Returns the supported bit rate by the source.
       
   386 // -----------------------------------------------------------------------------
       
   387 //
       
   388 EXPORT_C void CAdvancedAudioPlayController::MacGetSupportedSourceBitRatesL(
       
   389 	RArray<TUint>& aSupportedRates)
       
   390     {
       
   391     if (!iDataSource)
       
   392     	{
       
   393         User::Leave(KErrNotReady);
       
   394 		}
       
   395 
       
   396     aSupportedRates.Reset();
       
   397     User::LeaveIfError(aSupportedRates.Append(iBitRate));
       
   398     }
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // CAdvancedAudioPlayController::MacGetSupportedSourceNumChannelsL
       
   402 // Returns the supported number of channels by the source.
       
   403 // -----------------------------------------------------------------------------
       
   404 //
       
   405 EXPORT_C void CAdvancedAudioPlayController::MacGetSupportedSourceNumChannelsL(
       
   406 	RArray<TUint>& aSupportedChannels)
       
   407     {
       
   408     if (!iDataSource)
       
   409     	{
       
   410         User::Leave(KErrNotReady);
       
   411 		}
       
   412 
       
   413     aSupportedChannels.Reset();
       
   414     User::LeaveIfError(aSupportedChannels.Append(iChannels));
       
   415     }
       
   416 
       
   417 // -----------------------------------------------------------------------------
       
   418 // CAdvancedAudioPlayController::MacGetSupportedSourceDataTypesL
       
   419 // Returns the supported data types by the source.
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 EXPORT_C void CAdvancedAudioPlayController::MacGetSupportedSourceDataTypesL(
       
   423 	RArray<TFourCC>& aSupportedDataTypes)
       
   424     {
       
   425     if (!iDataSource)
       
   426     	{
       
   427         User::Leave(KErrNotReady);
       
   428 		}
       
   429 
       
   430     aSupportedDataTypes.Reset();
       
   431     User::LeaveIfError(aSupportedDataTypes.Append(iDataType));
       
   432     }
       
   433 
       
   434 // -----------------------------------------------------------------------------
       
   435 // CAdvancedAudioPlayController::MacGetSupportedSinkSampleRatesL
       
   436 // Returns the supported sample rates by audio output.
       
   437 // -----------------------------------------------------------------------------
       
   438 //
       
   439 EXPORT_C void CAdvancedAudioPlayController::MacGetSupportedSinkSampleRatesL(
       
   440 	RArray<TUint>& aSupportedRates)
       
   441     {
       
   442     if (!iDataSource)
       
   443     	{
       
   444         User::Leave(KErrNotReady);
       
   445 		}
       
   446 
       
   447     aSupportedRates.Reset();
       
   448     iAudioOutput->CapabilitiesRatesL(aSupportedRates);
       
   449     }
       
   450 
       
   451 // -----------------------------------------------------------------------------
       
   452 // CAdvancedAudioPlayController::MacGetSupportedSinkBitRatesL
       
   453 // Default implementation.
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 EXPORT_C void CAdvancedAudioPlayController::MacGetSupportedSinkBitRatesL(
       
   457 	RArray<TUint>& aSupportedRates)
       
   458     {
       
   459     if (!iDataSink || !iDataSource)
       
   460 		{
       
   461         User::Leave(KErrNotReady);
       
   462 		}
       
   463 
       
   464     if (iDataSink->DataSinkType() != KUidMmfFileSink)
       
   465         {
       
   466         User::Leave(KErrNotSupported);
       
   467         }
       
   468 
       
   469     aSupportedRates.Reset();
       
   470     aSupportedRates.Append(iBitRate);
       
   471     }
       
   472 
       
   473 // -----------------------------------------------------------------------------
       
   474 // CAdvancedAudioPlayController::MacGetSupportedSinkNumChannelsL
       
   475 // Returns the supported number of channels by audio output.
       
   476 // -----------------------------------------------------------------------------
       
   477 //
       
   478 EXPORT_C void CAdvancedAudioPlayController::MacGetSupportedSinkNumChannelsL(
       
   479 	RArray<TUint>& aSupportedChannels)
       
   480     {
       
   481     if (!iDataSink)
       
   482     	{
       
   483         User::Leave(KErrNotReady);
       
   484 		}
       
   485 
       
   486     aSupportedChannels.Reset();
       
   487     iAudioOutput->CapabilitiesChannelsL(aSupportedChannels);
       
   488     }
       
   489 
       
   490 // -----------------------------------------------------------------------------
       
   491 // CAdvancedAudioPlayController::MacGetSupportedSinkDataTypesL
       
   492 // Returns the supported data types by audio output.
       
   493 // -----------------------------------------------------------------------------
       
   494 //
       
   495 EXPORT_C void CAdvancedAudioPlayController::MacGetSupportedSinkDataTypesL(
       
   496 	RArray<TFourCC>& aSupportedDataTypes)
       
   497     {
       
   498     if (!iDataSink)
       
   499     	{
       
   500         User::Leave(KErrNotReady);
       
   501 		}
       
   502 
       
   503     aSupportedDataTypes.Reset();
       
   504     iAudioOutput->CapabilitiesDataTypesL(aSupportedDataTypes);
       
   505     }
       
   506 
       
   507 // -----------------------------------------------------------------------------
       
   508 // CAdvancedAudioPlayController::MapcSetPlaybackWindowL
       
   509 // Default implementation.
       
   510 // -----------------------------------------------------------------------------
       
   511 //
       
   512 EXPORT_C void CAdvancedAudioPlayController::MapcSetPlaybackWindowL(
       
   513     const TTimeIntervalMicroSeconds& aStart,
       
   514     const TTimeIntervalMicroSeconds& aEnd)
       
   515     {
       
   516 	DP0(_L("CAdvancedAudioPlayController::MapcSetPlaybackWindowL"));
       
   517     SetPlaybackWindowBoundariesL(aStart, aEnd);
       
   518     }
       
   519 
       
   520 // -----------------------------------------------------------------------------
       
   521 // CAdvancedAudioPlayController::MapcDeletePlaybackWindowL
       
   522 // Default implementation.
       
   523 // -----------------------------------------------------------------------------
       
   524 //
       
   525 EXPORT_C void CAdvancedAudioPlayController::MapcDeletePlaybackWindowL()
       
   526     {
       
   527     DP0(_L("CAdvancedAudioPlayController::MapcDeletePlaybackWindowL"));
       
   528     // iPlayWindowStartPosition = TTimeIntervalMicroSeconds(0);
       
   529     // iPlayWindowEndPosition = TTimeIntervalMicroSeconds(0);
       
   530     // ClearPlayWindow() can be called in either EPlaying or EPaused or EStopped state.
       
   531     // If ClearPlayWindow() is called before opening an audio file, then it doesn't have any effect.
       
   532     // This will call the Unregister event on the play window end position and sets the start and end position accordingly
       
   533     SetPlaybackWindowBoundariesL(0, 0);
       
   534     }
       
   535 
       
   536 // -----------------------------------------------------------------------------
       
   537 // CAdvancedAudioPlayController::MapcGetLoadingProgressL
       
   538 // Default implementation.
       
   539 // -----------------------------------------------------------------------------
       
   540 //
       
   541 EXPORT_C void CAdvancedAudioPlayController::MapcGetLoadingProgressL(
       
   542 	TInt& /*aPercentageComplete*/)
       
   543     {
       
   544     User::Leave(KErrNotSupported);
       
   545     }
       
   546 
       
   547 // -----------------------------------------------------------------------------
       
   548 // CAdvancedAudioPlayController::MapdSetVolumeL
       
   549 // Sets the volume in audion output.
       
   550 // -----------------------------------------------------------------------------
       
   551 //
       
   552 EXPORT_C void CAdvancedAudioPlayController::MapdSetVolumeL(
       
   553 	TInt aVolume)
       
   554     {
       
   555     DP1(_L("CAdvancedAudioPlayController::MapdSetVolumeL[%d]"), aVolume);
       
   556 
       
   557     if (!iDataSink)
       
   558     	{
       
   559         User::Leave(KErrNotReady);
       
   560 		}
       
   561 
       
   562     if (0 <= aVolume && aVolume <= iAudioOutput->MaxVolumeL())
       
   563         {
       
   564         iAudioOutput->SetVolumeL(aVolume);
       
   565         }
       
   566     }
       
   567 
       
   568 // -----------------------------------------------------------------------------
       
   569 // CAdvancedAudioPlayController::MapdGetMaxVolumeL
       
   570 // Returns the max volume supported by the audio output.
       
   571 // -----------------------------------------------------------------------------
       
   572 //
       
   573 EXPORT_C void CAdvancedAudioPlayController::MapdGetMaxVolumeL(
       
   574 	TInt& aMaxVolume)
       
   575     {
       
   576     if (!iDataSink)
       
   577     	{
       
   578         User::Leave(KErrNotReady);
       
   579 		}
       
   580 
       
   581 	aMaxVolume = iAudioOutput->MaxVolumeL();
       
   582     }
       
   583 
       
   584 // -----------------------------------------------------------------------------
       
   585 // CAdvancedAudioPlayController::MapdGetVolumeL
       
   586 // Returns the current volume set in audio output.
       
   587 // -----------------------------------------------------------------------------
       
   588 //
       
   589 EXPORT_C void CAdvancedAudioPlayController::MapdGetVolumeL(
       
   590 	TInt& aVolume)
       
   591     {
       
   592     if (!iDataSink)
       
   593     	{
       
   594         User::Leave(KErrNotReady);
       
   595 		}
       
   596 
       
   597     aVolume = iAudioOutput->VolumeL();
       
   598     }
       
   599 
       
   600 // -----------------------------------------------------------------------------
       
   601 // CAdvancedAudioPlayController::MapdSetVolumeRampL
       
   602 // Sets the volume ramp duration in audio output.
       
   603 // -----------------------------------------------------------------------------
       
   604 //
       
   605 EXPORT_C void CAdvancedAudioPlayController::MapdSetVolumeRampL(
       
   606 	const TTimeIntervalMicroSeconds& aRampDuration)
       
   607     {
       
   608     if (!iDataSink)
       
   609     	{
       
   610         User::Leave(KErrNotReady);
       
   611 		}
       
   612 
       
   613 	iAudioOutput->SetVolumeRampL(aRampDuration);
       
   614     }
       
   615 
       
   616 // -----------------------------------------------------------------------------
       
   617 // CAdvancedAudioPlayController::MapdSetBalanceL
       
   618 // Sets the balance.
       
   619 // -----------------------------------------------------------------------------
       
   620 //
       
   621 EXPORT_C void CAdvancedAudioPlayController::MapdSetBalanceL(
       
   622 	TInt aBalance)
       
   623     {
       
   624     if(!iDataSink)
       
   625     	{
       
   626         User::Leave(KErrNotReady);
       
   627 		}
       
   628 
       
   629     if(aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight)
       
   630     	{
       
   631         User::Leave(KErrArgument);
       
   632 		}
       
   633 
       
   634     TInt left  = 0;
       
   635     TInt right = 0;
       
   636     TInt rightBalance = 0;
       
   637     TInt leftBalance  = 0;
       
   638     
       
   639     CalculateLeftRightBalanceL(left, right, aBalance);
       
   640 	iAudioOutput->SetPlayBalanceL(left, right);
       
   641     iAudioOutput->GetPlayBalanceL(leftBalance, rightBalance);
       
   642 
       
   643     TBool postCondition = ((rightBalance == right) && (leftBalance == left));
       
   644     
       
   645     if (!postCondition)
       
   646         User::Leave(KErrNotSupported);
       
   647     }
       
   648 
       
   649 // -----------------------------------------------------------------------------
       
   650 // CAdvancedAudioPlayController::MapdGetBalanceL
       
   651 // Returns the currently set balance value.
       
   652 // -----------------------------------------------------------------------------
       
   653 //
       
   654 EXPORT_C void CAdvancedAudioPlayController::MapdGetBalanceL(
       
   655 	TInt& aBalance)
       
   656     {
       
   657     if (!iDataSink)
       
   658     	{
       
   659         User::Leave(KErrNotReady);
       
   660 		}
       
   661 
       
   662     TInt left = 0;
       
   663     TInt right = 0;
       
   664 
       
   665 	iAudioOutput->GetPlayBalanceL(left, right);
       
   666     CalculateBalanceL(aBalance, left, right);
       
   667     }
       
   668 
       
   669 // -----------------------------------------------------------------------------
       
   670 // CAdvancedAudioPlayController::GetBitRate
       
   671 // -----------------------------------------------------------------------------
       
   672 //
       
   673 EXPORT_C TInt CAdvancedAudioPlayController::GetBitRate(TUint& aBitRate)
       
   674     {
       
   675 	DP0(_L("CAdvancedAudioPlayController::GetBitRate"));
       
   676     UpdateBitRate();    
       
   677     aBitRate = iBitRate;
       
   678     return KErrNone;
       
   679     }
       
   680     
       
   681 // -----------------------------------------------------------------------------
       
   682 // CAdvancedAudioPlayController::MscEnableEvents
       
   683 // -----------------------------------------------------------------------------
       
   684 //
       
   685 EXPORT_C TInt CAdvancedAudioPlayController::MscEnableEvents(TBool aEnable)
       
   686     {
       
   687     iEventsEnabled = aEnable;
       
   688         
       
   689     // bit rate might be changed implicitly within a Controller's Utility, that would have effect on the duration event
       
   690     if (iAudioUtility)
       
   691         {
       
   692         TInt err = KErrNone;
       
   693             
       
   694         if (iEventsEnabled)
       
   695             {
       
   696             // callback on every 1000 millisecond (1 second) if bitrate changes
       
   697             TRAP(err, iAudioUtility->EnableBitRateChangedEventL(1000));
       
   698             }
       
   699         else
       
   700             {
       
   701             TRAP(err, iAudioUtility->EnableBitRateChangedEventL(-1));
       
   702             }
       
   703 
       
   704 		DP1(_L("CAdvancedAudioPlayController::MscEnableEvents, EnableBitRateChangedEventL err[%d]"), err);
       
   705         }
       
   706     return KErrNone;
       
   707     }
       
   708 
       
   709 // -----------------------------------------------------------------------------
       
   710 // CAdvancedAudioPlayController::MscGetSeekingSupported
       
   711 // -----------------------------------------------------------------------------
       
   712 //
       
   713 EXPORT_C TInt CAdvancedAudioPlayController::MscGetSeekingSupported(TBool& /*aSupported*/)
       
   714     {
       
   715     return KErrNotSupported;
       
   716     }
       
   717 
       
   718 // -----------------------------------------------------------------------------
       
   719 // CAdvancedAudioPlayController::MscGetRandomSeekingSupported
       
   720 // -----------------------------------------------------------------------------
       
   721 //
       
   722 EXPORT_C TInt CAdvancedAudioPlayController::MscGetRandomSeekingSupported(TBool& /*aSupported*/)
       
   723     {
       
   724     return KErrNotSupported;
       
   725     }
       
   726 
       
   727 
       
   728 // -----------------------------------------------------------------------------
       
   729 // CAdvancedAudioPlayController::CalculateLeftRightBalanceL
       
   730 // Calculates percentage of the balance going into left and right channels.
       
   731 // -----------------------------------------------------------------------------
       
   732 //
       
   733 void CAdvancedAudioPlayController::CalculateLeftRightBalanceL(
       
   734 	TInt& aLeft,
       
   735 	TInt& aRight,
       
   736 	TInt aBalance)
       
   737     {
       
   738     if ((aBalance < KMMFBalanceMaxLeft) || (aBalance > KMMFBalanceMaxRight))
       
   739         User::Leave(KErrArgument);
       
   740     
       
   741     aLeft = (100 * (aBalance-KMMFBalanceMaxRight)) / (KMMFBalanceMaxLeft-KMMFBalanceMaxRight);
       
   742     aRight = 100 - aLeft;
       
   743     
       
   744     if ((aLeft > 100) || (aLeft < 0) || (aRight > 100) || (aRight < 0))
       
   745         User::Leave(KErrArgument);
       
   746     }
       
   747 
       
   748 // -----------------------------------------------------------------------------
       
   749 // CAdvancedAudioPlayController::CalculateBalanceL
       
   750 // Calculates the balance based on the current left and right values.
       
   751 // -----------------------------------------------------------------------------
       
   752 //
       
   753 void CAdvancedAudioPlayController::CalculateBalanceL(
       
   754 	TInt& aBalance,
       
   755 	TInt aLeft,
       
   756 	TInt aRight)
       
   757     {
       
   758     if ((aLeft == 0) && (aRight == 0))
       
   759         {
       
   760         aBalance = 0;
       
   761         }
       
   762     else
       
   763         {
       
   764         if ((aLeft + aRight) != 100)
       
   765             User::Leave(KErrArgument);
       
   766         
       
   767         if ((aLeft > 100) || (aLeft < 0) || (aRight > 100) || (aRight < 0))
       
   768             User::Leave(KErrArgument);
       
   769         
       
   770         aBalance = (aLeft * (KMMFBalanceMaxLeft-KMMFBalanceMaxRight))/100 + KMMFBalanceMaxRight;
       
   771         
       
   772         if ((aBalance < KMMFBalanceMaxLeft) || (aBalance > KMMFBalanceMaxRight))
       
   773             User::Leave(KErrArgument);
       
   774         }
       
   775     }
       
   776 
       
   777 #ifdef SYMBIAN_CAF_V2
       
   778 // -----------------------------------------------------------------------------
       
   779 // CAdvancedAudioPlayController::MdcEvaluateIntent
       
   780 // Returns the result of EvaluateIntent() when DataSourceType is KUidMmfFileSource.
       
   781 // -----------------------------------------------------------------------------
       
   782 //
       
   783 EXPORT_C TInt CAdvancedAudioPlayController::MdcEvaluateIntent(ContentAccess::TIntent aIntent)
       
   784 	{
       
   785 	if (iDataSourceAdapter == NULL)
       
   786 	    {
       
   787 	    return KErrNotReady;
       
   788 	    }
       
   789 	TInt status = iDataSourceAdapter->EvaluateIntent(aIntent);
       
   790 	return status;
       
   791 	}
       
   792 
       
   793 // -----------------------------------------------------------------------------
       
   794 // CAdvancedAudioPlayController::MdcExecuteIntent
       
   795 // Returns the result of ExecuteIntent() when DataSourceType is KUidMmfFileSource.
       
   796 // -----------------------------------------------------------------------------
       
   797 //
       
   798 EXPORT_C TInt CAdvancedAudioPlayController::MdcExecuteIntent(ContentAccess::TIntent aIntent)
       
   799 	{
       
   800     if (iDataSourceAdapter == NULL)
       
   801         {
       
   802         return KErrNotReady;
       
   803         }
       
   804 	TInt status = iDataSourceAdapter->ExecuteIntent(aIntent);
       
   805 	return status;
       
   806 	}
       
   807 
       
   808 // -----------------------------------------------------------------------------
       
   809 // CAdvancedAudioPlayController::MdcDisableAutomaticIntent
       
   810 // Returns KErrNone. Setting the iDisableAutoIntent based on the client request.
       
   811 // -----------------------------------------------------------------------------
       
   812 //
       
   813 EXPORT_C TInt CAdvancedAudioPlayController::MdcDisableAutomaticIntent(TBool aDisableAutoIntent)
       
   814 	{
       
   815 	iDisableAutoIntent = aDisableAutoIntent;
       
   816 	return KErrNone;
       
   817 	}
       
   818 
       
   819 // -----------------------------------------------------------------------------
       
   820 // CAdvancedAudioPlayController::MdcSetAgentProperty
       
   821 // Returns the result of SetAgentProperty() when DataSourceType is KUidMmfFileSource.
       
   822 // -----------------------------------------------------------------------------
       
   823 //
       
   824 EXPORT_C TInt CAdvancedAudioPlayController::MdcSetAgentProperty(ContentAccess::TAgentProperty aProperty, TInt aValue)
       
   825 	{
       
   826     if (iDataSourceAdapter == NULL)
       
   827         {
       
   828         return KErrNotReady;
       
   829         }
       
   830 	TInt status = iDataSourceAdapter->SetAgentProperty(aProperty, aValue);
       
   831 	return status;
       
   832 	}
       
   833 
       
   834 #endif
       
   835 
       
   836 // -----------------------------------------------------------------------------
       
   837 // CAdvancedAudioPlayController::MapcSetRepeats
       
   838 // Sets the number of times the audio sample is to be repeated during the playback operation.
       
   839 // -----------------------------------------------------------------------------
       
   840 //
       
   841 EXPORT_C TInt CAdvancedAudioPlayController::MapcSetRepeats(TInt aRepeatNumberOfTimes, const TTimeIntervalMicroSeconds& aTrailingSilence)
       
   842     {
       
   843     DP0(_L("CAdvancedAudioPlayController::MapcSetRepeats"));
       
   844     if (iState == EInitializing)
       
   845         {
       
   846         return KErrNotReady;
       
   847         }
       
   848     else
       
   849         {
       
   850         TInt result = DoSetRepeats(aRepeatNumberOfTimes, aTrailingSilence);
       
   851         return result;
       
   852         }
       
   853     }
       
   854 // End of file