1 /* 2 * Copyright (C) 2009 Google 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 are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef WebMediaPlayerClientImpl_h 32 #define WebMediaPlayerClientImpl_h 33 34 #if ENABLE(VIDEO) 35 36 #include "MediaPlayerPrivate.h" 37 #include "VideoFrameChromium.h" 38 #include "VideoFrameProvider.h" 39 #include "VideoLayerChromium.h" 40 #include "WebMediaPlayerClient.h" 41 #include <wtf/OwnPtr.h> 42 43 namespace WebKit { 44 45 class WebMediaElement; 46 class WebMediaPlayer; 47 48 // This class serves as a bridge between WebCore::MediaPlayer and 49 // WebKit::WebMediaPlayer. 50 class WebMediaPlayerClientImpl : public WebCore::MediaPlayerPrivateInterface 51 #if USE(ACCELERATED_COMPOSITING) 52 , public WebCore::VideoFrameProvider 53 #endif 54 , public WebMediaPlayerClient { 55 56 public: 57 static bool isEnabled(); 58 static void setIsEnabled(bool); 59 static void registerSelf(WebCore::MediaEngineRegistrar); 60 61 static WebMediaPlayerClientImpl* fromMediaElement(const WebMediaElement* element); 62 63 // Returns the encapsulated WebKit::WebMediaPlayer. 64 WebMediaPlayer* mediaPlayer() const; 65 66 // WebMediaPlayerClient methods: 67 virtual ~WebMediaPlayerClientImpl(); 68 virtual void networkStateChanged(); 69 virtual void readyStateChanged(); 70 virtual void volumeChanged(float); 71 virtual void muteChanged(bool); 72 virtual void timeChanged(); 73 virtual void repaint(); 74 virtual void durationChanged(); 75 virtual void rateChanged(); 76 virtual void sizeChanged(); 77 virtual void sawUnsupportedTracks(); 78 virtual float volume() const; 79 virtual void playbackStateChanged(); 80 virtual WebMediaPlayer::Preload preload() const; 81 82 // MediaPlayerPrivateInterface methods: 83 virtual void load(const WTF::String& url); 84 virtual void cancelLoad(); 85 #if USE(ACCELERATED_COMPOSITING) 86 virtual WebCore::PlatformLayer* platformLayer() const; 87 #endif 88 virtual WebCore::PlatformMedia platformMedia() const; 89 virtual void play(); 90 virtual void pause(); 91 virtual void prepareToPlay(); 92 virtual bool supportsFullscreen() const; 93 virtual bool supportsSave() const; 94 virtual WebCore::IntSize naturalSize() const; 95 virtual bool hasVideo() const; 96 virtual bool hasAudio() const; 97 virtual void setVisible(bool); 98 virtual float duration() const; 99 virtual float currentTime() const; 100 virtual void seek(float time); 101 virtual bool seeking() const; 102 virtual void setEndTime(float time); 103 virtual void setRate(float); 104 virtual bool paused() const; 105 virtual void setVolume(float); 106 virtual WebCore::MediaPlayer::NetworkState networkState() const; 107 virtual WebCore::MediaPlayer::ReadyState readyState() const; 108 virtual float maxTimeSeekable() const; 109 virtual WTF::PassRefPtr<WebCore::TimeRanges> buffered() const; 110 virtual int dataRate() const; 111 virtual bool totalBytesKnown() const; 112 virtual unsigned totalBytes() const; 113 virtual unsigned bytesLoaded() const; 114 virtual void setSize(const WebCore::IntSize&); 115 virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect&); 116 virtual void paintCurrentFrameInContext(WebCore::GraphicsContext*, const WebCore::IntRect&); 117 virtual void setPreload(WebCore::MediaPlayer::Preload); 118 virtual bool hasSingleSecurityOrigin() const; 119 virtual WebCore::MediaPlayer::MovieLoadType movieLoadType() const; 120 virtual unsigned decodedFrameCount() const; 121 virtual unsigned droppedFrameCount() const; 122 virtual unsigned audioDecodedByteCount() const; 123 virtual unsigned videoDecodedByteCount() const; 124 #if USE(ACCELERATED_COMPOSITING) 125 virtual bool supportsAcceleratedRendering() const; 126 127 // VideoFrameProvider methods: 128 virtual WebCore::VideoFrameChromium* getCurrentFrame(); 129 virtual void putCurrentFrame(WebCore::VideoFrameChromium*); 130 #endif 131 132 private: 133 WebMediaPlayerClientImpl(); 134 void startDelayedLoad(); 135 void loadInternal(); 136 137 static WebCore::MediaPlayerPrivateInterface* create(WebCore::MediaPlayer*); 138 static void getSupportedTypes(WTF::HashSet<WTF::String>&); 139 static WebCore::MediaPlayer::SupportsType supportsType( 140 const WTF::String& type, const WTF::String& codecs); 141 #if USE(ACCELERATED_COMPOSITING) 142 bool acceleratedRenderingInUse(); 143 #endif 144 145 WebCore::MediaPlayer* m_mediaPlayer; 146 OwnPtr<WebMediaPlayer> m_webMediaPlayer; 147 String m_url; 148 bool m_delayingLoad; 149 WebCore::MediaPlayer::Preload m_preload; 150 #if USE(ACCELERATED_COMPOSITING) 151 RefPtr<WebCore::VideoLayerChromium> m_videoLayer; 152 bool m_supportsAcceleratedCompositing; 153 #endif 154 static bool m_isEnabled; 155 }; 156 157 } // namespace WebKit 158 159 #endif 160 161 #endif 162