Skip to content

Commit

Permalink
Cherry-pick f5f6345. rdar://problem/97273615
Browse files Browse the repository at this point in the history
    Refactor PlaybackSessionModel::externalPlaybackTargetType to use enum class
    rdar://63360025
    https://bugs.webkit.org/show_bug.cgi?id=242476

    Reviewed by Eric Carlson.

    * Source/WebCore/platform/cocoa/PlaybackSessionModel.h:
    (): Deleted.
    * Source/WebCore/platform/cocoa/PlaybackSessionModelMediaElement.mm:
    (WebCore::PlaybackSessionModelMediaElement::externalPlaybackTargetType const):
    * Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.mm:
    (WebCore::PlaybackSessionInterfaceAVKit::externalPlaybackChanged):
    * Source/WebCore/platform/ios/VideoFullscreenInterfaceAVKit.mm:
    (VideoFullscreenInterfaceAVKit::~VideoFullscreenInterfaceAVKit):
    * Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm:
    (VideoFullscreenControllerContext::externalPlaybackTargetType const):
    * Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.h:
    * Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.messages.in:
    * Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.mm:
    (WebKit::PlaybackSessionManagerProxy::externalPlaybackPropertiesChanged):
    * Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.mm:
    (WebKit::PlaybackSessionManager::externalPlaybackChanged):

    Canonical link: https://commits.webkit.org/252247@main

Canonical link: https://commits.webkit.org/245886.823@safari-7613.4.1.0-branch
  • Loading branch information
abigailfox authored and alancoon committed Aug 9, 2022
1 parent 4c0398c commit 5e1e9e3
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 21 deletions.
11 changes: 10 additions & 1 deletion Source/WebCore/platform/cocoa/PlaybackSessionModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class PlaybackSessionModel : public CanMakeWeakPtr<PlaybackSessionModel> {
virtual void setPlayingOnSecondScreen(bool) = 0;
virtual void sendRemoteCommand(PlatformMediaSession::RemoteControlCommandType, const PlatformMediaSession::RemoteCommandArgument&) { };

enum ExternalPlaybackTargetType { TargetTypeNone, TargetTypeAirPlay, TargetTypeTVOut };
enum class ExternalPlaybackTargetType { TargetTypeNone, TargetTypeAirPlay, TargetTypeTVOut };

virtual double playbackStartedTime() const = 0;
virtual double duration() const = 0;
Expand Down Expand Up @@ -128,6 +128,15 @@ class PlaybackSessionModelClient {

namespace WTF {

template<> struct EnumTraits<WebCore::PlaybackSessionModel::ExternalPlaybackTargetType> {
using values = EnumValues<
WebCore::PlaybackSessionModel::ExternalPlaybackTargetType,
WebCore::PlaybackSessionModel::ExternalPlaybackTargetType::TargetTypeNone,
WebCore::PlaybackSessionModel::ExternalPlaybackTargetType::TargetTypeAirPlay,
WebCore::PlaybackSessionModel::ExternalPlaybackTargetType::TargetTypeTVOut
>;
};

template<> struct EnumTraits<WebCore::PlaybackSessionModel::PlaybackState> {
using values = EnumValues<
WebCore::PlaybackSessionModel::PlaybackState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,18 +591,18 @@
PlaybackSessionModel::ExternalPlaybackTargetType PlaybackSessionModelMediaElement::externalPlaybackTargetType() const
{
if (!m_mediaElement || !m_mediaElement->mediaControlsHost())
return TargetTypeNone;
return ExternalPlaybackTargetType::TargetTypeNone;

switch (m_mediaElement->mediaControlsHost()->externalDeviceType()) {
default:
ASSERT_NOT_REACHED();
return TargetTypeNone;
return ExternalPlaybackTargetType::TargetTypeNone;
case MediaControlsHost::DeviceType::None:
return TargetTypeNone;
return ExternalPlaybackTargetType::TargetTypeNone;
case MediaControlsHost::DeviceType::Airplay:
return TargetTypeAirPlay;
return ExternalPlaybackTargetType::TargetTypeAirPlay;
case MediaControlsHost::DeviceType::Tvout:
return TargetTypeTVOut;
return ExternalPlaybackTargetType::TargetTypeTVOut;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.mm
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@
void PlaybackSessionInterfaceAVKit::externalPlaybackChanged(bool enabled, PlaybackSessionModel::ExternalPlaybackTargetType targetType, const String& localizedDeviceName)
{
AVPlayerControllerExternalPlaybackType externalPlaybackType = AVPlayerControllerExternalPlaybackTypeNone;
if (enabled && targetType == PlaybackSessionModel::TargetTypeAirPlay)
if (enabled && targetType == PlaybackSessionModel::ExternalPlaybackTargetType::TargetTypeAirPlay)
externalPlaybackType = AVPlayerControllerExternalPlaybackTypeAirPlay;
else if (enabled && targetType == PlaybackSessionModel::TargetTypeTVOut)
else if (enabled && targetType == PlaybackSessionModel::ExternalPlaybackTargetType::TargetTypeTVOut)
externalPlaybackType = AVPlayerControllerExternalPlaybackTypeTVOut;

WebAVPlayerController* playerController = m_playerController.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ - (void)removeFromParentViewController
{
WebAVPlayerController* playerController = this->playerController();
if (playerController && playerController.externalPlaybackActive)
externalPlaybackChanged(false, PlaybackSessionModel::TargetTypeNone, "");
externalPlaybackChanged(false, PlaybackSessionModel::ExternalPlaybackTargetType::TargetTypeNone, "");
if (m_videoFullscreenModel)
m_videoFullscreenModel->removeClient(*this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ void togglePictureInPicture() override { }
PlaybackSessionModel::ExternalPlaybackTargetType VideoFullscreenControllerContext::externalPlaybackTargetType() const
{
ASSERT(isUIThread());
return m_playbackModel ? m_playbackModel->externalPlaybackTargetType() : TargetTypeNone;
return m_playbackModel ? m_playbackModel->externalPlaybackTargetType() : ExternalPlaybackTargetType::TargetTypeNone;
}

String VideoFullscreenControllerContext::externalPlaybackLocalizedDeviceName() const
Expand Down
6 changes: 3 additions & 3 deletions Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2016-2021 Apple Inc. All rights reserved.
* Copyright (C) 2016-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -168,7 +168,7 @@ class PlaybackSessionModelContext final: public RefCounted<PlaybackSessionModelC
Vector<WebCore::MediaSelectionOption> m_legibleMediaSelectionOptions;
uint64_t m_legibleMediaSelectedIndex { 0 };
bool m_externalPlaybackEnabled { false };
PlaybackSessionModel::ExternalPlaybackTargetType m_externalPlaybackTargetType { PlaybackSessionModel::TargetTypeNone };
PlaybackSessionModel::ExternalPlaybackTargetType m_externalPlaybackTargetType { PlaybackSessionModel::ExternalPlaybackTargetType::TargetTypeNone };
String m_externalPlaybackLocalizedDeviceName;
bool m_wirelessVideoPlaybackDisabled { false };
bool m_muted { false };
Expand Down Expand Up @@ -218,7 +218,7 @@ class PlaybackSessionManagerProxy : public RefCounted<PlaybackSessionManagerProx
void legibleMediaSelectionOptionsChanged(PlaybackSessionContextIdentifier, Vector<WebCore::MediaSelectionOption> options, uint64_t selectedIndex);
void audioMediaSelectionIndexChanged(PlaybackSessionContextIdentifier, uint64_t selectedIndex);
void legibleMediaSelectionIndexChanged(PlaybackSessionContextIdentifier, uint64_t selectedIndex);
void externalPlaybackPropertiesChanged(PlaybackSessionContextIdentifier, bool enabled, uint32_t targetType, String localizedDeviceName);
void externalPlaybackPropertiesChanged(PlaybackSessionContextIdentifier, bool enabled, WebCore::PlaybackSessionModel::ExternalPlaybackTargetType, String localizedDeviceName);
void wirelessVideoPlaybackDisabledChanged(PlaybackSessionContextIdentifier, bool);
void durationChanged(PlaybackSessionContextIdentifier, double duration);
void playbackStartedTimeChanged(PlaybackSessionContextIdentifier, double playbackStartedTime);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2016-2020 Apple Inc. All rights reserved.
# Copyright (C) 2016-2022 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -30,7 +30,7 @@ messages -> PlaybackSessionManagerProxy {
LegibleMediaSelectionOptionsChanged(WebKit::PlaybackSessionContextIdentifier contextId, Vector<WebCore::MediaSelectionOption> options, uint64_t selectedIndex)
AudioMediaSelectionIndexChanged(WebKit::PlaybackSessionContextIdentifier contextId, uint64_t selectedIndex)
LegibleMediaSelectionIndexChanged(WebKit::PlaybackSessionContextIdentifier contextId, uint64_t selectedIndex)
ExternalPlaybackPropertiesChanged(WebKit::PlaybackSessionContextIdentifier contextId, bool enabled, uint32_t targetType, String localizedDeviceName)
ExternalPlaybackPropertiesChanged(WebKit::PlaybackSessionContextIdentifier contextId, bool enabled, WebCore::PlaybackSessionModel::ExternalPlaybackTargetType targetType, String localizedDeviceName)
WirelessVideoPlaybackDisabledChanged(WebKit::PlaybackSessionContextIdentifier contextId, bool disabled)
DurationChanged(WebKit::PlaybackSessionContextIdentifier contextId, double duration)
PlaybackStartedTimeChanged(WebKit::PlaybackSessionContextIdentifier contextId, double playbackStartedTime)
Expand Down
7 changes: 2 additions & 5 deletions Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,9 @@
ensureModel(contextId).legibleMediaSelectionIndexChanged(selectedIndex);
}

void PlaybackSessionManagerProxy::externalPlaybackPropertiesChanged(PlaybackSessionContextIdentifier contextId, bool enabled, uint32_t targetType, String localizedDeviceName)
void PlaybackSessionManagerProxy::externalPlaybackPropertiesChanged(PlaybackSessionContextIdentifier contextId, bool enabled, WebCore::PlaybackSessionModel::ExternalPlaybackTargetType targetType, String localizedDeviceName)
{
PlaybackSessionModel::ExternalPlaybackTargetType type = static_cast<PlaybackSessionModel::ExternalPlaybackTargetType>(targetType);
ASSERT(type == PlaybackSessionModel::TargetTypeAirPlay || type == PlaybackSessionModel::TargetTypeTVOut || type == PlaybackSessionModel::TargetTypeNone);

ensureModel(contextId).externalPlaybackChanged(enabled, type, localizedDeviceName);
ensureModel(contextId).externalPlaybackChanged(enabled, targetType, localizedDeviceName);
}

void PlaybackSessionManagerProxy::wirelessVideoPlaybackDisabledChanged(PlaybackSessionContextIdentifier contextId, bool disabled)
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@

void PlaybackSessionManager::externalPlaybackChanged(PlaybackSessionContextIdentifier contextId, bool enabled, PlaybackSessionModel::ExternalPlaybackTargetType targetType, String localizedDeviceName)
{
m_page->send(Messages::PlaybackSessionManagerProxy::ExternalPlaybackPropertiesChanged(contextId, enabled, static_cast<uint32_t>(targetType), localizedDeviceName));
m_page->send(Messages::PlaybackSessionManagerProxy::ExternalPlaybackPropertiesChanged(contextId, enabled, targetType, localizedDeviceName));
}

void PlaybackSessionManager::audioMediaSelectionIndexChanged(PlaybackSessionContextIdentifier contextId, uint64_t selectedIndex)
Expand Down

0 comments on commit 5e1e9e3

Please sign in to comment.