OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | 5 #ifndef WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ |
6 #define WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | 6 #define WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #if defined(GOOGLE_TV) | |
16 #include "media/base/demuxer_stream.h" | |
17 #endif | |
18 #include "cc/layers/video_frame_provider.h" | 15 #include "cc/layers/video_frame_provider.h" |
| 16 #include "media/base/android/media_player_bridge.h" |
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
20 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
21 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" | 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayer.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayer.h" |
23 #include "ui/gfx/rect_f.h" | 21 #include "ui/gfx/rect_f.h" |
24 #include "webkit/media/android/stream_texture_factory_android.h" | 22 #include "webkit/media/android/stream_texture_factory_android.h" |
25 | 23 |
26 namespace media { | 24 namespace media { |
27 class MediaLog; | 25 class MediaLog; |
28 } | 26 } |
29 | 27 |
30 namespace WebKit { | 28 namespace WebKit { |
31 class WebFrame; | 29 class WebFrame; |
32 } | 30 } |
33 | 31 |
34 namespace webkit { | 32 namespace webkit { |
35 class WebLayerImpl; | 33 class WebLayerImpl; |
36 } | 34 } |
37 | 35 |
38 namespace webkit_media { | 36 namespace webkit_media { |
39 | 37 |
40 #if defined(GOOGLE_TV) | |
41 class MediaSourceDelegate; | |
42 #endif | |
43 class WebMediaPlayerManagerAndroid; | 38 class WebMediaPlayerManagerAndroid; |
44 class WebMediaPlayerProxyAndroid; | 39 class WebMediaPlayerProxyAndroid; |
45 | 40 |
46 // This class implements WebKit::WebMediaPlayer by keeping the android | 41 // This class implements WebKit::WebMediaPlayer by keeping the android |
47 // media player in the browser process. It listens to all the status changes | 42 // media player in the browser process. It listens to all the status changes |
48 // sent from the browser process and sends playback controls to the media | 43 // sent from the browser process and sends playback controls to the media |
49 // player. | 44 // player. |
50 class WebMediaPlayerAndroid | 45 class WebMediaPlayerAndroid |
51 : public WebKit::WebMediaPlayer, | 46 : public WebKit::WebMediaPlayer, |
52 public cc::VideoFrameProvider, | 47 public cc::VideoFrameProvider, |
53 public base::MessageLoop::DestructionObserver { | 48 public base::MessageLoop::DestructionObserver { |
54 public: | 49 public: |
55 // Construct a WebMediaPlayerAndroid object. This class communicates | 50 // Construct a WebMediaPlayerAndroid object. This class communicates |
56 // with the MediaPlayerBridge object in the browser process through | 51 // with the MediaPlayerBridge object in the browser process through |
57 // |proxy|. | 52 // |proxy|. |
58 // TODO(qinmin): |frame| argument is used to determine whether the current | 53 // TODO(qinmin): |frame| argument is used to determine whether the current |
59 // player can enter fullscreen. This logic should probably be moved into | 54 // player can enter fullscreen. This logic should probably be moved into |
60 // blink, so that enterFullscreen() will not be called if another video is | 55 // blink, so that enterFullscreen() will not be called if another video is |
61 // already in fullscreen. | 56 // already in fullscreen. |
62 WebMediaPlayerAndroid(WebKit::WebFrame* frame, | 57 WebMediaPlayerAndroid(WebKit::WebFrame* frame, |
63 WebKit::WebMediaPlayerClient* client, | 58 WebKit::WebMediaPlayerClient* client, |
64 WebMediaPlayerManagerAndroid* manager, | 59 WebMediaPlayerManagerAndroid* manager, |
65 WebMediaPlayerProxyAndroid* proxy, | 60 WebMediaPlayerProxyAndroid* proxy, |
66 StreamTextureFactory* factory, | 61 StreamTextureFactory* factory); |
67 media::MediaLog* media_log); | |
68 virtual ~WebMediaPlayerAndroid(); | 62 virtual ~WebMediaPlayerAndroid(); |
69 | 63 |
70 // WebKit::WebMediaPlayer implementation. | 64 // WebKit::WebMediaPlayer implementation. |
71 virtual void enterFullscreen(); | 65 virtual void enterFullscreen(); |
72 virtual void exitFullscreen(); | 66 virtual void exitFullscreen(); |
73 virtual bool canEnterFullscreen() const; | 67 virtual bool canEnterFullscreen() const; |
74 | 68 |
75 // Resource loading. | 69 // Resource loading. |
76 virtual void load(const WebKit::WebURL& url, CORSMode cors_mode); | 70 virtual void load(const WebKit::WebURL& url, CORSMode cors_mode); |
77 virtual void load(const WebKit::WebURL& url, | 71 virtual void load(const WebKit::WebURL& url, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | 173 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
180 | 174 |
181 // Detach the player from its manager. | 175 // Detach the player from its manager. |
182 void Detach(); | 176 void Detach(); |
183 | 177 |
184 #if defined(GOOGLE_TV) | 178 #if defined(GOOGLE_TV) |
185 // Retrieve geometry of the media player (i.e. location and size of the video | 179 // Retrieve geometry of the media player (i.e. location and size of the video |
186 // frame) if changed. Returns true only if the geometry has been changed since | 180 // frame) if changed. Returns true only if the geometry has been changed since |
187 // the last call. | 181 // the last call. |
188 bool RetrieveGeometryChange(gfx::RectF* rect); | 182 bool RetrieveGeometryChange(gfx::RectF* rect); |
189 | |
190 virtual MediaKeyException generateKeyRequest( | |
191 const WebKit::WebString& key_system, | |
192 const unsigned char* init_data, | |
193 unsigned init_data_length) OVERRIDE; | |
194 virtual MediaKeyException addKey( | |
195 const WebKit::WebString& key_system, | |
196 const unsigned char* key, | |
197 unsigned key_length, | |
198 const unsigned char* init_data, | |
199 unsigned init_data_length, | |
200 const WebKit::WebString& session_id) OVERRIDE; | |
201 virtual MediaKeyException cancelKeyRequest( | |
202 const WebKit::WebString& key_system, | |
203 const WebKit::WebString& session_id) OVERRIDE; | |
204 | |
205 // Called when DemuxerStreamPlayer needs to read data from ChunkDemuxer. | |
206 void OnReadFromDemuxer(media::DemuxerStream::Type type, bool seek_done); | |
207 #endif | 183 #endif |
208 | 184 |
209 protected: | 185 protected: |
210 // Helper method to update the playing state. | 186 // Helper method to update the playing state. |
211 void UpdatePlayingState(bool is_playing_); | 187 void UpdatePlayingState(bool is_playing_); |
212 | 188 |
213 // Helper methods for posting task for setting states and update WebKit. | 189 // Helper methods for posting task for setting states and update WebKit. |
214 void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state); | 190 void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state); |
215 void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state); | 191 void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state); |
216 | 192 |
217 // Helper method to reestablish the surface texture peer for android | 193 // Helper method to reestablish the surface texture peer for android |
218 // media player. | 194 // media player. |
219 void EstablishSurfaceTexturePeer(); | 195 void EstablishSurfaceTexturePeer(); |
220 | 196 |
221 // Requesting whether the surface texture peer needs to be reestablished. | 197 // Requesting whether the surface texture peer needs to be reestablished. |
222 void SetNeedsEstablishPeer(bool needs_establish_peer); | 198 void SetNeedsEstablishPeer(bool needs_establish_peer); |
223 | 199 |
224 #if defined(GOOGLE_TV) | 200 void InitializeMediaPlayer(const WebKit::WebURL& url, |
225 // Request external surface for out-of-band composition. | 201 media::MediaPlayerBridge::MediaType media_type); |
226 void RequestExternalSurface(); | 202 |
227 #endif | 203 bool NeedsExternalSurface(); |
| 204 void SetNeedsExternalSurface(bool needs_external_surface); |
| 205 |
| 206 WebMediaPlayerProxyAndroid* proxy() { return proxy_; } |
| 207 WebKit::WebFrame* frame() { return frame_; } |
| 208 WebKit::WebMediaPlayerClient* client() { return client_; } |
| 209 int player_id() { return player_id_; } |
228 | 210 |
229 private: | 211 private: |
230 void ReallocateVideoFrame(); | 212 void ReallocateVideoFrame(); |
231 | 213 |
232 WebKit::WebFrame* const frame_; | 214 WebKit::WebFrame* const frame_; |
233 | 215 |
234 WebKit::WebMediaPlayerClient* const client_; | 216 WebKit::WebMediaPlayerClient* const client_; |
235 | 217 |
236 // Save the list of buffered time ranges. | 218 // Save the list of buffered time ranges. |
237 WebKit::WebTimeRanges buffered_; | 219 WebKit::WebTimeRanges buffered_; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 // A pointer back to the compositor to inform it about state changes. This is | 280 // A pointer back to the compositor to inform it about state changes. This is |
299 // not NULL while the compositor is actively using this webmediaplayer. | 281 // not NULL while the compositor is actively using this webmediaplayer. |
300 cc::VideoFrameProvider::Client* video_frame_provider_client_; | 282 cc::VideoFrameProvider::Client* video_frame_provider_client_; |
301 | 283 |
302 scoped_ptr<webkit::WebLayerImpl> video_weblayer_; | 284 scoped_ptr<webkit::WebLayerImpl> video_weblayer_; |
303 | 285 |
304 #if defined(GOOGLE_TV) | 286 #if defined(GOOGLE_TV) |
305 // A rectangle represents the geometry of video frame, when computed last | 287 // A rectangle represents the geometry of video frame, when computed last |
306 // time. | 288 // time. |
307 gfx::RectF last_computed_rect_; | 289 gfx::RectF last_computed_rect_; |
308 | |
309 scoped_ptr<MediaSourceDelegate> media_source_delegate_; | |
310 #endif | 290 #endif |
311 | 291 |
312 // Proxy object that delegates method calls on Render Thread. | 292 // Proxy object that delegates method calls on Render Thread. |
313 // This object is created on the Render Thread and is only called in the | 293 // This object is created on the Render Thread and is only called in the |
314 // destructor. | 294 // destructor. |
315 WebMediaPlayerProxyAndroid* proxy_; | 295 WebMediaPlayerProxyAndroid* proxy_; |
316 | 296 |
317 // The current playing time. Because the media player is in the browser | 297 // The current playing time. Because the media player is in the browser |
318 // process, it will regularly update the |current_time_| by calling | 298 // process, it will regularly update the |current_time_| by calling |
319 // OnTimeUpdate(). | 299 // OnTimeUpdate(). |
320 float current_time_; | 300 float current_time_; |
321 | 301 |
322 media::MediaLog* media_log_; | 302 media::MediaLog* media_log_; |
323 | 303 |
324 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); | 304 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); |
325 }; | 305 }; |
326 | 306 |
327 } // namespace webkit_media | 307 } // namespace webkit_media |
328 | 308 |
329 #endif // WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | 309 #endif // WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ |
OLD | NEW |