8cc00cf434d029bfdfcb30113122483a5b6356fc
[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 PassRefPtr<TimeRanges> MediaPlayer::seekable()
639 {
640     return m_private->seekable();
641 }
642
643 float MediaPlayer::maxTimeSeekable()
644 {
645     return m_private->maxTimeSeekable();
646 }
647
648 unsigned MediaPlayer::bytesLoaded()
649 {
650     return m_private->bytesLoaded();
651 }
652
653 void MediaPlayer::setSize(const IntSize& size)
654
655     m_size = size;
656     m_private->setSize(size);
657 }
658
659 // justine.bang@samsung.com
660 #if ENABLE(TIZEN_MM_PLAYER)
661 void MediaPlayer::stop( )
662 {
663     m_private->stop( );
664 }
665
666 void MediaPlayer::smartCalculate()
667 {
668     m_private->smartCalculate();
669 }
670
671 void MediaPlayer::setZoomWeak(void* data)
672 {
673     m_private->setZoomWeak(data);
674 }
675
676 void MediaPlayer::setZoom(void* data)
677 {
678     m_private->setZoom(data);
679 }
680
681 void MediaPlayer::pauseOrResume(bool b)
682 {
683     m_private->pauseOrResume(b);
684 }
685
686 void MediaPlayer::catchMouseDown()
687 {
688     m_private->catchMouseDown();
689 }
690
691 void MediaPlayer::catchMouseUp()
692 {
693     m_private->catchMouseUp();
694 }
695
696 #if !ENABLE(PLUGIN_PROXY_FOR_VIDEO)
697 void MediaPlayer::enterFullscreen()
698 {
699     m_private->enterFullscreen();
700 }
701
702 void MediaPlayer::exitFullscreen()
703 {
704     m_private->exitFullscreen();
705 }
706 #endif
707 #endif
708
709 bool MediaPlayer::visible() const
710 {
711     return m_visible;
712 }
713
714 void MediaPlayer::setVisible(bool b)
715 {
716     m_visible = b;
717     m_private->setVisible(b);
718 }
719
720 MediaPlayer::Preload MediaPlayer::preload() const
721 {
722     return m_preload;
723 }
724
725 void MediaPlayer::setPreload(MediaPlayer::Preload preload)
726 {
727     m_preload = preload;
728     m_private->setPreload(preload);
729 }
730
731 void MediaPlayer::paint(GraphicsContext* p, const IntRect& r)
732 {
733     m_private->paint(p, r);
734 }
735
736 void MediaPlayer::paintCurrentFrameInContext(GraphicsContext* p, const IntRect& r)
737 {
738     m_private->paintCurrentFrameInContext(p, r);
739 }
740
741 MediaPlayer::SupportsType MediaPlayer::supportsType(const ContentType& contentType)
742 {
743     String type = contentType.type().lower();
744     String typeCodecs = contentType.parameter(codecs());
745
746     // 4.8.10.3 MIME types - The canPlayType(type) method must return the empty string if type is a type that the 
747     // user agent knows it cannot render or is the type "application/octet-stream"
748     if (type == applicationOctetStream())
749         return IsNotSupported;
750
751     MediaPlayerFactory* engine = bestMediaEngineForTypeAndCodecs(type, typeCodecs);
752     if (!engine)
753         return IsNotSupported;
754
755     return engine->supportsTypeAndCodecs(type, typeCodecs);
756 }
757
758 void MediaPlayer::getSupportedTypes(HashSet<String>& types)
759 {
760     Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
761     if (engines.isEmpty())
762         return;
763
764     unsigned count = engines.size();
765     for (unsigned ndx = 0; ndx < count; ndx++)
766         engines[ndx]->getSupportedTypes(types);
767
768
769 bool MediaPlayer::isAvailable()
770 {
771     return !installedMediaEngines().isEmpty();
772
773
774 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
775 void MediaPlayer::deliverNotification(MediaPlayerProxyNotificationType notification)
776 {
777     m_private->deliverNotification(notification);
778 }
779
780 void MediaPlayer::setMediaPlayerProxy(WebMediaPlayerProxy* proxy)
781 {
782     m_playerProxy = proxy;
783     m_private->setMediaPlayerProxy(proxy);
784 }
785
786 void MediaPlayer::setControls(bool controls)
787 {
788     m_private->setControls(controls);
789 }    
790
791 void MediaPlayer::enterFullscreen()
792 {
793     m_private->enterFullscreen();
794 }    
795
796 void MediaPlayer::exitFullscreen()
797 {
798     m_private->exitFullscreen();
799 }    
800 #endif
801
802 #if USE(ACCELERATED_COMPOSITING)
803 void MediaPlayer::acceleratedRenderingStateChanged()
804 {
805     m_private->acceleratedRenderingStateChanged();
806 }
807
808 bool MediaPlayer::supportsAcceleratedRendering() const
809 {
810     return m_private->supportsAcceleratedRendering();
811 }
812 #endif // USE(ACCELERATED_COMPOSITING)
813
814 bool MediaPlayer::hasSingleSecurityOrigin() const
815 {
816     return m_private->hasSingleSecurityOrigin();
817 }
818
819 MediaPlayer::MovieLoadType MediaPlayer::movieLoadType() const
820 {
821     return m_private->movieLoadType();
822 }
823
824 float MediaPlayer::mediaTimeForTimeValue(float timeValue) const
825 {
826     return m_private->mediaTimeForTimeValue(timeValue);
827 }
828
829 double MediaPlayer::maximumDurationToCacheMediaTime() const
830 {
831     return m_private->maximumDurationToCacheMediaTime();
832 }
833
834 unsigned MediaPlayer::decodedFrameCount() const
835 {
836     return m_private->decodedFrameCount();
837 }
838
839 unsigned MediaPlayer::droppedFrameCount() const
840 {
841     return m_private->droppedFrameCount();
842 }
843
844 unsigned MediaPlayer::audioDecodedByteCount() const
845 {
846     return m_private->audioDecodedByteCount();
847 }
848
849 unsigned MediaPlayer::videoDecodedByteCount() const
850 {
851     return m_private->videoDecodedByteCount();
852 }
853
854 void MediaPlayer::reloadTimerFired(Timer<MediaPlayer>*)
855 {
856     m_private->cancelLoad();
857     loadWithNextMediaEngine(m_currentMediaEngine);
858 }
859
860 void MediaPlayer::getSitesInMediaCache(Vector<String>& sites)
861 {
862     Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
863     unsigned size = engines.size();
864     for (unsigned i = 0; i < size; i++) {
865         if (!engines[i]->getSitesInMediaCache)
866             continue;
867         Vector<String> engineSites;
868         engines[i]->getSitesInMediaCache(engineSites);
869         sites.append(engineSites);
870     }
871 }
872
873 void MediaPlayer::clearMediaCache()
874 {
875     Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
876     unsigned size = engines.size();
877     for (unsigned i = 0; i < size; i++) {
878         if (engines[i]->clearMediaCache)
879             engines[i]->clearMediaCache();
880     }
881 }
882
883 void MediaPlayer::clearMediaCacheForSite(const String& site)
884 {
885     Vector<MediaPlayerFactory*>& engines = installedMediaEngines();
886     unsigned size = engines.size();
887     for (unsigned i = 0; i < size; i++) {
888         if (engines[i]->clearMediaCacheForSite)
889             engines[i]->clearMediaCacheForSite(site);
890     }
891 }
892
893 void MediaPlayer::setPrivateBrowsingMode(bool privateBrowsingMode)
894 {
895     m_privateBrowsing = privateBrowsingMode;
896     m_private->setPrivateBrowsingMode(m_privateBrowsing);
897 }
898
899 #if ENABLE(MEDIA_SOURCE)
900 void MediaPlayer::sourceOpened()
901 {
902     if (m_mediaPlayerClient)
903         m_mediaPlayerClient->mediaPlayerSourceOpened();
904 }
905
906 String MediaPlayer::sourceURL() const
907 {
908     if (m_mediaPlayerClient)
909         return m_mediaPlayerClient->mediaPlayerSourceURL();
910     return String();
911 }
912 #endif
913
914 // Client callbacks.
915 void MediaPlayer::networkStateChanged()
916 {
917     // If more than one media engine is installed and this one failed before finding metadata,
918     // let the next engine try.
919     if (m_private->networkState() >= FormatError
920         && m_private->readyState() < HaveMetadata
921         && installedMediaEngines().size() > 1) {
922         if ( m_contentMIMEType.isEmpty() || bestMediaEngineForTypeAndCodecs(m_contentMIMEType, m_contentTypeCodecs, m_currentMediaEngine)) {
923             m_reloadTimer.startOneShot(0);
924             return;
925         }
926     }
927     if (m_mediaPlayerClient)
928         m_mediaPlayerClient->mediaPlayerNetworkStateChanged(this);
929 }
930
931 void MediaPlayer::readyStateChanged()
932 {
933     if (m_mediaPlayerClient)
934         m_mediaPlayerClient->mediaPlayerReadyStateChanged(this);
935 }
936
937 void MediaPlayer::volumeChanged(float newVolume)
938 {
939     m_volume = newVolume;
940     if (m_mediaPlayerClient)
941         m_mediaPlayerClient->mediaPlayerVolumeChanged(this);
942 }
943
944 void MediaPlayer::muteChanged(bool newMuted)
945 {
946     m_muted = newMuted;
947     if (m_mediaPlayerClient)
948         m_mediaPlayerClient->mediaPlayerMuteChanged(this);
949 }
950
951 void MediaPlayer::timeChanged()
952 {
953     if (m_mediaPlayerClient)
954         m_mediaPlayerClient->mediaPlayerTimeChanged(this);
955 }
956
957 void MediaPlayer::sizeChanged()
958 {
959     if (m_mediaPlayerClient)
960         m_mediaPlayerClient->mediaPlayerSizeChanged(this);
961 }
962
963 void MediaPlayer::repaint()
964 {
965     if (m_mediaPlayerClient)
966         m_mediaPlayerClient->mediaPlayerRepaint(this);
967 }
968
969 void MediaPlayer::durationChanged()
970 {
971     if (m_mediaPlayerClient)
972         m_mediaPlayerClient->mediaPlayerDurationChanged(this);
973 }
974
975 void MediaPlayer::rateChanged()
976 {
977     if (m_mediaPlayerClient)
978         m_mediaPlayerClient->mediaPlayerRateChanged(this);
979 }
980
981 void MediaPlayer::playbackStateChanged()
982 {
983     if (m_mediaPlayerClient)
984         m_mediaPlayerClient->mediaPlayerPlaybackStateChanged(this);
985 }
986
987 void MediaPlayer::firstVideoFrameAvailable()
988 {
989     if (m_mediaPlayerClient)
990         m_mediaPlayerClient->mediaPlayerFirstVideoFrameAvailable(this);
991 }
992
993 void MediaPlayer::characteristicChanged()
994 {
995     if (m_mediaPlayerClient)
996         m_mediaPlayerClient->mediaPlayerCharacteristicChanged(this);
997 }
998
999 #if ENABLE(WEB_AUDIO)
1000 AudioSourceProvider* MediaPlayer::audioSourceProvider()
1001 {
1002     return m_private->audioSourceProvider();
1003 }
1004 #endif // WEB_AUDIO
1005
1006 }
1007
1008 #endif