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

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

Powered by Google App Engine
This is Rietveld 408576698