os/mm/mmlibs/mmfw/inc/MdaAudioOutputStream.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#ifndef __MDAAUDIOOUTPUTSTREAM_H
sl@0
    17
#define __MDAAUDIOOUTPUTSTREAM_H
sl@0
    18
sl@0
    19
sl@0
    20
#include <e32std.h>
sl@0
    21
#include <mmf/common/mmfbase.h>
sl@0
    22
#include <mmf/common/mmfstandardcustomcommands.h>
sl@0
    23
#include <mda/common/base.h>      
sl@0
    24
#include <mda/client/utility.h>
sl@0
    25
#include <mmf/common/mmfaudio.h>
sl@0
    26
#include <mmfclntutility.h>
sl@0
    27
sl@0
    28
sl@0
    29
/**
sl@0
    30
@publishedAll
sl@0
    31
@released
sl@0
    32
sl@0
    33
An interface class that notifies the client of the progress of audio output streaming.
sl@0
    34
sl@0
    35
It must be implemented by users of the CMdaAudioOutputStream class.
sl@0
    36
sl@0
    37
An object that implements this interface is passed to CMdaAudioOutputStream::NewL().
sl@0
    38
*/
sl@0
    39
class MMdaAudioOutputStreamCallback 
sl@0
    40
	{
sl@0
    41
public:
sl@0
    42
sl@0
    43
	/**
sl@0
    44
	A callback function that is called when CMdaAudioOutputStream::Open() has completed, indicating that the
sl@0
    45
	audio output stream is ready for use.
sl@0
    46
sl@0
    47
	@param  aError
sl@0
    48
	        An error value which indicates if open was completed successfully. KErrNone if succeeded.
sl@0
    49
	*/
sl@0
    50
	virtual void MaoscOpenComplete(TInt aError) = 0;
sl@0
    51
sl@0
    52
	/**
sl@0
    53
	A callback function that is called when a descriptor has been copied to the lower layers of MMF. 
sl@0
    54
sl@0
    55
	It is also called when an error has occurred or when the client has stopped the stream playing before the descriptor 
sl@0
    56
	has been fully copied (by calling CMdaAudioOutputStream::Stop()).
sl@0
    57
sl@0
    58
	This function indicates to the client that it is safe to destroy the buffer passed to CMdaAudioOutputStream::WriteL(). 
sl@0
    59
	It can also be used to make the next call to WriteL().
sl@0
    60
sl@0
    61
	@param  aError
sl@0
    62
	        KErrNone if the copy succeeded, otherwise one of the system error codes. KErrAbort indicates that 
sl@0
    63
	        the client has stopped the stream playing before the descriptor has been copied.
sl@0
    64
	@param  aBuffer
sl@0
    65
	        A reference to the buffer that has been copied.
sl@0
    66
	*/
sl@0
    67
	virtual void MaoscBufferCopied(TInt aError, const TDesC8& aBuffer) = 0;
sl@0
    68
sl@0
    69
	/**
sl@0
    70
	A callback function that is called when playback terminates as a result of a CMdaAudioOutputStream::Stop().
sl@0
    71
sl@0
    72
	If the end of the sound data has been reached, the function returns KErrUnderFlow. If playback terminates for any 
sl@0
    73
	other reason, the function returns an appropriate error value.
sl@0
    74
sl@0
    75
	@param  aError
sl@0
    76
	        An error value which indicates play success or not. KErrNone if the close succeeded, otherwise one of the
sl@0
    77
	        system error codes.
sl@0
    78
	*/
sl@0
    79
	virtual void MaoscPlayComplete(TInt aError) = 0;
sl@0
    80
	};
sl@0
    81
sl@0
    82
sl@0
    83
class CMMFMdaAudioOutputStream;
sl@0
    84
sl@0
    85
/**
sl@0
    86
@publishedAll
sl@0
    87
@released
sl@0
    88
sl@0
    89
The interface to an audio stream player passing raw audio data from specified buffers to the audio hardware.
sl@0
    90
sl@0
    91
This class enables MMF clients to:
sl@0
    92
sl@0
    93
Stream raw audio data to the audio hardware from specified buffers
sl@0
    94
sl@0
    95
Specify the priority of the audio stream in relation to other clients that may request to use the same audio hardware
sl@0
    96
sl@0
    97
Set the sample rate and the number of channels after successfully opening the stream. It is not possible to change these 
sl@0
    98
values once  streaming has started.
sl@0
    99
sl@0
   100
Change the volume and balance before or while the stream is open for writing. Volume and balance settings take effect immediately.
sl@0
   101
sl@0
   102
The API supports callbacks from the server to notify the client:
sl@0
   103
sl@0
   104
MaoscOpenComplete() will be called when the audio streaming object is open and ready to stream data back to the
sl@0
   105
audio hardware as a result of a previous call to Open().
sl@0
   106
sl@0
   107
MaoscBufferCopied() will be called each time audio data has been successfully copied to the lower layers of the
sl@0
   108
MMF as a result of a previous WriteL().
sl@0
   109
sl@0
   110
MaoscPlayComplete() will be called when the audio data stream has been closed as a result of a previous Stop().
sl@0
   111
*/
sl@0
   112
class CMdaAudioOutputStream : public CBase,
sl@0
   113
							  public MMMFClientUtility
sl@0
   114
	{
sl@0
   115
public:
sl@0
   116
sl@0
   117
	/**
sl@0
   118
	Allocates and constructs an audio stream player object.
sl@0
   119
sl@0
   120
	@param  aCallBack
sl@0
   121
	        A callback to notify the client when the sound device is open and ready to receive data, when 
sl@0
   122
	        each descriptor has been copied and when the stream is closed. The caller must create a 
sl@0
   123
	        callback class which implements this interface.
sl@0
   124
	@param  aServer
sl@0
   125
	        A pointer to a CMdaServer. CMdaServer is deprecated and as such this parameter is only provided 
sl@0
   126
	        for backward compatibility.
sl@0
   127
sl@0
   128
	@return A pointer to new audio stream player.
sl@0
   129
	*/
sl@0
   130
	IMPORT_C static CMdaAudioOutputStream* NewL(MMdaAudioOutputStreamCallback& aCallBack,
sl@0
   131
												CMdaServer* aServer = NULL);
sl@0
   132
sl@0
   133
	/**
sl@0
   134
	Constructs and initialises a new instance of an audio streaming object.
sl@0
   135
sl@0
   136
	The function leaves if the audio streaming object cannot be created.
sl@0
   137
sl@0
   138
	@param  aCallBack
sl@0
   139
	        A callback to notify the client when the sound device is open and ready to receive data, when each
sl@0
   140
	        descriptor has been copied and when the stream is closed. The caller must create a callback class
sl@0
   141
	        which implements this interface.
sl@0
   142
    @param  aPriority
sl@0
   143
            The Priority Value - this client's relative priority. This is a value between EMdaPriorityMin and 
sl@0
   144
            EMdaPriorityMax and represents a relative priority. A higher value indicates a more important request.
sl@0
   145
    @param  aPref
sl@0
   146
            The Priority Preference - an additional audio policy parameter. The suggested default is 
sl@0
   147
            EMdaPriorityPreferenceNone. Further values are given by TMdaPriorityPreference, and additional 
sl@0
   148
            values may be supported by given phones and/or platforms, but should not be depended upon by 
sl@0
   149
            portable code.
sl@0
   150
sl@0
   151
	@return A pointer to CMdaAudioOutputStream.
sl@0
   152
sl@0
   153
    Note: The Priority Value and Priority Preference are used primarily when deciding what to do when
sl@0
   154
    several audio clients attempt to play or record simultaneously. In addition to the Priority Value and Preference, 
sl@0
   155
    the adaptation may consider other parameters such as the SecureId and Capabilities of the client process. 
sl@0
   156
    Whatever, the decision  as to what to do in such situations is up to the audio adaptation, and may
sl@0
   157
    vary between different phones. Portable applications are advised not to assume any specific behaviour. 
sl@0
   158
	*/
sl@0
   159
	IMPORT_C static CMdaAudioOutputStream* NewL(MMdaAudioOutputStreamCallback& aCallBack,
sl@0
   160
												TInt aPriority,
sl@0
   161
												TInt aPref = EMdaPriorityPreferenceTimeAndQuality);
sl@0
   162
sl@0
   163
sl@0
   164
	/**
sl@0
   165
    Destructor.
sl@0
   166
sl@0
   167
	Frees all resources owned by the object prior to its destruction.
sl@0
   168
	*/
sl@0
   169
	~CMdaAudioOutputStream();
sl@0
   170
sl@0
   171
	/**
sl@0
   172
	Sets the sample rate and number of audio channels.
sl@0
   173
sl@0
   174
	@param  aSampleRate
sl@0
   175
	        The new sample rate. For possible values, see the TAudioCaps enum in class TMdaAudioDataSettings.
sl@0
   176
	@param  aChannels
sl@0
   177
	        The new number of channels. For possible values, see the TAudioCaps enum in class TMdaAudioDataSettings.
sl@0
   178
	
sl@0
   179
	*/
sl@0
   180
	virtual void SetAudioPropertiesL(TInt aSampleRate, TInt aChannels);
sl@0
   181
sl@0
   182
	/**
sl@0
   183
	Opens an output audio stream package.
sl@0
   184
sl@0
   185
	The MMdaAudioOutputStreamCallback::MaoscOpenComplete() callback function is called when the stream has been 
sl@0
   186
	opened and is ready to receive audio data. If the open was unsuccessful, this is indicated by the aError 
sl@0
   187
	parameter of the callback.
sl@0
   188
sl@0
   189
sl@0
   190
	@param  aSettings
sl@0
   191
	        A pointer to a TMdaPackage object.
sl@0
   192
	
sl@0
   193
	*/
sl@0
   194
	virtual void Open(TMdaPackage* aSettings);
sl@0
   195
sl@0
   196
	/**
sl@0
   197
	Returns the maximum volume level.
sl@0
   198
sl@0
   199
	@return The maximum volume level supported by the sound device, as an integer.
sl@0
   200
	*/
sl@0
   201
	virtual TInt MaxVolume();
sl@0
   202
sl@0
   203
	/**
sl@0
   204
	Returns the current volume.
sl@0
   205
sl@0
   206
	@return The current volume as an integer.
sl@0
   207
	*/
sl@0
   208
	virtual TInt Volume();
sl@0
   209
sl@0
   210
	/**
sl@0
   211
	Sets the audio volume.
sl@0
   212
sl@0
   213
	Set the volume to zero for "sound off" or any other value between 1 and MaxVolume().
sl@0
   214
sl@0
   215
	@param  aNewVolume
sl@0
   216
	        A specified audio volume.
sl@0
   217
sl@0
   218
	*/
sl@0
   219
	virtual void SetVolume(const TInt aNewVolume);
sl@0
   220
sl@0
   221
	/**
sl@0
   222
	Sets the audio priority values.
sl@0
   223
sl@0
   224
	This function cannot be used while the stream object is open. It is intended for use before an Open() 
sl@0
   225
	is issued, or between a previous Stop() and a new Open().
sl@0
   226
sl@0
   227
	@param  aPriority
sl@0
   228
	        The Priority Value.
sl@0
   229
	@param  aPref
sl@0
   230
	        The Priority Preference.
sl@0
   231
sl@0
   232
    @see CMdaAudioOutputStream::NewL()
sl@0
   233
	*/
sl@0
   234
	virtual void SetPriority(TInt aPriority, TInt aPref);
sl@0
   235
	
sl@0
   236
	/**
sl@0
   237
	Writes (plays) streaming raw audio data.
sl@0
   238
sl@0
   239
	This function is asynchronous. When aData has been received, the client is notified by a call to 
sl@0
   240
	MMdaAudioOutputStreamCallback::MaoscBufferCopied(). The client can call WriteL() again before this notification 
sl@0
   241
	takes place because the buffers are maintained in a client-side queue until they have been sent. An active object 
sl@0
   242
	performs the notification, and copies the next item in the queue to the server.
sl@0
   243
	MMdaAudioOutputStreamCallback::MaoscPlayComplete() is called when all descriptors have been sent.
sl@0
   244
sl@0
   245
	@param  aData
sl@0
   246
	        A reference to the stream data.
sl@0
   247
sl@0
   248
	*/
sl@0
   249
	virtual void WriteL(const TDesC8& aData);
sl@0
   250
sl@0
   251
	/**
sl@0
   252
	Stops writing data to a stream.
sl@0
   253
sl@0
   254
	*/
sl@0
   255
	virtual void Stop();
sl@0
   256
sl@0
   257
	/**
sl@0
   258
	Pause data rendering by audio hardware.
sl@0
   259
	@return  An error code indicating if the operation was successful. KErrNone on success, 
sl@0
   260
		KErrNotReady if not streaming
sl@0
   261
		KErrNotSupported if trying to pause when resume is not supported by DevSound
sl@0
   262
	*/
sl@0
   263
sl@0
   264
	IMPORT_C TInt Pause();
sl@0
   265
sl@0
   266
sl@0
   267
	/**
sl@0
   268
	Resume data rendering by audio hardware.
sl@0
   269
	@return  An error code indicating if the operation was successful. KErrNone on success, 
sl@0
   270
		KErrNotReady if not paused. 
sl@0
   271
		KErrNotSupported if trying to resume when resume is not supported by DevSound
sl@0
   272
	*/
sl@0
   273
	IMPORT_C TInt Resume();
sl@0
   274
sl@0
   275
sl@0
   276
	/**
sl@0
   277
	Returns the current position within the data stream.
sl@0
   278
sl@0
   279
	@return The current position within the stream in microseconds.
sl@0
   280
	*/
sl@0
   281
	virtual const TTimeIntervalMicroSeconds& Position();
sl@0
   282
sl@0
   283
	/**
sl@0
   284
	Sets the audio balance.
sl@0
   285
sl@0
   286
	@param  aBalance
sl@0
   287
	        A specified balance volume. Default is KMMFBalanceCenter.
sl@0
   288
sl@0
   289
	*/
sl@0
   290
	IMPORT_C void SetBalanceL(TInt aBalance = KMMFBalanceCenter);
sl@0
   291
	
sl@0
   292
	/**
sl@0
   293
	Returns the current balance as an integer.
sl@0
   294
sl@0
   295
	@return The current balance value as integer.
sl@0
   296
	*/
sl@0
   297
	IMPORT_C TInt GetBalanceL() const;
sl@0
   298
sl@0
   299
	/**
sl@0
   300
	Returns the current number of bytes rendered by audio hardware.
sl@0
   301
sl@0
   302
	@return The current current number of bytes rendered by audio hardware as an integer.
sl@0
   303
	*/
sl@0
   304
	IMPORT_C TInt GetBytes();
sl@0
   305
sl@0
   306
	/**
sl@0
   307
    Sets the data type.  If the data type is not explicitly set it will assumed to be pcm16.
sl@0
   308
    If it is set then the hardware must support the data type being set otherwise the 
sl@0
   309
    function leaves with KErrNotSupported.
sl@0
   310
    
sl@0
   311
    @param	aAudioType The fourCC code used to specify the data type of the streamed audio
sl@0
   312
sl@0
   313
	@leave KErrNotSupported
sl@0
   314
	       Leaves with this for any unsuported data type.
sl@0
   315
	*/
sl@0
   316
    IMPORT_C void SetDataTypeL(TFourCC aAudioType);
sl@0
   317
sl@0
   318
	/**
sl@0
   319
	Returns the current data type.
sl@0
   320
sl@0
   321
	@return The ID of the data type.
sl@0
   322
	*/
sl@0
   323
	IMPORT_C TFourCC DataType() const;
sl@0
   324
	
sl@0
   325
	/**
sl@0
   326
	Registers the Event for Notification when resource is avaliable.
sl@0
   327
	@param	aCallback
sl@0
   328
	      	The audio outputstream observer interface..
sl@0
   329
	@param 	aNotificationEventUid
sl@0
   330
	 	The Event for which the client is registered.
sl@0
   331
	@param 	aNotificationRegistrationData
sl@0
   332
		Notification registration specific data.
sl@0
   333
	@return An error code indicating if the registration was successful. KErrNone on success, 
sl@0
   334
		otherwise another of the system-wide error codes.
sl@0
   335
	*/
sl@0
   336
	IMPORT_C TInt RegisterAudioResourceNotification(MMMFAudioResourceNotificationCallback& aCallback,TUid aNotificationEventUid,const TDesC8& aNotificationRegistrationData = KNullDesC8);
sl@0
   337
	
sl@0
   338
	/**
sl@0
   339
	Cancels the registered notification event.
sl@0
   340
	@param  aNotificationEventUid
sl@0
   341
		The Event to notify the client.
sl@0
   342
		
sl@0
   343
	@return An error code indicating if the registration was successful. KErrNone on success, 
sl@0
   344
		otherwise another of the system-wide error codes.
sl@0
   345
	*/
sl@0
   346
	IMPORT_C TInt CancelRegisterAudioResourceNotification(TUid aNotificationEventId);
sl@0
   347
    
sl@0
   348
    	/**
sl@0
   349
	Waits for the client to resume the play even after the default timer expires.
sl@0
   350
	@return An error code indicating if the registration was successful. KErrNone on success, 
sl@0
   351
		otherwise another of the system-wide error codes.
sl@0
   352
	*/
sl@0
   353
	IMPORT_C TInt WillResumePlay();
sl@0
   354
	
sl@0
   355
	/**
sl@0
   356
	Retrieves a custom interface to the underlying device.
sl@0
   357
sl@0
   358
	@param  aInterfaceId
sl@0
   359
	        The interface UID, defined with the custom interface.
sl@0
   360
	
sl@0
   361
	@return A pointer to the interface implementation, or NULL if the device does not
sl@0
   362
	        implement the interface requested. The return value must be cast to the
sl@0
   363
	        correct type by the user.
sl@0
   364
	*/
sl@0
   365
	IMPORT_C TAny* CustomInterface(TUid aInterfaceId);
sl@0
   366
	
sl@0
   367
	/**
sl@0
   368
	When this method is called, AudioOutputStream goes into a different mode wherein it does not call 
sl@0
   369
	MaoscPlayComplete() with KErrUnderflow when all the supplied data has been played. Instead client 
sl@0
   370
	should signal the end of the play by calling RequestStop() or Stop() on AudioOutputStream.
sl@0
   371
	If the client calls RequestStop(), AudioOutputStream waits until all the queued data has been played out
sl@0
   372
	and then calls MaoscPlayComplete(). This behaviour is different from that of Stop(), which stops the play
sl@0
   373
	immediately by discarding all the queued data.
sl@0
   374
	
sl@0
   375
	Client should call this method on CMdaAudioOutputStream just after its construction and its 
sl@0
   376
	effect remains through out its lifetime.
sl@0
   377
	
sl@0
   378
	Note: This feature is supported only on a DevSound which ignores the underflow errors in the middle of
sl@0
   379
	the play i.e which returns ETrue from QueryIgnoresUnderflow().
sl@0
   380
	
sl@0
   381
	@return KErrNone on success, 
sl@0
   382
			KErrNotSupported if the underlying DevSound does not ignore the underflow errors in the middle of the play
sl@0
   383
				
sl@0
   384
	@see CMdaAudioOutputStream::RequestStop()
sl@0
   385
	@see CMMFDevSound::QueryIgnoresUnderflow()
sl@0
   386
	*/
sl@0
   387
	IMPORT_C TInt KeepOpenAtEnd();
sl@0
   388
	
sl@0
   389
	/**
sl@0
   390
	This method signals the end of play when the AudioOutputStream is in KeepOpenAtEnd mode i.e when client
sl@0
   391
	makes KeepOpenAtEnd call on it. When RequestStop is called, AudioOutputStream completes playing all
sl@0
   392
	the data that is supplied to it and calls MaoscPlayComplete() with KErrUnderflow.
sl@0
   393
	
sl@0
   394
	Note: Before calling this method, client must have already called KeepOpenAtEnd() successfully, Otherwise, this
sl@0
   395
		  method returns KErrNotSupported. 
sl@0
   396
		  It is recommended to use KeepOpenAtEnd and RequestStop calls to get a predictable behaviour during stopping.
sl@0
   397
	
sl@0
   398
	@return KErrNone on success
sl@0
   399
			KErrNotSupported when this method is called without calling KeepOpenAtEnd
sl@0
   400
			KErrNotReady when this method is called before completing previous RequestStop or AudioOutputStream
sl@0
   401
			is already in the stopped state
sl@0
   402
	
sl@0
   403
	@see CMdaAudioOutputStream::KeepOpenAtEnd()
sl@0
   404
	*/
sl@0
   405
	IMPORT_C TInt RequestStop();
sl@0
   406
sl@0
   407
private:
sl@0
   408
	CMdaAudioOutputStream();
sl@0
   409
private:
sl@0
   410
	/**
sl@0
   411
	This member is internal and not intended for use.
sl@0
   412
	*/
sl@0
   413
	CMMFMdaAudioOutputStream* iProperties;
sl@0
   414
	};
sl@0
   415
sl@0
   416
#endif