os/mm/mmlibs/mmfw/inc/MdaAudioInputStream.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
sl@0
     2
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
// All rights reserved.
sl@0
     4
// This component and the accompanying materials are made available
sl@0
     5
// under the terms of "Eclipse Public License v1.0"
sl@0
     6
// which accompanies this distribution, and is available
sl@0
     7
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
//
sl@0
     9
// Initial Contributors:
sl@0
    10
// Nokia Corporation - initial contribution.
sl@0
    11
//
sl@0
    12
// Contributors:
sl@0
    13
//
sl@0
    14
// Description:
sl@0
    15
//
sl@0
    16
sl@0
    17
sl@0
    18
sl@0
    19
#ifndef __MDAAUDIOINPUTSTREAM_H
sl@0
    20
#define __MDAAUDIOINPUTSTREAM_H
sl@0
    21
sl@0
    22
sl@0
    23
#include <e32std.h>
sl@0
    24
#include <mmf/common/mmfbase.h>
sl@0
    25
#include <mmf/common/mmfstandardcustomcommands.h>
sl@0
    26
#include <mda/common/base.h>
sl@0
    27
#include <mmfclntutility.h>
sl@0
    28
sl@0
    29
sl@0
    30
/**
sl@0
    31
@publishedAll
sl@0
    32
@released
sl@0
    33
sl@0
    34
An interface class that notifies the client of the progress of the audio input streaming. 
sl@0
    35
sl@0
    36
It must be implemented by users of the CMdaAudioInputStream class. 
sl@0
    37
sl@0
    38
An object that implements this interface is passed to CMdaAudioInputStream::NewL().
sl@0
    39
*/
sl@0
    40
class MMdaAudioInputStreamCallback 
sl@0
    41
	{
sl@0
    42
public:
sl@0
    43
sl@0
    44
	/**
sl@0
    45
	A callback function that is called when CMdaAudioInputStream::Open() has 
sl@0
    46
	completed, indicating that the audio input stream is ready for use.
sl@0
    47
sl@0
    48
	@param  aError
sl@0
    49
	        An error value which indicates if open was successful or not. KErrNone if the open succeeded,
sl@0
    50
	        otherwise one of the system error codes.
sl@0
    51
sl@0
    52
	*/
sl@0
    53
	virtual void MaiscOpenComplete(TInt aError) = 0;
sl@0
    54
sl@0
    55
	/**
sl@0
    56
	A callback function that is called when a chunk of audio data has been copied to the descriptor specified 
sl@0
    57
	in a CMdaAudioInputStream::ReadL().
sl@0
    58
sl@0
    59
	It is also called as part of a 'cleanup' operation when CMdaAudioInputStream::Stop() is used. In such circumstances, 
sl@0
    60
	the remaining audio data in the FIFO since the last ReadL() and the Stop() command is returned. In addition aError 
sl@0
    61
	is set to KErrAbort.
sl@0
    62
sl@0
    63
	Use this callback to retrieve the pointers to your recorded data and to issue subsequent ReadL() calls, and be prepared 
sl@0
    64
	to shut down you recording functions if KErrAbort (input stream closed) is returned in aError.
sl@0
    65
sl@0
    66
	@param aError
sl@0
    67
	       An error value indicating if the copy was successful. KErrNone if the copy succeeded, KErrAbort if the input stream 
sl@0
    68
	       was closed for some reason, otherwise one of the system error codes.
sl@0
    69
	@param aBuffer
sl@0
    70
	       A reference to the buffer that has been copied.
sl@0
    71
	*/
sl@0
    72
	virtual void MaiscBufferCopied(TInt aError, const TDesC8& aBuffer) = 0;
sl@0
    73
sl@0
    74
	/**
sl@0
    75
	A callback function that is called when the input stream is closed using CMdaAudioInputStream::Stop(). 
sl@0
    76
sl@0
    77
	This callback is usually 'paired' with a MaiscBufferCopied() that returns the last remaining audio data
sl@0
    78
	in the FIFO between the last CMdaAudioInputStream::ReadL() and the Stop() command.
sl@0
    79
sl@0
    80
	@param aError
sl@0
    81
	       An error value indicating if the record was successful. KErrNone if the stop succeeded, otherwise one
sl@0
    82
	       of the system error codes.
sl@0
    83
	*/
sl@0
    84
	virtual void MaiscRecordComplete(TInt aError) = 0;
sl@0
    85
	};
sl@0
    86
sl@0
    87
sl@0
    88
class CMMFMdaAudioInputStream;
sl@0
    89
sl@0
    90
/**
sl@0
    91
@publishedAll
sl@0
    92
@released
sl@0
    93
sl@0
    94
The interface to an audio stream player passing raw audio data from the audio hardware to specified buffers.
sl@0
    95
sl@0
    96
This class enables MMF clients to:
sl@0
    97
sl@0
    98
Stream raw audio data from the audio hardware to specified buffers.
sl@0
    99
sl@0
   100
Specify the priority of the audio stream in relation to other clients that may request to use the same audio hardware.
sl@0
   101
sl@0
   102
Set the sample rate and  the number of channels after successfully opening the stream. It is not possible to
sl@0
   103
change these values once streaming has started.
sl@0
   104
sl@0
   105
Change the gain and balance before or while streaming is in progress. Gain and balance settings take effect immediately.
sl@0
   106
sl@0
   107
sl@0
   108
The API supports callbacks from the server to notify the client:
sl@0
   109
sl@0
   110
MaiscOpenComplete() will be called when the audio streaming object is open and ready to stream data back to the
sl@0
   111
user as a result of a previous call to Open().
sl@0
   112
sl@0
   113
MaiscBufferCopied() will be called multiple times while the FIFO (queued via ReadL()) is emptied.
sl@0
   114
Note: Each buffer will be flagged with KErrAbort if received after Stop() on is called. MaiscRecordComplete is called
sl@0
   115
once all remaining buffers have been read.
sl@0
   116
sl@0
   117
sl@0
   118
MaiscRecordComplete() is called after Stop() has been called. aError - KErrAbort if MaiscRecordComplete called
sl@0
   119
as a result of a call to Stop().
sl@0
   120
sl@0
   121
Users of object CMdaAudioInputStream should ensure that implementation of the callback methods MaiscOpenComplete,MaiscBufferCopied 
sl@0
   122
and MaiscRecordComplete in class MMdaAudioInputStreamCallback do not delete the object,otherwise a Kern-Exec 3 would occur during callback.
sl@0
   123
*/
sl@0
   124
class CMdaAudioInputStream : public CBase,
sl@0
   125
							 public MMMFClientUtility	
sl@0
   126
{
sl@0
   127
public:
sl@0
   128
sl@0
   129
	/**
sl@0
   130
	Instantiates a new audio input stream using default priority preferences.
sl@0
   131
sl@0
   132
	@param  aCallBack
sl@0
   133
	        A callback to notify the client when the input stream has been initialised and is ready 
sl@0
   134
	        for use, when data has been copied to a specified descriptor and when input streaming is 
sl@0
   135
	        stopped. The caller must create a callback class that implements this interface.
sl@0
   136
sl@0
   137
	@return A pointer to the audio input stream object.
sl@0
   138
	
sl@0
   139
	@capability	UserEnvironment
sl@0
   140
			For recording - the requesting client process must have a 
sl@0
   141
			UserEnvironment capability.
sl@0
   142
	*/
sl@0
   143
	IMPORT_C static CMdaAudioInputStream* NewL(MMdaAudioInputStreamCallback& aCallBack);
sl@0
   144
sl@0
   145
	/**
sl@0
   146
	Instantiates a new audio input stream.
sl@0
   147
sl@0
   148
	@param  aCallBack
sl@0
   149
	        A callback to notify the client when the input stream has been initialised and is ready for 
sl@0
   150
	        use. The caller must create a callback class which implements this interface.
sl@0
   151
	@param  aPriority
sl@0
   152
	        The Priority Value - this client's relative priority. This is a value between EMdaPriorityMin and 
sl@0
   153
	        EMdaPriorityMax and represents a relative priority. A higher value indicates a more important request.
sl@0
   154
    @param  aPref
sl@0
   155
            The Priority Preference - an additional audio policy parameter. The suggested default is 
sl@0
   156
            EMdaPriorityPreferenceNone. Further values are given by TMdaPriorityPreference, and additional 
sl@0
   157
            values may be supported by given phones and/or platforms, but should not be depended upon by 
sl@0
   158
            portable code.
sl@0
   159
sl@0
   160
	@return A pointer to the audio input stream object.
sl@0
   161
sl@0
   162
	@capability	UserEnvironment
sl@0
   163
			For recording - the requesting client process must have a 
sl@0
   164
			UserEnvironment capability.
sl@0
   165
			
sl@0
   166
	Note: The Priority Value and Priority Preference are used primarily when deciding what to do when
sl@0
   167
	several audio clients attempt to play or record simultaneously. In addition to the Priority Value and Preference, 
sl@0
   168
	the adaptation may consider other parameters such as the SecureId and Capabilities of the client process. 
sl@0
   169
	Whatever, the decision 	as to what to do in such situations is up to the audio adaptation, and may
sl@0
   170
	vary between different phones. Portable applications are advised not to assume any specific behaviour. 
sl@0
   171
	*/
sl@0
   172
	IMPORT_C static CMdaAudioInputStream* NewL(MMdaAudioInputStreamCallback& aCallBack,
sl@0
   173
		TInt aPriority,	TInt aPref);
sl@0
   174
sl@0
   175
	/**
sl@0
   176
    Destructor.
sl@0
   177
sl@0
   178
	Frees all resources owned by the object prior to its destruction.
sl@0
   179
	*/
sl@0
   180
	~CMdaAudioInputStream();
sl@0
   181
sl@0
   182
	/**
sl@0
   183
	Sets the sample rate and number of audio channels.
sl@0
   184
sl@0
   185
	@param  aSampleRate
sl@0
   186
	        The new sample rate. For possible values, see the TAudioCaps enum in class TMdaAudioDataSettings.
sl@0
   187
	@param  aChannels
sl@0
   188
	        The new number of channels. For possible values, see the TAudioCaps enum in class TMdaAudioDataSettings.
sl@0
   189
	*/
sl@0
   190
	IMPORT_C void SetAudioPropertiesL(TInt aSampleRate, TInt aChannels);
sl@0
   191
sl@0
   192
	/**
sl@0
   193
	Opens an input audio stream package.
sl@0
   194
sl@0
   195
	The MMdaAudioInputStreamCallback::MaisOpenComplete() callback function is called when the stream has been 
sl@0
   196
	opened and is ready to record data. If the open was unsuccessful, this is indicated by the aError parameter 
sl@0
   197
	of the callback.
sl@0
   198
sl@0
   199
	@param  aSettings
sl@0
   200
	        A pointer to an TMdaPackage object.
sl@0
   201
	*/
sl@0
   202
	IMPORT_C void Open(TMdaPackage* aSettings);
sl@0
   203
sl@0
   204
	/**
sl@0
   205
	Sets the gain for the audio device to a specified value.
sl@0
   206
sl@0
   207
	@param  aNewGain
sl@0
   208
	        The gain setting. This can be any value from zero to the value returned by a call to 
sl@0
   209
	        MaxGain(). A value which is less than zero is set to zero. A value which is greater 
sl@0
   210
	        than MaxGain() is set to MaxGain().
sl@0
   211
	*/
sl@0
   212
	IMPORT_C void SetGain(TInt aNewGain);
sl@0
   213
sl@0
   214
	/**
sl@0
   215
	Returns the current gain setting.
sl@0
   216
sl@0
   217
	@return The current gain setting.
sl@0
   218
	*/
sl@0
   219
	IMPORT_C TInt Gain() const;
sl@0
   220
sl@0
   221
	/**
sl@0
   222
	Returns the maximum gain level.
sl@0
   223
sl@0
   224
	@return The maximum gain value that is supported by the sound device.
sl@0
   225
	*/
sl@0
   226
	IMPORT_C TInt MaxGain() const;
sl@0
   227
sl@0
   228
	/**
sl@0
   229
	Sets the current audio balance.
sl@0
   230
sl@0
   231
	The balance can be any value between KMMFBalanceMaxLeft and KMMFBalanceMaxRight, the default value 
sl@0
   232
	being KMMFBalanceCenter.
sl@0
   233
sl@0
   234
	@param  aBalance
sl@0
   235
	        A specified balance value.
sl@0
   236
	*/
sl@0
   237
	IMPORT_C void SetBalanceL(TInt aBalance = KMMFBalanceCenter);
sl@0
   238
sl@0
   239
	/**
sl@0
   240
	Returns the current audio balance.
sl@0
   241
sl@0
   242
	@return The current balance value.
sl@0
   243
	*/
sl@0
   244
	IMPORT_C TInt GetBalanceL() const;
sl@0
   245
sl@0
   246
	/**
sl@0
   247
	Sets the audio priority values.
sl@0
   248
sl@0
   249
	This function cannot be used while the stream object is open. It is intended for use before an Open()
sl@0
   250
	is issued, or between a previous Stop() and a new Open().
sl@0
   251
sl@0
   252
    @param  aPriority
sl@0
   253
            The Priority Value.
sl@0
   254
    @param  aPref
sl@0
   255
            The Priority Preference.
sl@0
   256
sl@0
   257
    @see CMdaAudioInputStream::NewL()
sl@0
   258
	*/
sl@0
   259
	IMPORT_C void SetPriority(TInt aPriority, TInt aPref);
sl@0
   260
sl@0
   261
	/**
sl@0
   262
	Records streaming raw audio data.
sl@0
   263
sl@0
   264
	If this is the first ReadL() after a successful Open() this function starts the audio recording process.
sl@0
   265
sl@0
   266
	The MMdaAudioInputStreamCallback::MaisBufferCopied() callback function is called when the buffer has been successfully 
sl@0
   267
	filled. A pointer to the newly filled buffer is returned in the callback.
sl@0
   268
sl@0
   269
	Note: The MMdaAudioInputStreamCallback::MaisBufferCopied() callback function is also called when a Stop() is issued, with a 
sl@0
   270
	pointer to the remaining recorded audio data and the aError parameter of the callback set to indicate recording has finished.
sl@0
   271
sl@0
   272
	@param  aData
sl@0
   273
	        A reference to a buffer to be written into.
sl@0
   274
	*/
sl@0
   275
	IMPORT_C void ReadL(TDes8& aData);
sl@0
   276
sl@0
   277
	/**
sl@0
   278
	Stops the recording process.
sl@0
   279
sl@0
   280
	The MMdaAudioInputStreamCallback::MaisRecordComplete() callback function is called when recording has been halted. Just prior 
sl@0
   281
	to issuing this callback, the FIFO buffers are read and the remaining audio data passed back by a final 
sl@0
   282
	MMdaAudioInputStreamCallback::MaisBufferCopied() callback with its aError parameter set to KErrAbort.
sl@0
   283
	
sl@0
   284
	Any remaining FIFO buffers are also passed back, with their aError parameter set to KErrAbort.
sl@0
   285
	
sl@0
   286
	Stop is immediate and best used for premature stops, for example within destructors.
sl@0
   287
	If it is critical to receive all data buffers upto the point that Recording has Stopped, 
sl@0
   288
	we recommend using RequestStop instead. Otherwise some trailing buffers may be lost from the recording process.
sl@0
   289
	
sl@0
   290
	If a Stop is issued after a RequestStop, Stop will take precedent.
sl@0
   291
sl@0
   292
	@see CMdaAudioInputStream::RequestStop()
sl@0
   293
	*/
sl@0
   294
	IMPORT_C void Stop();
sl@0
   295
sl@0
   296
	/**
sl@0
   297
	Returns the current position within the data stream in microseconds since the start of streaming.
sl@0
   298
sl@0
   299
	@return The current position.
sl@0
   300
	*/
sl@0
   301
	IMPORT_C const TTimeIntervalMicroSeconds& Position();
sl@0
   302
sl@0
   303
	/**
sl@0
   304
	Returns the current number of bytes rendered by audio hardware.
sl@0
   305
sl@0
   306
	@return The number of bytes.
sl@0
   307
	*/
sl@0
   308
	IMPORT_C TInt GetBytes();
sl@0
   309
sl@0
   310
sl@0
   311
	/**
sl@0
   312
    Sets the data type.  If the data type is not explicitly set it will assumed to be pcm16.
sl@0
   313
    If it is set then the hardware must support the data type being set otherwise the 
sl@0
   314
    function leaves with KErrNotSupported.
sl@0
   315
    
sl@0
   316
    @param	aAudioType The fourCC code used to request the data type of the recorded data.
sl@0
   317
sl@0
   318
	@leave  KErrNotSupported
sl@0
   319
	        Leaves with this for any unsuported data type.
sl@0
   320
	*/
sl@0
   321
	IMPORT_C void SetDataTypeL(TFourCC aAudioType);
sl@0
   322
sl@0
   323
	/**
sl@0
   324
	Returns the current data type.
sl@0
   325
sl@0
   326
	@return The ID of the data type.
sl@0
   327
	*/
sl@0
   328
	IMPORT_C TFourCC DataType() const;
sl@0
   329
	
sl@0
   330
	/**
sl@0
   331
	Returns the bit rates supported by the sound device
sl@0
   332
	
sl@0
   333
	@param  aSupportedBitRates
sl@0
   334
	@leave KErrNotSupported
sl@0
   335
		If the sound device does not support setting the bit rate
sl@0
   336
	The supported bit rates, in bits per second, shall be appended to this array. Note that 
sl@0
   337
	the array shall be reset by this method.
sl@0
   338
	*/
sl@0
   339
	IMPORT_C void GetSupportedBitRatesL(RArray<TInt>& aSupportedBitRates);
sl@0
   340
	/**
sl@0
   341
	Returns the current bit rate.
sl@0
   342
	@return The current bit rate, in bits per second.
sl@0
   343
	@leave KErrNotSupported
sl@0
   344
		If the sound device does not support returning the current bit rate
sl@0
   345
	*/
sl@0
   346
	IMPORT_C TInt BitRateL() const;
sl@0
   347
	/**
sl@0
   348
	Sets the bit rate to a new value.
sl@0
   349
	@param  aBitRate
sl@0
   350
		The new bit rate, in bits per second.
sl@0
   351
	@leave KErrNotSupported
sl@0
   352
		If the sound device does not support returning the current bit rate or the bit rate set is not supported
sl@0
   353
	*/
sl@0
   354
	IMPORT_C void SetBitRateL(TInt aBitRate);
sl@0
   355
	
sl@0
   356
	/**
sl@0
   357
	Retrieves a custom interface to the underlying device.
sl@0
   358
sl@0
   359
	@param  aInterfaceId
sl@0
   360
	        The interface UID, defined with the custom interface.
sl@0
   361
	
sl@0
   362
	@return A pointer to the interface implementation, or NULL if the device does not
sl@0
   363
	        implement the interface requested. The return value must be cast to the
sl@0
   364
	        correct type by the user.
sl@0
   365
	*/
sl@0
   366
	IMPORT_C TAny* CustomInterface(TUid aInterfaceId);
sl@0
   367
sl@0
   368
	/**
sl@0
   369
	Indicates that the client wishes to use a single buffer	to collect the data. 
sl@0
   370
	This buffer is passed via the ReadL api.
sl@0
   371
	
sl@0
   372
	@param	aSingleMode
sl@0
   373
			ETrue to indicate setting of single buffer mode and the use of a single 
sl@0
   374
			buffer, EFalse to indicate use of multiple buffers.
sl@0
   375
	*/
sl@0
   376
	IMPORT_C void SetSingleBufferMode(TBool aSingleMode);
sl@0
   377
sl@0
   378
	/**
sl@0
   379
	Requests a Stop of the recording process.
sl@0
   380
sl@0
   381
	The device is requested to Stop and does so after all unprocessed buffers are processed and passed
sl@0
   382
	back to the input stream. The device is actually Stopped when the final empty buffer indicating 
sl@0
   383
	buffer process completion is received.
sl@0
   384
sl@0
   385
	@see CMdaAudioInputStream::Stop()
sl@0
   386
	*/
sl@0
   387
	IMPORT_C void RequestStop();
sl@0
   388
sl@0
   389
private:
sl@0
   390
	CMdaAudioInputStream();
sl@0
   391
private:
sl@0
   392
	CMMFMdaAudioInputStream* iProperties;
sl@0
   393
	};
sl@0
   394
sl@0
   395
#endif