2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, 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 COMPUTER, 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.
29 #include "MediaPlayer.h"
31 #include "ContentType.h"
34 #include "FrameView.h"
37 #include "MIMETypeRegistry.h"
38 #include "MediaPlayerPrivate.h"
40 #include "TimeRanges.h"
41 #include <wtf/text/CString.h>
48 #include "MediaPlayerPrivateGStreamer.h"
49 #define PlatformMediaEngineClassName MediaPlayerPrivateGStreamer
52 #if PLATFORM(MAC) || (PLATFORM(QT) && USE(QTKIT))
53 #include "MediaPlayerPrivateQTKit.h"
55 #include "MediaPlayerPrivateAVFoundationObjC.h"
57 #define PlatformMediaEngineClassName MediaPlayerPrivateQTKit
58 #elif OS(WINCE) && !PLATFORM(QT)
59 #include "MediaPlayerPrivateWinCE.h"
60 #define PlatformMediaEngineClassName MediaPlayerPrivate
62 #include "MediaPlayerPrivateQuickTimeVisualContext.h"
63 #define PlatformMediaEngineClassName MediaPlayerPrivateQuickTimeVisualContext
65 #include "MediaPlayerPrivateAVFoundationCF.h"
68 #if USE(QT_MULTIMEDIA) && !USE(GSTREAMER)
69 #include "MediaPlayerPrivateQt.h"
70 #define PlatformMediaEngineClassName MediaPlayerPrivateQt
72 #elif PLATFORM(CHROMIUM)
73 #include "MediaPlayerPrivateChromium.h"
74 #define PlatformMediaEngineClassName MediaPlayerPrivate
75 #elif PLATFORM(BLACKBERRY)
76 #include "MediaPlayerPrivateBlackBerry.h"
77 #define PlatformMediaEngineClassName MediaPlayerPrivate
82 const PlatformMedia NoPlatformMedia = { PlatformMedia::None, {0} };
84 // a null player to make MediaPlayer logic simpler
86 class NullMediaPlayerPrivate : public MediaPlayerPrivateInterface {
88 NullMediaPlayerPrivate(MediaPlayer*) { }
90 virtual void load(const String&) { }
91 virtual void cancelLoad() { }
93 virtual void prepareToPlay() { }
94 virtual void play() { }
95 virtual void pause() { }
97 virtual PlatformMedia platformMedia() const { return NoPlatformMedia; }
98 #if USE(ACCELERATED_COMPOSITING)
99 virtual PlatformLayer* platformLayer() const { return 0; }
100 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
101 virtual bool supportsAcceleratedRendering() const { return true; }
105 virtual IntSize naturalSize() const { return IntSize(0, 0); }
107 virtual bool hasVideo() const { return false; }
108 virtual bool hasAudio() const { return false; }
110 virtual void setVisible(bool) { }
112 virtual float duration() const { return 0; }
114 virtual float currentTime() const { return 0; }
115 virtual void seek(float) { }
116 virtual bool seeking() const { return false; }
118 virtual void setRate(float) { }
119 virtual void setPreservesPitch(bool) { }
120 virtual bool paused() const { return false; }
122 virtual void setVolume(float) { }
124 virtual bool supportsMuting() const { return false; }
125 virtual void setMuted(bool) { }
127 virtual bool hasClosedCaptions() const { return false; }
128 virtual void setClosedCaptionsVisible(bool) { };
130 virtual MediaPlayer::NetworkState networkState() const { return MediaPlayer::Empty; }
131 virtual MediaPlayer::ReadyState readyState() const { return MediaPlayer::HaveNothing; }
133 virtual float maxTimeSeekable() const { return 0; }
134 virtual PassRefPtr<TimeRanges> buffered() const { return TimeRanges::create(); }
136 virtual unsigned totalBytes() const { return 0; }
137 virtual bool didLoadingProgress() const { return false; }
139 virtual void setSize(const IntSize&) { }
141 virtual void paint(GraphicsContext*, const IntRect&) { }
143 virtual bool canLoadPoster() const { return false; }
144 virtual void setPoster(const String&) { }
146 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
147 virtual void deliverNotification(MediaPlayerProxyNotificationType) { }
148 virtual void setMediaPlayerProxy(WebMediaPlayerProxy*) { }
149 virtual void setControls(bool) { }
152 virtual bool hasSingleSecurityOrigin() const { return true; }
154 #if ENABLE(MEDIA_SOURCE)
155 virtual MediaPlayer::AddIdStatus sourceAddId(const String& id, const String& type, const Vector<String>& codecs) { return MediaPlayer::NotSupported; }
156 virtual PassRefPtr<TimeRanges> sourceBuffered(const String&) { return TimeRanges::create(); }
157 virtual bool sourceRemoveId(const String&) { return false; }
158 virtual bool sourceAppend(const String&, const unsigned char*, unsigned) { return false; }
159 virtual bool sourceAbort(const String&) { return false; }
160 virtual void sourceEndOfStream(MediaPlayer::EndOfStreamStatus) { }
163 #if ENABLE(ENCRYPTED_MEDIA)
164 virtual MediaPlayer::MediaKeyException generateKeyRequest(const String&, const unsigned char*, unsigned) OVERRIDE { return MediaPlayer::InvalidPlayerState; }
165 virtual MediaPlayer::MediaKeyException addKey(const String&, const unsigned char*, unsigned, const unsigned char*, unsigned, const String&) OVERRIDE { return MediaPlayer::InvalidPlayerState; }
166 virtual MediaPlayer::MediaKeyException cancelKeyRequest(const String&, const String&) OVERRIDE { return MediaPlayer::InvalidPlayerState; }
170 static PassOwnPtr<MediaPlayerPrivateInterface> createNullMediaPlayer(MediaPlayer* player)
172 return adoptPtr(new NullMediaPlayerPrivate(player));
178 struct MediaPlayerFactory {
179 WTF_MAKE_NONCOPYABLE(MediaPlayerFactory); WTF_MAKE_FAST_ALLOCATED;
181 MediaPlayerFactory(CreateMediaEnginePlayer constructor, MediaEngineSupportedTypes getSupportedTypes, MediaEngineSupportsType supportsTypeAndCodecs,
182 MediaEngineGetSitesInMediaCache getSitesInMediaCache, MediaEngineClearMediaCache clearMediaCache, MediaEngineClearMediaCacheForSite clearMediaCacheForSite)
183 : constructor(constructor)
184 , getSupportedTypes(getSupportedTypes)
185 , supportsTypeAndCodecs(supportsTypeAndCodecs)
186 , getSitesInMediaCache(getSitesInMediaCache)
187 , clearMediaCache(clearMediaCache)
188 , clearMediaCacheForSite(clearMediaCacheForSite)
192 CreateMediaEnginePlayer constructor;
193 MediaEngineSupportedTypes getSupportedTypes;
194 MediaEngineSupportsType supportsTypeAndCodecs;
195 MediaEngineGetSitesInMediaCache getSitesInMediaCache;
196 MediaEngineClearMediaCache clearMediaCache;
197 MediaEngineClearMediaCacheForSite clearMediaCacheForSite;
200 static void addMediaEngine(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType, MediaEngineGetSitesInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForSite);
202 static MediaPlayerFactory* bestMediaEngineForTypeAndCodecs(const String& type, const String& codecs, const String& keySystem, const KURL&, MediaPlayerFactory* current = 0);
203 static MediaPlayerFactory* nextMediaEngine(MediaPlayerFactory* current);
205 static Vector<MediaPlayerFactory*>& installedMediaEngines()
207 DEFINE_STATIC_LOCAL(Vector<MediaPlayerFactory*>, installedEngines, ());
208 static bool enginesQueried = false;
210 if (!enginesQueried) {
211 enginesQueried = true;
213 #if USE(AVFOUNDATION)
214 if (1 /* @@Settings::isAVFoundationEnabled() @@ */) {
216 MediaPlayerPrivateAVFoundationObjC::registerMediaEngine(addMediaEngine);
218 MediaPlayerPrivateAVFoundationCF::registerMediaEngine(addMediaEngine);
223 #if defined(PlatformMediaEngineClassName)
224 PlatformMediaEngineClassName::registerMediaEngine(addMediaEngine);
228 return installedEngines;
231 static void addMediaEngine(CreateMediaEnginePlayer constructor, MediaEngineSupportedTypes getSupportedTypes, MediaEngineSupportsType supportsType,
232 MediaEngineGetSitesInMediaCache getSitesInMediaCache, MediaEngineClearMediaCache clearMediaCache, MediaEngineClearMediaCacheForSite clearMediaCacheForSite)
235 ASSERT(getSupportedTypes);
236 ASSERT(supportsType);
238 installedMediaEngines().append(new MediaPlayerFactory(constructor, getSupportedTypes, supportsType, getSitesInMediaCache, clearMediaCache, clearMediaCacheForSite));
241 static const AtomicString& applicationOctetStream()
243 DEFINE_STATIC_LOCAL(const AtomicString, applicationOctetStream, ("application/octet-stream"));
244 return applicationOctetStream;
247 static const AtomicString& textPlain()
249 DEFINE_STATIC_LOCAL(const AtomicString, textPlain, ("text/plain"));
253 static const AtomicString& codecs()
255 DEFINE_STATIC_LOCAL(const AtomicString, codecs, ("codecs"));
259 static MediaPlayerFactory* bestMediaEngineForTypeAndCodecs(const String& type, const String& codecs, const String& keySystem, const KURL& url, MediaPlayerFactory* current)
264 Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
265 if (engines.isEmpty())
268 // 4.8.10.3 MIME types - In the absence of a specification to the contrary, the MIME type "application/octet-stream"
269 // when used with parameters, e.g. "application/octet-stream;codecs=theora", is a type that the user agent knows
271 if (type == applicationOctetStream()) {
272 if (!codecs.isEmpty())
276 MediaPlayerFactory* engine = 0;
277 MediaPlayer::SupportsType supported = MediaPlayer::IsNotSupported;
278 unsigned count = engines.size();
279 for (unsigned ndx = 0; ndx < count; ndx++) {
281 if (current == engines[ndx])
285 #if ENABLE(ENCRYPTED_MEDIA)
286 MediaPlayer::SupportsType engineSupport = engines[ndx]->supportsTypeAndCodecs(type, codecs, keySystem, url);
288 UNUSED_PARAM(keySystem);
289 ASSERT(keySystem.isEmpty());
290 MediaPlayer::SupportsType engineSupport = engines[ndx]->supportsTypeAndCodecs(type, codecs, url);
292 if (engineSupport > supported) {
293 supported = engineSupport;
294 engine = engines[ndx];
301 static MediaPlayerFactory* nextMediaEngine(MediaPlayerFactory* current)
303 Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
304 if (engines.isEmpty())
308 return engines.first();
310 size_t currentIndex = engines.find(current);
311 if (currentIndex == WTF::notFound || currentIndex + 1 >= engines.size())
314 return engines[currentIndex + 1];
319 MediaPlayer::MediaPlayer(MediaPlayerClient* client)
320 : m_mediaPlayerClient(client)
321 , m_reloadTimer(this, &MediaPlayer::reloadTimerFired)
322 , m_private(createNullMediaPlayer(this))
323 , m_currentMediaEngine(0)
330 , m_preservesPitch(true)
331 , m_privateBrowsing(false)
332 , m_shouldPrepareToRender(false)
333 , m_contentMIMETypeWasInferredFromExtension(false)
334 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
338 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
339 Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
340 if (!engines.isEmpty()) {
341 m_currentMediaEngine = engines[0];
342 m_private = engines[0]->constructor(this);
343 if (m_mediaPlayerClient)
344 m_mediaPlayerClient->mediaPlayerEngineUpdated(this);
349 MediaPlayer::~MediaPlayer()
351 m_mediaPlayerClient = 0;
354 bool MediaPlayer::load(const KURL& url, const ContentType& contentType, const String& keySystem)
356 m_contentMIMEType = contentType.type().lower();
357 m_contentTypeCodecs = contentType.parameter(codecs());
359 m_keySystem = keySystem.lower();
360 m_contentMIMETypeWasInferredFromExtension = false;
362 // If the MIME type is missing or is not meaningful, try to figure it out from the URL.
363 if (m_contentMIMEType.isEmpty() || m_contentMIMEType == applicationOctetStream() || m_contentMIMEType == textPlain()) {
364 if (protocolIs(m_url.string(), "data"))
365 m_contentMIMEType = mimeTypeFromDataURL(m_url.string());
367 String lastPathComponent = url.lastPathComponent();
368 size_t pos = lastPathComponent.reverseFind('.');
369 if (pos != notFound) {
370 String extension = lastPathComponent.substring(pos + 1);
371 String mediaType = MIMETypeRegistry::getMediaMIMETypeForExtension(extension);
372 if (!mediaType.isEmpty()) {
373 m_contentMIMEType = mediaType;
374 m_contentMIMETypeWasInferredFromExtension = true;
380 loadWithNextMediaEngine(0);
381 return m_currentMediaEngine;
384 void MediaPlayer::loadWithNextMediaEngine(MediaPlayerFactory* current)
386 MediaPlayerFactory* engine = 0;
388 if (!m_contentMIMEType.isEmpty())
389 engine = bestMediaEngineForTypeAndCodecs(m_contentMIMEType, m_contentTypeCodecs, m_keySystem, m_url, current);
391 // If no MIME type is specified or the type was inferred from the file extension, just use the next engine.
392 if (!engine && (m_contentMIMEType.isEmpty() || m_contentMIMETypeWasInferredFromExtension))
393 engine = nextMediaEngine(current);
395 // Don't delete and recreate the player unless it comes from a different engine.
397 LOG(Media, "MediaPlayer::loadWithNextMediaEngine - no media engine found for type \"%s\"", m_contentMIMEType.utf8().data());
398 m_currentMediaEngine = engine;
400 } else if (m_currentMediaEngine != engine) {
401 m_currentMediaEngine = engine;
402 m_private = engine->constructor(this);
403 if (m_mediaPlayerClient)
404 m_mediaPlayerClient->mediaPlayerEngineUpdated(this);
405 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
406 m_private->setMediaPlayerProxy(m_playerProxy);
408 m_private->setPrivateBrowsingMode(m_privateBrowsing);
409 m_private->setPreload(m_preload);
410 m_private->setPreservesPitch(preservesPitch());
411 if (m_shouldPrepareToRender)
412 m_private->prepareForRendering();
416 m_private->load(m_url.string());
418 m_private = createNullMediaPlayer(this);
419 if (m_mediaPlayerClient) {
420 m_mediaPlayerClient->mediaPlayerEngineUpdated(this);
421 m_mediaPlayerClient->mediaPlayerResourceNotSupported(this);
426 bool MediaPlayer::hasAvailableVideoFrame() const
428 return m_private->hasAvailableVideoFrame();
431 void MediaPlayer::prepareForRendering()
433 m_shouldPrepareToRender = true;
434 m_private->prepareForRendering();
437 bool MediaPlayer::canLoadPoster() const
439 return m_private->canLoadPoster();
442 void MediaPlayer::setPoster(const String& url)
444 m_private->setPoster(url);
447 void MediaPlayer::cancelLoad()
449 m_private->cancelLoad();
452 void MediaPlayer::prepareToPlay()
454 m_private->prepareToPlay();
457 void MediaPlayer::play()
462 void MediaPlayer::pause()
467 #if ENABLE(MEDIA_SOURCE)
469 MediaPlayer::AddIdStatus MediaPlayer::sourceAddId(const String& id, const String& type, const Vector<String>& codecs)
471 return m_private->sourceAddId(id, type, codecs);
474 PassRefPtr<TimeRanges> MediaPlayer::sourceBuffered(const String& id)
476 return m_private->sourceBuffered(id);
479 bool MediaPlayer::sourceRemoveId(const String& id)
481 return m_private->sourceRemoveId(id);
484 bool MediaPlayer::sourceAppend(const String& id, const unsigned char* data, unsigned length)
486 return m_private->sourceAppend(id, data, length);
489 bool MediaPlayer::sourceAbort(const String& id)
491 return m_private->sourceAbort(id);
494 void MediaPlayer::sourceEndOfStream(MediaPlayer::EndOfStreamStatus status)
496 return m_private->sourceEndOfStream(status);
500 #if ENABLE(ENCRYPTED_MEDIA)
501 MediaPlayer::MediaKeyException MediaPlayer::generateKeyRequest(const String& keySystem, const unsigned char* initData, unsigned initDataLength)
503 return m_private->generateKeyRequest(keySystem.lower(), initData, initDataLength);
506 MediaPlayer::MediaKeyException MediaPlayer::addKey(const String& keySystem, const unsigned char* key, unsigned keyLength, const unsigned char* initData, unsigned initDataLength, const String& sessionId)
508 return m_private->addKey(keySystem.lower(), key, keyLength, initData, initDataLength, sessionId);
511 MediaPlayer::MediaKeyException MediaPlayer::cancelKeyRequest(const String& keySystem, const String& sessionId)
513 return m_private->cancelKeyRequest(keySystem.lower(), sessionId);
517 float MediaPlayer::duration() const
519 return m_private->duration();
522 float MediaPlayer::startTime() const
524 return m_private->startTime();
527 double MediaPlayer::initialTime() const
529 return m_private->initialTime();
532 float MediaPlayer::currentTime() const
534 return m_private->currentTime();
537 void MediaPlayer::seek(float time)
539 m_private->seek(time);
542 bool MediaPlayer::paused() const
544 return m_private->paused();
547 bool MediaPlayer::seeking() const
549 return m_private->seeking();
552 bool MediaPlayer::supportsFullscreen() const
554 return m_private->supportsFullscreen();
557 bool MediaPlayer::supportsSave() const
559 return m_private->supportsSave();
562 bool MediaPlayer::supportsScanning() const
564 return m_private->supportsScanning();
567 IntSize MediaPlayer::naturalSize()
569 return m_private->naturalSize();
572 bool MediaPlayer::hasVideo() const
574 return m_private->hasVideo();
577 bool MediaPlayer::hasAudio() const
579 return m_private->hasAudio();
582 bool MediaPlayer::inMediaDocument()
584 Frame* frame = m_frameView ? m_frameView->frame() : 0;
585 Document* document = frame ? frame->document() : 0;
587 return document && document->isMediaDocument();
590 PlatformMedia MediaPlayer::platformMedia() const
592 return m_private->platformMedia();
595 #if USE(ACCELERATED_COMPOSITING)
596 PlatformLayer* MediaPlayer::platformLayer() const
598 return m_private->platformLayer();
602 MediaPlayer::NetworkState MediaPlayer::networkState()
604 return m_private->networkState();
607 MediaPlayer::ReadyState MediaPlayer::readyState()
609 return m_private->readyState();
612 float MediaPlayer::volume() const
617 void MediaPlayer::setVolume(float volume)
621 if (m_private->supportsMuting() || !m_muted)
622 m_private->setVolume(volume);
625 bool MediaPlayer::muted() const
630 void MediaPlayer::setMuted(bool muted)
634 if (m_private->supportsMuting())
635 m_private->setMuted(muted);
637 m_private->setVolume(muted ? 0 : m_volume);
640 bool MediaPlayer::hasClosedCaptions() const
642 return m_private->hasClosedCaptions();
645 void MediaPlayer::setClosedCaptionsVisible(bool closedCaptionsVisible)
647 m_private->setClosedCaptionsVisible(closedCaptionsVisible);
650 float MediaPlayer::rate() const
655 void MediaPlayer::setRate(float rate)
658 m_private->setRate(rate);
661 bool MediaPlayer::preservesPitch() const
663 return m_preservesPitch;
666 void MediaPlayer::setPreservesPitch(bool preservesPitch)
668 m_preservesPitch = preservesPitch;
669 m_private->setPreservesPitch(preservesPitch);
672 PassRefPtr<TimeRanges> MediaPlayer::buffered()
674 return m_private->buffered();
677 PassRefPtr<TimeRanges> MediaPlayer::seekable()
679 return m_private->seekable();
682 float MediaPlayer::maxTimeSeekable()
684 return m_private->maxTimeSeekable();
687 bool MediaPlayer::didLoadingProgress()
689 return m_private->didLoadingProgress();
692 void MediaPlayer::setSize(const IntSize& size)
695 m_private->setSize(size);
698 bool MediaPlayer::visible() const
703 void MediaPlayer::setVisible(bool b)
706 m_private->setVisible(b);
709 MediaPlayer::Preload MediaPlayer::preload() const
714 void MediaPlayer::setPreload(MediaPlayer::Preload preload)
717 m_private->setPreload(preload);
720 void MediaPlayer::paint(GraphicsContext* p, const IntRect& r)
722 m_private->paint(p, r);
725 void MediaPlayer::paintCurrentFrameInContext(GraphicsContext* p, const IntRect& r)
727 m_private->paintCurrentFrameInContext(p, r);
730 MediaPlayer::SupportsType MediaPlayer::supportsType(const ContentType& contentType, const String& keySystem, const KURL& url, const MediaPlayerSupportsTypeClient* client)
732 String type = contentType.type().lower();
733 // The codecs string is not lower-cased because MP4 values are case sensitive
734 // per http://tools.ietf.org/html/rfc4281#page-7.
735 String typeCodecs = contentType.parameter(codecs());
736 String system = keySystem.lower();
738 // 4.8.10.3 MIME types - The canPlayType(type) method must return the empty string if type is a type that the
739 // user agent knows it cannot render or is the type "application/octet-stream"
740 if (type == applicationOctetStream())
741 return IsNotSupported;
743 MediaPlayerFactory* engine = bestMediaEngineForTypeAndCodecs(type, typeCodecs, system, url);
745 return IsNotSupported;
748 // YouTube will ask if the HTMLMediaElement canPlayType video/webm, then
749 // video/x-flv, then finally video/mp4, and will then load a URL of the first type
750 // in that list which returns "probably". When Perian is installed,
751 // MediaPlayerPrivateQTKit claims to support both video/webm and video/x-flv, but
752 // due to a bug in Perian, loading media in these formats will sometimes fail on
753 // slow connections. <https://bugs.webkit.org/show_bug.cgi?id=86409>
754 if (client && client->mediaPlayerNeedsSiteSpecificHacks()) {
755 String host = client->mediaPlayerDocumentHost();
756 if ((host.endsWith(".youtube.com", false) || equalIgnoringCase("youtube.com", host))
757 && (contentType.type().startsWith("video/webm", false) || contentType.type().startsWith("video/x-flv", false)))
758 return IsNotSupported;
762 #if ENABLE(ENCRYPTED_MEDIA)
763 return engine->supportsTypeAndCodecs(type, typeCodecs, system, url);
765 ASSERT(system.isEmpty());
766 return engine->supportsTypeAndCodecs(type, typeCodecs, url);
770 void MediaPlayer::getSupportedTypes(HashSet<String>& types)
772 Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
773 if (engines.isEmpty())
776 unsigned count = engines.size();
777 for (unsigned ndx = 0; ndx < count; ndx++)
778 engines[ndx]->getSupportedTypes(types);
781 bool MediaPlayer::isAvailable()
783 return !installedMediaEngines().isEmpty();
786 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
787 void MediaPlayer::deliverNotification(MediaPlayerProxyNotificationType notification)
789 m_private->deliverNotification(notification);
792 void MediaPlayer::setMediaPlayerProxy(WebMediaPlayerProxy* proxy)
794 m_playerProxy = proxy;
795 m_private->setMediaPlayerProxy(proxy);
798 void MediaPlayer::setControls(bool controls)
800 m_private->setControls(controls);
804 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO) || USE(NATIVE_FULLSCREEN_VIDEO)
805 void MediaPlayer::enterFullscreen()
807 m_private->enterFullscreen();
810 void MediaPlayer::exitFullscreen()
812 m_private->exitFullscreen();
816 #if USE(NATIVE_FULLSCREEN_VIDEO)
817 bool MediaPlayer::canEnterFullscreen() const
819 return m_private->canEnterFullscreen();
823 #if USE(ACCELERATED_COMPOSITING)
824 void MediaPlayer::acceleratedRenderingStateChanged()
826 m_private->acceleratedRenderingStateChanged();
829 bool MediaPlayer::supportsAcceleratedRendering() const
831 return m_private->supportsAcceleratedRendering();
833 #endif // USE(ACCELERATED_COMPOSITING)
835 bool MediaPlayer::hasSingleSecurityOrigin() const
837 return m_private->hasSingleSecurityOrigin();
840 bool MediaPlayer::didPassCORSAccessCheck() const
842 return m_private->didPassCORSAccessCheck();
845 MediaPlayer::MovieLoadType MediaPlayer::movieLoadType() const
847 return m_private->movieLoadType();
850 float MediaPlayer::mediaTimeForTimeValue(float timeValue) const
852 return m_private->mediaTimeForTimeValue(timeValue);
855 double MediaPlayer::maximumDurationToCacheMediaTime() const
857 return m_private->maximumDurationToCacheMediaTime();
860 unsigned MediaPlayer::decodedFrameCount() const
862 return m_private->decodedFrameCount();
865 unsigned MediaPlayer::droppedFrameCount() const
867 return m_private->droppedFrameCount();
870 unsigned MediaPlayer::audioDecodedByteCount() const
872 return m_private->audioDecodedByteCount();
875 unsigned MediaPlayer::videoDecodedByteCount() const
877 return m_private->videoDecodedByteCount();
880 void MediaPlayer::reloadTimerFired(Timer<MediaPlayer>*)
882 m_private->cancelLoad();
883 loadWithNextMediaEngine(m_currentMediaEngine);
886 void MediaPlayer::getSitesInMediaCache(Vector<String>& sites)
888 Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
889 unsigned size = engines.size();
890 for (unsigned i = 0; i < size; i++) {
891 if (!engines[i]->getSitesInMediaCache)
893 Vector<String> engineSites;
894 engines[i]->getSitesInMediaCache(engineSites);
895 sites.append(engineSites);
899 void MediaPlayer::clearMediaCache()
901 Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
902 unsigned size = engines.size();
903 for (unsigned i = 0; i < size; i++) {
904 if (engines[i]->clearMediaCache)
905 engines[i]->clearMediaCache();
909 void MediaPlayer::clearMediaCacheForSite(const String& site)
911 Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
912 unsigned size = engines.size();
913 for (unsigned i = 0; i < size; i++) {
914 if (engines[i]->clearMediaCacheForSite)
915 engines[i]->clearMediaCacheForSite(site);
919 void MediaPlayer::setPrivateBrowsingMode(bool privateBrowsingMode)
921 m_privateBrowsing = privateBrowsingMode;
922 m_private->setPrivateBrowsingMode(m_privateBrowsing);
925 #if ENABLE(MEDIA_SOURCE)
926 void MediaPlayer::sourceOpened()
928 if (m_mediaPlayerClient)
929 m_mediaPlayerClient->mediaPlayerSourceOpened();
932 String MediaPlayer::sourceURL() const
934 if (m_mediaPlayerClient)
935 return m_mediaPlayerClient->mediaPlayerSourceURL();
941 void MediaPlayer::networkStateChanged()
943 // If more than one media engine is installed and this one failed before finding metadata,
944 // let the next engine try.
945 if (m_private->networkState() >= FormatError
946 && m_private->readyState() < HaveMetadata
947 && installedMediaEngines().size() > 1) {
948 if (m_contentMIMEType.isEmpty() || bestMediaEngineForTypeAndCodecs(m_contentMIMEType, m_contentTypeCodecs, m_keySystem, m_url, m_currentMediaEngine)) {
949 m_reloadTimer.startOneShot(0);
953 if (m_mediaPlayerClient)
954 m_mediaPlayerClient->mediaPlayerNetworkStateChanged(this);
957 void MediaPlayer::readyStateChanged()
959 if (m_mediaPlayerClient)
960 m_mediaPlayerClient->mediaPlayerReadyStateChanged(this);
963 void MediaPlayer::volumeChanged(float newVolume)
965 m_volume = newVolume;
966 if (m_mediaPlayerClient)
967 m_mediaPlayerClient->mediaPlayerVolumeChanged(this);
970 void MediaPlayer::muteChanged(bool newMuted)
973 if (m_mediaPlayerClient)
974 m_mediaPlayerClient->mediaPlayerMuteChanged(this);
977 void MediaPlayer::timeChanged()
979 if (m_mediaPlayerClient)
980 m_mediaPlayerClient->mediaPlayerTimeChanged(this);
983 void MediaPlayer::sizeChanged()
985 if (m_mediaPlayerClient)
986 m_mediaPlayerClient->mediaPlayerSizeChanged(this);
989 void MediaPlayer::repaint()
991 if (m_mediaPlayerClient)
992 m_mediaPlayerClient->mediaPlayerRepaint(this);
995 void MediaPlayer::durationChanged()
997 if (m_mediaPlayerClient)
998 m_mediaPlayerClient->mediaPlayerDurationChanged(this);
1001 void MediaPlayer::rateChanged()
1003 if (m_mediaPlayerClient)
1004 m_mediaPlayerClient->mediaPlayerRateChanged(this);
1007 void MediaPlayer::playbackStateChanged()
1009 if (m_mediaPlayerClient)
1010 m_mediaPlayerClient->mediaPlayerPlaybackStateChanged(this);
1013 void MediaPlayer::firstVideoFrameAvailable()
1015 if (m_mediaPlayerClient)
1016 m_mediaPlayerClient->mediaPlayerFirstVideoFrameAvailable(this);
1019 void MediaPlayer::characteristicChanged()
1021 if (m_mediaPlayerClient)
1022 m_mediaPlayerClient->mediaPlayerCharacteristicChanged(this);
1025 #if ENABLE(WEB_AUDIO)
1026 AudioSourceProvider* MediaPlayer::audioSourceProvider()
1028 return m_private->audioSourceProvider();
1032 #if ENABLE(ENCRYPTED_MEDIA)
1033 void MediaPlayer::keyAdded(const String& keySystem, const String& sessionId)
1035 if (m_mediaPlayerClient)
1036 m_mediaPlayerClient->mediaPlayerKeyAdded(this, keySystem, sessionId);
1039 void MediaPlayer::keyError(const String& keySystem, const String& sessionId, MediaPlayerClient::MediaKeyErrorCode errorCode, unsigned short systemCode)
1041 if (m_mediaPlayerClient)
1042 m_mediaPlayerClient->mediaPlayerKeyError(this, keySystem, sessionId, errorCode, systemCode);
1045 void MediaPlayer::keyMessage(const String& keySystem, const String& sessionId, const unsigned char* message, unsigned messageLength)
1047 if (m_mediaPlayerClient)
1048 m_mediaPlayerClient->mediaPlayerKeyMessage(this, keySystem, sessionId, message, messageLength);
1051 void MediaPlayer::keyNeeded(const String& keySystem, const String& sessionId, const unsigned char* initData, unsigned initDataLength)
1053 if (m_mediaPlayerClient)
1054 m_mediaPlayerClient->mediaPlayerKeyNeeded(this, keySystem, sessionId, initData, initDataLength);
1058 String MediaPlayer::referrer() const
1060 if (!m_mediaPlayerClient)
1063 return m_mediaPlayerClient->mediaPlayerReferrer();
1066 String MediaPlayer::userAgent() const
1068 if (!m_mediaPlayerClient)
1071 return m_mediaPlayerClient->mediaPlayerUserAgent();
1074 String MediaPlayer::engineDescription() const
1079 return m_private->engineDescription();
1082 #if PLATFORM(WIN) && USE(AVFOUNDATION)
1083 GraphicsDeviceAdapter* MediaPlayer::graphicsDeviceAdapter() const
1085 if (!m_mediaPlayerClient)
1088 return m_mediaPlayerClient->mediaPlayerGraphicsDeviceAdapter(this);