mmfenh/advancedaudiocontroller/audiocontrollerpluginsvariant/DevSoundAudioInput/Src/DevSoundAudioInput.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:  The functions in class implements the behavior that is
       
    15 *                specific to the interface with DevSound.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include 	"DevSoundAudioInput.h"
       
    23 #include 	<mmfpaniccodes.h>
       
    24 #include    "DebugMacros.h"
       
    25 
       
    26 // CONSTANTS
       
    27 const TUint KSampleRate8000Hz 	= 8000;
       
    28 const TUint KSampleRate11025Hz	= 11025;
       
    29 const TUint KSampleRate12000Hz  = 12000;
       
    30 const TUint KSampleRate16000Hz 	= 16000;
       
    31 const TUint KSampleRate22050Hz 	= 22050;
       
    32 const TUint KSampleRate24000Hz  = 24000;
       
    33 const TUint KSampleRate32000Hz 	= 32000;
       
    34 const TUint KSampleRate44100Hz 	= 44100;
       
    35 const TUint KSampleRate48000Hz 	= 48000;
       
    36 const TUint KSampleRate88200Hz 	= 88200;
       
    37 const TUint KSampleRate96000Hz 	= 96000;
       
    38 
       
    39 const TUint KNumChannelsMono 	= 1;
       
    40 const TUint KNumChannelsStereo 	= 2;
       
    41 
       
    42 // ============================ MEMBER FUNCTIONS ===============================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CDevSoundAudioInput::CDevSoundAudioInput
       
    46 // C++ default constructor can NOT contain any code, that
       
    47 // might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CDevSoundAudioInput::CDevSoundAudioInput(CMMFDevSound& aMMFDevSound)
       
    51 	:	iMMFDevSound(aMMFDevSound)
       
    52     {
       
    53 	iAdvancedAudioEncoder = NULL;
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CDevSoundAudioInput::ConstructL
       
    58 // Symbian 2nd phase constructor can leave.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 void CDevSoundAudioInput::ConstructL(
       
    62 	const TMMFPrioritySettings& aPrioritySettings,
       
    63 	MAdvancedAudioInputObserver& aObserver )
       
    64     {
       
    65     DP0(_L("CDevSoundAudioInput::ConstructL"));
       
    66 	iPrioritySettings = aPrioritySettings;
       
    67 	iObserver = &aObserver;
       
    68 
       
    69 	iState = EIdle;
       
    70 	}
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CDevSoundAudioInput::NewL
       
    74 // Two-phased constructor.
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 EXPORT_C CDevSoundAudioInput* CDevSoundAudioInput::NewL(
       
    78     const TMMFPrioritySettings& aPrioritySettings,
       
    79     MAdvancedAudioInputObserver& aObserver,
       
    80     CMMFDevSound& aMMFDevSound )
       
    81     {
       
    82     DP0(_L("CDevSoundAudioInput::NewL"));
       
    83     CDevSoundAudioInput* self = new (ELeave) CDevSoundAudioInput(aMMFDevSound);
       
    84     CleanupStack::PushL(self);
       
    85     self->ConstructL(aPrioritySettings, aObserver);
       
    86     CleanupStack::Pop(self);
       
    87     return self;
       
    88     }
       
    89 
       
    90 // Destructor
       
    91 EXPORT_C CDevSoundAudioInput::~CDevSoundAudioInput()
       
    92     {
       
    93     DP0(_L("CDevSoundAudioInput::~CDevSoundAudioInput"));
       
    94 	iCodecConfigData.Close();
       
    95 	iPendingCodecConfigData.Close();
       
    96 	delete iAdvancedAudioEncoder;
       
    97 
       
    98     iMMFDevSound.Stop();
       
    99     if (iBlockInitialize)
       
   100         {
       
   101         DP0(_L("CDevSoundAudioInput::~CDevSoundAudioInput unblocking initialize"));
       
   102         iBlockInitialize->AsyncStop();
       
   103         }
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CDevSoundAudioInput::PrimeL
       
   108 // Prepare to start recording, building configuration parameters and initializing DevSound.
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 EXPORT_C void CDevSoundAudioInput::PrimeL()
       
   112     {
       
   113     DP0(_L("CDevSoundAudioInput::PrimeL"));
       
   114 
       
   115     iDevSoundInitialized = EFalse; //Reset
       
   116 
       
   117 	if ( !iAdvancedAudioEncoder )
       
   118 		{
       
   119 		// SetEncoder hasn't been called!!!
       
   120 		User::Leave(KErrNotReady);
       
   121 		}
       
   122 
       
   123 	if ( iAdvancedAudioEncoder->IsHwAccelerated() )
       
   124 		{
       
   125 		iMMFDevSound.InitializeL(*this, iSinkFourCC, EMMFStateRecording);
       
   126 		}
       
   127 	else
       
   128 		{
       
   129 		iMMFDevSound.InitializeL(*this, KMMFFourCCCodePCM16, EMMFStateRecording);
       
   130 		}
       
   131 	if (!iDevSoundInitialized)
       
   132 	    {
       
   133 	    iBlockInitialize = new (ELeave) CActiveSchedulerWait();
       
   134 	    DP0(_L("CDevSoundAudioInput::PrimeL() blocking for iMMFDevSound.InitializeL"));
       
   135 	    iBlockInitialize->Start();
       
   136 	    DP0(_L("CDevSoundAudioInput::PrimeL() continuing after iMMFDevSound.InitializeL"));
       
   137 	    delete iBlockInitialize;
       
   138 	    iBlockInitialize = NULL;
       
   139 	    }
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CDevSoundAudioInput::PauseL
       
   144 // Send pause command to DevSound pause and set own state to paused
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 EXPORT_C void CDevSoundAudioInput::PauseL()
       
   148     {
       
   149     DP0(_L("CDevSoundAudioInput::PauseL"));
       
   150 
       
   151     iMMFDevSound.Pause();
       
   152     iState = EPaused;
       
   153     }
       
   154 
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CDevSoundAudioInput::RecordL
       
   158 // Start recording process by configuring the codec and initialize record on DevSound.
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 EXPORT_C void CDevSoundAudioInput::RecordL(
       
   162 	TAny* aBuffer )
       
   163 	{
       
   164 	DP0(_L("CDevSoundAudioInput::RecordL"));
       
   165 
       
   166     //DevSound should be initailized before recording.
       
   167     if(!iDevSoundInitialized)
       
   168     {
       
   169         User::Leave(KErrNotReady);
       
   170     }
       
   171        
       
   172 	// Give the audio encoder a handle to the sink buffers
       
   173 	iAdvancedAudioEncoder->SetSinkBuffers(REINTERPRET_CAST(RPointerArray<CMMFDataBuffer>*, aBuffer));
       
   174 	// Reset the encoder
       
   175 	iAdvancedAudioEncoder->ResetL();
       
   176 	// Configure the audio encoder
       
   177 	iAdvancedAudioEncoder->SetConfigL(iSinkSampleRate, iSinkChannels, iSinkSampleRate,
       
   178 										iSinkChannels, iCodecConfigData);
       
   179 
       
   180 	// Configure DevSound
       
   181 	iMMFDevSound.SetConfigL(iDevSoundConfig);
       
   182 //	iMMFDevSound.SetPrioritySettings(iPrioritySettings);
       
   183 
       
   184     iMMFDevSound.RecordInitL();
       
   185     iState = ERecord;
       
   186 	}
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CDevSoundAudioInput::BuildConfigurationParameters
       
   190 // Build a configuration profile based on DevSound capabilities
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CDevSoundAudioInput::BuildConfigurationParameters()
       
   194 	{
       
   195     DP0(_L("CDevSoundAudioInput::BuildConfigurationParameters"));
       
   196 
       
   197 	// Query DevSound capabilities and Try to use DevSound sample rate and
       
   198 	// mono/stereo capability
       
   199 	TMMFCapabilities devSoundCaps = iMMFDevSound.Capabilities();
       
   200 	// get current config
       
   201 	iDevSoundConfig = iMMFDevSound.Config();
       
   202 
       
   203 	// Default PCM16
       
   204 	iDevSoundConfig.iEncoding = EMMFSoundEncoding16BitPCM;
       
   205 
       
   206 	// 1 = Monophonic and 2 == Stereo
       
   207 	if (((iSinkChannels == 1) && (devSoundCaps.iChannels & EMMFMono)) ||
       
   208 		((iSinkChannels == 2) && (devSoundCaps.iChannels & EMMFStereo)))
       
   209 		iDevSoundConfig.iChannels = iSinkChannels;
       
   210 
       
   211 
       
   212 	// Check for std sample rates.
       
   213 	if ((iSinkSampleRate == 96000) && (devSoundCaps.iRate & EMMFSampleRate96000Hz))
       
   214 		iDevSoundConfig.iRate = EMMFSampleRate96000Hz;
       
   215 	else if ((iSinkSampleRate == 88200) && (devSoundCaps.iRate & EMMFSampleRate88200Hz))
       
   216 		iDevSoundConfig.iRate = EMMFSampleRate88200Hz;
       
   217 	else if ((iSinkSampleRate == 48000) && (devSoundCaps.iRate & EMMFSampleRate48000Hz))
       
   218 		iDevSoundConfig.iRate = EMMFSampleRate48000Hz;
       
   219 	else if ((iSinkSampleRate == 44100) && (devSoundCaps.iRate & EMMFSampleRate44100Hz))
       
   220 		iDevSoundConfig.iRate = EMMFSampleRate44100Hz;
       
   221 	else if ((iSinkSampleRate == 32000) && (devSoundCaps.iRate & EMMFSampleRate32000Hz))
       
   222 		iDevSoundConfig.iRate = EMMFSampleRate32000Hz;
       
   223 	else if ((iSinkSampleRate == 22050) && (devSoundCaps.iRate & EMMFSampleRate22050Hz))
       
   224 		iDevSoundConfig.iRate = EMMFSampleRate22050Hz;
       
   225 	else if ((iSinkSampleRate == 16000) && (devSoundCaps.iRate & EMMFSampleRate16000Hz))
       
   226 		iDevSoundConfig.iRate = EMMFSampleRate16000Hz;
       
   227 	else if ((iSinkSampleRate == 11025) && (devSoundCaps.iRate & EMMFSampleRate11025Hz))
       
   228 		iDevSoundConfig.iRate = EMMFSampleRate11025Hz;
       
   229 	else if ((iSinkSampleRate == 8000) && (devSoundCaps.iRate & EMMFSampleRate8000Hz))
       
   230 		iDevSoundConfig.iRate = EMMFSampleRate8000Hz;
       
   231 	else if ((iSinkSampleRate == 12000) && (devSoundCaps.iRate & EMMFSampleRate12000Hz))
       
   232 		iDevSoundConfig.iRate = EMMFSampleRate12000Hz;
       
   233 	else if ((iSinkSampleRate == 24000) && (devSoundCaps.iRate & EMMFSampleRate24000Hz))
       
   234 		iDevSoundConfig.iRate = EMMFSampleRate24000Hz;
       
   235 	else
       
   236 		{
       
   237 		// pick the maximum sample rate available
       
   238 		if (devSoundCaps.iRate & EMMFSampleRate96000Hz)
       
   239 			iDevSoundConfig.iRate = EMMFSampleRate96000Hz;
       
   240 		else if (devSoundCaps.iRate & EMMFSampleRate88200Hz)
       
   241 			iDevSoundConfig.iRate = EMMFSampleRate88200Hz;
       
   242 		else if (devSoundCaps.iRate & EMMFSampleRate48000Hz)
       
   243 			iDevSoundConfig.iRate = EMMFSampleRate48000Hz;
       
   244 		else if (devSoundCaps.iRate & EMMFSampleRate44100Hz)
       
   245 			iDevSoundConfig.iRate = EMMFSampleRate44100Hz;
       
   246 		else if (devSoundCaps.iRate & EMMFSampleRate32000Hz)
       
   247 			iDevSoundConfig.iRate = EMMFSampleRate32000Hz;
       
   248 		else if (devSoundCaps.iRate & EMMFSampleRate24000Hz)
       
   249 			iDevSoundConfig.iRate = EMMFSampleRate24000Hz;
       
   250 		else if (devSoundCaps.iRate & EMMFSampleRate22050Hz)
       
   251 			iDevSoundConfig.iRate = EMMFSampleRate22050Hz;
       
   252 		else if (devSoundCaps.iRate & EMMFSampleRate16000Hz)
       
   253 			iDevSoundConfig.iRate = EMMFSampleRate16000Hz;
       
   254 		else if (devSoundCaps.iRate & EMMFSampleRate12000Hz)
       
   255 			iDevSoundConfig.iRate = EMMFSampleRate12000Hz;
       
   256 		else if (devSoundCaps.iRate & EMMFSampleRate11025Hz)
       
   257 			iDevSoundConfig.iRate = EMMFSampleRate11025Hz;
       
   258 		else if (devSoundCaps.iRate & EMMFSampleRate8000Hz)
       
   259 			iDevSoundConfig.iRate = EMMFSampleRate8000Hz;
       
   260 		else
       
   261 			ASSERT(EFalse); // if we don't support any sample rates, there is not much we can do
       
   262 		}
       
   263 	}
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CDevSoundAudioInput::StopL
       
   267 // Send stop command to DevSound
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 EXPORT_C void CDevSoundAudioInput::StopL()
       
   271     {
       
   272     DP0(_L("CDevSoundAudioInput::StopL"));
       
   273 	if( iState != EIdle )
       
   274 		{
       
   275 		iState = EIdle;
       
   276 		iAdvancedAudioEncoder->Stop();
       
   277 		iMMFDevSound.Stop();
       
   278 		}
       
   279     }
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // CDevSoundAudioInput::SetPrioritySettings
       
   283 // Send new priority settings to DevSound. Priorities are enumerated to
       
   284 // determine audio recording priority. Higher numbers mean high priority (can
       
   285 // interrupt lower priorities).
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 EXPORT_C void CDevSoundAudioInput::SetPrioritySettingsL(
       
   289 	const TMMFPrioritySettings& aPrioritySettings )
       
   290     {
       
   291     DP0(_L("CDevSoundAudioInput::SetPrioritySettingsL"));
       
   292     iPrioritySettings = aPrioritySettings;
       
   293     iMMFDevSound.SetPrioritySettings(iPrioritySettings);
       
   294     }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CDevSoundAudioInput::CalculateAudioInputPositionL
       
   298 // Gets the current record position in terms of microseconds. This time position
       
   299 // is from the time playback started or resumed and is reset after a stop or
       
   300 // pause.
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 EXPORT_C TInt64 CDevSoundAudioInput::CalculateAudioInputPositionL() const
       
   304     {
       
   305     DP0(_L("CDevSoundAudioInput::CalculateAudioInputPositionL"));
       
   306 	TReal samplesPlayed = iMMFDevSound.SamplesRecorded();
       
   307 	TMMFCapabilities devSoundConfig = iMMFDevSound.Config();
       
   308 	TInt samplingFreq = 0;
       
   309 
       
   310 	switch ( devSoundConfig.iRate )
       
   311 		{
       
   312 		case EMMFSampleRate8000Hz:
       
   313 			samplingFreq = 8000;
       
   314 			break;
       
   315 		case EMMFSampleRate11025Hz:
       
   316 			samplingFreq = 11025;
       
   317 			break;
       
   318 		case EMMFSampleRate16000Hz:
       
   319 			samplingFreq = 16000;
       
   320 			break;
       
   321 		case EMMFSampleRate22050Hz:
       
   322 			samplingFreq = 22050;
       
   323 			break;
       
   324 		case EMMFSampleRate32000Hz:
       
   325 			samplingFreq = 32000;
       
   326 			break;
       
   327 		case EMMFSampleRate44100Hz:
       
   328 			samplingFreq = 44100;
       
   329 			break;
       
   330 		case EMMFSampleRate48000Hz:
       
   331 			samplingFreq = 48000;
       
   332 			break;
       
   333 		case EMMFSampleRate88200Hz:
       
   334 			samplingFreq = 88200;
       
   335 			break;
       
   336 		case EMMFSampleRate96000Hz:
       
   337 			samplingFreq = 96000;
       
   338 			break;
       
   339 		case EMMFSampleRate12000Hz:
       
   340             samplingFreq = 12000;
       
   341 		   break;
       
   342 		case EMMFSampleRate24000Hz:
       
   343            samplingFreq = 24000;
       
   344 		   break;
       
   345 		default:
       
   346             User::Leave(KErrCorrupt);
       
   347 		}
       
   348 
       
   349 	TReal timePlayedSeconds = 0;
       
   350 	if(samplesPlayed)
       
   351         timePlayedSeconds = samplesPlayed/samplingFreq;
       
   352 
       
   353 	TInt64 timePlayed(timePlayedSeconds*1000000);
       
   354 	return timePlayed;
       
   355     }
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // CDevSoundAudioInput::MaxGain
       
   359 // Get maximum gain value from DevSound
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 EXPORT_C TInt CDevSoundAudioInput::MaxGainL()
       
   363     {
       
   364     DP0(_L("CDevSoundAudioInput::MaxGainL"));
       
   365     return iMMFDevSound.MaxGain();
       
   366     }
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 // CDevSoundAudioInput::SetGain
       
   370 // Sends given new gain value to DevSound
       
   371 // -----------------------------------------------------------------------------
       
   372 //
       
   373 EXPORT_C void CDevSoundAudioInput::SetGainL(
       
   374 	TInt aGain )
       
   375     {
       
   376     DP0(_L("CDevSoundAudioInput::SetGainL"));
       
   377     iMMFDevSound.SetGain(aGain);
       
   378     }
       
   379 
       
   380 // -----------------------------------------------------------------------------
       
   381 // CDevSoundAudioInput::Gain
       
   382 // Get current gain value from DevSound
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 EXPORT_C TInt CDevSoundAudioInput::GainL()
       
   386     {
       
   387     DP0(_L("CDevSoundAudioInput::GainL"));
       
   388     return iMMFDevSound.Gain();
       
   389     }
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // CDevSoundAudioInput::ConfigRatesL
       
   393 // Get configured sampling rates from DevSound
       
   394 // -----------------------------------------------------------------------------
       
   395 //
       
   396 EXPORT_C void CDevSoundAudioInput::ConfigRatesL(
       
   397 	RArray<TUint>& aRates )
       
   398     {
       
   399     DP0(_L("CDevSoundAudioInput::ConfigRatesL"));
       
   400     ConvertFromDevSoundCapsToSampleRatesL(iMMFDevSound.Config(), aRates);
       
   401     }
       
   402 
       
   403 // -----------------------------------------------------------------------------
       
   404 // CDevSoundAudioInput::ConfigChannelsL
       
   405 // Get configured sampling rates from DevSound
       
   406 // -----------------------------------------------------------------------------
       
   407 //
       
   408 EXPORT_C void CDevSoundAudioInput::ConfigChannelsL(
       
   409 	RArray<TUint>& aChannels )
       
   410     {
       
   411     DP0(_L("CDevSoundAudioInput::ConfigChannelsL"));
       
   412     ConvertFromDevSoundCapsToNumChannelsL(iMMFDevSound.Config(), aChannels);
       
   413     }
       
   414 
       
   415 // -----------------------------------------------------------------------------
       
   416 // CDevSoundAudioInput::ConfigDataTypesL
       
   417 // Get configured data types (FourCC) from DevSound
       
   418 // -----------------------------------------------------------------------------
       
   419 //
       
   420 EXPORT_C void CDevSoundAudioInput::ConfigDataTypesL(
       
   421 	RArray<TFourCC>& aDataTypes )
       
   422     {
       
   423     DP0(_L("CDevSoundAudioInput::ConfigDataTypesL"));
       
   424     ConvertFromDevSoundCapsToDataTypesL(iMMFDevSound.Config(), aDataTypes);
       
   425     }
       
   426 
       
   427 // -----------------------------------------------------------------------------
       
   428 // CDevSoundAudioInput::CapabilitiesRatesL
       
   429 // CDevSoundAudioInput::CapabilitiesRatesL
       
   430 // -----------------------------------------------------------------------------
       
   431 //
       
   432 EXPORT_C void CDevSoundAudioInput::CapabilitiesRatesL(
       
   433 	RArray<TUint>& aRates )
       
   434     {
       
   435     DP0(_L("CDevSoundAudioInput::CapabilitiesRatesL"));
       
   436     ConvertFromDevSoundCapsToSampleRatesL(iMMFDevSound.Capabilities(), aRates);
       
   437     }
       
   438 
       
   439 // -----------------------------------------------------------------------------
       
   440 // CDevSoundAudioInput::CapabilitiesChannelsL
       
   441 // Get DevSound capabilities for channels
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 EXPORT_C void CDevSoundAudioInput::CapabilitiesChannelsL(
       
   445 	RArray<TUint>& aChannels )
       
   446     {
       
   447     DP0(_L("CDevSoundAudioInput::CapabilitiesChannelsL"));
       
   448     ConvertFromDevSoundCapsToNumChannelsL(iMMFDevSound.Capabilities(), aChannels);
       
   449     }
       
   450 
       
   451 // -----------------------------------------------------------------------------
       
   452 // CDevSoundAudioInput::CapabilitiesDataTypesL
       
   453 // Get DevSound capabilities for data types (FourCC)
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 EXPORT_C void CDevSoundAudioInput::CapabilitiesDataTypesL(
       
   457 	RArray<TFourCC>& aDataTypes )
       
   458     {
       
   459     DP0(_L("CDevSoundAudioInput::CapabilitiesDataTypesL"));
       
   460     ConvertFromDevSoundCapsToDataTypesL(iMMFDevSound.Capabilities(), aDataTypes);
       
   461     }
       
   462 
       
   463 
       
   464 
       
   465 // -----------------------------------------------------------------------------
       
   466 // CDevSoundAudioInput::ConfigureL
       
   467 // Save configuration information and initializes DevSound and codec.
       
   468 // -----------------------------------------------------------------------------
       
   469 //
       
   470 EXPORT_C void CDevSoundAudioInput::ConfigureL(
       
   471 	TUint aSampleRate,
       
   472 	TUint aNumChannel,
       
   473 	TFourCC aFourCC,
       
   474 	const RArray<TInt>& aCodecConfigData )
       
   475     {
       
   476     DP0(_L("CDevSoundAudioInput::ConfigureL"));
       
   477     iSinkSampleRate = aSampleRate;
       
   478     iSinkChannels = aNumChannel;
       
   479     iSinkFourCC = aFourCC;
       
   480 
       
   481 	iCodecConfigData.Reset();
       
   482     for ( TInt i = 0; i < aCodecConfigData.Count(); i++ )
       
   483     	{
       
   484     	//RDebug::Print(_L("Index %d [%d]"), i, aCodecConfigData[i]);
       
   485     	User::LeaveIfError(iCodecConfigData.Append(aCodecConfigData[i]));
       
   486     	}
       
   487     }
       
   488 
       
   489 // -----------------------------------------------------------------------------
       
   490 // CDevSoundAudioInput::SetEncoder
       
   491 // Sets the Encoder instance to be used by the audio input.
       
   492 // -----------------------------------------------------------------------------
       
   493 //
       
   494 EXPORT_C void CDevSoundAudioInput::SetEncoder(
       
   495 	CAdvancedAudioEncoder* aEncoder )
       
   496 	{
       
   497     DP0(_L("CDevSoundAudioInput::SetEncoder"));
       
   498 	iAdvancedAudioEncoder = aEncoder;
       
   499 
       
   500 	iAdvancedAudioEncoder->SetDevSound(iMMFDevSound);
       
   501 	iAdvancedAudioEncoder->SetObserver(*this);
       
   502 	}
       
   503 
       
   504 // -----------------------------------------------------------------------------
       
   505 // CDevSoundAudioInput::SetBitRateL
       
   506 // Sets the the bitrate to be used by the devsound.
       
   507 // -----------------------------------------------------------------------------
       
   508 //
       
   509 EXPORT_C void CDevSoundAudioInput::SetBitRateL(
       
   510 	TUint aBitRate,
       
   511 	const RArray<TInt>& aCodecConfigData )
       
   512 	{
       
   513     DP2(_L("CDevSoundAudioInput::SetBitRateL iDevSoundInitialized = %D, iEncoderConfigPending = %D"),iDevSoundInitialized,iEncoderConfigPending);
       
   514     iBitRate = aBitRate; //Save the bitrate
       
   515     // Only SetBitrate on DevSound after its been Initialized
       
   516     if(	iDevSoundInitialized)
       
   517         {
       
   518         iEncoderConfigPending = EFalse;
       
   519 	    iAdvancedAudioEncoder->SetBitRateL(aBitRate, aCodecConfigData);
       
   520 	    }
       
   521 	else // We hot initialised devsound, so we will hold on to any Codec Specific Setting.
       
   522 	    {
       
   523 	    iEncoderConfigPending = ETrue;
       
   524 	    // Save Confing Data, to be passed once initcomplete
       
   525 	    for ( TInt i = 0; i < aCodecConfigData.Count(); i++ )
       
   526     		{
       
   527     		//RDebug::Print(_L("Index %d [%d]"), i, aCodecConfigData[i]);
       
   528     		User::LeaveIfError(iPendingCodecConfigData.Append(aCodecConfigData[i]));
       
   529     		} 
       
   530 	    }
       
   531 	    
       
   532     iCodecConfigData.Reset();
       
   533     for ( TInt i = 0; i < aCodecConfigData.Count(); i++ )
       
   534     	{
       
   535     	//RDebug::Print(_L("Index %d [%d]"), i, aCodecConfigData[i]);
       
   536     	User::LeaveIfError(iCodecConfigData.Append(aCodecConfigData[i]));
       
   537     	}
       
   538     }
       
   539 
       
   540 // -----------------------------------------------------------------------------
       
   541 // CDevSoundAudioInput::InitializeComplete
       
   542 // Callback from DevSound to notify initialization has completed
       
   543 // -----------------------------------------------------------------------------
       
   544 //
       
   545 void CDevSoundAudioInput::InitializeComplete(TInt aError)
       
   546     {
       
   547     DP2(_L("CDevSoundAudioInput::InitializeComplete aError = %D, iEncoderConfigPending = %D"),aError,iEncoderConfigPending);
       
   548     if (iBlockInitialize)
       
   549         {
       
   550         DP0(_L("CDevSoundAudioInput::InitializeComplete unblocking initialize"));
       
   551         iBlockInitialize->AsyncStop();
       
   552         }
       
   553 
       
   554     if ( aError == KErrNone )
       
   555 	 	{
       
   556      	iState = EDevSoundReady;
       
   557      	iDevSoundInitialized = ETrue;
       
   558 	 	BuildConfigurationParameters();
       
   559 	 	//Set Pending Codec Config info
       
   560     	if(iEncoderConfigPending)
       
   561     	 	{
       
   562     	    TRAP_IGNORE(SetBitRateL(iBitRate, iPendingCodecConfigData));
       
   563     	 	}
       
   564 		}
       
   565 	else
       
   566 		{
       
   567     	iState = EIdle;
       
   568     	iObserver->SendEvent(TMMFEvent(KMMFEventCategoryPlaybackComplete, aError));
       
   569 		}
       
   570     DP0(_L("CDevSoundAudioInput::InitializeComplete end"));
       
   571     }
       
   572 
       
   573 // -----------------------------------------------------------------------------
       
   574 // CDevSoundAudioInput::ToneFinished
       
   575 // ToneFinished called when a tone has finished or interrupted
       
   576 // aError == KErrNone means success
       
   577 // -----------------------------------------------------------------------------
       
   578 //
       
   579 void CDevSoundAudioInput::ToneFinished(
       
   580 	TInt /*aError*/ )
       
   581      {
       
   582      //we should never get a tone error in MMFAudioOutput!
       
   583      __ASSERT_DEBUG(EFalse, Panic(EMMFAudioOutputPanicToneFinishedNotSupported));
       
   584      }
       
   585 
       
   586 
       
   587 // -----------------------------------------------------------------------------
       
   588 // CDevSoundAudioInput::PlayError
       
   589 // Callback error to indicate has error occurred during playback
       
   590 // Should not be called on DevSound Audio Input
       
   591 // -----------------------------------------------------------------------------
       
   592 //
       
   593 void CDevSoundAudioInput::PlayError(
       
   594 	TInt /*aError*/ )
       
   595 	{
       
   596 	//we should never get here during a record session!
       
   597 	__ASSERT_DEBUG(EFalse, Panic(EMMFAudioInputPanicPlayErrorNotSupported));
       
   598     }
       
   599 
       
   600 
       
   601 // -----------------------------------------------------------------------------
       
   602 // CDevSoundAudioOutput::BufferToBeFilled
       
   603 // Called when buffer has been used up by DevSound
       
   604 // -----------------------------------------------------------------------------
       
   605 //
       
   606 void CDevSoundAudioInput::BufferToBeFilled(
       
   607 	CMMFBuffer* /*aBuffer*/ )
       
   608 	{
       
   609 	//we should never get a BufferToBeFilled in Audio Input!
       
   610     }
       
   611 
       
   612 // -----------------------------------------------------------------------------
       
   613 // CDevSoundAudioInput::BufferToBeEmptied
       
   614 // Callback from MDevSoundObserver
       
   615 // -----------------------------------------------------------------------------
       
   616 //
       
   617 void CDevSoundAudioInput::BufferToBeEmptied(
       
   618 	CMMFBuffer* aBuffer )
       
   619 	{
       
   620 //    DP0 (_L ("CDevSoundAudioInput::BufferToBeEmptied"));
       
   621 	if ( iState != EIdle )
       
   622 		{
       
   623 		iAdvancedAudioEncoder->EmptyBuffer(aBuffer);
       
   624 		}
       
   625 	}
       
   626 
       
   627 // -----------------------------------------------------------------------------
       
   628 // CDevSoundAudioInput::RecordError
       
   629 // Callback from DevSound to indicate error occurred during a recording
       
   630 // -----------------------------------------------------------------------------
       
   631 //
       
   632 void CDevSoundAudioInput::RecordError(
       
   633 	TInt aError )
       
   634 	{
       
   635     DP2(_L("CDevSoundAudioInput::RecordError(%d) iState[%d]"), aError, iState);
       
   636     iMMFDevSound.Stop(); // might not need to do this. test
       
   637     iState = EIdle;
       
   638     iObserver->SendEvent(TMMFEvent(KMMFEventCategoryPlaybackComplete, aError));
       
   639 	}
       
   640 
       
   641 // -----------------------------------------------------------------------------
       
   642 // CDevSoundAudioInput::ConvertError
       
   643 // Called from DevSound when stopped due to error while coverting
       
   644 // -----------------------------------------------------------------------------
       
   645 //
       
   646 void CDevSoundAudioInput::ConvertError(
       
   647 	TInt /*aError*/ )
       
   648      {
       
   649      }
       
   650 
       
   651 // -----------------------------------------------------------------------------
       
   652 // CDevSoundAudioInput::DeviceMessage
       
   653 // Callback from DevSound for message from hardware device (no messages in
       
   654 // current implementation of DevSound)
       
   655 // -----------------------------------------------------------------------------
       
   656 //
       
   657 void CDevSoundAudioInput::DeviceMessage(
       
   658 	TUid /*aMessageType*/,
       
   659 	const TDesC8& /*aMsg*/ )
       
   660      {
       
   661      }
       
   662 
       
   663 // -----------------------------------------------------------------------------
       
   664 // CDevSoundAudioInput::SendEventToClient
       
   665 // Send given event to client
       
   666 // -----------------------------------------------------------------------------
       
   667 //
       
   668 void CDevSoundAudioInput::SendEventToClient(
       
   669 	const TMMFEvent& aEvent )
       
   670      {
       
   671      DP0(_L("CDevSoundAudioInput::SendEventToClient"));
       
   672      iObserver->SendEvent(aEvent);
       
   673      }
       
   674 
       
   675 // -----------------------------------------------------------------------------
       
   676 // CDevSoundAudioInput::BufferEmptied
       
   677 // Notification from Audio Converter that the specified buffer has been filled.
       
   678 // -----------------------------------------------------------------------------
       
   679 //
       
   680 void CDevSoundAudioInput::BufferEmptied()
       
   681     {
       
   682     DP0(_L("CDevSoundAudioInput::BufferEmptied"));
       
   683 	if ( iState != EIdle )
       
   684 		{
       
   685     	iMMFDevSound.RecordData();
       
   686 		}
       
   687 	}
       
   688 
       
   689 // -----------------------------------------------------------------------------
       
   690 // CDevSoundAudioInput::EmptyBuffer
       
   691 // Notification from Audio Converter that the specified buffer needs to be
       
   692 // emptied.
       
   693 // -----------------------------------------------------------------------------
       
   694 //
       
   695 void CDevSoundAudioInput::EmptyBuffer(
       
   696 	CMMFBuffer* aBuffer )
       
   697 	{
       
   698     DP0(_L("CDevSoundAudioInput::EmptyBuffer"));
       
   699 	// forward the request to the controller
       
   700     TRAPD(err,iObserver->EmptyBufferL(aBuffer));
       
   701 	if(err != KErrNone)
       
   702 	    {
       
   703 	    DP1(_L("CDevSoundAudioInput::EmptyBuffer err[%d]"),err);
       
   704 		RecordError(err);
       
   705 	    }
       
   706 	}
       
   707 
       
   708 // -----------------------------------------------------------------------------
       
   709 // CDevSoundAudioInput::SendEvent
       
   710 // Send given event to client
       
   711 // -----------------------------------------------------------------------------
       
   712 //
       
   713 void CDevSoundAudioInput::SendEvent(
       
   714 	const TMMFEvent& aEvent )
       
   715      {
       
   716      DP0(_L("CDevSoundAudioInput::SendEvent"));
       
   717      iObserver->SendEvent(aEvent);
       
   718      }
       
   719 
       
   720 // -----------------------------------------------------------------------------
       
   721 // CDevSoundAudioInput::ConvertFromDevSoundCapsToSampleRatesL
       
   722 // Internal function to convert sampling rate from DevSound representation to
       
   723 // integer value
       
   724 // -----------------------------------------------------------------------------
       
   725 //
       
   726 void CDevSoundAudioInput::ConvertFromDevSoundCapsToSampleRatesL(
       
   727 	const TMMFCapabilities& aDevSoundCaps,
       
   728 	RArray<TUint>& aSampleRates )
       
   729     {
       
   730     DP0(_L("CDevSoundAudioInput::ConvertFromDevSoundCapsToSampleRatesL"));
       
   731     if ( aDevSoundCaps.iRate & EMMFSampleRate8000Hz )
       
   732     	{
       
   733         User::LeaveIfError(aSampleRates.Append(KSampleRate8000Hz));
       
   734 		}
       
   735     if ( aDevSoundCaps.iRate & EMMFSampleRate11025Hz )
       
   736     	{
       
   737         User::LeaveIfError(aSampleRates.Append(KSampleRate11025Hz));
       
   738 		}
       
   739 	if ( aDevSoundCaps.iRate & EMMFSampleRate12000Hz )
       
   740     	{
       
   741         User::LeaveIfError(aSampleRates.Append(KSampleRate12000Hz));
       
   742 		}
       
   743     if ( aDevSoundCaps.iRate & EMMFSampleRate16000Hz )
       
   744     	{
       
   745         User::LeaveIfError(aSampleRates.Append(KSampleRate16000Hz));
       
   746 		}
       
   747     if ( aDevSoundCaps.iRate & EMMFSampleRate22050Hz )
       
   748     	{
       
   749         User::LeaveIfError(aSampleRates.Append(KSampleRate22050Hz));
       
   750 		}
       
   751 	if ( aDevSoundCaps.iRate & EMMFSampleRate24000Hz )
       
   752     	{
       
   753         User::LeaveIfError(aSampleRates.Append(KSampleRate24000Hz));
       
   754 		}
       
   755     if ( aDevSoundCaps.iRate & EMMFSampleRate32000Hz )
       
   756     	{
       
   757         User::LeaveIfError(aSampleRates.Append(KSampleRate32000Hz));
       
   758 		}
       
   759     if ( aDevSoundCaps.iRate & EMMFSampleRate44100Hz )
       
   760     	{
       
   761         User::LeaveIfError(aSampleRates.Append(KSampleRate44100Hz));
       
   762 		}
       
   763     if ( aDevSoundCaps.iRate & EMMFSampleRate48000Hz )
       
   764     	{
       
   765         User::LeaveIfError(aSampleRates.Append(KSampleRate48000Hz));
       
   766 		}
       
   767     if ( aDevSoundCaps.iRate & EMMFSampleRate88200Hz )
       
   768     	{
       
   769         User::LeaveIfError(aSampleRates.Append(KSampleRate88200Hz));
       
   770 		}
       
   771     if ( aDevSoundCaps.iRate & EMMFSampleRate96000Hz )
       
   772     	{
       
   773         User::LeaveIfError(aSampleRates.Append(KSampleRate96000Hz));
       
   774 		}
       
   775     }
       
   776 
       
   777 // -----------------------------------------------------------------------------
       
   778 // CDevSoundAudioInput::ConvertFromDevSoundCapsToDataTypesL
       
   779 // Internal function to convert data types from DevSound representation to
       
   780 // FourCC
       
   781 // -----------------------------------------------------------------------------
       
   782 //
       
   783 void CDevSoundAudioInput::ConvertFromDevSoundCapsToDataTypesL(
       
   784 	const TMMFCapabilities& aDevSoundCaps,
       
   785 	RArray<TFourCC>& aDataTypes )
       
   786     {
       
   787     DP0(_L("CDevSoundAudioInput::ConvertFromDevSoundCapsToDataTypesL"));
       
   788     if ( aDevSoundCaps.iEncoding & EMMFSoundEncoding8BitPCM )
       
   789     	{
       
   790         User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodePCM8));
       
   791 		}
       
   792     if ( aDevSoundCaps.iEncoding & EMMFSoundEncoding16BitPCM )
       
   793     	{
       
   794         User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodePCM16));
       
   795 		}
       
   796     if ( aDevSoundCaps.iEncoding & EMMFSoundEncoding8BitALaw )
       
   797     	{
       
   798         User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodeALAW));
       
   799 		}
       
   800     if ( aDevSoundCaps.iEncoding & EMMFSoundEncoding8BitMuLaw )
       
   801     	{
       
   802         User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodeMuLAW));
       
   803 		}
       
   804     }
       
   805 
       
   806 // -----------------------------------------------------------------------------
       
   807 // CDevSoundAudioInput::ConvertFromDevSoundCapsToNumChannelsL
       
   808 // Internal function to convert number of channels from DevSound representation to
       
   809 // integer value
       
   810 // -----------------------------------------------------------------------------
       
   811 //
       
   812 void CDevSoundAudioInput::ConvertFromDevSoundCapsToNumChannelsL(
       
   813 	const TMMFCapabilities& aDevSoundCaps,
       
   814 	RArray<TUint>& aNumChannels )
       
   815     {
       
   816     DP0(_L("CDevSoundAudioInput::ConvertFromDevSoundCapsToNumChannelsL"));
       
   817     if ( aDevSoundCaps.iChannels & EMMFMono )
       
   818     	{
       
   819         User::LeaveIfError(aNumChannels.Append(KNumChannelsMono));
       
   820 		}
       
   821     if ( aDevSoundCaps.iChannels & EMMFStereo )
       
   822     	{
       
   823         User::LeaveIfError(aNumChannels.Append(KNumChannelsStereo));
       
   824 		}
       
   825     }
       
   826 
       
   827 // -----------------------------------------------------------------------------
       
   828 // CDevSoundAudioInput::Panic
       
   829 // Raise user panic with appropriate panic code
       
   830 // -----------------------------------------------------------------------------
       
   831 //
       
   832 void CDevSoundAudioInput::Panic(
       
   833 	TInt aPanicCode ) const
       
   834     {
       
   835     _LIT(KDevSoundAudioInputPanicCategory, "DevSoundAudioInput");
       
   836     User::Panic(KDevSoundAudioInputPanicCategory, aPanicCode);
       
   837     }
       
   838 
       
   839 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   840 
       
   841 // End of file