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