| OLD | NEW |
| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 pending_play_event_(false), | 77 pending_play_event_(false), |
| 78 network_state_(WebMediaPlayer::NetworkStateEmpty), | 78 network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 79 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 79 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 80 texture_id_(0), | 80 texture_id_(0), |
| 81 stream_id_(0), | 81 stream_id_(0), |
| 82 needs_establish_peer_(true), | 82 needs_establish_peer_(true), |
| 83 stream_texture_factory_(factory) { | 83 stream_texture_factory_(factory) { |
| 84 main_loop_->AddDestructionObserver(this); | 84 main_loop_->AddDestructionObserver(this); |
| 85 if (manager_) | 85 if (manager_) |
| 86 player_id_ = manager_->RegisterMediaPlayer(this); | 86 player_id_ = manager_->RegisterMediaPlayer(this); |
| 87 if (stream_texture_factory_.get()) | 87 if (stream_texture_factory_.get()) { |
| 88 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 88 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
| 89 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); |
| 90 } |
| 89 } | 91 } |
| 90 | 92 |
| 91 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { | 93 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { |
| 92 if (manager_) | 94 if (manager_) |
| 93 manager_->UnregisterMediaPlayer(player_id_); | 95 manager_->UnregisterMediaPlayer(player_id_); |
| 94 | 96 |
| 97 if (stream_id_) |
| 98 stream_texture_factory_->DestroyStreamTexture(texture_id_); |
| 99 |
| 95 if (main_loop_) | 100 if (main_loop_) |
| 96 main_loop_->RemoveDestructionObserver(this); | 101 main_loop_->RemoveDestructionObserver(this); |
| 97 } | 102 } |
| 98 | 103 |
| 99 void WebMediaPlayerAndroid::InitIncognito(bool incognito_mode) { | 104 void WebMediaPlayerAndroid::InitIncognito(bool incognito_mode) { |
| 100 incognito_mode_ = incognito_mode; | 105 incognito_mode_ = incognito_mode; |
| 101 } | 106 } |
| 102 | 107 |
| 103 void WebMediaPlayerAndroid::load(const WebURL& url, CORSMode cors_mode) { | 108 void WebMediaPlayerAndroid::load(const WebURL& url, CORSMode cors_mode) { |
| 104 if (cors_mode != CORSModeUnspecified) | 109 if (cors_mode != CORSModeUnspecified) |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 break; | 439 break; |
| 435 } | 440 } |
| 436 client_->repaint(); | 441 client_->repaint(); |
| 437 } | 442 } |
| 438 | 443 |
| 439 void WebMediaPlayerAndroid::OnMediaInfo(int info_type) { | 444 void WebMediaPlayerAndroid::OnMediaInfo(int info_type) { |
| 440 NOTIMPLEMENTED(); | 445 NOTIMPLEMENTED(); |
| 441 } | 446 } |
| 442 | 447 |
| 443 void WebMediaPlayerAndroid::OnVideoSizeChanged(int width, int height) { | 448 void WebMediaPlayerAndroid::OnVideoSizeChanged(int width, int height) { |
| 449 if (natural_size_.width == width && natural_size_.height == height) |
| 450 return; |
| 451 |
| 444 natural_size_.width = width; | 452 natural_size_.width = width; |
| 445 natural_size_.height = height; | 453 natural_size_.height = height; |
| 454 if (texture_id_) { |
| 455 video_frame_.reset(new WebVideoFrameImpl(VideoFrame::WrapNativeTexture( |
| 456 texture_id_, kGLTextureExternalOES, width, height, base::TimeDelta(), |
| 457 base::Closure()))); |
| 458 } |
| 446 } | 459 } |
| 447 | 460 |
| 448 void WebMediaPlayerAndroid::UpdateNetworkState( | 461 void WebMediaPlayerAndroid::UpdateNetworkState( |
| 449 WebMediaPlayer::NetworkState state) { | 462 WebMediaPlayer::NetworkState state) { |
| 450 network_state_ = state; | 463 network_state_ = state; |
| 451 client_->networkStateChanged(); | 464 client_->networkStateChanged(); |
| 452 } | 465 } |
| 453 | 466 |
| 454 void WebMediaPlayerAndroid::UpdateReadyState( | 467 void WebMediaPlayerAndroid::UpdateReadyState( |
| 455 WebMediaPlayer::ReadyState state) { | 468 WebMediaPlayer::ReadyState state) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 base::Bind(&WebMediaPlayerProxyAndroid::MediaErrorCallback, proxy_), | 511 base::Bind(&WebMediaPlayerProxyAndroid::MediaErrorCallback, proxy_), |
| 499 base::Bind(&WebMediaPlayerProxyAndroid::VideoSizeChangedCallback, proxy_), | 512 base::Bind(&WebMediaPlayerProxyAndroid::VideoSizeChangedCallback, proxy_), |
| 500 base::Bind(&WebMediaPlayerProxyAndroid::BufferingUpdateCallback, proxy_), | 513 base::Bind(&WebMediaPlayerProxyAndroid::BufferingUpdateCallback, proxy_), |
| 501 base::Bind(&WebMediaPlayerProxyAndroid::MediaPreparedCallback, proxy_)); | 514 base::Bind(&WebMediaPlayerProxyAndroid::MediaPreparedCallback, proxy_)); |
| 502 } | 515 } |
| 503 | 516 |
| 504 void WebMediaPlayerAndroid::PlayInternal() { | 517 void WebMediaPlayerAndroid::PlayInternal() { |
| 505 CHECK(prepared_); | 518 CHECK(prepared_); |
| 506 | 519 |
| 507 if (hasVideo() && stream_texture_factory_.get()) { | 520 if (hasVideo() && stream_texture_factory_.get()) { |
| 508 if (!stream_id_) | |
| 509 CreateStreamTexture(); | |
| 510 | |
| 511 if (needs_establish_peer_) { | 521 if (needs_establish_peer_) { |
| 512 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); | 522 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); |
| 513 needs_establish_peer_ = false; | 523 needs_establish_peer_ = false; |
| 514 } | 524 } |
| 515 } | 525 } |
| 516 | 526 |
| 517 if (paused()) | 527 if (paused()) |
| 518 media_player_->Start(base::Bind( | 528 media_player_->Start(base::Bind( |
| 519 &WebMediaPlayerProxyAndroid::PlaybackCompleteCallback, proxy_)); | 529 &WebMediaPlayerProxyAndroid::PlaybackCompleteCallback, proxy_)); |
| 520 } | 530 } |
| 521 | 531 |
| 522 void WebMediaPlayerAndroid::PauseInternal() { | 532 void WebMediaPlayerAndroid::PauseInternal() { |
| 523 CHECK(prepared_); | 533 CHECK(prepared_); |
| 524 media_player_->Pause(); | 534 media_player_->Pause(); |
| 525 } | 535 } |
| 526 | 536 |
| 527 void WebMediaPlayerAndroid::SeekInternal(float seconds) { | 537 void WebMediaPlayerAndroid::SeekInternal(float seconds) { |
| 528 CHECK(prepared_); | 538 CHECK(prepared_); |
| 529 seeking_ = true; | 539 seeking_ = true; |
| 530 media_player_->SeekTo(ConvertSecondsToTimestamp(seconds), base::Bind( | 540 media_player_->SeekTo(ConvertSecondsToTimestamp(seconds), base::Bind( |
| 531 &WebMediaPlayerProxyAndroid::SeekCompleteCallback, proxy_)); | 541 &WebMediaPlayerProxyAndroid::SeekCompleteCallback, proxy_)); |
| 532 } | 542 } |
| 533 | 543 |
| 534 void WebMediaPlayerAndroid::CreateStreamTexture() { | |
| 535 DCHECK(!stream_id_); | |
| 536 DCHECK(!texture_id_); | |
| 537 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); | |
| 538 if (texture_id_) | |
| 539 video_frame_.reset(new WebVideoFrameImpl(VideoFrame::WrapNativeTexture( | |
| 540 texture_id_, | |
| 541 kGLTextureExternalOES, | |
| 542 texture_size_.width, | |
| 543 texture_size_.height, | |
| 544 base::TimeDelta(), | |
| 545 base::Bind(&WebMediaPlayerAndroid::DestroyStreamTexture, | |
| 546 base::Unretained(this))))); | |
| 547 } | |
| 548 | |
| 549 void WebMediaPlayerAndroid::DestroyStreamTexture() { | |
| 550 DCHECK(stream_id_); | |
| 551 DCHECK(texture_id_); | |
| 552 stream_texture_factory_->DestroyStreamTexture(texture_id_); | |
| 553 texture_id_ = 0; | |
| 554 stream_id_ = 0; | |
| 555 } | |
| 556 | |
| 557 void WebMediaPlayerAndroid::WillDestroyCurrentMessageLoop() { | 544 void WebMediaPlayerAndroid::WillDestroyCurrentMessageLoop() { |
| 558 manager_ = NULL; | 545 manager_ = NULL; |
| 559 main_loop_ = NULL; | 546 main_loop_ = NULL; |
| 560 } | 547 } |
| 561 | 548 |
| 562 WebVideoFrame* WebMediaPlayerAndroid::getCurrentFrame() { | 549 WebVideoFrame* WebMediaPlayerAndroid::getCurrentFrame() { |
| 563 if (!stream_texture_proxy_->IsInitialized() && stream_id_) { | 550 if (!stream_texture_proxy_->IsInitialized() && stream_id_) { |
| 564 stream_texture_proxy_->Initialize( | 551 stream_texture_proxy_->Initialize( |
| 565 stream_id_, video_frame_->width(), video_frame_->height()); | 552 stream_id_, video_frame_->width(), video_frame_->height()); |
| 566 } | 553 } |
| 567 | 554 |
| 568 return video_frame_.get(); | 555 return video_frame_.get(); |
| 569 } | 556 } |
| 570 | 557 |
| 571 void WebMediaPlayerAndroid::putCurrentFrame( | 558 void WebMediaPlayerAndroid::putCurrentFrame( |
| 572 WebVideoFrame* web_video_frame) { | 559 WebVideoFrame* web_video_frame) { |
| 573 } | 560 } |
| 574 | 561 |
| 575 // This gets called both on compositor and main thread. | 562 // This gets called both on compositor and main thread. |
| 576 void WebMediaPlayerAndroid::setStreamTextureClient( | 563 void WebMediaPlayerAndroid::setStreamTextureClient( |
| 577 WebKit::WebStreamTextureClient* client) { | 564 WebKit::WebStreamTextureClient* client) { |
| 578 if (stream_texture_proxy_.get()) | 565 if (stream_texture_proxy_.get()) |
| 579 stream_texture_proxy_->SetClient(client); | 566 stream_texture_proxy_->SetClient(client); |
| 580 } | 567 } |
| 581 | 568 |
| 582 } // namespace webkit_media | 569 } // namespace webkit_media |
| OLD | NEW |