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

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

Issue 10533049: Adding the logic for releasing decoder resources in WebMediaPlayerManagerAndroid (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move the logic for checking whether a WMPA is active into WMPA 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 #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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 WebMediaPlayerAndroid::WebMediaPlayerAndroid( 56 WebMediaPlayerAndroid::WebMediaPlayerAndroid(
57 WebKit::WebFrame* frame, 57 WebKit::WebFrame* frame,
58 WebMediaPlayerClient* client, 58 WebMediaPlayerClient* client,
59 WebKit::WebCookieJar* cookie_jar, 59 WebKit::WebCookieJar* cookie_jar,
60 webkit_media::WebMediaPlayerManagerAndroid* manager, 60 webkit_media::WebMediaPlayerManagerAndroid* manager,
61 webkit_media::StreamTextureFactory* factory) 61 webkit_media::StreamTextureFactory* factory)
62 : frame_(frame), 62 : frame_(frame),
63 client_(client), 63 client_(client),
64 buffered_(1u), 64 buffered_(1u),
65 video_frame_(new WebVideoFrameImpl(VideoFrame::CreateEmptyFrame())), 65 video_frame_(new WebVideoFrameImpl(VideoFrame::CreateEmptyFrame())),
66 proxy_(new WebMediaPlayerProxyAndroid(base::MessageLoopProxy::current(), 66 main_loop_(MessageLoop::current()),
67 proxy_(new WebMediaPlayerProxyAndroid(main_loop_->message_loop_proxy(),
67 AsWeakPtr())), 68 AsWeakPtr())),
68 prepared_(false), 69 prepared_(false),
69 duration_(0), 70 duration_(0),
70 pending_seek_(0), 71 pending_seek_(0),
71 seeking_(false), 72 seeking_(false),
72 playback_completed_(false), 73 playback_completed_(false),
73 buffered_bytes_(0), 74 buffered_bytes_(0),
74 did_loading_progress_(false), 75 did_loading_progress_(false),
75 cookie_jar_(cookie_jar), 76 cookie_jar_(cookie_jar),
76 manager_(manager), 77 manager_(manager),
77 pending_play_event_(false), 78 pending_play_event_(false),
78 network_state_(WebMediaPlayer::NetworkStateEmpty), 79 network_state_(WebMediaPlayer::NetworkStateEmpty),
79 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), 80 ready_state_(WebMediaPlayer::ReadyStateHaveNothing),
80 texture_id_(0), 81 texture_id_(0),
81 stream_id_(0), 82 stream_id_(0),
82 needs_establish_peer_(true), 83 needs_establish_peer_(true),
83 stream_texture_factory_(factory) { 84 stream_texture_factory_(factory) {
84 player_id_ = manager_->RegisterMediaPlayer(this); 85 main_loop_->AddDestructionObserver(this);
86 if (manager_)
87 player_id_ = manager_->RegisterMediaPlayer(this);
85 if (stream_texture_factory_.get()) 88 if (stream_texture_factory_.get())
86 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); 89 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy());
87 } 90 }
88 91
89 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { 92 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() {
90 if (media_player_.get()) { 93 if (media_player_.get()) {
91 media_player_->Stop(); 94 media_player_->Stop();
scherkus (not reviewing) 2012/06/07 21:44:34 how does Stop() differ from deleting the media_pla
qinmin 2012/06/08 17:09:06 After stop(), the player needs to call setDataSour
92 } 95 }
93 96
94 manager_->UnregisterMediaPlayer(player_id_); 97 if (manager_)
98 manager_->UnregisterMediaPlayer(player_id_);
99
100 if (main_loop_)
101 main_loop_->RemoveDestructionObserver(this);
95 } 102 }
96 103
97 void WebMediaPlayerAndroid::InitIncognito(bool incognito_mode) { 104 void WebMediaPlayerAndroid::InitIncognito(bool incognito_mode) {
98 incognito_mode_ = incognito_mode; 105 incognito_mode_ = incognito_mode;
99 } 106 }
100 107
101 void WebMediaPlayerAndroid::load(const WebURL& url) { 108 void WebMediaPlayerAndroid::load(const WebURL& url) {
102 url_ = url; 109 url_ = url;
103 110
104 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); 111 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading);
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 // Save the current media player status. 473 // Save the current media player status.
467 pending_seek_ = currentTime(); 474 pending_seek_ = currentTime();
468 duration_ = duration(); 475 duration_ = duration();
469 476
470 media_player_.reset(); 477 media_player_.reset();
471 needs_establish_peer_ = true; 478 needs_establish_peer_ = true;
472 } 479 }
473 prepared_ = false; 480 prepared_ = false;
474 } 481 }
475 482
483 bool WebMediaPlayerAndroid::IsInitialized() const {
484 return (media_player_ != NULL);
485 }
486
476 void WebMediaPlayerAndroid::InitializeMediaPlayer() { 487 void WebMediaPlayerAndroid::InitializeMediaPlayer() {
477 CHECK(!media_player_.get()); 488 CHECK(!media_player_.get());
478 prepared_ = false; 489 prepared_ = false;
479 media_player_.reset(new MediaPlayerBridge()); 490 media_player_.reset(new MediaPlayerBridge());
480 media_player_->SetStayAwakeWhilePlaying(); 491 media_player_->SetStayAwakeWhilePlaying();
481 492
482 std::string cookies; 493 std::string cookies;
483 if (cookie_jar_ != NULL) { 494 if (cookie_jar_ != NULL) {
484 WebURL first_party_url(frame_->document().firstPartyForCookies()); 495 WebURL first_party_url(frame_->document().firstPartyForCookies());
485 cookies = UTF16ToUTF8(cookie_jar_->cookies(url_, first_party_url)); 496 cookies = UTF16ToUTF8(cookie_jar_->cookies(url_, first_party_url));
486 } 497 }
487 media_player_->SetDataSource(url_.spec(), cookies, incognito_mode_); 498 media_player_->SetDataSource(url_.spec(), cookies, incognito_mode_);
488 499
500 if (manager_)
501 manager_->RequestMediaResources(player_id_);
502
489 media_player_->Prepare( 503 media_player_->Prepare(
490 base::Bind(&WebMediaPlayerProxyAndroid::MediaInfoCallback, proxy_), 504 base::Bind(&WebMediaPlayerProxyAndroid::MediaInfoCallback, proxy_),
491 base::Bind(&WebMediaPlayerProxyAndroid::MediaErrorCallback, proxy_), 505 base::Bind(&WebMediaPlayerProxyAndroid::MediaErrorCallback, proxy_),
492 base::Bind(&WebMediaPlayerProxyAndroid::VideoSizeChangedCallback, proxy_), 506 base::Bind(&WebMediaPlayerProxyAndroid::VideoSizeChangedCallback, proxy_),
493 base::Bind(&WebMediaPlayerProxyAndroid::BufferingUpdateCallback, proxy_), 507 base::Bind(&WebMediaPlayerProxyAndroid::BufferingUpdateCallback, proxy_),
494 base::Bind(&WebMediaPlayerProxyAndroid::MediaPreparedCallback, proxy_)); 508 base::Bind(&WebMediaPlayerProxyAndroid::MediaPreparedCallback, proxy_));
495 } 509 }
496 510
497 void WebMediaPlayerAndroid::PlayInternal() { 511 void WebMediaPlayerAndroid::PlayInternal() {
498 CHECK(prepared_); 512 CHECK(prepared_);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } 555 }
542 556
543 void WebMediaPlayerAndroid::DestroyStreamTexture() { 557 void WebMediaPlayerAndroid::DestroyStreamTexture() {
544 DCHECK(stream_id_); 558 DCHECK(stream_id_);
545 DCHECK(texture_id_); 559 DCHECK(texture_id_);
546 stream_texture_factory_->DestroyStreamTexture(texture_id_); 560 stream_texture_factory_->DestroyStreamTexture(texture_id_);
547 texture_id_ = 0; 561 texture_id_ = 0;
548 stream_id_ = 0; 562 stream_id_ = 0;
549 } 563 }
550 564
565 void WebMediaPlayerAndroid::WillDestroyCurrentMessageLoop() {
scherkus (not reviewing) 2012/06/07 21:44:34 typically when the loop is going away the process
qinmin 2012/06/08 17:09:06 I haven't see that happening myself, but i saw tha
566 manager_ = NULL;
567 main_loop_ = NULL;
568 }
569
551 WebVideoFrame* WebMediaPlayerAndroid::getCurrentFrame() { 570 WebVideoFrame* WebMediaPlayerAndroid::getCurrentFrame() {
552 if (!stream_texture_proxy_->IsInitialized() && stream_id_) { 571 if (!stream_texture_proxy_->IsInitialized() && stream_id_) {
553 stream_texture_proxy_->Initialize( 572 stream_texture_proxy_->Initialize(
554 stream_id_, video_frame_->width(), video_frame_->height()); 573 stream_id_, video_frame_->width(), video_frame_->height());
555 } 574 }
556 575
557 return video_frame_.get(); 576 return video_frame_.get();
558 } 577 }
559 578
560 void WebMediaPlayerAndroid::putCurrentFrame( 579 void WebMediaPlayerAndroid::putCurrentFrame(
561 WebVideoFrame* web_video_frame) { 580 WebVideoFrame* web_video_frame) {
562 } 581 }
563 582
564 // This gets called both on compositor and main thread. 583 // This gets called both on compositor and main thread.
565 void WebMediaPlayerAndroid::setStreamTextureClient( 584 void WebMediaPlayerAndroid::setStreamTextureClient(
566 WebKit::WebStreamTextureClient* client) { 585 WebKit::WebStreamTextureClient* client) {
567 if (stream_texture_proxy_.get()) 586 if (stream_texture_proxy_.get())
568 stream_texture_proxy_->SetClient(client); 587 stream_texture_proxy_->SetClient(client);
569 } 588 }
570 589
571 } // namespace webkit_media 590 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698