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

Side by Side Diff: content/browser/android/media_player_manager_impl.cc

Issue 13669003: Refactoring ContentVideoViewContextDelegate.java (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix tests Created 7 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 #include "content/browser/android/media_player_manager_impl.h" 5 #include "content/browser/android/media_player_manager_impl.h"
6 6
7 #include "content/browser/android/content_view_core_impl.h"
7 #include "content/browser/android/media_resource_getter_impl.h" 8 #include "content/browser/android/media_resource_getter_impl.h"
8 #include "content/browser/web_contents/web_contents_view_android.h" 9 #include "content/browser/web_contents/web_contents_view_android.h"
9 #include "content/common/media/media_player_messages_android.h" 10 #include "content/common/media/media_player_messages_android.h"
10 #include "content/public/browser/browser_context.h" 11 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/render_process_host.h" 12 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/render_view_host.h" 13 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/storage_partition.h" 14 #include "content/public/browser/storage_partition.h"
15 #include "content/public/browser/web_contents.h"
14 16
15 using media::MediaPlayerAndroid; 17 using media::MediaPlayerAndroid;
16 18
17 // Threshold on the number of media players per renderer before we start 19 // Threshold on the number of media players per renderer before we start
18 // attempting to release inactive media players. 20 // attempting to release inactive media players.
19 static const int kMediaPlayerThreshold = 1; 21 static const int kMediaPlayerThreshold = 1;
20 22
21 namespace media { 23 namespace media {
22 24
23 static MediaPlayerManager::FactoryFunction g_factory_function = NULL; 25 static MediaPlayerManager::FactoryFunction g_factory_function = NULL;
(...skipping 12 matching lines...) Expand all
36 return new content::MediaPlayerManagerImpl(render_view_host); 38 return new content::MediaPlayerManagerImpl(render_view_host);
37 } 39 }
38 40
39 } // namespace media 41 } // namespace media
40 42
41 namespace content { 43 namespace content {
42 44
43 MediaPlayerManagerImpl::MediaPlayerManagerImpl( 45 MediaPlayerManagerImpl::MediaPlayerManagerImpl(
44 RenderViewHost* render_view_host) 46 RenderViewHost* render_view_host)
45 : RenderViewHostObserver(render_view_host), 47 : RenderViewHostObserver(render_view_host),
46 video_view_(this),
47 fullscreen_player_id_(-1), 48 fullscreen_player_id_(-1),
48 web_contents_(WebContents::FromRenderViewHost(render_view_host)) { 49 web_contents_(WebContents::FromRenderViewHost(render_view_host)) {
49 } 50 }
50 51
51 MediaPlayerManagerImpl::~MediaPlayerManagerImpl() {} 52 MediaPlayerManagerImpl::~MediaPlayerManagerImpl() {}
52 53
53 bool MediaPlayerManagerImpl::OnMessageReceived(const IPC::Message& msg) { 54 bool MediaPlayerManagerImpl::OnMessageReceived(const IPC::Message& msg) {
54 bool handled = true; 55 bool handled = true;
55 IPC_BEGIN_MESSAGE_MAP(MediaPlayerManagerImpl, msg) 56 IPC_BEGIN_MESSAGE_MAP(MediaPlayerManagerImpl, msg)
56 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_EnterFullscreen, OnEnterFullscreen) 57 IPC_MESSAGE_HANDLER(MediaPlayerHostMsg_EnterFullscreen, OnEnterFullscreen)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 Send(new MediaPlayerMsg_DidExitFullscreen( 108 Send(new MediaPlayerMsg_DidExitFullscreen(
108 routing_id(), fullscreen_player_id_)); 109 routing_id(), fullscreen_player_id_));
109 MediaPlayerAndroid* player = GetFullscreenPlayer(); 110 MediaPlayerAndroid* player = GetFullscreenPlayer();
110 fullscreen_player_id_ = -1; 111 fullscreen_player_id_ = -1;
111 if (!player) 112 if (!player)
112 return; 113 return;
113 if (release_media_player) 114 if (release_media_player)
114 player->Release(); 115 player->Release();
115 else 116 else
116 player->SetVideoSurface(gfx::ScopedJavaSurface()); 117 player->SetVideoSurface(gfx::ScopedJavaSurface());
118 video_view_.reset();
117 } 119 }
118 120
119 void MediaPlayerManagerImpl::SetVideoSurface(gfx::ScopedJavaSurface surface) { 121 void MediaPlayerManagerImpl::SetVideoSurface(gfx::ScopedJavaSurface surface) {
120 MediaPlayerAndroid* player = GetFullscreenPlayer(); 122 MediaPlayerAndroid* player = GetFullscreenPlayer();
121 if (player) { 123 if (player) {
122 player->SetVideoSurface(surface.Pass()); 124 player->SetVideoSurface(surface.Pass());
123 Send(new MediaPlayerMsg_DidEnterFullscreen( 125 Send(new MediaPlayerMsg_DidEnterFullscreen(
124 routing_id(), player->player_id())); 126 routing_id(), player->player_id()));
125 } 127 }
126 } 128 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 167
166 void MediaPlayerManagerImpl::OnPause(int player_id) { 168 void MediaPlayerManagerImpl::OnPause(int player_id) {
167 MediaPlayerAndroid* player = GetPlayer(player_id); 169 MediaPlayerAndroid* player = GetPlayer(player_id);
168 if (player) 170 if (player)
169 player->Pause(); 171 player->Pause();
170 } 172 }
171 173
172 void MediaPlayerManagerImpl::OnEnterFullscreen(int player_id) { 174 void MediaPlayerManagerImpl::OnEnterFullscreen(int player_id) {
173 DCHECK_EQ(fullscreen_player_id_, -1); 175 DCHECK_EQ(fullscreen_player_id_, -1);
174 176
175 fullscreen_player_id_ = player_id; 177 if (video_view_.get()) {
176 video_view_.CreateContentVideoView(); 178 fullscreen_player_id_ = player_id;
179 video_view_->OpenVideo();
180 } else if (!ContentVideoView::HasContentVideoView()) {
181 // In Android WebView, two ContentViewCores could both try to enter
182 // fullscreen video, we just ignore the second one.
183 fullscreen_player_id_ = player_id;
184 WebContents* web_contents =
185 WebContents::FromRenderViewHost(render_view_host());
186 ContentViewCoreImpl* content_view_core_impl =
187 ContentViewCoreImpl::FromWebContents(web_contents);
188 video_view_.reset(new ContentVideoView(content_view_core_impl->GetContext(),
189 content_view_core_impl->GetContentVideoViewClient(), this));
190 }
177 } 191 }
178 192
179 void MediaPlayerManagerImpl::OnExitFullscreen(int player_id) { 193 void MediaPlayerManagerImpl::OnExitFullscreen(int player_id) {
180 if (fullscreen_player_id_ == player_id) { 194 if (fullscreen_player_id_ == player_id) {
181 MediaPlayerAndroid* player = GetPlayer(player_id); 195 MediaPlayerAndroid* player = GetPlayer(player_id);
182 if (player) 196 if (player)
183 player->SetVideoSurface(gfx::ScopedJavaSurface()); 197 player->SetVideoSurface(gfx::ScopedJavaSurface());
184 video_view_.DestroyContentVideoView();
185 fullscreen_player_id_ = -1; 198 fullscreen_player_id_ = -1;
199 video_view_->OnExitFullscreen();
200 video_view_.reset();
186 } 201 }
187 } 202 }
188 203
189 void MediaPlayerManagerImpl::OnReleaseResources(int player_id) { 204 void MediaPlayerManagerImpl::OnReleaseResources(int player_id) {
190 MediaPlayerAndroid* player = GetPlayer(player_id); 205 MediaPlayerAndroid* player = GetPlayer(player_id);
191 // Don't release the fullscreen player when tab visibility changes, 206 // Don't release the fullscreen player when tab visibility changes,
192 // it will be released when user hit the back/home button or when 207 // it will be released when user hit the back/home button or when
193 // OnDestroyPlayer is called. 208 // OnDestroyPlayer is called.
194 if (player && player_id != fullscreen_player_id_) 209 if (player && player_id != fullscreen_player_id_)
195 player->Release(); 210 player->Release();
196 } 211 }
197 212
198 void MediaPlayerManagerImpl::OnDestroyPlayer(int player_id) { 213 void MediaPlayerManagerImpl::OnDestroyPlayer(int player_id) {
199 RemovePlayer(player_id); 214 RemovePlayer(player_id);
200 if (fullscreen_player_id_ == player_id) 215 if (fullscreen_player_id_ == player_id)
201 fullscreen_player_id_ = -1; 216 fullscreen_player_id_ = -1;
202 } 217 }
203 218
204 void MediaPlayerManagerImpl::DestroyAllMediaPlayers() { 219 void MediaPlayerManagerImpl::DestroyAllMediaPlayers() {
205 players_.clear(); 220 players_.clear();
206 if (fullscreen_player_id_ != -1) { 221 if (fullscreen_player_id_ != -1) {
207 video_view_.DestroyContentVideoView(); 222 video_view_.reset();
208 fullscreen_player_id_ = -1; 223 fullscreen_player_id_ = -1;
209 } 224 }
210 } 225 }
211 226
212 void MediaPlayerManagerImpl::OnDemuxerReady( 227 void MediaPlayerManagerImpl::OnDemuxerReady(
213 int player_id, 228 int player_id,
214 const media::MediaPlayerHostMsg_DemuxerReady_Params& params) { 229 const media::MediaPlayerHostMsg_DemuxerReady_Params& params) {
215 MediaPlayerAndroid* player = GetPlayer(player_id); 230 MediaPlayerAndroid* player = GetPlayer(player_id);
216 if (player) 231 if (player)
217 player->DemuxerReady(params); 232 player->DemuxerReady(params);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 MediaPlayerAndroid* MediaPlayerManagerImpl::GetFullscreenPlayer() { 287 MediaPlayerAndroid* MediaPlayerManagerImpl::GetFullscreenPlayer() {
273 return GetPlayer(fullscreen_player_id_); 288 return GetPlayer(fullscreen_player_id_);
274 } 289 }
275 290
276 void MediaPlayerManagerImpl::OnMediaMetadataChanged( 291 void MediaPlayerManagerImpl::OnMediaMetadataChanged(
277 int player_id, base::TimeDelta duration, int width, int height, 292 int player_id, base::TimeDelta duration, int width, int height,
278 bool success) { 293 bool success) {
279 Send(new MediaPlayerMsg_MediaMetadataChanged( 294 Send(new MediaPlayerMsg_MediaMetadataChanged(
280 routing_id(), player_id, duration, width, height, success)); 295 routing_id(), player_id, duration, width, height, success));
281 if (fullscreen_player_id_ != -1) 296 if (fullscreen_player_id_ != -1)
282 video_view_.UpdateMediaMetadata(); 297 video_view_->UpdateMediaMetadata();
283 } 298 }
284 299
285 void MediaPlayerManagerImpl::OnPlaybackComplete(int player_id) { 300 void MediaPlayerManagerImpl::OnPlaybackComplete(int player_id) {
286 Send(new MediaPlayerMsg_MediaPlaybackCompleted(routing_id(), player_id)); 301 Send(new MediaPlayerMsg_MediaPlaybackCompleted(routing_id(), player_id));
287 if (fullscreen_player_id_ != -1) 302 if (fullscreen_player_id_ != -1)
288 video_view_.OnPlaybackComplete(); 303 video_view_->OnPlaybackComplete();
289 } 304 }
290 305
291 void MediaPlayerManagerImpl::OnMediaInterrupted(int player_id) { 306 void MediaPlayerManagerImpl::OnMediaInterrupted(int player_id) {
292 // Tell WebKit that the audio should be paused, then release all resources 307 // Tell WebKit that the audio should be paused, then release all resources
293 Send(new MediaPlayerMsg_DidMediaPlayerPause(routing_id(), player_id)); 308 Send(new MediaPlayerMsg_DidMediaPlayerPause(routing_id(), player_id));
294 OnReleaseResources(player_id); 309 OnReleaseResources(player_id);
295 } 310 }
296 311
297 void MediaPlayerManagerImpl::OnBufferingUpdate( 312 void MediaPlayerManagerImpl::OnBufferingUpdate(
298 int player_id, int percentage) { 313 int player_id, int percentage) {
299 Send(new MediaPlayerMsg_MediaBufferingUpdate( 314 Send(new MediaPlayerMsg_MediaBufferingUpdate(
300 routing_id(), player_id, percentage)); 315 routing_id(), player_id, percentage));
301 if (fullscreen_player_id_ != -1) 316 if (fullscreen_player_id_ != -1)
302 video_view_.OnBufferingUpdate(percentage); 317 video_view_->OnBufferingUpdate(percentage);
303 } 318 }
304 319
305 void MediaPlayerManagerImpl::OnSeekComplete(int player_id, 320 void MediaPlayerManagerImpl::OnSeekComplete(int player_id,
306 base::TimeDelta current_time) { 321 base::TimeDelta current_time) {
307 Send(new MediaPlayerMsg_MediaSeekCompleted( 322 Send(new MediaPlayerMsg_MediaSeekCompleted(
308 routing_id(), player_id, current_time)); 323 routing_id(), player_id, current_time));
309 } 324 }
310 325
311 void MediaPlayerManagerImpl::OnMediaSeekRequest( 326 void MediaPlayerManagerImpl::OnMediaSeekRequest(
312 int player_id, base::TimeDelta time_to_seek, bool request_surface) { 327 int player_id, base::TimeDelta time_to_seek, bool request_surface) {
313 bool request_texture_peer = request_surface; 328 bool request_texture_peer = request_surface;
314 if (request_surface && player_id == fullscreen_player_id_) { 329 if (request_surface && player_id == fullscreen_player_id_ &&
315 video_view_.CreateContentVideoView(); 330 video_view_.get()) {
331 video_view_->OpenVideo();
316 request_texture_peer = false; 332 request_texture_peer = false;
317 } 333 }
318 Send(new MediaPlayerMsg_MediaSeekRequest( 334 Send(new MediaPlayerMsg_MediaSeekRequest(
319 routing_id(), player_id, time_to_seek, request_texture_peer)); 335 routing_id(), player_id, time_to_seek, request_texture_peer));
320 } 336 }
321 337
322 void MediaPlayerManagerImpl::OnError(int player_id, int error) { 338 void MediaPlayerManagerImpl::OnError(int player_id, int error) {
323 Send(new MediaPlayerMsg_MediaError(routing_id(), player_id, error)); 339 Send(new MediaPlayerMsg_MediaError(routing_id(), player_id, error));
324 if (fullscreen_player_id_ != -1) 340 if (fullscreen_player_id_ != -1)
325 video_view_.OnMediaPlayerError(error); 341 video_view_->OnMediaPlayerError(error);
326 } 342 }
327 343
328 void MediaPlayerManagerImpl::OnVideoSizeChanged( 344 void MediaPlayerManagerImpl::OnVideoSizeChanged(
329 int player_id, int width, int height) { 345 int player_id, int width, int height) {
330 Send(new MediaPlayerMsg_MediaVideoSizeChanged(routing_id(), player_id, 346 Send(new MediaPlayerMsg_MediaVideoSizeChanged(routing_id(), player_id,
331 width, height)); 347 width, height));
332 if (fullscreen_player_id_ != -1) 348 if (fullscreen_player_id_ != -1)
333 video_view_.OnVideoSizeChanged(width, height); 349 video_view_->OnVideoSizeChanged(width, height);
334 } 350 }
335 351
336 void MediaPlayerManagerImpl::OnTimeUpdate(int player_id, 352 void MediaPlayerManagerImpl::OnTimeUpdate(int player_id,
337 base::TimeDelta current_time) { 353 base::TimeDelta current_time) {
338 Send(new MediaPlayerMsg_MediaTimeUpdate( 354 Send(new MediaPlayerMsg_MediaTimeUpdate(
339 routing_id(), player_id, current_time)); 355 routing_id(), player_id, current_time));
340 } 356 }
341 357
342 void MediaPlayerManagerImpl::OnReadFromDemuxer( 358 void MediaPlayerManagerImpl::OnReadFromDemuxer(
343 int player_id, media::DemuxerStream::Type type, bool seek_done) { 359 int player_id, media::DemuxerStream::Type type, bool seek_done) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); 407 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin();
392 it != players_.end(); ++it) { 408 it != players_.end(); ++it) {
393 if ((*it)->player_id() == player_id) { 409 if ((*it)->player_id() == player_id) {
394 players_.erase(it); 410 players_.erase(it);
395 break; 411 break;
396 } 412 }
397 } 413 }
398 } 414 }
399 415
400 } // namespace content 416 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698