Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / web / WebMediaPlayerClientImpl.h
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 #include "platform/audio/AudioSourceProvider.h"
35 #include "platform/graphics/media/MediaPlayer.h"
36 #include "public/platform/WebAudioSourceProviderClient.h"
37 #include "public/platform/WebMediaPlayerClient.h"
38 #include "third_party/khronos/GLES2/gl2.h"
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
44 #include "platform/weborigin/KURL.h"
45 #include "wtf/OwnPtr.h"
46 #include "wtf/PassOwnPtr.h"
47 #include "wtf/ThreadingPrimitives.h"
48
49 namespace WebCore {
50 class AudioSourceProviderClient;
51 class HTMLMediaElement;
52 }
53
54 namespace blink {
55
56 class WebAudioSourceProvider;
57 class WebContentDecryptionModule;
58 class WebMediaPlayer;
59 class WebGraphicsContext3D;
60
61 // This class serves as a bridge between WebCore::MediaPlayer and
62 // blink::WebMediaPlayer.
63 class WebMediaPlayerClientImpl FINAL : public WebCore::MediaPlayer, public WebMediaPlayerClient {
64
65 public:
66     static PassOwnPtr<WebCore::MediaPlayer> create(WebCore::MediaPlayerClient*);
67
68     virtual ~WebMediaPlayerClientImpl();
69
70     // WebMediaPlayerClient methods:
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;
81
82     // WebEncryptedMediaPlayerClient methods:
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;
87
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;
94
95     // MediaPlayer methods:
96     virtual WebMediaPlayer* webMediaPlayer() const OVERRIDE;
97     virtual void load(WebMediaPlayer::LoadType, const WTF::String& url, WebMediaPlayer::CORSMode) OVERRIDE;
98     virtual void play() OVERRIDE;
99     virtual void pause() OVERRIDE;
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;
111     virtual void setPoster(const WebCore::KURL&) OVERRIDE;
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;
118     virtual bool copyVideoTextureToPlatformTexture(WebGraphicsContext3D*, Platform3DObject texture, GLint level, GLenum type, GLenum internalFormat, bool premultiplyAlpha, bool flipY) OVERRIDE;
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;
125     virtual unsigned corruptedFrameCount() const OVERRIDE;
126     virtual unsigned audioDecodedByteCount() const OVERRIDE;
127     virtual unsigned videoDecodedByteCount() const OVERRIDE;
128     virtual void showFullscreenOverlay() OVERRIDE;
129     virtual void hideFullscreenOverlay() OVERRIDE;
130     virtual bool canShowFullscreenOverlay() const OVERRIDE;
131
132 #if ENABLE(WEB_AUDIO)
133     virtual WebCore::AudioSourceProvider* audioSourceProvider() OVERRIDE;
134 #endif
135
136 private:
137     explicit WebMediaPlayerClientImpl(WebCore::MediaPlayerClient*);
138
139     WebCore::HTMLMediaElement& mediaElement() const;
140
141     WebCore::MediaPlayerClient* m_client;
142     OwnPtr<WebMediaPlayer> m_webMediaPlayer;
143     WebCore::MediaPlayer::Preload m_preload;
144     double m_rate;
145
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
150     void paintOnAndroid(WebCore::GraphicsContext*, const WebCore::IntRect&, uint8_t alpha);
151     SkBitmap m_bitmap;
152     bool m_usePaintOnAndroid;
153 #endif
154
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
159     class AudioClientImpl FINAL : public blink::WebAudioSourceProviderClient {
160     public:
161         AudioClientImpl(WebCore::AudioSourceProviderClient* client)
162             : m_client(client)
163         {
164         }
165
166         virtual ~AudioClientImpl() { }
167
168         // WebAudioSourceProviderClient
169         virtual void setFormat(size_t numberOfChannels, float sampleRate) OVERRIDE;
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
178     class AudioSourceProviderImpl FINAL : public WebCore::AudioSourceProvider {
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
191         virtual void setClient(WebCore::AudioSourceProviderClient*) OVERRIDE;
192         virtual void provideInput(WebCore::AudioBus*, size_t framesToProcess) OVERRIDE;
193
194     private:
195         WebAudioSourceProvider* m_webAudioSourceProvider;
196         OwnPtr<AudioClientImpl> m_client;
197         Mutex provideInputLock;
198     };
199
200     AudioSourceProviderImpl m_audioSourceProvider;
201 #endif
202 };
203
204 } // namespace blink
205
206 #endif