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

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.
38 class WebMediaPlayerAndroid : 27 class WebMediaPlayerAndroid :
39 public WebKit::WebMediaPlayer, 28 public WebKit::WebMediaPlayer,
scherkus (not reviewing) 2012/09/10 12:19:08 fix style -- colon should go on this line
qinmin 2012/09/11 04:50:24 Done.
40 public MessageLoop::DestructionObserver, 29 public MessageLoop::DestructionObserver {
41 public base::SupportsWeakPtr<WebMediaPlayerAndroid> {
42 public: 30 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. 31 // Resource loading.
54 virtual void load(const WebKit::WebURL& url, CORSMode cors_mode); 32 virtual void load(const WebKit::WebURL& url, CORSMode cors_mode);
55 virtual void cancelLoad(); 33 virtual void cancelLoad();
56 34
57 // Playback controls. 35 // Playback controls.
58 virtual void play(); 36 virtual void play();
59 virtual void pause(); 37 virtual void pause();
60 virtual void seek(float seconds); 38 virtual void seek(float seconds);
61 virtual bool supportsFullscreen() const; 39 virtual bool supportsFullscreen() const;
62 virtual bool supportsSave() const; 40 virtual bool supportsSave() const;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // Provide statistics. 84 // Provide statistics.
107 virtual unsigned decodedFrameCount() const; 85 virtual unsigned decodedFrameCount() const;
108 virtual unsigned droppedFrameCount() const; 86 virtual unsigned droppedFrameCount() const;
109 virtual unsigned audioDecodedByteCount() const; 87 virtual unsigned audioDecodedByteCount() const;
110 virtual unsigned videoDecodedByteCount() const; 88 virtual unsigned videoDecodedByteCount() const;
111 89
112 // Methods called from VideoLayerChromium. These methods are running on the 90 // Methods called from VideoLayerChromium. These methods are running on the
113 // compositor thread. 91 // compositor thread.
114 virtual WebKit::WebVideoFrame* getCurrentFrame(); 92 virtual WebKit::WebVideoFrame* getCurrentFrame();
115 virtual void putCurrentFrame(WebKit::WebVideoFrame*); 93 virtual void putCurrentFrame(WebKit::WebVideoFrame*);
116 virtual void setStreamTextureClient( 94
117 WebKit::WebStreamTextureClient* client); 95 // This gets called both on compositor and main thread to set the callback
96 // target when a frame is produced.
97 virtual void setStreamTextureClient(WebKit::WebStreamTextureClient* client);
118 98
119 // Media player callback handlers. 99 // Media player callback handlers.
120 void OnMediaPrepared(); 100 virtual void OnMediaPrepared(base::TimeDelta duration);
121 void OnPlaybackComplete(); 101 virtual void OnPlaybackComplete();
122 void OnBufferingUpdate(int percentage); 102 virtual void OnBufferingUpdate(int percentage);
123 void OnSeekComplete(); 103 virtual void OnSeekComplete(base::TimeDelta current_time);
124 void OnMediaError(int error_type); 104 virtual void OnMediaError(int error_type);
125 void OnMediaInfo(int info_type); 105 virtual void OnVideoSizeChanged(int width, int height);
126 void OnVideoSizeChanged(int width, int height);
127 106
128 // This function is called by WebMediaPlayerManagerAndroid to pause the video 107 // Called to update the current time.
129 // and release |media_player_| and its surface texture when we switch tabs. 108 virtual void OnTimeUpdate(base::TimeDelta current_time) {};
scherkus (not reviewing) 2012/09/10 12:19:08 virtual methods shouldn't be inlined -- can you de
qinmin 2012/09/11 04:50:24 Done.
109
110 // Called when the player is released.
111 virtual void OnPlayerReleased();
112
113 // This function is called by the WebMediaPlayerManagerAndroid to pause the
114 // 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. 115 // However, the actual GlTexture is not released to keep the video screenshot.
131 void ReleaseMediaResources(); 116 virtual void ReleaseMediaResources();
132 117
133 // Whether |media_player_| has been initialized. 118 // Method to set the surface for video.
134 bool IsInitialized() const; 119 virtual void SetVideoSurface(jobject j_surface) {}
scherkus (not reviewing) 2012/09/10 12:19:08 ditto
qinmin 2012/09/11 04:50:24 Done.
135 120
136 // Method inherited from DestructionObserver. 121 // Method inherited from DestructionObserver.
137 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; 122 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
138 123
139 private: 124 protected:
140 // Create a media player to load the |url_| and prepare for playback. 125 WebMediaPlayerAndroid(WebKit::WebMediaPlayerClient* client,
141 // Because of limited decoding resources on mobile devices, idle media players 126 WebMediaPlayerManagerAndroid* manager,
142 // could get released. In that case, we call this function to get a new media 127 StreamTextureFactory* factory);
143 // player when needed. 128 virtual ~WebMediaPlayerAndroid();
144 void InitializeMediaPlayer();
145 129
146 // Functions that implements media player control. 130 // Helper method to update the playing state.
147 void PlayInternal(); 131 virtual void UpdatePlayingState(bool is_playing_);
148 void PauseInternal();
149 void SeekInternal(float seconds);
150 132
151 // Helper methods for posting task for setting states and update WebKit. 133 // Helper methods for posting task for setting states and update WebKit.
152 void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state); 134 virtual void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state);
153 void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state); 135 virtual void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state);
154 136
155 // whether the current process is incognito mode 137 // Helper method to reestablish the surface texture peer for android
156 static bool incognito_mode_; 138 // mediaplayer.
139 virtual void EstablishSurfaceTexturePeer();
157 140
158 WebKit::WebFrame* frame_; 141 // Method to be implemented by child classes.
142 // Initialize the media player bridge object.
143 virtual void InitializeMediaPlayer(GURL url) = 0;
159 144
145 // Inform the media player to start playing.
146 virtual void PlayInternal() = 0;
147
148 // Inform the media player to pause.
149 virtual void PauseInternal() = 0;
150
151 // Inform the media player to seek to a particular position.
152 virtual void SeekInternal(base::TimeDelta time) = 0;
153
154 // Get the current time from the media player.
155 virtual float GetCurrentTimeInternal() const = 0;
156
157 // Release the Android Media player.
158 virtual void ReleaseResourcesInternal() = 0;
159
160 // Cleaning up all remaining resources as this object is about to get deleted.
161 virtual void Destroy() {};
scherkus (not reviewing) 2012/09/10 12:19:08 ditto
qinmin 2012/09/11 04:50:24 Done.
162
163 virtual WebKit::WebMediaPlayerClient* client() { return client_; }
scherkus (not reviewing) 2012/09/10 12:19:08 ditto
qinmin 2012/09/11 04:50:24 Done. This doens't need to be virtual as no child
164
165 int player_id() { return player_id_; }
166
167 private:
160 WebKit::WebMediaPlayerClient* const client_; 168 WebKit::WebMediaPlayerClient* const client_;
161 169
162 // Save the list of buffered time ranges. 170 // Save the list of buffered time ranges.
163 WebKit::WebTimeRanges buffered_; 171 WebKit::WebTimeRanges buffered_;
164 172
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. 173 // Size of the video.
172 WebKit::WebSize natural_size_; 174 WebKit::WebSize natural_size_;
173 175
174 // The video frame object used for renderering by WebKit. 176 // The video frame object used for renderering by WebKit.
175 scoped_ptr<WebKit::WebVideoFrame> video_frame_; 177 scoped_ptr<WebKit::WebVideoFrame> video_frame_;
176 178
177 // Message loops for main renderer thread. 179 // Message loop for main renderer thread.
178 MessageLoop* main_loop_; 180 MessageLoop* main_loop_;
179 181
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. 182 // URL of the media file to be fetched.
189 GURL url_; 183 GURL url_;
190 184
191 // Media duration. 185 // Media duration.
192 float duration_; 186 base::TimeDelta duration_;
193 187
194 // When switching tabs, we release the media player. This variable keeps 188 // 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_; 189 float pending_seek_;
198 190
199 // Internal seek state. 191 // Internal seek state.
200 bool seeking_; 192 bool seeking_;
201 193
202 // Whether playback has completed.
203 float playback_completed_;
204
205 // Whether loading has progressed since the last call to didLoadingProgress. 194 // Whether loading has progressed since the last call to didLoadingProgress.
206 mutable bool did_loading_progress_; 195 mutable bool did_loading_progress_;
207 196
208 // Pointer to the cookie jar to get the cookie for the media url. 197 // Manager for managing this object.
209 WebKit::WebCookieJar* cookie_jar_; 198 WebMediaPlayerManagerAndroid* manager_;
210 199
211 // Manager for managing this media player. 200 // 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_; 201 int player_id_;
216 202
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. 203 // Current player states.
222 WebKit::WebMediaPlayer::NetworkState network_state_; 204 WebKit::WebMediaPlayer::NetworkState network_state_;
223 WebKit::WebMediaPlayer::ReadyState ready_state_; 205 WebKit::WebMediaPlayer::ReadyState ready_state_;
224 206
225 // GL texture ID allocated to the video. 207 // GL texture ID allocated to the video.
226 unsigned int texture_id_; 208 unsigned int texture_id_;
227 209
228 // Stream texture ID allocated to the video. 210 // Stream texture ID allocated to the video.
229 unsigned int stream_id_; 211 unsigned int stream_id_;
230 212
231 // Whether |media_player_| needs to re-establish the surface texture peer. 213 // Whether the mediaplayer is playing.
214 bool is_playing_;
215
216 // Whether media player needs to re-establish the surface texture peer.
232 bool needs_establish_peer_; 217 bool needs_establish_peer_;
233 218
234 // Object for allocating stream textures. 219 // Object for allocating stream textures.
235 scoped_ptr<webkit_media::StreamTextureFactory> stream_texture_factory_; 220 scoped_ptr<StreamTextureFactory> stream_texture_factory_;
236 221
237 // Object for calling back the compositor thread to repaint the video when a 222 // Object for calling back the compositor thread to repaint the video when a
238 // frame available. It should be initialized on the compositor thread. 223 // frame available. It should be initialized on the compositor thread.
239 scoped_ptr<webkit_media::StreamTextureProxy> stream_texture_proxy_; 224 scoped_ptr<StreamTextureProxy> stream_texture_proxy_;
240 225
241 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); 226 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid);
242 }; 227 };
243 228
244 } // namespace webkit_media 229 } // namespace webkit_media
245 230
246 #endif // WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ 231 #endif // WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698