Add support for reporting "display composited video frames" through the VideoPlayback...
[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     m_private->prepareToPlay();
544 }
545
546 void MediaPlayer::play()
547 {
548     m_private->play();
549 }
550
551 void MediaPlayer::pause()
552 {
553     m_private->pause();
554 }
555
556 void MediaPlayer::setShouldBufferData(bool shouldBuffer)
557 {
558     m_private->setShouldBufferData(shouldBuffer);
559 }
560
561 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
562
563 std::unique_ptr<LegacyCDMSession> MediaPlayer::createSession(const String& keySystem, LegacyCDMSessionClient* client)
564 {
565     return m_private->createSession(keySystem, client);
566 }
567
568 void MediaPlayer::setCDMSession(LegacyCDMSession* session)
569 {
570     m_private->setCDMSession(session);
571 }
572
573 void MediaPlayer::keyAdded()
574 {
575     m_private->keyAdded();
576 }
577
578 #endif
579     
580 #if ENABLE(ENCRYPTED_MEDIA)
581
582 void MediaPlayer::cdmInstanceAttached(CDMInstance& instance)
583 {
584     m_private->cdmInstanceAttached(instance);
585 }
586
587 void MediaPlayer::cdmInstanceDetached(CDMInstance& instance)
588 {
589     m_private->cdmInstanceDetached(instance);
590 }
591
592 void MediaPlayer::attemptToDecryptWithInstance(CDMInstance& instance)
593 {
594     m_private->attemptToDecryptWithInstance(instance);
595 }
596
597 #endif
598
599 MediaTime MediaPlayer::duration() const
600 {
601     return m_private->durationMediaTime();
602 }
603
604 MediaTime MediaPlayer::startTime() const
605 {
606     return m_private->startTime();
607 }
608
609 MediaTime MediaPlayer::initialTime() const
610 {
611     return m_private->initialTime();
612 }
613
614 MediaTime MediaPlayer::currentTime() const
615 {
616     return m_private->currentMediaTime();
617 }
618
619 MediaTime MediaPlayer::getStartDate() const
620 {
621     return m_private->getStartDate();
622 }
623
624 void MediaPlayer::seekWithTolerance(const MediaTime& time, const MediaTime& negativeTolerance, const MediaTime& positiveTolerance)
625 {
626     m_private->seekWithTolerance(time, negativeTolerance, positiveTolerance);
627 }
628
629 void MediaPlayer::seek(const MediaTime& time)
630 {
631     m_private->seek(time);
632 }
633
634 bool MediaPlayer::paused() const
635 {
636     return m_private->paused();
637 }
638
639 bool MediaPlayer::seeking() const
640 {
641     return m_private->seeking();
642 }
643
644 bool MediaPlayer::supportsFullscreen() const
645 {
646     return m_private->supportsFullscreen();
647 }
648
649 bool MediaPlayer::canSaveMediaData() const
650 {
651     return m_private->canSaveMediaData();
652 }
653
654 bool MediaPlayer::supportsScanning() const
655 {
656     return m_private->supportsScanning();
657 }
658
659 bool MediaPlayer::requiresImmediateCompositing() const
660 {
661     return m_private->requiresImmediateCompositing();
662 }
663
664 FloatSize MediaPlayer::naturalSize()
665 {
666     return m_private->naturalSize();
667 }
668
669 bool MediaPlayer::hasVideo() const
670 {
671     return m_private->hasVideo();
672 }
673
674 bool MediaPlayer::hasAudio() const
675 {
676     return m_private->hasAudio();
677 }
678
679 bool MediaPlayer::inMediaDocument() const
680 {
681     return m_visible && client().mediaPlayerIsInMediaDocument();
682 }
683
684 PlatformLayer* MediaPlayer::platformLayer() const
685 {
686     return m_private->platformLayer();
687 }
688     
689 #if PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
690
691 void MediaPlayer::setVideoFullscreenLayer(PlatformLayer* layer, WTF::Function<void()>&& completionHandler)
692 {
693     m_private->setVideoFullscreenLayer(layer, WTFMove(completionHandler));
694 }
695
696 void MediaPlayer::updateVideoFullscreenInlineImage()
697 {
698     m_private->updateVideoFullscreenInlineImage();
699 }
700
701 void MediaPlayer::setVideoFullscreenFrame(FloatRect frame)
702 {
703     m_private->setVideoFullscreenFrame(frame);
704 }
705
706 void MediaPlayer::setVideoFullscreenGravity(MediaPlayer::VideoGravity gravity)
707 {
708     m_private->setVideoFullscreenGravity(gravity);
709 }
710
711 void MediaPlayer::setVideoFullscreenMode(MediaPlayer::VideoFullscreenMode mode)
712 {
713     m_private->setVideoFullscreenMode(mode);
714 }
715
716 MediaPlayer::VideoFullscreenMode MediaPlayer::fullscreenMode() const
717 {
718     return client().mediaPlayerFullscreenMode();
719 }
720
721 #endif
722
723 #if PLATFORM(IOS)
724
725 NSArray* MediaPlayer::timedMetadata() const
726 {
727     return m_private->timedMetadata();
728 }
729
730 String MediaPlayer::accessLog() const
731 {
732     return m_private->accessLog();
733 }
734
735 String MediaPlayer::errorLog() const
736 {
737     return m_private->errorLog();
738 }
739
740 #endif
741
742 MediaPlayer::NetworkState MediaPlayer::networkState()
743 {
744     return m_private->networkState();
745 }
746
747 MediaPlayer::ReadyState MediaPlayer::readyState()
748 {
749     return m_private->readyState();
750 }
751
752 double MediaPlayer::volume() const
753 {
754     return m_volume;
755 }
756
757 void MediaPlayer::setVolume(double volume)
758 {
759     m_volume = volume;
760
761     if (m_private->supportsMuting() || !m_muted)
762         m_private->setVolumeDouble(volume);
763 }
764
765 bool MediaPlayer::muted() const
766 {
767     return m_muted;
768 }
769
770 void MediaPlayer::setMuted(bool muted)
771 {
772     m_muted = muted;
773
774     if (m_private->supportsMuting())
775         m_private->setMuted(muted);
776     else
777         m_private->setVolume(muted ? 0 : m_volume);
778 }
779
780 bool MediaPlayer::hasClosedCaptions() const
781 {
782     return m_private->hasClosedCaptions();
783 }
784
785 void MediaPlayer::setClosedCaptionsVisible(bool closedCaptionsVisible)
786 {
787     m_private->setClosedCaptionsVisible(closedCaptionsVisible);
788 }
789
790 double MediaPlayer::rate() const
791 {
792     return m_private->rate();
793 }
794
795 void MediaPlayer::setRate(double rate)
796 {
797     m_private->setRateDouble(rate);
798 }
799
800 double MediaPlayer::requestedRate() const
801 {
802     return client().mediaPlayerRequestedPlaybackRate();
803 }
804
805 bool MediaPlayer::preservesPitch() const
806 {
807     return m_preservesPitch;
808 }
809
810 void MediaPlayer::setPreservesPitch(bool preservesPitch)
811 {
812     m_preservesPitch = preservesPitch;
813     m_private->setPreservesPitch(preservesPitch);
814 }
815
816 std::unique_ptr<PlatformTimeRanges> MediaPlayer::buffered()
817 {
818     return m_private->buffered();
819 }
820
821 std::unique_ptr<PlatformTimeRanges> MediaPlayer::seekable()
822 {
823     return m_private->seekable();
824 }
825
826 MediaTime MediaPlayer::maxTimeSeekable()
827 {
828     return m_private->maxMediaTimeSeekable();
829 }
830
831 MediaTime MediaPlayer::minTimeSeekable()
832 {
833     return m_private->minMediaTimeSeekable();
834 }
835
836 double MediaPlayer::seekableTimeRangesLastModifiedTime()
837 {
838     return m_private->seekableTimeRangesLastModifiedTime();
839 }
840
841 double MediaPlayer::liveUpdateInterval()
842 {
843     return m_private->liveUpdateInterval();
844 }
845
846 bool MediaPlayer::didLoadingProgress()
847 {
848     return m_private->didLoadingProgress();
849 }
850
851 void MediaPlayer::setSize(const IntSize& size)
852
853     m_size = size;
854     m_private->setSize(size);
855 }
856
857 bool MediaPlayer::visible() const
858 {
859     return m_visible;
860 }
861
862 void MediaPlayer::setVisible(bool b)
863 {
864     m_visible = b;
865     m_private->setVisible(b);
866 }
867
868 MediaPlayer::Preload MediaPlayer::preload() const
869 {
870     return m_preload;
871 }
872
873 void MediaPlayer::setPreload(MediaPlayer::Preload preload)
874 {
875     m_preload = preload;
876     m_private->setPreload(preload);
877 }
878
879 void MediaPlayer::paint(GraphicsContext& p, const FloatRect& r)
880 {
881     m_private->paint(p, r);
882 }
883
884 void MediaPlayer::paintCurrentFrameInContext(GraphicsContext& p, const FloatRect& r)
885 {
886     m_private->paintCurrentFrameInContext(p, r);
887 }
888
889 bool MediaPlayer::copyVideoTextureToPlatformTexture(GraphicsContext3D* context, Platform3DObject texture, GC3Denum target, GC3Dint level, GC3Denum internalFormat, GC3Denum format, GC3Denum type, bool premultiplyAlpha, bool flipY)
890 {
891     return m_private->copyVideoTextureToPlatformTexture(context, texture, target, level, internalFormat, format, type, premultiplyAlpha, flipY);
892 }
893
894 NativeImagePtr MediaPlayer::nativeImageForCurrentTime()
895 {
896     return m_private->nativeImageForCurrentTime();
897 }
898
899 MediaPlayer::SupportsType MediaPlayer::supportsType(const MediaEngineSupportParameters& parameters)
900 {
901     // 4.8.10.3 MIME types - The canPlayType(type) method must return the empty string if type is a type that the 
902     // user agent knows it cannot render or is the type "application/octet-stream"
903     AtomicString containerType = parameters.type.containerType();
904     if (containerType == applicationOctetStream())
905         return IsNotSupported;
906
907     const MediaPlayerFactory* engine = bestMediaEngineForSupportParameters(parameters);
908     if (!engine)
909         return IsNotSupported;
910
911     return engine->supportsTypeAndCodecs(parameters);
912 }
913
914 void MediaPlayer::getSupportedTypes(HashSet<String, ASCIICaseInsensitiveHash>& types)
915 {
916     for (auto& engine : installedMediaEngines()) {
917         HashSet<String, ASCIICaseInsensitiveHash> engineTypes;
918         engine.getSupportedTypes(engineTypes);
919         types.add(engineTypes.begin(), engineTypes.end());
920     }
921
922
923 bool MediaPlayer::isAvailable()
924 {
925 #if PLATFORM(IOS)
926     if (DeprecatedGlobalSettings::isAVFoundationEnabled())
927         return true;
928 #endif
929     return !installedMediaEngines().isEmpty();
930 }
931
932 bool MediaPlayer::supportsPictureInPicture() const
933 {
934     return m_private->supportsPictureInPicture();
935 }
936
937 #if USE(NATIVE_FULLSCREEN_VIDEO)
938
939 void MediaPlayer::enterFullscreen()
940 {
941     m_private->enterFullscreen();
942 }
943
944 void MediaPlayer::exitFullscreen()
945 {
946     m_private->exitFullscreen();
947 }
948
949 #endif
950
951 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
952
953 bool MediaPlayer::isCurrentPlaybackTargetWireless() const
954 {
955     return m_private->isCurrentPlaybackTargetWireless();
956 }
957
958 String MediaPlayer::wirelessPlaybackTargetName() const
959 {
960     return m_private->wirelessPlaybackTargetName();
961 }
962
963 MediaPlayer::WirelessPlaybackTargetType MediaPlayer::wirelessPlaybackTargetType() const
964 {
965     return m_private->wirelessPlaybackTargetType();
966 }
967
968 bool MediaPlayer::wirelessVideoPlaybackDisabled() const
969 {
970     return m_private->wirelessVideoPlaybackDisabled();
971 }
972
973 void MediaPlayer::setWirelessVideoPlaybackDisabled(bool disabled)
974 {
975     m_private->setWirelessVideoPlaybackDisabled(disabled);
976 }
977
978 void MediaPlayer::currentPlaybackTargetIsWirelessChanged()
979 {
980     client().mediaPlayerCurrentPlaybackTargetIsWirelessChanged(this);
981 }
982
983 bool MediaPlayer::canPlayToWirelessPlaybackTarget() const
984 {
985     return m_private->canPlayToWirelessPlaybackTarget();
986 }
987
988 void MediaPlayer::setWirelessPlaybackTarget(Ref<MediaPlaybackTarget>&& device)
989 {
990     m_private->setWirelessPlaybackTarget(WTFMove(device));
991 }
992
993 void MediaPlayer::setShouldPlayToPlaybackTarget(bool shouldPlay)
994 {
995     m_private->setShouldPlayToPlaybackTarget(shouldPlay);
996 }
997
998 #endif
999
1000 double MediaPlayer::maxFastForwardRate() const
1001 {
1002     return m_private->maxFastForwardRate();
1003 }
1004
1005 double MediaPlayer::minFastReverseRate() const
1006 {
1007     return m_private->minFastReverseRate();
1008 }
1009
1010 #if USE(NATIVE_FULLSCREEN_VIDEO)
1011
1012 bool MediaPlayer::canEnterFullscreen() const
1013 {
1014     return m_private->canEnterFullscreen();
1015 }
1016
1017 #endif
1018
1019 void MediaPlayer::acceleratedRenderingStateChanged()
1020 {
1021     m_private->acceleratedRenderingStateChanged();
1022 }
1023
1024 bool MediaPlayer::supportsAcceleratedRendering() const
1025 {
1026     return m_private->supportsAcceleratedRendering();
1027 }
1028
1029 bool MediaPlayer::shouldMaintainAspectRatio() const
1030 {
1031     return m_private->shouldMaintainAspectRatio();
1032 }
1033
1034 void MediaPlayer::setShouldMaintainAspectRatio(bool maintainAspectRatio)
1035 {
1036     m_private->setShouldMaintainAspectRatio(maintainAspectRatio);
1037 }
1038
1039 bool MediaPlayer::hasSingleSecurityOrigin() const
1040 {
1041     return m_private->hasSingleSecurityOrigin();
1042 }
1043
1044 bool MediaPlayer::didPassCORSAccessCheck() const
1045 {
1046     return m_private->didPassCORSAccessCheck();
1047 }
1048
1049 bool MediaPlayer::wouldTaintOrigin(const SecurityOrigin& origin) const
1050 {
1051     auto wouldTaint = m_private->wouldTaintOrigin(origin);
1052     if (wouldTaint.has_value())
1053         return wouldTaint.value();
1054
1055     if (m_url.protocolIsData())
1056         return false;
1057
1058     return !origin.canRequest(m_url);
1059 }
1060
1061 MediaPlayer::MovieLoadType MediaPlayer::movieLoadType() const
1062 {
1063     return m_private->movieLoadType();
1064 }
1065
1066 MediaTime MediaPlayer::mediaTimeForTimeValue(const MediaTime& timeValue) const
1067 {
1068     return m_private->mediaTimeForTimeValue(timeValue);
1069 }
1070
1071 double MediaPlayer::maximumDurationToCacheMediaTime() const
1072 {
1073     return m_private->maximumDurationToCacheMediaTime();
1074 }
1075
1076 unsigned MediaPlayer::decodedFrameCount() const
1077 {
1078     return m_private->decodedFrameCount();
1079 }
1080
1081 unsigned MediaPlayer::droppedFrameCount() const
1082 {
1083     return m_private->droppedFrameCount();
1084 }
1085
1086 unsigned MediaPlayer::audioDecodedByteCount() const
1087 {
1088     return m_private->audioDecodedByteCount();
1089 }
1090
1091 unsigned MediaPlayer::videoDecodedByteCount() const
1092 {
1093     return m_private->videoDecodedByteCount();
1094 }
1095
1096 void MediaPlayer::reloadTimerFired()
1097 {
1098     m_private->cancelLoad();
1099     loadWithNextMediaEngine(m_currentMediaEngine);
1100 }
1101
1102 template<typename T>
1103 static void addToHash(HashSet<T>& toHash, HashSet<T>&& fromHash)
1104 {
1105     if (toHash.isEmpty())
1106         toHash = WTFMove(fromHash);
1107     else
1108         toHash.add(fromHash.begin(), fromHash.end());
1109 }
1110     
1111 HashSet<RefPtr<SecurityOrigin>> MediaPlayer::originsInMediaCache(const String& path)
1112 {
1113     HashSet<RefPtr<SecurityOrigin>> origins;
1114     for (auto& engine : installedMediaEngines()) {
1115         if (!engine.originsInMediaCache)
1116             continue;
1117         addToHash(origins, engine.originsInMediaCache(path));
1118     }
1119     return origins;
1120 }
1121
1122 void MediaPlayer::clearMediaCache(const String& path, WallTime modifiedSince)
1123 {
1124     for (auto& engine : installedMediaEngines()) {
1125         if (engine.clearMediaCache)
1126             engine.clearMediaCache(path, modifiedSince);
1127     }
1128 }
1129
1130 void MediaPlayer::clearMediaCacheForOrigins(const String& path, const HashSet<RefPtr<SecurityOrigin>>& origins)
1131 {
1132     for (auto& engine : installedMediaEngines()) {
1133         if (engine.clearMediaCacheForOrigins)
1134             engine.clearMediaCacheForOrigins(path, origins);
1135     }
1136 }
1137
1138 bool MediaPlayer::supportsKeySystem(const String& keySystem, const String& mimeType)
1139 {
1140     for (auto& engine : installedMediaEngines()) {
1141         if (engine.supportsKeySystem && engine.supportsKeySystem(keySystem, mimeType))
1142             return true;
1143     }
1144     return false;
1145 }
1146
1147 void MediaPlayer::setPrivateBrowsingMode(bool privateBrowsingMode)
1148 {
1149     m_privateBrowsing = privateBrowsingMode;
1150     if (m_private)
1151         m_private->setPrivateBrowsingMode(m_privateBrowsing);
1152 }
1153
1154 // Client callbacks.
1155 void MediaPlayer::networkStateChanged()
1156 {
1157     // If more than one media engine is installed and this one failed before finding metadata,
1158     // let the next engine try.
1159     if (m_private->networkState() >= FormatError && m_private->readyState() < HaveMetadata) {
1160         client().mediaPlayerEngineFailedToLoad();
1161         if (installedMediaEngines().size() > 1 && (m_contentType.isEmpty() || nextBestMediaEngine(m_currentMediaEngine))) {
1162             m_reloadTimer.startOneShot(0_s);
1163             return;
1164         }
1165     }
1166     client().mediaPlayerNetworkStateChanged(this);
1167 }
1168
1169 void MediaPlayer::readyStateChanged()
1170 {
1171     client().mediaPlayerReadyStateChanged(this);
1172 }
1173
1174 void MediaPlayer::volumeChanged(double newVolume)
1175 {
1176 #if PLATFORM(IOS)
1177     UNUSED_PARAM(newVolume);
1178     m_volume = m_private->volume();
1179 #else
1180     m_volume = newVolume;
1181 #endif
1182     client().mediaPlayerVolumeChanged(this);
1183 }
1184
1185 void MediaPlayer::muteChanged(bool newMuted)
1186 {
1187     if (newMuted == m_muted)
1188         return;
1189
1190     m_muted = newMuted;
1191     client().mediaPlayerMuteChanged(this);
1192 }
1193
1194 void MediaPlayer::timeChanged()
1195 {
1196     client().mediaPlayerTimeChanged(this);
1197 }
1198
1199 void MediaPlayer::sizeChanged()
1200 {
1201     client().mediaPlayerSizeChanged(this);
1202 }
1203
1204 void MediaPlayer::repaint()
1205 {
1206     client().mediaPlayerRepaint(this);
1207 }
1208
1209 void MediaPlayer::durationChanged()
1210 {
1211     client().mediaPlayerDurationChanged(this);
1212 }
1213
1214 void MediaPlayer::rateChanged()
1215 {
1216     client().mediaPlayerRateChanged(this);
1217 }
1218
1219 void MediaPlayer::playbackStateChanged()
1220 {
1221     client().mediaPlayerPlaybackStateChanged(this);
1222 }
1223
1224 void MediaPlayer::firstVideoFrameAvailable()
1225 {
1226     client().mediaPlayerFirstVideoFrameAvailable(this);
1227 }
1228
1229 void MediaPlayer::characteristicChanged()
1230 {
1231     client().mediaPlayerCharacteristicChanged(this);
1232 }
1233
1234 #if ENABLE(WEB_AUDIO)
1235
1236 AudioSourceProvider* MediaPlayer::audioSourceProvider()
1237 {
1238     return m_private->audioSourceProvider();
1239 }
1240
1241 #endif
1242
1243 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
1244
1245 RefPtr<ArrayBuffer> MediaPlayer::cachedKeyForKeyId(const String& keyId) const
1246 {
1247     return client().mediaPlayerCachedKeyForKeyId(keyId);
1248 }
1249
1250 bool MediaPlayer::keyNeeded(Uint8Array* initData)
1251 {
1252     return client().mediaPlayerKeyNeeded(this, initData);
1253 }
1254
1255 String MediaPlayer::mediaKeysStorageDirectory() const
1256 {
1257     return client().mediaPlayerMediaKeysStorageDirectory();
1258 }
1259
1260 #endif
1261
1262 #if ENABLE(ENCRYPTED_MEDIA)
1263
1264 void MediaPlayer::initializationDataEncountered(const String& initDataType, RefPtr<ArrayBuffer>&& initData)
1265 {
1266     client().mediaPlayerInitializationDataEncountered(initDataType, WTFMove(initData));
1267 }
1268
1269 void MediaPlayer::waitingForKeyChanged()
1270 {
1271     client().mediaPlayerWaitingForKeyChanged();
1272 }
1273
1274 bool MediaPlayer::waitingForKey() const
1275 {
1276     if (!m_private)
1277         return false;
1278     return m_private->waitingForKey();
1279 }
1280 #endif
1281
1282 String MediaPlayer::referrer() const
1283 {
1284     return client().mediaPlayerReferrer();
1285 }
1286
1287 String MediaPlayer::userAgent() const
1288 {
1289     return client().mediaPlayerUserAgent();
1290 }
1291
1292 String MediaPlayer::engineDescription() const
1293 {
1294     if (!m_private)
1295         return String();
1296
1297     return m_private->engineDescription();
1298 }
1299
1300 long MediaPlayer::platformErrorCode() const
1301 {
1302     if (!m_private)
1303         return 0;
1304
1305     return m_private->platformErrorCode();
1306 }
1307
1308 #if PLATFORM(WIN) && USE(AVFOUNDATION)
1309 GraphicsDeviceAdapter* MediaPlayer::graphicsDeviceAdapter() const
1310 {
1311     return client().mediaPlayerGraphicsDeviceAdapter(this);
1312 }
1313 #endif
1314
1315 CachedResourceLoader* MediaPlayer::cachedResourceLoader()
1316 {
1317     return client().mediaPlayerCachedResourceLoader();
1318 }
1319
1320 RefPtr<PlatformMediaResourceLoader> MediaPlayer::createResourceLoader()
1321 {
1322     return client().mediaPlayerCreateResourceLoader();
1323 }
1324
1325 #if ENABLE(VIDEO_TRACK)
1326
1327 void MediaPlayer::addAudioTrack(AudioTrackPrivate& track)
1328 {
1329     client().mediaPlayerDidAddAudioTrack(track);
1330 }
1331
1332 void MediaPlayer::removeAudioTrack(AudioTrackPrivate& track)
1333 {
1334     client().mediaPlayerDidRemoveAudioTrack(track);
1335 }
1336
1337 void MediaPlayer::addTextTrack(InbandTextTrackPrivate& track)
1338 {
1339     client().mediaPlayerDidAddTextTrack(track);
1340 }
1341
1342 void MediaPlayer::removeTextTrack(InbandTextTrackPrivate& track)
1343 {
1344     client().mediaPlayerDidRemoveTextTrack(track);
1345 }
1346
1347 void MediaPlayer::addVideoTrack(VideoTrackPrivate& track)
1348 {
1349     client().mediaPlayerDidAddVideoTrack(track);
1350 }
1351
1352 void MediaPlayer::removeVideoTrack(VideoTrackPrivate& track)
1353 {
1354     client().mediaPlayerDidRemoveVideoTrack(track);
1355 }
1356
1357 bool MediaPlayer::requiresTextTrackRepresentation() const
1358 {
1359     return m_private->requiresTextTrackRepresentation();
1360 }
1361
1362 void MediaPlayer::setTextTrackRepresentation(TextTrackRepresentation* representation)
1363 {
1364     m_private->setTextTrackRepresentation(representation);
1365 }
1366
1367 void MediaPlayer::syncTextTrackBounds()
1368 {
1369     m_private->syncTextTrackBounds();
1370 }
1371
1372 void MediaPlayer::tracksChanged()
1373 {
1374     m_private->tracksChanged();
1375 }
1376
1377 #if ENABLE(AVF_CAPTIONS)
1378
1379 void MediaPlayer::notifyTrackModeChanged()
1380 {
1381     if (m_private)
1382         m_private->notifyTrackModeChanged();
1383 }
1384
1385 Vector<RefPtr<PlatformTextTrack>> MediaPlayer::outOfBandTrackSources()
1386 {
1387     return client().outOfBandTrackSources();
1388 }
1389
1390 #endif
1391
1392 #endif // ENABLE(VIDEO_TRACK)
1393
1394 void MediaPlayer::resetMediaEngines()
1395 {
1396     auto locker = holdLock(mediaEngineVectorLock);
1397
1398     mutableInstalledMediaEnginesVector().clear();
1399     haveMediaEnginesVector() = false;
1400 }
1401
1402 #if USE(GSTREAMER)
1403 void MediaPlayer::simulateAudioInterruption()
1404 {
1405     if (!m_private)
1406         return;
1407
1408     m_private->simulateAudioInterruption();
1409 }
1410 #endif
1411
1412 void MediaPlayer::beginSimulatedHDCPError()
1413 {
1414     if (m_private)
1415         m_private->beginSimulatedHDCPError();
1416 }
1417
1418 void MediaPlayer::endSimulatedHDCPError()
1419 {
1420     if (m_private)
1421         m_private->endSimulatedHDCPError();
1422 }
1423
1424 String MediaPlayer::languageOfPrimaryAudioTrack() const
1425 {
1426     if (!m_private)
1427         return emptyString();
1428     
1429     return m_private->languageOfPrimaryAudioTrack();
1430 }
1431
1432 size_t MediaPlayer::extraMemoryCost() const
1433 {
1434     if (!m_private)
1435         return 0;
1436
1437     return m_private->extraMemoryCost();
1438 }
1439
1440 unsigned long long MediaPlayer::fileSize() const
1441 {
1442     if (!m_private)
1443         return 0;
1444     
1445     return m_private->fileSize();
1446 }
1447
1448 bool MediaPlayer::ended() const
1449 {
1450     return m_private->ended();
1451 }
1452
1453 std::optional<VideoPlaybackQualityMetrics> MediaPlayer::videoPlaybackQualityMetrics()
1454 {
1455     if (!m_private)
1456         return std::nullopt;
1457
1458     return m_private->videoPlaybackQualityMetrics();
1459 }
1460
1461 void MediaPlayer::handlePlaybackCommand(PlatformMediaSession::RemoteControlCommandType command)
1462 {
1463     client().mediaPlayerHandlePlaybackCommand(command);
1464 }
1465
1466 String MediaPlayer::sourceApplicationIdentifier() const
1467 {
1468     return client().mediaPlayerSourceApplicationIdentifier();
1469 }
1470
1471 Vector<String> MediaPlayer::preferredAudioCharacteristics() const
1472 {
1473     return client().mediaPlayerPreferredAudioCharacteristics();
1474 }
1475
1476 void MediaPlayerFactorySupport::callRegisterMediaEngine(MediaEngineRegister registerMediaEngine)
1477 {
1478     registerMediaEngine(addMediaEngine);
1479 }
1480
1481 bool MediaPlayer::doesHaveAttribute(const AtomicString& attribute, AtomicString* value) const
1482 {
1483     return client().doesHaveAttribute(attribute, value);
1484 }
1485
1486 #if PLATFORM(IOS)
1487 String MediaPlayer::mediaPlayerNetworkInterfaceName() const
1488 {
1489     return client().mediaPlayerNetworkInterfaceName();
1490 }
1491
1492 bool MediaPlayer::getRawCookies(const URL& url, Vector<Cookie>& cookies) const
1493 {
1494     return client().mediaPlayerGetRawCookies(url, cookies);
1495 }
1496 #endif
1497
1498 void MediaPlayer::setShouldDisableSleep(bool flag)
1499 {
1500     if (m_private)
1501         m_private->setShouldDisableSleep(flag);
1502 }
1503
1504 bool MediaPlayer::shouldDisableSleep() const
1505 {
1506     return client().mediaPlayerShouldDisableSleep();
1507 }
1508
1509 const Vector<ContentType>& MediaPlayer::mediaContentTypesRequiringHardwareSupport() const
1510 {
1511     return client().mediaContentTypesRequiringHardwareSupport();
1512 }
1513
1514 bool MediaPlayer::shouldCheckHardwareSupport() const
1515 {
1516     return client().mediaPlayerShouldCheckHardwareSupport();
1517 }
1518
1519 void MediaPlayer::applicationWillResignActive()
1520 {
1521     m_private->applicationWillResignActive();
1522 }
1523
1524 void MediaPlayer::applicationDidBecomeActive()
1525 {
1526     m_private->applicationDidBecomeActive();
1527 }
1528
1529 #if ENABLE(VIDEO) && USE(AVFOUNDATION)
1530
1531 AVPlayer* MediaPlayer::objCAVFoundationAVPlayer() const
1532 {
1533     return m_private->objCAVFoundationAVPlayer();
1534 }
1535
1536 #endif
1537
1538 #if !RELEASE_LOG_DISABLED
1539 const Logger& MediaPlayer::mediaPlayerLogger()
1540 {
1541     return client().mediaPlayerLogger();
1542 }
1543 #endif
1544
1545 String convertEnumerationToString(MediaPlayerEnums::ReadyState enumerationValue)
1546 {
1547     static const NeverDestroyed<String> values[] = {
1548         MAKE_STATIC_STRING_IMPL("HaveNothing"),
1549         MAKE_STATIC_STRING_IMPL("HaveMetadata"),
1550         MAKE_STATIC_STRING_IMPL("HaveCurrentData"),
1551         MAKE_STATIC_STRING_IMPL("HaveFutureData"),
1552         MAKE_STATIC_STRING_IMPL("HaveEnoughData"),
1553     };
1554     static_assert(static_cast<size_t>(MediaPlayerEnums::HaveNothing) == 0, "MediaPlayerEnums::HaveNothing is not 0 as expected");
1555     static_assert(static_cast<size_t>(MediaPlayerEnums::HaveMetadata) == 1, "MediaPlayerEnums::HaveMetadata is not 1 as expected");
1556     static_assert(static_cast<size_t>(MediaPlayerEnums::HaveCurrentData) == 2, "MediaPlayerEnums::HaveCurrentData is not 2 as expected");
1557     static_assert(static_cast<size_t>(MediaPlayerEnums::HaveFutureData) == 3, "MediaPlayerEnums::HaveFutureData is not 3 as expected");
1558     static_assert(static_cast<size_t>(MediaPlayerEnums::HaveEnoughData) == 4, "MediaPlayerEnums::HaveEnoughData is not 4 as expected");
1559     ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
1560     return values[static_cast<size_t>(enumerationValue)];
1561 }
1562
1563 String convertEnumerationToString(MediaPlayerEnums::NetworkState enumerationValue)
1564 {
1565     static const NeverDestroyed<String> values[] = {
1566         MAKE_STATIC_STRING_IMPL("Empty"),
1567         MAKE_STATIC_STRING_IMPL("Idle"),
1568         MAKE_STATIC_STRING_IMPL("Loading"),
1569         MAKE_STATIC_STRING_IMPL("Loaded"),
1570         MAKE_STATIC_STRING_IMPL("FormatError"),
1571         MAKE_STATIC_STRING_IMPL("NetworkError"),
1572         MAKE_STATIC_STRING_IMPL("DecodeError"),
1573     };
1574     static_assert(static_cast<size_t>(MediaPlayerEnums::Empty) == 0, "MediaPlayerEnums::Empty is not 0 as expected");
1575     static_assert(static_cast<size_t>(MediaPlayerEnums::Idle) == 1, "MediaPlayerEnums::Idle is not 1 as expected");
1576     static_assert(static_cast<size_t>(MediaPlayerEnums::Loading) == 2, "MediaPlayerEnums::Loading is not 2 as expected");
1577     static_assert(static_cast<size_t>(MediaPlayerEnums::Loaded) == 3, "MediaPlayerEnums::Loaded is not 3 as expected");
1578     static_assert(static_cast<size_t>(MediaPlayerEnums::FormatError) == 4, "MediaPlayerEnums::FormatError is not 4 as expected");
1579     static_assert(static_cast<size_t>(MediaPlayerEnums::NetworkError) == 5, "MediaPlayerEnums::NetworkError is not 5 as expected");
1580     static_assert(static_cast<size_t>(MediaPlayerEnums::DecodeError) == 6, "MediaPlayerEnums::DecodeError is not 6 as expected");
1581     ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
1582     return values[static_cast<size_t>(enumerationValue)];
1583 }
1584
1585 String convertEnumerationToString(MediaPlayerEnums::Preload enumerationValue)
1586 {
1587     static const NeverDestroyed<String> values[] = {
1588         MAKE_STATIC_STRING_IMPL("None"),
1589         MAKE_STATIC_STRING_IMPL("MetaData"),
1590         MAKE_STATIC_STRING_IMPL("Auto"),
1591     };
1592     static_assert(!static_cast<size_t>(MediaPlayerEnums::None), "MediaPlayerEnums::None is not 0 as expected");
1593     static_assert(static_cast<size_t>(MediaPlayerEnums::MetaData) == 1, "MediaPlayerEnums::MetaData is not 1 as expected");
1594     static_assert(static_cast<size_t>(MediaPlayerEnums::Auto) == 2, "MediaPlayerEnums::Auto is not 2 as expected");
1595     ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
1596     return values[static_cast<size_t>(enumerationValue)];
1597 }
1598
1599 }
1600
1601 #endif