-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[video_player] Optimize caption retrieval with binary search in VideoPlayerController #8347
Open
abdelaziz-mahdy
wants to merge
13
commits into
flutter:main
Choose a base branch
from
abdelaziz-mahdy:binary-search-captions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+141
−26
Open
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a67e5ef
Optimize caption retrieval with binary search in VideoPlayerController
abdelaziz-mahdy 106f838
Update Change Log
abdelaziz-mahdy 44aefb8
Refactor: Optimize caption lookup using binary search with `package:c…
abdelaziz-mahdy 08f21d9
Refactor: Enhance closed caption retrieval using binary search from `…
abdelaziz-mahdy be6ba80
Merge branch 'main' into binary-search-captions
abdelaziz-mahdy 246ee3f
Bump version to 2.9.3
abdelaziz-mahdy 1fd8e70
Merge branch 'binary-search-captions' of https://github.com/zezo357/p…
abdelaziz-mahdy 2142659
test: Enhance closed caption tests for sorting and seeking behavior
abdelaziz-mahdy 5e9ace9
feat: Add sortedCaptions getter to VideoPlayerController
abdelaziz-mahdy b74b352
fix: Correct binary search logic for caption retrieval and update tes…
abdelaziz-mahdy cedd1a4
adding more captions checks
abdelaziz-mahdy 9a23e47
refactor: Remove sortedCaptions getter and related test.
abdelaziz-mahdy 57260cb
test: Add test to verify input captions are unsorted
abdelaziz-mahdy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
Why is new public API needed? I don't see any implementation code using this.
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.
To be able to access that list in testing, as I mentioned in the last comment I couldn't make it private and available for testing,
If the test is not needed I can remove it with the test
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 removed it and the test.
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.
If something needs to be visible only for testing, it should be annotated
@visibleForTesting
.It's not clear to me why even that would be necessary though; API to get the current caption is already public, and I would expect that it should be straightforward to construct a case where getting the caption for some time would be incorrect unless the captions are sorted internally.
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.
its only a getter so calling sort on it doesnt sort the original list, this is why i copied the list and sorted it and the public method was for the testing part only, if the test is not needed the public method is not needed
but
_sortedCaptions
is neededThere 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'm not sure what part of my comments led you to believe I don't understand
_sortedCaptions
. My comment is about the new public API.I still don't understand why you are presenting a binary choice between adding new public API and having testing. Whether or not the correct caption is fetched for a given time is already an observable property with existing public API. You should be able to construct a case where, with binary search, the wrong caption is reported without the internal sorting step, and thus validate that it is being handled correctly without directly inspecting internal state via new public accessors.
Testing internal implementation details is an anti-pattern, and should only be done when the important properties cannot be tested via the actual client APIs. I have not seen any argument for why that would not be the case here. What scenario are you unable to test without adding a new public API?
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 didnt mean all the testing of the testing is ignored, just this test
captions are sorted correctly on initialization
since it requires the expose of the public interface so i can check if they are sorted correctlyList<Caption>? get sortedCaptions
without it i cant get the sorted list and without the sorted list i cant make that testbut i did add test cases for not sorted captions and tested retrieving them which works correctly and if the sorting is removed they wont pass
so i think those are enough, and no need to introduce the public interface since all of the cases are covered as you mentioned
and i did remove the public method.
edit: i am sorry if my english is not clear enough since its not my first language,
but in the end the public method is not needed since the other tests already covered the sorting checks