[AN-765] Support for runtime Audio Usage Switching for HiFi Audio Playback in Android#63
Merged
aleksandar-apostolov merged 9 commits intopatch/m137.5from Oct 29, 2025
Merged
Conversation
…ult of bufferSizeFactor = 1.0 while switching b/w mono and stereo
…safe method initPlayoutThreadSafe which does not have any thread checking logic
…safe method initPlayoutThreadSafe which does not have any thread checking logic
…restarted with the new configuration.
…ioAttribute to be updated.
…io Attribute when it is changed from the app
aleksandar-apostolov
approved these changes
Oct 29, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
checkThreadboolean toinitPlayout,startPlayout, andstopPlayoutmethods so they can run from app threadsAutomatically 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.