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