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

Side by Side 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, 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "media/blink/webmediaplayer_impl.h" 5 #include "media/blink/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 570
571 return pipeline_metadata_.has_video; 571 return pipeline_metadata_.has_video;
572 } 572 }
573 573
574 bool WebMediaPlayerImpl::hasAudio() const { 574 bool WebMediaPlayerImpl::hasAudio() const {
575 DCHECK(main_task_runner_->BelongsToCurrentThread()); 575 DCHECK(main_task_runner_->BelongsToCurrentThread());
576 576
577 return pipeline_metadata_.has_audio; 577 return pipeline_metadata_.has_audio;
578 } 578 }
579 579
580 using RestartStreamPlaybackCB =
581 base::Callback<void(DemuxerStream*, base::TimeDelta)>;
582
583 void OnEnabledAudioTracksChanged(
584 Demuxer* demuxer,
585 base::TimeDelta currentTime,
586 const blink::WebVector<blink::WebMediaPlayer::TrackId>& enabledTrackIds,
587 const RestartStreamPlaybackCB& restart_stream_playback_cb) {
588 DemuxerStream* audio_stream = demuxer->GetStream(DemuxerStream::AUDIO);
589 bool enabled = false;
590 for (const auto& trackId : enabledTrackIds) {
591 const DemuxerStream* s = demuxer->GetDemuxerStreamByTrackId(trackId);
592 CHECK(s);
593 CHECK_EQ(s, audio_stream);
594 enabled = true;
595 }
596
597 DVLOG(1) << __FUNCTION__ << (enabled ? " enabling" : " disabling")
598 << " audio_stream=" << audio_stream
599 << " currentTime=" << currentTime.InSecondsF();
600 bool was_disabled = !audio_stream->enabled();
601 audio_stream->set_enabled(enabled, currentTime);
602 if (enabled && was_disabled) {
603 restart_stream_playback_cb.Run(audio_stream, currentTime);
604 }
605 }
606
580 void WebMediaPlayerImpl::enabledAudioTracksChanged( 607 void WebMediaPlayerImpl::enabledAudioTracksChanged(
581 const blink::WebVector<blink::WebMediaPlayer::TrackId>& enabledTrackIds) { 608 const blink::WebVector<blink::WebMediaPlayer::TrackId>& enabledTrackIds) {
582 DCHECK(main_task_runner_->BelongsToCurrentThread()); 609 DCHECK(main_task_runner_->BelongsToCurrentThread());
583 CHECK(demuxer_.get()); 610 CHECK(demuxer_.get());
584 611
585 // TODO(servolk): Implement disabling/enabling audio streams. 612 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
613 FROM_HERE,
614 base::Bind(
615 &OnEnabledAudioTracksChanged, demuxer_.get(),
616 base::TimeDelta::FromSecondsD(currentTime()), enabledTrackIds,
617 BindToCurrentLoop(base::Bind(
618 &WebMediaPlayerImpl::RestartStreamPlayback, AsWeakPtr()))));
619 }
620
621 void OnSelectedVideoTrackChanged(
622 Demuxer* demuxer,
623 base::TimeDelta currentTime,
624 const std::vector<blink::WebMediaPlayer::TrackId>& selectedTrackIdVector,
625 const RestartStreamPlaybackCB& restart_stream_playback_cb) {
626 DemuxerStream* video_stream = demuxer->GetStream(DemuxerStream::VIDEO);
627 bool enabled = false;
628 if (!selectedTrackIdVector.empty()) {
629 const DemuxerStream* selectedVideoStream =
630 demuxer->GetDemuxerStreamByTrackId(selectedTrackIdVector[0]);
631 CHECK(selectedVideoStream);
632 CHECK_EQ(selectedVideoStream, video_stream);
633 enabled = true;
634 }
635
636 DVLOG(1) << __FUNCTION__ << (enabled ? " enabling" : " disabling")
637 << " video_stream=" << video_stream
638 << " currentTime=" << currentTime.InSecondsF();
639 bool was_disabled = !video_stream->enabled();
640 video_stream->set_enabled(enabled, currentTime);
641 if (enabled && was_disabled) {
642 restart_stream_playback_cb.Run(video_stream, currentTime);
643 }
586 } 644 }
587 645
588 void WebMediaPlayerImpl::selectedVideoTrackChanged( 646 void WebMediaPlayerImpl::selectedVideoTrackChanged(
589 blink::WebMediaPlayer::TrackId* selectedTrackId) { 647 blink::WebMediaPlayer::TrackId* selectedTrackId) {
590 DCHECK(main_task_runner_->BelongsToCurrentThread()); 648 DCHECK(main_task_runner_->BelongsToCurrentThread());
591 CHECK(demuxer_.get()); 649 CHECK(demuxer_.get());
592 650
593 // TODO(servolk): Implement disabling/enabling video stream. 651 std::vector<blink::WebMediaPlayer::TrackId> selectedTrackIdVector;
652 if (selectedTrackId) {
653 selectedTrackIdVector.push_back(*selectedTrackId);
654 }
655 media_task_runner_->PostTask(
656 FROM_HERE,
657 base::Bind(
658 &OnSelectedVideoTrackChanged, demuxer_.get(),
659 base::TimeDelta::FromSecondsD(currentTime()), selectedTrackIdVector,
660 BindToCurrentLoop(base::Bind(
661 &WebMediaPlayerImpl::RestartStreamPlayback, AsWeakPtr()))));
662 }
663
664 void WebMediaPlayerImpl::RestartStreamPlayback(DemuxerStream* stream,
665 base::TimeDelta time) {
666 DCHECK(main_task_runner_->BelongsToCurrentThread());
667 pipeline_.RestartStreamPlayback(stream, time);
594 } 668 }
595 669
596 blink::WebSize WebMediaPlayerImpl::naturalSize() const { 670 blink::WebSize WebMediaPlayerImpl::naturalSize() const {
597 DCHECK(main_task_runner_->BelongsToCurrentThread()); 671 DCHECK(main_task_runner_->BelongsToCurrentThread());
598 672
599 return blink::WebSize(pipeline_metadata_.natural_size); 673 return blink::WebSize(pipeline_metadata_.natural_size);
600 } 674 }
601 675
602 bool WebMediaPlayerImpl::paused() const { 676 bool WebMediaPlayerImpl::paused() const {
603 DCHECK(main_task_runner_->BelongsToCurrentThread()); 677 DCHECK(main_task_runner_->BelongsToCurrentThread());
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 << ", Video: " << stats.video_memory_usage << ", DataSource: " 1703 << ", Video: " << stats.video_memory_usage << ", DataSource: "
1630 << (data_source_ ? data_source_->GetMemoryUsage() : 0) 1704 << (data_source_ ? data_source_->GetMemoryUsage() : 0)
1631 << ", Demuxer: " << demuxer_memory_usage; 1705 << ", Demuxer: " << demuxer_memory_usage;
1632 1706
1633 const int64_t delta = current_memory_usage - last_reported_memory_usage_; 1707 const int64_t delta = current_memory_usage - last_reported_memory_usage_;
1634 last_reported_memory_usage_ = current_memory_usage; 1708 last_reported_memory_usage_ = current_memory_usage;
1635 adjust_allocated_memory_cb_.Run(delta); 1709 adjust_allocated_memory_cb_.Run(delta);
1636 } 1710 }
1637 1711
1638 } // namespace media 1712 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698