Skip to content

Commit 5d34573

Browse files
[video_player] Fix crash when videoTrack has zero-duration minFrameDuration (flutter#12796)
Fixes a crash on iOS caused by a zero-duration frame duration. When creating the `AVMutableVideoComposition` a check is made against `CMTIME_IS_VALID` but this doesn't guard against a frame duration of 0. I just added one more check to make sure the frame duration is > 0. Part of flutter#151031 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent cedf32b commit 5d34573

6 files changed

Lines changed: 37 additions & 3 deletions

File tree

‎packages/video_player/video_player_avfoundation/CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 2.12.1
22

3+
* Fixes a crash when a video track reports a zero `minFrameDuration`.
34
* Updates minimum supported SDK version to Flutter 3.41/Dart 3.11.
45

56
## 2.12.0

‎packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.swift‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,32 @@ private let hlsAudioTestURI =
10161016
player.disposeWithError(&error)
10171017
}
10181018

1019+
@Test func validFrameDurationWithPositiveTime() {
1020+
let duration = CMTimeMake(value: 1, timescale: 30)
1021+
#expect(FVPFrameDurationIsValid(duration))
1022+
}
1023+
1024+
@Test func validFrameDurationWithZeroTime() {
1025+
#expect(!FVPFrameDurationIsValid(CMTime.zero))
1026+
}
1027+
1028+
@Test func validFrameDurationWithInvalidTime() {
1029+
#expect(!FVPFrameDurationIsValid(CMTime.invalid))
1030+
}
1031+
1032+
@Test func validFrameDurationWithNegativeTime() {
1033+
let duration = CMTimeMake(value: -1, timescale: 30)
1034+
#expect(!FVPFrameDurationIsValid(duration))
1035+
}
1036+
1037+
@Test func validFrameDurationWithPositiveInfinity() {
1038+
#expect(!FVPFrameDurationIsValid(CMTime.positiveInfinity))
1039+
}
1040+
1041+
@Test func validFrameDurationWithIndefinite() {
1042+
#expect(!FVPFrameDurationIsValid(CMTime.indefinite))
1043+
}
1044+
10191045
// MARK: - Helper Methods
10201046

10211047
/// Creates a plugin with the given dependencies, and default stubs for any that aren't provided,

‎packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation_objc/AVAssetTrackUtils.m‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ CGAffineTransform FVPGetStandardizedTrackTransform(CGAffineTransform t, CGSize s
4242
}
4343
return t;
4444
}
45+
46+
BOOL FVPFrameDurationIsValid(CMTime frameDuration) {
47+
return CMTIME_IS_NUMERIC(frameDuration) && CMTimeCompare(frameDuration, kCMTimeZero) > 0;
48+
}

‎packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation_objc/FVPVideoPlayer.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ - (AVMutableVideoComposition *)videoCompositionWithTransform:(CGAffineTransform)
286286
videoComposition.renderSize = CGSizeMake(width, height);
287287

288288
videoComposition.sourceTrackIDForFrameTiming = videoTrack.trackID;
289-
if (CMTIME_IS_VALID(videoTrack.minFrameDuration)) {
289+
if (FVPFrameDurationIsValid(videoTrack.minFrameDuration)) {
290290
videoComposition.frameDuration = videoTrack.minFrameDuration;
291291
} else {
292292
NSLog(@"Warning: videoTrack.minFrameDuration for input video is invalid, please report this to "

‎packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation_objc/include/video_player_avfoundation_objc/AVAssetTrackUtils.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
/// Note: https://stackoverflow.com/questions/64161544
1111
/// `AVAssetTrack.preferredTransform` can have wrong `tx` and `ty`.
1212
CGAffineTransform FVPGetStandardizedTrackTransform(CGAffineTransform t, CGSize size);
13+
14+
/// Returns true if the given CMTime is valid and strictly positive.
15+
BOOL FVPFrameDurationIsValid(CMTime frameDuration);

‎packages/video_player/video_player_avfoundation/pubspec.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player_avfoundation
22
description: iOS and macOS implementation of the video_player plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_avfoundation
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
5-
version: 2.12.0
5+
version: 2.12.1
66

77
environment:
88
sdk: ^3.11.0

0 commit comments

Comments
 (0)