~mmach/netext73/webkit2gtk

« back to all changes in this revision

Viewing changes to Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.h

  • Committer: mmach
  • Date: 2023-06-16 17:21:37 UTC
  • Revision ID: netbit73@gmail.com-20230616172137-2rqx6yr96ga9g3kp
1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2019 Apple Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
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.
 
12
 *
 
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.
 
24
 */
 
25
 
 
26
#pragma once
 
27
 
 
28
#if ENABLE(GPU_PROCESS)
 
29
 
 
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>
 
47
 
 
48
namespace WebCore {
 
49
class AudioTrackPrivate;
 
50
class VideoTrackPrivate;
 
51
}
 
52
 
 
53
namespace WebKit {
 
54
 
 
55
using LayerHostingContextID = uint32_t;
 
56
class LayerHostingContext;
 
57
class RemoteAudioTrackProxy;
 
58
class RemoteMediaPlayerManagerProxy;
 
59
class RemoteVideoTrackProxy;
 
60
 
 
61
class RemoteMediaPlayerProxy final
 
62
    : public CanMakeWeakPtr<RemoteMediaPlayerProxy>
 
63
    , public WebCore::MediaPlayerClient
 
64
    , private IPC::MessageReceiver {
 
65
    WTF_MAKE_FAST_ALLOCATED;
 
66
public:
 
67
    RemoteMediaPlayerProxy(RemoteMediaPlayerManagerProxy&, MediaPlayerPrivateRemoteIdentifier, Ref<IPC::Connection>&&, WebCore::MediaPlayerEnums::MediaEngineIdentifier, RemoteMediaPlayerProxyConfiguration&&);
 
68
    ~RemoteMediaPlayerProxy();
 
69
 
 
70
    MediaPlayerPrivateRemoteIdentifier idendifier() const { return m_id; }
 
71
    void invalidate();
 
72
 
 
73
    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
 
74
 
 
75
    void getConfiguration(RemoteMediaPlayerConfiguration&);
 
76
 
 
77
    void prepareForPlayback(bool privateMode, WebCore::MediaPlayerEnums::Preload, bool preservesPitch, bool prepareForRendering, WebCore::LayoutRect, float videoContentScale, CompletionHandler<void(Optional<LayerHostingContextID>&&)>&&);
 
78
    void prepareForRendering();
 
79
 
 
80
    void load(URL&&, Optional<SandboxExtension::Handle>&&, const WebCore::ContentType&, const String&, CompletionHandler<void(RemoteMediaPlayerConfiguration&&)>&&);
 
81
    void cancelLoad();
 
82
 
 
83
    void prepareToPlay();
 
84
 
 
85
    void play();
 
86
    void pause();
 
87
 
 
88
    void seek(MediaTime&&);
 
89
    void seekWithTolerance(MediaTime&&, MediaTime&& negativeTolerance, MediaTime&& positiveTolerance);
 
90
 
 
91
    void setVolume(double);
 
92
    void setMuted(bool);
 
93
 
 
94
    void setPreload(WebCore::MediaPlayerEnums::Preload);
 
95
    void setPrivateBrowsingMode(bool);
 
96
    void setPreservesPitch(bool);
 
97
 
 
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);
 
105
 
 
106
    void audioTrackSetEnabled(TrackPrivateRemoteIdentifier, bool);
 
107
    void videoTrackSetSelected(TrackPrivateRemoteIdentifier, bool);
 
108
 
 
109
#if ENABLE(WIRELESS_PLAYBACK_TARGET)
 
110
    void setWirelessVideoPlaybackDisabled(bool);
 
111
    void setShouldPlayToPlaybackTarget(bool);
 
112
#endif
 
113
 
 
114
#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
 
115
    void keyAdded();
 
116
#endif
 
117
 
 
118
    void beginSimulatedHDCPError();
 
119
    void endSimulatedHDCPError();
 
120
 
 
121
    void notifyActiveSourceBuffersChanged();
 
122
 
 
123
    void applicationWillResignActive();
 
124
    void applicationDidBecomeActive();
 
125
 
 
126
    Ref<WebCore::PlatformMediaResource> requestResource(WebCore::ResourceRequest&&, WebCore::PlatformMediaResourceLoader::LoadOptions);
 
127
    void removeResource(RemoteMediaResourceIdentifier);
 
128
 
 
129
private:
 
130
    // MediaPlayerClient
 
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;
 
143
 
 
144
    void mediaPlayerDidAddAudioTrack(WebCore::AudioTrackPrivate&) final;
 
145
    void mediaPlayerDidRemoveAudioTrack(WebCore::AudioTrackPrivate&) final;
 
146
    void mediaPlayerDidAddVideoTrack(WebCore::VideoTrackPrivate&) final;
 
147
    void mediaPlayerDidRemoveVideoTrack(WebCore::VideoTrackPrivate&) final;
 
148
 
 
149
    // Not implemented
 
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;
 
157
 
 
158
#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
 
159
    RefPtr<ArrayBuffer> mediaPlayerCachedKeyForKeyId(const String&) const final;
 
160
    bool mediaPlayerKeyNeeded(Uint8Array*) final;
 
161
    String mediaPlayerMediaKeysStorageDirectory() const final;
 
162
#endif
 
163
 
 
164
#if ENABLE(ENCRYPTED_MEDIA)
 
165
    void mediaPlayerInitializationDataEncountered(const String&, RefPtr<ArrayBuffer>&&) final;
 
166
    void mediaPlayerWaitingForKeyChanged() final;
 
167
#endif
 
168
 
 
169
    void mediaPlayerCurrentPlaybackTargetIsWirelessChanged(bool) final;
 
170
 
 
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;
 
188
 
 
189
    void mediaPlayerDidAddTextTrack(WebCore::InbandTextTrackPrivate&) final;
 
190
    void mediaPlayerDidRemoveTextTrack(WebCore::InbandTextTrackPrivate&) final;
 
191
 
 
192
    void textTrackRepresentationBoundsChanged(const WebCore::IntRect&) final;
 
193
 
 
194
#if ENABLE(VIDEO_TRACK) && ENABLE(AVF_CAPTIONS)
 
195
    Vector<RefPtr<WebCore::PlatformTextTrack>> outOfBandTrackSources() final;
 
196
#endif
 
197
 
 
198
#if PLATFORM(IOS_FAMILY)
 
199
    String mediaPlayerNetworkInterfaceName() const final;
 
200
    bool mediaPlayerGetRawCookies(const URL&, Vector<WebCore::Cookie>&) const final;
 
201
#endif
 
202
 
 
203
    String mediaPlayerSourceApplicationIdentifier() const final;
 
204
 
 
205
    double mediaPlayerRequestedPlaybackRate() const final;
 
206
    WebCore::MediaPlayerEnums::VideoFullscreenMode mediaPlayerFullscreenMode() const final;
 
207
    bool mediaPlayerIsVideoFullscreenStandby() const final;
 
208
    Vector<String> mediaPlayerPreferredAudioCharacteristics() const final;
 
209
 
 
210
    bool mediaPlayerShouldDisableSleep() const final;
 
211
    const Vector<WebCore::ContentType>& mediaContentTypesRequiringHardwareSupport() const final;
 
212
    bool mediaPlayerShouldCheckHardwareSupport() const final;
 
213
 
 
214
    void startUpdateCachedStateMessageTimer();
 
215
    void updateCachedState();
 
216
    void sendCachedState();
 
217
    void timerFired();
 
218
 
 
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); }
 
222
#endif
 
223
 
 
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 };
 
242
 
 
243
#if !RELEASE_LOG_DISABLED
 
244
    const Logger& m_logger;
 
245
#endif
 
246
};
 
247
 
 
248
} // namespace WebKit
 
249
 
 
250
#endif