AudioGroup


public class AudioGroup
extends Object

java.lang.Object
   ↳ android.net.rtp.AudioGroup


This class was deprecated in API level 31.
SipManager and associated classes are no longer supported and should not be used as the basis of future VOIP apps.

An AudioGroup is an audio hub for the speaker, the microphone, and AudioStreams. Each of these components can be logically turned on or off by calling setMode(int) or RtpStream#setMode(int). The AudioGroup will go through these components and process them one by one within its execution loop. The loop consists of four steps. First, for each AudioStream not in RtpStream#MODE_SEND_ONLY, decodes its incoming packets and stores in its buffer. Then, if the microphone is enabled, processes the recorded audio and stores in its buffer. Third, if the speaker is enabled, mixes all AudioStream buffers and plays back. Finally, for each AudioStream not in RtpStream#MODE_RECEIVE_ONLY, mixes all other buffers and sends back the encoded packets. An AudioGroup does nothing if there is no AudioStream in it.

Few things must be noticed before using these classes. The performance is highly related to the system load and the network bandwidth. Usually a simpler AudioCodec costs fewer CPU cycles but requires more network bandwidth, and vise versa. Using two AudioStreams at the same time doubles not only the load but also the bandwidth. The condition varies from one device to another, and developers should choose the right combination in order to get the best result.

It is sometimes useful to keep multiple AudioGroups at the same time. For example, a Voice over IP (VoIP) application might want to put a conference call on hold in order to make a new call but still allow people in the conference call talking to each other. This can be done easily using two AudioGroups, but there are some limitations. Since the speaker and the microphone are globally shared resources, only one AudioGroup at a time is allowed to run in a mode other than MODE_ON_HOLD. The others will be unable to acquire these resources and fail silently.

Using this class requires Manifest.permission.RECORD_AUDIO permission. Developers should set the audio mode to AudioManager#MODE_IN_COMMUNICATION using AudioManager#setMode(int) and change it back when none of the AudioGroups is in use.

See also:

Summary

Constants

int MODE_ECHO_SUPPRESSION

This mode is similar to MODE_NORMAL except the echo suppression is enabled.

int MODE_MUTED

This mode is similar to MODE_NORMAL except the microphone is disabled.

int MODE_NORMAL

This mode indicates that the speaker, the microphone, and all AudioStreams in the group are enabled.

int MODE_ON_HOLD

This mode is similar to MODE_NORMAL except the speaker and the microphone are both disabled.

Public constructors

AudioGroup()

This constructor is deprecated. Replaced by AudioGroup(android.content.Context)

AudioGroup(Context context)

Creates an empty AudioGroup.

Public methods

void clear()

Removes every AudioStream in this group.

int getMode()

Returns the current mode.

AudioStream[] getStreams()

Returns the AudioStreams in this group.

void sendDtmf(int event)

Sends a DTMF digit to every AudioStream in this group.

void setMode(int mode)

Changes the current mode.

Protected methods

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

Inherited methods

Constants

MODE_ECHO_SUPPRESSION

Added in API level 12
public static final int MODE_ECHO_SUPPRESSION

This mode is similar to MODE_NORMAL except the echo suppression is enabled. It should be only used when the speaker phone is on.

Constant Value: 3 (0x00000003)

MODE_MUTED

Added in API level 12
public static final int MODE_MUTED

This mode is similar to MODE_NORMAL except the microphone is disabled.

Constant Value: 1 (0x00000001)

MODE_NORMAL

Added in API level 12
public static final int MODE_NORMAL

This mode indicates that the speaker, the microphone, and all AudioStreams in the group are enabled. First, the packets received from the streams are decoded and mixed with the audio recorded from the microphone. Then, the results are played back to the speaker, encoded and sent back to each stream.

Constant Value: 2 (0x00000002)

MODE_ON_HOLD

Added in API level 12
public static final int MODE_ON_HOLD

This mode is similar to MODE_NORMAL except the speaker and the microphone are both disabled.

Constant Value: 0 (0x00000000)

Public constructors

AudioGroup

Added in API level 12
public AudioGroup ()

This constructor is deprecated.
Replaced by AudioGroup(android.content.Context)

Creates an empty AudioGroup.

AudioGroup

Added in API level 30
public AudioGroup (Context context)

Creates an empty AudioGroup.

Parameters
context Context: Context the group belongs to This value cannot be null.

Public methods

clear

Added in API level 12
public void clear ()

Removes every AudioStream in this group.

getMode

Added in API level 12
public int getMode ()

Returns the current mode.

Returns
int

getStreams

Added in API level 12
public AudioStream[] getStreams ()

Returns the AudioStreams in this group.

Returns
AudioStream[]

sendDtmf

Added in API level 12
public void sendDtmf (int event)

Sends a DTMF digit to every AudioStream in this group. Currently only event 0 to 15 are supported.

Parameters
event int

Throws
IllegalArgumentException if the event is invalid.

setMode

Added in API level 12
public void setMode (int mode)

Changes the current mode. It must be one of MODE_ON_HOLD, MODE_MUTED, MODE_NORMAL, and MODE_ECHO_SUPPRESSION.

Parameters
mode int: The mode to change to.

Throws
IllegalArgumentException if the mode is invalid.

Protected methods

finalize

Added in API level 12
protected void finalize ()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Throws
Throwable