LoudnessCodecController


public class LoudnessCodecController
extends Object implements AutoCloseable

java.lang.Object
   ↳ android.media.LoudnessCodecController


Class for getting recommended loudness parameter updates for audio decoders as they are used to play back media content according to the encoded format and current audio routing. These audio decoder updates leverage loudness metadata present in compressed audio streams. They ensure the loudness and dynamic range of the content is optimized to the physical characteristics of the audio output device (e.g. phone microspeakers vs headphones vs TV speakers).Those updates can be automatically applied to the MediaCodec instance(s), or be provided to the user. The codec loudness management parameter updates are computed in accordance to the CTA-2075 standard.

A new object should be instantiated for each audio session (see AudioManager#generateAudioSessionId()) using creator methods create(int) or create(int, java.util.concurrent.Executor, android.media.LoudnessCodecController.OnLoudnessCodecUpdateListener).

Summary

Nested classes

interface LoudnessCodecController.OnLoudnessCodecUpdateListener

Listener used for receiving asynchronous loudness metadata updates. 

Public methods

boolean addMediaCodec(MediaCodec mediaCodec)

Adds a new MediaCodec that will stream data to a player which uses ERROR(/#mSessionId).

void close()

Stops any loudness updates and frees up the resources.

static LoudnessCodecController create(int sessionId, Executor executor, LoudnessCodecController.OnLoudnessCodecUpdateListener listener)

Creates a new instance of LoudnessCodecController

This method should be used when the client wants to alter the codec loudness parameters before they are applied to the audio decoders.

static LoudnessCodecController create(int sessionId)

Creates a new instance of LoudnessCodecController

This method should be used when the client does not need to alter the codec loudness parameters before they are applied to the audio decoders.

Bundle getLoudnessCodecParams(MediaCodec mediaCodec)

Returns the loudness parameters of the registered audio decoders

Those parameters may have been automatically applied if the LoudnessCodecController was created with create(int), or they are the parameters that have been sent to the OnLoudnessCodecUpdateListener if using a codec update listener.

void removeMediaCodec(MediaCodec mediaCodec)

Removes the MediaCodec from receiving loudness updates.

Inherited methods

Public methods

addMediaCodec

public boolean addMediaCodec (MediaCodec mediaCodec)

Adds a new MediaCodec that will stream data to a player which uses ERROR(/#mSessionId).

No new element will be added if the passed mediaCodec was previously added.

Parameters
mediaCodec MediaCodec: the codec to start receiving asynchronous loudness updates. The codec has to be in a configured or started state in order to add it for loudness updates.

Returns
boolean false if the mediaCodec was not configured or does not contain loudness metadata, true otherwise.

Throws
IllegalArgumentException if the same mediaCodec was already added before.

close

public void close ()

Stops any loudness updates and frees up the resources.

create

public static LoudnessCodecController create (int sessionId, 
                Executor executor, 
                LoudnessCodecController.OnLoudnessCodecUpdateListener listener)

Creates a new instance of LoudnessCodecController

This method should be used when the client wants to alter the codec loudness parameters before they are applied to the audio decoders. Otherwise, use create(int).

Parameters
sessionId int: the session ID of the track that will receive data from the added MediaCodec's

executor Executor: Executor to handle the callbacks Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.

listener LoudnessCodecController.OnLoudnessCodecUpdateListener: used for receiving updates

Returns
LoudnessCodecController the LoudnessCodecController instance

create

public static LoudnessCodecController create (int sessionId)

Creates a new instance of LoudnessCodecController

This method should be used when the client does not need to alter the codec loudness parameters before they are applied to the audio decoders. Otherwise, use create(int, java.util.concurrent.Executor, android.media.LoudnessCodecController.OnLoudnessCodecUpdateListener).

Parameters
sessionId int: the session ID of the track that will receive data from the added MediaCodec's

Returns
LoudnessCodecController the LoudnessCodecController instance

getLoudnessCodecParams

public Bundle getLoudnessCodecParams (MediaCodec mediaCodec)

Returns the loudness parameters of the registered audio decoders

Those parameters may have been automatically applied if the LoudnessCodecController was created with create(int), or they are the parameters that have been sent to the OnLoudnessCodecUpdateListener if using a codec update listener.

Parameters
mediaCodec MediaCodec: codec that decodes loudness annotated data. Has to be added with addMediaCodec(android.media.MediaCodec) before calling this method

Returns
Bundle the Bundle containing the current loudness parameters.

Throws
IllegalArgumentException if the passed MediaCodec was not added before calling this method

removeMediaCodec

public void removeMediaCodec (MediaCodec mediaCodec)

Removes the MediaCodec from receiving loudness updates.

This method can be called while asynchronous updates are live.

No elements will be removed if the passed mediaCodec was not added before.

Parameters
mediaCodec MediaCodec: the element to remove for receiving asynchronous updates

Throws
IllegalArgumentException if the mediaCodec was not configured, does not contain loudness metadata or if it was not added before