• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007, 2008, 2009, 2010, 2011 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 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.
24  */
25 
26 #include "config.h"
27 
28 #if ENABLE(VIDEO)
29 #include "MediaPlayer.h"
30 
31 #include "ContentType.h"
32 #include "Document.h"
33 #include "Frame.h"
34 #include "FrameView.h"
35 #include "IntRect.h"
36 #include "MIMETypeRegistry.h"
37 #include "MediaPlayerPrivate.h"
38 #include "TimeRanges.h"
39 
40 #if PLATFORM(QT)
41 #include <QtGlobal>
42 #endif
43 
44 #if USE(GSTREAMER)
45 #include "MediaPlayerPrivateGStreamer.h"
46 #endif
47 
48 #if PLATFORM(MAC)
49 #include "MediaPlayerPrivateQTKit.h"
50 #if USE(AVFOUNDATION)
51 #include "MediaPlayerPrivateAVFoundationObjC.h"
52 #endif
53 #define PlatformMediaEngineClassName MediaPlayerPrivateQTKit
54 #elif OS(WINCE) && !PLATFORM(QT)
55 #include "MediaPlayerPrivateWinCE.h"
56 #define PlatformMediaEngineClassName MediaPlayerPrivate
57 #elif PLATFORM(WIN)
58 #include "MediaPlayerPrivateQuickTimeVisualContext.h"
59 #define PlatformMediaEngineClassName MediaPlayerPrivateQuickTimeVisualContext
60 #elif PLATFORM(QT)
61 #if USE(QT_MULTIMEDIA) && !USE(GSTREAMER)
62 #include "MediaPlayerPrivateQt.h"
63 #define PlatformMediaEngineClassName MediaPlayerPrivateQt
64 #elif !USE(GSTREAMER)
65 #include "MediaPlayerPrivatePhonon.h"
66 #define PlatformMediaEngineClassName MediaPlayerPrivatePhonon
67 #endif
68 #elif PLATFORM(CHROMIUM)
69 #include "MediaPlayerPrivateChromium.h"
70 #define PlatformMediaEngineClassName MediaPlayerPrivate
71 #elif PLATFORM(ANDROID)
72 #include "MediaPlayerPrivateAndroid.h"
73 #define PlatformMediaEngineClassName MediaPlayerPrivate
74 #endif
75 
76 namespace WebCore {
77 
78 const PlatformMedia NoPlatformMedia = { PlatformMedia::None, {0} };
79 
80 // a null player to make MediaPlayer logic simpler
81 
82 class NullMediaPlayerPrivate : public MediaPlayerPrivateInterface {
83 public:
NullMediaPlayerPrivate(MediaPlayer *)84     NullMediaPlayerPrivate(MediaPlayer*) { }
85 
load(const String &)86     virtual void load(const String&) { }
cancelLoad()87     virtual void cancelLoad() { }
88 
prepareToPlay()89     virtual void prepareToPlay() { }
play()90     virtual void play() { }
pause()91     virtual void pause() { }
92 
platformMedia() const93     virtual PlatformMedia platformMedia() const { return NoPlatformMedia; }
94 #if USE(ACCELERATED_COMPOSITING)
platformLayer() const95     virtual PlatformLayer* platformLayer() const { return 0; }
96 #endif
97 
naturalSize() const98     virtual IntSize naturalSize() const { return IntSize(0, 0); }
99 
hasVideo() const100     virtual bool hasVideo() const { return false; }
hasAudio() const101     virtual bool hasAudio() const { return false; }
102 
setVisible(bool)103     virtual void setVisible(bool) { }
104 
duration() const105     virtual float duration() const { return 0; }
106 
currentTime() const107     virtual float currentTime() const { return 0; }
seek(float)108     virtual void seek(float) { }
seeking() const109     virtual bool seeking() const { return false; }
110 
setRate(float)111     virtual void setRate(float) { }
setPreservesPitch(bool)112     virtual void setPreservesPitch(bool) { }
paused() const113     virtual bool paused() const { return false; }
114 
setVolume(float)115     virtual void setVolume(float) { }
116 
supportsMuting() const117     virtual bool supportsMuting() const { return false; }
setMuted(bool)118     virtual void setMuted(bool) { }
119 
hasClosedCaptions() const120     virtual bool hasClosedCaptions() const { return false; }
setClosedCaptionsVisible(bool)121     virtual void setClosedCaptionsVisible(bool) { };
122 
networkState() const123     virtual MediaPlayer::NetworkState networkState() const { return MediaPlayer::Empty; }
readyState() const124     virtual MediaPlayer::ReadyState readyState() const { return MediaPlayer::HaveNothing; }
125 
maxTimeSeekable() const126     virtual float maxTimeSeekable() const { return 0; }
buffered() const127     virtual PassRefPtr<TimeRanges> buffered() const { return TimeRanges::create(); }
128 
totalBytes() const129     virtual unsigned totalBytes() const { return 0; }
bytesLoaded() const130     virtual unsigned bytesLoaded() const { return 0; }
131 
setSize(const IntSize &)132     virtual void setSize(const IntSize&) { }
133 
paint(GraphicsContext *,const IntRect &)134     virtual void paint(GraphicsContext*, const IntRect&) { }
135 
canLoadPoster() const136     virtual bool canLoadPoster() const { return false; }
setPoster(const String &)137     virtual void setPoster(const String&) { }
138 
139 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
deliverNotification(MediaPlayerProxyNotificationType)140     virtual void deliverNotification(MediaPlayerProxyNotificationType) { }
setMediaPlayerProxy(WebMediaPlayerProxy *)141     virtual void setMediaPlayerProxy(WebMediaPlayerProxy*) { }
setControls(bool)142     virtual void setControls(bool) { }
143 #endif
144 
hasSingleSecurityOrigin() const145     virtual bool hasSingleSecurityOrigin() const { return true; }
146 };
147 
createNullMediaPlayer(MediaPlayer * player)148 static MediaPlayerPrivateInterface* createNullMediaPlayer(MediaPlayer* player)
149 {
150     return new NullMediaPlayerPrivate(player);
151 }
152 
153 
154 // engine support
155 
156 struct MediaPlayerFactory {
157     WTF_MAKE_NONCOPYABLE(MediaPlayerFactory); WTF_MAKE_FAST_ALLOCATED;
158 public:
MediaPlayerFactoryWebCore::MediaPlayerFactory159     MediaPlayerFactory(CreateMediaEnginePlayer constructor, MediaEngineSupportedTypes getSupportedTypes, MediaEngineSupportsType supportsTypeAndCodecs,
160         MediaEngineGetSitesInMediaCache getSitesInMediaCache, MediaEngineClearMediaCache clearMediaCache, MediaEngineClearMediaCacheForSite clearMediaCacheForSite)
161         : constructor(constructor)
162         , getSupportedTypes(getSupportedTypes)
163         , supportsTypeAndCodecs(supportsTypeAndCodecs)
164         , getSitesInMediaCache(getSitesInMediaCache)
165         , clearMediaCache(clearMediaCache)
166         , clearMediaCacheForSite(clearMediaCacheForSite)
167 
168     {
169     }
170 
171     CreateMediaEnginePlayer constructor;
172     MediaEngineSupportedTypes getSupportedTypes;
173     MediaEngineSupportsType supportsTypeAndCodecs;
174     MediaEngineGetSitesInMediaCache getSitesInMediaCache;
175     MediaEngineClearMediaCache clearMediaCache;
176     MediaEngineClearMediaCacheForSite clearMediaCacheForSite;
177 };
178 
179 static void addMediaEngine(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType, MediaEngineGetSitesInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForSite);
180 static MediaPlayerFactory* bestMediaEngineForTypeAndCodecs(const String& type, const String& codecs, MediaPlayerFactory* current = 0);
181 static MediaPlayerFactory* nextMediaEngine(MediaPlayerFactory* current);
182 
installedMediaEngines()183 static Vector<MediaPlayerFactory*>& installedMediaEngines()
184 {
185     DEFINE_STATIC_LOCAL(Vector<MediaPlayerFactory*>, installedEngines, ());
186     static bool enginesQueried = false;
187 
188     if (!enginesQueried) {
189         enginesQueried = true;
190 
191 #if USE(GSTREAMER)
192         MediaPlayerPrivateGStreamer::registerMediaEngine(addMediaEngine);
193 #endif
194 
195 #if USE(AVFOUNDATION) && PLATFORM(MAC)
196         MediaPlayerPrivateAVFoundationObjC::registerMediaEngine(addMediaEngine);
197 #endif
198 
199 #if !PLATFORM(GTK) && !PLATFORM(EFL) && !(PLATFORM(QT) && USE(GSTREAMER))
200         PlatformMediaEngineClassName::registerMediaEngine(addMediaEngine);
201 #endif
202     }
203 
204     return installedEngines;
205 }
206 
addMediaEngine(CreateMediaEnginePlayer constructor,MediaEngineSupportedTypes getSupportedTypes,MediaEngineSupportsType supportsType,MediaEngineGetSitesInMediaCache getSitesInMediaCache,MediaEngineClearMediaCache clearMediaCache,MediaEngineClearMediaCacheForSite clearMediaCacheForSite)207 static void addMediaEngine(CreateMediaEnginePlayer constructor, MediaEngineSupportedTypes getSupportedTypes, MediaEngineSupportsType supportsType,
208     MediaEngineGetSitesInMediaCache getSitesInMediaCache, MediaEngineClearMediaCache clearMediaCache, MediaEngineClearMediaCacheForSite clearMediaCacheForSite)
209 {
210     ASSERT(constructor);
211     ASSERT(getSupportedTypes);
212     ASSERT(supportsType);
213 
214     installedMediaEngines().append(new MediaPlayerFactory(constructor, getSupportedTypes, supportsType, getSitesInMediaCache, clearMediaCache, clearMediaCacheForSite));
215 }
216 
applicationOctetStream()217 static const AtomicString& applicationOctetStream()
218 {
219     DEFINE_STATIC_LOCAL(const AtomicString, applicationOctetStream, ("application/octet-stream"));
220     return applicationOctetStream;
221 }
222 
textPlain()223 static const AtomicString& textPlain()
224 {
225     DEFINE_STATIC_LOCAL(const AtomicString, textPlain, ("text/plain"));
226     return textPlain;
227 }
228 
codecs()229 static const AtomicString& codecs()
230 {
231     DEFINE_STATIC_LOCAL(const AtomicString, codecs, ("codecs"));
232     return codecs;
233 }
234 
bestMediaEngineForTypeAndCodecs(const String & type,const String & codecs,MediaPlayerFactory * current)235 static MediaPlayerFactory* bestMediaEngineForTypeAndCodecs(const String& type, const String& codecs, MediaPlayerFactory* current)
236 {
237     if (type.isEmpty())
238         return 0;
239 
240     Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
241     if (engines.isEmpty())
242         return 0;
243 
244     // 4.8.10.3 MIME types - In the absence of a specification to the contrary, the MIME type "application/octet-stream"
245     // when used with parameters, e.g. "application/octet-stream;codecs=theora", is a type that the user agent knows
246     // it cannot render.
247     if (type == applicationOctetStream()) {
248         if (!codecs.isEmpty())
249             return 0;
250     }
251 
252     MediaPlayerFactory* engine = 0;
253     MediaPlayer::SupportsType supported = MediaPlayer::IsNotSupported;
254     unsigned count = engines.size();
255     for (unsigned ndx = 0; ndx < count; ndx++) {
256         if (current) {
257             if (current == engines[ndx])
258                 current = 0;
259             continue;
260         }
261         MediaPlayer::SupportsType engineSupport = engines[ndx]->supportsTypeAndCodecs(type, codecs);
262         if (engineSupport > supported) {
263             supported = engineSupport;
264             engine = engines[ndx];
265         }
266     }
267 
268     return engine;
269 }
270 
nextMediaEngine(MediaPlayerFactory * current)271 static MediaPlayerFactory* nextMediaEngine(MediaPlayerFactory* current)
272 {
273     Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
274     if (engines.isEmpty())
275         return 0;
276 
277     if (!current)
278         return engines.first();
279 
280     size_t currentIndex = engines.find(current);
281     if (currentIndex == WTF::notFound || currentIndex == engines.size())
282         return 0;
283 
284     return engines[currentIndex + 1];
285 }
286 
287 // media player
288 
MediaPlayer(MediaPlayerClient * client)289 MediaPlayer::MediaPlayer(MediaPlayerClient* client)
290     : m_mediaPlayerClient(client)
291     , m_reloadTimer(this, &MediaPlayer::reloadTimerFired)
292     , m_private(createNullMediaPlayer(this))
293     , m_currentMediaEngine(0)
294     , m_frameView(0)
295     , m_preload(Auto)
296     , m_visible(false)
297     , m_rate(1.0f)
298     , m_volume(1.0f)
299     , m_muted(false)
300     , m_preservesPitch(true)
301     , m_privateBrowsing(false)
302     , m_shouldPrepareToRender(false)
303 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
304     , m_playerProxy(0)
305 #endif
306 #if PLATFORM(ANDROID)
307     , m_mediaElementType(Video)
308 #endif
309 {
310 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
311     Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
312     if (!engines.isEmpty()) {
313         m_currentMediaEngine = engines[0];
314         m_private.clear();
315         m_private.set(engines[0]->constructor(this));
316         if (m_mediaPlayerClient)
317             m_mediaPlayerClient->mediaPlayerEngineUpdated(this);
318     }
319 #endif
320 }
321 
~MediaPlayer()322 MediaPlayer::~MediaPlayer()
323 {
324     m_mediaPlayerClient = 0;
325 }
326 
load(const String & url,const ContentType & contentType)327 void MediaPlayer::load(const String& url, const ContentType& contentType)
328 {
329     String type = contentType.type().lower();
330     String typeCodecs = contentType.parameter(codecs());
331 
332     // If the MIME type is missing or is not meaningful, try to figure it out from the URL.
333     if (type.isEmpty() || type == applicationOctetStream() || type == textPlain()) {
334         if (protocolIs(url, "data"))
335             type = mimeTypeFromDataURL(url);
336         else {
337             size_t pos = url.reverseFind('.');
338             if (pos != notFound) {
339                 String extension = url.substring(pos + 1);
340                 String mediaType = MIMETypeRegistry::getMediaMIMETypeForExtension(extension);
341                 if (!mediaType.isEmpty())
342                     type = mediaType;
343             }
344         }
345     }
346 
347     m_url = url;
348     m_contentMIMEType = type;
349     m_contentTypeCodecs = typeCodecs;
350     loadWithNextMediaEngine(0);
351 }
352 
loadWithNextMediaEngine(MediaPlayerFactory * current)353 void MediaPlayer::loadWithNextMediaEngine(MediaPlayerFactory* current)
354 {
355     MediaPlayerFactory* engine;
356 
357     // If no MIME type is specified, just use the next engine.
358     if (m_contentMIMEType.isEmpty())
359         engine = nextMediaEngine(current);
360     else
361         engine = bestMediaEngineForTypeAndCodecs(m_contentMIMEType, m_contentTypeCodecs, current);
362 
363     // Don't delete and recreate the player unless it comes from a different engine.
364     if (!engine) {
365         m_currentMediaEngine = engine;
366         m_private.clear();
367     } else if (m_currentMediaEngine != engine) {
368         m_currentMediaEngine = engine;
369         m_private.clear();
370         m_private.set(engine->constructor(this));
371         if (m_mediaPlayerClient)
372             m_mediaPlayerClient->mediaPlayerEngineUpdated(this);
373 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
374         m_private->setMediaPlayerProxy(m_playerProxy);
375 #endif
376         m_private->setPrivateBrowsingMode(m_privateBrowsing);
377         m_private->setPreload(m_preload);
378         m_private->setPreservesPitch(preservesPitch());
379         if (m_shouldPrepareToRender)
380             m_private->prepareForRendering();
381     }
382 
383     if (m_private)
384         m_private->load(m_url);
385     else {
386         m_private.set(createNullMediaPlayer(this));
387         if (m_mediaPlayerClient)
388             m_mediaPlayerClient->mediaPlayerEngineUpdated(this);
389     }
390 }
391 
hasAvailableVideoFrame() const392 bool MediaPlayer::hasAvailableVideoFrame() const
393 {
394     return m_private->hasAvailableVideoFrame();
395 }
396 
prepareForRendering()397 void MediaPlayer::prepareForRendering()
398 {
399     m_shouldPrepareToRender = true;
400     m_private->prepareForRendering();
401 }
402 
canLoadPoster() const403 bool MediaPlayer::canLoadPoster() const
404 {
405     return m_private->canLoadPoster();
406 }
407 
setPoster(const String & url)408 void MediaPlayer::setPoster(const String& url)
409 {
410     m_private->setPoster(url);
411 }
412 
cancelLoad()413 void MediaPlayer::cancelLoad()
414 {
415     m_private->cancelLoad();
416 }
417 
prepareToPlay()418 void MediaPlayer::prepareToPlay()
419 {
420     m_private->prepareToPlay();
421 }
422 
play()423 void MediaPlayer::play()
424 {
425     m_private->play();
426 }
427 
pause()428 void MediaPlayer::pause()
429 {
430     m_private->pause();
431 }
432 
duration() const433 float MediaPlayer::duration() const
434 {
435     return m_private->duration();
436 }
437 
startTime() const438 float MediaPlayer::startTime() const
439 {
440     return m_private->startTime();
441 }
442 
currentTime() const443 float MediaPlayer::currentTime() const
444 {
445     return m_private->currentTime();
446 }
447 
seek(float time)448 void MediaPlayer::seek(float time)
449 {
450     m_private->seek(time);
451 }
452 
paused() const453 bool MediaPlayer::paused() const
454 {
455     return m_private->paused();
456 }
457 
seeking() const458 bool MediaPlayer::seeking() const
459 {
460     return m_private->seeking();
461 }
462 
supportsFullscreen() const463 bool MediaPlayer::supportsFullscreen() const
464 {
465     return m_private->supportsFullscreen();
466 }
467 
supportsSave() const468 bool MediaPlayer::supportsSave() const
469 {
470     return m_private->supportsSave();
471 }
472 
naturalSize()473 IntSize MediaPlayer::naturalSize()
474 {
475     return m_private->naturalSize();
476 }
477 
hasVideo() const478 bool MediaPlayer::hasVideo() const
479 {
480     return m_private->hasVideo();
481 }
482 
hasAudio() const483 bool MediaPlayer::hasAudio() const
484 {
485     return m_private->hasAudio();
486 }
487 
inMediaDocument()488 bool MediaPlayer::inMediaDocument()
489 {
490     Frame* frame = m_frameView ? m_frameView->frame() : 0;
491     Document* document = frame ? frame->document() : 0;
492 
493     return document && document->isMediaDocument();
494 }
495 
platformMedia() const496 PlatformMedia MediaPlayer::platformMedia() const
497 {
498     return m_private->platformMedia();
499 }
500 
501 #if USE(ACCELERATED_COMPOSITING)
platformLayer() const502 PlatformLayer* MediaPlayer::platformLayer() const
503 {
504     return m_private->platformLayer();
505 }
506 #endif
507 
networkState()508 MediaPlayer::NetworkState MediaPlayer::networkState()
509 {
510     return m_private->networkState();
511 }
512 
readyState()513 MediaPlayer::ReadyState MediaPlayer::readyState()
514 {
515     return m_private->readyState();
516 }
517 
volume() const518 float MediaPlayer::volume() const
519 {
520     return m_volume;
521 }
522 
setVolume(float volume)523 void MediaPlayer::setVolume(float volume)
524 {
525     m_volume = volume;
526 
527     if (m_private->supportsMuting() || !m_muted)
528         m_private->setVolume(volume);
529 }
530 
muted() const531 bool MediaPlayer::muted() const
532 {
533     return m_muted;
534 }
535 
setMuted(bool muted)536 void MediaPlayer::setMuted(bool muted)
537 {
538     m_muted = muted;
539 
540     if (m_private->supportsMuting())
541         m_private->setMuted(muted);
542     else
543         m_private->setVolume(muted ? 0 : m_volume);
544 }
545 
hasClosedCaptions() const546 bool MediaPlayer::hasClosedCaptions() const
547 {
548     return m_private->hasClosedCaptions();
549 }
550 
setClosedCaptionsVisible(bool closedCaptionsVisible)551 void MediaPlayer::setClosedCaptionsVisible(bool closedCaptionsVisible)
552 {
553     m_private->setClosedCaptionsVisible(closedCaptionsVisible);
554 }
555 
rate() const556 float MediaPlayer::rate() const
557 {
558     return m_rate;
559 }
560 
setRate(float rate)561 void MediaPlayer::setRate(float rate)
562 {
563     m_rate = rate;
564     m_private->setRate(rate);
565 }
566 
preservesPitch() const567 bool MediaPlayer::preservesPitch() const
568 {
569     return m_preservesPitch;
570 }
571 
setPreservesPitch(bool preservesPitch)572 void MediaPlayer::setPreservesPitch(bool preservesPitch)
573 {
574     m_preservesPitch = preservesPitch;
575     m_private->setPreservesPitch(preservesPitch);
576 }
577 
buffered()578 PassRefPtr<TimeRanges> MediaPlayer::buffered()
579 {
580     return m_private->buffered();
581 }
582 
maxTimeSeekable()583 float MediaPlayer::maxTimeSeekable()
584 {
585     return m_private->maxTimeSeekable();
586 }
587 
bytesLoaded()588 unsigned MediaPlayer::bytesLoaded()
589 {
590     return m_private->bytesLoaded();
591 }
592 
setSize(const IntSize & size)593 void MediaPlayer::setSize(const IntSize& size)
594 {
595     m_size = size;
596     m_private->setSize(size);
597 }
598 
visible() const599 bool MediaPlayer::visible() const
600 {
601     return m_visible;
602 }
603 
setVisible(bool b)604 void MediaPlayer::setVisible(bool b)
605 {
606     m_visible = b;
607     m_private->setVisible(b);
608 }
609 
preload() const610 MediaPlayer::Preload MediaPlayer::preload() const
611 {
612     return m_preload;
613 }
614 
setPreload(MediaPlayer::Preload preload)615 void MediaPlayer::setPreload(MediaPlayer::Preload preload)
616 {
617     m_preload = preload;
618     m_private->setPreload(preload);
619 }
620 
paint(GraphicsContext * p,const IntRect & r)621 void MediaPlayer::paint(GraphicsContext* p, const IntRect& r)
622 {
623     m_private->paint(p, r);
624 }
625 
paintCurrentFrameInContext(GraphicsContext * p,const IntRect & r)626 void MediaPlayer::paintCurrentFrameInContext(GraphicsContext* p, const IntRect& r)
627 {
628     m_private->paintCurrentFrameInContext(p, r);
629 }
630 
supportsType(const ContentType & contentType)631 MediaPlayer::SupportsType MediaPlayer::supportsType(const ContentType& contentType)
632 {
633     String type = contentType.type().lower();
634     String typeCodecs = contentType.parameter(codecs());
635 
636     // 4.8.10.3 MIME types - The canPlayType(type) method must return the empty string if type is a type that the
637     // user agent knows it cannot render or is the type "application/octet-stream"
638     if (type == applicationOctetStream())
639         return IsNotSupported;
640 
641     MediaPlayerFactory* engine = bestMediaEngineForTypeAndCodecs(type, typeCodecs);
642     if (!engine)
643         return IsNotSupported;
644 
645     return engine->supportsTypeAndCodecs(type, typeCodecs);
646 }
647 
getSupportedTypes(HashSet<String> & types)648 void MediaPlayer::getSupportedTypes(HashSet<String>& types)
649 {
650     Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
651     if (engines.isEmpty())
652         return;
653 
654     unsigned count = engines.size();
655     for (unsigned ndx = 0; ndx < count; ndx++)
656         engines[ndx]->getSupportedTypes(types);
657 }
658 
isAvailable()659 bool MediaPlayer::isAvailable()
660 {
661     return !installedMediaEngines().isEmpty();
662 }
663 
664 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
deliverNotification(MediaPlayerProxyNotificationType notification)665 void MediaPlayer::deliverNotification(MediaPlayerProxyNotificationType notification)
666 {
667     m_private->deliverNotification(notification);
668 }
669 
setMediaPlayerProxy(WebMediaPlayerProxy * proxy)670 void MediaPlayer::setMediaPlayerProxy(WebMediaPlayerProxy* proxy)
671 {
672     m_playerProxy = proxy;
673     m_private->setMediaPlayerProxy(proxy);
674 }
675 
setControls(bool controls)676 void MediaPlayer::setControls(bool controls)
677 {
678     m_private->setControls(controls);
679 }
680 
enterFullscreen()681 void MediaPlayer::enterFullscreen()
682 {
683     m_private->enterFullscreen();
684 }
685 
exitFullscreen()686 void MediaPlayer::exitFullscreen()
687 {
688     m_private->exitFullscreen();
689 }
690 #endif
691 
692 #if USE(ACCELERATED_COMPOSITING)
acceleratedRenderingStateChanged()693 void MediaPlayer::acceleratedRenderingStateChanged()
694 {
695     m_private->acceleratedRenderingStateChanged();
696 }
697 
supportsAcceleratedRendering() const698 bool MediaPlayer::supportsAcceleratedRendering() const
699 {
700     return m_private->supportsAcceleratedRendering();
701 }
702 #endif // USE(ACCELERATED_COMPOSITING)
703 
hasSingleSecurityOrigin() const704 bool MediaPlayer::hasSingleSecurityOrigin() const
705 {
706     return m_private->hasSingleSecurityOrigin();
707 }
708 
movieLoadType() const709 MediaPlayer::MovieLoadType MediaPlayer::movieLoadType() const
710 {
711     return m_private->movieLoadType();
712 }
713 
mediaTimeForTimeValue(float timeValue) const714 float MediaPlayer::mediaTimeForTimeValue(float timeValue) const
715 {
716     return m_private->mediaTimeForTimeValue(timeValue);
717 }
718 
maximumDurationToCacheMediaTime() const719 double MediaPlayer::maximumDurationToCacheMediaTime() const
720 {
721     return m_private->maximumDurationToCacheMediaTime();
722 }
723 
decodedFrameCount() const724 unsigned MediaPlayer::decodedFrameCount() const
725 {
726     return m_private->decodedFrameCount();
727 }
728 
droppedFrameCount() const729 unsigned MediaPlayer::droppedFrameCount() const
730 {
731     return m_private->droppedFrameCount();
732 }
733 
audioDecodedByteCount() const734 unsigned MediaPlayer::audioDecodedByteCount() const
735 {
736     return m_private->audioDecodedByteCount();
737 }
738 
videoDecodedByteCount() const739 unsigned MediaPlayer::videoDecodedByteCount() const
740 {
741     return m_private->videoDecodedByteCount();
742 }
743 
reloadTimerFired(Timer<MediaPlayer> *)744 void MediaPlayer::reloadTimerFired(Timer<MediaPlayer>*)
745 {
746     m_private->cancelLoad();
747     loadWithNextMediaEngine(m_currentMediaEngine);
748 }
749 
getSitesInMediaCache(Vector<String> & sites)750 void MediaPlayer::getSitesInMediaCache(Vector<String>& sites)
751 {
752     Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
753     unsigned size = engines.size();
754     for (unsigned i = 0; i < size; i++) {
755         if (!engines[i]->getSitesInMediaCache)
756             continue;
757         Vector<String> engineSites;
758         engines[i]->getSitesInMediaCache(engineSites);
759         sites.append(engineSites);
760     }
761 }
762 
clearMediaCache()763 void MediaPlayer::clearMediaCache()
764 {
765     Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
766     unsigned size = engines.size();
767     for (unsigned i = 0; i < size; i++) {
768         if (engines[i]->clearMediaCache)
769             engines[i]->clearMediaCache();
770     }
771 }
772 
clearMediaCacheForSite(const String & site)773 void MediaPlayer::clearMediaCacheForSite(const String& site)
774 {
775     Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
776     unsigned size = engines.size();
777     for (unsigned i = 0; i < size; i++) {
778         if (engines[i]->clearMediaCacheForSite)
779             engines[i]->clearMediaCacheForSite(site);
780     }
781 }
782 
setPrivateBrowsingMode(bool privateBrowsingMode)783 void MediaPlayer::setPrivateBrowsingMode(bool privateBrowsingMode)
784 {
785     m_privateBrowsing = privateBrowsingMode;
786     m_private->setPrivateBrowsingMode(m_privateBrowsing);
787 }
788 
789 // Client callbacks.
networkStateChanged()790 void MediaPlayer::networkStateChanged()
791 {
792     // If more than one media engine is installed and this one failed before finding metadata,
793     // let the next engine try.
794     if (m_private->networkState() >= FormatError
795         && m_private->readyState() < HaveMetadata
796         && installedMediaEngines().size() > 1) {
797         if ( m_contentMIMEType.isEmpty() || bestMediaEngineForTypeAndCodecs(m_contentMIMEType, m_contentTypeCodecs, m_currentMediaEngine)) {
798             m_reloadTimer.startOneShot(0);
799             return;
800         }
801     }
802     if (m_mediaPlayerClient)
803         m_mediaPlayerClient->mediaPlayerNetworkStateChanged(this);
804 }
805 
readyStateChanged()806 void MediaPlayer::readyStateChanged()
807 {
808     if (m_mediaPlayerClient)
809         m_mediaPlayerClient->mediaPlayerReadyStateChanged(this);
810 }
811 
volumeChanged(float newVolume)812 void MediaPlayer::volumeChanged(float newVolume)
813 {
814     m_volume = newVolume;
815     if (m_mediaPlayerClient)
816         m_mediaPlayerClient->mediaPlayerVolumeChanged(this);
817 }
818 
muteChanged(bool newMuted)819 void MediaPlayer::muteChanged(bool newMuted)
820 {
821     m_muted = newMuted;
822     if (m_mediaPlayerClient)
823         m_mediaPlayerClient->mediaPlayerMuteChanged(this);
824 }
825 
timeChanged()826 void MediaPlayer::timeChanged()
827 {
828     if (m_mediaPlayerClient)
829         m_mediaPlayerClient->mediaPlayerTimeChanged(this);
830 }
831 
sizeChanged()832 void MediaPlayer::sizeChanged()
833 {
834     if (m_mediaPlayerClient)
835         m_mediaPlayerClient->mediaPlayerSizeChanged(this);
836 }
837 
repaint()838 void MediaPlayer::repaint()
839 {
840     if (m_mediaPlayerClient)
841         m_mediaPlayerClient->mediaPlayerRepaint(this);
842 }
843 
durationChanged()844 void MediaPlayer::durationChanged()
845 {
846     if (m_mediaPlayerClient)
847         m_mediaPlayerClient->mediaPlayerDurationChanged(this);
848 }
849 
rateChanged()850 void MediaPlayer::rateChanged()
851 {
852     if (m_mediaPlayerClient)
853         m_mediaPlayerClient->mediaPlayerRateChanged(this);
854 }
855 
playbackStateChanged()856 void MediaPlayer::playbackStateChanged()
857 {
858     if (m_mediaPlayerClient)
859         m_mediaPlayerClient->mediaPlayerPlaybackStateChanged(this);
860 }
861 
firstVideoFrameAvailable()862 void MediaPlayer::firstVideoFrameAvailable()
863 {
864     if (m_mediaPlayerClient)
865         m_mediaPlayerClient->mediaPlayerFirstVideoFrameAvailable(this);
866 }
867 
868 }
869 
870 #endif
871