1 | /* |
2 | * Copyright (C) 2009-2018 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. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(VIDEO) |
29 | |
30 | #include "MediaPlayer.h" |
31 | #include "PlatformTimeRanges.h" |
32 | |
33 | namespace WebCore { |
34 | |
35 | class MediaPlayerPrivateInterface { |
36 | WTF_MAKE_NONCOPYABLE(MediaPlayerPrivateInterface); WTF_MAKE_FAST_ALLOCATED; |
37 | public: |
38 | MediaPlayerPrivateInterface() = default; |
39 | virtual ~MediaPlayerPrivateInterface() = default; |
40 | |
41 | virtual void load(const String& url) = 0; |
42 | #if ENABLE(MEDIA_SOURCE) |
43 | virtual void load(const String& url, MediaSourcePrivateClient*) = 0; |
44 | #endif |
45 | #if ENABLE(MEDIA_STREAM) |
46 | virtual void load(MediaStreamPrivate&) = 0; |
47 | #endif |
48 | virtual void cancelLoad() = 0; |
49 | |
50 | virtual void prepareToPlay() { } |
51 | virtual PlatformLayer* platformLayer() const { return 0; } |
52 | |
53 | #if PLATFORM(IOS_FAMILY) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) |
54 | virtual void setVideoFullscreenLayer(PlatformLayer*, WTF::Function<void()>&& completionHandler) { completionHandler(); } |
55 | virtual void updateVideoFullscreenInlineImage() { } |
56 | virtual void setVideoFullscreenFrame(FloatRect) { } |
57 | virtual void setVideoFullscreenGravity(MediaPlayer::VideoGravity) { } |
58 | virtual void setVideoFullscreenMode(MediaPlayer::VideoFullscreenMode) { } |
59 | virtual void videoFullscreenStandbyChanged() { } |
60 | #endif |
61 | |
62 | #if PLATFORM(IOS_FAMILY) |
63 | virtual NSArray *timedMetadata() const { return 0; } |
64 | virtual String accessLog() const { return emptyString(); } |
65 | virtual String errorLog() const { return emptyString(); } |
66 | #endif |
67 | virtual long platformErrorCode() const { return 0; } |
68 | |
69 | virtual void play() = 0; |
70 | virtual void pause() = 0; |
71 | virtual void setBufferingPolicy(MediaPlayer::BufferingPolicy) { } |
72 | |
73 | virtual bool supportsPictureInPicture() const { return false; } |
74 | virtual bool supportsFullscreen() const { return false; } |
75 | virtual bool supportsScanning() const { return false; } |
76 | virtual bool requiresImmediateCompositing() const { return false; } |
77 | |
78 | virtual bool canSaveMediaData() const { return false; } |
79 | |
80 | virtual FloatSize naturalSize() const = 0; |
81 | |
82 | virtual bool hasVideo() const = 0; |
83 | virtual bool hasAudio() const = 0; |
84 | |
85 | virtual void setVisible(bool) = 0; |
86 | |
87 | virtual float duration() const { return 0; } |
88 | virtual double durationDouble() const { return duration(); } |
89 | virtual MediaTime durationMediaTime() const { return MediaTime::createWithDouble(durationDouble()); } |
90 | |
91 | virtual float currentTime() const { return 0; } |
92 | virtual double currentTimeDouble() const { return currentTime(); } |
93 | virtual MediaTime currentMediaTime() const { return MediaTime::createWithDouble(currentTimeDouble()); } |
94 | |
95 | virtual MediaTime getStartDate() const { return MediaTime::createWithDouble(std::numeric_limits<double>::quiet_NaN()); } |
96 | |
97 | virtual void seek(float) { } |
98 | virtual void seekDouble(double time) { seek(time); } |
99 | virtual void seek(const MediaTime& time) { seekDouble(time.toDouble()); } |
100 | virtual void seekWithTolerance(const MediaTime& time, const MediaTime&, const MediaTime&) { seek(time); } |
101 | |
102 | virtual bool seeking() const = 0; |
103 | |
104 | virtual MediaTime startTime() const { return MediaTime::zeroTime(); } |
105 | virtual MediaTime initialTime() const { return MediaTime::zeroTime(); } |
106 | |
107 | virtual void setRate(float) { } |
108 | virtual void setRateDouble(double rate) { setRate(rate); } |
109 | virtual double rate() const { return 0; } |
110 | |
111 | virtual void setPreservesPitch(bool) { } |
112 | |
113 | virtual bool paused() const = 0; |
114 | |
115 | virtual void setVolume(float) { } |
116 | virtual void setVolumeDouble(double volume) { return setVolume(volume); } |
117 | #if PLATFORM(IOS_FAMILY) || USE(GSTREAMER) |
118 | virtual float volume() const { return 1; } |
119 | #endif |
120 | |
121 | virtual bool supportsMuting() const { return false; } |
122 | virtual void setMuted(bool) { } |
123 | |
124 | virtual bool hasClosedCaptions() const { return false; } |
125 | virtual void setClosedCaptionsVisible(bool) { } |
126 | |
127 | virtual double maxFastForwardRate() const { return std::numeric_limits<double>::infinity(); } |
128 | virtual double minFastReverseRate() const { return -std::numeric_limits<double>::infinity(); } |
129 | |
130 | virtual MediaPlayer::NetworkState networkState() const = 0; |
131 | virtual MediaPlayer::ReadyState readyState() const = 0; |
132 | |
133 | virtual std::unique_ptr<PlatformTimeRanges> seekable() const { return maxMediaTimeSeekable() == MediaTime::zeroTime() ? std::make_unique<PlatformTimeRanges>() : std::make_unique<PlatformTimeRanges>(minMediaTimeSeekable(), maxMediaTimeSeekable()); } |
134 | virtual float maxTimeSeekable() const { return 0; } |
135 | virtual MediaTime maxMediaTimeSeekable() const { return MediaTime::createWithDouble(maxTimeSeekable()); } |
136 | virtual double minTimeSeekable() const { return 0; } |
137 | virtual MediaTime minMediaTimeSeekable() const { return MediaTime::createWithDouble(minTimeSeekable()); } |
138 | virtual std::unique_ptr<PlatformTimeRanges> buffered() const = 0; |
139 | virtual double seekableTimeRangesLastModifiedTime() const { return 0; } |
140 | virtual double liveUpdateInterval() const { return 0; } |
141 | |
142 | virtual unsigned long long totalBytes() const { return 0; } |
143 | virtual bool didLoadingProgress() const = 0; |
144 | |
145 | virtual void setSize(const IntSize&) = 0; |
146 | |
147 | virtual void paint(GraphicsContext&, const FloatRect&) = 0; |
148 | |
149 | virtual void paintCurrentFrameInContext(GraphicsContext& c, const FloatRect& r) { paint(c, r); } |
150 | virtual bool copyVideoTextureToPlatformTexture(GraphicsContext3D*, Platform3DObject, GC3Denum, GC3Dint, GC3Denum, GC3Denum, GC3Denum, bool, bool) { return false; } |
151 | virtual NativeImagePtr nativeImageForCurrentTime() { return nullptr; } |
152 | |
153 | virtual void setPreload(MediaPlayer::Preload) { } |
154 | |
155 | virtual bool hasAvailableVideoFrame() const { return readyState() >= MediaPlayer::HaveCurrentData; } |
156 | |
157 | virtual bool canLoadPoster() const { return false; } |
158 | virtual void setPoster(const String&) { } |
159 | |
160 | #if USE(NATIVE_FULLSCREEN_VIDEO) |
161 | virtual void enterFullscreen() { } |
162 | virtual void exitFullscreen() { } |
163 | #endif |
164 | |
165 | #if ENABLE(WIRELESS_PLAYBACK_TARGET) |
166 | |
167 | virtual String wirelessPlaybackTargetName() const { return emptyString(); } |
168 | virtual MediaPlayer::WirelessPlaybackTargetType wirelessPlaybackTargetType() const { return MediaPlayer::TargetTypeNone; } |
169 | |
170 | virtual bool wirelessVideoPlaybackDisabled() const { return true; } |
171 | virtual void setWirelessVideoPlaybackDisabled(bool) { } |
172 | |
173 | virtual bool canPlayToWirelessPlaybackTarget() const { return false; } |
174 | virtual bool isCurrentPlaybackTargetWireless() const { return false; } |
175 | virtual void setWirelessPlaybackTarget(Ref<MediaPlaybackTarget>&&) { } |
176 | |
177 | virtual void setShouldPlayToPlaybackTarget(bool) { } |
178 | #endif |
179 | |
180 | #if USE(NATIVE_FULLSCREEN_VIDEO) |
181 | virtual bool canEnterFullscreen() const { return false; } |
182 | #endif |
183 | |
184 | // whether accelerated rendering is supported by the media engine for the current media. |
185 | virtual bool supportsAcceleratedRendering() const { return false; } |
186 | // called when the rendering system flips the into or out of accelerated rendering mode. |
187 | virtual void acceleratedRenderingStateChanged() { } |
188 | |
189 | virtual bool shouldMaintainAspectRatio() const { return true; } |
190 | virtual void setShouldMaintainAspectRatio(bool) { } |
191 | |
192 | virtual bool hasSingleSecurityOrigin() const { return false; } |
193 | virtual bool didPassCORSAccessCheck() const { return false; } |
194 | virtual Optional<bool> wouldTaintOrigin(const SecurityOrigin&) const { return WTF::nullopt; } |
195 | |
196 | virtual MediaPlayer::MovieLoadType movieLoadType() const { return MediaPlayer::Unknown; } |
197 | |
198 | virtual void prepareForRendering() { } |
199 | |
200 | // Time value in the movie's time scale. It is only necessary to override this if the media |
201 | // engine uses rational numbers to represent media time. |
202 | virtual MediaTime mediaTimeForTimeValue(const MediaTime& timeValue) const { return timeValue; } |
203 | |
204 | // Overide this if it is safe for HTMLMediaElement to cache movie time and report |
205 | // 'currentTime' as [cached time + elapsed wall time]. Returns the maximum wall time |
206 | // it is OK to calculate movie time before refreshing the cached time. |
207 | virtual double maximumDurationToCacheMediaTime() const { return 0; } |
208 | |
209 | virtual unsigned decodedFrameCount() const { return 0; } |
210 | virtual unsigned droppedFrameCount() const { return 0; } |
211 | virtual unsigned audioDecodedByteCount() const { return 0; } |
212 | virtual unsigned videoDecodedByteCount() const { return 0; } |
213 | |
214 | HashSet<RefPtr<SecurityOrigin>> originsInMediaCache(const String&) { return { }; } |
215 | void clearMediaCache(const String&, WallTime) { } |
216 | void clearMediaCacheForOrigins(const String&, const HashSet<RefPtr<SecurityOrigin>>&) { } |
217 | |
218 | virtual void setPrivateBrowsingMode(bool) { } |
219 | |
220 | virtual String engineDescription() const { return emptyString(); } |
221 | |
222 | #if ENABLE(WEB_AUDIO) |
223 | virtual AudioSourceProvider* audioSourceProvider() { return 0; } |
224 | #endif |
225 | |
226 | #if ENABLE(LEGACY_ENCRYPTED_MEDIA) |
227 | virtual std::unique_ptr<LegacyCDMSession> createSession(const String&, LegacyCDMSessionClient*) { return nullptr; } |
228 | virtual void setCDMSession(LegacyCDMSession*) { } |
229 | virtual void keyAdded() { } |
230 | #endif |
231 | |
232 | #if ENABLE(ENCRYPTED_MEDIA) |
233 | virtual void cdmInstanceAttached(CDMInstance&) { } |
234 | virtual void cdmInstanceDetached(CDMInstance&) { } |
235 | virtual void attemptToDecryptWithInstance(CDMInstance&) { } |
236 | virtual bool waitingForKey() const { return false; } |
237 | #endif |
238 | |
239 | #if ENABLE(VIDEO_TRACK) |
240 | virtual bool requiresTextTrackRepresentation() const { return false; } |
241 | virtual void setTextTrackRepresentation(TextTrackRepresentation*) { } |
242 | virtual void syncTextTrackBounds() { }; |
243 | virtual void tracksChanged() { }; |
244 | #endif |
245 | |
246 | #if USE(GSTREAMER) |
247 | virtual void simulateAudioInterruption() { } |
248 | #endif |
249 | |
250 | virtual void beginSimulatedHDCPError() { } |
251 | virtual void endSimulatedHDCPError() { } |
252 | |
253 | virtual String languageOfPrimaryAudioTrack() const { return emptyString(); } |
254 | |
255 | virtual size_t () const |
256 | { |
257 | MediaTime duration = this->durationMediaTime(); |
258 | if (!duration) |
259 | return 0; |
260 | |
261 | unsigned long long = totalBytes() * buffered()->totalDuration().toDouble() / duration.toDouble(); |
262 | return static_cast<unsigned>(extra); |
263 | } |
264 | |
265 | virtual unsigned long long fileSize() const { return 0; } |
266 | |
267 | virtual bool ended() const { return false; } |
268 | |
269 | virtual Optional<VideoPlaybackQualityMetrics> videoPlaybackQualityMetrics() { return WTF::nullopt; } |
270 | |
271 | #if ENABLE(AVF_CAPTIONS) |
272 | virtual void notifyTrackModeChanged() { } |
273 | #endif |
274 | |
275 | virtual void notifyActiveSourceBuffersChanged() { } |
276 | |
277 | virtual void setShouldDisableSleep(bool) { } |
278 | |
279 | virtual void applicationWillResignActive() { } |
280 | virtual void applicationDidBecomeActive() { } |
281 | |
282 | #if USE(AVFOUNDATION) |
283 | virtual AVPlayer *objCAVFoundationAVPlayer() const { return nullptr; } |
284 | #endif |
285 | |
286 | virtual bool performTaskAtMediaTime(WTF::Function<void()>&&, MediaTime) { return false; } |
287 | |
288 | virtual bool shouldIgnoreIntrinsicSize() { return false; } |
289 | }; |
290 | |
291 | } |
292 | |
293 | #endif |
294 | |