-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Added Automatic Adaptive Bitrate Streaming(ABR) in Android and iOS #10908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
|
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces automatic adaptive bitrate (ABR) streaming support for HLS/DASH in Android and iOS video players. It includes core changes to manage bandwidth limits, platform-specific implementations for Android (ExoPlayer) and iOS (AVFoundation), and updates to the video_player plugin. The changes involve adding a new AdaptiveBitrateManager class, modifying platform-specific code to support ABR, and updating the Pigeon messaging interface. I have provided comments to address potential issues and improve the code.
| MediaSource.Factory getMediaSourceFactory( | ||
| Context context, DefaultHttpDataSource.Factory initialFactory) { | ||
| unstableUpdateDataSourceFactory(initialFactory, httpHeaders, userAgent); | ||
| unstableUpdateDataSourceFactory(initialFactory, httpHeaders, userAgent, assetUrl, streamingFormat); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * @deprecated This method DISABLES adaptive bitrate streaming. Do not use. | ||
| * ExoPlayer's adaptive streaming is now enabled by default in the player creation. | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // ExoPlayer handles HLS adaptive bitrate resolution changes automatically. | ||
| // No need to recreate the surface - doing so causes frame misalignment issues. | ||
| // The MediaCodec decoder will seamlessly adapt to the new resolution. | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good that you're preventing surface recreation during resolution changes, but it's important to verify that the TextureView is indeed adapting correctly to the new dimensions. Consider adding a check or a log to confirm the TextureView's dimensions are updated after an adaptive streaming quality change.
| .setAllowVideoNonSeamlessAdaptiveness(true) // Allow quality switches even with brief buffering | ||
| .setAllowVideoMixedMimeTypeAdaptiveness(false) // Keep same codec for stability | ||
| .setAllowVideoMixedDecoderSupportAdaptiveness(true) // Allow decoder adaptiveness |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| @OptIn(markerClass = androidx.media3.common.util.UnstableApi.class) | ||
| @Override | ||
| public void onVideoSizeChanged(@NonNull VideoSize videoSize) { | ||
| android.util.Log.d("TextureListener", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good that you're preventing re-initialization during resolution changes, but it's important to verify that the TextureView is indeed adapting correctly to the new dimensions. Consider adding a check or a log to confirm the TextureView's dimensions are updated after an adaptive streaming quality change.
6ae312a to
926d1f1
Compare
|
Thanks for the contribution! You’ve checked boxes in the PR checklist above that are not reflected in this PR, so I’m assuming this is a work in progress and am marking it as a Draft. Please review the checklist, updating the PR as appropriate, and when the state of the PR as posted reflects the checklist please feel free to mark it as ready for review. |
|
This will also need a design document before the code is reviewed, to get a review of the high-level approach. For instance, it appears that this is implementing some heuristic logic at the Dart level that's not part of any of the underlying players, and that will need design exploration to evaluate whether the plugin is the right place for logic that none of the underlying players provide. |
feat: Add Automatic Adaptive Bitrate (ABR) support for HLS/DASH streaming in Android and iOS.
Introduces a built-in AdaptiveBitrateManager to the core video_player package
and implements native support for Android and iOS. This allows the player
to dynamically switch video quality based on network conditions and
buffering events.
Key changes:
AdaptiveBitrateManagerto monitor buffering events andautomatically adjust bandwidth limits.
setBandwidthLimit(int bps)inVideoPlayerControllerto allow manual or automated quality capping.
PlatformVideoViewfromSurfaceViewtoTextureViewto handle seamless resolution switching during adaptive transitions
without frame misalignment or surface recreation.
DefaultTrackSelectorwithsetMaxVideoBitrateto enforce bandwidth constraints in ExoPlayer.
ExoPlayerEventListenerto trackand report adaptive quality changes (e.g., 360p -> 1080p).
preferredPeakBitRatein AVFoundation to supportnative ABR constraints.
For Reference - https://github.com/user-attachments/assets/b271adb2-7942-4b98-8234-fbbbbae6b850
HLS used - https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the [pub versioning philosophy], or I have commented below to indicate which [version change exemption] this PR falls under[^1].CHANGELOG.mdto add a description of the change, [following repository CHANGELOG style], or I have commented below to indicate which [CHANGELOG exemption] this PR falls under[^1].///).