Commit df5883f0 authored by qinmin@chromium.org's avatar qinmin@chromium.org

Fix a renderer crash when media elements get deleted

When media elements got deleted, stream_texture_factory_ will get deleted before video_frame_.
This causes the callback function to execute with a null pointer.
Move the DestroyStreamTexture call in to WMPA dtor.

BUG=138827

Review URL: https://chromiumcodereview.appspot.com/10828079

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149379 0039d316-1c4b-4281-b951-d872f2087c98
parent 1f2d75f4
......@@ -84,14 +84,19 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid(
main_loop_->AddDestructionObserver(this);
if (manager_)
player_id_ = manager_->RegisterMediaPlayer(this);
if (stream_texture_factory_.get())
if (stream_texture_factory_.get()) {
stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy());
stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_);
}
}
WebMediaPlayerAndroid::~WebMediaPlayerAndroid() {
if (manager_)
manager_->UnregisterMediaPlayer(player_id_);
if (stream_id_)
stream_texture_factory_->DestroyStreamTexture(texture_id_);
if (main_loop_)
main_loop_->RemoveDestructionObserver(this);
}
......@@ -441,8 +446,16 @@ void WebMediaPlayerAndroid::OnMediaInfo(int info_type) {
}
void WebMediaPlayerAndroid::OnVideoSizeChanged(int width, int height) {
if (natural_size_.width == width && natural_size_.height == height)
return;
natural_size_.width = width;
natural_size_.height = height;
if (texture_id_) {
video_frame_.reset(new WebVideoFrameImpl(VideoFrame::WrapNativeTexture(
texture_id_, kGLTextureExternalOES, width, height, base::TimeDelta(),
base::Closure())));
}
}
void WebMediaPlayerAndroid::UpdateNetworkState(
......@@ -505,9 +518,6 @@ void WebMediaPlayerAndroid::PlayInternal() {
CHECK(prepared_);
if (hasVideo() && stream_texture_factory_.get()) {
if (!stream_id_)
CreateStreamTexture();
if (needs_establish_peer_) {
stream_texture_factory_->EstablishPeer(stream_id_, player_id_);
needs_establish_peer_ = false;
......@@ -531,29 +541,6 @@ void WebMediaPlayerAndroid::SeekInternal(float seconds) {
&WebMediaPlayerProxyAndroid::SeekCompleteCallback, proxy_));
}
void WebMediaPlayerAndroid::CreateStreamTexture() {
DCHECK(!stream_id_);
DCHECK(!texture_id_);
stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_);
if (texture_id_)
video_frame_.reset(new WebVideoFrameImpl(VideoFrame::WrapNativeTexture(
texture_id_,
kGLTextureExternalOES,
texture_size_.width,
texture_size_.height,
base::TimeDelta(),
base::Bind(&WebMediaPlayerAndroid::DestroyStreamTexture,
base::Unretained(this)))));
}
void WebMediaPlayerAndroid::DestroyStreamTexture() {
DCHECK(stream_id_);
DCHECK(texture_id_);
stream_texture_factory_->DestroyStreamTexture(texture_id_);
texture_id_ = 0;
stream_id_ = 0;
}
void WebMediaPlayerAndroid::WillDestroyCurrentMessageLoop() {
manager_ = NULL;
main_loop_ = NULL;
......
......@@ -152,10 +152,6 @@ class WebMediaPlayerAndroid :
void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state);
void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state);
// Methods for creation and deletion of stream texture.
void CreateStreamTexture();
void DestroyStreamTexture();
// whether the current process is incognito mode
static bool incognito_mode_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment