diff options
| author | ronghuawu@chromium.org <ronghuawu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-21 21:10:37 +0000 |
|---|---|---|
| committer | ronghuawu@chromium.org <ronghuawu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-21 21:10:37 +0000 |
| commit | 012eabcaaef074ee90fefd434c3c972ac45cfbb0 (patch) | |
| tree | d64ea1c107fbced57635ec2f9cb3bffde9646527 | |
| parent | 7ebeb4bd3e5acb8e641956f5cf9509822441b142 (diff) | |
| download | chromium_src-012eabcaaef074ee90fefd434c3c972ac45cfbb0.zip chromium_src-012eabcaaef074ee90fefd434c3c972ac45cfbb0.tar.gz chromium_src-012eabcaaef074ee90fefd434c3c972ac45cfbb0.tar.bz2 | |
Fix a hang when the RtcVideoDecoder was given a MediaStream without video track, in which case there won't be any frame from RtcVideoDecoder. The hang happened when the page tried to destroy the WebMediaPlayer but the pipeline can't be stopped because it's still in the seeking state, which in turn becauses the RtcVideoDecoder never returned a frame.
This cl override the PrepareForShutdownHack, set the shutting_down flag and fullfill any pending read in it.
BUG=http://code.google.com/p/webrtc/issues/detail?id=508
TEST=
http://code.google.com/p/webrtc/issues/attachmentText?id=508&aid=5080004000&name=apprtc_loopback_audio_only.html&token=ghcCq45Vu7SH7HwcKsfjSo8ldqA%3A1340221943627
https://s3.amazonaws.com/webrtc-test/freeze_test.html
Review URL: https://chromiumcodereview.appspot.com/10581044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143452 0039d316-1c4b-4281-b951-d872f2087c98
| -rw-r--r-- | content/renderer/media/rtc_video_decoder.cc | 49 | ||||
| -rw-r--r-- | content/renderer/media/rtc_video_decoder.h | 4 |
2 files changed, 37 insertions, 16 deletions
diff --git a/content/renderer/media/rtc_video_decoder.cc b/content/renderer/media/rtc_video_decoder.cc index 7f9e095..6d5615a 100644 --- a/content/renderer/media/rtc_video_decoder.cc +++ b/content/renderer/media/rtc_video_decoder.cc @@ -31,7 +31,8 @@ RTCVideoDecoder::RTCVideoDecoder(MessageLoop* message_loop, visible_size_(640, 480), url_(url), state_(kUnInitialized), - got_first_frame_(false) { + got_first_frame_(false), + shutting_down_(false) { } void RTCVideoDecoder::Initialize(const scoped_refptr<DemuxerStream>& stream, @@ -63,6 +64,11 @@ void RTCVideoDecoder::Read(const ReadCB& read_cb) { base::AutoLock auto_lock(lock_); CHECK(read_cb_.is_null()); read_cb_ = read_cb; + + if (shutting_down_) { + message_loop_->PostTask(FROM_HERE, + base::Bind(&RTCVideoDecoder::CancelPendingRead, this)); + } } void RTCVideoDecoder::Reset(const base::Closure& closure) { @@ -74,21 +80,7 @@ void RTCVideoDecoder::Reset(const base::Closure& closure) { DCHECK_EQ(MessageLoop::current(), message_loop_); - ReadCB read_cb; - { - base::AutoLock auto_lock(lock_); - if (!read_cb_.is_null()) { - std::swap(read_cb, read_cb_); - } - } - - if (!read_cb.is_null()) { - scoped_refptr<media::VideoFrame> video_frame = - media::VideoFrame::CreateBlackFrame(visible_size_.width(), - visible_size_.height()); - read_cb.Run(kOk, video_frame); - } - + CancelPendingRead(); closure.Run(); } @@ -111,6 +103,18 @@ const gfx::Size& RTCVideoDecoder::natural_size() { return visible_size_; } +void RTCVideoDecoder::PrepareForShutdownHack() { + if (MessageLoop::current() != message_loop_) { + message_loop_->PostTask(FROM_HERE, + base::Bind(&RTCVideoDecoder::PrepareForShutdownHack, + this)); + return; + } + DCHECK_EQ(MessageLoop::current(), message_loop_); + shutting_down_ = true; + CancelPendingRead(); +} + bool RTCVideoDecoder::SetSize(int width, int height, int reserved) { visible_size_.SetSize(width, height); return true; @@ -173,4 +177,17 @@ bool RTCVideoDecoder::RenderFrame(const cricket::VideoFrame* frame) { return true; } +void RTCVideoDecoder::CancelPendingRead() { + DCHECK_EQ(MessageLoop::current(), message_loop_); + ReadCB read_cb; + { + base::AutoLock auto_lock(lock_); + std::swap(read_cb, read_cb_); + } + + if (!read_cb.is_null()) { + read_cb.Run(kOk, NULL); + } +} + RTCVideoDecoder::~RTCVideoDecoder() {} diff --git a/content/renderer/media/rtc_video_decoder.h b/content/renderer/media/rtc_video_decoder.h index 8317049..14813e0 100644 --- a/content/renderer/media/rtc_video_decoder.h +++ b/content/renderer/media/rtc_video_decoder.h @@ -36,6 +36,7 @@ class CONTENT_EXPORT RTCVideoDecoder virtual void Reset(const base::Closure& clusure) OVERRIDE; virtual void Stop(const base::Closure& clusure) OVERRIDE; virtual const gfx::Size& natural_size() OVERRIDE; + virtual void PrepareForShutdownHack() OVERRIDE; // cricket::VideoRenderer implementation virtual bool SetSize(int width, int height, int reserved) OVERRIDE; @@ -57,12 +58,15 @@ class CONTENT_EXPORT RTCVideoDecoder kStopped }; + void CancelPendingRead(); + MessageLoop* message_loop_; gfx::Size visible_size_; std::string url_; DecoderState state_; ReadCB read_cb_; bool got_first_frame_; + bool shutting_down_; base::TimeDelta last_frame_timestamp_; base::TimeDelta start_time_; |
