Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: webkit/media/android/webmediaplayer_android.h

Issue 10919075: Move android mediaplayer from render process to browser process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressing comments Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.h" 11 #include "base/message_loop.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/time.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/WebVideoFrame.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h"
18
19 namespace WebKit {
20 class WebCookieJar;
21 class WebFrame;
22 }
23
24 namespace media {
25 class MediaPlayerBridge;
26 }
27 18
28 namespace webkit_media { 19 namespace webkit_media {
29 20
30 class StreamTextureFactory; 21 class StreamTextureFactory;
31 class StreamTextureProxy; 22 class StreamTextureProxy;
32 class WebMediaPlayerManagerAndroid; 23 class WebMediaPlayerManagerAndroid;
33 class WebMediaPlayerProxyAndroid;
34 24
35 // This class serves as the android implementation of WebKit::WebMediaPlayer. 25 // An abstract class that serves as the common base class for implementing
36 // It implements all the playback functions by forwarding calls to android 26 // WebKit::WebMediaPlayer on Android.
37 // media player, and reports player state changes to the webkit. 27 class WebMediaPlayerAndroid : public WebKit::WebMediaPlayer,
38 class WebMediaPlayerAndroid : 28 public MessageLoop::DestructionObserver {
39 public WebKit::WebMediaPlayer,
40 public MessageLoop::DestructionObserver,
41 public base::SupportsWeakPtr<WebMediaPlayerAndroid> {
42 public: 29 public:
43 WebMediaPlayerAndroid(WebKit::WebFrame* frame,
44 WebKit::WebMediaPlayerClient* client,
45 WebKit::WebCookieJar* cookie_jar,
46 webkit_media::WebMediaPlayerManagerAndroid* manager,
47 webkit_media::StreamTextureFactory* factory);
48 virtual ~WebMediaPlayerAndroid();
49
50 // Set |incognito_mode_| to true if in incognito mode.
51 static void InitIncognito(bool incognito_mode);
52
53 // Resource loading. 30 // Resource loading.
54 virtual void load(const WebKit::WebURL& url, CORSMode cors_mode); 31 virtual void load(const WebKit::WebURL& url, CORSMode cors_mode);
55 virtual void cancelLoad(); 32 virtual void cancelLoad();
56 33
57 // Playback controls. 34 // Playback controls.
58 virtual void play(); 35 virtual void play();
59 virtual void pause(); 36 virtual void pause();
60 virtual void seek(float seconds); 37 virtual void seek(float seconds);
61 virtual bool supportsFullscreen() const; 38 virtual bool supportsFullscreen() const;
62 virtual bool supportsSave() const; 39 virtual bool supportsSave() const;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // Provide statistics. 83 // Provide statistics.
107 virtual unsigned decodedFrameCount() const; 84 virtual unsigned decodedFrameCount() const;
108 virtual unsigned droppedFrameCount() const; 85 virtual unsigned droppedFrameCount() const;
109 virtual unsigned audioDecodedByteCount() const; 86 virtual unsigned audioDecodedByteCount() const;
110 virtual unsigned videoDecodedByteCount() const; 87 virtual unsigned videoDecodedByteCount() const;
111 88
112 // Methods called from VideoLayerChromium. These methods are running on the 89 // Methods called from VideoLayerChromium. These methods are running on the
113 // compositor thread. 90 // compositor thread.
114 virtual WebKit::WebVideoFrame* getCurrentFrame(); 91 virtual WebKit::WebVideoFrame* getCurrentFrame();
115 virtual void putCurrentFrame(WebKit::WebVideoFrame*); 92 virtual void putCurrentFrame(WebKit::WebVideoFrame*);
116 virtual void setStreamTextureClient( 93
117 WebKit::WebStreamTextureClient* client); 94 // This gets called both on compositor and main thread to set the callback
95 // target when a frame is produced.
96 virtual void setStreamTextureClient(WebKit::WebStreamTextureClient* client);
118 97
119 // Media player callback handlers. 98 // Media player callback handlers.
120 void OnMediaPrepared(); 99 virtual void OnMediaPrepared(base::TimeDelta duration);
121 void OnPlaybackComplete(); 100 virtual void OnPlaybackComplete();
122 void OnBufferingUpdate(int percentage); 101 virtual void OnBufferingUpdate(int percentage);
123 void OnSeekComplete(); 102 virtual void OnSeekComplete(base::TimeDelta current_time);
124 void OnMediaError(int error_type); 103 virtual void OnMediaError(int error_type);
125 void OnMediaInfo(int info_type); 104 virtual void OnVideoSizeChanged(int width, int height);
126 void OnVideoSizeChanged(int width, int height);
127 105
128 // This function is called by WebMediaPlayerManagerAndroid to pause the video 106 // Called to update the current time.
129 // and release |media_player_| and its surface texture when we switch tabs. 107 virtual void OnTimeUpdate(base::TimeDelta current_time) {};
108
109 // This function is called by the WebMediaPlayerManagerAndroid to pause the
110 // video and release the media player and surface texture when we switch tabs.
130 // However, the actual GlTexture is not released to keep the video screenshot. 111 // However, the actual GlTexture is not released to keep the video screenshot.
131 void ReleaseMediaResources(); 112 virtual void ReleaseMediaResources();
132 113
133 // Whether |media_player_| has been initialized. 114 // Method to set the surface for video.
134 bool IsInitialized() const; 115 virtual void SetVideoSurface(jobject j_surface) {}
135 116
136 // Method inherited from DestructionObserver. 117 // Method inherited from DestructionObserver.
137 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; 118 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
138 119
139 private: 120 protected:
140 // Create a media player to load the |url_| and prepare for playback. 121 WebMediaPlayerAndroid(WebKit::WebMediaPlayerClient* client,
141 // Because of limited decoding resources on mobile devices, idle media players 122 WebMediaPlayerManagerAndroid* manager,
142 // could get released. In that case, we call this function to get a new media 123 StreamTextureFactory* factory);
143 // player when needed. 124 virtual ~WebMediaPlayerAndroid();
144 void InitializeMediaPlayer();
145 125
146 // Functions that implements media player control. 126 // Helper method to update the playing state.
147 void PlayInternal(); 127 virtual void UpdatePlayingState(bool is_playing_);
148 void PauseInternal();
149 void SeekInternal(float seconds);
150 128
151 // Helper methods for posting task for setting states and update WebKit. 129 // Helper methods for posting task for setting states and update WebKit.
152 void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state); 130 virtual void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state);
153 void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state); 131 virtual void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state);
154 132
155 // whether the current process is incognito mode 133 // Helper method to reestablish the surface texture peer for android
156 static bool incognito_mode_; 134 // mediaplayer.
135 virtual void EstablishSurfaceTexturePeer();
157 136
158 WebKit::WebFrame* frame_; 137 // Method to be implemented by child classes.
138 // Initialize the media player bridge object.
139 virtual void InitializeMediaPlayer(GURL url) = 0;
159 140
141 // Inform the media player to start playing.
142 virtual void PlayInternal() = 0;
143
144 // Inform the media player to pause.
145 virtual void PauseInternal() = 0;
146
147 // Inform the media player to seek to a particular position.
148 virtual void SeekInternal(base::TimeDelta time) = 0;
149
150 // Get the current time from the media player.
151 virtual float GetCurrentTimeInternal() const = 0;
152
153 // Release the Android Media player.
154 virtual void ReleaseResourcesInternal() = 0;
155
156 // Cleaning up all remaining resources as this object is about to get deleted.
157 virtual void Destroy() {};
158
159 virtual WebKit::WebMediaPlayerClient* client() { return client_; }
160
161 int player_id() { return player_id_; }
162
163 private:
160 WebKit::WebMediaPlayerClient* const client_; 164 WebKit::WebMediaPlayerClient* const client_;
161 165
162 // Save the list of buffered time ranges. 166 // Save the list of buffered time ranges.
163 WebKit::WebTimeRanges buffered_; 167 WebKit::WebTimeRanges buffered_;
164 168
165 // Bridge to the android media player.
166 scoped_ptr<media::MediaPlayerBridge> media_player_;
167
168 // Size of the media element.
169 WebKit::WebSize texture_size_;
170
171 // Size of the video. 169 // Size of the video.
172 WebKit::WebSize natural_size_; 170 WebKit::WebSize natural_size_;
173 171
174 // The video frame object used for renderering by WebKit. 172 // The video frame object used for renderering by WebKit.
175 scoped_ptr<WebKit::WebVideoFrame> video_frame_; 173 scoped_ptr<WebKit::WebVideoFrame> video_frame_;
176 174
177 // Message loops for main renderer thread. 175 // Message loop for main renderer thread.
178 MessageLoop* main_loop_; 176 MessageLoop* main_loop_;
179 177
180 // Proxy object that delegates method calls on Render Thread.
181 // This object is created on the Render Thread and is only called in the
182 // destructor.
183 scoped_refptr<WebMediaPlayerProxyAndroid> proxy_;
184
185 // If this is set to true, prepare of the media player is done.
186 bool prepared_;
187
188 // URL of the media file to be fetched. 178 // URL of the media file to be fetched.
189 GURL url_; 179 GURL url_;
190 180
191 // Media duration. 181 // Media duration.
192 float duration_; 182 base::TimeDelta duration_;
193 183
194 // When switching tabs, we release the media player. This variable keeps 184 // The time android media player is trying to seek.
195 // track of the current playback time so that a seek will be performed
196 // next time the media player gets recreated.
197 float pending_seek_; 185 float pending_seek_;
198 186
199 // Internal seek state. 187 // Internal seek state.
200 bool seeking_; 188 bool seeking_;
201 189
202 // Whether playback has completed.
203 float playback_completed_;
204
205 // Whether loading has progressed since the last call to didLoadingProgress. 190 // Whether loading has progressed since the last call to didLoadingProgress.
206 mutable bool did_loading_progress_; 191 mutable bool did_loading_progress_;
207 192
208 // Pointer to the cookie jar to get the cookie for the media url. 193 // Manager for managing this object.
209 WebKit::WebCookieJar* cookie_jar_; 194 WebMediaPlayerManagerAndroid* manager_;
210 195
211 // Manager for managing this media player. 196 // Player ID assigned by the |manager_|.
212 webkit_media::WebMediaPlayerManagerAndroid* manager_;
213
214 // Player ID assigned by the media player manager.
215 int player_id_; 197 int player_id_;
216 198
217 // Whether the user has clicked the play button while media player
218 // is preparing.
219 bool pending_play_event_;
220
221 // Current player states. 199 // Current player states.
222 WebKit::WebMediaPlayer::NetworkState network_state_; 200 WebKit::WebMediaPlayer::NetworkState network_state_;
223 WebKit::WebMediaPlayer::ReadyState ready_state_; 201 WebKit::WebMediaPlayer::ReadyState ready_state_;
224 202
225 // GL texture ID allocated to the video. 203 // GL texture ID allocated to the video.
226 unsigned int texture_id_; 204 unsigned int texture_id_;
227 205
228 // Stream texture ID allocated to the video. 206 // Stream texture ID allocated to the video.
229 unsigned int stream_id_; 207 unsigned int stream_id_;
230 208
231 // Whether |media_player_| needs to re-establish the surface texture peer. 209 // Whether the mediaplayer is playing.
210 bool is_playing_;
211
212 // Whether media player needs to re-establish the surface texture peer.
232 bool needs_establish_peer_; 213 bool needs_establish_peer_;
233 214
234 // Object for allocating stream textures. 215 // Object for allocating stream textures.
235 scoped_ptr<webkit_media::StreamTextureFactory> stream_texture_factory_; 216 scoped_ptr<StreamTextureFactory> stream_texture_factory_;
236 217
237 // Object for calling back the compositor thread to repaint the video when a 218 // Object for calling back the compositor thread to repaint the video when a
238 // frame available. It should be initialized on the compositor thread. 219 // frame available. It should be initialized on the compositor thread.
239 scoped_ptr<webkit_media::StreamTextureProxy> stream_texture_proxy_; 220 scoped_ptr<StreamTextureProxy> stream_texture_proxy_;
240 221
241 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); 222 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid);
242 }; 223 };
243 224
244 } // namespace webkit_media 225 } // namespace webkit_media
245 226
246 #endif // WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ 227 #endif // WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698