MAudioStream Class Reference

class MAudioStream

this is the main control interface for the state of a processing unit chain.

An AudioStream object binds together audio components processing the same data. An AudioStrem executes the audio processing states as requested by the client. The processing units attached to a stream will follow the state of the stream.

The possible states of an AudioStream object are: EUninitialized: The state which the chain is in initially. The logical chain can be constructed. The settings in the logical chain cannot be related to the adaptation because no adaptation has been selected yet.

EInitialized: this state is set after a successful initialization request. EIdle: All the chain resources are allocated, however, no processing time (other than expended to put the chain into EIdle state) is consumed in this phase. EPrimed: As per EIdle, but the stream can consume processing time, by filling its buffers. EActive: The chain has all the resources as per EIdle and EPrimed but also has started to process the actions requested by the client. EDead: The stream can no longer function due to fatal error. The logical chain still exists, but any physical resources should be reclaimed by the adaptation.

The MAudioStreamObserver includes completion callbacks for many of the methods of MAudioStream. The protocol is such that when an asynchronous method is called and KErrNone is returned, then the call will be followed by a corresponding callback. if the returned error code from the asynchronous function is other than KErrNone, then a callback will not be made as a result of that method call. The callbacks will always occur out-of-context. Note that many of the functions will also require a context commit for the actual processing to take place.

Member Functions Documentation

Activate()

TInt Activate()[pure virtual]

Starts the audio processing. this function is only allowed while the stream is in EIdle or EPrimed states.

The start-up procedures include requesting permission for audio processing from audio policy.

AddAudioCodec(MAudioProcessingUnit *)

TInt AddAudioCodec(MAudioProcessingUnit *aCodec)[pure virtual]

Adds an codec for this stream.

The codec must be removed from the stream before the codec or the stream is deleted. The codec can only be set while the stream is in uninitialized state. this is an asynchronous call and the completion will be indicated to the client via a callback in the stream observer interface.

Parameters

MAudioProcessingUnit * aCodecthe codec for this stream

AddGainControl(MAudioProcessingUnit *)

TInt AddGainControl(MAudioProcessingUnit *aGainControl)[pure virtual]

Adds an audio processing unit to this stream.

The processing unit must be removed from the stream before the processing unit or the stream is removed from the context. The supplied component must implement the AudioGainControl feature.

Parameters

MAudioProcessingUnit * aGainControlthe gain control to add to this stream.

AddSink(MAudioProcessingUnit *)

TInt AddSink(MAudioProcessingUnit *aSink)[pure virtual]

Adds sink for this stream.

Stream cannot operate before source and sink have been set. The sink must be removed from the stream before it is destroyed. The sink can only be set while the stream is in uninitialized state. this is an asynchronous call and the completion will be indicated to the client via a callback in the stream observer interface.

Parameters

MAudioProcessingUnit * aSinkthe sink for this stream

AddSource(MAudioProcessingUnit *)

TInt AddSource(MAudioProcessingUnit *aSource)[pure virtual]

Adds an audio source to this stream.

A stream cannot operate before a source has been set. The source must be removed from the stream before the sink or the stream is destroyed. The source can only be set while the stream is in uninitialized state. this is an asynchronous call and the completion will be indicated to the client via a callback in the stream observer interface.

Parameters

MAudioProcessingUnit * aSourcethe audio source for this stream.

Flush()

TInt Flush()[pure virtual]

Empty any buffers that have been filled.

Reclain any outstanding buffers from the client, if required. this function is only allowed while the stream is in Idle state. this is an asynchronous operation. if the call returns KErrNone it merely indicates a flush has been requested and there will be a subsequent FlushComplete() callback. Note that this does not relate to the Commit() cycle, and is not considered transactional.

GetAudioType(TAudioTypeSettings &)

voidGetAudioType(TAudioTypeSettings &aAudioTypeSettings)const [pure virtual]

Fetch the type of audio being processed in this stream.

Parameters

TAudioTypeSettings & aAudioTypeSettingsOn return contains the audio type of this stream.

GetStreamTime(TTimeIntervalMicroSeconds &)

TInt GetStreamTime(TTimeIntervalMicroSeconds &aStreamTime)[pure virtual]

Returns the duration of audio that has been processed from the hardware device perspective. The time is reset when the MAudioStream object transfers from Initialized state to Idle. as a result of calling Load(). It can be reset at other times using ResetStreamTime().

Parameters

TTimeIntervalMicroSeconds & aStreamTime

Initialize()

TInt Initialize()[pure virtual]

Requests a transition to the EInitialized state.

this function is asynchronous, and its successful return merely issues a request which is acted upon on Commit(), and while will lead to a StateEvent() callback. this function is only allowed while the stream is in EUninitialized state. A call in any other state will cause an error code of KErrNotReady to be returned.

InstanceId()

TAudioStreamId InstanceId()const [pure virtual]

Returns the component instance id.

Interface(TUid)

TAny *Interface(TUidaType)[pure virtual]

A mechanism to obtain additional control APIs on the stream.

These can be used to extend the basic play/record, pause, stop with future use-cases such as seek play.

Parameters

TUid aTypeUid that denotes the type of the interface.

Load()

TInt Load()[pure virtual]

Requests a transition to the EIdle state.

this function is asynchronous, and its successful return merely issues a request which is acted upon on Commit(), and while will lead to a StateEvent() callback. this function is only allowed while the stream is in EInitialized state. A call in any other state will cause an error code of KErrNotReady to be returned

The resources must be released using Unload() when they are no longer needed. Note that it is recommended that the resources are not kept reserved for long periods of inactivity, since it may prevent other audio streams from becoming active by stealing resources they need to use

Prime()

TInt Prime()[pure virtual]

Requests a transition to the EPrime state.

this function is asynchronous, and its successful return merely issues a request which is acted upon on Commit(), and while will lead to a StateEvent() callback. this function is only allowed while the stream is in EActive (semantics of Prime in EActive go into a buffering pause) or EIdle state (semantics of Prime in EIdle start to buffer). A call in any other state will cause an error code of KErrNotReady to be returned. Not all streams support Prime.

RegisterAudioStreamObserver(MAudioStreamObserver &)

TInt RegisterAudioStreamObserver(MAudioStreamObserver &aObserver)[pure virtual]

Registers an audio stream observer.

Note that this function is meant for clients of the Audio Stream. The client should unregister using UnregisterAudioStreamObserver() when applicable.

Parameters

MAudioStreamObserver & aObserverreference to the observer to register.

RemoveProcessingUnit(MAudioProcessingUnit *)

TInt RemoveProcessingUnit(MAudioProcessingUnit *aProcessingUnit)[pure virtual]

Removes any audio processing unit from this stream, whether it has been added by AddSource(), AddSink(), AddCodec() or AddGainControl(). this is an asynchronous function, on successful call there will be a subsequent RemoveProcessingUnitComplete() callback.

Parameters

MAudioProcessingUnit * aProcessingUnitthe processing unit to remove.

ResetStreamTime()

TInt ResetStreamTime()[pure virtual]

Resets the duration counter.

Used to differentiate between when a stream has been momentarily interrupted and when a different conceptual use-case is underway. Defined for EIdle.

SetAudioType(const TAudioTypeSettings &)

TInt SetAudioType(const TAudioTypeSettings &aAudioTypeSettings)[pure virtual]

Sets the type of audio being processed in this context.

The audio type settings are used by the resource control subsystem when it arbitrates between multiple clients trying to access the same resource. Additionally it may impact the availability of certain audio features for the client. It may also have an effect on other aspects, including, but not limited to routing and automatically applied effects. The audio types available for the client may be limited by the platform security capabilities, vendorId etc of the client application.

Parameters

const TAudioTypeSettings & aAudioTypeSettingsdefines the settings associated with this stream.

Stop()

TInt Stop()[pure virtual]

Requests a transition to the Idle state stopping the ongoing operation.

this function is asynchronous, and its successful return merely issues a request which is acted upon on Commit(), and while will lead to a StateEvent() callback this function is only allowed while the stream is either Active or Primed. A call in any other state will cause an error code of KErrNotReady to be returned.

Uninitialize()

TInt Uninitialize()[pure virtual]

Requests a transition to the Unitialized state returning the stream to its initial state.

this function is asynchronous, and its successful return merely issues a request which is acted upon on Commit(), and while will lead to a StateEvent() callback. this function is only allowed while the stream is in Initialized state. A call in any other state will cause an error code of KErrNotReady to be returned.

Unload()

TInt Unload()[pure virtual]

Prepares the audio stream for releasing the resources reserved for it and for the processing units attached to the stream.

this function is only allowed while the stream is EIdle state. A call in any other state will cause an error code of KErrNotReady to be returned.

During this call the stream will query all attached processing units whether they are ready to unload. if a processing unit indicates that it is not ready to uninitialize, then an error code other than KErrNone will be returned. Provided that this call succeeds, the actual unloading process will begins once Commit() is called for the context of this stream.

UnregisterAudioStreamObserver(MAudioStreamObserver &)

voidUnregisterAudioStreamObserver(MAudioStreamObserver &aObserver)[pure virtual]

Unregisters an audio stream observer.

Parameters

MAudioStreamObserver & aObserverreference to the observer to unregister.