Add AdaptiveTrackSelection format priority ordering hooks#3064
Add AdaptiveTrackSelection format priority ordering hooks#3064AndyWangLYN wants to merge 2 commits intoandroidx:releasefrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
...exoplayer/src/main/java/androidx/media3/exoplayer/trackselection/AdaptiveTrackSelection.java
Outdated
Show resolved
Hide resolved
...exoplayer/src/main/java/androidx/media3/exoplayer/trackselection/AdaptiveTrackSelection.java
Show resolved
Hide resolved
...exoplayer/src/main/java/androidx/media3/exoplayer/trackselection/AdaptiveTrackSelection.java
Outdated
Show resolved
Hide resolved
Do you have an concrete example where this logic applies? If there is a format with a higher bitrate and a lower quality, I don't see a case where it would ever be beneficial to select that format. If that's the case, a better approach to solve your underlying issue may be to ensure that format is never part of the ABR selection ladder to start with. Example:
The concept of bitrate ordering is quite deeply engrained into the |
|
Hey @tonihei thank you for reviewing and commenting on my PR. This is an ABR customization issue I've encountered where server-side pruning isn't feasible because the 'best' track is device-dependent. For example, in a mixed-codec manifest, a more efficient codec can provide higher quality at a lower bitrate. Furthermore, on devices without hardware AV1 decoding, a high-bitrate AV1 rendition may cause stuttering compared to a lower-bitrate AVC rendition. |
- Keep fallback index tied to bitrate order instead of priority traversal order - Use bitmask validation for <=64 tracks to reduce allocation - Add tests for null and invalid custom priority order fallback
|
Based on the comment above, opened a new PR: #3068 to better address the track format sorting from the base level. Intend to close this PR once that one is deemed good. |
|
Let's move the conversation to this PR: #3068 in which I propose a better and more robost way to sort format tracks. Thank you! @tonihei @oceanjules |
Summary
This change adds extension points to AdaptiveTrackSelection so apps can control candidate format priority beyond default bitrate ordering, while preserving existing ABR behavior by default.
What Changed
Added getFormatPriorityOrder(...) hook to let developers provide an explicit per-update format priority list.
Added getFormatIndexForPriorityPosition(...) hook (default bitrate-descending behavior) for position-based custom ordering.
Updated ideal-index selection to use custom priority when provided.
Kept default behavior unchanged when hooks are not overridden.
Added validation/fallback behavior for invalid custom priority order:
invalid order is ignored with a warning
selection falls back to default ordering
Added unit coverage in AdaptiveTrackSelectionTest proving a custom priority order can be applied.
Why
Current adaptive selection effectively prioritizes higher bitrate first. This makes it hard to prioritize developer-defined rules (for example, quality score ranking). These hooks allow custom ordering without changing core ABR switching logic.
Compatibility
No behavior change for existing users.
No API break for default usage.
Buffer-based switch-up/switch-down logic remains unchanged.
Testing
Ran:
gradlew :lib-exoplayer:testDebugUnitTest --tests androidx.media3.exoplayer.trackselection.AdaptiveTrackSelectionTest
Result: BUILD SUCCESSFUL