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