mmfenh/advancedaudiocontroller/audiocontrollerpluginsvariant/DevSoundAudioOutput/Inc/DevSoundAudioOutput.h
changeset 0 71ca22bcf22a
child 41 a36789189b53
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This file defines the DevSound audio output class responsible for
       
    15 *                sending output to the speaker.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef CDEVSOUNDAUDIOOUTPUT_H
       
    21 #define CDEVSOUNDAUDIOOUTPUT_H
       
    22 
       
    23 // INCLUDES
       
    24 #include "AdvancedAudioOutput.h"
       
    25 #include <sounddevice.h>
       
    26 
       
    27 // CLASS DECLARATIONS
       
    28 class CConfigurationComponentsFactory;
       
    29 class CAudioOutputControlUtility;  
       
    30 /**
       
    31 * This class defines audio output functions specific to DevSound used for playback.
       
    32 *
       
    33 * @lib DevSoundAudioOutput.lib
       
    34 * @since 3.0
       
    35 */
       
    36 class CDevSoundAudioOutput : public CAdvancedAudioOutput,
       
    37                              public MDevSoundObserver
       
    38     {
       
    39     public:  // Constructors and destructor
       
    40 
       
    41        /**
       
    42         * Class instantiation function.
       
    43         * @param   aPrioritySettings  priority settings for devSound and policy
       
    44         * @param   aObserver          observer class that will handle all DevSoundAudioOutput
       
    45         *                             callbacks
       
    46         * @return  pointer to the instance created
       
    47         */
       
    48         IMPORT_C static CDevSoundAudioOutput* NewL(const TMMFPrioritySettings& aPrioritySettings,
       
    49                                                     MAdvancedAudioOutputObserver& aObserver,
       
    50                                                     CMMFDevSound& aMMFDevSound);
       
    51 
       
    52         /**
       
    53         * Destructor function
       
    54         * @param   none
       
    55         * @return  none
       
    56         */
       
    57         IMPORT_C virtual ~CDevSoundAudioOutput();
       
    58 
       
    59     public: // Functions from base classes (CAdvancedAudioOutput)
       
    60 
       
    61         /**
       
    62         * From CAdvancedAudioOutput
       
    63         * Prepares DevSound Audio Output for playback.
       
    64         * @since 3.0
       
    65         * @param   none
       
    66         * @return  none
       
    67         */
       
    68         IMPORT_C virtual void PrimeL();
       
    69 
       
    70         /**
       
    71         * From CAdvancedAudioOutput
       
    72         * Handles request to pause playback. Sends pause command to DevSound.
       
    73         * @since 3.0
       
    74         * @param   none
       
    75         * @return  none
       
    76         */
       
    77         IMPORT_C virtual void PauseL();
       
    78 
       
    79         /**
       
    80         * From CAdvancedAudioOutput
       
    81         * Handles request to start playback. Configures and initializes DevSound.
       
    82         * @since 3.1
       
    83         * @param aBuffer buffer to be played
       
    84         *        aIndex index of the buffer to be played.
       
    85         * @return  none
       
    86         */
       
    87         IMPORT_C virtual void PlayL(TAny* aBuffer, TInt aIndex);
       
    88 
       
    89         /**
       
    90         * From CAdvancedAudioOutput
       
    91         * Handles request to stop playback. Sends stop command to DevSound.
       
    92         * @since 3.0
       
    93         * @param   none
       
    94         * @return  none
       
    95         */
       
    96         IMPORT_C virtual void StopL(TBool aStopDevsound=ETrue);
       
    97 
       
    98         /**
       
    99         * From CAdvancedAudioOutput
       
   100         * Handles request to get the maximum volume. The max volume is obtained from DevSound.
       
   101         * @since 3.0
       
   102         * @param   none
       
   103         * @return  the maximum gain value
       
   104         */
       
   105         IMPORT_C virtual TInt MaxVolumeL();
       
   106 
       
   107         /**
       
   108         * From CAdvancedAudioOutput
       
   109         * Handles request to set the volume. The new value is sent to DevSound.
       
   110         * @since 3.0
       
   111         * @param   aVolume  new volume value
       
   112         * @return  void
       
   113         */
       
   114         IMPORT_C virtual void SetVolumeL(TInt aVolume);
       
   115 
       
   116         /**
       
   117         * From CAdvancedAudioOutput
       
   118         * Handles request to get the current volume. The current volume is obtained from DevSound.
       
   119         * @since 3.0
       
   120         * @param   void
       
   121         * @return  the current volume value
       
   122         */
       
   123         IMPORT_C virtual TInt VolumeL();
       
   124 
       
   125         /**
       
   126         * From CAdvancedAudioOutput
       
   127         * Handles request to set priority. The given priority settings are sent to DevSound.
       
   128         * @since 3.0
       
   129         * @param   aPrioritySettings  new priority settings
       
   130         * @return  none
       
   131         */
       
   132 		IMPORT_C virtual void SetPrioritySettingsL(const TMMFPrioritySettings& aPrioritySettings);
       
   133 
       
   134         /**
       
   135         * From CAdvancedAudioOutput
       
   136         * Handles request to calculate current playback position in terms to micro seconds
       
   137         * @since 3.0
       
   138         * @param   none
       
   139         * @return  Current position in microseconds
       
   140         */
       
   141         IMPORT_C virtual TInt64 CalculateAudioOutputPositionL() const;
       
   142 
       
   143         /**
       
   144         * From CAdvancedAudioOutput
       
   145         * Handles request to get all configured sampling rates from DevSound.
       
   146         * This is a request for all sampling rates that DevSound is currently
       
   147         * configured with.
       
   148         * @since 3.0
       
   149         * @param   aRates  array to hold the retrieved sampling rates
       
   150         * @return  void
       
   151         */
       
   152         IMPORT_C virtual void ConfigRatesL(RArray<TUint>& aRates);
       
   153 
       
   154         /**
       
   155         * From CAdvancedAudioOutput
       
   156         * Handles request to get all configured channels from DevSound.
       
   157         * This is a request for all channels that DevSound is currently
       
   158         * configured with.
       
   159         * @since 3.0
       
   160         * @param   aChannels  array to hold the retrieved channels
       
   161         * @return  void
       
   162         */
       
   163         IMPORT_C virtual void ConfigChannelsL(RArray<TUint>& aChannels);
       
   164 
       
   165         /**
       
   166         * From CAdvancedAudioOutput
       
   167         * Handles request to get all configured data types (FourCC) from DevSound.
       
   168         * This is a request for all data types that DevSound is currently
       
   169         * configured with.
       
   170         * @since 3.0
       
   171         * @param   aDataTypes  array to hold the retrieved data types
       
   172         * @return  void
       
   173         */
       
   174         IMPORT_C virtual void ConfigDataTypesL(RArray<TFourCC>& aDataTypes);
       
   175 
       
   176         /**
       
   177         * From CAdvancedAudioOutput
       
   178         * Handles request to get all capablities sampling rates from DevSound.
       
   179         * This contains all sampling rates DevSound is capable of supporting
       
   180         * @since 3.0
       
   181         * @param   aRates  array to hold the retrieved sampling rates
       
   182         * @return  void
       
   183         */
       
   184         IMPORT_C virtual void CapabilitiesRatesL(RArray<TUint>& aRates);
       
   185 
       
   186         /**
       
   187         * Handles request to get all capabilities channels from DevSound.
       
   188         * This is a request for all channels that DevSound is capable of
       
   189         * supporting.
       
   190         * @since 3.0
       
   191         * @param   aChannels  array to hold the retrieved channels
       
   192         * @return  void
       
   193         */
       
   194         IMPORT_C virtual void CapabilitiesChannelsL(RArray<TUint>& aChannels);
       
   195 
       
   196         /**
       
   197         * From CAdvancedAudioOutput
       
   198         * Handles request to get all capabilities data types (FourCC) from DevSound.
       
   199         * This is a request for all data types that DevSound is capable of
       
   200         * supporting.
       
   201         * @since 3.0
       
   202         * @param   aDataTypes  array to hold the retrieved channels
       
   203         * @return  void
       
   204         */
       
   205         IMPORT_C virtual void CapabilitiesDataTypesL(RArray<TFourCC>& aDataTypes);
       
   206 
       
   207         /**
       
   208         * From CAdvancedAudioOutput
       
   209         * Handles request to set volume ramp to given duration.
       
   210         * @since 3.0
       
   211         * @param   aRampDuration  ramp duration in microseconds
       
   212         * @return  void
       
   213         */
       
   214         IMPORT_C virtual void SetVolumeRampL(const TTimeIntervalMicroSeconds& aRampDuration);
       
   215 
       
   216         /**
       
   217         * From CAdvancedAudioOutput
       
   218         * Handles request to set play balance in DevSound.
       
   219         * @since 3.0
       
   220         * @param   aLeftPercentage   percentage for left channel
       
   221         * @param   aRightPercentage  percentage for right channel
       
   222         * @return  void
       
   223         */
       
   224         IMPORT_C virtual void SetPlayBalanceL(TInt aLeftPercentage, TInt aRightPercentage);
       
   225 
       
   226         /**
       
   227         * From CAdvancedAudioOutput
       
   228         * Handles request to get play balance from DevSound.
       
   229         * @since 3.0
       
   230         * @param   aLeftPercentage   percentage retrieved for left channel
       
   231         * @param   aRightPercentage  percentage retrieved for right channel
       
   232         * @return  void
       
   233         */
       
   234         IMPORT_C virtual void GetPlayBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage);
       
   235 
       
   236         /**
       
   237         * Handles request to configure DevSound with the given parameters.
       
   238         * @since 3.0
       
   239         * @param   aSampleRate       sampling rate
       
   240         * @param   aNumChannel       required number of channels (mono/stereo indication)
       
   241         * @param   aFourCC           FourCC of required recording format
       
   242         * @param   aCodecConfigData  specific codec configuration data
       
   243         * @return  void
       
   244         */
       
   245         IMPORT_C virtual void ConfigureL(TUint aSampleRate, TUint aNumChannel, TFourCC aFourCC,
       
   246                                           const RArray<TInt>& aCodecConfigData);
       
   247 
       
   248         /**
       
   249         * Sets the Decoder instance to be used by the audio output.
       
   250         * @since 3.0
       
   251         * @param aDecoder Decoder instance
       
   252         * @return void
       
   253         */
       
   254         IMPORT_C virtual void SetDecoder(CAdvancedAudioDecoder* aDecoder);
       
   255 
       
   256         IMPORT_C virtual void Resume(TInt aBufferIndex = -1);
       
   257         
       
   258         IMPORT_C virtual void IsLoopPlayEnabled(const TBool aLoopPlayEnabled);
       
   259         
       
   260         IMPORT_C virtual void UnSetLastBuffer(const TBool aUnSetLastBuffer);
       
   261         
       
   262         IMPORT_C TBool IsDSStopped();
       
   263         
       
   264         IMPORT_C virtual void SetDataSourceAdapter(CDataSourceAdapter* aDataSourceAdapter);
       
   265 
       
   266     public: // Functions from base classes (MDevSoundObserver)
       
   267 
       
   268         /**
       
   269         * From MDevSoundObserver
       
   270         * Callback function from DevSound to indicate initialization has completed.
       
   271         * @since 2.0
       
   272         * @param   aError  error code returned by DevSound (KErrNone if no error)
       
   273         * @return  void
       
   274         */
       
   275         virtual void InitializeComplete(TInt aError);
       
   276 
       
   277         /**
       
   278         * From MDevSoundObserver
       
   279         * Callback function from DevSound to indicate tone playback has completed
       
   280         * since 2.0
       
   281         * @param   aError  error code returned by DevSound (KErrNone if no error)
       
   282         * @return  void
       
   283         */
       
   284         virtual void ToneFinished(TInt aError);
       
   285 
       
   286         /**
       
   287         * From MDevSoundObserver
       
   288         * Callback function from DevSound to indicate the spcecified buffer needs to be filled.
       
   289         * (Applicable to playback only)
       
   290         * @since 2.0
       
   291         * @param   aBuffer  buffer to place playback data
       
   292         * @return  void
       
   293         */
       
   294         virtual void BufferToBeFilled(CMMFBuffer* aBuffer);
       
   295 
       
   296         /**
       
   297         * From MDevSoundObserver
       
   298         * Callback function from DevSound to indicate playback has completed successfully
       
   299         * or otherwise.
       
   300         * @since 2.0
       
   301         * @param   aError  error code returned by DevSound (KErrNone if no error)
       
   302         * @return  void
       
   303         */
       
   304         virtual void PlayError(TInt aError);
       
   305 
       
   306         /**
       
   307         * From MDevSoundObserver
       
   308         * Callback function from DevSound to indicate the specified buffer has been filled and
       
   309         * needs to be emptied. (Applicable for Recording only)
       
   310         * @since 2.0
       
   311         * @param   aBuffer  buffer with recorded data that needs to be emptied
       
   312         * @return  void
       
   313         */
       
   314         virtual void BufferToBeEmptied(CMMFBuffer* aBuffer);
       
   315 
       
   316         /**
       
   317         * From MDevSoundObserver
       
   318         * Callback function from DevSound to indicate error has occurred during recording
       
   319         * (for record only)
       
   320         * @since 3.0
       
   321         * @param   aError  error code returned by DevSound (KErrNone if no error)
       
   322         * @return  void
       
   323         */
       
   324         virtual void RecordError(TInt aError);
       
   325 
       
   326         /**
       
   327         * From MDevSoundObserver
       
   328         * Callback function from DevSound to indicate conversion from one format to another
       
   329         * has completed successfully or otherwise.
       
   330         * (during conversion only)
       
   331         * @since 3.0
       
   332         * @param   aError  error code returned by DevSound (KErrNone if no error)
       
   333         * @return  void
       
   334         */
       
   335         virtual void ConvertError(TInt aError);
       
   336 
       
   337         /**
       
   338         * From MDevSoundObserver
       
   339         * Callback function from hardware device passed through via DevSound
       
   340         * @since 3.0
       
   341         * @param   aMessageType  type of message
       
   342         * @param   aMsg          message contents
       
   343         * @return  void
       
   344         */
       
   345         virtual void DeviceMessage(TUid aMessageType, const TDesC8& aMsg);
       
   346 
       
   347         /**
       
   348         * From MDevSoundObserver
       
   349         * Callback function from DevSound to request given event be sent to client
       
   350         * @since 3.0
       
   351         * @param   aEvent  event to send
       
   352         * @return  void
       
   353         */
       
   354         virtual void SendEventToClient(const TMMFEvent& aEvent);
       
   355 
       
   356         /**
       
   357         * From MAdvancedAudioDecoderObserver
       
   358         * Called by a CAdvancedAudioDecoder object when the specifed buffer is filled.
       
   359         * @since 3.0
       
   360         * @param @param   aFilledBuffer  data buffer filled with decoded data
       
   361         * @return void
       
   362         */
       
   363         virtual void BufferFilled(CMMFBuffer* aFilledBuffer);
       
   364 
       
   365         /**
       
   366         * From MAdvancedAudioDecoderObserver
       
   367         * Callback function from CAdvancedAudioDecoder when the specified source buffer
       
   368         * needs to be refilled.
       
   369         * @since 3.0
       
   370         * @param   aEmptyBuffer an empty buffer to be refilled
       
   371         * @param   aDoSynchronousRead whether read should be Sync
       
   372         * @return  -
       
   373         */
       
   374         virtual void RefillBuffer(CMMFBuffer* aEmptyBuffer);
       
   375         
       
   376         /**
       
   377         * From MAdvancedAudioDecoderObserver
       
   378         * Callback function from CAdvancedAudioDecoder when the specified buffer
       
   379         * needs to be refilled. This indicates a shared buffer is to be refilled.
       
   380         * @since 3.2
       
   381         * @param   aEmptyBuffer an empty buffer to be refilled
       
   382         * @param   aDoSynchronousRead if the operation should be perform Synchronuously
       
   383         * @return  -
       
   384         */
       
   385 //        virtual void RefillBuffer(CMMFBuffer* aEmptyBuffer, TBool aDoSynchronousRead);
       
   386 
       
   387         /**
       
   388         * From MAdvancedAudioDecoderObserver
       
   389         * Callback function from CAdvancedAudioDecoder to handle specified event
       
   390         * @since 3.0
       
   391         * @param aEvent The event to be handled
       
   392         * @return -
       
   393         */
       
   394 		virtual void SendEvent(const TMMFEvent& aEvent);
       
   395 
       
   396     private:
       
   397 
       
   398         /**
       
   399         * C++ default constructor.
       
   400         */
       
   401         CDevSoundAudioOutput(CMMFDevSound& aMMFDevSound);
       
   402 
       
   403         /**
       
   404         *
       
   405         * Phase 2 of two-phase constructor
       
   406         *
       
   407         * @param   aPrioritySettings  priority settings for devSound and policy
       
   408         * @param   aObserver          observer class that will handle all DevSoundAudioOutput
       
   409         *                             callbacks
       
   410         *
       
   411         * @return  void
       
   412         *
       
   413         */
       
   414         void ConstructL(const TMMFPrioritySettings& aPrioritySettings,
       
   415 						 MAdvancedAudioOutputObserver& aObserver);
       
   416 
       
   417        /**
       
   418         * Builds configuration data for DevSound and codec.
       
   419         * @since 3.0
       
   420         * @return  void
       
   421         */
       
   422         void BuildConfigurationParametersL();
       
   423 
       
   424         /**
       
   425         *
       
   426         * Converts DevSound bit representation of sampling rates to integer values.
       
   427         *
       
   428         * @param   aDevSoundCaps  DevSound capabilities structure
       
   429         * @param   aSampleRates   array to hold the retrieved sampling rates
       
   430         *
       
   431         * @return  void
       
   432         *
       
   433         */
       
   434 		void ConvertFromDevSoundCapsToSampleRatesL(const TMMFCapabilities& aDevSoundCaps,
       
   435 													RArray<TUint>& aSampleRates);
       
   436 
       
   437         /**
       
   438         *
       
   439         * Converts DevSound representation of data types to FourCC values.
       
   440         *
       
   441         * @param   aDevSoundCaps  DevSound capabilities structure
       
   442         * @param   aDataTypes     array to hold the retrieved data types
       
   443         *
       
   444         * @return  void
       
   445         *
       
   446         */
       
   447 		void ConvertFromDevSoundCapsToDataTypesL(const TMMFCapabilities& aDevSoundCaps,
       
   448 												  RArray<TFourCC>& aDataTypes);
       
   449 
       
   450         /**
       
   451         *
       
   452         * Converts DevSound representation of channels to integer values.
       
   453         *
       
   454         * @param   aDevSoundCaps  DevSound capabilities structure
       
   455         * @param   aNumChannels   array to hold the retrieved number of channels
       
   456         *
       
   457         * @return  void
       
   458         *
       
   459         */
       
   460 		void ConvertFromDevSoundCapsToNumChannelsL(const TMMFCapabilities& aDevSoundCaps,
       
   461 													RArray<TUint>& aNumChannels);
       
   462 
       
   463         /**
       
   464         *
       
   465         * Issues a user panic with the given panic code.
       
   466         * @param   aPanicCode  panic code
       
   467         * @return  void
       
   468         *
       
   469         */
       
   470 		void Panic(TInt aPanicCode) const;
       
   471 
       
   472 		/**
       
   473         * Handles actual start of playback. Configures and initializes DevSound.
       
   474         * @since 3.0
       
   475         * @param   none
       
   476         * @return  none
       
   477         */
       
   478         void DoPlayL(TAny* aBuffer, TInt aIndex);
       
   479     private:
       
   480 
       
   481         // DevSoundAudioOutput states
       
   482         enum TState
       
   483             {
       
   484             EIdle=0,
       
   485             EDevSoundReady,
       
   486             EMMFDevSoundFirstBufferSent,
       
   487             EPlaying,
       
   488             EPaused,
       
   489             EBufferEmpty,
       
   490 			EPreIdle,
       
   491 			EPlayPending
       
   492             };
       
   493 
       
   494         // DevSoundAudioOutput error code
       
   495         enum TError
       
   496             {
       
   497             ECantCreateBuffer,
       
   498             EEmptyBuffer,
       
   499             EDevSoundNotLoaded,
       
   500             ERecordNotSupported,
       
   501             EDevSoundError,
       
   502             EUnknown
       
   503             };
       
   504 
       
   505     private:
       
   506 
       
   507         // DevSoundAudioOutput internal state
       
   508         TState iState;
       
   509 
       
   510         // True if sampling rate conversion is required
       
   511         TBool iNeedsSWConversion;
       
   512 
       
   513         // Sample rate to convert to
       
   514         TUint iSWConvertSampleRate;
       
   515 
       
   516         // Number of channels to convert to
       
   517         TUint iSWConvertChannels;
       
   518 
       
   519         // priority settings for DevSound
       
   520         TMMFPrioritySettings iPrioritySettings;
       
   521 
       
   522         // Structure for DevSound configuration parameters
       
   523         TMMFCapabilities iDevSoundConfig;
       
   524 
       
   525         // sampling rate from the source audio data
       
   526         TUint iSourceSampleRate;
       
   527 
       
   528         // number of channel from the source audio data
       
   529         TUint iSourceChannels;
       
   530 
       
   531         // FourCC from the source audio data
       
   532         TFourCC iSourceFourCC;
       
   533 
       
   534 		// Codec configuration data
       
   535         RArray<TInt> iCodecConfigData;
       
   536 
       
   537        // DevSound pointer
       
   538         CMMFDevSound& iMMFDevSound;
       
   539 		TAny* iPlayPendingBuffer;
       
   540 		TBool iDevSoundInitialized;
       
   541 
       
   542 		TInt iBufferIndex;
       
   543 		TUint32 iPlayDevSound;
       
   544 		
       
   545 		TBool iLoopPlayEnabled; // Indicates if LoopPlay is enabled or not
       
   546 		TBool iIgnoreBTBFDuringLoopPlay; // Ignores any BTBF callbacks from DevSound during the TrailingSilence in LoopPlay
       
   547 		TBool iUnSetLastBuffer; // Indicates if LastBuffer needs to be unset during LoopPlay
       
   548 		TBool iDSStopped; // Indicates if DevSound is Stopped or not
       
   549 		TBool iLastBufferSentToDevSound; // Indicates the end of the playback when last buffer is sent to DevSound at (in normal playback or in loopplay)
       
   550 
       
   551 		CConfigurationComponentsFactory*    iFactory;
       
   552         CAudioOutputControlUtility*         iAudioOutputControlUtility;  
       
   553 	};
       
   554 
       
   555 #endif 		// CDEVSOUNDAUDIOOUTPUT_H