2
* Copyright (C) 2019 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
* THE POSSIBILITY OF SUCH DAMAGE.
28
#if ENABLE(GPU_PROCESS)
30
#include "Connection.h"
31
#include "MediaPlayerPrivateRemoteIdentifier.h"
32
#include "MessageReceiver.h"
33
#include "RemoteMediaPlayerConfiguration.h"
34
#include "RemoteMediaPlayerProxyConfiguration.h"
35
#include "RemoteMediaPlayerState.h"
36
#include "RemoteMediaResourceIdentifier.h"
37
#include "SandboxExtension.h"
38
#include "TrackPrivateRemoteIdentifier.h"
39
#include <WebCore/Cookie.h>
40
#include <WebCore/MediaPlayer.h>
41
#include <WebCore/PlatformMediaResourceLoader.h>
42
#include <wtf/LoggerHelper.h>
43
#include <wtf/RefPtr.h>
44
#include <wtf/RunLoop.h>
45
#include <wtf/Vector.h>
46
#include <wtf/WeakPtr.h>
49
class AudioTrackPrivate;
50
class VideoTrackPrivate;
55
using LayerHostingContextID = uint32_t;
56
class LayerHostingContext;
57
class RemoteAudioTrackProxy;
58
class RemoteMediaPlayerManagerProxy;
59
class RemoteVideoTrackProxy;
61
class RemoteMediaPlayerProxy final
62
: public CanMakeWeakPtr<RemoteMediaPlayerProxy>
63
, public WebCore::MediaPlayerClient
64
, private IPC::MessageReceiver {
65
WTF_MAKE_FAST_ALLOCATED;
67
RemoteMediaPlayerProxy(RemoteMediaPlayerManagerProxy&, MediaPlayerPrivateRemoteIdentifier, Ref<IPC::Connection>&&, WebCore::MediaPlayerEnums::MediaEngineIdentifier, RemoteMediaPlayerProxyConfiguration&&);
68
~RemoteMediaPlayerProxy();
70
MediaPlayerPrivateRemoteIdentifier idendifier() const { return m_id; }
73
void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
75
void getConfiguration(RemoteMediaPlayerConfiguration&);
77
void prepareForPlayback(bool privateMode, WebCore::MediaPlayerEnums::Preload, bool preservesPitch, bool prepareForRendering, WebCore::LayoutRect, float videoContentScale, CompletionHandler<void(Optional<LayerHostingContextID>&&)>&&);
78
void prepareForRendering();
80
void load(URL&&, Optional<SandboxExtension::Handle>&&, const WebCore::ContentType&, const String&, CompletionHandler<void(RemoteMediaPlayerConfiguration&&)>&&);
88
void seek(MediaTime&&);
89
void seekWithTolerance(MediaTime&&, MediaTime&& negativeTolerance, MediaTime&& positiveTolerance);
91
void setVolume(double);
94
void setPreload(WebCore::MediaPlayerEnums::Preload);
95
void setPrivateBrowsingMode(bool);
96
void setPreservesPitch(bool);
98
void setVisible(bool);
99
void setShouldMaintainAspectRatio(bool);
100
void setVideoFullscreenFrame(WebCore::FloatRect);
101
void setVideoFullscreenGravity(WebCore::MediaPlayerEnums::VideoGravity);
102
void acceleratedRenderingStateChanged(bool);
103
void setShouldDisableSleep(bool);
104
void setRate(double);
106
void audioTrackSetEnabled(TrackPrivateRemoteIdentifier, bool);
107
void videoTrackSetSelected(TrackPrivateRemoteIdentifier, bool);
109
#if ENABLE(WIRELESS_PLAYBACK_TARGET)
110
void setWirelessVideoPlaybackDisabled(bool);
111
void setShouldPlayToPlaybackTarget(bool);
114
#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
118
void beginSimulatedHDCPError();
119
void endSimulatedHDCPError();
121
void notifyActiveSourceBuffersChanged();
123
void applicationWillResignActive();
124
void applicationDidBecomeActive();
126
Ref<WebCore::PlatformMediaResource> requestResource(WebCore::ResourceRequest&&, WebCore::PlatformMediaResourceLoader::LoadOptions);
127
void removeResource(RemoteMediaResourceIdentifier);
131
void mediaPlayerNetworkStateChanged() final;
132
void mediaPlayerReadyStateChanged() final;
133
void mediaPlayerVolumeChanged() final;
134
void mediaPlayerMuteChanged() final;
135
void mediaPlayerTimeChanged() final;
136
void mediaPlayerDurationChanged() final;
137
void mediaPlayerRateChanged() final;
138
void mediaPlayerPlaybackStateChanged() final;
139
void mediaPlayerEngineFailedToLoad() const final;
140
void mediaPlayerBufferedTimeRangesChanged() final;
141
void mediaPlayerSeekableTimeRangesChanged() final;
142
bool mediaPlayerRenderingCanBeAccelerated() final;
144
void mediaPlayerDidAddAudioTrack(WebCore::AudioTrackPrivate&) final;
145
void mediaPlayerDidRemoveAudioTrack(WebCore::AudioTrackPrivate&) final;
146
void mediaPlayerDidAddVideoTrack(WebCore::VideoTrackPrivate&) final;
147
void mediaPlayerDidRemoveVideoTrack(WebCore::VideoTrackPrivate&) final;
150
void mediaPlayerResourceNotSupported() final;
151
void mediaPlayerSizeChanged() final;
152
void mediaPlayerEngineUpdated() final;
153
void mediaPlayerFirstVideoFrameAvailable() final;
154
void mediaPlayerCharacteristicChanged() final;
155
void mediaPlayerRenderingModeChanged() final;
156
void mediaPlayerActiveSourceBuffersChanged() final;
158
#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
159
RefPtr<ArrayBuffer> mediaPlayerCachedKeyForKeyId(const String&) const final;
160
bool mediaPlayerKeyNeeded(Uint8Array*) final;
161
String mediaPlayerMediaKeysStorageDirectory() const final;
164
#if ENABLE(ENCRYPTED_MEDIA)
165
void mediaPlayerInitializationDataEncountered(const String&, RefPtr<ArrayBuffer>&&) final;
166
void mediaPlayerWaitingForKeyChanged() final;
169
void mediaPlayerCurrentPlaybackTargetIsWirelessChanged(bool) final;
171
String mediaPlayerReferrer() const final;
172
String mediaPlayerUserAgent() const final;
173
void mediaPlayerEnterFullscreen() final;
174
void mediaPlayerExitFullscreen() final;
175
bool mediaPlayerIsFullscreen() const final;
176
bool mediaPlayerIsFullscreenPermitted() const final;
177
bool mediaPlayerIsVideo() const final;
178
WebCore::LayoutRect mediaPlayerContentBoxRect() const final;
179
float mediaPlayerContentsScale() const final;
180
void mediaPlayerPause() final;
181
void mediaPlayerPlay() final;
182
bool mediaPlayerPlatformVolumeConfigurationRequired() const final;
183
WebCore::CachedResourceLoader* mediaPlayerCachedResourceLoader() final;
184
RefPtr<WebCore::PlatformMediaResourceLoader> mediaPlayerCreateResourceLoader() final;
185
bool doesHaveAttribute(const AtomString&, AtomString* = nullptr) const final;
186
bool mediaPlayerShouldUsePersistentCache() const final;
187
const String& mediaPlayerMediaCacheDirectory() const final;
189
void mediaPlayerDidAddTextTrack(WebCore::InbandTextTrackPrivate&) final;
190
void mediaPlayerDidRemoveTextTrack(WebCore::InbandTextTrackPrivate&) final;
192
void textTrackRepresentationBoundsChanged(const WebCore::IntRect&) final;
194
#if ENABLE(VIDEO_TRACK) && ENABLE(AVF_CAPTIONS)
195
Vector<RefPtr<WebCore::PlatformTextTrack>> outOfBandTrackSources() final;
198
#if PLATFORM(IOS_FAMILY)
199
String mediaPlayerNetworkInterfaceName() const final;
200
bool mediaPlayerGetRawCookies(const URL&, Vector<WebCore::Cookie>&) const final;
203
String mediaPlayerSourceApplicationIdentifier() const final;
205
double mediaPlayerRequestedPlaybackRate() const final;
206
WebCore::MediaPlayerEnums::VideoFullscreenMode mediaPlayerFullscreenMode() const final;
207
bool mediaPlayerIsVideoFullscreenStandby() const final;
208
Vector<String> mediaPlayerPreferredAudioCharacteristics() const final;
210
bool mediaPlayerShouldDisableSleep() const final;
211
const Vector<WebCore::ContentType>& mediaContentTypesRequiringHardwareSupport() const final;
212
bool mediaPlayerShouldCheckHardwareSupport() const final;
214
void startUpdateCachedStateMessageTimer();
215
void updateCachedState();
216
void sendCachedState();
219
#if !RELEASE_LOG_DISABLED
220
const Logger& mediaPlayerLogger() final { return m_logger; }
221
const void* mediaPlayerLogIdentifier() { return reinterpret_cast<const void*>(m_configuration.logIdentifier); }
224
HashMap<WebCore::AudioTrackPrivate*, Ref<RemoteAudioTrackProxy>> m_audioTracks;
225
HashMap<WebCore::VideoTrackPrivate*, Ref<RemoteVideoTrackProxy>> m_videoTracks;
226
MediaPlayerPrivateRemoteIdentifier m_id;
227
RefPtr<SandboxExtension> m_sandboxExtension;
228
Ref<IPC::Connection> m_webProcessConnection;
229
RefPtr<WebCore::MediaPlayer> m_player;
230
std::unique_ptr<LayerHostingContext> m_layerHostingContext;
231
RemoteMediaPlayerManagerProxy& m_manager;
232
WebCore::MediaPlayerEnums::MediaEngineIdentifier m_engineIdentifier;
233
Vector<WebCore::ContentType> m_typesRequiringHardwareSupport;
234
RunLoop::Timer<RemoteMediaPlayerProxy> m_updateCachedStateMessageTimer;
235
RemoteMediaPlayerState m_cachedState;
236
RemoteMediaPlayerProxyConfiguration m_configuration;
237
bool m_seekableChanged { true };
238
bool m_bufferedChanged { true };
239
bool m_renderingCanBeAccelerated { true };
240
WebCore::LayoutRect m_videoContentBoxRect;
241
float m_videoContentScale { 1.0 };
243
#if !RELEASE_LOG_DISABLED
244
const Logger& m_logger;
248
} // namespace WebKit