diff options
author | perkj <perkj@chromium.org> | 2014-09-01 01:57:40 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-01 08:59:25 +0000 |
commit | 530c4af7cd8af97421b7aaa215ee893c1f6d6e14 (patch) | |
tree | 84a97adaf6ca2f6b124a6716e371ef5f09d5699b /content/renderer/media/media_stream_video_source.cc | |
parent | 7b4bf4d19b1412460c3512f1632a3cc86eb0fd8c (diff) | |
download | chromium_src-530c4af7cd8af97421b7aaa215ee893c1f6d6e14.zip chromium_src-530c4af7cd8af97421b7aaa215ee893c1f6d6e14.tar.gz chromium_src-530c4af7cd8af97421b7aaa215ee893c1f6d6e14.tar.bz2 |
Refactor MediaStreamTrack video onmute event.
This changes monitoring of video frames delivered to MediaStreamVideoSource to be started when the source is started and stopped when the source is stopped rather than depend on
that the source object is destroyed since destruction is dependent on when blink runs garbage collection.
It removes the unused MediaStreamVideoTrack::SetMuted and GetMuted.
It reduces the need for a thread hop between the io-thread and the render thread for each monitor intervall by only trigger the monitoring callback on if a change has occured.
It reduces the test time of media_stream_video_source_unittest.cc from more than 7s to around 200ms.
BUG= 404106
Review URL: https://codereview.chromium.org/509873002
Cr-Commit-Position: refs/heads/master@{#292853}
Diffstat (limited to 'content/renderer/media/media_stream_video_source.cc')
-rw-r--r-- | content/renderer/media/media_stream_video_source.cc | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/content/renderer/media/media_stream_video_source.cc b/content/renderer/media/media_stream_video_source.cc index eb6ac78..ba8bb54 100644 --- a/content/renderer/media/media_stream_video_source.cc +++ b/content/renderer/media/media_stream_video_source.cc @@ -15,7 +15,6 @@ #include "content/renderer/media/media_stream_constraints_util.h" #include "content/renderer/media/media_stream_video_track.h" #include "content/renderer/media/video_track_adapter.h" -#include "media/base/bind_to_current_loop.h" namespace content { @@ -358,7 +357,6 @@ bool MediaStreamVideoSource::IsConstraintSupported(const std::string& name) { MediaStreamVideoSource::MediaStreamVideoSource() : state_(NEW), - muted_state_(false), track_adapter_(new VideoTrackAdapter( ChildProcess::current()->io_message_loop_proxy())), weak_factory_(this) { @@ -460,6 +458,7 @@ void MediaStreamVideoSource::DoStopSource() { DVLOG(3) << "DoStopSource()"; if (state_ == ENDED) return; + track_adapter_->StopFrameMonitoring(); StopSourceImpl(); state_ = ENDED; SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); @@ -535,6 +534,12 @@ void MediaStreamVideoSource::OnStartDone(MediaStreamRequestResult result) { DCHECK_EQ(STARTING, state_); state_ = STARTED; SetReadyState(blink::WebMediaStreamSource::ReadyStateLive); + + track_adapter_->StartFrameMonitoring( + current_format_.frame_rate, + base::Bind(&MediaStreamVideoSource::SetMutedState, + weak_factory_.GetWeakPtr())); + } else { StopSource(); } @@ -577,15 +582,10 @@ void MediaStreamVideoSource::FinalizeAddTrack() { GetConstraintValueAsDouble(it->constraints, kMaxFrameRate, &max_frame_rate); - VideoTrackAdapter::OnMutedCallback on_mute_callback = - media::BindToCurrentLoop(base::Bind( - &MediaStreamVideoSource::SetMutedState, - weak_factory_.GetWeakPtr())); track_adapter_->AddTrack(it->track, it->frame_callback, max_width, max_height, min_aspect_ratio, max_aspect_ratio, - max_frame_rate, current_format_.frame_rate, - on_mute_callback); + max_frame_rate); } DVLOG(3) << "FinalizeAddTrack() result " << result; @@ -611,18 +611,10 @@ void MediaStreamVideoSource::SetReadyState( void MediaStreamVideoSource::SetMutedState(bool muted_state) { DVLOG(3) << "MediaStreamVideoSource::SetMutedState state=" << muted_state; DCHECK(CalledOnValidThread()); - if (muted_state != muted_state_) { - muted_state_ = muted_state; - if (!owner().isNull()) { - owner().setReadyState(muted_state_ + if (!owner().isNull()) { + owner().setReadyState(muted_state ? blink::WebMediaStreamSource::ReadyStateMuted : blink::WebMediaStreamSource::ReadyStateLive); - } - } - // WebMediaStreamSource doesn't have a muted state, the tracks do. - for (std::vector<MediaStreamVideoTrack*>::iterator it = tracks_.begin(); - it != tracks_.end(); ++it) { - (*it)->SetMutedState(muted_state); } } |