2 // Copyright (c) 2002-2009 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".
9 // Initial Contributors:
10 // Nokia Corporation - initial contribution.
19 #ifndef __MDAAUDIOINPUTSTREAM_H
20 #define __MDAAUDIOINPUTSTREAM_H
24 #include <mmf/common/mmfbase.h>
25 #include <mmf/common/mmfstandardcustomcommands.h>
26 #include <mda/common/base.h>
27 #include <mmfclntutility.h>
34 An interface class that notifies the client of the progress of the audio input streaming.
36 It must be implemented by users of the CMdaAudioInputStream class.
38 An object that implements this interface is passed to CMdaAudioInputStream::NewL().
40 class MMdaAudioInputStreamCallback
45 A callback function that is called when CMdaAudioInputStream::Open() has
46 completed, indicating that the audio input stream is ready for use.
49 An error value which indicates if open was successful or not. KErrNone if the open succeeded,
50 otherwise one of the system error codes.
53 virtual void MaiscOpenComplete(TInt aError) = 0;
56 A callback function that is called when a chunk of audio data has been copied to the descriptor specified
57 in a CMdaAudioInputStream::ReadL().
59 It is also called as part of a 'cleanup' operation when CMdaAudioInputStream::Stop() is used. In such circumstances,
60 the remaining audio data in the FIFO since the last ReadL() and the Stop() command is returned. In addition aError
63 Use this callback to retrieve the pointers to your recorded data and to issue subsequent ReadL() calls, and be prepared
64 to shut down you recording functions if KErrAbort (input stream closed) is returned in aError.
67 An error value indicating if the copy was successful. KErrNone if the copy succeeded, KErrAbort if the input stream
68 was closed for some reason, otherwise one of the system error codes.
70 A reference to the buffer that has been copied.
72 virtual void MaiscBufferCopied(TInt aError, const TDesC8& aBuffer) = 0;
75 A callback function that is called when the input stream is closed using CMdaAudioInputStream::Stop().
77 This callback is usually 'paired' with a MaiscBufferCopied() that returns the last remaining audio data
78 in the FIFO between the last CMdaAudioInputStream::ReadL() and the Stop() command.
81 An error value indicating if the record was successful. KErrNone if the stop succeeded, otherwise one
82 of the system error codes.
84 virtual void MaiscRecordComplete(TInt aError) = 0;
88 class CMMFMdaAudioInputStream;
94 The interface to an audio stream player passing raw audio data from the audio hardware to specified buffers.
96 This class enables MMF clients to:
98 Stream raw audio data from the audio hardware to specified buffers.
100 Specify the priority of the audio stream in relation to other clients that may request to use the same audio hardware.
102 Set the sample rate and the number of channels after successfully opening the stream. It is not possible to
103 change these values once streaming has started.
105 Change the gain and balance before or while streaming is in progress. Gain and balance settings take effect immediately.
108 The API supports callbacks from the server to notify the client:
110 MaiscOpenComplete() will be called when the audio streaming object is open and ready to stream data back to the
111 user as a result of a previous call to Open().
113 MaiscBufferCopied() will be called multiple times while the FIFO (queued via ReadL()) is emptied.
114 Note: Each buffer will be flagged with KErrAbort if received after Stop() on is called. MaiscRecordComplete is called
115 once all remaining buffers have been read.
118 MaiscRecordComplete() is called after Stop() has been called. aError - KErrAbort if MaiscRecordComplete called
119 as a result of a call to Stop().
121 Users of object CMdaAudioInputStream should ensure that implementation of the callback methods MaiscOpenComplete,MaiscBufferCopied
122 and MaiscRecordComplete in class MMdaAudioInputStreamCallback do not delete the object,otherwise a Kern-Exec 3 would occur during callback.
124 class CMdaAudioInputStream : public CBase,
125 public MMMFClientUtility
130 Instantiates a new audio input stream using default priority preferences.
133 A callback to notify the client when the input stream has been initialised and is ready
134 for use, when data has been copied to a specified descriptor and when input streaming is
135 stopped. The caller must create a callback class that implements this interface.
137 @return A pointer to the audio input stream object.
139 @capability UserEnvironment
140 For recording - the requesting client process must have a
141 UserEnvironment capability.
143 IMPORT_C static CMdaAudioInputStream* NewL(MMdaAudioInputStreamCallback& aCallBack);
146 Instantiates a new audio input stream.
149 A callback to notify the client when the input stream has been initialised and is ready for
150 use. The caller must create a callback class which implements this interface.
152 The Priority Value - this client's relative priority. This is a value between EMdaPriorityMin and
153 EMdaPriorityMax and represents a relative priority. A higher value indicates a more important request.
155 The Priority Preference - an additional audio policy parameter. The suggested default is
156 EMdaPriorityPreferenceNone. Further values are given by TMdaPriorityPreference, and additional
157 values may be supported by given phones and/or platforms, but should not be depended upon by
160 @return A pointer to the audio input stream object.
162 @capability UserEnvironment
163 For recording - the requesting client process must have a
164 UserEnvironment capability.
166 Note: The Priority Value and Priority Preference are used primarily when deciding what to do when
167 several audio clients attempt to play or record simultaneously. In addition to the Priority Value and Preference,
168 the adaptation may consider other parameters such as the SecureId and Capabilities of the client process.
169 Whatever, the decision as to what to do in such situations is up to the audio adaptation, and may
170 vary between different phones. Portable applications are advised not to assume any specific behaviour.
172 IMPORT_C static CMdaAudioInputStream* NewL(MMdaAudioInputStreamCallback& aCallBack,
173 TInt aPriority, TInt aPref);
178 Frees all resources owned by the object prior to its destruction.
180 ~CMdaAudioInputStream();
183 Sets the sample rate and number of audio channels.
186 The new sample rate. For possible values, see the TAudioCaps enum in class TMdaAudioDataSettings.
188 The new number of channels. For possible values, see the TAudioCaps enum in class TMdaAudioDataSettings.
190 IMPORT_C void SetAudioPropertiesL(TInt aSampleRate, TInt aChannels);
193 Opens an input audio stream package.
195 The MMdaAudioInputStreamCallback::MaisOpenComplete() callback function is called when the stream has been
196 opened and is ready to record data. If the open was unsuccessful, this is indicated by the aError parameter
200 A pointer to an TMdaPackage object.
202 IMPORT_C void Open(TMdaPackage* aSettings);
205 Sets the gain for the audio device to a specified value.
208 The gain setting. This can be any value from zero to the value returned by a call to
209 MaxGain(). A value which is less than zero is set to zero. A value which is greater
210 than MaxGain() is set to MaxGain().
212 IMPORT_C void SetGain(TInt aNewGain);
215 Returns the current gain setting.
217 @return The current gain setting.
219 IMPORT_C TInt Gain() const;
222 Returns the maximum gain level.
224 @return The maximum gain value that is supported by the sound device.
226 IMPORT_C TInt MaxGain() const;
229 Sets the current audio balance.
231 The balance can be any value between KMMFBalanceMaxLeft and KMMFBalanceMaxRight, the default value
232 being KMMFBalanceCenter.
235 A specified balance value.
237 IMPORT_C void SetBalanceL(TInt aBalance = KMMFBalanceCenter);
240 Returns the current audio balance.
242 @return The current balance value.
244 IMPORT_C TInt GetBalanceL() const;
247 Sets the audio priority values.
249 This function cannot be used while the stream object is open. It is intended for use before an Open()
250 is issued, or between a previous Stop() and a new Open().
255 The Priority Preference.
257 @see CMdaAudioInputStream::NewL()
259 IMPORT_C void SetPriority(TInt aPriority, TInt aPref);
262 Records streaming raw audio data.
264 If this is the first ReadL() after a successful Open() this function starts the audio recording process.
266 The MMdaAudioInputStreamCallback::MaisBufferCopied() callback function is called when the buffer has been successfully
267 filled. A pointer to the newly filled buffer is returned in the callback.
269 Note: The MMdaAudioInputStreamCallback::MaisBufferCopied() callback function is also called when a Stop() is issued, with a
270 pointer to the remaining recorded audio data and the aError parameter of the callback set to indicate recording has finished.
273 A reference to a buffer to be written into.
275 IMPORT_C void ReadL(TDes8& aData);
278 Stops the recording process.
280 The MMdaAudioInputStreamCallback::MaisRecordComplete() callback function is called when recording has been halted. Just prior
281 to issuing this callback, the FIFO buffers are read and the remaining audio data passed back by a final
282 MMdaAudioInputStreamCallback::MaisBufferCopied() callback with its aError parameter set to KErrAbort.
284 Any remaining FIFO buffers are also passed back, with their aError parameter set to KErrAbort.
286 Stop is immediate and best used for premature stops, for example within destructors.
287 If it is critical to receive all data buffers upto the point that Recording has Stopped,
288 we recommend using RequestStop instead. Otherwise some trailing buffers may be lost from the recording process.
290 If a Stop is issued after a RequestStop, Stop will take precedent.
292 @see CMdaAudioInputStream::RequestStop()
294 IMPORT_C void Stop();
297 Returns the current position within the data stream in microseconds since the start of streaming.
299 @return The current position.
301 IMPORT_C const TTimeIntervalMicroSeconds& Position();
304 Returns the current number of bytes rendered by audio hardware.
306 @return The number of bytes.
308 IMPORT_C TInt GetBytes();
312 Sets the data type. If the data type is not explicitly set it will assumed to be pcm16.
313 If it is set then the hardware must support the data type being set otherwise the
314 function leaves with KErrNotSupported.
316 @param aAudioType The fourCC code used to request the data type of the recorded data.
318 @leave KErrNotSupported
319 Leaves with this for any unsuported data type.
321 IMPORT_C void SetDataTypeL(TFourCC aAudioType);
324 Returns the current data type.
326 @return The ID of the data type.
328 IMPORT_C TFourCC DataType() const;
331 Returns the bit rates supported by the sound device
333 @param aSupportedBitRates
334 @leave KErrNotSupported
335 If the sound device does not support setting the bit rate
336 The supported bit rates, in bits per second, shall be appended to this array. Note that
337 the array shall be reset by this method.
339 IMPORT_C void GetSupportedBitRatesL(RArray<TInt>& aSupportedBitRates);
341 Returns the current bit rate.
342 @return The current bit rate, in bits per second.
343 @leave KErrNotSupported
344 If the sound device does not support returning the current bit rate
346 IMPORT_C TInt BitRateL() const;
348 Sets the bit rate to a new value.
350 The new bit rate, in bits per second.
351 @leave KErrNotSupported
352 If the sound device does not support returning the current bit rate or the bit rate set is not supported
354 IMPORT_C void SetBitRateL(TInt aBitRate);
357 Retrieves a custom interface to the underlying device.
360 The interface UID, defined with the custom interface.
362 @return A pointer to the interface implementation, or NULL if the device does not
363 implement the interface requested. The return value must be cast to the
364 correct type by the user.
366 IMPORT_C TAny* CustomInterface(TUid aInterfaceId);
369 Indicates that the client wishes to use a single buffer to collect the data.
370 This buffer is passed via the ReadL api.
373 ETrue to indicate setting of single buffer mode and the use of a single
374 buffer, EFalse to indicate use of multiple buffers.
376 IMPORT_C void SetSingleBufferMode(TBool aSingleMode);
379 Requests a Stop of the recording process.
381 The device is requested to Stop and does so after all unprocessed buffers are processed and passed
382 back to the input stream. The device is actually Stopped when the final empty buffer indicating
383 buffer process completion is received.
385 @see CMdaAudioInputStream::Stop()
387 IMPORT_C void RequestStop();
390 CMdaAudioInputStream();
392 CMMFMdaAudioInputStream* iProperties;