Skip to content

Commit

Permalink
CrashTracer: com.apple.WebKit.GPU at AVFCore: -[AVPlayerItem _seekToT…
Browse files Browse the repository at this point in the history
…ime:toleranceBefore:toleranceAfter:seekID:completionHandler:]

https://bugs.webkit.org/show_bug.cgi?id=243068
<rdar://95237949>

Reviewed by Jer Noble.

AVPlayerItem throws an exception when an invalid or negative tolerance value
is passed to the -seekToTime: method. If we run into a bad tolerance value,
we can just ignore the tolerance by setting it to positive infinity.

From the AVF documentation: (https://developer.apple.com/documentation/avfoundation/avplayer/1388493-seektotime)
Invoking this method with toleranceBefore set to kCMTimePositiveInfinity
and toleranceAfter set to kCMTimePositiveInfinity is the same as invoking seekToTime:.

* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::seekTask):
* Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::seekToTime):

Canonical link: https://commits.webkit.org/252714@main
  • Loading branch information
youssefsoli committed Jul 21, 2022
1 parent afacf71 commit cfafcba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Source/WebCore/html/HTMLMediaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3228,7 +3228,10 @@ void HTMLMediaElement::seekTask()
MediaTime positiveTolerance = m_pendingSeek->positiveTolerance;
m_pendingSeek = nullptr;

ASSERT(negativeTolerance.isValid());
ASSERT(negativeTolerance >= MediaTime::zeroTime());
ASSERT(positiveTolerance.isValid());
ASSERT(positiveTolerance >= MediaTime::zeroTime());

// 6 - If the new playback position is later than the end of the media resource, then let it be the end
// of the media resource instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,8 @@ static URL conformFragmentIdentifierForURL(const URL& url)

void MediaPlayerPrivateAVFoundationObjC::seekToTime(const MediaTime& time, const MediaTime& negativeTolerance, const MediaTime& positiveTolerance)
{
ASSERT(time.isFinite());

// setCurrentTime generates several event callbacks, update afterwards.
setDelayCallbacks(true);

Expand All @@ -1567,9 +1569,11 @@ static URL conformFragmentIdentifierForURL(const URL& url)
CMTime cmBefore = PAL::toCMTime(negativeTolerance);
CMTime cmAfter = PAL::toCMTime(positiveTolerance);

// [AVPlayerItem seekToTime] will throw an exception if toleranceBefore is negative.
if (PAL::CMTimeCompare(cmBefore, PAL::kCMTimeZero) < 0)
cmBefore = PAL::kCMTimeZero;
// [AVPlayerItem seekToTime] will throw an exception if a tolerance is invalid or negative.
if (!CMTIME_IS_VALID(cmBefore) || PAL::CMTimeCompare(cmBefore, PAL::kCMTimeZero) < 0)
cmBefore = PAL::kCMTimePositiveInfinity;
if (!CMTIME_IS_VALID(cmAfter) || PAL::CMTimeCompare(cmAfter, PAL::kCMTimeZero) < 0)
cmAfter = PAL::kCMTimePositiveInfinity;

WeakPtr weakThis { *this };

Expand Down

0 comments on commit cfafcba

Please sign in to comment.