| 1 | /* |
| 2 | * Copyright (C) 2007-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 "AudioTrackPrivate.h" |
| 31 | #include "ContentType.h" |
| 32 | #include "GraphicsTypes3D.h" |
| 33 | #include "InbandTextTrackPrivate.h" |
| 34 | #include "LayoutRect.h" |
| 35 | #include "LegacyCDMSession.h" |
| 36 | #include "MediaPlayerEnums.h" |
| 37 | #include "NativeImage.h" |
| 38 | #include "PlatformLayer.h" |
| 39 | #include "PlatformMediaResourceLoader.h" |
| 40 | #include "PlatformMediaSession.h" |
| 41 | #include "SecurityOriginHash.h" |
| 42 | #include "Timer.h" |
| 43 | #include <wtf/URL.h> |
| 44 | #include "VideoTrackPrivate.h" |
| 45 | #include <JavaScriptCore/Uint8Array.h> |
| 46 | #include <wtf/Function.h> |
| 47 | #include <wtf/HashSet.h> |
| 48 | #include <wtf/Logger.h> |
| 49 | #include <wtf/MediaTime.h> |
| 50 | #include <wtf/WallTime.h> |
| 51 | #include <wtf/text/StringHash.h> |
| 52 | |
| 53 | #if ENABLE(AVF_CAPTIONS) |
| 54 | #include "PlatformTextTrack.h" |
| 55 | #endif |
| 56 | |
| 57 | OBJC_CLASS AVPlayer; |
| 58 | OBJC_CLASS NSArray; |
| 59 | |
| 60 | namespace WebCore { |
| 61 | |
| 62 | class AudioSourceProvider; |
| 63 | class CDMInstance; |
| 64 | class CachedResourceLoader; |
| 65 | class GraphicsContext3D; |
| 66 | class GraphicsContext; |
| 67 | class LegacyCDMSessionClient; |
| 68 | class MediaPlaybackTarget; |
| 69 | class MediaPlayer; |
| 70 | class MediaPlayerPrivateInterface; |
| 71 | class MediaPlayerRequestInstallMissingPluginsCallback; |
| 72 | class MediaSourcePrivateClient; |
| 73 | class MediaStreamPrivate; |
| 74 | class PlatformTimeRanges; |
| 75 | class TextTrackRepresentation; |
| 76 | |
| 77 | struct Cookie; |
| 78 | struct GraphicsDeviceAdapter; |
| 79 | struct MediaPlayerFactory; |
| 80 | |
| 81 | struct MediaEngineSupportParameters { |
| 82 | ContentType type; |
| 83 | URL url; |
| 84 | bool isMediaSource { false }; |
| 85 | bool isMediaStream { false }; |
| 86 | Vector<ContentType> contentTypesRequiringHardwareSupport; |
| 87 | }; |
| 88 | |
| 89 | struct VideoPlaybackQualityMetrics { |
| 90 | uint32_t totalVideoFrames { 0 }; |
| 91 | uint32_t droppedVideoFrames { 0 }; |
| 92 | uint32_t corruptedVideoFrames { 0 }; |
| 93 | double totalFrameDelay { 0 }; |
| 94 | uint32_t displayCompositedVideoFrames { 0 }; |
| 95 | }; |
| 96 | |
| 97 | class MediaPlayerClient { |
| 98 | public: |
| 99 | virtual ~MediaPlayerClient() = default; |
| 100 | |
| 101 | // the network state has changed |
| 102 | virtual void mediaPlayerNetworkStateChanged(MediaPlayer*) { } |
| 103 | |
| 104 | // the ready state has changed |
| 105 | virtual void mediaPlayerReadyStateChanged(MediaPlayer*) { } |
| 106 | |
| 107 | // the volume state has changed |
| 108 | virtual void mediaPlayerVolumeChanged(MediaPlayer*) { } |
| 109 | |
| 110 | // the mute state has changed |
| 111 | virtual void mediaPlayerMuteChanged(MediaPlayer*) { } |
| 112 | |
| 113 | // time has jumped, eg. not as a result of normal playback |
| 114 | virtual void mediaPlayerTimeChanged(MediaPlayer*) { } |
| 115 | |
| 116 | // the media file duration has changed, or is now known |
| 117 | virtual void mediaPlayerDurationChanged(MediaPlayer*) { } |
| 118 | |
| 119 | // the playback rate has changed |
| 120 | virtual void mediaPlayerRateChanged(MediaPlayer*) { } |
| 121 | |
| 122 | // the play/pause status changed |
| 123 | virtual void mediaPlayerPlaybackStateChanged(MediaPlayer*) { } |
| 124 | |
| 125 | // The MediaPlayer has found potentially problematic media content. |
| 126 | // This is used internally to trigger swapping from a <video> |
| 127 | // element to an <embed> in standalone documents |
| 128 | virtual void mediaPlayerSawUnsupportedTracks(MediaPlayer*) { } |
| 129 | |
| 130 | // The MediaPlayer could not discover an engine which supports the requested resource. |
| 131 | virtual void mediaPlayerResourceNotSupported(MediaPlayer*) { } |
| 132 | |
| 133 | // Presentation-related methods |
| 134 | // a new frame of video is available |
| 135 | virtual void mediaPlayerRepaint(MediaPlayer*) { } |
| 136 | |
| 137 | // the movie size has changed |
| 138 | virtual void mediaPlayerSizeChanged(MediaPlayer*) { } |
| 139 | |
| 140 | virtual void mediaPlayerEngineUpdated(MediaPlayer*) { } |
| 141 | |
| 142 | // The first frame of video is available to render. A media engine need only make this callback if the |
| 143 | // first frame is not available immediately when prepareForRendering is called. |
| 144 | virtual void mediaPlayerFirstVideoFrameAvailable(MediaPlayer*) { } |
| 145 | |
| 146 | // A characteristic of the media file, eg. video, audio, closed captions, etc, has changed. |
| 147 | virtual void mediaPlayerCharacteristicChanged(MediaPlayer*) { } |
| 148 | |
| 149 | // whether the rendering system can accelerate the display of this MediaPlayer. |
| 150 | virtual bool mediaPlayerRenderingCanBeAccelerated(MediaPlayer*) { return false; } |
| 151 | |
| 152 | // called when the media player's rendering mode changed, which indicates a change in the |
| 153 | // availability of the platformLayer(). |
| 154 | virtual void mediaPlayerRenderingModeChanged(MediaPlayer*) { } |
| 155 | |
| 156 | // whether accelerated compositing is enabled for video rendering |
| 157 | virtual bool mediaPlayerAcceleratedCompositingEnabled() { return false; } |
| 158 | |
| 159 | virtual void mediaPlayerActiveSourceBuffersChanged(const MediaPlayer*) { } |
| 160 | |
| 161 | #if PLATFORM(WIN) && USE(AVFOUNDATION) |
| 162 | virtual GraphicsDeviceAdapter* mediaPlayerGraphicsDeviceAdapter(const MediaPlayer*) const { return nullptr; } |
| 163 | #endif |
| 164 | |
| 165 | #if ENABLE(LEGACY_ENCRYPTED_MEDIA) |
| 166 | virtual RefPtr<ArrayBuffer> mediaPlayerCachedKeyForKeyId(const String&) const { return nullptr; } |
| 167 | virtual bool mediaPlayerKeyNeeded(MediaPlayer*, Uint8Array*) { return false; } |
| 168 | virtual String mediaPlayerMediaKeysStorageDirectory() const { return emptyString(); } |
| 169 | #endif |
| 170 | |
| 171 | #if ENABLE(ENCRYPTED_MEDIA) |
| 172 | virtual void mediaPlayerInitializationDataEncountered(const String&, RefPtr<ArrayBuffer>&&) { } |
| 173 | virtual void mediaPlayerWaitingForKeyChanged() { } |
| 174 | #endif |
| 175 | |
| 176 | #if ENABLE(WIRELESS_PLAYBACK_TARGET) |
| 177 | virtual void mediaPlayerCurrentPlaybackTargetIsWirelessChanged(MediaPlayer*) { }; |
| 178 | #endif |
| 179 | |
| 180 | virtual String mediaPlayerReferrer() const { return String(); } |
| 181 | virtual String mediaPlayerUserAgent() const { return String(); } |
| 182 | virtual void mediaPlayerEnterFullscreen() { } |
| 183 | virtual void mediaPlayerExitFullscreen() { } |
| 184 | virtual bool mediaPlayerIsFullscreen() const { return false; } |
| 185 | virtual bool mediaPlayerIsFullscreenPermitted() const { return false; } |
| 186 | virtual bool mediaPlayerIsVideo() const { return false; } |
| 187 | virtual LayoutRect mediaPlayerContentBoxRect() const { return LayoutRect(); } |
| 188 | virtual float mediaPlayerContentsScale() const { return 1; } |
| 189 | virtual void mediaPlayerSetSize(const IntSize&) { } |
| 190 | virtual void mediaPlayerPause() { } |
| 191 | virtual void mediaPlayerPlay() { } |
| 192 | virtual bool mediaPlayerPlatformVolumeConfigurationRequired() const { return false; } |
| 193 | virtual bool mediaPlayerIsPaused() const { return true; } |
| 194 | virtual bool mediaPlayerIsLooping() const { return false; } |
| 195 | virtual CachedResourceLoader* mediaPlayerCachedResourceLoader() { return nullptr; } |
| 196 | virtual RefPtr<PlatformMediaResourceLoader> mediaPlayerCreateResourceLoader() { return nullptr; } |
| 197 | virtual bool doesHaveAttribute(const AtomicString&, AtomicString* = nullptr) const { return false; } |
| 198 | virtual bool mediaPlayerShouldUsePersistentCache() const { return true; } |
| 199 | virtual const String& mediaPlayerMediaCacheDirectory() const { return emptyString(); } |
| 200 | |
| 201 | #if ENABLE(VIDEO_TRACK) |
| 202 | virtual void mediaPlayerDidAddAudioTrack(AudioTrackPrivate&) { } |
| 203 | virtual void mediaPlayerDidAddTextTrack(InbandTextTrackPrivate&) { } |
| 204 | virtual void mediaPlayerDidAddVideoTrack(VideoTrackPrivate&) { } |
| 205 | virtual void mediaPlayerDidRemoveAudioTrack(AudioTrackPrivate&) { } |
| 206 | virtual void mediaPlayerDidRemoveTextTrack(InbandTextTrackPrivate&) { } |
| 207 | virtual void mediaPlayerDidRemoveVideoTrack(VideoTrackPrivate&) { } |
| 208 | |
| 209 | virtual void textTrackRepresentationBoundsChanged(const IntRect&) { } |
| 210 | #endif |
| 211 | |
| 212 | #if ENABLE(VIDEO_TRACK) && ENABLE(AVF_CAPTIONS) |
| 213 | virtual Vector<RefPtr<PlatformTextTrack>> outOfBandTrackSources() { return { }; } |
| 214 | #endif |
| 215 | |
| 216 | #if PLATFORM(IOS_FAMILY) |
| 217 | virtual String mediaPlayerNetworkInterfaceName() const { return String(); } |
| 218 | virtual bool mediaPlayerGetRawCookies(const URL&, Vector<Cookie>&) const { return false; } |
| 219 | #endif |
| 220 | |
| 221 | virtual void mediaPlayerHandlePlaybackCommand(PlatformMediaSession::RemoteControlCommandType) { } |
| 222 | |
| 223 | virtual String mediaPlayerSourceApplicationIdentifier() const { return emptyString(); } |
| 224 | |
| 225 | virtual bool mediaPlayerIsInMediaDocument() const { return false; } |
| 226 | virtual void mediaPlayerEngineFailedToLoad() const { } |
| 227 | |
| 228 | virtual double mediaPlayerRequestedPlaybackRate() const { return 0; } |
| 229 | virtual MediaPlayerEnums::VideoFullscreenMode mediaPlayerFullscreenMode() const { return MediaPlayerEnums::VideoFullscreenModeNone; } |
| 230 | virtual bool mediaPlayerIsVideoFullscreenStandby() const { return false; } |
| 231 | virtual Vector<String> mediaPlayerPreferredAudioCharacteristics() const { return Vector<String>(); } |
| 232 | |
| 233 | #if USE(GSTREAMER) |
| 234 | virtual void requestInstallMissingPlugins(const String&, const String&, MediaPlayerRequestInstallMissingPluginsCallback&) { }; |
| 235 | #endif |
| 236 | |
| 237 | virtual bool mediaPlayerShouldDisableSleep() const { return false; } |
| 238 | virtual const Vector<ContentType>& mediaContentTypesRequiringHardwareSupport() const; |
| 239 | virtual bool mediaPlayerShouldCheckHardwareSupport() const { return false; } |
| 240 | |
| 241 | #if !RELEASE_LOG_DISABLED |
| 242 | virtual const void* mediaPlayerLogIdentifier() { return nullptr; } |
| 243 | virtual const Logger& mediaPlayerLogger() = 0; |
| 244 | #endif |
| 245 | }; |
| 246 | |
| 247 | class MediaPlayer : public MediaPlayerEnums, public RefCounted<MediaPlayer> { |
| 248 | WTF_MAKE_NONCOPYABLE(MediaPlayer); WTF_MAKE_FAST_ALLOCATED; |
| 249 | public: |
| 250 | static Ref<MediaPlayer> create(MediaPlayerClient&); |
| 251 | virtual ~MediaPlayer(); |
| 252 | |
| 253 | void invalidate(); |
| 254 | |
| 255 | // Media engine support. |
| 256 | using MediaPlayerEnums::SupportsType; |
| 257 | static SupportsType supportsType(const MediaEngineSupportParameters&); |
| 258 | static void getSupportedTypes(HashSet<String, ASCIICaseInsensitiveHash>&); |
| 259 | static bool isAvailable(); |
| 260 | static HashSet<RefPtr<SecurityOrigin>> originsInMediaCache(const String& path); |
| 261 | static void clearMediaCache(const String& path, WallTime modifiedSince); |
| 262 | static void clearMediaCacheForOrigins(const String& path, const HashSet<RefPtr<SecurityOrigin>>&); |
| 263 | static bool supportsKeySystem(const String& keySystem, const String& mimeType); |
| 264 | |
| 265 | bool supportsPictureInPicture() const; |
| 266 | bool supportsFullscreen() const; |
| 267 | bool supportsScanning() const; |
| 268 | bool canSaveMediaData() const; |
| 269 | bool requiresImmediateCompositing() const; |
| 270 | bool doesHaveAttribute(const AtomicString&, AtomicString* value = nullptr) const; |
| 271 | PlatformLayer* platformLayer() const; |
| 272 | |
| 273 | #if PLATFORM(IOS_FAMILY) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) |
| 274 | void setVideoFullscreenLayer(PlatformLayer*, WTF::Function<void()>&& completionHandler = [] { }); |
| 275 | void setVideoFullscreenFrame(FloatRect); |
| 276 | void updateVideoFullscreenInlineImage(); |
| 277 | using MediaPlayerEnums::VideoGravity; |
| 278 | void setVideoFullscreenGravity(VideoGravity); |
| 279 | void setVideoFullscreenMode(VideoFullscreenMode); |
| 280 | VideoFullscreenMode fullscreenMode() const; |
| 281 | void videoFullscreenStandbyChanged(); |
| 282 | bool isVideoFullscreenStandby() const; |
| 283 | #endif |
| 284 | |
| 285 | #if PLATFORM(IOS_FAMILY) |
| 286 | NSArray *timedMetadata() const; |
| 287 | String accessLog() const; |
| 288 | String errorLog() const; |
| 289 | #endif |
| 290 | |
| 291 | FloatSize naturalSize(); |
| 292 | bool hasVideo() const; |
| 293 | bool hasAudio() const; |
| 294 | |
| 295 | bool inMediaDocument() const; |
| 296 | |
| 297 | IntSize size() const { return m_size; } |
| 298 | void setSize(const IntSize& size); |
| 299 | |
| 300 | bool load(const URL&, const ContentType&, const String& keySystem); |
| 301 | #if ENABLE(MEDIA_SOURCE) |
| 302 | bool load(const URL&, const ContentType&, MediaSourcePrivateClient*); |
| 303 | #endif |
| 304 | #if ENABLE(MEDIA_STREAM) |
| 305 | bool load(MediaStreamPrivate&); |
| 306 | #endif |
| 307 | void cancelLoad(); |
| 308 | |
| 309 | bool visible() const; |
| 310 | void setVisible(bool); |
| 311 | |
| 312 | void prepareToPlay(); |
| 313 | void play(); |
| 314 | void pause(); |
| 315 | |
| 316 | using MediaPlayerEnums::BufferingPolicy; |
| 317 | void setBufferingPolicy(BufferingPolicy); |
| 318 | |
| 319 | #if ENABLE(LEGACY_ENCRYPTED_MEDIA) |
| 320 | // Represents synchronous exceptions that can be thrown from the Encrypted Media methods. |
| 321 | // This is different from the asynchronous MediaKeyError. |
| 322 | enum MediaKeyException { NoError, InvalidPlayerState, KeySystemNotSupported }; |
| 323 | |
| 324 | std::unique_ptr<LegacyCDMSession> createSession(const String& keySystem, LegacyCDMSessionClient*); |
| 325 | void setCDMSession(LegacyCDMSession*); |
| 326 | void keyAdded(); |
| 327 | #endif |
| 328 | |
| 329 | #if ENABLE(ENCRYPTED_MEDIA) |
| 330 | void cdmInstanceAttached(CDMInstance&); |
| 331 | void cdmInstanceDetached(CDMInstance&); |
| 332 | void attemptToDecryptWithInstance(CDMInstance&); |
| 333 | #endif |
| 334 | |
| 335 | bool paused() const; |
| 336 | bool seeking() const; |
| 337 | |
| 338 | static double invalidTime() { return -1.0;} |
| 339 | MediaTime duration() const; |
| 340 | MediaTime currentTime() const; |
| 341 | void seek(const MediaTime&); |
| 342 | void seekWithTolerance(const MediaTime&, const MediaTime& negativeTolerance, const MediaTime& positiveTolerance); |
| 343 | |
| 344 | MediaTime startTime() const; |
| 345 | MediaTime initialTime() const; |
| 346 | |
| 347 | MediaTime getStartDate() const; |
| 348 | |
| 349 | double rate() const; |
| 350 | void setRate(double); |
| 351 | double requestedRate() const; |
| 352 | |
| 353 | bool preservesPitch() const; |
| 354 | void setPreservesPitch(bool); |
| 355 | |
| 356 | std::unique_ptr<PlatformTimeRanges> buffered(); |
| 357 | std::unique_ptr<PlatformTimeRanges> seekable(); |
| 358 | MediaTime minTimeSeekable(); |
| 359 | MediaTime maxTimeSeekable(); |
| 360 | |
| 361 | double seekableTimeRangesLastModifiedTime(); |
| 362 | double liveUpdateInterval(); |
| 363 | |
| 364 | bool didLoadingProgress(); |
| 365 | |
| 366 | double volume() const; |
| 367 | void setVolume(double); |
| 368 | bool platformVolumeConfigurationRequired() const { return client().mediaPlayerPlatformVolumeConfigurationRequired(); } |
| 369 | |
| 370 | bool muted() const; |
| 371 | void setMuted(bool); |
| 372 | |
| 373 | bool hasClosedCaptions() const; |
| 374 | void setClosedCaptionsVisible(bool closedCaptionsVisible); |
| 375 | |
| 376 | void paint(GraphicsContext&, const FloatRect&); |
| 377 | void paintCurrentFrameInContext(GraphicsContext&, const FloatRect&); |
| 378 | |
| 379 | // copyVideoTextureToPlatformTexture() is used to do the GPU-GPU textures copy without a readback to system memory. |
| 380 | // The first five parameters denote the corresponding GraphicsContext, destination texture, requested level, requested type and the required internalFormat for destination texture. |
| 381 | // The last two parameters premultiplyAlpha and flipY denote whether addtional premultiplyAlpha and flip operation are required during the copy. |
| 382 | // It returns true on success and false on failure. |
| 383 | |
| 384 | // In the GPU-GPU textures copy, the source texture(Video texture) should have valid target, internalFormat and size, etc. |
| 385 | // The destination texture may need to be resized to to the dimensions of the source texture or re-defined to the required internalFormat. |
| 386 | // The current restrictions require that format shoud be RGB or RGBA, type should be UNSIGNED_BYTE and level should be 0. It may be lifted in the future. |
| 387 | |
| 388 | bool copyVideoTextureToPlatformTexture(GraphicsContext3D*, Platform3DObject texture, GC3Denum target, GC3Dint level, GC3Denum internalFormat, GC3Denum format, GC3Denum type, bool premultiplyAlpha, bool flipY); |
| 389 | |
| 390 | NativeImagePtr nativeImageForCurrentTime(); |
| 391 | |
| 392 | using MediaPlayerEnums::NetworkState; |
| 393 | NetworkState networkState(); |
| 394 | |
| 395 | using MediaPlayerEnums::ReadyState; |
| 396 | ReadyState readyState(); |
| 397 | |
| 398 | using MediaPlayerEnums::MovieLoadType; |
| 399 | MovieLoadType movieLoadType() const; |
| 400 | |
| 401 | using MediaPlayerEnums::Preload; |
| 402 | Preload preload() const; |
| 403 | void setPreload(Preload); |
| 404 | |
| 405 | void networkStateChanged(); |
| 406 | void readyStateChanged(); |
| 407 | void volumeChanged(double); |
| 408 | void muteChanged(bool); |
| 409 | void timeChanged(); |
| 410 | void sizeChanged(); |
| 411 | void rateChanged(); |
| 412 | void playbackStateChanged(); |
| 413 | void durationChanged(); |
| 414 | void firstVideoFrameAvailable(); |
| 415 | void characteristicChanged(); |
| 416 | |
| 417 | void repaint(); |
| 418 | |
| 419 | MediaPlayerClient& client() const { return *m_client; } |
| 420 | |
| 421 | bool hasAvailableVideoFrame() const; |
| 422 | void prepareForRendering(); |
| 423 | |
| 424 | bool canLoadPoster() const; |
| 425 | void setPoster(const String&); |
| 426 | |
| 427 | #if USE(NATIVE_FULLSCREEN_VIDEO) |
| 428 | void enterFullscreen(); |
| 429 | void exitFullscreen(); |
| 430 | #endif |
| 431 | |
| 432 | #if ENABLE(WIRELESS_PLAYBACK_TARGET) |
| 433 | enum WirelessPlaybackTargetType { TargetTypeNone, TargetTypeAirPlay, TargetTypeTVOut }; |
| 434 | WirelessPlaybackTargetType wirelessPlaybackTargetType() const; |
| 435 | |
| 436 | String wirelessPlaybackTargetName() const; |
| 437 | |
| 438 | bool wirelessVideoPlaybackDisabled() const; |
| 439 | void setWirelessVideoPlaybackDisabled(bool); |
| 440 | |
| 441 | void currentPlaybackTargetIsWirelessChanged(); |
| 442 | void playbackTargetAvailabilityChanged(); |
| 443 | |
| 444 | bool isCurrentPlaybackTargetWireless() const; |
| 445 | bool canPlayToWirelessPlaybackTarget() const; |
| 446 | void setWirelessPlaybackTarget(Ref<MediaPlaybackTarget>&&); |
| 447 | |
| 448 | void setShouldPlayToPlaybackTarget(bool); |
| 449 | #endif |
| 450 | |
| 451 | double minFastReverseRate() const; |
| 452 | double maxFastForwardRate() const; |
| 453 | |
| 454 | #if USE(NATIVE_FULLSCREEN_VIDEO) |
| 455 | bool canEnterFullscreen() const; |
| 456 | #endif |
| 457 | |
| 458 | // whether accelerated rendering is supported by the media engine for the current media. |
| 459 | bool supportsAcceleratedRendering() const; |
| 460 | // called when the rendering system flips the into or out of accelerated rendering mode. |
| 461 | void acceleratedRenderingStateChanged(); |
| 462 | |
| 463 | bool shouldMaintainAspectRatio() const; |
| 464 | void setShouldMaintainAspectRatio(bool); |
| 465 | |
| 466 | #if PLATFORM(WIN) && USE(AVFOUNDATION) |
| 467 | GraphicsDeviceAdapter* graphicsDeviceAdapter() const; |
| 468 | #endif |
| 469 | |
| 470 | bool hasSingleSecurityOrigin() const; |
| 471 | bool didPassCORSAccessCheck() const; |
| 472 | bool wouldTaintOrigin(const SecurityOrigin&) const; |
| 473 | |
| 474 | MediaTime mediaTimeForTimeValue(const MediaTime&) const; |
| 475 | |
| 476 | double maximumDurationToCacheMediaTime() const; |
| 477 | |
| 478 | unsigned decodedFrameCount() const; |
| 479 | unsigned droppedFrameCount() const; |
| 480 | unsigned audioDecodedByteCount() const; |
| 481 | unsigned videoDecodedByteCount() const; |
| 482 | |
| 483 | void setPrivateBrowsingMode(bool); |
| 484 | |
| 485 | #if ENABLE(WEB_AUDIO) |
| 486 | AudioSourceProvider* audioSourceProvider(); |
| 487 | #endif |
| 488 | |
| 489 | #if ENABLE(LEGACY_ENCRYPTED_MEDIA) |
| 490 | RefPtr<ArrayBuffer> cachedKeyForKeyId(const String& keyId) const; |
| 491 | bool keyNeeded(Uint8Array* initData); |
| 492 | String mediaKeysStorageDirectory() const; |
| 493 | #endif |
| 494 | |
| 495 | #if ENABLE(ENCRYPTED_MEDIA) |
| 496 | void initializationDataEncountered(const String&, RefPtr<ArrayBuffer>&&); |
| 497 | void waitingForKeyChanged(); |
| 498 | bool waitingForKey() const; |
| 499 | #endif |
| 500 | |
| 501 | String referrer() const; |
| 502 | String userAgent() const; |
| 503 | |
| 504 | String engineDescription() const; |
| 505 | long platformErrorCode() const; |
| 506 | |
| 507 | CachedResourceLoader* cachedResourceLoader(); |
| 508 | RefPtr<PlatformMediaResourceLoader> createResourceLoader(); |
| 509 | |
| 510 | #if ENABLE(VIDEO_TRACK) |
| 511 | void addAudioTrack(AudioTrackPrivate&); |
| 512 | void addTextTrack(InbandTextTrackPrivate&); |
| 513 | void addVideoTrack(VideoTrackPrivate&); |
| 514 | void removeAudioTrack(AudioTrackPrivate&); |
| 515 | void removeTextTrack(InbandTextTrackPrivate&); |
| 516 | void removeVideoTrack(VideoTrackPrivate&); |
| 517 | |
| 518 | bool requiresTextTrackRepresentation() const; |
| 519 | void setTextTrackRepresentation(TextTrackRepresentation*); |
| 520 | void syncTextTrackBounds(); |
| 521 | void tracksChanged(); |
| 522 | #endif |
| 523 | |
| 524 | #if ENABLE(VIDEO_TRACK) && ENABLE(AVF_CAPTIONS) |
| 525 | void notifyTrackModeChanged(); |
| 526 | Vector<RefPtr<PlatformTextTrack>> outOfBandTrackSources(); |
| 527 | #endif |
| 528 | |
| 529 | #if PLATFORM(IOS_FAMILY) |
| 530 | String mediaPlayerNetworkInterfaceName() const; |
| 531 | bool getRawCookies(const URL&, Vector<Cookie>&) const; |
| 532 | #endif |
| 533 | |
| 534 | static void resetMediaEngines(); |
| 535 | |
| 536 | #if USE(GSTREAMER) |
| 537 | WEBCORE_EXPORT void simulateAudioInterruption(); |
| 538 | #endif |
| 539 | |
| 540 | WEBCORE_EXPORT void beginSimulatedHDCPError(); |
| 541 | WEBCORE_EXPORT void endSimulatedHDCPError(); |
| 542 | |
| 543 | String languageOfPrimaryAudioTrack() const; |
| 544 | |
| 545 | size_t () const; |
| 546 | |
| 547 | unsigned long long fileSize() const; |
| 548 | |
| 549 | Optional<VideoPlaybackQualityMetrics> videoPlaybackQualityMetrics(); |
| 550 | |
| 551 | void handlePlaybackCommand(PlatformMediaSession::RemoteControlCommandType); |
| 552 | String sourceApplicationIdentifier() const; |
| 553 | Vector<String> preferredAudioCharacteristics() const; |
| 554 | |
| 555 | bool ended() const; |
| 556 | |
| 557 | void setShouldDisableSleep(bool); |
| 558 | bool shouldDisableSleep() const; |
| 559 | |
| 560 | String contentMIMEType() const { return m_contentType.containerType(); } |
| 561 | String contentTypeCodecs() const { return m_contentType.parameter(ContentType::codecsParameter()); } |
| 562 | bool contentMIMETypeWasInferredFromExtension() const { return m_contentMIMETypeWasInferredFromExtension; } |
| 563 | |
| 564 | const Vector<ContentType>& mediaContentTypesRequiringHardwareSupport() const; |
| 565 | bool shouldCheckHardwareSupport() const; |
| 566 | |
| 567 | #if !RELEASE_LOG_DISABLED |
| 568 | const Logger& mediaPlayerLogger(); |
| 569 | const void* mediaPlayerLogIdentifier() { return client().mediaPlayerLogIdentifier(); } |
| 570 | #endif |
| 571 | |
| 572 | void applicationWillResignActive(); |
| 573 | void applicationDidBecomeActive(); |
| 574 | |
| 575 | #if USE(AVFOUNDATION) |
| 576 | WEBCORE_EXPORT AVPlayer *objCAVFoundationAVPlayer() const; |
| 577 | #endif |
| 578 | |
| 579 | bool performTaskAtMediaTime(WTF::Function<void()>&&, MediaTime); |
| 580 | |
| 581 | bool shouldIgnoreIntrinsicSize(); |
| 582 | |
| 583 | private: |
| 584 | MediaPlayer(MediaPlayerClient&); |
| 585 | |
| 586 | const MediaPlayerFactory* nextBestMediaEngine(const MediaPlayerFactory*) const; |
| 587 | void loadWithNextMediaEngine(const MediaPlayerFactory*); |
| 588 | void reloadTimerFired(); |
| 589 | |
| 590 | MediaPlayerClient* m_client; |
| 591 | Timer m_reloadTimer; |
| 592 | std::unique_ptr<MediaPlayerPrivateInterface> m_private; |
| 593 | const MediaPlayerFactory* m_currentMediaEngine { nullptr }; |
| 594 | URL m_url; |
| 595 | ContentType m_contentType; |
| 596 | String m_keySystem; |
| 597 | IntSize m_size; |
| 598 | Preload m_preload { Auto }; |
| 599 | double m_volume { 1 }; |
| 600 | bool m_visible { false }; |
| 601 | bool m_muted { false }; |
| 602 | bool m_preservesPitch { true }; |
| 603 | bool m_privateBrowsing { false }; |
| 604 | bool m_shouldPrepareToRender { false }; |
| 605 | bool m_contentMIMETypeWasInferredFromExtension { false }; |
| 606 | bool m_initializingMediaEngine { false }; |
| 607 | |
| 608 | #if ENABLE(MEDIA_SOURCE) |
| 609 | RefPtr<MediaSourcePrivateClient> m_mediaSource; |
| 610 | #endif |
| 611 | #if ENABLE(MEDIA_STREAM) |
| 612 | RefPtr<MediaStreamPrivate> m_mediaStream; |
| 613 | #endif |
| 614 | }; |
| 615 | |
| 616 | using CreateMediaEnginePlayer = WTF::Function<std::unique_ptr<MediaPlayerPrivateInterface> (MediaPlayer*)>; |
| 617 | typedef void (*MediaEngineSupportedTypes)(HashSet<String, ASCIICaseInsensitiveHash>& types); |
| 618 | typedef MediaPlayer::SupportsType (*MediaEngineSupportsType)(const MediaEngineSupportParameters& parameters); |
| 619 | typedef HashSet<RefPtr<SecurityOrigin>> (*MediaEngineOriginsInMediaCache)(const String& path); |
| 620 | typedef void (*MediaEngineClearMediaCache)(const String& path, WallTime modifiedSince); |
| 621 | typedef void (*MediaEngineClearMediaCacheForOrigins)(const String& path, const HashSet<RefPtr<SecurityOrigin>>&); |
| 622 | typedef bool (*MediaEngineSupportsKeySystem)(const String& keySystem, const String& mimeType); |
| 623 | |
| 624 | typedef void (*MediaEngineRegistrar)(CreateMediaEnginePlayer&&, MediaEngineSupportedTypes, MediaEngineSupportsType, |
| 625 | MediaEngineOriginsInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForOrigins, MediaEngineSupportsKeySystem); |
| 626 | typedef void (*MediaEngineRegister)(MediaEngineRegistrar); |
| 627 | |
| 628 | class MediaPlayerFactorySupport { |
| 629 | public: |
| 630 | WEBCORE_EXPORT static void callRegisterMediaEngine(MediaEngineRegister); |
| 631 | }; |
| 632 | |
| 633 | } // namespace WebCore |
| 634 | |
| 635 | namespace WTF { |
| 636 | |
| 637 | template<typename Type> |
| 638 | struct LogArgument; |
| 639 | |
| 640 | template <> |
| 641 | struct LogArgument<MediaTime> { |
| 642 | static String toString(const MediaTime& time) |
| 643 | { |
| 644 | return time.toJSONString(); |
| 645 | } |
| 646 | }; |
| 647 | |
| 648 | template <> |
| 649 | struct LogArgument<MediaTimeRange> { |
| 650 | static String toString(const MediaTimeRange& range) |
| 651 | { |
| 652 | return range.toJSONString(); |
| 653 | } |
| 654 | }; |
| 655 | |
| 656 | } |
| 657 | |
| 658 | #endif // ENABLE(VIDEO) |
| 659 | |