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