| 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 | #include "config.h" |
| 27 | #include "MediaPlayer.h" |
| 28 | |
| 29 | #if ENABLE(VIDEO) |
| 30 | |
| 31 | #include "ContentType.h" |
| 32 | #include "DeprecatedGlobalSettings.h" |
| 33 | #include "Document.h" |
| 34 | #include "IntRect.h" |
| 35 | #include "Logging.h" |
| 36 | #include "MIMETypeRegistry.h" |
| 37 | #include "MediaPlayerPrivate.h" |
| 38 | #include "PlatformTimeRanges.h" |
| 39 | #include <wtf/NeverDestroyed.h> |
| 40 | #include <wtf/text/CString.h> |
| 41 | |
| 42 | #if ENABLE(VIDEO_TRACK) |
| 43 | #include "InbandTextTrackPrivate.h" |
| 44 | #endif |
| 45 | |
| 46 | #if ENABLE(MEDIA_SOURCE) |
| 47 | #include "MediaSourcePrivateClient.h" |
| 48 | #endif |
| 49 | |
| 50 | #if ENABLE(MEDIA_STREAM) |
| 51 | #include "MediaStreamPrivate.h" |
| 52 | #endif |
| 53 | |
| 54 | #if USE(GSTREAMER) |
| 55 | #include "MediaPlayerPrivateGStreamer.h" |
| 56 | #define PlatformMediaEngineClassName MediaPlayerPrivateGStreamer |
| 57 | #if ENABLE(MEDIA_SOURCE) && ENABLE(VIDEO_TRACK) |
| 58 | #include "MediaPlayerPrivateGStreamerMSE.h" |
| 59 | #endif |
| 60 | #endif // USE(GSTREAMER) |
| 61 | |
| 62 | #if USE(MEDIA_FOUNDATION) |
| 63 | #include "MediaPlayerPrivateMediaFoundation.h" |
| 64 | #define PlatformMediaEngineClassName MediaPlayerPrivateMediaFoundation |
| 65 | #endif |
| 66 | |
| 67 | #if PLATFORM(COCOA) |
| 68 | |
| 69 | #if USE(AVFOUNDATION) |
| 70 | #include "MediaPlayerPrivateAVFoundationObjC.h" |
| 71 | #endif |
| 72 | |
| 73 | #if ENABLE(MEDIA_SOURCE) && USE(AVFOUNDATION) |
| 74 | #include "MediaPlayerPrivateMediaSourceAVFObjC.h" |
| 75 | #endif |
| 76 | |
| 77 | #if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION) |
| 78 | #include "MediaPlayerPrivateMediaStreamAVFObjC.h" |
| 79 | #endif |
| 80 | |
| 81 | #endif // PLATFORM(COCOA) |
| 82 | |
| 83 | #if PLATFORM(WIN) && USE(AVFOUNDATION) && !USE(GSTREAMER) |
| 84 | #include "MediaPlayerPrivateAVFoundationCF.h" |
| 85 | #endif |
| 86 | |
| 87 | #if USE(EXTERNAL_HOLEPUNCH) |
| 88 | #include "MediaPlayerPrivateHolePunch.h" |
| 89 | #endif |
| 90 | |
| 91 | namespace WebCore { |
| 92 | |
| 93 | #if !RELEASE_LOG_DISABLED |
| 94 | static RefPtr<Logger>& nullLogger() |
| 95 | { |
| 96 | static NeverDestroyed<RefPtr<Logger>> logger; |
| 97 | return logger; |
| 98 | } |
| 99 | #endif |
| 100 | |
| 101 | // a null player to make MediaPlayer logic simpler |
| 102 | |
| 103 | class NullMediaPlayerPrivate : public MediaPlayerPrivateInterface { |
| 104 | public: |
| 105 | explicit NullMediaPlayerPrivate(MediaPlayer*) { } |
| 106 | |
| 107 | void load(const String&) override { } |
| 108 | #if ENABLE(MEDIA_SOURCE) |
| 109 | void load(const String&, MediaSourcePrivateClient*) override { } |
| 110 | #endif |
| 111 | #if ENABLE(MEDIA_STREAM) |
| 112 | void load(MediaStreamPrivate&) override { } |
| 113 | #endif |
| 114 | void cancelLoad() override { } |
| 115 | |
| 116 | void prepareToPlay() override { } |
| 117 | void play() override { } |
| 118 | void pause() override { } |
| 119 | |
| 120 | PlatformLayer* platformLayer() const override { return 0; } |
| 121 | |
| 122 | FloatSize naturalSize() const override { return FloatSize(); } |
| 123 | |
| 124 | bool hasVideo() const override { return false; } |
| 125 | bool hasAudio() const override { return false; } |
| 126 | |
| 127 | void setVisible(bool) override { } |
| 128 | |
| 129 | double durationDouble() const override { return 0; } |
| 130 | |
| 131 | double currentTimeDouble() const override { return 0; } |
| 132 | void seekDouble(double) override { } |
| 133 | bool seeking() const override { return false; } |
| 134 | |
| 135 | void setRateDouble(double) override { } |
| 136 | void setPreservesPitch(bool) override { } |
| 137 | bool paused() const override { return true; } |
| 138 | |
| 139 | void setVolumeDouble(double) override { } |
| 140 | |
| 141 | bool supportsMuting() const override { return false; } |
| 142 | void setMuted(bool) override { } |
| 143 | |
| 144 | bool hasClosedCaptions() const override { return false; } |
| 145 | void setClosedCaptionsVisible(bool) override { }; |
| 146 | |
| 147 | MediaPlayer::NetworkState networkState() const override { return MediaPlayer::Empty; } |
| 148 | MediaPlayer::ReadyState readyState() const override { return MediaPlayer::HaveNothing; } |
| 149 | |
| 150 | float maxTimeSeekable() const override { return 0; } |
| 151 | double minTimeSeekable() const override { return 0; } |
| 152 | std::unique_ptr<PlatformTimeRanges> buffered() const override { return std::make_unique<PlatformTimeRanges>(); } |
| 153 | |
| 154 | double seekableTimeRangesLastModifiedTime() const override { return 0; } |
| 155 | double liveUpdateInterval() const override { return 0; } |
| 156 | |
| 157 | unsigned long long totalBytes() const override { return 0; } |
| 158 | bool didLoadingProgress() const override { return false; } |
| 159 | |
| 160 | void setSize(const IntSize&) override { } |
| 161 | |
| 162 | void paint(GraphicsContext&, const FloatRect&) override { } |
| 163 | |
| 164 | bool canLoadPoster() const override { return false; } |
| 165 | void setPoster(const String&) override { } |
| 166 | |
| 167 | bool hasSingleSecurityOrigin() const override { return true; } |
| 168 | }; |
| 169 | |
| 170 | class NullMediaPlayerClient : public MediaPlayerClient { |
| 171 | public: |
| 172 | #if !RELEASE_LOG_DISABLED |
| 173 | const Logger& mediaPlayerLogger() final |
| 174 | { |
| 175 | if (!nullLogger().get()) { |
| 176 | nullLogger() = Logger::create(this); |
| 177 | nullLogger()->setEnabled(this, false); |
| 178 | } |
| 179 | |
| 180 | return *nullLogger().get(); |
| 181 | } |
| 182 | #endif |
| 183 | }; |
| 184 | |
| 185 | const Vector<ContentType>& MediaPlayerClient::mediaContentTypesRequiringHardwareSupport() const |
| 186 | { |
| 187 | static NeverDestroyed<Vector<ContentType>> contentTypes; |
| 188 | return contentTypes; |
| 189 | } |
| 190 | |
| 191 | static MediaPlayerClient& nullMediaPlayerClient() |
| 192 | { |
| 193 | static NeverDestroyed<NullMediaPlayerClient> client; |
| 194 | return client.get(); |
| 195 | } |
| 196 | |
| 197 | // engine support |
| 198 | |
| 199 | struct MediaPlayerFactory { |
| 200 | CreateMediaEnginePlayer constructor; |
| 201 | MediaEngineSupportedTypes getSupportedTypes; |
| 202 | MediaEngineSupportsType supportsTypeAndCodecs; |
| 203 | MediaEngineOriginsInMediaCache originsInMediaCache; |
| 204 | MediaEngineClearMediaCache clearMediaCache; |
| 205 | MediaEngineClearMediaCacheForOrigins clearMediaCacheForOrigins; |
| 206 | MediaEngineSupportsKeySystem supportsKeySystem; |
| 207 | }; |
| 208 | |
| 209 | static void addMediaEngine(CreateMediaEnginePlayer&&, MediaEngineSupportedTypes, MediaEngineSupportsType, MediaEngineOriginsInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForOrigins, MediaEngineSupportsKeySystem); |
| 210 | |
| 211 | static Lock mediaEngineVectorLock; |
| 212 | |
| 213 | static bool& haveMediaEnginesVector() |
| 214 | { |
| 215 | static bool haveVector; |
| 216 | return haveVector; |
| 217 | } |
| 218 | |
| 219 | static Vector<MediaPlayerFactory>& mutableInstalledMediaEnginesVector() |
| 220 | { |
| 221 | static NeverDestroyed<Vector<MediaPlayerFactory>> installedEngines; |
| 222 | return installedEngines; |
| 223 | } |
| 224 | |
| 225 | static void buildMediaEnginesVector() |
| 226 | { |
| 227 | ASSERT(mediaEngineVectorLock.isLocked()); |
| 228 | |
| 229 | #if USE(AVFOUNDATION) |
| 230 | if (DeprecatedGlobalSettings::isAVFoundationEnabled()) { |
| 231 | |
| 232 | #if PLATFORM(COCOA) |
| 233 | MediaPlayerPrivateAVFoundationObjC::registerMediaEngine(addMediaEngine); |
| 234 | #endif |
| 235 | |
| 236 | #if ENABLE(MEDIA_SOURCE) |
| 237 | MediaPlayerPrivateMediaSourceAVFObjC::registerMediaEngine(addMediaEngine); |
| 238 | #endif |
| 239 | |
| 240 | #if ENABLE(MEDIA_STREAM) |
| 241 | MediaPlayerPrivateMediaStreamAVFObjC::registerMediaEngine(addMediaEngine); |
| 242 | #endif |
| 243 | |
| 244 | #if PLATFORM(WIN) |
| 245 | MediaPlayerPrivateAVFoundationCF::registerMediaEngine(addMediaEngine); |
| 246 | #endif |
| 247 | } |
| 248 | #endif // USE(AVFOUNDATION) |
| 249 | |
| 250 | #if defined(PlatformMediaEngineClassName) |
| 251 | #if USE(GSTREAMER) |
| 252 | if (DeprecatedGlobalSettings::isGStreamerEnabled()) |
| 253 | #endif |
| 254 | PlatformMediaEngineClassName::registerMediaEngine(addMediaEngine); |
| 255 | #endif |
| 256 | |
| 257 | #if USE(GSTREAMER) && ENABLE(MEDIA_SOURCE) && ENABLE(VIDEO_TRACK) |
| 258 | if (DeprecatedGlobalSettings::isGStreamerEnabled()) |
| 259 | MediaPlayerPrivateGStreamerMSE::registerMediaEngine(addMediaEngine); |
| 260 | #endif |
| 261 | |
| 262 | #if USE(EXTERNAL_HOLEPUNCH) |
| 263 | MediaPlayerPrivateHolePunch::registerMediaEngine(addMediaEngine); |
| 264 | #endif |
| 265 | |
| 266 | haveMediaEnginesVector() = true; |
| 267 | } |
| 268 | |
| 269 | static const Vector<MediaPlayerFactory>& installedMediaEngines() |
| 270 | { |
| 271 | { |
| 272 | auto locker = holdLock(mediaEngineVectorLock); |
| 273 | if (!haveMediaEnginesVector()) |
| 274 | buildMediaEnginesVector(); |
| 275 | } |
| 276 | |
| 277 | return mutableInstalledMediaEnginesVector(); |
| 278 | } |
| 279 | |
| 280 | static void addMediaEngine(CreateMediaEnginePlayer&& constructor, MediaEngineSupportedTypes getSupportedTypes, MediaEngineSupportsType supportsType, |
| 281 | MediaEngineOriginsInMediaCache originsInMediaCache, MediaEngineClearMediaCache clearMediaCache, MediaEngineClearMediaCacheForOrigins clearMediaCacheForOrigins, MediaEngineSupportsKeySystem supportsKeySystem) |
| 282 | { |
| 283 | ASSERT(constructor); |
| 284 | ASSERT(getSupportedTypes); |
| 285 | ASSERT(supportsType); |
| 286 | |
| 287 | mutableInstalledMediaEnginesVector().append(MediaPlayerFactory { WTFMove(constructor), getSupportedTypes, supportsType, originsInMediaCache, clearMediaCache, clearMediaCacheForOrigins, supportsKeySystem }); |
| 288 | } |
| 289 | |
| 290 | static const AtomicString& applicationOctetStream() |
| 291 | { |
| 292 | static NeverDestroyed<const AtomicString> applicationOctetStream("application/octet-stream" , AtomicString::ConstructFromLiteral); |
| 293 | return applicationOctetStream; |
| 294 | } |
| 295 | |
| 296 | static const AtomicString& textPlain() |
| 297 | { |
| 298 | static NeverDestroyed<const AtomicString> textPlain("text/plain" , AtomicString::ConstructFromLiteral); |
| 299 | return textPlain; |
| 300 | } |
| 301 | |
| 302 | static const MediaPlayerFactory* bestMediaEngineForSupportParameters(const MediaEngineSupportParameters& parameters, const MediaPlayerFactory* current = nullptr) |
| 303 | { |
| 304 | if (parameters.type.isEmpty() && !parameters.isMediaSource && !parameters.isMediaStream) |
| 305 | return nullptr; |
| 306 | |
| 307 | // 4.8.10.3 MIME types - In the absence of a specification to the contrary, the MIME type "application/octet-stream" |
| 308 | // when used with parameters, e.g. "application/octet-stream;codecs=theora", is a type that the user agent knows |
| 309 | // it cannot render. |
| 310 | if (parameters.type.containerType() == applicationOctetStream()) { |
| 311 | if (!parameters.type.codecs().isEmpty()) |
| 312 | return nullptr; |
| 313 | } |
| 314 | |
| 315 | const MediaPlayerFactory* foundEngine = nullptr; |
| 316 | MediaPlayer::SupportsType supported = MediaPlayer::IsNotSupported; |
| 317 | for (auto& engine : installedMediaEngines()) { |
| 318 | if (current) { |
| 319 | if (current == &engine) |
| 320 | current = nullptr; |
| 321 | continue; |
| 322 | } |
| 323 | MediaPlayer::SupportsType engineSupport = engine.supportsTypeAndCodecs(parameters); |
| 324 | if (engineSupport > supported) { |
| 325 | supported = engineSupport; |
| 326 | foundEngine = &engine; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | return foundEngine; |
| 331 | } |
| 332 | |
| 333 | static const MediaPlayerFactory* nextMediaEngine(const MediaPlayerFactory* current) |
| 334 | { |
| 335 | auto& engines = installedMediaEngines(); |
| 336 | if (engines.isEmpty()) |
| 337 | return nullptr; |
| 338 | |
| 339 | if (!current) |
| 340 | return &engines.first(); |
| 341 | |
| 342 | size_t currentIndex = current - &engines.first(); |
| 343 | if (currentIndex + 1 >= engines.size()) |
| 344 | return nullptr; |
| 345 | |
| 346 | return &engines[currentIndex + 1]; |
| 347 | } |
| 348 | |
| 349 | // media player |
| 350 | |
| 351 | Ref<MediaPlayer> MediaPlayer::create(MediaPlayerClient& client) |
| 352 | { |
| 353 | return adoptRef(*new MediaPlayer(client)); |
| 354 | } |
| 355 | |
| 356 | MediaPlayer::MediaPlayer(MediaPlayerClient& client) |
| 357 | : m_client(&client) |
| 358 | , m_reloadTimer(*this, &MediaPlayer::reloadTimerFired) |
| 359 | , m_private(std::make_unique<NullMediaPlayerPrivate>(this)) |
| 360 | { |
| 361 | } |
| 362 | |
| 363 | MediaPlayer::~MediaPlayer() |
| 364 | { |
| 365 | ASSERT(!m_initializingMediaEngine); |
| 366 | } |
| 367 | |
| 368 | void MediaPlayer::invalidate() |
| 369 | { |
| 370 | m_client = &nullMediaPlayerClient(); |
| 371 | } |
| 372 | |
| 373 | bool MediaPlayer::load(const URL& url, const ContentType& contentType, const String& keySystem) |
| 374 | { |
| 375 | ASSERT(!m_reloadTimer.isActive()); |
| 376 | |
| 377 | // Protect against MediaPlayer being destroyed during a MediaPlayerClient callback. |
| 378 | Ref<MediaPlayer> protectedThis(*this); |
| 379 | |
| 380 | m_contentType = contentType; |
| 381 | m_url = url; |
| 382 | m_keySystem = keySystem.convertToASCIILowercase(); |
| 383 | m_contentMIMETypeWasInferredFromExtension = false; |
| 384 | |
| 385 | #if ENABLE(MEDIA_SOURCE) |
| 386 | m_mediaSource = nullptr; |
| 387 | #endif |
| 388 | #if ENABLE(MEDIA_STREAM) |
| 389 | m_mediaStream = nullptr; |
| 390 | #endif |
| 391 | |
| 392 | // If the MIME type is missing or is not meaningful, try to figure it out from the URL. |
| 393 | AtomicString containerType = m_contentType.containerType(); |
| 394 | if (containerType.isEmpty() || containerType == applicationOctetStream() || containerType == textPlain()) { |
| 395 | if (m_url.protocolIsData()) |
| 396 | m_contentType = ContentType(mimeTypeFromDataURL(m_url.string())); |
| 397 | else { |
| 398 | String lastPathComponent = url.lastPathComponent(); |
| 399 | size_t pos = lastPathComponent.reverseFind('.'); |
| 400 | if (pos != notFound) { |
| 401 | String extension = lastPathComponent.substring(pos + 1); |
| 402 | String mediaType = MIMETypeRegistry::getMediaMIMETypeForExtension(extension); |
| 403 | if (!mediaType.isEmpty()) { |
| 404 | m_contentType = ContentType { WTFMove(mediaType) }; |
| 405 | m_contentMIMETypeWasInferredFromExtension = true; |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | loadWithNextMediaEngine(nullptr); |
| 412 | return m_currentMediaEngine; |
| 413 | } |
| 414 | |
| 415 | #if ENABLE(MEDIA_SOURCE) |
| 416 | bool MediaPlayer::load(const URL& url, const ContentType& contentType, MediaSourcePrivateClient* mediaSource) |
| 417 | { |
| 418 | ASSERT(!m_reloadTimer.isActive()); |
| 419 | ASSERT(mediaSource); |
| 420 | |
| 421 | m_mediaSource = mediaSource; |
| 422 | m_contentType = contentType; |
| 423 | m_url = url; |
| 424 | m_keySystem = emptyString(); |
| 425 | m_contentMIMETypeWasInferredFromExtension = false; |
| 426 | loadWithNextMediaEngine(nullptr); |
| 427 | return m_currentMediaEngine; |
| 428 | } |
| 429 | #endif |
| 430 | |
| 431 | #if ENABLE(MEDIA_STREAM) |
| 432 | bool MediaPlayer::load(MediaStreamPrivate& mediaStream) |
| 433 | { |
| 434 | ASSERT(!m_reloadTimer.isActive()); |
| 435 | |
| 436 | m_mediaStream = &mediaStream; |
| 437 | m_keySystem = emptyString(); |
| 438 | m_contentType = { }; |
| 439 | m_contentMIMETypeWasInferredFromExtension = false; |
| 440 | loadWithNextMediaEngine(nullptr); |
| 441 | return m_currentMediaEngine; |
| 442 | } |
| 443 | #endif |
| 444 | |
| 445 | const MediaPlayerFactory* MediaPlayer::nextBestMediaEngine(const MediaPlayerFactory* current) const |
| 446 | { |
| 447 | MediaEngineSupportParameters parameters; |
| 448 | parameters.type = m_contentType; |
| 449 | parameters.url = m_url; |
| 450 | #if ENABLE(MEDIA_SOURCE) |
| 451 | parameters.isMediaSource = !!m_mediaSource; |
| 452 | #endif |
| 453 | #if ENABLE(MEDIA_STREAM) |
| 454 | parameters.isMediaStream = !!m_mediaStream; |
| 455 | #endif |
| 456 | |
| 457 | return bestMediaEngineForSupportParameters(parameters, current); |
| 458 | } |
| 459 | |
| 460 | void MediaPlayer::loadWithNextMediaEngine(const MediaPlayerFactory* current) |
| 461 | { |
| 462 | #if ENABLE(MEDIA_SOURCE) |
| 463 | #define MEDIASOURCE m_mediaSource |
| 464 | #else |
| 465 | #define MEDIASOURCE 0 |
| 466 | #endif |
| 467 | |
| 468 | #if ENABLE(MEDIA_STREAM) |
| 469 | #define MEDIASTREAM m_mediaStream |
| 470 | #else |
| 471 | #define MEDIASTREAM 0 |
| 472 | #endif |
| 473 | |
| 474 | ASSERT(!m_initializingMediaEngine); |
| 475 | m_initializingMediaEngine = true; |
| 476 | |
| 477 | const MediaPlayerFactory* engine = nullptr; |
| 478 | |
| 479 | if (!m_contentType.isEmpty() || MEDIASTREAM || MEDIASOURCE) |
| 480 | engine = nextBestMediaEngine(current); |
| 481 | |
| 482 | // If no MIME type is specified or the type was inferred from the file extension, just use the next engine. |
| 483 | if (!engine && (m_contentType.isEmpty() || m_contentMIMETypeWasInferredFromExtension)) |
| 484 | engine = nextMediaEngine(current); |
| 485 | |
| 486 | // Don't delete and recreate the player unless it comes from a different engine. |
| 487 | if (!engine) { |
| 488 | LOG(Media, "MediaPlayer::loadWithNextMediaEngine - no media engine found for type \"%s\"" , m_contentType.raw().utf8().data()); |
| 489 | m_currentMediaEngine = engine; |
| 490 | m_private = nullptr; |
| 491 | } else if (m_currentMediaEngine != engine) { |
| 492 | m_currentMediaEngine = engine; |
| 493 | m_private = engine->constructor(this); |
| 494 | client().mediaPlayerEngineUpdated(this); |
| 495 | m_private->setPrivateBrowsingMode(m_privateBrowsing); |
| 496 | m_private->setPreload(m_preload); |
| 497 | m_private->setPreservesPitch(preservesPitch()); |
| 498 | if (m_shouldPrepareToRender) |
| 499 | m_private->prepareForRendering(); |
| 500 | } |
| 501 | |
| 502 | if (m_private) { |
| 503 | #if ENABLE(MEDIA_SOURCE) |
| 504 | if (m_mediaSource) |
| 505 | m_private->load(m_url.string(), m_mediaSource.get()); |
| 506 | else |
| 507 | #endif |
| 508 | #if ENABLE(MEDIA_STREAM) |
| 509 | if (m_mediaStream) |
| 510 | m_private->load(*m_mediaStream); |
| 511 | else |
| 512 | #endif |
| 513 | m_private->load(m_url.string()); |
| 514 | } else { |
| 515 | m_private = std::make_unique<NullMediaPlayerPrivate>(this); |
| 516 | client().mediaPlayerEngineUpdated(this); |
| 517 | client().mediaPlayerResourceNotSupported(this); |
| 518 | } |
| 519 | |
| 520 | m_initializingMediaEngine = false; |
| 521 | } |
| 522 | |
| 523 | bool MediaPlayer::hasAvailableVideoFrame() const |
| 524 | { |
| 525 | return m_private->hasAvailableVideoFrame(); |
| 526 | } |
| 527 | |
| 528 | void MediaPlayer::prepareForRendering() |
| 529 | { |
| 530 | m_shouldPrepareToRender = true; |
| 531 | m_private->prepareForRendering(); |
| 532 | } |
| 533 | |
| 534 | bool MediaPlayer::canLoadPoster() const |
| 535 | { |
| 536 | return m_private->canLoadPoster(); |
| 537 | } |
| 538 | |
| 539 | void MediaPlayer::setPoster(const String& url) |
| 540 | { |
| 541 | m_private->setPoster(url); |
| 542 | } |
| 543 | |
| 544 | void MediaPlayer::cancelLoad() |
| 545 | { |
| 546 | m_private->cancelLoad(); |
| 547 | } |
| 548 | |
| 549 | void MediaPlayer::prepareToPlay() |
| 550 | { |
| 551 | Ref<MediaPlayer> protectedThis(*this); |
| 552 | |
| 553 | m_private->prepareToPlay(); |
| 554 | } |
| 555 | |
| 556 | void MediaPlayer::play() |
| 557 | { |
| 558 | m_private->play(); |
| 559 | } |
| 560 | |
| 561 | void MediaPlayer::pause() |
| 562 | { |
| 563 | m_private->pause(); |
| 564 | } |
| 565 | |
| 566 | void MediaPlayer::setBufferingPolicy(BufferingPolicy policy) |
| 567 | { |
| 568 | m_private->setBufferingPolicy(policy); |
| 569 | } |
| 570 | |
| 571 | #if ENABLE(LEGACY_ENCRYPTED_MEDIA) |
| 572 | |
| 573 | std::unique_ptr<LegacyCDMSession> MediaPlayer::createSession(const String& keySystem, LegacyCDMSessionClient* client) |
| 574 | { |
| 575 | return m_private->createSession(keySystem, client); |
| 576 | } |
| 577 | |
| 578 | void MediaPlayer::setCDMSession(LegacyCDMSession* session) |
| 579 | { |
| 580 | m_private->setCDMSession(session); |
| 581 | } |
| 582 | |
| 583 | void MediaPlayer::keyAdded() |
| 584 | { |
| 585 | m_private->keyAdded(); |
| 586 | } |
| 587 | |
| 588 | #endif |
| 589 | |
| 590 | #if ENABLE(ENCRYPTED_MEDIA) |
| 591 | |
| 592 | void MediaPlayer::cdmInstanceAttached(CDMInstance& instance) |
| 593 | { |
| 594 | m_private->cdmInstanceAttached(instance); |
| 595 | } |
| 596 | |
| 597 | void MediaPlayer::cdmInstanceDetached(CDMInstance& instance) |
| 598 | { |
| 599 | m_private->cdmInstanceDetached(instance); |
| 600 | } |
| 601 | |
| 602 | void MediaPlayer::attemptToDecryptWithInstance(CDMInstance& instance) |
| 603 | { |
| 604 | m_private->attemptToDecryptWithInstance(instance); |
| 605 | } |
| 606 | |
| 607 | #endif |
| 608 | |
| 609 | MediaTime MediaPlayer::duration() const |
| 610 | { |
| 611 | return m_private->durationMediaTime(); |
| 612 | } |
| 613 | |
| 614 | MediaTime MediaPlayer::startTime() const |
| 615 | { |
| 616 | return m_private->startTime(); |
| 617 | } |
| 618 | |
| 619 | MediaTime MediaPlayer::initialTime() const |
| 620 | { |
| 621 | return m_private->initialTime(); |
| 622 | } |
| 623 | |
| 624 | MediaTime MediaPlayer::currentTime() const |
| 625 | { |
| 626 | return m_private->currentMediaTime(); |
| 627 | } |
| 628 | |
| 629 | MediaTime MediaPlayer::getStartDate() const |
| 630 | { |
| 631 | return m_private->getStartDate(); |
| 632 | } |
| 633 | |
| 634 | void MediaPlayer::seekWithTolerance(const MediaTime& time, const MediaTime& negativeTolerance, const MediaTime& positiveTolerance) |
| 635 | { |
| 636 | m_private->seekWithTolerance(time, negativeTolerance, positiveTolerance); |
| 637 | } |
| 638 | |
| 639 | void MediaPlayer::seek(const MediaTime& time) |
| 640 | { |
| 641 | m_private->seek(time); |
| 642 | } |
| 643 | |
| 644 | bool MediaPlayer::paused() const |
| 645 | { |
| 646 | return m_private->paused(); |
| 647 | } |
| 648 | |
| 649 | bool MediaPlayer::seeking() const |
| 650 | { |
| 651 | return m_private->seeking(); |
| 652 | } |
| 653 | |
| 654 | bool MediaPlayer::supportsFullscreen() const |
| 655 | { |
| 656 | return m_private->supportsFullscreen(); |
| 657 | } |
| 658 | |
| 659 | bool MediaPlayer::canSaveMediaData() const |
| 660 | { |
| 661 | return m_private->canSaveMediaData(); |
| 662 | } |
| 663 | |
| 664 | bool MediaPlayer::supportsScanning() const |
| 665 | { |
| 666 | return m_private->supportsScanning(); |
| 667 | } |
| 668 | |
| 669 | bool MediaPlayer::requiresImmediateCompositing() const |
| 670 | { |
| 671 | return m_private->requiresImmediateCompositing(); |
| 672 | } |
| 673 | |
| 674 | FloatSize MediaPlayer::naturalSize() |
| 675 | { |
| 676 | return m_private->naturalSize(); |
| 677 | } |
| 678 | |
| 679 | bool MediaPlayer::hasVideo() const |
| 680 | { |
| 681 | return m_private->hasVideo(); |
| 682 | } |
| 683 | |
| 684 | bool MediaPlayer::hasAudio() const |
| 685 | { |
| 686 | return m_private->hasAudio(); |
| 687 | } |
| 688 | |
| 689 | bool MediaPlayer::inMediaDocument() const |
| 690 | { |
| 691 | return m_visible && client().mediaPlayerIsInMediaDocument(); |
| 692 | } |
| 693 | |
| 694 | PlatformLayer* MediaPlayer::platformLayer() const |
| 695 | { |
| 696 | return m_private->platformLayer(); |
| 697 | } |
| 698 | |
| 699 | #if PLATFORM(IOS_FAMILY) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)) |
| 700 | |
| 701 | void MediaPlayer::setVideoFullscreenLayer(PlatformLayer* layer, WTF::Function<void()>&& completionHandler) |
| 702 | { |
| 703 | m_private->setVideoFullscreenLayer(layer, WTFMove(completionHandler)); |
| 704 | } |
| 705 | |
| 706 | void MediaPlayer::updateVideoFullscreenInlineImage() |
| 707 | { |
| 708 | m_private->updateVideoFullscreenInlineImage(); |
| 709 | } |
| 710 | |
| 711 | void MediaPlayer::setVideoFullscreenFrame(FloatRect frame) |
| 712 | { |
| 713 | m_private->setVideoFullscreenFrame(frame); |
| 714 | } |
| 715 | |
| 716 | void MediaPlayer::setVideoFullscreenGravity(MediaPlayer::VideoGravity gravity) |
| 717 | { |
| 718 | m_private->setVideoFullscreenGravity(gravity); |
| 719 | } |
| 720 | |
| 721 | void MediaPlayer::setVideoFullscreenMode(MediaPlayer::VideoFullscreenMode mode) |
| 722 | { |
| 723 | m_private->setVideoFullscreenMode(mode); |
| 724 | } |
| 725 | |
| 726 | MediaPlayer::VideoFullscreenMode MediaPlayer::fullscreenMode() const |
| 727 | { |
| 728 | return client().mediaPlayerFullscreenMode(); |
| 729 | } |
| 730 | |
| 731 | void MediaPlayer::videoFullscreenStandbyChanged() |
| 732 | { |
| 733 | m_private->videoFullscreenStandbyChanged(); |
| 734 | } |
| 735 | |
| 736 | bool MediaPlayer::isVideoFullscreenStandby() const |
| 737 | { |
| 738 | return client().mediaPlayerIsVideoFullscreenStandby(); |
| 739 | } |
| 740 | |
| 741 | #endif |
| 742 | |
| 743 | #if PLATFORM(IOS_FAMILY) |
| 744 | |
| 745 | NSArray* MediaPlayer::timedMetadata() const |
| 746 | { |
| 747 | return m_private->timedMetadata(); |
| 748 | } |
| 749 | |
| 750 | String MediaPlayer::accessLog() const |
| 751 | { |
| 752 | return m_private->accessLog(); |
| 753 | } |
| 754 | |
| 755 | String MediaPlayer::errorLog() const |
| 756 | { |
| 757 | return m_private->errorLog(); |
| 758 | } |
| 759 | |
| 760 | #endif |
| 761 | |
| 762 | MediaPlayer::NetworkState MediaPlayer::networkState() |
| 763 | { |
| 764 | return m_private->networkState(); |
| 765 | } |
| 766 | |
| 767 | MediaPlayer::ReadyState MediaPlayer::readyState() |
| 768 | { |
| 769 | return m_private->readyState(); |
| 770 | } |
| 771 | |
| 772 | double MediaPlayer::volume() const |
| 773 | { |
| 774 | return m_volume; |
| 775 | } |
| 776 | |
| 777 | void MediaPlayer::setVolume(double volume) |
| 778 | { |
| 779 | m_volume = volume; |
| 780 | |
| 781 | if (m_private->supportsMuting() || !m_muted) |
| 782 | m_private->setVolumeDouble(volume); |
| 783 | } |
| 784 | |
| 785 | bool MediaPlayer::muted() const |
| 786 | { |
| 787 | return m_muted; |
| 788 | } |
| 789 | |
| 790 | void MediaPlayer::setMuted(bool muted) |
| 791 | { |
| 792 | m_muted = muted; |
| 793 | |
| 794 | if (m_private->supportsMuting()) |
| 795 | m_private->setMuted(muted); |
| 796 | else |
| 797 | m_private->setVolume(muted ? 0 : m_volume); |
| 798 | } |
| 799 | |
| 800 | bool MediaPlayer::hasClosedCaptions() const |
| 801 | { |
| 802 | return m_private->hasClosedCaptions(); |
| 803 | } |
| 804 | |
| 805 | void MediaPlayer::setClosedCaptionsVisible(bool closedCaptionsVisible) |
| 806 | { |
| 807 | m_private->setClosedCaptionsVisible(closedCaptionsVisible); |
| 808 | } |
| 809 | |
| 810 | double MediaPlayer::rate() const |
| 811 | { |
| 812 | return m_private->rate(); |
| 813 | } |
| 814 | |
| 815 | void MediaPlayer::setRate(double rate) |
| 816 | { |
| 817 | m_private->setRateDouble(rate); |
| 818 | } |
| 819 | |
| 820 | double MediaPlayer::requestedRate() const |
| 821 | { |
| 822 | return client().mediaPlayerRequestedPlaybackRate(); |
| 823 | } |
| 824 | |
| 825 | bool MediaPlayer::preservesPitch() const |
| 826 | { |
| 827 | return m_preservesPitch; |
| 828 | } |
| 829 | |
| 830 | void MediaPlayer::setPreservesPitch(bool preservesPitch) |
| 831 | { |
| 832 | m_preservesPitch = preservesPitch; |
| 833 | m_private->setPreservesPitch(preservesPitch); |
| 834 | } |
| 835 | |
| 836 | std::unique_ptr<PlatformTimeRanges> MediaPlayer::buffered() |
| 837 | { |
| 838 | return m_private->buffered(); |
| 839 | } |
| 840 | |
| 841 | std::unique_ptr<PlatformTimeRanges> MediaPlayer::seekable() |
| 842 | { |
| 843 | return m_private->seekable(); |
| 844 | } |
| 845 | |
| 846 | MediaTime MediaPlayer::maxTimeSeekable() |
| 847 | { |
| 848 | return m_private->maxMediaTimeSeekable(); |
| 849 | } |
| 850 | |
| 851 | MediaTime MediaPlayer::minTimeSeekable() |
| 852 | { |
| 853 | return m_private->minMediaTimeSeekable(); |
| 854 | } |
| 855 | |
| 856 | double MediaPlayer::seekableTimeRangesLastModifiedTime() |
| 857 | { |
| 858 | return m_private->seekableTimeRangesLastModifiedTime(); |
| 859 | } |
| 860 | |
| 861 | double MediaPlayer::liveUpdateInterval() |
| 862 | { |
| 863 | return m_private->liveUpdateInterval(); |
| 864 | } |
| 865 | |
| 866 | bool MediaPlayer::didLoadingProgress() |
| 867 | { |
| 868 | return m_private->didLoadingProgress(); |
| 869 | } |
| 870 | |
| 871 | void MediaPlayer::setSize(const IntSize& size) |
| 872 | { |
| 873 | m_size = size; |
| 874 | m_private->setSize(size); |
| 875 | } |
| 876 | |
| 877 | bool MediaPlayer::visible() const |
| 878 | { |
| 879 | return m_visible; |
| 880 | } |
| 881 | |
| 882 | void MediaPlayer::setVisible(bool b) |
| 883 | { |
| 884 | m_visible = b; |
| 885 | m_private->setVisible(b); |
| 886 | } |
| 887 | |
| 888 | MediaPlayer::Preload MediaPlayer::preload() const |
| 889 | { |
| 890 | return m_preload; |
| 891 | } |
| 892 | |
| 893 | void MediaPlayer::setPreload(MediaPlayer::Preload preload) |
| 894 | { |
| 895 | m_preload = preload; |
| 896 | m_private->setPreload(preload); |
| 897 | } |
| 898 | |
| 899 | void MediaPlayer::paint(GraphicsContext& p, const FloatRect& r) |
| 900 | { |
| 901 | m_private->paint(p, r); |
| 902 | } |
| 903 | |
| 904 | void MediaPlayer::paintCurrentFrameInContext(GraphicsContext& p, const FloatRect& r) |
| 905 | { |
| 906 | m_private->paintCurrentFrameInContext(p, r); |
| 907 | } |
| 908 | |
| 909 | bool MediaPlayer::copyVideoTextureToPlatformTexture(GraphicsContext3D* context, Platform3DObject texture, GC3Denum target, GC3Dint level, GC3Denum internalFormat, GC3Denum format, GC3Denum type, bool premultiplyAlpha, bool flipY) |
| 910 | { |
| 911 | return m_private->copyVideoTextureToPlatformTexture(context, texture, target, level, internalFormat, format, type, premultiplyAlpha, flipY); |
| 912 | } |
| 913 | |
| 914 | NativeImagePtr MediaPlayer::nativeImageForCurrentTime() |
| 915 | { |
| 916 | return m_private->nativeImageForCurrentTime(); |
| 917 | } |
| 918 | |
| 919 | MediaPlayer::SupportsType MediaPlayer::supportsType(const MediaEngineSupportParameters& parameters) |
| 920 | { |
| 921 | // 4.8.10.3 MIME types - The canPlayType(type) method must return the empty string if type is a type that the |
| 922 | // user agent knows it cannot render or is the type "application/octet-stream" |
| 923 | AtomicString containerType = parameters.type.containerType(); |
| 924 | if (containerType == applicationOctetStream()) |
| 925 | return IsNotSupported; |
| 926 | |
| 927 | const MediaPlayerFactory* engine = bestMediaEngineForSupportParameters(parameters); |
| 928 | if (!engine) |
| 929 | return IsNotSupported; |
| 930 | |
| 931 | return engine->supportsTypeAndCodecs(parameters); |
| 932 | } |
| 933 | |
| 934 | void MediaPlayer::getSupportedTypes(HashSet<String, ASCIICaseInsensitiveHash>& types) |
| 935 | { |
| 936 | for (auto& engine : installedMediaEngines()) { |
| 937 | HashSet<String, ASCIICaseInsensitiveHash> engineTypes; |
| 938 | engine.getSupportedTypes(engineTypes); |
| 939 | types.add(engineTypes.begin(), engineTypes.end()); |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | bool MediaPlayer::isAvailable() |
| 944 | { |
| 945 | #if PLATFORM(IOS_FAMILY) |
| 946 | if (DeprecatedGlobalSettings::isAVFoundationEnabled()) |
| 947 | return true; |
| 948 | #endif |
| 949 | return !installedMediaEngines().isEmpty(); |
| 950 | } |
| 951 | |
| 952 | bool MediaPlayer::supportsPictureInPicture() const |
| 953 | { |
| 954 | return m_private->supportsPictureInPicture(); |
| 955 | } |
| 956 | |
| 957 | #if USE(NATIVE_FULLSCREEN_VIDEO) |
| 958 | |
| 959 | void MediaPlayer::enterFullscreen() |
| 960 | { |
| 961 | m_private->enterFullscreen(); |
| 962 | } |
| 963 | |
| 964 | void MediaPlayer::exitFullscreen() |
| 965 | { |
| 966 | m_private->exitFullscreen(); |
| 967 | } |
| 968 | |
| 969 | #endif |
| 970 | |
| 971 | #if ENABLE(WIRELESS_PLAYBACK_TARGET) |
| 972 | |
| 973 | bool MediaPlayer::isCurrentPlaybackTargetWireless() const |
| 974 | { |
| 975 | return m_private->isCurrentPlaybackTargetWireless(); |
| 976 | } |
| 977 | |
| 978 | String MediaPlayer::wirelessPlaybackTargetName() const |
| 979 | { |
| 980 | return m_private->wirelessPlaybackTargetName(); |
| 981 | } |
| 982 | |
| 983 | MediaPlayer::WirelessPlaybackTargetType MediaPlayer::wirelessPlaybackTargetType() const |
| 984 | { |
| 985 | return m_private->wirelessPlaybackTargetType(); |
| 986 | } |
| 987 | |
| 988 | bool MediaPlayer::wirelessVideoPlaybackDisabled() const |
| 989 | { |
| 990 | return m_private->wirelessVideoPlaybackDisabled(); |
| 991 | } |
| 992 | |
| 993 | void MediaPlayer::setWirelessVideoPlaybackDisabled(bool disabled) |
| 994 | { |
| 995 | m_private->setWirelessVideoPlaybackDisabled(disabled); |
| 996 | } |
| 997 | |
| 998 | void MediaPlayer::currentPlaybackTargetIsWirelessChanged() |
| 999 | { |
| 1000 | client().mediaPlayerCurrentPlaybackTargetIsWirelessChanged(this); |
| 1001 | } |
| 1002 | |
| 1003 | bool MediaPlayer::canPlayToWirelessPlaybackTarget() const |
| 1004 | { |
| 1005 | return m_private->canPlayToWirelessPlaybackTarget(); |
| 1006 | } |
| 1007 | |
| 1008 | void MediaPlayer::setWirelessPlaybackTarget(Ref<MediaPlaybackTarget>&& device) |
| 1009 | { |
| 1010 | m_private->setWirelessPlaybackTarget(WTFMove(device)); |
| 1011 | } |
| 1012 | |
| 1013 | void MediaPlayer::setShouldPlayToPlaybackTarget(bool shouldPlay) |
| 1014 | { |
| 1015 | m_private->setShouldPlayToPlaybackTarget(shouldPlay); |
| 1016 | } |
| 1017 | |
| 1018 | #endif |
| 1019 | |
| 1020 | double MediaPlayer::maxFastForwardRate() const |
| 1021 | { |
| 1022 | return m_private->maxFastForwardRate(); |
| 1023 | } |
| 1024 | |
| 1025 | double MediaPlayer::minFastReverseRate() const |
| 1026 | { |
| 1027 | return m_private->minFastReverseRate(); |
| 1028 | } |
| 1029 | |
| 1030 | #if USE(NATIVE_FULLSCREEN_VIDEO) |
| 1031 | |
| 1032 | bool MediaPlayer::canEnterFullscreen() const |
| 1033 | { |
| 1034 | return m_private->canEnterFullscreen(); |
| 1035 | } |
| 1036 | |
| 1037 | #endif |
| 1038 | |
| 1039 | void MediaPlayer::acceleratedRenderingStateChanged() |
| 1040 | { |
| 1041 | m_private->acceleratedRenderingStateChanged(); |
| 1042 | } |
| 1043 | |
| 1044 | bool MediaPlayer::supportsAcceleratedRendering() const |
| 1045 | { |
| 1046 | return m_private->supportsAcceleratedRendering(); |
| 1047 | } |
| 1048 | |
| 1049 | bool MediaPlayer::shouldMaintainAspectRatio() const |
| 1050 | { |
| 1051 | return m_private->shouldMaintainAspectRatio(); |
| 1052 | } |
| 1053 | |
| 1054 | void MediaPlayer::setShouldMaintainAspectRatio(bool maintainAspectRatio) |
| 1055 | { |
| 1056 | m_private->setShouldMaintainAspectRatio(maintainAspectRatio); |
| 1057 | } |
| 1058 | |
| 1059 | bool MediaPlayer::hasSingleSecurityOrigin() const |
| 1060 | { |
| 1061 | return m_private->hasSingleSecurityOrigin(); |
| 1062 | } |
| 1063 | |
| 1064 | bool MediaPlayer::didPassCORSAccessCheck() const |
| 1065 | { |
| 1066 | return m_private->didPassCORSAccessCheck(); |
| 1067 | } |
| 1068 | |
| 1069 | bool MediaPlayer::wouldTaintOrigin(const SecurityOrigin& origin) const |
| 1070 | { |
| 1071 | auto wouldTaint = m_private->wouldTaintOrigin(origin); |
| 1072 | if (wouldTaint.hasValue()) |
| 1073 | return wouldTaint.value(); |
| 1074 | |
| 1075 | if (m_url.protocolIsData()) |
| 1076 | return false; |
| 1077 | |
| 1078 | return !origin.canRequest(m_url); |
| 1079 | } |
| 1080 | |
| 1081 | MediaPlayer::MovieLoadType MediaPlayer::movieLoadType() const |
| 1082 | { |
| 1083 | return m_private->movieLoadType(); |
| 1084 | } |
| 1085 | |
| 1086 | MediaTime MediaPlayer::mediaTimeForTimeValue(const MediaTime& timeValue) const |
| 1087 | { |
| 1088 | return m_private->mediaTimeForTimeValue(timeValue); |
| 1089 | } |
| 1090 | |
| 1091 | double MediaPlayer::maximumDurationToCacheMediaTime() const |
| 1092 | { |
| 1093 | return m_private->maximumDurationToCacheMediaTime(); |
| 1094 | } |
| 1095 | |
| 1096 | unsigned MediaPlayer::decodedFrameCount() const |
| 1097 | { |
| 1098 | return m_private->decodedFrameCount(); |
| 1099 | } |
| 1100 | |
| 1101 | unsigned MediaPlayer::droppedFrameCount() const |
| 1102 | { |
| 1103 | return m_private->droppedFrameCount(); |
| 1104 | } |
| 1105 | |
| 1106 | unsigned MediaPlayer::audioDecodedByteCount() const |
| 1107 | { |
| 1108 | return m_private->audioDecodedByteCount(); |
| 1109 | } |
| 1110 | |
| 1111 | unsigned MediaPlayer::videoDecodedByteCount() const |
| 1112 | { |
| 1113 | return m_private->videoDecodedByteCount(); |
| 1114 | } |
| 1115 | |
| 1116 | void MediaPlayer::reloadTimerFired() |
| 1117 | { |
| 1118 | m_private->cancelLoad(); |
| 1119 | loadWithNextMediaEngine(m_currentMediaEngine); |
| 1120 | } |
| 1121 | |
| 1122 | template<typename T> |
| 1123 | static void addToHash(HashSet<T>& toHash, HashSet<T>&& fromHash) |
| 1124 | { |
| 1125 | if (toHash.isEmpty()) |
| 1126 | toHash = WTFMove(fromHash); |
| 1127 | else |
| 1128 | toHash.add(fromHash.begin(), fromHash.end()); |
| 1129 | } |
| 1130 | |
| 1131 | HashSet<RefPtr<SecurityOrigin>> MediaPlayer::originsInMediaCache(const String& path) |
| 1132 | { |
| 1133 | HashSet<RefPtr<SecurityOrigin>> origins; |
| 1134 | for (auto& engine : installedMediaEngines()) { |
| 1135 | if (!engine.originsInMediaCache) |
| 1136 | continue; |
| 1137 | addToHash(origins, engine.originsInMediaCache(path)); |
| 1138 | } |
| 1139 | return origins; |
| 1140 | } |
| 1141 | |
| 1142 | void MediaPlayer::clearMediaCache(const String& path, WallTime modifiedSince) |
| 1143 | { |
| 1144 | for (auto& engine : installedMediaEngines()) { |
| 1145 | if (engine.clearMediaCache) |
| 1146 | engine.clearMediaCache(path, modifiedSince); |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | void MediaPlayer::clearMediaCacheForOrigins(const String& path, const HashSet<RefPtr<SecurityOrigin>>& origins) |
| 1151 | { |
| 1152 | for (auto& engine : installedMediaEngines()) { |
| 1153 | if (engine.clearMediaCacheForOrigins) |
| 1154 | engine.clearMediaCacheForOrigins(path, origins); |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | bool MediaPlayer::supportsKeySystem(const String& keySystem, const String& mimeType) |
| 1159 | { |
| 1160 | for (auto& engine : installedMediaEngines()) { |
| 1161 | if (engine.supportsKeySystem && engine.supportsKeySystem(keySystem, mimeType)) |
| 1162 | return true; |
| 1163 | } |
| 1164 | return false; |
| 1165 | } |
| 1166 | |
| 1167 | void MediaPlayer::setPrivateBrowsingMode(bool privateBrowsingMode) |
| 1168 | { |
| 1169 | m_privateBrowsing = privateBrowsingMode; |
| 1170 | if (m_private) |
| 1171 | m_private->setPrivateBrowsingMode(m_privateBrowsing); |
| 1172 | } |
| 1173 | |
| 1174 | // Client callbacks. |
| 1175 | void MediaPlayer::networkStateChanged() |
| 1176 | { |
| 1177 | // If more than one media engine is installed and this one failed before finding metadata, |
| 1178 | // let the next engine try. |
| 1179 | if (m_private->networkState() >= FormatError && m_private->readyState() < HaveMetadata) { |
| 1180 | client().mediaPlayerEngineFailedToLoad(); |
| 1181 | if (installedMediaEngines().size() > 1 && (m_contentType.isEmpty() || nextBestMediaEngine(m_currentMediaEngine))) { |
| 1182 | m_reloadTimer.startOneShot(0_s); |
| 1183 | return; |
| 1184 | } |
| 1185 | } |
| 1186 | client().mediaPlayerNetworkStateChanged(this); |
| 1187 | } |
| 1188 | |
| 1189 | void MediaPlayer::readyStateChanged() |
| 1190 | { |
| 1191 | client().mediaPlayerReadyStateChanged(this); |
| 1192 | } |
| 1193 | |
| 1194 | void MediaPlayer::volumeChanged(double newVolume) |
| 1195 | { |
| 1196 | #if PLATFORM(IOS_FAMILY) |
| 1197 | UNUSED_PARAM(newVolume); |
| 1198 | m_volume = m_private->volume(); |
| 1199 | #else |
| 1200 | m_volume = newVolume; |
| 1201 | #endif |
| 1202 | client().mediaPlayerVolumeChanged(this); |
| 1203 | } |
| 1204 | |
| 1205 | void MediaPlayer::muteChanged(bool newMuted) |
| 1206 | { |
| 1207 | if (newMuted == m_muted) |
| 1208 | return; |
| 1209 | |
| 1210 | m_muted = newMuted; |
| 1211 | client().mediaPlayerMuteChanged(this); |
| 1212 | } |
| 1213 | |
| 1214 | void MediaPlayer::timeChanged() |
| 1215 | { |
| 1216 | client().mediaPlayerTimeChanged(this); |
| 1217 | } |
| 1218 | |
| 1219 | void MediaPlayer::sizeChanged() |
| 1220 | { |
| 1221 | client().mediaPlayerSizeChanged(this); |
| 1222 | } |
| 1223 | |
| 1224 | void MediaPlayer::repaint() |
| 1225 | { |
| 1226 | client().mediaPlayerRepaint(this); |
| 1227 | } |
| 1228 | |
| 1229 | void MediaPlayer::durationChanged() |
| 1230 | { |
| 1231 | client().mediaPlayerDurationChanged(this); |
| 1232 | } |
| 1233 | |
| 1234 | void MediaPlayer::rateChanged() |
| 1235 | { |
| 1236 | client().mediaPlayerRateChanged(this); |
| 1237 | } |
| 1238 | |
| 1239 | void MediaPlayer::playbackStateChanged() |
| 1240 | { |
| 1241 | client().mediaPlayerPlaybackStateChanged(this); |
| 1242 | } |
| 1243 | |
| 1244 | void MediaPlayer::firstVideoFrameAvailable() |
| 1245 | { |
| 1246 | client().mediaPlayerFirstVideoFrameAvailable(this); |
| 1247 | } |
| 1248 | |
| 1249 | void MediaPlayer::characteristicChanged() |
| 1250 | { |
| 1251 | client().mediaPlayerCharacteristicChanged(this); |
| 1252 | } |
| 1253 | |
| 1254 | #if ENABLE(WEB_AUDIO) |
| 1255 | |
| 1256 | AudioSourceProvider* MediaPlayer::audioSourceProvider() |
| 1257 | { |
| 1258 | return m_private->audioSourceProvider(); |
| 1259 | } |
| 1260 | |
| 1261 | #endif |
| 1262 | |
| 1263 | #if ENABLE(LEGACY_ENCRYPTED_MEDIA) |
| 1264 | |
| 1265 | RefPtr<ArrayBuffer> MediaPlayer::cachedKeyForKeyId(const String& keyId) const |
| 1266 | { |
| 1267 | return client().mediaPlayerCachedKeyForKeyId(keyId); |
| 1268 | } |
| 1269 | |
| 1270 | bool MediaPlayer::keyNeeded(Uint8Array* initData) |
| 1271 | { |
| 1272 | return client().mediaPlayerKeyNeeded(this, initData); |
| 1273 | } |
| 1274 | |
| 1275 | String MediaPlayer::mediaKeysStorageDirectory() const |
| 1276 | { |
| 1277 | return client().mediaPlayerMediaKeysStorageDirectory(); |
| 1278 | } |
| 1279 | |
| 1280 | #endif |
| 1281 | |
| 1282 | #if ENABLE(ENCRYPTED_MEDIA) |
| 1283 | |
| 1284 | void MediaPlayer::initializationDataEncountered(const String& initDataType, RefPtr<ArrayBuffer>&& initData) |
| 1285 | { |
| 1286 | client().mediaPlayerInitializationDataEncountered(initDataType, WTFMove(initData)); |
| 1287 | } |
| 1288 | |
| 1289 | void MediaPlayer::waitingForKeyChanged() |
| 1290 | { |
| 1291 | client().mediaPlayerWaitingForKeyChanged(); |
| 1292 | } |
| 1293 | |
| 1294 | bool MediaPlayer::waitingForKey() const |
| 1295 | { |
| 1296 | if (!m_private) |
| 1297 | return false; |
| 1298 | return m_private->waitingForKey(); |
| 1299 | } |
| 1300 | #endif |
| 1301 | |
| 1302 | String MediaPlayer::referrer() const |
| 1303 | { |
| 1304 | return client().mediaPlayerReferrer(); |
| 1305 | } |
| 1306 | |
| 1307 | String MediaPlayer::userAgent() const |
| 1308 | { |
| 1309 | return client().mediaPlayerUserAgent(); |
| 1310 | } |
| 1311 | |
| 1312 | String MediaPlayer::engineDescription() const |
| 1313 | { |
| 1314 | if (!m_private) |
| 1315 | return String(); |
| 1316 | |
| 1317 | return m_private->engineDescription(); |
| 1318 | } |
| 1319 | |
| 1320 | long MediaPlayer::platformErrorCode() const |
| 1321 | { |
| 1322 | if (!m_private) |
| 1323 | return 0; |
| 1324 | |
| 1325 | return m_private->platformErrorCode(); |
| 1326 | } |
| 1327 | |
| 1328 | #if PLATFORM(WIN) && USE(AVFOUNDATION) |
| 1329 | GraphicsDeviceAdapter* MediaPlayer::graphicsDeviceAdapter() const |
| 1330 | { |
| 1331 | return client().mediaPlayerGraphicsDeviceAdapter(this); |
| 1332 | } |
| 1333 | #endif |
| 1334 | |
| 1335 | CachedResourceLoader* MediaPlayer::cachedResourceLoader() |
| 1336 | { |
| 1337 | return client().mediaPlayerCachedResourceLoader(); |
| 1338 | } |
| 1339 | |
| 1340 | RefPtr<PlatformMediaResourceLoader> MediaPlayer::createResourceLoader() |
| 1341 | { |
| 1342 | return client().mediaPlayerCreateResourceLoader(); |
| 1343 | } |
| 1344 | |
| 1345 | #if ENABLE(VIDEO_TRACK) |
| 1346 | |
| 1347 | void MediaPlayer::addAudioTrack(AudioTrackPrivate& track) |
| 1348 | { |
| 1349 | client().mediaPlayerDidAddAudioTrack(track); |
| 1350 | } |
| 1351 | |
| 1352 | void MediaPlayer::removeAudioTrack(AudioTrackPrivate& track) |
| 1353 | { |
| 1354 | client().mediaPlayerDidRemoveAudioTrack(track); |
| 1355 | } |
| 1356 | |
| 1357 | void MediaPlayer::addTextTrack(InbandTextTrackPrivate& track) |
| 1358 | { |
| 1359 | client().mediaPlayerDidAddTextTrack(track); |
| 1360 | } |
| 1361 | |
| 1362 | void MediaPlayer::removeTextTrack(InbandTextTrackPrivate& track) |
| 1363 | { |
| 1364 | client().mediaPlayerDidRemoveTextTrack(track); |
| 1365 | } |
| 1366 | |
| 1367 | void MediaPlayer::addVideoTrack(VideoTrackPrivate& track) |
| 1368 | { |
| 1369 | client().mediaPlayerDidAddVideoTrack(track); |
| 1370 | } |
| 1371 | |
| 1372 | void MediaPlayer::removeVideoTrack(VideoTrackPrivate& track) |
| 1373 | { |
| 1374 | client().mediaPlayerDidRemoveVideoTrack(track); |
| 1375 | } |
| 1376 | |
| 1377 | bool MediaPlayer::requiresTextTrackRepresentation() const |
| 1378 | { |
| 1379 | return m_private->requiresTextTrackRepresentation(); |
| 1380 | } |
| 1381 | |
| 1382 | void MediaPlayer::setTextTrackRepresentation(TextTrackRepresentation* representation) |
| 1383 | { |
| 1384 | m_private->setTextTrackRepresentation(representation); |
| 1385 | } |
| 1386 | |
| 1387 | void MediaPlayer::syncTextTrackBounds() |
| 1388 | { |
| 1389 | m_private->syncTextTrackBounds(); |
| 1390 | } |
| 1391 | |
| 1392 | void MediaPlayer::tracksChanged() |
| 1393 | { |
| 1394 | m_private->tracksChanged(); |
| 1395 | } |
| 1396 | |
| 1397 | #if ENABLE(AVF_CAPTIONS) |
| 1398 | |
| 1399 | void MediaPlayer::notifyTrackModeChanged() |
| 1400 | { |
| 1401 | if (m_private) |
| 1402 | m_private->notifyTrackModeChanged(); |
| 1403 | } |
| 1404 | |
| 1405 | Vector<RefPtr<PlatformTextTrack>> MediaPlayer::outOfBandTrackSources() |
| 1406 | { |
| 1407 | return client().outOfBandTrackSources(); |
| 1408 | } |
| 1409 | |
| 1410 | #endif |
| 1411 | |
| 1412 | #endif // ENABLE(VIDEO_TRACK) |
| 1413 | |
| 1414 | void MediaPlayer::resetMediaEngines() |
| 1415 | { |
| 1416 | auto locker = holdLock(mediaEngineVectorLock); |
| 1417 | |
| 1418 | mutableInstalledMediaEnginesVector().clear(); |
| 1419 | haveMediaEnginesVector() = false; |
| 1420 | } |
| 1421 | |
| 1422 | #if USE(GSTREAMER) |
| 1423 | void MediaPlayer::simulateAudioInterruption() |
| 1424 | { |
| 1425 | if (!m_private) |
| 1426 | return; |
| 1427 | |
| 1428 | m_private->simulateAudioInterruption(); |
| 1429 | } |
| 1430 | #endif |
| 1431 | |
| 1432 | void MediaPlayer::beginSimulatedHDCPError() |
| 1433 | { |
| 1434 | if (m_private) |
| 1435 | m_private->beginSimulatedHDCPError(); |
| 1436 | } |
| 1437 | |
| 1438 | void MediaPlayer::endSimulatedHDCPError() |
| 1439 | { |
| 1440 | if (m_private) |
| 1441 | m_private->endSimulatedHDCPError(); |
| 1442 | } |
| 1443 | |
| 1444 | String MediaPlayer::languageOfPrimaryAudioTrack() const |
| 1445 | { |
| 1446 | if (!m_private) |
| 1447 | return emptyString(); |
| 1448 | |
| 1449 | return m_private->languageOfPrimaryAudioTrack(); |
| 1450 | } |
| 1451 | |
| 1452 | size_t MediaPlayer::() const |
| 1453 | { |
| 1454 | if (!m_private) |
| 1455 | return 0; |
| 1456 | |
| 1457 | return m_private->extraMemoryCost(); |
| 1458 | } |
| 1459 | |
| 1460 | unsigned long long MediaPlayer::fileSize() const |
| 1461 | { |
| 1462 | if (!m_private) |
| 1463 | return 0; |
| 1464 | |
| 1465 | return m_private->fileSize(); |
| 1466 | } |
| 1467 | |
| 1468 | bool MediaPlayer::ended() const |
| 1469 | { |
| 1470 | return m_private->ended(); |
| 1471 | } |
| 1472 | |
| 1473 | Optional<VideoPlaybackQualityMetrics> MediaPlayer::videoPlaybackQualityMetrics() |
| 1474 | { |
| 1475 | if (!m_private) |
| 1476 | return WTF::nullopt; |
| 1477 | |
| 1478 | return m_private->videoPlaybackQualityMetrics(); |
| 1479 | } |
| 1480 | |
| 1481 | void MediaPlayer::handlePlaybackCommand(PlatformMediaSession::RemoteControlCommandType command) |
| 1482 | { |
| 1483 | client().mediaPlayerHandlePlaybackCommand(command); |
| 1484 | } |
| 1485 | |
| 1486 | String MediaPlayer::sourceApplicationIdentifier() const |
| 1487 | { |
| 1488 | return client().mediaPlayerSourceApplicationIdentifier(); |
| 1489 | } |
| 1490 | |
| 1491 | Vector<String> MediaPlayer::preferredAudioCharacteristics() const |
| 1492 | { |
| 1493 | return client().mediaPlayerPreferredAudioCharacteristics(); |
| 1494 | } |
| 1495 | |
| 1496 | void MediaPlayerFactorySupport::callRegisterMediaEngine(MediaEngineRegister registerMediaEngine) |
| 1497 | { |
| 1498 | registerMediaEngine(addMediaEngine); |
| 1499 | } |
| 1500 | |
| 1501 | bool MediaPlayer::doesHaveAttribute(const AtomicString& attribute, AtomicString* value) const |
| 1502 | { |
| 1503 | return client().doesHaveAttribute(attribute, value); |
| 1504 | } |
| 1505 | |
| 1506 | #if PLATFORM(IOS_FAMILY) |
| 1507 | String MediaPlayer::mediaPlayerNetworkInterfaceName() const |
| 1508 | { |
| 1509 | return client().mediaPlayerNetworkInterfaceName(); |
| 1510 | } |
| 1511 | |
| 1512 | bool MediaPlayer::getRawCookies(const URL& url, Vector<Cookie>& cookies) const |
| 1513 | { |
| 1514 | return client().mediaPlayerGetRawCookies(url, cookies); |
| 1515 | } |
| 1516 | #endif |
| 1517 | |
| 1518 | void MediaPlayer::setShouldDisableSleep(bool flag) |
| 1519 | { |
| 1520 | if (m_private) |
| 1521 | m_private->setShouldDisableSleep(flag); |
| 1522 | } |
| 1523 | |
| 1524 | bool MediaPlayer::shouldDisableSleep() const |
| 1525 | { |
| 1526 | return client().mediaPlayerShouldDisableSleep(); |
| 1527 | } |
| 1528 | |
| 1529 | const Vector<ContentType>& MediaPlayer::mediaContentTypesRequiringHardwareSupport() const |
| 1530 | { |
| 1531 | return client().mediaContentTypesRequiringHardwareSupport(); |
| 1532 | } |
| 1533 | |
| 1534 | bool MediaPlayer::shouldCheckHardwareSupport() const |
| 1535 | { |
| 1536 | return client().mediaPlayerShouldCheckHardwareSupport(); |
| 1537 | } |
| 1538 | |
| 1539 | void MediaPlayer::applicationWillResignActive() |
| 1540 | { |
| 1541 | m_private->applicationWillResignActive(); |
| 1542 | } |
| 1543 | |
| 1544 | void MediaPlayer::applicationDidBecomeActive() |
| 1545 | { |
| 1546 | m_private->applicationDidBecomeActive(); |
| 1547 | } |
| 1548 | |
| 1549 | #if USE(AVFOUNDATION) |
| 1550 | |
| 1551 | AVPlayer* MediaPlayer::objCAVFoundationAVPlayer() const |
| 1552 | { |
| 1553 | return m_private->objCAVFoundationAVPlayer(); |
| 1554 | } |
| 1555 | |
| 1556 | #endif |
| 1557 | |
| 1558 | bool MediaPlayer::performTaskAtMediaTime(WTF::Function<void()>&& task, MediaTime time) |
| 1559 | { |
| 1560 | return m_private->performTaskAtMediaTime(WTFMove(task), time); |
| 1561 | } |
| 1562 | |
| 1563 | bool MediaPlayer::shouldIgnoreIntrinsicSize() |
| 1564 | { |
| 1565 | return m_private->shouldIgnoreIntrinsicSize(); |
| 1566 | } |
| 1567 | |
| 1568 | #if !RELEASE_LOG_DISABLED |
| 1569 | const Logger& MediaPlayer::mediaPlayerLogger() |
| 1570 | { |
| 1571 | return client().mediaPlayerLogger(); |
| 1572 | } |
| 1573 | #endif |
| 1574 | |
| 1575 | String convertEnumerationToString(MediaPlayerEnums::ReadyState enumerationValue) |
| 1576 | { |
| 1577 | static const NeverDestroyed<String> values[] = { |
| 1578 | MAKE_STATIC_STRING_IMPL("HaveNothing" ), |
| 1579 | MAKE_STATIC_STRING_IMPL("HaveMetadata" ), |
| 1580 | MAKE_STATIC_STRING_IMPL("HaveCurrentData" ), |
| 1581 | MAKE_STATIC_STRING_IMPL("HaveFutureData" ), |
| 1582 | MAKE_STATIC_STRING_IMPL("HaveEnoughData" ), |
| 1583 | }; |
| 1584 | static_assert(static_cast<size_t>(MediaPlayerEnums::HaveNothing) == 0, "MediaPlayerEnums::HaveNothing is not 0 as expected" ); |
| 1585 | static_assert(static_cast<size_t>(MediaPlayerEnums::HaveMetadata) == 1, "MediaPlayerEnums::HaveMetadata is not 1 as expected" ); |
| 1586 | static_assert(static_cast<size_t>(MediaPlayerEnums::HaveCurrentData) == 2, "MediaPlayerEnums::HaveCurrentData is not 2 as expected" ); |
| 1587 | static_assert(static_cast<size_t>(MediaPlayerEnums::HaveFutureData) == 3, "MediaPlayerEnums::HaveFutureData is not 3 as expected" ); |
| 1588 | static_assert(static_cast<size_t>(MediaPlayerEnums::HaveEnoughData) == 4, "MediaPlayerEnums::HaveEnoughData is not 4 as expected" ); |
| 1589 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| 1590 | return values[static_cast<size_t>(enumerationValue)]; |
| 1591 | } |
| 1592 | |
| 1593 | String convertEnumerationToString(MediaPlayerEnums::NetworkState enumerationValue) |
| 1594 | { |
| 1595 | static const NeverDestroyed<String> values[] = { |
| 1596 | MAKE_STATIC_STRING_IMPL("Empty" ), |
| 1597 | MAKE_STATIC_STRING_IMPL("Idle" ), |
| 1598 | MAKE_STATIC_STRING_IMPL("Loading" ), |
| 1599 | MAKE_STATIC_STRING_IMPL("Loaded" ), |
| 1600 | MAKE_STATIC_STRING_IMPL("FormatError" ), |
| 1601 | MAKE_STATIC_STRING_IMPL("NetworkError" ), |
| 1602 | MAKE_STATIC_STRING_IMPL("DecodeError" ), |
| 1603 | }; |
| 1604 | static_assert(static_cast<size_t>(MediaPlayerEnums::Empty) == 0, "MediaPlayerEnums::Empty is not 0 as expected" ); |
| 1605 | static_assert(static_cast<size_t>(MediaPlayerEnums::Idle) == 1, "MediaPlayerEnums::Idle is not 1 as expected" ); |
| 1606 | static_assert(static_cast<size_t>(MediaPlayerEnums::Loading) == 2, "MediaPlayerEnums::Loading is not 2 as expected" ); |
| 1607 | static_assert(static_cast<size_t>(MediaPlayerEnums::Loaded) == 3, "MediaPlayerEnums::Loaded is not 3 as expected" ); |
| 1608 | static_assert(static_cast<size_t>(MediaPlayerEnums::FormatError) == 4, "MediaPlayerEnums::FormatError is not 4 as expected" ); |
| 1609 | static_assert(static_cast<size_t>(MediaPlayerEnums::NetworkError) == 5, "MediaPlayerEnums::NetworkError is not 5 as expected" ); |
| 1610 | static_assert(static_cast<size_t>(MediaPlayerEnums::DecodeError) == 6, "MediaPlayerEnums::DecodeError is not 6 as expected" ); |
| 1611 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| 1612 | return values[static_cast<size_t>(enumerationValue)]; |
| 1613 | } |
| 1614 | |
| 1615 | String convertEnumerationToString(MediaPlayerEnums::Preload enumerationValue) |
| 1616 | { |
| 1617 | static const NeverDestroyed<String> values[] = { |
| 1618 | MAKE_STATIC_STRING_IMPL("None" ), |
| 1619 | MAKE_STATIC_STRING_IMPL("MetaData" ), |
| 1620 | MAKE_STATIC_STRING_IMPL("Auto" ), |
| 1621 | }; |
| 1622 | static_assert(!static_cast<size_t>(MediaPlayerEnums::None), "MediaPlayerEnums::None is not 0 as expected" ); |
| 1623 | static_assert(static_cast<size_t>(MediaPlayerEnums::MetaData) == 1, "MediaPlayerEnums::MetaData is not 1 as expected" ); |
| 1624 | static_assert(static_cast<size_t>(MediaPlayerEnums::Auto) == 2, "MediaPlayerEnums::Auto is not 2 as expected" ); |
| 1625 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| 1626 | return values[static_cast<size_t>(enumerationValue)]; |
| 1627 | } |
| 1628 | |
| 1629 | String convertEnumerationToString(MediaPlayerEnums::SupportsType enumerationValue) |
| 1630 | { |
| 1631 | static const NeverDestroyed<String> values[] = { |
| 1632 | MAKE_STATIC_STRING_IMPL("IsNotSupported" ), |
| 1633 | MAKE_STATIC_STRING_IMPL("IsSupported" ), |
| 1634 | MAKE_STATIC_STRING_IMPL("MayBeSupported" ), |
| 1635 | }; |
| 1636 | static_assert(!static_cast<size_t>(MediaPlayerEnums::IsNotSupported), "MediaPlayerEnums::IsNotSupported is not 0 as expected" ); |
| 1637 | static_assert(static_cast<size_t>(MediaPlayerEnums::IsSupported) == 1, "MediaPlayerEnums::IsSupported is not 1 as expected" ); |
| 1638 | static_assert(static_cast<size_t>(MediaPlayerEnums::MayBeSupported) == 2, "MediaPlayerEnums::MayBeSupported is not 2 as expected" ); |
| 1639 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| 1640 | return values[static_cast<size_t>(enumerationValue)]; |
| 1641 | } |
| 1642 | |
| 1643 | String convertEnumerationToString(MediaPlayerEnums::BufferingPolicy enumerationValue) |
| 1644 | { |
| 1645 | static const NeverDestroyed<String> values[] = { |
| 1646 | MAKE_STATIC_STRING_IMPL("Default" ), |
| 1647 | MAKE_STATIC_STRING_IMPL("LimitReadAhead" ), |
| 1648 | MAKE_STATIC_STRING_IMPL("MakeResourcesPurgeable" ), |
| 1649 | MAKE_STATIC_STRING_IMPL("PurgeResources" ), |
| 1650 | }; |
| 1651 | static_assert(!static_cast<size_t>(MediaPlayerEnums::BufferingPolicy::Default), "MediaPlayerEnums::Default is not 0 as expected" ); |
| 1652 | static_assert(static_cast<size_t>(MediaPlayerEnums::BufferingPolicy::LimitReadAhead) == 1, "MediaPlayerEnums::LimitReadAhead is not 1 as expected" ); |
| 1653 | static_assert(static_cast<size_t>(MediaPlayerEnums::BufferingPolicy::MakeResourcesPurgeable) == 2, "MediaPlayerEnums::MakeResourcesPurgeable is not 2 as expected" ); |
| 1654 | static_assert(static_cast<size_t>(MediaPlayerEnums::BufferingPolicy::PurgeResources) == 3, "MediaPlayerEnums::PurgeResources is not 3 as expected" ); |
| 1655 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
| 1656 | return values[static_cast<size_t>(enumerationValue)]; |
| 1657 | } |
| 1658 | |
| 1659 | } |
| 1660 | |
| 1661 | #endif |
| 1662 | |