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