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