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

Unified Diff: media/blink/webmediaplayer_impl.cc

Issue 1935873002: Implement disabling and enabling media tracks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@track-control2
Patch Set: Updated comments + dchecks in ffmpeg demux stream Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: media/blink/webmediaplayer_impl.cc
diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc
index 3b373485a2ae011fd57fcf8bdd8e060aa1357bb7..bd58e7772fee1e6a975be1eed41e81ac82bd1948 100644
--- a/media/blink/webmediaplayer_impl.cc
+++ b/media/blink/webmediaplayer_impl.cc
@@ -577,12 +577,70 @@ bool WebMediaPlayerImpl::hasAudio() const {
return pipeline_metadata_.has_audio;
}
+using RestartStreamPlaybackCB =
+ base::Callback<void(DemuxerStream*, base::TimeDelta)>;
+
+void OnEnabledAudioTracksChanged(
+ Demuxer* demuxer,
+ base::TimeDelta currentTime,
+ const blink::WebVector<blink::WebMediaPlayer::TrackId>& enabledTrackIds,
+ const RestartStreamPlaybackCB& restart_stream_playback_cb) {
+ DemuxerStream* audio_stream = demuxer->GetStream(DemuxerStream::AUDIO);
+ bool enabled = false;
+ for (const auto& trackId : enabledTrackIds) {
+ const DemuxerStream* s = demuxer->GetDemuxerStreamByTrackId(trackId);
+ CHECK(s);
+ CHECK_EQ(s, audio_stream);
+ enabled = true;
+ }
+
+ DVLOG(1) << __FUNCTION__ << (enabled ? " enabling" : " disabling")
+ << " audio_stream=" << audio_stream
+ << " currentTime=" << currentTime.InSecondsF();
+ bool was_disabled = !audio_stream->enabled();
+ audio_stream->set_enabled(enabled, currentTime);
+ if (enabled && was_disabled) {
+ restart_stream_playback_cb.Run(audio_stream, currentTime);
+ }
+}
+
void WebMediaPlayerImpl::enabledAudioTracksChanged(
const blink::WebVector<blink::WebMediaPlayer::TrackId>& enabledTrackIds) {
DCHECK(main_task_runner_->BelongsToCurrentThread());
CHECK(demuxer_.get());
- // TODO(servolk): Implement disabling/enabling audio streams.
+ media_task_runner_->PostTask(
chcunningham 2016/06/02 23:49:42 This is bit bouncy. Main Thread: JS sets enabl
servolk 2016/06/03 02:53:15 Yes, we could do what you suggested, but one signi
chcunningham 2016/06/03 20:54:59 Let me see how our discussion here shakes out htt
xhwang 2016/06/04 00:09:43 For the thread hopping chcunningham pointed out, w
servolk 2016/06/09 21:00:13 There is a lot of different points here, let me tr
+ FROM_HERE,
+ base::Bind(
+ &OnEnabledAudioTracksChanged, demuxer_.get(),
+ base::TimeDelta::FromSecondsD(currentTime()), enabledTrackIds,
+ BindToCurrentLoop(base::Bind(
+ &WebMediaPlayerImpl::RestartStreamPlayback, AsWeakPtr()))));
+}
+
+void OnSelectedVideoTrackChanged(
+ Demuxer* demuxer,
+ base::TimeDelta currentTime,
+ const std::vector<blink::WebMediaPlayer::TrackId>& selectedTrackIdVector,
+ const RestartStreamPlaybackCB& restart_stream_playback_cb) {
+ DemuxerStream* video_stream = demuxer->GetStream(DemuxerStream::VIDEO);
+ bool enabled = false;
+ if (!selectedTrackIdVector.empty()) {
+ const DemuxerStream* selectedVideoStream =
+ demuxer->GetDemuxerStreamByTrackId(selectedTrackIdVector[0]);
+ CHECK(selectedVideoStream);
+ CHECK_EQ(selectedVideoStream, video_stream);
+ enabled = true;
+ }
+
+ DVLOG(1) << __FUNCTION__ << (enabled ? " enabling" : " disabling")
+ << " video_stream=" << video_stream
+ << " currentTime=" << currentTime.InSecondsF();
+ bool was_disabled = !video_stream->enabled();
+ video_stream->set_enabled(enabled, currentTime);
+ if (enabled && was_disabled) {
+ restart_stream_playback_cb.Run(video_stream, currentTime);
+ }
}
void WebMediaPlayerImpl::selectedVideoTrackChanged(
@@ -590,7 +648,23 @@ void WebMediaPlayerImpl::selectedVideoTrackChanged(
DCHECK(main_task_runner_->BelongsToCurrentThread());
CHECK(demuxer_.get());
- // TODO(servolk): Implement disabling/enabling video stream.
+ std::vector<blink::WebMediaPlayer::TrackId> selectedTrackIdVector;
+ if (selectedTrackId) {
+ selectedTrackIdVector.push_back(*selectedTrackId);
+ }
+ media_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &OnSelectedVideoTrackChanged, demuxer_.get(),
+ base::TimeDelta::FromSecondsD(currentTime()), selectedTrackIdVector,
+ BindToCurrentLoop(base::Bind(
+ &WebMediaPlayerImpl::RestartStreamPlayback, AsWeakPtr()))));
+}
+
+void WebMediaPlayerImpl::RestartStreamPlayback(DemuxerStream* stream,
+ base::TimeDelta time) {
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
+ pipeline_.RestartStreamPlayback(stream, time);
}
blink::WebSize WebMediaPlayerImpl::naturalSize() const {

Powered by Google App Engine
This is Rietveld 408576698