Added in API level 35

LoudnessCodecController


open class LoudnessCodecController : AutoCloseable
kotlin.Any
   ↳ 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
abstract

Listener used for receiving asynchronous loudness metadata updates.

Public methods
open Boolean

Adds a new MediaCodec that will stream data to a player which uses #mSessionId.

open Unit

Stops any loudness updates and frees up the resources.

open static LoudnessCodecController
create(sessionId: Int)

Creates a new instance of LoudnessCodecController

open static LoudnessCodecController

Creates a new instance of LoudnessCodecController

open Bundle

Returns the loudness parameters of the registered audio decoders

open Unit

Removes the MediaCodec from receiving loudness updates.

Public methods

addMediaCodec

Added in API level 35
open fun addMediaCodec(mediaCodec: MediaCodec): Boolean

Adds a new MediaCodec that will stream data to a player which uses #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.
Return
Boolean false if the mediaCodec was not configured or does not contain loudness metadata, true otherwise.
Exceptions
java.lang.IllegalArgumentException if the same mediaCodec was already added before.

close

Added in API level 35
open fun close(): Unit

Stops any loudness updates and frees up the resources.

Exceptions
java.lang.Exception if this resource cannot be closed

create

Added in API level 35
open static fun create(sessionId: Int): LoudnessCodecController

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
Return
LoudnessCodecController the LoudnessCodecController instance

create

Added in API level 35
open static fun create(
    sessionId: Int,
    executor: Executor,
    listener: LoudnessCodecController.OnLoudnessCodecUpdateListener
): LoudnessCodecController

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
Return
LoudnessCodecController the LoudnessCodecController instance

getLoudnessCodecParams

Added in API level 35
open fun getLoudnessCodecParams(mediaCodec: MediaCodec): Bundle

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
Return
Bundle the Bundle containing the current loudness parameters.
Exceptions
java.lang.IllegalArgumentException if the passed MediaCodec was not added before calling this method

removeMediaCodec

Added in API level 35
open fun removeMediaCodec(mediaCodec: MediaCodec): Unit

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
Exceptions
java.lang.IllegalArgumentException if the mediaCodec was not configured, does not contain loudness metadata or if it was not added before