-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[video_player] Fixes a bug where the aspect ratio of some HLS videos are incorrectly inverted #6507
[video_player] Fixes a bug where the aspect ratio of some HLS videos are incorrectly inverted #6507
Conversation
// TODO: (hellohuanlin) Provide a non-deprecated codepath. See | ||
// https://github.com/flutter/flutter/issues/104117 | ||
return UIApplication.sharedApplication.keyWindow.rootViewController; | ||
#pragma clang diagnostic pop |
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.
I simply copied the code from another plugin. Fixing it is not the scope of this PR (tho I'm happy to help if needed).
679b2ee
to
8422c89
Compare
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.
I think this needs a test to validate the presentationSize
is correct, if that's possible to check.
@@ -66,12 +68,11 @@ @interface VideoPlayerTests : XCTestCase | |||
@implementation VideoPlayerTests | |||
|
|||
- (void)testIOS16BugWithEncryptedVideoStream { |
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.
Rename test.
// This is to fix 2 bugs: 1. blank video for encrypted video streams on iOS 16 | ||
// (https://github.com/flutter/flutter/issues/111457) and 2. swapped width and height for some video | ||
// streams (not just iOS 16). (https://github.com/flutter/flutter/issues/109116). | ||
// An invisible AVPlayerLayer is used to overwrite the protection of pixel buffers in those streams | ||
// for issue #1, and restore the correct width and height for issue #2. |
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.
I don't think we need this comment twice.
// This is to fix 2 bugs: 1. blank video for encrypted video streams on iOS 16 | |
// (https://github.com/flutter/flutter/issues/111457) and 2. swapped width and height for some video | |
// streams (not just iOS 16). (https://github.com/flutter/flutter/issues/109116). | |
// An invisible AVPlayerLayer is used to overwrite the protection of pixel buffers in those streams | |
// for issue #1, and restore the correct width and height for issue #2. |
It turned out that validating I plan to dig deeper, but given the P2 priority, let's land it for now and revisit afterwards? WDYT? @jmagman |
Checking the frames seemed flaky. I wouldn't have thought checking the width and height of the view would be flaky, since our tests that check the closed captioning isn't flaky. How were you testing it? |
@jmagman I was referring to the flakiness of the integration test for the iOS 16 bug (previous PR), which is tracked here: flutter/flutter#112562 For this particular one, I am thinking about taking a screenshot and then scanning through pixels to determine the frame of the video area. (if i understand it correctly, since we are not using platform view, the video frames are simply drawn on the full-screen UIView just like any other widgets) |
@jmagman Oh to clarify, I haven't tried out integration tests for this one. I was worrying it's taking longer time since it's P2. But if time permits, I can try integration test before Landing it. |
We shouldn't land anything without proper tests, even P2s 🙂
That's what I'm referring to as well.
Scanning through pixels and taking screenshots was what was extremely flaky. I'm suggesting something more simple to just check the width and height of the video. For example, using the video from the issue (note we shouldn't use that video, we should have our own that reproduces, though I wasn't able to get any of our test videos to repro), this fails on master on an iOS 14 simulator, but passes on this PR: testWidgets('m3u8 has correct aspect ratio', (WidgetTester tester) async {
final MiniController livestreamController = MiniController.network(
'https://videodelivery.net/11a75f7cf7314f5a880d49fb8bebaaed/manifest/video.m3u8',
);
await livestreamController.initialize();
expect(livestreamController.value.isInitialized, true);
expect(livestreamController.value.size.width, lessThan(livestreamController.value.size.height));
}); to be added around here: Line 168 in b82bb69
|
@jmagman Ah I didn't realize we have tests on the dart side! Was thinking about xcuitests. Let me try tomorrow. |
8422c89
to
f30a7b1
Compare
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.
LGTM
…LS videos are incorrectly inverted (flutter/plugins#6507)
…are incorrectly inverted (flutter#6507)
…are incorrectly inverted (flutter#6507)
The issue is that
item.presentationSize
returns the swapped width and height for some video streams (likely due to transform).I did lots of research and wasn't able to find any workaround online. Then I thought that each segment of the HLS may have different resolution (e.g. different internet speed), so AVFoundation must be adjusting the
presentationSize
continuously. Fixing aspect ratio could also be part of that adjustment. So I used the same trick as the previous PR to leverage AVPlayerLayer to do the heavy lifting work for us.Just like the previous PR, we can also leverage AVPlayerLayer to do the heavy lifting work for us. And it worked :)
(If it weren't for the previous iOS 16 bug, I probably wouldn't be able to come up with this solution).
About the deprecated
keyWindow.rootViewController
I simply copied the code from another plugin. Fixing it is not the scope of this PR (tho I'm happy to help if needed).
List which issues are fixed by this PR. You must list at least one issue.
Fixes flutter/flutter#109116
If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.