[AN-765] Support for runtime Audio Usage Switching for HiFi Audio Playback in Android #63
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.