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

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

Issue 12443003: Implement out-of-band video compositing on Android: Step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 7 years, 9 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
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 "webkit/media/android/webmediaplayer_android.h" 5 #include "webkit/media/android/webmediaplayer_android.h"
6 6
7 #include "base/command_line.h"
7 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "media/base/android/media_player_bridge.h" 10 #include "media/base/android/media_player_bridge.h"
11 #include "media/base/media_switches.h"
10 #include "media/base/video_frame.h" 12 #include "media/base/video_frame.h"
11 #include "net/base/mime_util.h" 13 #include "net/base/mime_util.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient. h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient. h"
13 #include "webkit/media/android/stream_texture_factory_android.h" 15 #include "webkit/media/android/stream_texture_factory_android.h"
14 #include "webkit/media/android/webmediaplayer_manager_android.h" 16 #include "webkit/media/android/webmediaplayer_manager_android.h"
15 #include "webkit/media/webmediaplayer_util.h" 17 #include "webkit/media/webmediaplayer_util.h"
16 #include "webkit/media/webvideoframe_impl.h" 18 #include "webkit/media/webvideoframe_impl.h"
17 19
18 static const uint32 kGLTextureExternalOES = 0x8D65; 20 static const uint32 kGLTextureExternalOES = 0x8D65;
19 21
(...skipping 16 matching lines...) Expand all
36 main_loop_(MessageLoop::current()), 38 main_loop_(MessageLoop::current()),
37 pending_seek_(0), 39 pending_seek_(0),
38 seeking_(false), 40 seeking_(false),
39 did_loading_progress_(false), 41 did_loading_progress_(false),
40 manager_(manager), 42 manager_(manager),
41 network_state_(WebMediaPlayer::NetworkStateEmpty), 43 network_state_(WebMediaPlayer::NetworkStateEmpty),
42 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), 44 ready_state_(WebMediaPlayer::ReadyStateHaveNothing),
43 is_playing_(false), 45 is_playing_(false),
44 needs_establish_peer_(true), 46 needs_establish_peer_(true),
45 has_size_info_(false), 47 has_size_info_(false),
46 stream_texture_factory_(factory) { 48 stream_texture_factory_(factory),
49 needs_external_surface_(false) {
47 main_loop_->AddDestructionObserver(this); 50 main_loop_->AddDestructionObserver(this);
48 if (manager_) 51 if (manager_)
49 player_id_ = manager_->RegisterMediaPlayer(this); 52 player_id_ = manager_->RegisterMediaPlayer(this);
50 53
54 if (CommandLine::ForCurrentProcess()->HasSwitch(
55 switches::kAlwaysUseExternalVideoSurface)) {
56 SetNeedsExternalSurface(true);
57 }
51 if (stream_texture_factory_.get()) { 58 if (stream_texture_factory_.get()) {
52 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); 59 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy());
53 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); 60 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_);
54 ReallocateVideoFrame(); 61 ReallocateVideoFrame();
55 } 62 }
56 } 63 }
57 64
58 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { 65 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() {
59 if (stream_id_) 66 if (stream_id_)
60 stream_texture_factory_->DestroyStreamTexture(texture_id_); 67 stream_texture_factory_->DestroyStreamTexture(texture_id_);
(...skipping 12 matching lines...) Expand all
73 url_ = url; 80 url_ = url;
74 81
75 InitializeMediaPlayer(url_); 82 InitializeMediaPlayer(url_);
76 } 83 }
77 84
78 void WebMediaPlayerAndroid::cancelLoad() { 85 void WebMediaPlayerAndroid::cancelLoad() {
79 NOTIMPLEMENTED(); 86 NOTIMPLEMENTED();
80 } 87 }
81 88
82 void WebMediaPlayerAndroid::play() { 89 void WebMediaPlayerAndroid::play() {
90 if (hasVideo() && needs_external_surface_) {
91 DCHECK(!needs_establish_peer_);
92 RequestExternalSurface();
93 }
83 if (hasVideo() && needs_establish_peer_) 94 if (hasVideo() && needs_establish_peer_)
84 EstablishSurfaceTexturePeer(); 95 EstablishSurfaceTexturePeer();
85 96
86 PlayInternal(); 97 PlayInternal();
87 is_playing_ = true; 98 is_playing_ = true;
88 } 99 }
89 100
90 void WebMediaPlayerAndroid::pause() { 101 void WebMediaPlayerAndroid::pause() {
91 PauseInternal(); 102 PauseInternal();
92 is_playing_ = false; 103 is_playing_ = false;
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 stream_texture_factory_->DestroyStreamTexture(texture_id_); 384 stream_texture_factory_->DestroyStreamTexture(texture_id_);
374 stream_id_ = 0; 385 stream_id_ = 0;
375 } 386 }
376 387
377 video_frame_.reset(); 388 video_frame_.reset();
378 389
379 manager_ = NULL; 390 manager_ = NULL;
380 } 391 }
381 392
382 void WebMediaPlayerAndroid::ReallocateVideoFrame() { 393 void WebMediaPlayerAndroid::ReallocateVideoFrame() {
383 if (texture_id_) { 394 if (needs_external_surface_) {
395 // VideoFrame::CreateHoleFrame is only defined under GOOGLE_TV.
396 #if defined(GOOGLE_TV)
397 if (!natural_size_.isEmpty())
398 video_frame_.reset(new WebVideoFrameImpl(VideoFrame::CreateHoleFrame(
399 natural_size_)));
400 #else
401 NOTIMPLEMENTED() << "Hole punching not supported outside of Google TV";
402 #endif
403 } else if (texture_id_) {
384 video_frame_.reset(new WebVideoFrameImpl(VideoFrame::WrapNativeTexture( 404 video_frame_.reset(new WebVideoFrameImpl(VideoFrame::WrapNativeTexture(
385 texture_id_, kGLTextureExternalOES, natural_size_, 405 texture_id_, kGLTextureExternalOES, natural_size_,
386 gfx::Rect(natural_size_), natural_size_, base::TimeDelta(), 406 gfx::Rect(natural_size_), natural_size_, base::TimeDelta(),
387 VideoFrame::ReadPixelsCB(), 407 VideoFrame::ReadPixelsCB(),
388 base::Closure()))); 408 base::Closure())));
389 } 409 }
390 } 410 }
391 411
392 WebVideoFrame* WebMediaPlayerAndroid::getCurrentFrame() { 412 WebVideoFrame* WebMediaPlayerAndroid::getCurrentFrame() {
393 if (stream_texture_proxy_.get() && !stream_texture_proxy_->IsInitialized() 413 if (stream_texture_proxy_.get() && !stream_texture_proxy_->IsInitialized()
394 && stream_id_) { 414 && stream_id_ && !needs_external_surface_) {
395 stream_texture_proxy_->Initialize( 415 stream_texture_proxy_->Initialize(
396 stream_id_, video_frame_->width(), video_frame_->height()); 416 stream_id_, video_frame_->width(), video_frame_->height());
397 } 417 }
398 418
399 return video_frame_.get(); 419 return video_frame_.get();
400 } 420 }
401 421
402 void WebMediaPlayerAndroid::putCurrentFrame( 422 void WebMediaPlayerAndroid::putCurrentFrame(
403 WebVideoFrame* web_video_frame) { 423 WebVideoFrame* web_video_frame) {
404 } 424 }
(...skipping 11 matching lines...) Expand all
416 } 436 }
417 437
418 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { 438 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) {
419 needs_establish_peer_ = needs_establish_peer; 439 needs_establish_peer_ = needs_establish_peer;
420 } 440 }
421 441
422 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { 442 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) {
423 is_playing_ = is_playing; 443 is_playing_ = is_playing;
424 } 444 }
425 445
446 void WebMediaPlayerAndroid::SetNeedsExternalSurface(
scherkus (not reviewing) 2013/03/07 00:09:13 do you really need this method? it looks like you
wonsik 2013/03/07 02:54:08 I expect to have more criteria for using external
scherkus (not reviewing) 2013/03/07 18:59:10 Unless you have a CL ready to review that uses thi
wonsik 2013/03/11 12:32:44 Got it. Done.
447 bool needs_external_surface) {
448 needs_external_surface_ = needs_external_surface;
449 SetNeedsEstablishPeer(!needs_external_surface);
450 ReallocateVideoFrame();
451 }
452
426 } // namespace webkit_media 453 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698