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

Side by Side Diff: media/base/pipeline_impl.cc

Issue 2718483003: Use base::Optional for selected video track. (Closed)
Patch Set: rebase Created 3 years, 10 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
« no previous file with comments | « media/base/pipeline_impl.h ('k') | media/blink/webmediaplayer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/base/pipeline_impl.h" 5 #include "media/base/pipeline_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 void Suspend(); 60 void Suspend();
61 void Resume(std::unique_ptr<Renderer> renderer, base::TimeDelta time); 61 void Resume(std::unique_ptr<Renderer> renderer, base::TimeDelta time);
62 void SetPlaybackRate(double playback_rate); 62 void SetPlaybackRate(double playback_rate);
63 void SetVolume(float volume); 63 void SetVolume(float volume);
64 base::TimeDelta GetMediaTime() const; 64 base::TimeDelta GetMediaTime() const;
65 Ranges<base::TimeDelta> GetBufferedTimeRanges() const; 65 Ranges<base::TimeDelta> GetBufferedTimeRanges() const;
66 bool DidLoadingProgress(); 66 bool DidLoadingProgress();
67 PipelineStatistics GetStatistics() const; 67 PipelineStatistics GetStatistics() const;
68 void SetCdm(CdmContext* cdm_context, const CdmAttachedCB& cdm_attached_cb); 68 void SetCdm(CdmContext* cdm_context, const CdmAttachedCB& cdm_attached_cb);
69 69
70 // |enabledTrackIds| contains track ids of enabled audio tracks. 70 // |enabled_track_ids| contains track ids of enabled audio tracks.
71 void OnEnabledAudioTracksChanged( 71 void OnEnabledAudioTracksChanged(
72 const std::vector<MediaTrack::Id>& enabledTrackIds); 72 const std::vector<MediaTrack::Id>& enabled_track_ids);
73 73
74 // |trackId| either empty, which means no video track is selected, or contain 74 // |selected_track_id| is either empty, which means no video track is
75 // one element - the selected video track id. 75 // selected, or contains the selected video track id.
76 void OnSelectedVideoTrackChanged( 76 void OnSelectedVideoTrackChanged(
77 const std::vector<MediaTrack::Id>& selectedTrackId); 77 base::Optional<MediaTrack::Id> selected_track_id);
78 78
79 private: 79 private:
80 // Contains state shared between main and media thread. 80 // Contains state shared between main and media thread.
81 // Main thread can only read. Media thread can both - read and write. 81 // Main thread can only read. Media thread can both - read and write.
82 // So it is not necessary to lock when reading from the media thread. 82 // So it is not necessary to lock when reading from the media thread.
83 // This struct should only contain state that is not immediately needed by 83 // This struct should only contain state that is not immediately needed by
84 // PipelineClient and can be cached on the media thread until queried. 84 // PipelineClient and can be cached on the media thread until queried.
85 // Alternatively we could cache it on the main thread by posting the 85 // Alternatively we could cache it on the main thread by posting the
86 // notification to the main thread. But some of the state change notifications 86 // notification to the main thread. But some of the state change notifications
87 // (OnStatisticsUpdate and OnBufferedTimeRangesChanged) arrive much more 87 // (OnStatisticsUpdate and OnBufferedTimeRangesChanged) arrive much more
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 553
554 if (state_ != kPlaying) 554 if (state_ != kPlaying)
555 return; 555 return;
556 556
557 DCHECK(!renderer_ended_); 557 DCHECK(!renderer_ended_);
558 renderer_ended_ = true; 558 renderer_ended_ = true;
559 CheckPlaybackEnded(); 559 CheckPlaybackEnded();
560 } 560 }
561 561
562 void PipelineImpl::OnEnabledAudioTracksChanged( 562 void PipelineImpl::OnEnabledAudioTracksChanged(
563 const std::vector<MediaTrack::Id>& enabledTrackIds) { 563 const std::vector<MediaTrack::Id>& enabled_track_ids) {
564 DCHECK(thread_checker_.CalledOnValidThread()); 564 DCHECK(thread_checker_.CalledOnValidThread());
565 media_task_runner_->PostTask( 565 media_task_runner_->PostTask(
566 FROM_HERE, 566 FROM_HERE,
567 base::Bind(&RendererWrapper::OnEnabledAudioTracksChanged, 567 base::Bind(&RendererWrapper::OnEnabledAudioTracksChanged,
568 base::Unretained(renderer_wrapper_.get()), enabledTrackIds)); 568 base::Unretained(renderer_wrapper_.get()), enabled_track_ids));
569 } 569 }
570 570
571 void PipelineImpl::OnSelectedVideoTrackChanged( 571 void PipelineImpl::OnSelectedVideoTrackChanged(
572 const std::vector<MediaTrack::Id>& selectedTrackId) { 572 base::Optional<MediaTrack::Id> selected_track_id) {
573 DCHECK(thread_checker_.CalledOnValidThread()); 573 DCHECK(thread_checker_.CalledOnValidThread());
574 media_task_runner_->PostTask( 574 media_task_runner_->PostTask(
575 FROM_HERE, 575 FROM_HERE,
576 base::Bind(&RendererWrapper::OnSelectedVideoTrackChanged, 576 base::Bind(&RendererWrapper::OnSelectedVideoTrackChanged,
577 base::Unretained(renderer_wrapper_.get()), selectedTrackId)); 577 base::Unretained(renderer_wrapper_.get()), selected_track_id));
578 } 578 }
579 579
580 void PipelineImpl::RendererWrapper::OnEnabledAudioTracksChanged( 580 void PipelineImpl::RendererWrapper::OnEnabledAudioTracksChanged(
581 const std::vector<MediaTrack::Id>& enabledTrackIds) { 581 const std::vector<MediaTrack::Id>& enabled_track_ids) {
582 DCHECK(media_task_runner_->BelongsToCurrentThread()); 582 DCHECK(media_task_runner_->BelongsToCurrentThread());
583 583
584 // If the pipeline has been created, but not started yet, we may still receive 584 // If the pipeline has been created, but not started yet, we may still receive
585 // track notifications from blink level (e.g. when video track gets deselected 585 // track notifications from blink level (e.g. when video track gets deselected
586 // due to player/pipeline belonging to a background tab). We can safely ignore 586 // due to player/pipeline belonging to a background tab). We can safely ignore
587 // these, since WebMediaPlayerImpl will ensure that demuxer stream / track 587 // these, since WebMediaPlayerImpl will ensure that demuxer stream / track
588 // status is in sync with blink after pipeline is started. 588 // status is in sync with blink after pipeline is started.
589 if (state_ == kCreated) { 589 if (state_ == kCreated) {
590 DCHECK(!demuxer_); 590 DCHECK(!demuxer_);
591 return; 591 return;
592 } 592 }
593 593
594 // Track status notifications might be delivered asynchronously. If we receive 594 // Track status notifications might be delivered asynchronously. If we receive
595 // a notification when pipeline is stopped/shut down, it's safe to ignore it. 595 // a notification when pipeline is stopped/shut down, it's safe to ignore it.
596 if (state_ == kStopping || state_ == kStopped) { 596 if (state_ == kStopping || state_ == kStopped) {
597 return; 597 return;
598 } 598 }
599 599
600 DCHECK(demuxer_); 600 DCHECK(demuxer_);
601 DCHECK(shared_state_.renderer || (state_ != kPlaying)); 601 DCHECK(shared_state_.renderer || (state_ != kPlaying));
602 602
603 base::TimeDelta currTime = (state_ == kPlaying) 603 base::TimeDelta curr_time = (state_ == kPlaying)
604 ? shared_state_.renderer->GetMediaTime() 604 ? shared_state_.renderer->GetMediaTime()
605 : demuxer_->GetStartTime(); 605 : demuxer_->GetStartTime();
606 demuxer_->OnEnabledAudioTracksChanged(enabledTrackIds, currTime); 606 demuxer_->OnEnabledAudioTracksChanged(enabled_track_ids, curr_time);
607 } 607 }
608 608
609 void PipelineImpl::RendererWrapper::OnSelectedVideoTrackChanged( 609 void PipelineImpl::RendererWrapper::OnSelectedVideoTrackChanged(
610 const std::vector<MediaTrack::Id>& selectedTrackId) { 610 base::Optional<MediaTrack::Id> selected_track_id) {
611 DCHECK(media_task_runner_->BelongsToCurrentThread()); 611 DCHECK(media_task_runner_->BelongsToCurrentThread());
612 612
613 // If the pipeline has been created, but not started yet, we may still receive 613 // If the pipeline has been created, but not started yet, we may still receive
614 // track notifications from blink level (e.g. when video track gets deselected 614 // track notifications from blink level (e.g. when video track gets deselected
615 // due to player/pipeline belonging to a background tab). We can safely ignore 615 // due to player/pipeline belonging to a background tab). We can safely ignore
616 // these, since WebMediaPlayerImpl will ensure that demuxer stream / track 616 // these, since WebMediaPlayerImpl will ensure that demuxer stream / track
617 // status is in sync with blink after pipeline is started. 617 // status is in sync with blink after pipeline is started.
618 if (state_ == kCreated) { 618 if (state_ == kCreated) {
619 DCHECK(!demuxer_); 619 DCHECK(!demuxer_);
620 return; 620 return;
621 } 621 }
622 622
623 // Track status notifications might be delivered asynchronously. If we receive 623 // Track status notifications might be delivered asynchronously. If we receive
624 // a notification when pipeline is stopped/shut down, it's safe to ignore it. 624 // a notification when pipeline is stopped/shut down, it's safe to ignore it.
625 if (state_ == kStopping || state_ == kStopped) { 625 if (state_ == kStopping || state_ == kStopped) {
626 return; 626 return;
627 } 627 }
628 628
629 DCHECK(demuxer_); 629 DCHECK(demuxer_);
630 DCHECK(shared_state_.renderer || (state_ != kPlaying)); 630 DCHECK(shared_state_.renderer || (state_ != kPlaying));
631 631
632 base::TimeDelta currTime = (state_ == kPlaying) 632 base::TimeDelta curr_time = (state_ == kPlaying)
633 ? shared_state_.renderer->GetMediaTime() 633 ? shared_state_.renderer->GetMediaTime()
634 : demuxer_->GetStartTime(); 634 : demuxer_->GetStartTime();
635 demuxer_->OnSelectedVideoTrackChanged(selectedTrackId, currTime); 635 demuxer_->OnSelectedVideoTrackChanged(selected_track_id, curr_time);
636 } 636 }
637 637
638 void PipelineImpl::RendererWrapper::OnStatisticsUpdate( 638 void PipelineImpl::RendererWrapper::OnStatisticsUpdate(
639 const PipelineStatistics& stats) { 639 const PipelineStatistics& stats) {
640 DVLOG(3) << __func__; 640 DVLOG(3) << __func__;
641 DCHECK(media_task_runner_->BelongsToCurrentThread()); 641 DCHECK(media_task_runner_->BelongsToCurrentThread());
642 642
643 base::AutoLock auto_lock(shared_state_lock_); 643 base::AutoLock auto_lock(shared_state_lock_);
644 shared_state_.statistics.audio_bytes_decoded += stats.audio_bytes_decoded; 644 shared_state_.statistics.audio_bytes_decoded += stats.audio_bytes_decoded;
645 shared_state_.statistics.video_bytes_decoded += stats.video_bytes_decoded; 645 shared_state_.statistics.video_bytes_decoded += stats.video_bytes_decoded;
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 void PipelineImpl::OnSuspendDone() { 1357 void PipelineImpl::OnSuspendDone() {
1358 DVLOG(3) << __func__; 1358 DVLOG(3) << __func__;
1359 DCHECK(thread_checker_.CalledOnValidThread()); 1359 DCHECK(thread_checker_.CalledOnValidThread());
1360 DCHECK(IsRunning()); 1360 DCHECK(IsRunning());
1361 1361
1362 DCHECK(!suspend_cb_.is_null()); 1362 DCHECK(!suspend_cb_.is_null());
1363 base::ResetAndReturn(&suspend_cb_).Run(PIPELINE_OK); 1363 base::ResetAndReturn(&suspend_cb_).Run(PIPELINE_OK);
1364 } 1364 }
1365 1365
1366 } // namespace media 1366 } // namespace media
OLDNEW
« no previous file with comments | « media/base/pipeline_impl.h ('k') | media/blink/webmediaplayer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698