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