Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 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 | |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 34 | #include "platform/audio/AudioSourceProvider.h" |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 35 | #include "platform/graphics/media/MediaPlayer.h" |
| 36 | #include "public/platform/WebAudioSourceProviderClient.h" |
| 37 | #include "public/platform/WebMediaPlayerClient.h" |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 38 | #include "third_party/khronos/GLES2/gl2.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 39 | #if OS(ANDROID) |
| 40 | #include "third_party/skia/include/core/SkBitmap.h" |
| 41 | #include "third_party/skia/include/core/SkRefCnt.h" |
| 42 | #include "third_party/skia/include/gpu/GrTexture.h" |
| 43 | #endif |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 44 | #include "platform/weborigin/KURL.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 45 | #include "wtf/OwnPtr.h" |
| 46 | #include "wtf/PassOwnPtr.h" |
Torne (Richard Coles) | c0e19a6 | 2013-08-30 15:15:11 +0100 | [diff] [blame] | 47 | #include "wtf/ThreadingPrimitives.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 48 | |
| 49 | namespace WebCore { |
| 50 | class AudioSourceProviderClient; |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 51 | class HTMLMediaElement; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 52 | } |
| 53 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 54 | namespace blink { |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 55 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 56 | class WebAudioSourceProvider; |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 57 | class WebContentDecryptionModule; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 58 | class WebMediaPlayer; |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 59 | class WebGraphicsContext3D; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 60 | |
| 61 | // This class serves as a bridge between WebCore::MediaPlayer and |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 62 | // blink::WebMediaPlayer. |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 63 | class WebMediaPlayerClientImpl FINAL : public WebCore::MediaPlayer, public WebMediaPlayerClient { |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 64 | |
| 65 | public: |
| 66 | static PassOwnPtr<WebCore::MediaPlayer> create(WebCore::MediaPlayerClient*); |
| 67 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 68 | virtual ~WebMediaPlayerClientImpl(); |
| 69 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 70 | // WebMediaPlayerClient methods: |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 71 | virtual void networkStateChanged() OVERRIDE; |
| 72 | virtual void readyStateChanged() OVERRIDE; |
| 73 | virtual void timeChanged() OVERRIDE; |
| 74 | virtual void repaint() OVERRIDE; |
| 75 | virtual void durationChanged() OVERRIDE; |
| 76 | virtual void sizeChanged() OVERRIDE; |
| 77 | virtual void setOpaque(bool) OVERRIDE; |
| 78 | virtual double volume() const OVERRIDE; |
| 79 | virtual void playbackStateChanged() OVERRIDE; |
| 80 | virtual WebMediaPlayer::Preload preload() const OVERRIDE; |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 81 | |
| 82 | // WebEncryptedMediaPlayerClient methods: |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 83 | virtual void keyAdded(const WebString& keySystem, const WebString& sessionId) OVERRIDE; |
| 84 | virtual void keyError(const WebString& keySystem, const WebString& sessionId, MediaKeyErrorCode, unsigned short systemCode) OVERRIDE; |
| 85 | virtual void keyMessage(const WebString& keySystem, const WebString& sessionId, const unsigned char* message, unsigned messageLength, const WebURL& defaultURL) OVERRIDE; |
| 86 | virtual void keyNeeded(const WebString& contentType, const unsigned char* initData, unsigned initDataLength) OVERRIDE; |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 87 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 88 | virtual void setWebLayer(WebLayer*) OVERRIDE; |
| 89 | virtual void addTextTrack(WebInbandTextTrack*) OVERRIDE; |
| 90 | virtual void removeTextTrack(WebInbandTextTrack*) OVERRIDE; |
| 91 | virtual void mediaSourceOpened(WebMediaSource*) OVERRIDE; |
| 92 | virtual void requestFullscreen() OVERRIDE; |
| 93 | virtual void requestSeek(double) OVERRIDE; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 94 | |
| 95 | // MediaPlayer methods: |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 96 | virtual WebMediaPlayer* webMediaPlayer() const OVERRIDE; |
Ben Murdoch | 07a852d | 2014-03-31 11:51:52 +0100 | [diff] [blame] | 97 | virtual void load(WebMediaPlayer::LoadType, const WTF::String& url, WebMediaPlayer::CORSMode) OVERRIDE; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 98 | virtual void play() OVERRIDE; |
| 99 | virtual void pause() OVERRIDE; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 100 | virtual bool supportsSave() const OVERRIDE; |
| 101 | virtual WebCore::IntSize naturalSize() const OVERRIDE; |
| 102 | virtual bool hasVideo() const OVERRIDE; |
| 103 | virtual bool hasAudio() const OVERRIDE; |
| 104 | virtual double duration() const OVERRIDE; |
| 105 | virtual double currentTime() const OVERRIDE; |
| 106 | virtual void seek(double time) OVERRIDE; |
| 107 | virtual bool seeking() const OVERRIDE; |
| 108 | virtual double rate() const OVERRIDE; |
| 109 | virtual void setRate(double) OVERRIDE; |
| 110 | virtual bool paused() const OVERRIDE; |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 111 | virtual void setPoster(const WebCore::KURL&) OVERRIDE; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 112 | virtual WebCore::MediaPlayer::NetworkState networkState() const OVERRIDE; |
| 113 | virtual WebCore::MediaPlayer::ReadyState readyState() const OVERRIDE; |
| 114 | virtual double maxTimeSeekable() const OVERRIDE; |
| 115 | virtual WTF::PassRefPtr<WebCore::TimeRanges> buffered() const OVERRIDE; |
| 116 | virtual bool didLoadingProgress() const OVERRIDE; |
| 117 | virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect&) OVERRIDE; |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 118 | virtual bool copyVideoTextureToPlatformTexture(WebGraphicsContext3D*, Platform3DObject texture, GLint level, GLenum type, GLenum internalFormat, bool premultiplyAlpha, bool flipY) OVERRIDE; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 119 | virtual void setPreload(WebCore::MediaPlayer::Preload) OVERRIDE; |
| 120 | virtual bool hasSingleSecurityOrigin() const OVERRIDE; |
| 121 | virtual bool didPassCORSAccessCheck() const OVERRIDE; |
| 122 | virtual double mediaTimeForTimeValue(double timeValue) const OVERRIDE; |
| 123 | virtual unsigned decodedFrameCount() const OVERRIDE; |
| 124 | virtual unsigned droppedFrameCount() const OVERRIDE; |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 125 | virtual unsigned corruptedFrameCount() const OVERRIDE; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 126 | virtual unsigned audioDecodedByteCount() const OVERRIDE; |
| 127 | virtual unsigned videoDecodedByteCount() const OVERRIDE; |
Torne (Richard Coles) | 06f816c | 2013-09-26 13:25:12 +0100 | [diff] [blame] | 128 | virtual void showFullscreenOverlay() OVERRIDE; |
| 129 | virtual void hideFullscreenOverlay() OVERRIDE; |
| 130 | virtual bool canShowFullscreenOverlay() const OVERRIDE; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 131 | |
| 132 | #if ENABLE(WEB_AUDIO) |
| 133 | virtual WebCore::AudioSourceProvider* audioSourceProvider() OVERRIDE; |
| 134 | #endif |
| 135 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 136 | private: |
| 137 | explicit WebMediaPlayerClientImpl(WebCore::MediaPlayerClient*); |
| 138 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 139 | WebCore::HTMLMediaElement& mediaElement() const; |
| 140 | |
Ben Murdoch | 07a852d | 2014-03-31 11:51:52 +0100 | [diff] [blame] | 141 | WebCore::MediaPlayerClient* m_client; |
| 142 | OwnPtr<WebMediaPlayer> m_webMediaPlayer; |
| 143 | WebCore::MediaPlayer::Preload m_preload; |
| 144 | double m_rate; |
| 145 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 146 | #if OS(ANDROID) |
| 147 | // FIXME: This path "only works" on Android. It is a workaround for the problem that Skia could not handle Android's GL_TEXTURE_EXTERNAL_OES |
| 148 | // texture internally. It should be removed and replaced by the normal paint path. |
| 149 | // https://code.google.com/p/skia/issues/detail?id=1189 |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 150 | void paintOnAndroid(WebCore::GraphicsContext*, const WebCore::IntRect&, uint8_t alpha); |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 151 | SkBitmap m_bitmap; |
Ben Murdoch | 07a852d | 2014-03-31 11:51:52 +0100 | [diff] [blame] | 152 | bool m_usePaintOnAndroid; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 153 | #endif |
| 154 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 155 | #if ENABLE(WEB_AUDIO) |
| 156 | // AudioClientImpl wraps an AudioSourceProviderClient. |
| 157 | // When the audio format is known, Chromium calls setFormat() which then dispatches into WebCore. |
| 158 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 159 | class AudioClientImpl FINAL : public blink::WebAudioSourceProviderClient { |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 160 | public: |
| 161 | AudioClientImpl(WebCore::AudioSourceProviderClient* client) |
| 162 | : m_client(client) |
| 163 | { |
| 164 | } |
| 165 | |
| 166 | virtual ~AudioClientImpl() { } |
| 167 | |
| 168 | // WebAudioSourceProviderClient |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 169 | virtual void setFormat(size_t numberOfChannels, float sampleRate) OVERRIDE; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 170 | |
| 171 | private: |
| 172 | WebCore::AudioSourceProviderClient* m_client; |
| 173 | }; |
| 174 | |
| 175 | // AudioSourceProviderImpl wraps a WebAudioSourceProvider. |
| 176 | // provideInput() calls into Chromium to get a rendered audio stream. |
| 177 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 178 | class AudioSourceProviderImpl FINAL : public WebCore::AudioSourceProvider { |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 179 | public: |
| 180 | AudioSourceProviderImpl() |
| 181 | : m_webAudioSourceProvider(0) |
| 182 | { |
| 183 | } |
| 184 | |
| 185 | virtual ~AudioSourceProviderImpl() { } |
| 186 | |
| 187 | // Wraps the given WebAudioSourceProvider. |
| 188 | void wrap(WebAudioSourceProvider*); |
| 189 | |
| 190 | // WebCore::AudioSourceProvider |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 191 | virtual void setClient(WebCore::AudioSourceProviderClient*) OVERRIDE; |
| 192 | virtual void provideInput(WebCore::AudioBus*, size_t framesToProcess) OVERRIDE; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 193 | |
| 194 | private: |
| 195 | WebAudioSourceProvider* m_webAudioSourceProvider; |
| 196 | OwnPtr<AudioClientImpl> m_client; |
| 197 | Mutex provideInputLock; |
| 198 | }; |
| 199 | |
| 200 | AudioSourceProviderImpl m_audioSourceProvider; |
| 201 | #endif |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 202 | }; |
| 203 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 204 | } // namespace blink |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 205 | |
| 206 | #endif |