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