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

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

Issue 10413015: Upstream implementation for embedded video for WebMediaPlayerAndroid (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressing feedbacks Created 8 years, 7 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_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
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
124 // This function is called by WebMediaPlayerManagerAndroid to pause the video
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();
128
117 // Method to set the video surface for android media player. 129 // Method to set the video surface for android media player.
118 void SetVideoSurface(jobject j_surface); 130 void SetVideoSurface(jobject j_surface);
scherkus (not reviewing) 2012/05/25 22:01:46 if it's possible could you try to not include meth
qinmin 2012/05/26 00:37:42 This function is removed from this class, will ups
119 131
120 private: 132 private:
121 // Create a media player to load the |url_| and prepare for playback. 133 // Create a media player to load the |url_| and prepare for playback.
122 // Because of limited decoding resources on mobile devices, idle media players 134 // 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 135 // could get released. In that case, we call this function to get a new media
124 // player when needed. 136 // player when needed.
125 void InitializeMediaPlayer(); 137 void InitializeMediaPlayer();
126 138
127 // Functions that implements media player control. 139 // Functions that implements media player control.
128 void PlayInternal(); 140 void PlayInternal();
129 void PauseInternal(); 141 void PauseInternal();
130 void SeekInternal(float seconds); 142 void SeekInternal(float seconds);
131 143
132 // Helper methods for posting task for setting states and update WebKit. 144 // Helper methods for posting task for setting states and update WebKit.
133 void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state); 145 void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state);
134 void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state); 146 void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state);
135 147
148 // Methods for creation and deletion of stream texture.
149 void CreateStreamTexture();
150 void DestroyStreamTexture();
151
136 // whether the current process is incognito mode 152 // whether the current process is incognito mode
137 static bool incognito_mode_; 153 static bool incognito_mode_;
138 154
139 WebKit::WebMediaPlayerClient* const client_; 155 WebKit::WebMediaPlayerClient* const client_;
140 156
141 // Save the list of buffered time ranges. 157 // Save the list of buffered time ranges.
142 WebKit::WebTimeRanges buffered_; 158 WebKit::WebTimeRanges buffered_;
143 159
144 // Bridge to the android media player. 160 // Bridge to the android media player.
145 scoped_ptr<media::MediaPlayerBridge> media_player_; 161 scoped_ptr<media::MediaPlayerBridge> media_player_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 193
178 // Whether playback has completed. 194 // Whether playback has completed.
179 float playback_completed_; 195 float playback_completed_;
180 196
181 // Fake it by self increasing on every OnBufferingUpdate event. 197 // Fake it by self increasing on every OnBufferingUpdate event.
182 int64 buffered_bytes_; 198 int64 buffered_bytes_;
183 199
184 // Pointer to the cookie jar to get the cookie for the media url. 200 // Pointer to the cookie jar to get the cookie for the media url.
185 WebKit::WebCookieJar* cookie_jar_; 201 WebKit::WebCookieJar* cookie_jar_;
186 202
203 // Manager for managing this media player.
204 webkit_media::WebMediaPlayerManagerAndroid* manager_;
205
206 // Player ID assigned by the media player manager.
207 int player_id_;
208
187 // Whether the user has clicked the play button while media player 209 // Whether the user has clicked the play button while media player
188 // is preparing. 210 // is preparing.
189 bool pending_play_event_; 211 bool pending_play_event_;
190 212
191 // Current player states. 213 // Current player states.
192 WebKit::WebMediaPlayer::NetworkState network_state_; 214 WebKit::WebMediaPlayer::NetworkState network_state_;
193 WebKit::WebMediaPlayer::ReadyState ready_state_; 215 WebKit::WebMediaPlayer::ReadyState ready_state_;
194 216
217 // GL texture ID allocated to the video.
218 unsigned int texture_id_;
219
220 // Stream texture ID allocated to the video.
221 unsigned int stream_id_;
222
223 // Whether |media_player_| needs to re-establish the surface texture peer.
224 bool needs_establish_peer_;
225
226 // Object for allocating stream textures.
227 scoped_ptr<webkit_media::StreamTextureFactory> stream_texture_factory_;
228
229 // Object for calling back the compositor thread to repaint the video when a
230 // frame available. It should be initialized on the compositor thread.
231 scoped_ptr<webkit_media::StreamTextureProxy> stream_texture_proxy_;
232
195 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); 233 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid);
196 }; 234 };
197 235
198 } // namespace webkit_media 236 } // namespace webkit_media
199 237
200 #endif // WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ 238 #endif // WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698