Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[macOS] AirPlay sometimes fails at Vimeo.com
https://bugs.webkit.org/show_bug.cgi?id=256099
rdar://108326570

Reviewed by Jer Noble.

Use a timer to schedule media engine AirPlay compatibility.

* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement):
(WebCore::HTMLMediaElement::checkPlaybackTargetCompatibility):
(WebCore::HTMLMediaElement::stopPeriodicTimers):
(WebCore::HTMLMediaElement::cancelPendingTasks):
(WebCore::HTMLMediaElement::setIsPlayingToWirelessTarget):
(WebCore::HTMLMediaElement::scheduleCheckPlaybackTargetCompatability): Deleted.
* Source/WebCore/html/HTMLMediaElement.h:

Canonical link: https://commits.webkit.org/263534@main
  • Loading branch information
eric-carlson committed Apr 29, 2023
1 parent 22a3280 commit aa760bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
26 changes: 4 additions & 22 deletions Source/WebCore/html/HTMLMediaElement.cpp
Expand Up @@ -437,6 +437,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum
, m_scanTimer(*this, &HTMLMediaElement::scanTimerFired)
, m_playbackControlsManagerBehaviorRestrictionsTimer(*this, &HTMLMediaElement::playbackControlsManagerBehaviorRestrictionsTimerFired)
, m_seekToPlaybackPositionEndedTimer(*this, &HTMLMediaElement::seekToPlaybackPositionEndedTimerFired)
, m_checkPlaybackTargetCompatibilityTimer(*this, &HTMLMediaElement::checkPlaybackTargetCompatibility)
, m_currentIdentifier(MediaUniqueIdentifier::generate())
, m_lastTimeUpdateEventMovieTime(MediaTime::positiveInfiniteTime())
, m_firstTimePlaying(true)
Expand Down Expand Up @@ -1053,38 +1054,20 @@ bool HTMLMediaElement::hasEverNotifiedAboutPlaying() const
return m_hasEverNotifiedAboutPlaying;
}

void HTMLMediaElement::scheduleCheckPlaybackTargetCompatability()
{
if (m_checkPlaybackTargetCompatibilityTaskCancellationGroup.hasPendingTask())
return;

ALWAYS_LOG(LOGIDENTIFIER);
queueCancellableTaskKeepingObjectAlive(*this, TaskSource::MediaElement, m_checkPlaybackTargetCompatibilityTaskCancellationGroup, [this] {
checkPlaybackTargetCompatibility();
});
}

void HTMLMediaElement::checkPlaybackTargetCompatibility()
{
#if ENABLE(WIRELESS_PLAYBACK_TARGET)
if (!m_isPlayingToWirelessTarget || m_player->canPlayToWirelessPlaybackTarget())
return;

static const Seconds maxIntervalForWirelessPlaybackPlayerUpdate { 500_ms };
Seconds delta = MonotonicTime::now() - m_currentPlaybackTargetIsWirelessEventFiredTime;
if (delta < maxIntervalForWirelessPlaybackPlayerUpdate) {
scheduleCheckPlaybackTargetCompatability();
return;
}

auto tryToSwitchEngines = !m_remotePlaybackConfiguration && m_loadState == LoadingFromSourceElement;
if (tryToSwitchEngines) {
m_remotePlaybackConfiguration = { currentMediaTime(), playbackRate(), paused() };
tryToSwitchEngines = havePotentialSourceChild();
}

if (!tryToSwitchEngines) {
ERROR_LOG(LOGIDENTIFIER, "player incompatible after ", delta.value(), ", calling setShouldPlayToPlaybackTarget(false)");
ERROR_LOG(LOGIDENTIFIER, "player incompatible, calling setShouldPlayToPlaybackTarget(false)");
m_failedToPlayToWirelessTarget = true;
m_remotePlaybackConfiguration = { };
m_player->setShouldPlayToPlaybackTarget(false);
Expand Down Expand Up @@ -6092,13 +6075,13 @@ void HTMLMediaElement::stopPeriodicTimers()
{
m_progressEventTimer.stop();
m_playbackProgressTimer.stop();
m_checkPlaybackTargetCompatibilityTimer.stop();
}

void HTMLMediaElement::cancelPendingTasks()
{
m_configureTextTracksTaskCancellationGroup.cancel();
m_updateTextTracksTaskCancellationGroup.cancel();
m_checkPlaybackTargetCompatibilityTaskCancellationGroup.cancel();
m_updateMediaStateTaskCancellationGroup.cancel();
m_mediaEngineUpdatedTaskCancellationGroup.cancel();
m_updatePlayStateTaskCancellationGroup.cancel();
Expand Down Expand Up @@ -6462,8 +6445,7 @@ void HTMLMediaElement::setIsPlayingToWirelessTarget(bool isPlayingToWirelessTarg
updateSleepDisabling();

m_failedToPlayToWirelessTarget = false;
m_currentPlaybackTargetIsWirelessEventFiredTime = MonotonicTime::now();
scheduleCheckPlaybackTargetCompatability();
m_checkPlaybackTargetCompatibilityTimer.startOneShot(500_ms);

if (!isContextStopped())
dispatchEvent(Event::create(eventNames().webkitcurrentplaybacktargetiswirelesschangedEvent, Event::CanBubble::No, Event::IsCancelable::Yes));
Expand Down
4 changes: 1 addition & 3 deletions Source/WebCore/html/HTMLMediaElement.h
Expand Up @@ -206,7 +206,6 @@ class HTMLMediaElement
MediaPlayer::VideoGravity videoFullscreenGravity() const { return m_videoFullscreenGravity; }
#endif

void scheduleCheckPlaybackTargetCompatability();
void checkPlaybackTargetCompatibility();
void scheduleResolvePendingPlayPromises();
void scheduleRejectPendingPlayPromises(Ref<DOMException>&&);
Expand Down Expand Up @@ -1038,9 +1037,9 @@ class HTMLMediaElement
Timer m_scanTimer;
Timer m_playbackControlsManagerBehaviorRestrictionsTimer;
Timer m_seekToPlaybackPositionEndedTimer;
Timer m_checkPlaybackTargetCompatibilityTimer;
TaskCancellationGroup m_configureTextTracksTaskCancellationGroup;
TaskCancellationGroup m_updateTextTracksTaskCancellationGroup;
TaskCancellationGroup m_checkPlaybackTargetCompatibilityTaskCancellationGroup;
TaskCancellationGroup m_updateMediaStateTaskCancellationGroup;
TaskCancellationGroup m_mediaEngineUpdatedTaskCancellationGroup;
TaskCancellationGroup m_updatePlayStateTaskCancellationGroup;
Expand Down Expand Up @@ -1278,7 +1277,6 @@ class HTMLMediaElement
MediaProducerMediaStateFlags m_mediaState;

#if ENABLE(WIRELESS_PLAYBACK_TARGET)
MonotonicTime m_currentPlaybackTargetIsWirelessEventFiredTime;
bool m_hasPlaybackTargetAvailabilityListeners { false };
bool m_failedToPlayToWirelessTarget { false };
bool m_lastTargetAvailabilityEventState { false };
Expand Down

0 comments on commit aa760bb

Please sign in to comment.