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

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: rebase after https://chromiumcodereview.appspot.com/10469003/ got committed 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(); 48 virtual ~WebMediaPlayerAndroid();
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); 54 virtual void load(const WebKit::WebURL& url);
47 virtual void cancelLoad(); 55 virtual void cancelLoad();
48 56
49 // Playback controls. 57 // Playback controls.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // Provide statistics. 106 // Provide statistics.
99 virtual unsigned decodedFrameCount() const; 107 virtual unsigned decodedFrameCount() const;
100 virtual unsigned droppedFrameCount() const; 108 virtual unsigned droppedFrameCount() const;
101 virtual unsigned audioDecodedByteCount() const; 109 virtual unsigned audioDecodedByteCount() const;
102 virtual unsigned videoDecodedByteCount() const; 110 virtual unsigned videoDecodedByteCount() const;
103 111
104 // Methods called from VideoLayerChromium. These methods are running on the 112 // Methods called from VideoLayerChromium. These methods are running on the
105 // compositor thread. 113 // compositor thread.
106 virtual WebKit::WebVideoFrame* getCurrentFrame(); 114 virtual WebKit::WebVideoFrame* getCurrentFrame();
107 virtual void putCurrentFrame(WebKit::WebVideoFrame*); 115 virtual void putCurrentFrame(WebKit::WebVideoFrame*);
116 virtual void setStreamTextureClient(
117 WebKit::WebStreamTextureClient* client);
108 118
109 // Media player callback handlers. 119 // Media player callback handlers.
110 void OnMediaPrepared(); 120 void OnMediaPrepared();
111 void OnPlaybackComplete(); 121 void OnPlaybackComplete();
112 void OnBufferingUpdate(int percentage); 122 void OnBufferingUpdate(int percentage);
113 void OnSeekComplete(); 123 void OnSeekComplete();
114 void OnMediaError(int error_type); 124 void OnMediaError(int error_type);
115 void OnMediaInfo(int info_type); 125 void OnMediaInfo(int info_type);
116 void OnVideoSizeChanged(int width, int height); 126 void OnVideoSizeChanged(int width, int height);
117 127
118 // Method to set the video surface for android media player. 128 // This function is called by WebMediaPlayerManagerAndroid to pause the video
119 void SetVideoSurface(jobject j_surface); 129 // and release |media_player_| and its surface texture when we switch tabs.
130 // However, the actual GlTexture is not released to keep the video screenshot.
131 void ReleaseMediaResources();
120 132
121 private: 133 private:
122 // Create a media player to load the |url_| and prepare for playback. 134 // Create a media player to load the |url_| and prepare for playback.
123 // Because of limited decoding resources on mobile devices, idle media players 135 // Because of limited decoding resources on mobile devices, idle media players
124 // could get released. In that case, we call this function to get a new media 136 // could get released. In that case, we call this function to get a new media
125 // player when needed. 137 // player when needed.
126 void InitializeMediaPlayer(); 138 void InitializeMediaPlayer();
127 139
128 // Functions that implements media player control. 140 // Functions that implements media player control.
129 void PlayInternal(); 141 void PlayInternal();
130 void PauseInternal(); 142 void PauseInternal();
131 void SeekInternal(float seconds); 143 void SeekInternal(float seconds);
132 144
133 // Helper methods for posting task for setting states and update WebKit. 145 // Helper methods for posting task for setting states and update WebKit.
134 void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state); 146 void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state);
135 void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state); 147 void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state);
136 148
149 // Methods for creation and deletion of stream texture.
150 void CreateStreamTexture();
151 void DestroyStreamTexture();
152
137 // whether the current process is incognito mode 153 // whether the current process is incognito mode
138 static bool incognito_mode_; 154 static bool incognito_mode_;
139 155
156 WebKit::WebFrame* frame_;
157
140 WebKit::WebMediaPlayerClient* const client_; 158 WebKit::WebMediaPlayerClient* const client_;
141 159
142 // Save the list of buffered time ranges. 160 // Save the list of buffered time ranges.
143 WebKit::WebTimeRanges buffered_; 161 WebKit::WebTimeRanges buffered_;
144 162
145 // Bridge to the android media player. 163 // Bridge to the android media player.
146 scoped_ptr<media::MediaPlayerBridge> media_player_; 164 scoped_ptr<media::MediaPlayerBridge> media_player_;
147 165
148 // Size of the media element. 166 // Size of the media element.
149 WebKit::WebSize texture_size_; 167 WebKit::WebSize texture_size_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 199
182 // Fake it by self increasing on every OnBufferingUpdate event. 200 // Fake it by self increasing on every OnBufferingUpdate event.
183 int64 buffered_bytes_; 201 int64 buffered_bytes_;
184 202
185 // Whether loading has progressed since the last call to didLoadingProgress. 203 // Whether loading has progressed since the last call to didLoadingProgress.
186 mutable bool did_loading_progress_; 204 mutable bool did_loading_progress_;
187 205
188 // Pointer to the cookie jar to get the cookie for the media url. 206 // Pointer to the cookie jar to get the cookie for the media url.
189 WebKit::WebCookieJar* cookie_jar_; 207 WebKit::WebCookieJar* cookie_jar_;
190 208
209 // Manager for managing this media player.
210 webkit_media::WebMediaPlayerManagerAndroid* manager_;
211
212 // Player ID assigned by the media player manager.
213 int player_id_;
214
191 // Whether the user has clicked the play button while media player 215 // Whether the user has clicked the play button while media player
192 // is preparing. 216 // is preparing.
193 bool pending_play_event_; 217 bool pending_play_event_;
194 218
195 // Current player states. 219 // Current player states.
196 WebKit::WebMediaPlayer::NetworkState network_state_; 220 WebKit::WebMediaPlayer::NetworkState network_state_;
197 WebKit::WebMediaPlayer::ReadyState ready_state_; 221 WebKit::WebMediaPlayer::ReadyState ready_state_;
198 222
223 // GL texture ID allocated to the video.
224 unsigned int texture_id_;
225
226 // Stream texture ID allocated to the video.
227 unsigned int stream_id_;
228
229 // Whether |media_player_| needs to re-establish the surface texture peer.
230 bool needs_establish_peer_;
231
232 // Object for allocating stream textures.
233 scoped_ptr<webkit_media::StreamTextureFactory> stream_texture_factory_;
234
235 // Object for calling back the compositor thread to repaint the video when a
236 // frame available. It should be initialized on the compositor thread.
237 scoped_ptr<webkit_media::StreamTextureProxy> stream_texture_proxy_;
238
199 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); 239 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid);
200 }; 240 };
201 241
202 } // namespace webkit_media 242 } // namespace webkit_media
203 243
204 #endif // WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ 244 #endif // WEBKIT_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_
OLDNEW
« no previous file with comments | « webkit/media/android/stream_texture_factory_android.h ('k') | webkit/media/android/webmediaplayer_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698