mmfenh/advancedaudiocontroller/audiocontrollerpluginsvariant/amraudioplaycontroller/Src/AMRAudioPlayControllerPlugin.cpp
changeset 0 71ca22bcf22a
child 7 709f89d8c047
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:  Play controller for AMR audio formats.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include "AMRAudioPlayControllerPlugin.h"
       
    21 #include "AMRAudioPlayControllerPlugin.hrh"
       
    22 #include "AMRAudioControllerUtility.h"
       
    23 #include "AMRAudioPlayControllerDecoderBuilder.h"
       
    24 #include "AMRAudioPlayControllerResource.h"
       
    25 #include "DevSoundAudioOutput.h"
       
    26 #include "FileAudioOutput.h"
       
    27 #include "DebugMacros.h"
       
    28 #include <mmfformatimplementationuids.hrh>
       
    29 
       
    30 // CONSTANTS
       
    31 //const TInt KAapBufferSize       = 8*1024;
       
    32 const TUint KMonoChannel        = 1;
       
    33 const TUint KStereoChannel      = 2;
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CAMRAudioPlayControllerPlugin::CAMRAudioPlayControllerPlugin
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CAMRAudioPlayControllerPlugin::CAMRAudioPlayControllerPlugin()
       
    42 	:	iDecoderBuilder(NULL)
       
    43 	{
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CAMRAudioPlayControllerPlugin::ConstructL
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void CAMRAudioPlayControllerPlugin::ConstructL()
       
    51     {
       
    52     CAdvancedAudioPlayController::ConstructL();
       
    53 
       
    54 	iAudioResource = CAMRAudioPlayControllerResource::NewL();
       
    55     TAapProperties aapProperties = iAudioResource->PropertiesL();
       
    56     iSharedBufferMaxNum = aapProperties.iSharedBufferMaxNum;
       
    57     iSharedBufferMaxSize = aapProperties.iSharedBufferMaxSize;
       
    58     iMetaDataSupport = aapProperties.iMetaDataSupport;
       
    59 
       
    60 	iAudioUtility = CAMRAudioControllerUtility::NewL();
       
    61 	iDecoderBuilder = CAMRAudioPlayControllerDecoderBuilder::NewL();
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CAMRAudioPlayControllerPlugin::NewL
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CAMRAudioPlayControllerPlugin* CAMRAudioPlayControllerPlugin::NewL()
       
    69     {
       
    70 	DP0(_L("CAMRAudioPlayControllerPlugin::NewL"));
       
    71     CAMRAudioPlayControllerPlugin* self = new(ELeave) CAMRAudioPlayControllerPlugin;
       
    72     CleanupStack::PushL(self);
       
    73     self->ConstructL();
       
    74     CleanupStack::Pop(self);
       
    75     return self;
       
    76     }
       
    77 
       
    78 // Destructor
       
    79 CAMRAudioPlayControllerPlugin::~CAMRAudioPlayControllerPlugin()
       
    80     {
       
    81 	DP0(_L("CAMRAudioPlayControllerPlugin::~CAMRAudioPlayControllerPlugin"));
       
    82     if (iIsDRMProtected)
       
    83 		{
       
    84 		delete iDataSource;
       
    85 		}
       
    86 
       
    87     if ((iState != EStopped) && (iState != EInitialized) && iAudioOutput)
       
    88         {
       
    89         TRAPD(err, iAudioOutput->StopL());
       
    90 		err = err;
       
    91         }
       
    92 
       
    93 	delete iDecoderBuilder;
       
    94     delete iAudioUtility;
       
    95     delete iAudioResource;
       
    96     delete iAudioOutput;
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CAMRAudioPlayControllerPlugin::DoAddDataSourceL
       
   101 // Initialization of Clip properties. We build a table needed for positioning.
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void CAMRAudioPlayControllerPlugin::DoAddDataSourceL()
       
   105     {
       
   106     DP0(_L("CAMRAudioPlayControllerPlugin::DoAddDataSourceL"));
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CAMRAudioPlayControllerPlugin::DoAddDataSinkL
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void CAMRAudioPlayControllerPlugin::DoAddDataSinkL()
       
   114     {
       
   115     DP0(_L("CAMRAudioPlayControllerPlugin::DoAddDataSinkL"));
       
   116     if (iDataSink->DataSinkType() == KUidMmfAudioOutput)
       
   117 		{
       
   118 		iAudioOutput = CDevSoundAudioOutput::NewL(iPrioritySettings, *this, *iMMFDevSound);
       
   119 		iDecoderType = KAMRDecoder;
       
   120         }
       
   121     else if (iDataSink->DataSinkType() == KUidMmfFileSink)
       
   122         {
       
   123 		iAudioOutput = CFileAudioOutput::NewL(*iDataSink, iPrioritySettings, *this);
       
   124 		iDecoderType = KAMRConverter;
       
   125         }
       
   126     else
       
   127         {
       
   128         User::Leave(KErrNotSupported);
       
   129         }
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CAMRAudioPlayControllerPlugin::DoReadHeaderL
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CAMRAudioPlayControllerPlugin::DoReadHeaderL(CMMFDataBuffer* aBuffer)
       
   137     {
       
   138     DP0(_L("CAMRAudioPlayControllerPlugin::DoReadHeaderL"));
       
   139 	// While parsing past header or id3 data, ScanHeaderL will leave with KErrNotReady.
       
   140 	// ScanHeaderL will leave if the util still wants more data for averaging
       
   141 	// by returning KErrCompletion.
       
   142 	// We need to trap so that we can save the config info and then
       
   143 	// do the leave below.
       
   144     TRAPD(err, iAudioUtility->ScanHeaderL(aBuffer));
       
   145 
       
   146     if(err != KErrNotReady)
       
   147 	    {
       
   148 	    iHeaderOffset = iAudioUtility->HeaderOffset();
       
   149 	    iSyncOffset = iAudioUtility->SyncOffset();
       
   150 	    iSampleRate = iAudioUtility->SampleRate();
       
   151 	    iSinkSampleRate = iSampleRate; // Default same as source
       
   152 	//    iBitRate = iAudioUtility->BitRate();
       
   153 	    iChannels = iAudioUtility->Channels();
       
   154 	//    iSinkNumChannels = iChannels; // Default same as source
       
   155 	//    iDuration = iAudioUtility->ScanDuration();
       
   156 	    iDataType = TFourCC(' ','A','M','R');
       
   157 	    iSourceFormat = TUid::Uid(KAdvancedUidFormatAMRRead); // what is this for ???
       
   158 	
       
   159 	    if (!(iChannels == KMonoChannel || iChannels == KStereoChannel))
       
   160 	       {
       
   161 	       User::Leave(KErrNotSupported);
       
   162 	       }
       
   163 		}
       
   164 
       
   165 	User::LeaveIfError(err);
       
   166         	
       
   167 //	iCurrentPosition = iHeaderOffset;
       
   168 //	iReadHeader = EFalse;
       
   169 
       
   170     }
       
   171 
       
   172 CAdvancedAudioDecoder* CAMRAudioPlayControllerPlugin::BuildDecoderL()
       
   173 	{
       
   174 	return iDecoderBuilder->BuildDecoderL(iDecoderType);
       
   175 	}
       
   176 
       
   177 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   178 
       
   179 // Exported proxy for instantiation method resolution
       
   180 // Define the interface UIDs
       
   181 const TImplementationProxy ImplementationTable[] =
       
   182     {
       
   183 	    IMPLEMENTATION_PROXY_ENTRY(KUIDAMRPlayControllerPluginImplementation, CAMRAudioPlayControllerPlugin::NewL)
       
   184     };
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // ImplementationGroupProxy
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(
       
   191     TInt& aTableCount)
       
   192     {
       
   193     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   194     return ImplementationTable;
       
   195     }
       
   196 
       
   197 // End of file