audiostubs/devsoundextensions_stubs/mmfdevsoundadaptation_stub/src/MmfDevSoundAdaptationBody.cpp
changeset 43 e71858845f73
parent 40 b7e5ed8c1342
child 46 e1758cbb96ac
equal deleted inserted replaced
40:b7e5ed8c1342 43:e71858845f73
     1 /*
       
     2 * Copyright (c) 2006-2008 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: Audio Stubs -  DevSound adaptation stub body implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <mdaaudiotoneplayer.h>
       
    22 
       
    23 #include "G711DecoderIntfc.h"
       
    24 #include "G729DecoderIntfc.h"
       
    25 #include "IlbcDecoderIntfc.h"
       
    26 #include "G711EncoderIntfc.h"
       
    27 #include "G729EncoderIntfc.h"
       
    28 #include "IlbcEncoderIntfc.h"
       
    29 #include "ErrorConcealmentIntfc.h"
       
    30 #include "SpeechEncoderConfig.h"
       
    31 
       
    32 #include "AudioInputMessageTypes.h"
       
    33 #include "AudioOutputMessageTypes.h"
       
    34 //#include "AudioResourceMessageTypes.h"
       
    35 
       
    36 #include "AudioInputCI.h"
       
    37 #include "AudioOutputCI.h"
       
    38 #include "G711DecoderIntfcCI.h"
       
    39 #include "G729DecoderIntfcCI.h"
       
    40 #include "IlbcDecoderIntfcCI.h"
       
    41 #include "G711EncoderIntfcCI.h"
       
    42 #include "G729EncoderIntfcCI.h"
       
    43 #include "IlbcEncoderIntfcCI.h"
       
    44 #include "ErrorConcealmentIntfcCI.h"
       
    45 #include "SpeechEncoderConfigCI.h"
       
    46 
       
    47 //#include <AudioResourceCIStub.h>
       
    48 //#include <AudioEqualizerCI.h>
       
    49 //#include <EnvironmentalReverbCI.h>
       
    50 //#include <StereoWideningCI.h>
       
    51 //#include <BassBoostCI.h>
       
    52 //#include <SourceDopplerBase.h>
       
    53 //#include <ListenerDopplerBase.h>
       
    54 //#include <SourceDopplerCI.h>
       
    55 //#include <ListenerDopplerCI.h>
       
    56 //#include <ListenerLocationCI.h>
       
    57 //#include <SourceLocationCI.h>
       
    58 //#include <ListenerOrientationCI.h>
       
    59 //#include <SourceOrientationCI.h>
       
    60 //#include <DistanceAttenuationCI.h>
       
    61 //#include <LoudnessCI.h>
       
    62 
       
    63 //#include <AddedDevSoundControlCI.h>
       
    64 //#include <AddedDevSoundControlCIStub.h>
       
    65 //#include <RestrictedAudioOutputCI.h>
       
    66 
       
    67 #include "MmfDevSoundAdaptationBody.h"
       
    68 #include "MmfHwDeviceStub.h"
       
    69 #include "TonePlayCompleteTimer.h"
       
    70 
       
    71 
       
    72 // CONSTANTS
       
    73 #ifdef _DEBUG
       
    74 #include "e32debug.h"
       
    75 
       
    76 #define DEBPRN0(str)                RDebug::Print(str, this)
       
    77 #define DEBPRN1(str, val1)          RDebug::Print(str, this, val1)
       
    78 #define DEBPRN2(str, val1, val2)    RDebug::Print(str, this, val1, val2)
       
    79 #else
       
    80 #define DEBPRN0(str)
       
    81 #define DEBPRN1(str, val1)
       
    82 #define DEBPRN2(str, val1, val2)
       
    83 #endif //_DEBUG
       
    84 
       
    85 
       
    86 const TUint KMaxVolume = 10;
       
    87 const TUint KToneSamplingRate = 8000;
       
    88 const TUint KToneChannels = 2;
       
    89 // Time to play one note 1/10th of 1/2 a second
       
    90 const TUint KToneNotePlayTime = 50000;
       
    91 
       
    92 // ============================ MEMBER FUNCTIONS ===============================
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CMMFDevSoundAdaptation::CBody::CBody
       
    96 // C++ default constructor can NOT contain any code, that
       
    97 // might leave.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 CMMFDevSoundAdaptation::CBody::CBody()
       
   101     {
       
   102     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CBody"));
       
   103     iMode= EMMFStateIdle;
       
   104     //Set reasonable default values for DTMF
       
   105     iDTMFGen.SetToneDurations(250000,50000,250000);
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CMMFDevSoundAdaptation::CBody::ConstructL
       
   110 // Symbian 2nd phase constructor can leave.
       
   111 // assumes that iParent has already been set up properly
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CMMFDevSoundAdaptation::CBody::ConstructL(
       
   115     RServer2& /*aPolicyServerHandle*/)
       
   116     {
       
   117     // Default
       
   118     // set the default capability
       
   119     iDeviceCapabilities.iRate = EMMFSampleRate8000Hz;
       
   120     iDeviceCapabilities.iEncoding = EMMFSoundEncoding16BitPCM;
       
   121     iDeviceCapabilities.iChannels = EMMFMono;
       
   122     iDeviceCapabilities.iBufferSize = KBufferLength;
       
   123 
       
   124     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::ConstructL:EXIT"));
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CMMFDevSoundAdaptation::CBody::NewL
       
   129 // Two-phased constructor.
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 CMMFDevSoundAdaptation::CBody* CMMFDevSoundAdaptation::CBody::NewL()
       
   133     {
       
   134     CMMFDevSoundAdaptation::CBody* self = new (ELeave) CBody;
       
   135     return self;
       
   136     }
       
   137 
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CMMFDevSoundAdaptation::CBodye::~CBody
       
   141 // Destructor
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 CMMFDevSoundAdaptation::CBody::~CBody()
       
   145     {
       
   146     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::~CBody:ENTER"));
       
   147     delete iToneBuffer1;
       
   148     delete iToneBuffer2;
       
   149     delete iDevSoundUtil;
       
   150     delete iFixedSequences;
       
   151     delete iCMMFHwDevice;
       
   152     delete iTonePlayCompleteTimer;
       
   153     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::~CBody:EXIT"));
       
   154     }
       
   155 
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CMMFDevSoundAdaptation::CBody::InitializeL
       
   159 // Initializes CMMFDevSoundProxy object to play and record PCM16 raw audio data
       
   160 // with sampling rate of 8 KHz.
       
   161 //
       
   162 // On completion of Initialization, calls InitializeComplete() on
       
   163 // aDevSoundObserver.
       
   164 // (other items were commented in a header).
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void CMMFDevSoundAdaptation::CBody::InitializeL(
       
   168     MDevSoundAdaptationObserver& aDevSoundObserver,
       
   169     TMMFState aMode)
       
   170     {
       
   171     // if no HwDevice id specified, load default null implementation
       
   172     TUid rawUid = {0};
       
   173     InitializeL(aDevSoundObserver, rawUid, aMode);
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CMMFDevSoundAdaptation::CBody::InitializeL
       
   178 // Initializes DevSound object for the mode aMode for processing audio data
       
   179 // with hardware device aHWDev.
       
   180 //
       
   181 // On completion of Initialization, the observer will be notified via call back
       
   182 // InitializeComplete().
       
   183 //
       
   184 // Leaves on failure.
       
   185 // (other items were commented in a header).
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 void CMMFDevSoundAdaptation::CBody::InitializeL(
       
   189     MDevSoundAdaptationObserver& aDevSoundObserver,
       
   190     TUid aHWDev,
       
   191     TMMFState aMode)
       
   192     {
       
   193     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::InitializeL:ENTER"));
       
   194     TInt initError = KErrNone;
       
   195     iDevSoundObserver = &aDevSoundObserver;
       
   196 
       
   197     if (aMode == EMMFStateIdle)
       
   198         {
       
   199         User::Leave(KErrNotSupported);
       
   200         }
       
   201     iMode= aMode;
       
   202 
       
   203 
       
   204     iDevSoundObserver = &aDevSoundObserver;
       
   205     iHwDeviceID.iUid = aHWDev.iUid;
       
   206     if(iCMMFHwDevice)
       
   207         {
       
   208         delete iCMMFHwDevice;
       
   209         iHwDeviceBuffer = NULL; // buffer is deleted by HwDevice delete
       
   210         }
       
   211 
       
   212     iCMMFHwDevice = NULL;
       
   213     iCMMFHwDevice = CMMFHwDeviceStub::NewL();
       
   214 
       
   215     iDevInfo.iHwDeviceObserver = this;
       
   216     initError = iCMMFHwDevice->Init(iDevInfo);
       
   217 
       
   218     iDevSoundObserver->InitializeComplete(initError);
       
   219 
       
   220     if (initError)
       
   221         {
       
   222         User::Leave(initError);
       
   223         }
       
   224     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::InitializeL:EXIT"));
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CMMFDevSoundAdaptation::CBody::InitializeL
       
   229 // Initializes DevSound object for the mode aMode for processing audio data
       
   230 // with hardware device supporting FourCC aDesiredFourCC.
       
   231 //
       
   232 // On completion of Initialization, the observer will be notified via call back
       
   233 // InitializeComplete().
       
   234 //
       
   235 // Leaves on failure.
       
   236 // (other items were commented in a header).
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 void CMMFDevSoundAdaptation::CBody::InitializeL(
       
   240     MDevSoundAdaptationObserver& aDevSoundObserver,
       
   241     TFourCC /*aDesiredFourCC*/,
       
   242     TMMFState aMode)
       
   243     {
       
   244     TUid implUid = {0};
       
   245     InitializeL(aDevSoundObserver, implUid, aMode);
       
   246     }
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CMMFDevSoundAdaptation::CBody::Capabilities
       
   250 // Returns the supported Audio settings.
       
   251 // (other items were commented in a header).
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 TMMFCapabilities CMMFDevSoundAdaptation::CBody::Capabilities()
       
   255     {
       
   256     return iDeviceCapabilities;
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CMMFDevSoundAdaptation::CBody::Config
       
   261 // Returns the current audio settings.
       
   262 // (other items were commented in a header).
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 TMMFCapabilities CMMFDevSoundAdaptation::CBody::Config() const
       
   266     {
       
   267     return iDeviceConfig;
       
   268     }
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // CMMFDevSoundAdaptation::CBody::SetConfigL
       
   272 // Configure CMMFDevSoundProxy object for the settings in aConfig.
       
   273 // Use this to set sampling rate, Encoding and Mono/Stereo.
       
   274 // As part of defect 20796, the iRecordFormat has been set under the iPlayFormat,
       
   275 //  before it was not set at all.
       
   276 // (other items were commented in a header).
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 void CMMFDevSoundAdaptation::CBody::SetConfigL(
       
   280     const TMMFCapabilities& aConfig)
       
   281     {
       
   282     iDeviceConfig = aConfig;
       
   283 
       
   284     // Fix to WAV recording problem.
       
   285     // A kludge to init channel number to 'something' in case the device returns 0.
       
   286     if (!iDeviceConfig.iChannels)
       
   287         {
       
   288         iDeviceConfig.iChannels = EMMFMono;
       
   289         }
       
   290     }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // CMMFDevSoundAdaptation::CBody::MaxVolume
       
   294 // Returns an integer representing the maximum volume.
       
   295 // This is the maximum value which can be passed to CMMFDevSoundProxy::SetVolume.
       
   296 // (other items were commented in a header).
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 TInt CMMFDevSoundAdaptation::CBody::MaxVolume()
       
   300     {
       
   301     return KMaxVolume;
       
   302     }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CMMFDevSoundAdaptation::CBody::Volume
       
   306 // Returns an integer representing the current volume.
       
   307 // (other items were commented in a header).
       
   308 // -----------------------------------------------------------------------------
       
   309 //
       
   310 TInt CMMFDevSoundAdaptation::CBody::Volume()
       
   311     {
       
   312     return iVolume;
       
   313     }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // CMMFDevSoundAdaptation::CBody::SetVolume
       
   317 // Changes the current playback volume to a specified value.
       
   318 // The volume can be changed before or during playback and is effective
       
   319 // immediately.
       
   320 // (other items were commented in a header).
       
   321 // -----------------------------------------------------------------------------
       
   322 //
       
   323 void CMMFDevSoundAdaptation::CBody::SetVolume(
       
   324     TInt aVolume)
       
   325     {
       
   326     // Check and make sure that the volume is in valid range
       
   327     if (aVolume < 0)
       
   328         {
       
   329         aVolume = 0;
       
   330         }
       
   331     if (aVolume > MaxVolume())
       
   332         {
       
   333         aVolume = MaxVolume();
       
   334         }
       
   335     iVolume = aVolume;
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // CMMFDevSoundAdaptation::CBody::MaxGain
       
   340 // Returns an integer representing the maximum gain.
       
   341 // This is the maximum value which can be passed to CMMFDevSoundProxy::SetGain.
       
   342 // (other items were commented in a header).
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 TInt CMMFDevSoundAdaptation::CBody::MaxGain()
       
   346     {
       
   347     return KMaxVolume;//uses iMaxVolume for iMaxGain
       
   348     }
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // CMMFDevSoundAdaptation::CBody::Gain
       
   352 // Returns an integer representing the current gain.
       
   353 // (other items were commented in a header).
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 TInt CMMFDevSoundAdaptation::CBody::Gain()
       
   357     {
       
   358     return iGain;
       
   359     }
       
   360 
       
   361 // -----------------------------------------------------------------------------
       
   362 // CMMFDevSoundAdaptation::CBody::SetGain
       
   363 // Changes the current recording gain to a specified value.
       
   364 //
       
   365 // The gain can be changed before or during recording and is effective
       
   366 // immediately.
       
   367 // (other items were commented in a header).
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 void CMMFDevSoundAdaptation::CBody::SetGain(TInt aGain)
       
   371     {
       
   372     // make sure it falls with the correct range
       
   373     if (aGain > MaxGain())
       
   374         {
       
   375         aGain = MaxGain();
       
   376         }
       
   377     else if (aGain < 0)
       
   378         {
       
   379         aGain = 0;
       
   380         }
       
   381     iGain = aGain;
       
   382     }
       
   383 
       
   384 // -----------------------------------------------------------------------------
       
   385 // CMMFDevSoundAdaptation::CBody::GetPlayBalanceL
       
   386 // Returns the speaker balance set for playing.
       
   387 // Leaves on failure.
       
   388 // (other items were commented in a header).
       
   389 // -----------------------------------------------------------------------------
       
   390 //
       
   391 void CMMFDevSoundAdaptation::CBody::GetPlayBalanceL(
       
   392     TInt& aLeftPercentage,
       
   393     TInt& aRightPercentage)
       
   394     {
       
   395     aLeftPercentage = iLeftPlayBalance;
       
   396     aRightPercentage = iRightPlayBalance;
       
   397     }
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CMMFDevSoundAdaptation::CBody::SetPlayBalanceL
       
   401 // Sets the speaker balance for playing.
       
   402 // The speaker balance can be changed before or during playback and is
       
   403 // effective immediately.
       
   404 // (other items were commented in a header).
       
   405 // -----------------------------------------------------------------------------
       
   406 //
       
   407 void CMMFDevSoundAdaptation::CBody::SetPlayBalanceL(
       
   408     TInt aLeftPercentage,
       
   409     TInt aRightPercentage)
       
   410     {
       
   411     if (aLeftPercentage < 0)
       
   412         {
       
   413         aLeftPercentage = 0;
       
   414         }
       
   415     else if (aLeftPercentage > 100)
       
   416         {
       
   417         aLeftPercentage = 100;
       
   418         }
       
   419     if (aRightPercentage < 0)
       
   420         {
       
   421         aRightPercentage = 0;
       
   422         }
       
   423     else if (aRightPercentage > 100)
       
   424         {
       
   425         aRightPercentage = 100;
       
   426         }
       
   427     iLeftPlayBalance = aLeftPercentage;
       
   428     iRightPlayBalance = aRightPercentage;
       
   429     }
       
   430 
       
   431 // -----------------------------------------------------------------------------
       
   432 // CMMFDevSoundAdaptation::CBody::GetRecordBalanceL
       
   433 // Returns the microphone gain balance set for recording.
       
   434 // Leaves on failure.
       
   435 // (other items were commented in a header).
       
   436 // -----------------------------------------------------------------------------
       
   437 //
       
   438 void CMMFDevSoundAdaptation::CBody::GetRecordBalanceL(
       
   439     TInt& aLeftPercentage,
       
   440     TInt& aRightPercentage)
       
   441     {
       
   442     aLeftPercentage = iLeftRecordBalance;
       
   443     aRightPercentage = iRightRecordBalance;
       
   444     }
       
   445 
       
   446 // -----------------------------------------------------------------------------
       
   447 // CMMFDevSoundAdaptation::CBody::SetRecordBalanceL
       
   448 // Sets the microphone gain balance for recording.
       
   449 // The microphone gain balance can be changed before or during recording and
       
   450 // is effective immediately.
       
   451 // (other items were commented in a header).
       
   452 // -----------------------------------------------------------------------------
       
   453 //
       
   454 void CMMFDevSoundAdaptation::CBody::SetRecordBalanceL(
       
   455     TInt aLeftPercentage,
       
   456     TInt aRightPercentage)
       
   457     {
       
   458     if (aLeftPercentage < 0)
       
   459         {
       
   460         aLeftPercentage = 0;
       
   461         }
       
   462     else if (aLeftPercentage > 100)
       
   463         {
       
   464         aLeftPercentage = 100;
       
   465         }
       
   466     if (aRightPercentage < 0)
       
   467         {
       
   468         aRightPercentage = 0;
       
   469         }
       
   470     else if (aRightPercentage > 100)
       
   471         {
       
   472         aRightPercentage = 100;
       
   473         }
       
   474     iLeftRecordBalance = aLeftPercentage;
       
   475     iRightRecordBalance = aRightPercentage;
       
   476     }
       
   477 
       
   478 // -----------------------------------------------------------------------------
       
   479 // CMMFDevSoundAdaptation::CBody::PlayInitL
       
   480 // Initializes audio device and start play process. This method queries and
       
   481 // acquires the audio policy before initializing audio device. If there was an
       
   482 // error during policy initialization, PlayError() method will be called on
       
   483 // the observer with error code KErrAccessDenied, otherwise BufferToBeFilled()
       
   484 // method will be called with a buffer reference. After reading data into the
       
   485 // buffer reference passed, the client should call PlayData() to play data.
       
   486 //
       
   487 // The amount of data that can be played is specified in
       
   488 // CMMFBuffer::RequestSize(). Any data that is read into buffer beyond this
       
   489 // size will be ignored.
       
   490 //
       
   491 // Leaves on failure.
       
   492 // (other items were commented in a header).
       
   493 // -----------------------------------------------------------------------------
       
   494 //
       
   495 void CMMFDevSoundAdaptation::CBody::PlayInitL()
       
   496     {
       
   497     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::PlayInitL"));
       
   498     if (!iDevSoundObserver)
       
   499         {
       
   500         User::Leave(KErrNotReady);
       
   501         }
       
   502 
       
   503     StartPlayDataL();
       
   504     }
       
   505 
       
   506 // -----------------------------------------------------------------------------
       
   507 // CMMFDevSoundAdaptation::CBody::RecordInitL
       
   508 // Initializes audio device and start record process. This method queries and
       
   509 // acquires the audio policy before initializing audio device. If there was an
       
   510 // error during policy initialization, RecordError() method will be called on
       
   511 // the observer with error code KErrAccessDenied, otherwise BufferToBeEmptied()
       
   512 // method will be called with a buffer reference. This buffer contains recorded
       
   513 // or encoded data. After processing data in the buffer reference passed, the
       
   514 // client should call RecordData() to continue recording process.
       
   515 //
       
   516 // The amount of data that is available is specified in
       
   517 // CMMFBuffer::RequestSize().
       
   518 //
       
   519 // Leaves on failure.
       
   520 // (other items were commented in a header).
       
   521 // -----------------------------------------------------------------------------
       
   522 //
       
   523 void CMMFDevSoundAdaptation::CBody::RecordInitL()
       
   524     {
       
   525     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::RecordInitL"));
       
   526     if (!iDevSoundObserver)
       
   527         {
       
   528         User::Leave(KErrNotReady);
       
   529         }
       
   530 
       
   531     StartRecordDataL();
       
   532     }
       
   533 
       
   534 // -----------------------------------------------------------------------------
       
   535 // CMMFDevSoundAdaptation::CBody::PlayData
       
   536 // Plays data in the buffer at the current volume. The client should fill
       
   537 // the buffer with audio data before calling this method. The Observer gets
       
   538 // reference to buffer along with callback BufferToBeFilled(). When playing of
       
   539 // the audio sample is complete, successfully or otherwise, the method
       
   540 // PlayError() on observer is called.
       
   541 // (other items were commented in a header).
       
   542 // -----------------------------------------------------------------------------
       
   543 //
       
   544 void CMMFDevSoundAdaptation::CBody::PlayData()
       
   545     {
       
   546     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::PlayData"));
       
   547     ASSERT(iDevSoundObserver);
       
   548 
       
   549     if (iMode== EMMFStateIdle)
       
   550         {
       
   551         return;
       
   552         }
       
   553 
       
   554     TInt error = KErrNone;
       
   555 
       
   556     if(iCMMFHwDevice)
       
   557         {
       
   558         if (iPaused)
       
   559             {
       
   560             iPaused = EFalse;
       
   561             //note PlayData does not leave or return an error code so the
       
   562             //Start() fails we cannot report the error back at this point
       
   563             if (iCMMFHwDevice->IsActive())
       
   564                 {
       
   565                 iCMMFHwDevice->Cancel();
       
   566                 }
       
   567             //restart hw device after pause
       
   568             error = iCMMFHwDevice->Start(EDevDecode, EDevOutFlow);
       
   569             }
       
   570        else if(iMode== EMMFStatePlaying)
       
   571             {
       
   572             TInt len = iHwDeviceBuffer->Data().Length();
       
   573             iPlayedBytesCount += len;
       
   574             if (iHwDeviceBuffer->LastBuffer())
       
   575                 {
       
   576                 iLastBufferReceived = ETrue;
       
   577                 }
       
   578 
       
   579             // Pass the data buffer to HwDevice
       
   580             if (iMode== EMMFStatePlaying)
       
   581                 {
       
   582                 error = iCMMFHwDevice->ThisHwBufferFilled(*iHwDeviceBuffer);
       
   583                 }
       
   584             }
       
   585         }
       
   586     if (error != KErrNone)
       
   587         {
       
   588         iDevSoundObserver->PlayError(error);
       
   589         }
       
   590     }
       
   591 
       
   592 // -----------------------------------------------------------------------------
       
   593 // CMMFDevSoundAdaptation::CBody::RecordData
       
   594 // Contine the process of recording. Once the buffer is filled with recorded
       
   595 // data, the Observer gets reference to buffer along with callback
       
   596 // BufferToBeEmptied(). After processing the buffer (copying over to a
       
   597 // different buffer or writing to file) the client should call this
       
   598 // method to continue recording process.
       
   599 // (other items were commented in a header).
       
   600 // -----------------------------------------------------------------------------
       
   601 //
       
   602 void CMMFDevSoundAdaptation::CBody::RecordData()
       
   603     {
       
   604     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::RecordData"));
       
   605     ASSERT(iDevSoundObserver);
       
   606     if(iCMMFHwDevice)
       
   607         {
       
   608         if(iMode == EMMFStateRecording)
       
   609             {
       
   610             // Fix to WAV recording issue.
       
   611             // In case of real DevSound adaptation implementation, the
       
   612             // CMMFSwCodecRecordDataPath sets the last buffer parameter when no
       
   613             // more data is in the buffer to process. In case of the stub, this
       
   614             // never gets set as the s/w codec is not involved - we are simply
       
   615             // copying same fixed 4k block of data over and over again. So, on
       
   616             // pause or stop we need to indicate to the data path that we no
       
   617             // longer need processing of data by manually setting last buffer
       
   618             // parameter and resetting requested data size to 0.
       
   619             if (iPaused)
       
   620                 {
       
   621                 iHwDeviceBuffer->SetLastBuffer(ETrue);
       
   622                 iHwDeviceBuffer->Data().SetLength(0);
       
   623                 }
       
   624             else
       
   625                 {
       
   626                 iHwDeviceBuffer->Data().SetLength(iHwDeviceBuffer->RequestSize());
       
   627                 }
       
   628 
       
   629             iCMMFHwDevice->ThisHwBufferEmptied(*iHwDeviceBuffer);
       
   630             }
       
   631         }
       
   632     }
       
   633 
       
   634 // -----------------------------------------------------------------------------
       
   635 // CMMFDevSoundAdaptation::CBody::Stop
       
   636 // Stops the ongoing operation (Play, Record, TonePlay, Convert)
       
   637 // (other items were commented in a header).
       
   638 // -----------------------------------------------------------------------------
       
   639 //
       
   640 void CMMFDevSoundAdaptation::CBody::Stop()
       
   641     {
       
   642     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::Stop"));
       
   643 
       
   644     iPaused = EFalse;
       
   645 
       
   646     if (iMode== EMMFStateIdle)
       
   647         {
       
   648         return;
       
   649         }
       
   650 
       
   651     // For custom interface
       
   652 
       
   653      // Stop the hw device first - this unloads sound drivers
       
   654     if(iCMMFHwDevice)
       
   655         {
       
   656         iCMMFHwDevice->Stop();
       
   657         }
       
   658 
       
   659     if ((iMode== EMMFStateTonePlaying) && (iTonePlayCompleteTimer))
       
   660         {
       
   661         iTonePlayCompleteTimer->Cancel();
       
   662         }
       
   663 
       
   664     }
       
   665 
       
   666 // -----------------------------------------------------------------------------
       
   667 // CMMFDevSoundAdaptation::CBody::Pause
       
   668 // Temporarily Stops the ongoing operation (Play, Record, TonePlay, Convert)
       
   669 // (other items were commented in a header).
       
   670 // -----------------------------------------------------------------------------
       
   671 //
       
   672 void CMMFDevSoundAdaptation::CBody::Pause()
       
   673     {
       
   674     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::Pause"));
       
   675     iPaused = ETrue;
       
   676 
       
   677     if (iMode== EMMFStateIdle)
       
   678         {
       
   679         return;
       
   680         }
       
   681 
       
   682     // Pause the HW device first
       
   683     if(iCMMFHwDevice)
       
   684         {
       
   685         iCMMFHwDevice->Pause();
       
   686         }
       
   687     }
       
   688 
       
   689 // -----------------------------------------------------------------------------
       
   690 // CMMFDevSoundAdaptation::CBody::SamplesRecorded
       
   691 // Returns the sample recorded so far.
       
   692 // (other items were commented in a header).
       
   693 // -----------------------------------------------------------------------------
       
   694 //
       
   695 TInt CMMFDevSoundAdaptation::CBody::SamplesRecorded()
       
   696     {
       
   697     TInt samples = 0;
       
   698     samples = iRecordedBytesCount;
       
   699     if(NumberOfChannels() > 1)
       
   700         {
       
   701         samples /= NumberOfChannels();
       
   702         }
       
   703     if(BytesPerAudioSample() > 1)
       
   704         {
       
   705         samples /= BytesPerAudioSample();
       
   706         }
       
   707     return samples;
       
   708     }
       
   709 
       
   710 // -----------------------------------------------------------------------------
       
   711 // CMMFDevSoundAdaptation::CBody::SamplesPlayed
       
   712 // Returns the sample played so far.
       
   713 // (other items were commented in a header).
       
   714 // -----------------------------------------------------------------------------
       
   715 //
       
   716 TInt CMMFDevSoundAdaptation::CBody::SamplesPlayed()
       
   717     {
       
   718     TInt samples = 0;
       
   719     samples = iPlayedBytesCount;
       
   720     if(NumberOfChannels() > 1)
       
   721         {
       
   722         samples /= NumberOfChannels();
       
   723         }
       
   724 
       
   725     if(BytesPerAudioSample() > 1)
       
   726         {
       
   727         samples /= BytesPerAudioSample();
       
   728         }
       
   729     return samples; //each sample is 2 bytes
       
   730     }
       
   731 
       
   732 // -----------------------------------------------------------------------------
       
   733 // CMMFDevSoundAdaptation::CBody::PlayToneL
       
   734 // Initializes audio device and start playing tone. Tone is played with
       
   735 // frequency and for duration specified.
       
   736 //
       
   737 // Leaves on failure.
       
   738 // (other items were commented in a header).
       
   739 // -----------------------------------------------------------------------------
       
   740 //
       
   741 void CMMFDevSoundAdaptation::CBody::PlayToneL(
       
   742     TInt aFrequency,
       
   743     const TTimeIntervalMicroSeconds& aDuration)
       
   744     {
       
   745     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::PlayToneL"));
       
   746     if (iMode!= EMMFStateTonePlaying)
       
   747         {
       
   748         //tone playing only supported in tone play state
       
   749         User::Leave(KErrNotSupported);
       
   750         }
       
   751     // Check whether frequency and duration is valid or not
       
   752     TInt64 zeroInt64(0);
       
   753     if ((aFrequency<0) || (aDuration.Int64() < zeroInt64))
       
   754         {
       
   755         User::Leave(KErrArgument);
       
   756         }
       
   757     if (!iDevSoundObserver)
       
   758         {
       
   759         User::Leave(KErrNotReady);
       
   760         }
       
   761     iToneGen.SetFrequencyAndDuration(aFrequency,aDuration);
       
   762 
       
   763     StartPlayToneL();
       
   764     }
       
   765 
       
   766 // -----------------------------------------------------------------------------
       
   767 // CMMFDevSoundAdaptation::CBody::PlayDualToneL
       
   768 // Initializes audio device and start playing a dual tone.
       
   769 // The tone consists of two sine waves of different frequencies summed together
       
   770 // Dual Tone is played with specified frequencies and for specified duration.
       
   771 // (other items were commented in a header).
       
   772 // -----------------------------------------------------------------------------
       
   773 //
       
   774 void CMMFDevSoundAdaptation::CBody::PlayDualToneL(
       
   775     TInt aFrequencyOne,
       
   776     TInt aFrequencyTwo,
       
   777     const TTimeIntervalMicroSeconds& aDuration)
       
   778     {
       
   779     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::PlayDualToneL"));
       
   780 
       
   781     // Check whether frequencies and duration are valid or not
       
   782     TInt64 zeroInt64(0);
       
   783     if ((aFrequencyOne<0) || (aFrequencyTwo<0) ||
       
   784         (aDuration.Int64() < zeroInt64))
       
   785         {
       
   786         User::Leave(KErrArgument);
       
   787         }
       
   788     if (!iDevSoundObserver)
       
   789         {
       
   790         User::Leave(KErrNotReady);
       
   791         }
       
   792     iDualToneGen.SetFrequencyAndDuration(aFrequencyOne,
       
   793                                          aFrequencyTwo,
       
   794                                          aDuration);
       
   795     StartPlayDualToneL();
       
   796     }
       
   797 
       
   798 // -----------------------------------------------------------------------------
       
   799 // CMMFDevSoundAdaptation::CBody::PlayDTMFStringL
       
   800 // Initializes audio device and start playing DTMF string aDTMFString.
       
   801 // Leaves on failure.
       
   802 // (other items were commented in a header).
       
   803 // -----------------------------------------------------------------------------
       
   804 //
       
   805 void CMMFDevSoundAdaptation::CBody::PlayDTMFStringL(
       
   806     const TDesC& aDTMFString)
       
   807     {
       
   808     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::PlayDTMFStringL"));
       
   809 
       
   810     if (!iDevSoundObserver)
       
   811         {
       
   812         User::Leave(KErrNotReady);
       
   813         }
       
   814     if (iMode!= EMMFStateTonePlaying)
       
   815         {
       
   816         //tone playing only supported in tone play state
       
   817         User::Leave(KErrNotSupported);
       
   818         }
       
   819     iDTMFGen.SetString(aDTMFString);
       
   820     StartPlayDTMFStringL();
       
   821     }
       
   822 
       
   823 // -----------------------------------------------------------------------------
       
   824 // CMMFDevSoundAdaptation::CBody::PlayToneSequenceL
       
   825 // Initializes audio device and start playing tone sequence.
       
   826 //
       
   827 // Leaves on failure.
       
   828 // (other items were commented in a header).
       
   829 // -----------------------------------------------------------------------------
       
   830 //
       
   831 void CMMFDevSoundAdaptation::CBody::PlayToneSequenceL(const TDesC8& aData)
       
   832     {
       
   833     DEBPRN1(
       
   834     _L("CMMFDevSoundAdaptationStub[0x%x]::CBody::PlayToneSequenceL:Length[%d]"),
       
   835     aData.Length());
       
   836 
       
   837     if (!iDevSoundObserver)
       
   838         {
       
   839         User::Leave(KErrNotReady);
       
   840         }
       
   841     if (iMode!= EMMFStateTonePlaying)
       
   842         {
       
   843         //tone playing only supported in tone play state
       
   844         User::Leave(KErrNotSupported);
       
   845         }
       
   846 
       
   847     InitializeDevSoundUtilL();
       
   848     // Check whether the sequence is valid or not
       
   849     if (!iDevSoundUtil->RecognizeSequence(aData))
       
   850         {
       
   851         User::Leave(KErrCorrupt);
       
   852         }
       
   853 
       
   854     // For playing Tone sequence, we don't use PCM generator.
       
   855     // We use a timer instead
       
   856     // iSequenceGen.SetSequenceData(aData);
       
   857 
       
   858     if (!iTonePlayCompleteTimer)
       
   859         {
       
   860         iTonePlayCompleteTimer =
       
   861             CTonePlayCompleteTimer::NewL(*iDevSoundObserver);
       
   862         }
       
   863     // Determine the time out based on iRepeatCount and number of notes
       
   864     // in the sequence
       
   865     TUint repeats = ((iRepeatCount > 0) ? iRepeatCount : 1);
       
   866     TTimeIntervalMicroSeconds32 time(KToneNotePlayTime*aData.Length()*repeats);
       
   867     iTonePlayCompleteTimer->SetTimeOut(time);
       
   868 
       
   869     StartPlayToneSequenceL();
       
   870     }
       
   871 
       
   872 // -----------------------------------------------------------------------------
       
   873 // CMMFDevSoundAdaptation::CBody::PlayFixedSequenceL
       
   874 // Initializes audio device and start playing the specified pre-defined tone
       
   875 // sequence.
       
   876 //
       
   877 // Leaves on failure.
       
   878 // (other items were commented in a header).
       
   879 // -----------------------------------------------------------------------------
       
   880 //
       
   881 void CMMFDevSoundAdaptation::CBody::PlayFixedSequenceL(TInt aSequenceNumber)
       
   882     {
       
   883     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::PlayFixedSequenceL"));
       
   884 
       
   885     if (!iDevSoundObserver)
       
   886         {
       
   887         User::Leave(KErrNotReady);
       
   888         }
       
   889     if (iMode!= EMMFStateTonePlaying)
       
   890         {
       
   891         //tone playing only supported in tone play state
       
   892         User::Leave(KErrNotSupported);
       
   893         }
       
   894     ASSERT((aSequenceNumber >= 0) &&
       
   895            (aSequenceNumber < iFixedSequences->Count()));
       
   896 
       
   897     iFixedSequence.Set(iFixedSequences->MdcaPoint(aSequenceNumber));
       
   898     iSequenceGen.SetSequenceData(iFixedSequence);
       
   899 
       
   900     StartPlayToneSequenceL();
       
   901     }
       
   902 
       
   903 // -----------------------------------------------------------------------------
       
   904 // CMMFDevSoundAdaptation::CBody::SetToneRepeats
       
   905 // Defines the number of times the audio is to be repeated during the tone
       
   906 // playback operation. A period of silence can follow each playing of tone.
       
   907 // The tone playing can be repeated indefinitely.
       
   908 // Supported only during tone playing.
       
   909 // (other items were commented in a header).
       
   910 // -----------------------------------------------------------------------------
       
   911 //
       
   912 void CMMFDevSoundAdaptation::CBody::SetToneRepeats(
       
   913     TInt aRepeatCount,
       
   914     const TTimeIntervalMicroSeconds& aRepeatTrailingSilence)
       
   915     {
       
   916     iRepeatCount = aRepeatCount;
       
   917     iRepeatTrailingSilence = aRepeatTrailingSilence;
       
   918     }
       
   919 
       
   920 // -----------------------------------------------------------------------------
       
   921 // CMMFDevSoundAdaptation::CBody::SetDTMFLengths
       
   922 // Defines the duration of tone on, tone off and tone pause to be used during the
       
   923 // DTMF tone playback operation.
       
   924 // Supported only during tone playing.
       
   925 // (other items were commented in a header).
       
   926 // -----------------------------------------------------------------------------
       
   927 //
       
   928 void CMMFDevSoundAdaptation::CBody::SetDTMFLengths(
       
   929     TTimeIntervalMicroSeconds32& aToneOnLength,
       
   930     TTimeIntervalMicroSeconds32& aToneOffLength,
       
   931     TTimeIntervalMicroSeconds32& aPauseLength)
       
   932     {
       
   933 
       
   934     if(aToneOnLength.Int() < KMdaInfiniteDurationDTMFToneOnLength)
       
   935         {
       
   936         aToneOnLength = TTimeIntervalMicroSeconds32(0);
       
   937         }
       
   938     if(aToneOffLength.Int() < 0)
       
   939         {
       
   940         aToneOffLength = TTimeIntervalMicroSeconds32(0);
       
   941         }
       
   942     if(aPauseLength.Int() < 0)
       
   943         {
       
   944         aPauseLength = TTimeIntervalMicroSeconds32(0);
       
   945         }
       
   946 
       
   947     iDTMFGen.SetToneDurations(aToneOnLength,aToneOffLength,aPauseLength);
       
   948     }
       
   949 
       
   950 // -----------------------------------------------------------------------------
       
   951 // CMMFDevSoundAdaptation::CBody::SetVolumeRamp
       
   952 // Defines the period over which the volume level is to rise smoothly from
       
   953 // nothing to the normal volume level.
       
   954 // (other items were commented in a header).
       
   955 // -----------------------------------------------------------------------------
       
   956 //
       
   957 void CMMFDevSoundAdaptation::CBody::SetVolumeRamp(
       
   958     const TTimeIntervalMicroSeconds& aRampDuration)
       
   959     {
       
   960     // save ramp duration for tone generator
       
   961     iRampDuration = aRampDuration;
       
   962     }
       
   963 
       
   964 // -----------------------------------------------------------------------------
       
   965 // CMMFDevSoundAdaptation::CBody::SetPrioritySettings
       
   966 // Defines the priority settings that should be used for this instance.
       
   967 // (other items were commented in a header).
       
   968 // -----------------------------------------------------------------------------
       
   969 //
       
   970 void CMMFDevSoundAdaptation::CBody::SetPrioritySettings(
       
   971     const TMMFPrioritySettings& /*aPrioritySettings*/)
       
   972     {
       
   973     }
       
   974 
       
   975 // -----------------------------------------------------------------------------
       
   976 // CMMFDevSoundAdaptation::CBody::CustomInterface
       
   977 // @see sounddevice.h
       
   978 // (other items were commented in a header).
       
   979 // -----------------------------------------------------------------------------
       
   980 //
       
   981 TAny* CMMFDevSoundAdaptation::CBody::CustomInterface(TUid aInterfaceId)
       
   982     {
       
   983 // Note: These can only be uncommented when supported by the
       
   984 //       MessageHandlerFactory and CustomInterfaceProxyFactory stubs.
       
   985 //       Will result in memory leak if re-enabled without updating of
       
   986 //       the proxy and message factory stubs.
       
   987 //
       
   988     DEBPRN1(
       
   989     _L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:InterfaceId[0x%x]"),
       
   990     aInterfaceId);
       
   991 
       
   992     if (aInterfaceId == KUidSpeechEncoderConfig)
       
   993         {
       
   994         TRAP_IGNORE(iSpeechEncoderConfigCI = CSpeechEncoderConfigCI::NewL());
       
   995         DEBPRN0(
       
   996         _L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CSpeechEncoderConfigCI..."));
       
   997         return iSpeechEncoderConfigCI;
       
   998         }
       
   999     else if (aInterfaceId == KUidErrorConcealmentIntfc)
       
  1000         {
       
  1001         TRAP_IGNORE(iErrorConcealmentIntfcCI = CErrorConcealmentIntfcCI::NewL());
       
  1002         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CErrorConcealmentIntfcCI..."));
       
  1003         return iErrorConcealmentIntfcCI;
       
  1004         }
       
  1005     else if (aInterfaceId == KUidG711DecoderIntfc)
       
  1006         {
       
  1007         TRAP_IGNORE(iG711DecoderIntfcCI = CG711DecoderIntfcCI::NewL());
       
  1008         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CG711DecoderIntfcCI..."));
       
  1009         return iG711DecoderIntfcCI;
       
  1010         }
       
  1011     else if (aInterfaceId == KUidG729DecoderIntfc)
       
  1012         {
       
  1013         TRAP_IGNORE(iG729DecoderIntfcCI = CG729DecoderIntfcCI::NewL());
       
  1014         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CG729DecoderIntfcCI..."));
       
  1015         return iG729DecoderIntfcCI;
       
  1016         }
       
  1017     else if (aInterfaceId == KUidIlbcDecoderIntfc)
       
  1018         {
       
  1019         TRAP_IGNORE(iIlbcDecoderIntfcCI = CIlbcDecoderIntfcCI::NewL());
       
  1020         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CIlbcDecoderIntfcCI..."));
       
  1021         return iIlbcDecoderIntfcCI;
       
  1022         }
       
  1023     else if (aInterfaceId == KUidG711EncoderIntfc)
       
  1024         {
       
  1025         TRAP_IGNORE(iG711EncoderIntfcCI = CG711EncoderIntfcCI::NewL());
       
  1026         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CG711EncoderIntfcCI..."));
       
  1027         return iG711EncoderIntfcCI;
       
  1028         }
       
  1029     else if (aInterfaceId == KUidG729EncoderIntfc)
       
  1030         {
       
  1031         TRAP_IGNORE(iG729EncoderIntfcCI = CG729EncoderIntfcCI::NewL());
       
  1032         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CG729EncoderIntfcCI..."));
       
  1033         return iG729EncoderIntfcCI;
       
  1034         }
       
  1035     else if (aInterfaceId == KUidIlbcEncoderIntfc)
       
  1036         {
       
  1037         TRAP_IGNORE(iIlbcEncoderIntfcCI = CIlbcEncoderIntfcCI::NewL());
       
  1038         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CIlbcEncoderIntfcCI..."));
       
  1039         return iIlbcEncoderIntfcCI;
       
  1040         }
       
  1041     else if (aInterfaceId == KUidAudioInput)
       
  1042         {
       
  1043         CAudioInputCI* retCI(NULL);
       
  1044         TRAP_IGNORE(retCI = CAudioInputCI::NewL());
       
  1045         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CAudioInputCI..."));
       
  1046         return retCI;
       
  1047         }
       
  1048     else if(aInterfaceId == KUidAudioOutput)
       
  1049         {
       
  1050         CAudioOutputCI* retCI(NULL);
       
  1051         TRAP_IGNORE(retCI = CAudioOutputCI::NewL());
       
  1052         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CAudioOutputCI..."));
       
  1053         return retCI;
       
  1054         }/*
       
  1055     else if (aInterfaceId == KUidSbcEncoderIntfc)
       
  1056         {
       
  1057         TRAP_IGNORE(iSbcEncoderIntfcCI = CSbcEncoderIntfcCI::NewL());
       
  1058         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CSbcEncoderIntfcCI..."));
       
  1059         return iSbcEncoderIntfcCI;
       
  1060         }
       
  1061     else if (aInterfaceId == KUidAudioVibraControl)
       
  1062         {
       
  1063         TRAP_IGNORE(iAudioVibraControlCI = CAudioVibraControlCI::NewL());
       
  1064         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CAudioVibraControlCI..."));
       
  1065         return iAudioVibraControlCI;
       
  1066         }
       
  1067     else if (aInterfaceId == KUidAudioResource)
       
  1068         {
       
  1069         CAudioResourceCIStub* retCI(NULL);
       
  1070         TRAP_IGNORE(retCI = CAudioResourceCIStub::NewL());
       
  1071         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CAudioResourceCIStub..."));
       
  1072         return retCI;
       
  1073         }
       
  1074     else if (aInterfaceId == KUidAudioEqualizerEffect)
       
  1075         {
       
  1076         CAudioEqualizerCI* retCI(NULL);
       
  1077         TRAP_IGNORE(retCI = CAudioEqualizerCI::NewL());
       
  1078         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CAudioEqualizerCI..."));
       
  1079         return retCI;
       
  1080         }
       
  1081     else if (aInterfaceId == KUidEnvironmentalReverbEffect)
       
  1082         {
       
  1083         CEnvironmentalReverbCI* retCI(NULL);
       
  1084         TRAP_IGNORE(retCI = CEnvironmentalReverbCI::NewL());
       
  1085         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CEnvironmentalReverbCI..."));
       
  1086         return retCI;
       
  1087         }
       
  1088     else if (aInterfaceId == KUidStereoWideningEffect)
       
  1089         {
       
  1090         CStereoWideningCI* retCI(NULL);
       
  1091         TRAP_IGNORE(retCI = CStereoWideningCI::NewL());
       
  1092         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CStereoWideningCI..."));
       
  1093         return retCI;
       
  1094         }
       
  1095     else if (aInterfaceId == KUidBassBoostEffect)
       
  1096         {
       
  1097         CBassBoostCI* retCI(NULL);
       
  1098         TRAP_IGNORE(retCI = CBassBoostCI::NewL());
       
  1099         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CBassBoostCI..."));
       
  1100         return retCI;
       
  1101         }
       
  1102     else if (aInterfaceId == KUidSourceDopplerEffect)
       
  1103         {
       
  1104         CSourceDopplerCI* retCI(NULL);
       
  1105         TRAP_IGNORE(retCI = CSourceDopplerCI::NewL());
       
  1106         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CSourceDopplerCI..."));
       
  1107         return retCI;
       
  1108         }
       
  1109     else if (aInterfaceId == KUidListenerDopplerEffect)
       
  1110         {
       
  1111         CListenerDopplerCI* retCI(NULL);
       
  1112         TRAP_IGNORE(retCI = CListenerDopplerCI::NewL());
       
  1113         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CListenerDopplerCI..."));
       
  1114         return retCI;
       
  1115         }
       
  1116     else if (aInterfaceId == KUidListenerLocationEffect)
       
  1117         {
       
  1118         CListenerLocationCI* retCI(NULL);
       
  1119         TRAP_IGNORE(retCI = CListenerLocationCI::NewL());
       
  1120         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CListenerLocationCI..."));
       
  1121         return retCI;
       
  1122         }
       
  1123     else if (aInterfaceId == KUidSourceLocationEffect)
       
  1124         {
       
  1125         CSourceLocationCI* retCI(NULL);
       
  1126         TRAP_IGNORE(retCI = CSourceLocationCI::NewL());
       
  1127         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CSourceLocationCI..."));
       
  1128         return retCI;
       
  1129         }
       
  1130     else if (aInterfaceId == KUidListenerOrientationEffect)
       
  1131         {
       
  1132         CListenerOrientationCI* retCI(NULL);
       
  1133         TRAP_IGNORE(retCI = CListenerOrientationCI::NewL());
       
  1134         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CListenerOrientationCI..."));
       
  1135         return retCI;
       
  1136         }
       
  1137     else if (aInterfaceId == KUidSourceOrientationEffect)
       
  1138         {
       
  1139         CSourceOrientationCI* retCI(NULL);
       
  1140         TRAP_IGNORE(retCI = CSourceOrientationCI::NewL());
       
  1141         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CSourceOrientationCI..."));
       
  1142         return retCI;
       
  1143         }
       
  1144     else if (aInterfaceId == KUidDistanceAttenuationEffect)
       
  1145         {
       
  1146         CDistanceAttenuationCI* retCI(NULL);
       
  1147         TRAP_IGNORE(retCI = CDistanceAttenuationCI::NewL());
       
  1148         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CDistanceAttenuationCI..."));
       
  1149         return retCI;
       
  1150         }
       
  1151     else if (aInterfaceId == KUidLoudnessEffect)
       
  1152         {
       
  1153         CLoudnessCI* retCI(NULL);
       
  1154         TRAP_IGNORE(retCI = CLoudnessCI::NewL());
       
  1155         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CLoudnessCI..."));
       
  1156         return retCI;
       
  1157         }
       
  1158     else if (aInterfaceId == KUidAddedDevSoundControlInterface)
       
  1159         {
       
  1160         CAddedDevSoundControlCI* retCI(NULL);
       
  1161         TRAP_IGNORE(retCI = CAddedDevSoundControlCI::NewL());
       
  1162         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CAddedDevSoundControlCI..."));
       
  1163         return (MAddedDevSoundControl*)retCI;
       
  1164         }
       
  1165     else if (aInterfaceId == KUidRestrictedAudioOutput)
       
  1166         {
       
  1167         CRestrictedAudioOutputCI* retCI(NULL);
       
  1168         TRAP_IGNORE(retCI = CRestrictedAudioOutputCI::NewL());
       
  1169         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CRestrictedAudioOutputCI..."));
       
  1170         return retCI;
       
  1171         }
       
  1172     else if (aInterfaceId == KUidAacDecoderConfig)
       
  1173         {
       
  1174         TRAP_IGNORE(iAacDecoderConfigCI = CAacDecoderConfigCI::NewL());
       
  1175         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CAacDecoderConfigCI..."));
       
  1176         return iAacDecoderConfigCI;
       
  1177         }
       
  1178     else if (aInterfaceId == KUidEAacPlusDecoderIntfc)
       
  1179         {
       
  1180         TRAP_IGNORE(iEAacPlusDecoderConfigCI = CEAacPlusDecoderIntfcCI::NewL());
       
  1181         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning CEAacPlusDecoderIntfcCI..."));
       
  1182         return iEAacPlusDecoderConfigCI;
       
  1183         }*/
       
  1184     else
       
  1185         {
       
  1186         DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::CustomInterface:returning NULL..."));
       
  1187         return NULL;
       
  1188         }
       
  1189     }
       
  1190 
       
  1191 // -----------------------------------------------------------------------------
       
  1192 // CMMFDevSoundAdaptation::CBody::FixedSequenceCount
       
  1193 // Returns the number of available pre-defined tone sequences.
       
  1194 // This is the number of fixed sequence supported by DevSound by default.
       
  1195 // (other items were commented in a header).
       
  1196 // -----------------------------------------------------------------------------
       
  1197 //
       
  1198 TInt CMMFDevSoundAdaptation::CBody::FixedSequenceCount()
       
  1199     {
       
  1200     return iFixedSequences->Count();
       
  1201     }
       
  1202 
       
  1203 // -----------------------------------------------------------------------------
       
  1204 // CMMFDevSoundAdaptation::CBody::FixedSequenceName
       
  1205 // Returns the name assigned to a specific pre-defined tone sequence.
       
  1206 // This is the number of fixed sequence supported by DevSound by default.
       
  1207 // The function raises a panic if sequence number specified invalid.
       
  1208 // (other items were commented in a header).
       
  1209 // -----------------------------------------------------------------------------
       
  1210 //
       
  1211 const TDesC& CMMFDevSoundAdaptation::CBody::FixedSequenceName(
       
  1212     TInt aSequenceNumber)
       
  1213     {
       
  1214     ASSERT((aSequenceNumber >= 0) &&
       
  1215            (aSequenceNumber < iFixedSequences->Count()));
       
  1216 
       
  1217     TRAPD(err, InitializeDevSoundUtilL());
       
  1218     if (err == KErrNone)
       
  1219         {
       
  1220         return iDevSoundUtil->FixedSequenceName(aSequenceNumber);
       
  1221         }
       
  1222     else
       
  1223         {
       
  1224         return KNullDesC;
       
  1225         }
       
  1226     }
       
  1227 
       
  1228 // -----------------------------------------------------------------------------
       
  1229 // CMMFDevSoundAdaptation::CBody::GetSupportedInputDataTypesL
       
  1230 // @see sounddevice.h
       
  1231 // (other items were commented in a header).
       
  1232 // -----------------------------------------------------------------------------
       
  1233 //
       
  1234 void CMMFDevSoundAdaptation::CBody::GetSupportedInputDataTypesL(
       
  1235     RArray<TFourCC>& aSupportedDataTypes,
       
  1236     const TMMFPrioritySettings& /*aPrioritySettings*/) const
       
  1237     {
       
  1238     //aPrioritySettings not used on ref DevSound
       
  1239     //search for playing datatypes
       
  1240     InitializeDevSoundUtilL();
       
  1241     iDevSoundUtil->SeekHwDevicePluginsL(aSupportedDataTypes, EMMFStatePlaying);
       
  1242     }
       
  1243 
       
  1244 // -----------------------------------------------------------------------------
       
  1245 // CMMFDevSoundAdaptation::CBody::GetSupportedOutputDataTypesL
       
  1246 // @see sounddevice.h
       
  1247 // (other items were commented in a header).
       
  1248 // -----------------------------------------------------------------------------
       
  1249 //
       
  1250 void CMMFDevSoundAdaptation::CBody::GetSupportedOutputDataTypesL(
       
  1251     RArray<TFourCC>& aSupportedDataTypes,
       
  1252     const TMMFPrioritySettings& /*aPrioritySettings*/) const
       
  1253     {
       
  1254     //aPrioritySettings not used on ref DevSound
       
  1255     // search for recording datatypes
       
  1256     InitializeDevSoundUtilL();
       
  1257     iDevSoundUtil->SeekHwDevicePluginsL(aSupportedDataTypes,
       
  1258                                         EMMFStateRecording);
       
  1259     }
       
  1260 
       
  1261 // -----------------------------------------------------------------------------
       
  1262 // CMMFDevSoundAdaptation::CBody::SetClientConfig
       
  1263 // Sets client capabilities for this instance of DevSound Adaptation.
       
  1264 // (other items were commented in a header).
       
  1265 // -----------------------------------------------------------------------------
       
  1266 //
       
  1267 void CMMFDevSoundAdaptation::CBody::SetClientConfig(
       
  1268     const TMMFClientConfig& aClientConfig)
       
  1269     {
       
  1270     iClientConfig = aClientConfig;
       
  1271     }
       
  1272 
       
  1273 // -----------------------------------------------------------------------------
       
  1274 // TMMFClientConfig& CMMFDevSoundAdaptation::CBody::ClientConfig
       
  1275 // Returns client capabilities of this instance of DevSound Adaptation.
       
  1276 // (other items were commented in a header).
       
  1277 // -----------------------------------------------------------------------------
       
  1278 //
       
  1279 const TMMFClientConfig& CMMFDevSoundAdaptation::CBody::ClientConfig() const
       
  1280     {
       
  1281     return iClientConfig;
       
  1282     }
       
  1283 
       
  1284 /********************************************************************************
       
  1285  *              Implementations of Non Exported public functions begins here    *
       
  1286  ********************************************************************************/
       
  1287 
       
  1288 //////////////////////////////////////////////////////////////////////////////////
       
  1289 //              Audio Policy specific implementation begins here                //
       
  1290 //////////////////////////////////////////////////////////////////////////////////
       
  1291 
       
  1292 // -----------------------------------------------------------------------------
       
  1293 // CMMFDevSoundAdaptation::CBody::StartPlayDataL
       
  1294 // Called by Audio Policy Server when a request to play is approved by the
       
  1295 // Audio Policy Server.
       
  1296 //
       
  1297 // Leaves on failure??.
       
  1298 // (other items were commented in a header).
       
  1299 // -----------------------------------------------------------------------------
       
  1300 //
       
  1301 void CMMFDevSoundAdaptation::CBody::StartPlayDataL()
       
  1302     {
       
  1303     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::StartPlayDataL"));
       
  1304 
       
  1305     ASSERT(iMode== EMMFStatePlaying);
       
  1306 
       
  1307     TInt error = KErrNone;
       
  1308 
       
  1309     if(iCMMFHwDevice)
       
  1310         {
       
  1311         // Initialize attribute values
       
  1312         iPlayedBytesCount = 0;
       
  1313         iLastBufferReceived = EFalse;
       
  1314 
       
  1315         // Start HwDevice
       
  1316         if (iCMMFHwDevice->IsActive())
       
  1317             {
       
  1318             iCMMFHwDevice->Cancel();
       
  1319             }
       
  1320         error = iCMMFHwDevice->Start(EDevDecode, EDevOutFlow);
       
  1321         }
       
  1322     else
       
  1323         {
       
  1324         error = KErrNotReady;
       
  1325         }
       
  1326 
       
  1327     if (error != KErrNone)
       
  1328         {
       
  1329         iDevSoundObserver->PlayError(error);
       
  1330         }
       
  1331     }
       
  1332 
       
  1333 // -----------------------------------------------------------------------------
       
  1334 // CMMFDevSoundAdaptation::CBody::StartRecordDataL
       
  1335 // Called by Audio Policy Server when a request to record is approved by the
       
  1336 // Audio Policy Server.
       
  1337 //
       
  1338 // Leaves on failure.
       
  1339 // (other items were commented in a header).
       
  1340 // -----------------------------------------------------------------------------
       
  1341 //
       
  1342 void CMMFDevSoundAdaptation::CBody::StartRecordDataL()
       
  1343     {
       
  1344     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::StartRecordDataL"));
       
  1345 
       
  1346     ASSERT(iMode== EMMFStateRecording);
       
  1347 
       
  1348      if(iCMMFHwDevice)
       
  1349         {
       
  1350         TInt error = KErrNone;
       
  1351         // Initialize attribute values
       
  1352         iRecordedBytesCount = 0;
       
  1353 
       
  1354         if (iCMMFHwDevice->IsActive())
       
  1355             {
       
  1356             iCMMFHwDevice->Cancel();
       
  1357             }
       
  1358         error = iCMMFHwDevice->Start(EDevEncode, EDevInFlow);
       
  1359 
       
  1360         if (iHwDeviceBuffer)
       
  1361             {
       
  1362             iHwDeviceBuffer->SetLastBuffer(EFalse);
       
  1363             }
       
  1364         if (error != KErrNone)
       
  1365             {
       
  1366             iDevSoundObserver->RecordError(error);
       
  1367             return;
       
  1368             }
       
  1369         }
       
  1370     else
       
  1371         {
       
  1372         iDevSoundObserver->RecordError(KErrNotReady);
       
  1373         }
       
  1374     }
       
  1375 
       
  1376 // -----------------------------------------------------------------------------
       
  1377 // CMMFDevSoundAdaptation::CBody::StartPlayToneL
       
  1378 // Called by Audio Policy Server when a request to play tone is approved by
       
  1379 // the Audio Policy Server.
       
  1380 //
       
  1381 // Leaves on failure.
       
  1382 // (other items were commented in a header).
       
  1383 // -----------------------------------------------------------------------------
       
  1384 //
       
  1385 void CMMFDevSoundAdaptation::CBody::StartPlayToneL()
       
  1386     {
       
  1387     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::StartPlayToneL"));
       
  1388 
       
  1389     ASSERT(iMode== EMMFStateTonePlaying);
       
  1390 
       
  1391      if(iCMMFHwDevice)
       
  1392         {
       
  1393         // Initialize attribute values
       
  1394         iPlayedBytesCount = 0;
       
  1395 
       
  1396         // Configure tone generator
       
  1397         iToneGen.Configure(
       
  1398             KToneSamplingRate,
       
  1399             KToneChannels,
       
  1400             iRepeatCount,
       
  1401             I64LOW((iRepeatTrailingSilence.Int64()*KToneSamplingRate)/1000000),
       
  1402             I64LOW((iRampDuration.Int64()*KToneSamplingRate)/1000000)
       
  1403             );
       
  1404 
       
  1405         iCurrentGenerator = &iToneGen;
       
  1406 
       
  1407         // Start playback
       
  1408         DoPlayL();
       
  1409 
       
  1410         }
       
  1411     else
       
  1412         {
       
  1413         iDevSoundObserver->ToneFinished(KErrNotReady);
       
  1414         }
       
  1415     }
       
  1416 
       
  1417 // -----------------------------------------------------------------------------
       
  1418 // CMMFDevSoundAdaptation::CBody::StartPlayDualToneL
       
  1419 // Called by Audio Policy Server when a request to play a dual tone is approved
       
  1420 // by the Audio Policy Server.
       
  1421 // (other items were commented in a header).
       
  1422 // -----------------------------------------------------------------------------
       
  1423 //
       
  1424 void CMMFDevSoundAdaptation::CBody::StartPlayDualToneL()
       
  1425     {
       
  1426     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::StartPlayDualToneL"));
       
  1427 
       
  1428     ASSERT(iMode== EMMFStateTonePlaying);
       
  1429 
       
  1430      if(iCMMFHwDevice)
       
  1431         {
       
  1432         // Initialize attribute values
       
  1433         iPlayedBytesCount = 0;
       
  1434 
       
  1435         // Configure dual tone generator
       
  1436         iDualToneGen.Configure(
       
  1437             KToneSamplingRate,
       
  1438             KToneChannels,
       
  1439             iRepeatCount,
       
  1440             I64LOW((iRepeatTrailingSilence.Int64()
       
  1441                     *KToneSamplingRate)/KOneMillionMicroSeconds),
       
  1442             I64LOW((iRampDuration.Int64()
       
  1443                     *KToneSamplingRate)/KOneMillionMicroSeconds)
       
  1444             );
       
  1445 
       
  1446         iCurrentGenerator = &iDualToneGen;
       
  1447 
       
  1448         // Start playback
       
  1449         DoPlayL();
       
  1450         }
       
  1451     else
       
  1452         iDevSoundObserver->ToneFinished(KErrNotReady);
       
  1453     }
       
  1454 
       
  1455 // -----------------------------------------------------------------------------
       
  1456 // CMMFDevSoundAdaptation::CBody::StartPlayDTMFStringL
       
  1457 // Called by Audio Policy Server when a request to play DTMF String is approved
       
  1458 // by the Audio Policy Server.
       
  1459 //
       
  1460 // Leaves on failure.
       
  1461 // (other items were commented in a header).
       
  1462 // -----------------------------------------------------------------------------
       
  1463 //
       
  1464 void CMMFDevSoundAdaptation::CBody::StartPlayDTMFStringL()
       
  1465     {
       
  1466     DEBPRN0(
       
  1467     _L("CMMFDevSoundAdaptationStub[0x%x]::CBody::StartPlayDTMFStringL"));
       
  1468 
       
  1469     ASSERT(iMode== EMMFStateTonePlaying);
       
  1470 
       
  1471     if(iCMMFHwDevice)
       
  1472         {
       
  1473         TInt error = KErrNone;
       
  1474         // Initialize attribute values
       
  1475         iPlayedBytesCount = 0;
       
  1476 
       
  1477         iDTMFGen.Configure(
       
  1478             KToneSamplingRate,
       
  1479             KToneChannels,
       
  1480             iRepeatCount,
       
  1481             I64LOW((iRepeatTrailingSilence.Int64()*KToneSamplingRate)/1000000),
       
  1482             I64LOW((iRampDuration.Int64()*KToneSamplingRate)/1000000)
       
  1483             );
       
  1484 
       
  1485         iCurrentGenerator = &iDTMFGen;
       
  1486 
       
  1487         // Start playback
       
  1488         //need to trap this as we can leave with KErrUnderflow
       
  1489         //if there was no data to play - the error has already
       
  1490         //been sent to the observer and we don't want to call RunError
       
  1491         TRAP(error,DoPlayL());
       
  1492         if ((error != KErrUnderflow)&&(error != KErrNone))
       
  1493             {
       
  1494             User::Leave(error);
       
  1495             }
       
  1496         }
       
  1497     else
       
  1498         {
       
  1499         iDevSoundObserver->ToneFinished(KErrNotReady);
       
  1500         }
       
  1501     }
       
  1502 
       
  1503 // -----------------------------------------------------------------------------
       
  1504 // CMMFDevSoundAdaptation::CBody::StartPlayToneSequenceL
       
  1505 // Called by Audio Policy Server when a request to play tone sequence is
       
  1506 // approved by the Audio Policy Server.
       
  1507 //
       
  1508 // Leaves on failure.
       
  1509 // (other items were commented in a header).
       
  1510 // -----------------------------------------------------------------------------
       
  1511 //
       
  1512 void CMMFDevSoundAdaptation::CBody::StartPlayToneSequenceL()
       
  1513     {
       
  1514     DEBPRN0(
       
  1515     _L("CMMFDevSoundAdaptationStub[0x%x]::CBody::StartPlayToneSequenceL"));
       
  1516 
       
  1517     ASSERT(iMode == EMMFStateTonePlaying);
       
  1518 
       
  1519     // For playing Tone sequence, we don't use PCM generator.
       
  1520     // We use a timer instead
       
  1521 /*
       
  1522     if(iCMMFHwDevice)
       
  1523         {
       
  1524         // Initialize attribute values
       
  1525         iPlayedBytesCount = 0;
       
  1526 
       
  1527         iSequenceGen.Configure(
       
  1528             KToneSamplingRate,
       
  1529             KToneChannels,
       
  1530             iRepeatCount,
       
  1531             I64LOW((iRepeatTrailingSilence.Int64()*KToneSamplingRate)/1000000),
       
  1532             I64LOW((iRampDuration.Int64()*KToneSamplingRate)/1000000)
       
  1533             );
       
  1534 
       
  1535         iCurrentGenerator = &iSequenceGen;
       
  1536 
       
  1537         // Start playback
       
  1538         DoPlayL();
       
  1539         }
       
  1540     else
       
  1541         iDevSoundObserver->ToneFinished(KErrNotReady);
       
  1542 */
       
  1543     if (iTonePlayCompleteTimer->IsActive())
       
  1544         {
       
  1545         iTonePlayCompleteTimer->Cancel();
       
  1546         }
       
  1547     iTonePlayCompleteTimer->Start();
       
  1548     }
       
  1549 
       
  1550 // -----------------------------------------------------------------------------
       
  1551 // CMMFDevSoundAdaptation::CBody::FillThisHwBuffer
       
  1552 // MMMFHwDeviceObserver mixin implementation.
       
  1553 // The CMMFHwDevice implementation object calls this method during decoding
       
  1554 // (playing), when it needs the encoded data in the buffer
       
  1555 // aHwDataBuffer.
       
  1556 // (other items were commented in a header).
       
  1557 // -----------------------------------------------------------------------------
       
  1558 //
       
  1559 TInt CMMFDevSoundAdaptation::CBody::FillThisHwBuffer(
       
  1560     CMMFBuffer& aHwDataBuffer)
       
  1561     {
       
  1562     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::FillThisHwBuffer"));
       
  1563 
       
  1564     TInt err = KErrNone;
       
  1565     // Keep a reference to this Hw data Buffer. We need to send the
       
  1566     // reference back to HwDevice implementation
       
  1567     iHwDeviceBuffer = static_cast<CMMFDataBuffer*> (&aHwDataBuffer);
       
  1568     // Set the request length, From HwDevice this comes with buffer
       
  1569     // length.
       
  1570     TInt len = iHwDeviceBuffer->Data().MaxLength();
       
  1571     // Ignore error. since buffer size = Buffer Length
       
  1572     TRAP(err, iHwDeviceBuffer->SetRequestSizeL(len));
       
  1573 
       
  1574     if (iMode== EMMFStatePlaying) // Get Data from Observer
       
  1575         {
       
  1576         if (iLastBufferReceived)
       
  1577             {
       
  1578             iHwDeviceBuffer->Data().SetLength(0);
       
  1579             // Pass the buffer to the he device
       
  1580             err = iCMMFHwDevice->ThisHwBufferFilled(*iHwDeviceBuffer);
       
  1581             }
       
  1582         else
       
  1583             {
       
  1584             // Pass the buffer to the observer
       
  1585             iDevSoundObserver->BufferToBeFilled(&aHwDataBuffer);
       
  1586             }
       
  1587         }
       
  1588     else if (iMode== EMMFStateTonePlaying)
       
  1589         {
       
  1590         // Hw device will call this method right after its Start was called.
       
  1591         // When it calls this for the first time it hasn't played one single
       
  1592         // buffer yet so check that.
       
  1593         // In this case there's no need to set the active buffer as it's already
       
  1594         // waiting to be played.
       
  1595         if (!iFirstCallFromHwDevice)
       
  1596             {
       
  1597             SetActiveToneBuffer();
       
  1598             }
       
  1599 
       
  1600         // If there is no data in the active buffer, tone play is finished.
       
  1601         // DevSound just have to wait for completion event from audio device.
       
  1602         if (iActiveToneBuffer->Data().Length() > 0)
       
  1603             {
       
  1604             len = iActiveToneBuffer->Data().Length();
       
  1605             // Copy data from tone buffer to hw device buffer
       
  1606             Mem::Copy((TAny*)(iHwDeviceBuffer->Data().Ptr()),
       
  1607                       (TAny*)(iActiveToneBuffer->Data().Ptr()),
       
  1608                       len);
       
  1609 
       
  1610             iHwDeviceBuffer->Data().SetLength(len);
       
  1611             if (len < iHwDeviceBuffer->RequestSize())
       
  1612                 {
       
  1613                 iHwDeviceBuffer->SetLastBuffer(ETrue);
       
  1614                 }
       
  1615             // Play data and try to generate next data block
       
  1616             err = iCMMFHwDevice->ThisHwBufferFilled(*iHwDeviceBuffer);
       
  1617             if (err != KErrNone)
       
  1618                 {
       
  1619                 return err;
       
  1620                 }
       
  1621 
       
  1622             // Check again whether this is the first call from Hw device.
       
  1623             // FillFreeToneBuffer assumes the iActiveToneBuffer has already
       
  1624             // been played.
       
  1625             if (!iFirstCallFromHwDevice)
       
  1626                 {
       
  1627                 err = FillFreeToneBuffer();
       
  1628                 }
       
  1629             else
       
  1630                 {
       
  1631                 iFirstCallFromHwDevice = EFalse;  // Reset flag
       
  1632                 }
       
  1633             }
       
  1634         else if (iFirstCallFromHwDevice)
       
  1635             {
       
  1636             //we have no data in the tone buffer and thus have no
       
  1637             //outstanding requests to play
       
  1638             err = KErrUnderflow; //simulate underrun
       
  1639             iHwDeviceBuffer->SetLastBuffer(ETrue);
       
  1640             // Play data and try to generate next data block
       
  1641             err = iCMMFHwDevice->ThisHwBufferFilled(*iHwDeviceBuffer);
       
  1642             if (err != KErrNone)
       
  1643                 {
       
  1644                 return err;
       
  1645                 }
       
  1646             }
       
  1647 
       
  1648         // If there was an error filling the buffer could be corrupt data
       
  1649         // notify the client and stop playing.Set err to KErrNone.
       
  1650         if (err != KErrNone)
       
  1651             {
       
  1652             Error(err);//Updates Bytes played informs client
       
  1653             err = KErrNone;
       
  1654             iCMMFHwDevice->Stop();//unloads sound device
       
  1655             Stopped();//Updates policy
       
  1656             }
       
  1657         }
       
  1658     else
       
  1659         {
       
  1660         err = KErrGeneral;
       
  1661         iDevSoundObserver->PlayError(KErrGeneral);
       
  1662         }
       
  1663     return err;
       
  1664     }
       
  1665 
       
  1666 // -----------------------------------------------------------------------------
       
  1667 // CMMFDevSoundAdaptation::CBody::EmptyThisHwBuffer
       
  1668 // MMMFHwDeviceObserver mixin implementation.
       
  1669 // The CMMFHwDevice implementation object calls this method during encoding
       
  1670 // (recording), when it fills the buffer aHwDataBuffer with
       
  1671 // encoded data.
       
  1672 // (other items were commented in a header).
       
  1673 // -----------------------------------------------------------------------------
       
  1674 //
       
  1675 TInt CMMFDevSoundAdaptation::CBody::EmptyThisHwBuffer(
       
  1676     CMMFBuffer& aHwDataBuffer)
       
  1677     {
       
  1678     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::EmptyThisHwBuffer"));
       
  1679 
       
  1680     TInt err = KErrNone;
       
  1681     if(iMode== EMMFStateRecording)
       
  1682         {
       
  1683         // Keep a reference to this Hw data Buffer. We need to send the
       
  1684         // reference back to HwDevice implementation
       
  1685         iHwDeviceBuffer = static_cast<CMMFDataBuffer*>(&aHwDataBuffer);
       
  1686 
       
  1687         // Set the request length, From HwDevice this comes with buffer
       
  1688         // length. MMF will use RequestSize attribute of the buffer.
       
  1689         // We can avoid this by setting in HwDevice implemenation
       
  1690         TInt len = iHwDeviceBuffer->Data().Length();
       
  1691         iRecordedBytesCount += len;
       
  1692         TRAP(err, iHwDeviceBuffer->SetRequestSizeL(len));
       
  1693 
       
  1694         // if we're pausing (i.e. flushing) set the last buffer flag
       
  1695         // when we get an empty buffer from the logical driver
       
  1696         if(iPaused  && iHwDeviceBuffer->Data().Length() == 0)
       
  1697             {
       
  1698             iPaused = EFalse;
       
  1699             iHwDeviceBuffer->SetLastBuffer(ETrue);
       
  1700             }
       
  1701 
       
  1702         // Send Data from Observer
       
  1703         iDevSoundObserver->BufferToBeEmptied(iHwDeviceBuffer);
       
  1704         }
       
  1705     else
       
  1706         {
       
  1707         err = KErrGeneral;
       
  1708         iDevSoundObserver->RecordError(KErrGeneral);
       
  1709         }
       
  1710 
       
  1711     return err;
       
  1712     }
       
  1713 
       
  1714 // -----------------------------------------------------------------------------
       
  1715 // CMMFDevSoundAdaptation::CBody::MsgFromHwDevice
       
  1716 // MMMFHwDeviceObserver mixin implementation.
       
  1717 // The CMMFHwDevice implementation object calls this method when a message from
       
  1718 // the hardware device implementation is received.
       
  1719 // (other items were commented in a header).
       
  1720 // -----------------------------------------------------------------------------
       
  1721 //
       
  1722 TInt CMMFDevSoundAdaptation::CBody::MsgFromHwDevice(
       
  1723     TUid /*aMessageType*/,
       
  1724     const TDesC8& /*aMsg*/)
       
  1725     {
       
  1726     return KErrNotSupported;
       
  1727     }
       
  1728 
       
  1729 // -----------------------------------------------------------------------------
       
  1730 // CMMFDevSoundAdaptation::CBody::Stopped
       
  1731 // MMMFHwDeviceObserver mixin implementation.
       
  1732 //
       
  1733 // The CMMFHwDevice implementation object calls this method when the current
       
  1734 // encode or decode task is finished or stopped.  The policy state is updated
       
  1735 // (other items were commented in a header).
       
  1736 // -----------------------------------------------------------------------------
       
  1737 //
       
  1738 void CMMFDevSoundAdaptation::CBody::Stopped()
       
  1739     {
       
  1740     //for swcodec wrap hw devices bytes played updated in MsgFromHwDevice
       
  1741     //but non Swcodec wrappers hw devices may do it differently also don't
       
  1742     //know if non Swcodec wrap hw device will call Stopped or Error first
       
  1743     iLastBufferReceived = EFalse;
       
  1744     }
       
  1745 
       
  1746 // -----------------------------------------------------------------------------
       
  1747 // CMMFDevSoundAdaptation::CBody::Error
       
  1748 // MMMFHwDeviceObserver mixin implementation
       
  1749 //  Processes error from hw device
       
  1750 // (other items were commented in a header).
       
  1751 // -----------------------------------------------------------------------------
       
  1752 //
       
  1753 void CMMFDevSoundAdaptation::CBody::Error(
       
  1754     TInt aError)
       
  1755     {
       
  1756     DEBPRN1(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::Error(%d)"), aError);
       
  1757 
       
  1758     if (iMode== EMMFStatePlaying)
       
  1759         {
       
  1760         iDevSoundObserver->PlayError(aError);
       
  1761         }
       
  1762     else if (iMode== EMMFStateRecording)
       
  1763         {
       
  1764         iDevSoundObserver->RecordError(aError);
       
  1765         }
       
  1766     else if (iMode== EMMFStateTonePlaying)
       
  1767         {
       
  1768         if (aError == KErrUnderflow)
       
  1769             {
       
  1770             iDevSoundObserver->ToneFinished(KErrNone);
       
  1771             }
       
  1772         else
       
  1773             {
       
  1774             iDevSoundObserver->ToneFinished(aError);
       
  1775             }
       
  1776         }
       
  1777     //else can't handle error
       
  1778     }
       
  1779 
       
  1780 /********************************************************************************
       
  1781  *              Non Exported public functions ends here                         *
       
  1782  ********************************************************************************/
       
  1783 
       
  1784 
       
  1785 /********************************************************************************
       
  1786  *              Private functions begins here                                   *
       
  1787  ********************************************************************************/
       
  1788 
       
  1789 // -----------------------------------------------------------------------------
       
  1790 // CMMFDevSoundAdaptation::CBody::DoPlayL
       
  1791 // Creates buffer and begin playback using the specified tone generator.
       
  1792 // (other items were commented in a header).
       
  1793 // -----------------------------------------------------------------------------
       
  1794 //
       
  1795 void CMMFDevSoundAdaptation::CBody::DoPlayL()
       
  1796     {
       
  1797     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::DoPlayL"));
       
  1798 
       
  1799     // Delete any buffer from previous call and try to create maximum buffer
       
  1800     // size. Double Buffer the Tone data.
       
  1801     if (iToneBuffer1)
       
  1802         {
       
  1803         delete iToneBuffer1;
       
  1804         iToneBuffer1 = NULL;
       
  1805         }
       
  1806 
       
  1807     iToneBuffer1 = CMMFDataBuffer::NewL(KDevSoundDefaultFrameSize);
       
  1808     User::LeaveIfError(iCurrentGenerator->FillBuffer(iToneBuffer1->Data()));
       
  1809 
       
  1810     if (iToneBuffer2)
       
  1811         {
       
  1812         delete iToneBuffer2;
       
  1813         iToneBuffer2 = NULL;
       
  1814         }
       
  1815     iToneBuffer2 = CMMFDataBuffer::NewL(KDevSoundDefaultFrameSize);
       
  1816     User::LeaveIfError(iCurrentGenerator->FillBuffer(iToneBuffer2->Data()));
       
  1817 
       
  1818     // Assign active buffer
       
  1819     iActiveToneBuffer = iToneBuffer1;
       
  1820 
       
  1821     // Hw device hasn't played anything yet so don't change
       
  1822     // active buffer. This is checked in FillThisHwBuffer.
       
  1823     iFirstCallFromHwDevice = ETrue;
       
  1824 
       
  1825     // Start HwDevice to play data
       
  1826     if (iCMMFHwDevice->IsActive())
       
  1827         {
       
  1828         iCMMFHwDevice->Cancel();
       
  1829         }
       
  1830     User::LeaveIfError(iCMMFHwDevice->Start(EDevDecode, EDevOutFlow));
       
  1831     }
       
  1832 
       
  1833 // -----------------------------------------------------------------------------
       
  1834 // CMMFDevSoundAdaptation::CBody::SetActiveToneBuffer
       
  1835 // This method assigns the other buffer as active buffer. The tone audio
       
  1836 //  generator should fill data in the other buffer by now.
       
  1837 // (other items were commented in a header).
       
  1838 // -----------------------------------------------------------------------------
       
  1839 //
       
  1840 void CMMFDevSoundAdaptation::CBody::SetActiveToneBuffer()
       
  1841     {
       
  1842     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::SetActiveToneBuffer"));
       
  1843 
       
  1844     if (iActiveToneBuffer == iToneBuffer1)
       
  1845         {
       
  1846         iActiveToneBuffer = iToneBuffer2;
       
  1847         }
       
  1848     else if (iActiveToneBuffer == iToneBuffer2)
       
  1849         {
       
  1850         iActiveToneBuffer = iToneBuffer1;
       
  1851         }
       
  1852     }
       
  1853 
       
  1854 // -----------------------------------------------------------------------------
       
  1855 // CMMFDevSoundAdaptation::CBody::FillFreeToneBuffer
       
  1856 // This method fills data into the free buffer.
       
  1857 // (other items were commented in a header).
       
  1858 // -----------------------------------------------------------------------------
       
  1859 //
       
  1860 TInt CMMFDevSoundAdaptation::CBody::FillFreeToneBuffer()
       
  1861     {
       
  1862     DEBPRN0(_L("CMMFDevSoundAdaptationStub[0x%x]::CBody::FillFreeToneBuffer"));
       
  1863 
       
  1864     TInt err(KErrNone);
       
  1865     if (iActiveToneBuffer == iToneBuffer1)
       
  1866         {
       
  1867         err = iCurrentGenerator->FillBuffer(iToneBuffer2->Data());
       
  1868         }
       
  1869     else if (iActiveToneBuffer == iToneBuffer2)
       
  1870         {
       
  1871         err = iCurrentGenerator->FillBuffer(iToneBuffer1->Data());
       
  1872         }
       
  1873     return err;
       
  1874     }
       
  1875 
       
  1876 // -----------------------------------------------------------------------------
       
  1877 // CMMFDevSoundAdaptation::CBody::InitTask
       
  1878 // Initializes audio device node by setting volume, and sampling rate.
       
  1879 // (other items were commented in a header).
       
  1880 // -----------------------------------------------------------------------------
       
  1881 //
       
  1882 TInt CMMFDevSoundAdaptation::CBody::InitTask()
       
  1883     {
       
  1884     // No Implementation
       
  1885     return KErrNone;
       
  1886     }
       
  1887 
       
  1888 // -----------------------------------------------------------------------------
       
  1889 // CMMFDevSoundAdaptation::CBody::SamplingFrequency
       
  1890 // Returns an integer representing Sampling Frequency the device is currently
       
  1891 //  configured to.
       
  1892 // (other items were commented in a header).
       
  1893 // -----------------------------------------------------------------------------
       
  1894 //
       
  1895 TInt CMMFDevSoundAdaptation::CBody::SamplingFrequency()
       
  1896     {
       
  1897     if(iDeviceConfig.iRate == EMMFSampleRate8000Hz)
       
  1898         {
       
  1899         return 8000;
       
  1900         }
       
  1901     else if(iDeviceConfig.iRate == EMMFSampleRate11025Hz)
       
  1902         {
       
  1903         return 11025;
       
  1904         }
       
  1905     else if(iDeviceConfig.iRate == EMMFSampleRate12000Hz)
       
  1906         {
       
  1907         return 12000;
       
  1908         }
       
  1909     else if(iDeviceConfig.iRate == EMMFSampleRate16000Hz)
       
  1910         {
       
  1911         return 16000;
       
  1912         }
       
  1913     else if(iDeviceConfig.iRate == EMMFSampleRate22050Hz)
       
  1914         {
       
  1915         return 22050;
       
  1916         }
       
  1917     else if(iDeviceConfig.iRate == EMMFSampleRate24000Hz)
       
  1918         {
       
  1919         return 24000;
       
  1920         }
       
  1921     else if(iDeviceConfig.iRate == EMMFSampleRate32000Hz)
       
  1922         {
       
  1923         return 32000;
       
  1924         }
       
  1925     else if(iDeviceConfig.iRate == EMMFSampleRate44100Hz)
       
  1926         {
       
  1927         return 44100;
       
  1928         }
       
  1929     else if(iDeviceConfig.iRate == EMMFSampleRate48000Hz)
       
  1930         {
       
  1931         return 48000;
       
  1932         }
       
  1933     else if(iDeviceConfig.iRate == EMMFSampleRate88200Hz)
       
  1934         {
       
  1935         return 88200;
       
  1936         }
       
  1937     else if(iDeviceConfig.iRate == EMMFSampleRate96000Hz)
       
  1938         {
       
  1939         return 96000;
       
  1940         }
       
  1941     else
       
  1942         {
       
  1943         return 8000; //default
       
  1944         }
       
  1945     }
       
  1946 
       
  1947 // -----------------------------------------------------------------------------
       
  1948 // CMMFDevSoundAdaptation::CBody::NumberOfChannels
       
  1949 // Returns an integer representing number of channels the device is currently
       
  1950 //  configured to.
       
  1951 // (other items were commented in a header).
       
  1952 // -----------------------------------------------------------------------------
       
  1953 //
       
  1954 TInt CMMFDevSoundAdaptation::CBody::NumberOfChannels()
       
  1955     {
       
  1956     if(iDeviceConfig.iChannels == EMMFMono)
       
  1957         {
       
  1958         return 1;
       
  1959         }
       
  1960     else
       
  1961         {
       
  1962         return 2;
       
  1963         }
       
  1964     }
       
  1965 
       
  1966 // -----------------------------------------------------------------------------
       
  1967 // CMMFDevSoundAdaptation::CBody::BytesPerAudioSample
       
  1968 // Returns an integer representing number of bytes in each audio sample
       
  1969 // (other items were commented in a header).
       
  1970 // -----------------------------------------------------------------------------
       
  1971 //
       
  1972 TInt CMMFDevSoundAdaptation::CBody::BytesPerAudioSample()
       
  1973     {
       
  1974     TInt bytes=1;
       
  1975     switch (iDeviceConfig.iEncoding)
       
  1976         {
       
  1977         case EMMFSoundEncoding8BitPCM:
       
  1978         case EMMFSoundEncoding8BitALaw:
       
  1979         case EMMFSoundEncoding8BitMuLaw:
       
  1980             {
       
  1981             bytes=1;
       
  1982             }
       
  1983         break;
       
  1984         case EMMFSoundEncoding16BitPCM:
       
  1985             {
       
  1986             bytes=2;
       
  1987             }
       
  1988         break;
       
  1989         }
       
  1990     return bytes;
       
  1991     }
       
  1992 
       
  1993 // -----------------------------------------------------------------------------
       
  1994 // CMMFDevSoundAdaptation::CBody::InitializeDevSoundUtilL
       
  1995 // Initializes DevSoundUtil object.
       
  1996 // (other items were commented in a header).
       
  1997 // -----------------------------------------------------------------------------
       
  1998 //
       
  1999 void CMMFDevSoundAdaptation::CBody::InitializeDevSoundUtilL() const
       
  2000     {
       
  2001     if (!iDevSoundUtil)
       
  2002         {
       
  2003         DEBPRN0(
       
  2004         _L("CMMFDevSoundAdaptationStub[0x%x]::CBody::InitializeDevSoundUtilL:ENTER"));
       
  2005 
       
  2006         iDevSoundUtil = CMMFDevSoundUtility::NewL();
       
  2007 
       
  2008         // Initialize Fixed sequence related
       
  2009         DEBPRN0(
       
  2010         _L("CMMFDevSoundAdaptationStub[0x%x]::CBody::InitializeDevSoundUtilL"));
       
  2011         iDevSoundUtil->InitializeFixedSequenceL(&iFixedSequences);
       
  2012 
       
  2013         DEBPRN0(
       
  2014         _L("CMMFDevSoundAdaptationStub[0x%x]::CBody::InitializeDevSoundUtilL"));
       
  2015         }
       
  2016 
       
  2017     }
       
  2018 
       
  2019 //End of File