Skip to content

Conversation

@PratimMallick
Copy link
Contributor

@PratimMallick PratimMallick commented Oct 29, 2025

Summary

Enables switching audio usage (voice vs media) at runtime on Android to support HiFi audio without reinitializing the entire AudioDeviceModule.

Changes

1. WebRtcAudioTrack.java
Add updateAudioTrackUsage() to update AudioAttributes at runtime
Cache sample rate, channels, and buffer size to support reinitialization
Introduce checkThread boolean to initPlayout, startPlayout, and stopPlayout methods so they can run from app threads
Automatically stop/restart playout during updates

2. JavaAudioDeviceModule.java
Expose updateAudioTrackUsage() that delegates to WebRtcAudioTrack

3. audio_track_jni.cc
Update JNI to pass checkThread=true for native path calls

Use Case

Support dynamic switching between voice communication (USAGE_VOICE_COMMUNICATION) and media playback (USAGE_MEDIA) for HiFi audio. The ADM stays stereo while only AudioAttributes change.

Behavior

If playout is active, it stops and restarts with the new attributes. No reinitialization of the ADM is required.

@PratimMallick PratimMallick changed the title [AN-765] Support for changing between mono and stereo audio playback [AN-765] Support for runtime Audio Usage Switching for HiFi Audio Playback Oct 29, 2025
@aleksandar-apostolov aleksandar-apostolov merged commit c867861 into patch/m137.5 Oct 29, 2025
@aleksandar-apostolov aleksandar-apostolov deleted the patch/m137.5_hifi_audio branch October 29, 2025 10:47
@PratimMallick PratimMallick changed the title [AN-765] Support for runtime Audio Usage Switching for HiFi Audio Playback [AN-765] Support for runtime Audio Usage Switching for HiFi Audio Playback in Android Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants