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/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayer.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayer.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" |
18 | 18 |
19 namespace WebKit { | 19 namespace WebKit { |
20 class WebCookieJar; | 20 class WebCookieJar; |
21 } | 21 } |
22 | 22 |
23 namespace media { | 23 namespace media { |
24 class MediaPlayerBridge; | 24 class MediaPlayerBridge; |
25 } | 25 } |
26 | 26 |
27 namespace webkit_media { | 27 namespace webkit_media { |
28 | 28 |
| 29 class StreamTextureFactory; |
| 30 class StreamTextureProxy; |
| 31 class WebMediaPlayerManagerAndroid; |
29 class WebMediaPlayerProxyAndroid; | 32 class WebMediaPlayerProxyAndroid; |
30 | 33 |
31 // This class serves as the android implementation of WebKit::WebMediaPlayer. | 34 // This class serves as the android implementation of WebKit::WebMediaPlayer. |
32 // It implements all the playback functions by forwarding calls to android | 35 // It implements all the playback functions by forwarding calls to android |
33 // media player, and reports player state changes to the webkit. | 36 // media player, and reports player state changes to the webkit. |
34 class WebMediaPlayerAndroid : | 37 class WebMediaPlayerAndroid : |
35 public WebKit::WebMediaPlayer, | 38 public WebKit::WebMediaPlayer, |
36 public base::SupportsWeakPtr<WebMediaPlayerAndroid> { | 39 public base::SupportsWeakPtr<WebMediaPlayerAndroid> { |
37 public: | 40 public: |
38 WebMediaPlayerAndroid(WebKit::WebMediaPlayerClient* client, | 41 WebMediaPlayerAndroid(WebKit::WebMediaPlayerClient* client, |
39 WebKit::WebCookieJar* cookie_jar); | 42 WebKit::WebCookieJar* cookie_jar, |
| 43 webkit_media::WebMediaPlayerManagerAndroid* manager, |
| 44 webkit_media::StreamTextureFactory* factory); |
40 virtual ~WebMediaPlayerAndroid() OVERRIDE; | 45 virtual ~WebMediaPlayerAndroid() OVERRIDE; |
41 | 46 |
42 // Set |incognito_mode_| to true if in incognito mode. | 47 // Set |incognito_mode_| to true if in incognito mode. |
43 static void InitIncognito(bool incognito_mode); | 48 static void InitIncognito(bool incognito_mode); |
44 | 49 |
45 // Resource loading. | 50 // Resource loading. |
46 virtual void load(const WebKit::WebURL& url) OVERRIDE; | 51 virtual void load(const WebKit::WebURL& url) OVERRIDE; |
47 virtual void cancelLoad() OVERRIDE; | 52 virtual void cancelLoad() OVERRIDE; |
48 | 53 |
49 // Playback controls. | 54 // Playback controls. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // Provide statistics. | 102 // Provide statistics. |
98 virtual unsigned decodedFrameCount() const OVERRIDE; | 103 virtual unsigned decodedFrameCount() const OVERRIDE; |
99 virtual unsigned droppedFrameCount() const OVERRIDE; | 104 virtual unsigned droppedFrameCount() const OVERRIDE; |
100 virtual unsigned audioDecodedByteCount() const OVERRIDE; | 105 virtual unsigned audioDecodedByteCount() const OVERRIDE; |
101 virtual unsigned videoDecodedByteCount() const OVERRIDE; | 106 virtual unsigned videoDecodedByteCount() const OVERRIDE; |
102 | 107 |
103 // Methods called from VideoLayerChromium. These methods are running on the | 108 // Methods called from VideoLayerChromium. These methods are running on the |
104 // compositor thread. | 109 // compositor thread. |
105 virtual WebKit::WebVideoFrame* getCurrentFrame() OVERRIDE; | 110 virtual WebKit::WebVideoFrame* getCurrentFrame() OVERRIDE; |
106 virtual void putCurrentFrame(WebKit::WebVideoFrame*) OVERRIDE; | 111 virtual void putCurrentFrame(WebKit::WebVideoFrame*) OVERRIDE; |
| 112 virtual void setStreamTextureClient( |
| 113 WebKit::WebStreamTextureClient* client) OVERRIDE; |
107 | 114 |
108 // Media player callback handlers. | 115 // Media player callback handlers. |
109 void OnMediaPrepared(); | 116 void OnMediaPrepared(); |
110 void OnPlaybackComplete(); | 117 void OnPlaybackComplete(); |
111 void OnBufferingUpdate(int percentage); | 118 void OnBufferingUpdate(int percentage); |
112 void OnSeekComplete(); | 119 void OnSeekComplete(); |
113 void OnMediaError(int error_type); | 120 void OnMediaError(int error_type); |
114 void OnMediaInfo(int info_type); | 121 void OnMediaInfo(int info_type); |
115 void OnVideoSizeChanged(int width, int height); | 122 void OnVideoSizeChanged(int width, int height); |
116 | 123 |
117 // Method to set the video surface for android media player. | 124 // This function is called by WebMediaPlayerManagerAndroid to pause the video |
118 void SetVideoSurface(jobject j_surface); | 125 // and release |media_player_| and its surface texture when we switch tabs. |
| 126 // However, the actual GlTexture is not released to keep the video screenshot. |
| 127 void ReleaseMediaResources(); |
119 | 128 |
120 private: | 129 private: |
121 // Create a media player to load the |url_| and prepare for playback. | 130 // Create a media player to load the |url_| and prepare for playback. |
122 // Because of limited decoding resources on mobile devices, idle media players | 131 // Because of limited decoding resources on mobile devices, idle media players |
123 // could get released. In that case, we call this function to get a new media | 132 // could get released. In that case, we call this function to get a new media |
124 // player when needed. | 133 // player when needed. |
125 void InitializeMediaPlayer(); | 134 void InitializeMediaPlayer(); |
126 | 135 |
127 // Functions that implements media player control. | 136 // Functions that implements media player control. |
128 void PlayInternal(); | 137 void PlayInternal(); |
129 void PauseInternal(); | 138 void PauseInternal(); |
130 void SeekInternal(float seconds); | 139 void SeekInternal(float seconds); |
131 | 140 |
132 // Helper methods for posting task for setting states and update WebKit. | 141 // Helper methods for posting task for setting states and update WebKit. |
133 void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state); | 142 void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state); |
134 void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state); | 143 void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state); |
135 | 144 |
| 145 // Methods for creation and deletion of stream texture. |
| 146 void CreateStreamTexture(); |
| 147 void DestroyStreamTexture(); |
| 148 |
136 // whether the current process is incognito mode | 149 // whether the current process is incognito mode |
137 static bool incognito_mode_; | 150 static bool incognito_mode_; |
138 | 151 |
139 WebKit::WebMediaPlayerClient* const client_; | 152 WebKit::WebMediaPlayerClient* const client_; |
140 | 153 |
141 // Save the list of buffered time ranges. | 154 // Save the list of buffered time ranges. |
142 WebKit::WebTimeRanges buffered_; | 155 WebKit::WebTimeRanges buffered_; |
143 | 156 |
144 // Bridge to the android media player. | 157 // Bridge to the android media player. |
145 scoped_ptr<media::MediaPlayerBridge> media_player_; | 158 scoped_ptr<media::MediaPlayerBridge> media_player_; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 190 |
178 // Whether playback has completed. | 191 // Whether playback has completed. |
179 float playback_completed_; | 192 float playback_completed_; |
180 | 193 |
181 // Fake it by self increasing on every OnBufferingUpdate event. | 194 // Fake it by self increasing on every OnBufferingUpdate event. |
182 int64 buffered_bytes_; | 195 int64 buffered_bytes_; |
183 | 196 |
184 // Pointer to the cookie jar to get the cookie for the media url. | 197 // Pointer to the cookie jar to get the cookie for the media url. |
185 WebKit::WebCookieJar* cookie_jar_; | 198 WebKit::WebCookieJar* cookie_jar_; |
186 | 199 |
| 200 // Manager for managing this media player. |
| 201 webkit_media::WebMediaPlayerManagerAndroid* manager_; |
| 202 |
| 203 // Player ID assigned by the media player manager. |
| 204 int player_id_; |
| 205 |
187 // Whether the user has clicked the play button while media player | 206 // Whether the user has clicked the play button while media player |
188 // is preparing. | 207 // is preparing. |
189 bool pending_play_event_; | 208 bool pending_play_event_; |
190 | 209 |
191 // Current player states. | 210 // Current player states. |
192 WebKit::WebMediaPlayer::NetworkState network_state_; | 211 WebKit::WebMediaPlayer::NetworkState network_state_; |
193 WebKit::WebMediaPlayer::ReadyState ready_state_; | 212 WebKit::WebMediaPlayer::ReadyState ready_state_; |
194 | 213 |
| 214 // GL texture ID allocated to the video. |
| 215 unsigned int texture_id_; |
| 216 |
| 217 // Stream texture ID allocated to the video. |
| 218 unsigned int stream_id_; |
| 219 |
| 220 // Whether |media_player_| needs to re-establish the surface texture peer. |
| 221 bool needs_establish_peer_; |
| 222 |
| 223 // Object for allocating stream textures. |
| 224 scoped_ptr<webkit_media::StreamTextureFactory> stream_texture_factory_; |
| 225 |
| 226 // Object for calling back the compositor thread to repaint the video when a |
| 227 // frame available. It should be initialized on the compositor thread. |
| 228 scoped_ptr<webkit_media::StreamTextureProxy> stream_texture_proxy_; |
| 229 |
195 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); | 230 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); |
196 }; | 231 }; |
197 | 232 |
198 } // namespace webkit_media | 233 } // namespace webkit_media |
199 | 234 |
200 #endif // WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | 235 #endif // WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ |
OLD | NEW |