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