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

Side by Side Diff: media/blink/webmediaplayer_impl.cc

Issue 2689863002: Change ownership of PipelineImpl (Closed)
Patch Set: Proper 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/blink/webmediaplayer_impl.h ('k') | media/filters/pipeline_controller.h » ('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 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 return result; 138 return result;
139 } 139 }
140 140
141 gfx::Size GetRotatedVideoSize(VideoRotation rotation, gfx::Size natural_size) { 141 gfx::Size GetRotatedVideoSize(VideoRotation rotation, gfx::Size natural_size) {
142 if (rotation == VIDEO_ROTATION_90 || rotation == VIDEO_ROTATION_270) 142 if (rotation == VIDEO_ROTATION_90 || rotation == VIDEO_ROTATION_270)
143 return gfx::Size(natural_size.height(), natural_size.width()); 143 return gfx::Size(natural_size.height(), natural_size.width());
144 return natural_size; 144 return natural_size;
145 } 145 }
146 146
147 base::TimeDelta GetCurrentTimeInternal(WebMediaPlayerImpl* p_this) { 147 base::TimeDelta GetCurrentTimeInternal(WebMediaPlayerImpl* p_this) {
148 // We wrap currentTime() instead of using pipeline_.GetMediaTime() since there 148 // We wrap currentTime() instead of using pipeline_controller_.GetMediaTime()
149 // are a variety of cases in which that time is not accurate; e.g., while 149 // since there are a variety of cases in which that time is not accurate;
150 // remoting and during a pause or seek. 150 // e.g., while remoting and during a pause or seek.
151 return base::TimeDelta::FromSecondsD(p_this->currentTime()); 151 return base::TimeDelta::FromSecondsD(p_this->currentTime());
152 } 152 }
153 153
154 // How much time must have elapsed since loading last progressed before we 154 // How much time must have elapsed since loading last progressed before we
155 // assume that the decoder will have had time to complete preroll. 155 // assume that the decoder will have had time to complete preroll.
156 constexpr base::TimeDelta kPrerollAttemptTimeout = 156 constexpr base::TimeDelta kPrerollAttemptTimeout =
157 base::TimeDelta::FromSeconds(3); 157 base::TimeDelta::FromSeconds(3);
158 158
159 } // namespace 159 } // namespace
160 160
(...skipping 18 matching lines...) Expand all
179 delegate_has_audio_(false), 179 delegate_has_audio_(false),
180 network_state_(WebMediaPlayer::NetworkStateEmpty), 180 network_state_(WebMediaPlayer::NetworkStateEmpty),
181 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), 181 ready_state_(WebMediaPlayer::ReadyStateHaveNothing),
182 highest_ready_state_(WebMediaPlayer::ReadyStateHaveNothing), 182 highest_ready_state_(WebMediaPlayer::ReadyStateHaveNothing),
183 preload_(MultibufferDataSource::AUTO), 183 preload_(MultibufferDataSource::AUTO),
184 buffering_strategy_(MultibufferDataSource::BUFFERING_STRATEGY_NORMAL), 184 buffering_strategy_(MultibufferDataSource::BUFFERING_STRATEGY_NORMAL),
185 main_task_runner_(frame->loadingTaskRunner()), 185 main_task_runner_(frame->loadingTaskRunner()),
186 media_task_runner_(params.media_task_runner()), 186 media_task_runner_(params.media_task_runner()),
187 worker_task_runner_(params.worker_task_runner()), 187 worker_task_runner_(params.worker_task_runner()),
188 media_log_(params.media_log()), 188 media_log_(params.media_log()),
189 pipeline_(media_task_runner_, media_log_.get()),
190 pipeline_controller_( 189 pipeline_controller_(
191 &pipeline_, 190 base::MakeUnique<PipelineImpl>(media_task_runner_, media_log_.get()),
192 base::Bind(&WebMediaPlayerImpl::CreateRenderer, 191 base::Bind(&WebMediaPlayerImpl::CreateRenderer,
193 base::Unretained(this)), 192 base::Unretained(this)),
194 base::Bind(&WebMediaPlayerImpl::OnPipelineSeeked, AsWeakPtr()), 193 base::Bind(&WebMediaPlayerImpl::OnPipelineSeeked, AsWeakPtr()),
195 base::Bind(&WebMediaPlayerImpl::OnPipelineSuspended, AsWeakPtr()), 194 base::Bind(&WebMediaPlayerImpl::OnPipelineSuspended, AsWeakPtr()),
196 base::Bind(&WebMediaPlayerImpl::OnBeforePipelineResume, AsWeakPtr()), 195 base::Bind(&WebMediaPlayerImpl::OnBeforePipelineResume, AsWeakPtr()),
197 base::Bind(&WebMediaPlayerImpl::OnPipelineResumed, AsWeakPtr()), 196 base::Bind(&WebMediaPlayerImpl::OnPipelineResumed, AsWeakPtr()),
198 base::Bind(&WebMediaPlayerImpl::OnError, AsWeakPtr())), 197 base::Bind(&WebMediaPlayerImpl::OnError, AsWeakPtr())),
199 load_type_(LoadTypeURL), 198 load_type_(LoadTypeURL),
200 opaque_(false), 199 opaque_(false),
201 playback_rate_(0.0), 200 playback_rate_(0.0),
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 DCHECK(main_task_runner_->BelongsToCurrentThread()); 275 DCHECK(main_task_runner_->BelongsToCurrentThread());
277 276
278 suppress_destruction_errors_ = true; 277 suppress_destruction_errors_ = true;
279 278
280 delegate_->PlayerGone(delegate_id_); 279 delegate_->PlayerGone(delegate_id_);
281 delegate_->RemoveObserver(delegate_id_); 280 delegate_->RemoveObserver(delegate_id_);
282 281
283 // Finalize any watch time metrics before destroying the pipeline. 282 // Finalize any watch time metrics before destroying the pipeline.
284 watch_time_reporter_.reset(); 283 watch_time_reporter_.reset();
285 284
286 // Pipeline must be stopped before it is destroyed. 285 // The underlying Pipeline must be stopped before it is destroyed.
287 pipeline_.Stop(); 286 pipeline_controller_.Stop();
288 287
289 if (last_reported_memory_usage_) 288 if (last_reported_memory_usage_)
290 adjust_allocated_memory_cb_.Run(-last_reported_memory_usage_); 289 adjust_allocated_memory_cb_.Run(-last_reported_memory_usage_);
291 290
292 // Destruct compositor resources in the proper order. 291 // Destruct compositor resources in the proper order.
293 client_->setWebLayer(nullptr); 292 client_->setWebLayer(nullptr);
294 if (video_weblayer_) 293 if (video_weblayer_)
295 static_cast<cc::VideoLayer*>(video_weblayer_->layer())->StopUsingProvider(); 294 static_cast<cc::VideoLayer*>(video_weblayer_->layer())->StopUsingProvider();
296 compositor_task_runner_->DeleteSoon(FROM_HERE, compositor_); 295 compositor_task_runner_->DeleteSoon(FROM_HERE, compositor_);
297 296
298 media_log_->AddEvent( 297 media_log_->AddEvent(
299 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); 298 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_DESTROYED));
300 } 299 }
301 300
302 void WebMediaPlayerImpl::load(LoadType load_type, 301 void WebMediaPlayerImpl::load(LoadType load_type,
303 const blink::WebMediaPlayerSource& source, 302 const blink::WebMediaPlayerSource& source,
304 CORSMode cors_mode) { 303 CORSMode cors_mode) {
305 // Only URL or MSE blob URL is supported. 304 // Only URL or MSE blob URL is supported.
306 DCHECK(source.isURL()); 305 DCHECK(source.isURL());
307 blink::WebURL url = source.getAsURL(); 306 blink::WebURL url = source.getAsURL();
308 DVLOG(1) << __func__ << "(" << load_type << ", " << url << ", " << cors_mode 307 DVLOG(1) << __func__ << "(" << load_type << ", " << url << ", " << cors_mode
309 << ")"; 308 << ")";
310 if (!defer_load_cb_.is_null()) { 309 if (!defer_load_cb_.is_null()) {
311 defer_load_cb_.Run(base::Bind( 310 defer_load_cb_.Run(base::Bind(&WebMediaPlayerImpl::DoLoad, AsWeakPtr(),
312 &WebMediaPlayerImpl::DoLoad, AsWeakPtr(), load_type, url, cors_mode)); 311 load_type, url, cors_mode));
313 return; 312 return;
314 } 313 }
315 DoLoad(load_type, url, cors_mode); 314 DoLoad(load_type, url, cors_mode);
316 } 315 }
317 316
318 bool WebMediaPlayerImpl::supportsOverlayFullscreenVideo() { 317 bool WebMediaPlayerImpl::supportsOverlayFullscreenVideo() {
319 #if defined(OS_ANDROID) 318 #if defined(OS_ANDROID)
320 return true; 319 return true;
321 #else 320 #else
322 return false; 321 return false;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 425
427 #if defined(OS_ANDROID) // WMPI_CAST 426 #if defined(OS_ANDROID) // WMPI_CAST
428 if (isRemote()) { 427 if (isRemote()) {
429 cast_impl_.play(); 428 cast_impl_.play();
430 return; 429 return;
431 } 430 }
432 #endif 431 #endif
433 // TODO(sandersd): Do we want to reset the idle timer here? 432 // TODO(sandersd): Do we want to reset the idle timer here?
434 delegate_->SetIdle(delegate_id_, false); 433 delegate_->SetIdle(delegate_id_, false);
435 paused_ = false; 434 paused_ = false;
436 pipeline_.SetPlaybackRate(playback_rate_); 435 pipeline_controller_.SetPlaybackRate(playback_rate_);
437 background_pause_timer_.Stop(); 436 background_pause_timer_.Stop();
438 437
439 if (data_source_) 438 if (data_source_)
440 data_source_->MediaIsPlaying(); 439 data_source_->MediaIsPlaying();
441 440
442 if (observer_) 441 if (observer_)
443 observer_->OnPlaying(); 442 observer_->OnPlaying();
444 443
445 DCHECK(watch_time_reporter_); 444 DCHECK(watch_time_reporter_);
446 watch_time_reporter_->OnPlaying(); 445 watch_time_reporter_->OnPlaying();
(...skipping 17 matching lines...) Expand all
464 if (blink::WebUserGestureIndicator::isProcessingUserGesture()) 463 if (blink::WebUserGestureIndicator::isProcessingUserGesture())
465 video_locked_when_paused_when_hidden_ = true; 464 video_locked_when_paused_when_hidden_ = true;
466 465
467 #if defined(OS_ANDROID) // WMPI_CAST 466 #if defined(OS_ANDROID) // WMPI_CAST
468 if (isRemote()) { 467 if (isRemote()) {
469 cast_impl_.pause(); 468 cast_impl_.pause();
470 return; 469 return;
471 } 470 }
472 #endif 471 #endif
473 472
474 pipeline_.SetPlaybackRate(0.0); 473 pipeline_controller_.SetPlaybackRate(0.0);
475 474
476 // pause() may be called after playback has ended and the HTMLMediaElement 475 // pause() may be called after playback has ended and the HTMLMediaElement
477 // requires that currentTime() == duration() after ending. We want to ensure 476 // requires that currentTime() == duration() after ending. We want to ensure
478 // |paused_time_| matches currentTime() in this case or a future seek() may 477 // |paused_time_| matches currentTime() in this case or a future seek() may
479 // incorrectly discard what it thinks is a seek to the existing time. 478 // incorrectly discard what it thinks is a seek to the existing time.
480 paused_time_ = ended_ ? GetPipelineMediaDuration() : pipeline_.GetMediaTime(); 479 paused_time_ =
480 ended_ ? GetPipelineMediaDuration() : pipeline_controller_.GetMediaTime();
481 481
482 if (observer_) 482 if (observer_)
483 observer_->OnPaused(); 483 observer_->OnPaused();
484 484
485 DCHECK(watch_time_reporter_); 485 DCHECK(watch_time_reporter_);
486 watch_time_reporter_->OnPaused(); 486 watch_time_reporter_->OnPaused();
487 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE)); 487 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PAUSE));
488 488
489 UpdatePlayState(); 489 UpdatePlayState();
490 } 490 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 // Limit rates to reasonable values by clamping. 567 // Limit rates to reasonable values by clamping.
568 if (rate != 0.0) { 568 if (rate != 0.0) {
569 if (rate < kMinRate) 569 if (rate < kMinRate)
570 rate = kMinRate; 570 rate = kMinRate;
571 else if (rate > kMaxRate) 571 else if (rate > kMaxRate)
572 rate = kMaxRate; 572 rate = kMaxRate;
573 } 573 }
574 574
575 playback_rate_ = rate; 575 playback_rate_ = rate;
576 if (!paused_) { 576 if (!paused_) {
577 pipeline_.SetPlaybackRate(rate); 577 pipeline_controller_.SetPlaybackRate(rate);
578 if (data_source_) 578 if (data_source_)
579 data_source_->MediaPlaybackRateChanged(rate); 579 data_source_->MediaPlaybackRateChanged(rate);
580 } 580 }
581 } 581 }
582 582
583 void WebMediaPlayerImpl::setVolume(double volume) { 583 void WebMediaPlayerImpl::setVolume(double volume) {
584 DVLOG(1) << __func__ << "(" << volume << ")"; 584 DVLOG(1) << __func__ << "(" << volume << ")";
585 DCHECK(main_task_runner_->BelongsToCurrentThread()); 585 DCHECK(main_task_runner_->BelongsToCurrentThread());
586 volume_ = volume; 586 volume_ = volume;
587 pipeline_.SetVolume(volume_ * volume_multiplier_); 587 pipeline_controller_.SetVolume(volume_ * volume_multiplier_);
588 if (watch_time_reporter_) 588 if (watch_time_reporter_)
589 watch_time_reporter_->OnVolumeChange(volume); 589 watch_time_reporter_->OnVolumeChange(volume);
590 590
591 // The play state is updated because the player might have left the autoplay 591 // The play state is updated because the player might have left the autoplay
592 // muted state. 592 // muted state.
593 UpdatePlayState(); 593 UpdatePlayState();
594 } 594 }
595 595
596 void WebMediaPlayerImpl::setSinkId( 596 void WebMediaPlayerImpl::setSinkId(
597 const blink::WebString& sink_id, 597 const blink::WebString& sink_id,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 666
667 std::ostringstream logstr; 667 std::ostringstream logstr;
668 std::vector<MediaTrack::Id> enabledMediaTrackIds; 668 std::vector<MediaTrack::Id> enabledMediaTrackIds;
669 for (const auto& blinkTrackId : enabledTrackIds) { 669 for (const auto& blinkTrackId : enabledTrackIds) {
670 MediaTrack::Id track_id = blinkTrackId.utf8().data(); 670 MediaTrack::Id track_id = blinkTrackId.utf8().data();
671 logstr << track_id << " "; 671 logstr << track_id << " ";
672 enabledMediaTrackIds.push_back(track_id); 672 enabledMediaTrackIds.push_back(track_id);
673 } 673 }
674 MEDIA_LOG(INFO, media_log_) << "Enabled audio tracks: [" << logstr.str() 674 MEDIA_LOG(INFO, media_log_) << "Enabled audio tracks: [" << logstr.str()
675 << "]"; 675 << "]";
676 pipeline_.OnEnabledAudioTracksChanged(enabledMediaTrackIds); 676 pipeline_controller_.OnEnabledAudioTracksChanged(enabledMediaTrackIds);
677 } 677 }
678 678
679 void WebMediaPlayerImpl::selectedVideoTrackChanged( 679 void WebMediaPlayerImpl::selectedVideoTrackChanged(
680 blink::WebMediaPlayer::TrackId* selectedTrackId) { 680 blink::WebMediaPlayer::TrackId* selectedTrackId) {
681 DCHECK(main_task_runner_->BelongsToCurrentThread()); 681 DCHECK(main_task_runner_->BelongsToCurrentThread());
682 682
683 base::Optional<MediaTrack::Id> selected_video_track_id; 683 base::Optional<MediaTrack::Id> selected_video_track_id;
684 if (selectedTrackId && !video_track_disabled_) 684 if (selectedTrackId && !video_track_disabled_)
685 selected_video_track_id = MediaTrack::Id(selectedTrackId->utf8().data()); 685 selected_video_track_id = MediaTrack::Id(selectedTrackId->utf8().data());
686 MEDIA_LOG(INFO, media_log_) << "Selected video track: [" 686 MEDIA_LOG(INFO, media_log_) << "Selected video track: ["
687 << selected_video_track_id.value_or("") << "]"; 687 << selected_video_track_id.value_or("") << "]";
688 pipeline_.OnSelectedVideoTrackChanged(selected_video_track_id); 688 pipeline_controller_.OnSelectedVideoTrackChanged(selected_video_track_id);
689 } 689 }
690 690
691 blink::WebSize WebMediaPlayerImpl::naturalSize() const { 691 blink::WebSize WebMediaPlayerImpl::naturalSize() const {
692 DCHECK(main_task_runner_->BelongsToCurrentThread()); 692 DCHECK(main_task_runner_->BelongsToCurrentThread());
693 693
694 return blink::WebSize(pipeline_metadata_.natural_size); 694 return blink::WebSize(pipeline_metadata_.natural_size);
695 } 695 }
696 696
697 bool WebMediaPlayerImpl::paused() const { 697 bool WebMediaPlayerImpl::paused() const {
698 DCHECK(main_task_runner_->BelongsToCurrentThread()); 698 DCHECK(main_task_runner_->BelongsToCurrentThread());
699 699
700 #if defined(OS_ANDROID) // WMPI_CAST 700 #if defined(OS_ANDROID) // WMPI_CAST
701 if (isRemote()) 701 if (isRemote())
702 return cast_impl_.IsPaused(); 702 return cast_impl_.IsPaused();
703 #endif 703 #endif
704 704
705 return pipeline_.GetPlaybackRate() == 0.0f; 705 return pipeline_controller_.GetPlaybackRate() == 0.0f;
706 } 706 }
707 707
708 bool WebMediaPlayerImpl::seeking() const { 708 bool WebMediaPlayerImpl::seeking() const {
709 DCHECK(main_task_runner_->BelongsToCurrentThread()); 709 DCHECK(main_task_runner_->BelongsToCurrentThread());
710 710
711 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) 711 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing)
712 return false; 712 return false;
713 713
714 return seeking_; 714 return seeking_;
715 } 715 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 return seek_time_.InSecondsF(); 756 return seek_time_.InSecondsF();
757 757
758 #if defined(OS_ANDROID) // WMPI_CAST 758 #if defined(OS_ANDROID) // WMPI_CAST
759 if (isRemote()) 759 if (isRemote())
760 return cast_impl_.currentTime(); 760 return cast_impl_.currentTime();
761 #endif 761 #endif
762 762
763 if (paused_) 763 if (paused_)
764 return paused_time_.InSecondsF(); 764 return paused_time_.InSecondsF();
765 765
766 return pipeline_.GetMediaTime().InSecondsF(); 766 return pipeline_controller_.GetMediaTime().InSecondsF();
767 } 767 }
768 768
769 WebMediaPlayer::NetworkState WebMediaPlayerImpl::getNetworkState() const { 769 WebMediaPlayer::NetworkState WebMediaPlayerImpl::getNetworkState() const {
770 DCHECK(main_task_runner_->BelongsToCurrentThread()); 770 DCHECK(main_task_runner_->BelongsToCurrentThread());
771 return network_state_; 771 return network_state_;
772 } 772 }
773 773
774 WebMediaPlayer::ReadyState WebMediaPlayerImpl::getReadyState() const { 774 WebMediaPlayer::ReadyState WebMediaPlayerImpl::getReadyState() const {
775 DCHECK(main_task_runner_->BelongsToCurrentThread()); 775 DCHECK(main_task_runner_->BelongsToCurrentThread());
776 return ready_state_; 776 return ready_state_;
777 } 777 }
778 778
779 blink::WebString WebMediaPlayerImpl::getErrorMessage() { 779 blink::WebString WebMediaPlayerImpl::getErrorMessage() {
780 DCHECK(main_task_runner_->BelongsToCurrentThread()); 780 DCHECK(main_task_runner_->BelongsToCurrentThread());
781 return blink::WebString::fromUTF8(media_log_->GetLastErrorMessage()); 781 return blink::WebString::fromUTF8(media_log_->GetLastErrorMessage());
782 } 782 }
783 783
784 blink::WebTimeRanges WebMediaPlayerImpl::buffered() const { 784 blink::WebTimeRanges WebMediaPlayerImpl::buffered() const {
785 DCHECK(main_task_runner_->BelongsToCurrentThread()); 785 DCHECK(main_task_runner_->BelongsToCurrentThread());
786 786
787 Ranges<base::TimeDelta> buffered_time_ranges = 787 Ranges<base::TimeDelta> buffered_time_ranges =
788 pipeline_.GetBufferedTimeRanges(); 788 pipeline_controller_.GetBufferedTimeRanges();
789 789
790 const base::TimeDelta duration = GetPipelineMediaDuration(); 790 const base::TimeDelta duration = GetPipelineMediaDuration();
791 if (duration != kInfiniteDuration) { 791 if (duration != kInfiniteDuration) {
792 buffered_data_source_host_.AddBufferedTimeRanges( 792 buffered_data_source_host_.AddBufferedTimeRanges(&buffered_time_ranges,
793 &buffered_time_ranges, duration); 793 duration);
794 } 794 }
795 return ConvertToWebTimeRanges(buffered_time_ranges); 795 return ConvertToWebTimeRanges(buffered_time_ranges);
796 } 796 }
797 797
798 blink::WebTimeRanges WebMediaPlayerImpl::seekable() const { 798 blink::WebTimeRanges WebMediaPlayerImpl::seekable() const {
799 DCHECK(main_task_runner_->BelongsToCurrentThread()); 799 DCHECK(main_task_runner_->BelongsToCurrentThread());
800 800
801 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) 801 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata)
802 return blink::WebTimeRanges(); 802 return blink::WebTimeRanges();
803 803
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 837
838 base::TimeDelta preroll_attempt_duration = 838 base::TimeDelta preroll_attempt_duration =
839 tick_clock_->NowTicks() - preroll_attempt_start_time_; 839 tick_clock_->NowTicks() - preroll_attempt_start_time_;
840 return preroll_attempt_duration < kPrerollAttemptTimeout; 840 return preroll_attempt_duration < kPrerollAttemptTimeout;
841 } 841 }
842 842
843 bool WebMediaPlayerImpl::didLoadingProgress() { 843 bool WebMediaPlayerImpl::didLoadingProgress() {
844 DCHECK(main_task_runner_->BelongsToCurrentThread()); 844 DCHECK(main_task_runner_->BelongsToCurrentThread());
845 845
846 // Note: Separate variables used to ensure both methods are called every time. 846 // Note: Separate variables used to ensure both methods are called every time.
847 const bool pipeline_progress = pipeline_.DidLoadingProgress(); 847 const bool pipeline_progress = pipeline_controller_.DidLoadingProgress();
848 const bool data_progress = buffered_data_source_host_.DidLoadingProgress(); 848 const bool data_progress = buffered_data_source_host_.DidLoadingProgress();
849 const bool did_loading_progress = pipeline_progress || data_progress; 849 const bool did_loading_progress = pipeline_progress || data_progress;
850 850
851 if (did_loading_progress && 851 if (did_loading_progress &&
852 highest_ready_state_ < ReadyState::ReadyStateHaveFutureData) { 852 highest_ready_state_ < ReadyState::ReadyStateHaveFutureData) {
853 // Reset the preroll attempt clock. 853 // Reset the preroll attempt clock.
854 preroll_attempt_pending_ = true; 854 preroll_attempt_pending_ = true;
855 preroll_attempt_start_time_ = base::TimeTicks(); 855 preroll_attempt_start_time_ = base::TimeTicks();
856 856
857 // Clear any 'stale' flag and give the pipeline a chance to resume. If we 857 // Clear any 'stale' flag and give the pipeline a chance to resume. If we
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 OnCdmAttached(false); 1060 OnCdmAttached(false);
1061 return; 1061 return;
1062 } 1062 }
1063 1063
1064 if (observer_) 1064 if (observer_)
1065 observer_->OnSetCdm(cdm_context); 1065 observer_->OnSetCdm(cdm_context);
1066 1066
1067 // Keep the reference to the CDM, as it shouldn't be destroyed until 1067 // Keep the reference to the CDM, as it shouldn't be destroyed until
1068 // after the pipeline is done with the |cdm_context|. 1068 // after the pipeline is done with the |cdm_context|.
1069 pending_cdm_ = std::move(cdm_reference); 1069 pending_cdm_ = std::move(cdm_reference);
1070 pipeline_.SetCdm(cdm_context, 1070 pipeline_controller_.SetCdm(
1071 base::Bind(&WebMediaPlayerImpl::OnCdmAttached, AsWeakPtr())); 1071 cdm_context, base::Bind(&WebMediaPlayerImpl::OnCdmAttached, AsWeakPtr()));
1072 } 1072 }
1073 1073
1074 void WebMediaPlayerImpl::OnCdmAttached(bool success) { 1074 void WebMediaPlayerImpl::OnCdmAttached(bool success) {
1075 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1075 DCHECK(main_task_runner_->BelongsToCurrentThread());
1076 DCHECK(pending_cdm_); 1076 DCHECK(pending_cdm_);
1077 1077
1078 // If the CDM is set from the constructor there is no promise 1078 // If the CDM is set from the constructor there is no promise
1079 // (|set_cdm_result_|) to fulfill. 1079 // (|set_cdm_result_|) to fulfill.
1080 if (success) { 1080 if (success) {
1081 // This will release the previously attached CDM (if any). 1081 // This will release the previously attached CDM (if any).
(...skipping 17 matching lines...) Expand all
1099 1099
1100 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) { 1100 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) {
1101 seeking_ = false; 1101 seeking_ = false;
1102 seek_time_ = base::TimeDelta(); 1102 seek_time_ = base::TimeDelta();
1103 1103
1104 if (paused_) { 1104 if (paused_) {
1105 #if defined(OS_ANDROID) // WMPI_CAST 1105 #if defined(OS_ANDROID) // WMPI_CAST
1106 if (isRemote()) { 1106 if (isRemote()) {
1107 paused_time_ = base::TimeDelta::FromSecondsD(cast_impl_.currentTime()); 1107 paused_time_ = base::TimeDelta::FromSecondsD(cast_impl_.currentTime());
1108 } else { 1108 } else {
1109 paused_time_ = pipeline_.GetMediaTime(); 1109 paused_time_ = pipeline_controller_.GetMediaTime();
1110 } 1110 }
1111 #else 1111 #else
1112 paused_time_ = pipeline_.GetMediaTime(); 1112 paused_time_ = pipeline_controller_.GetMediaTime();
1113 #endif 1113 #endif
1114 } else { 1114 } else {
1115 DCHECK(watch_time_reporter_); 1115 DCHECK(watch_time_reporter_);
1116 watch_time_reporter_->OnPlaying(); 1116 watch_time_reporter_->OnPlaying();
1117 } 1117 }
1118 if (time_updated) 1118 if (time_updated)
1119 should_notify_time_changed_ = true; 1119 should_notify_time_changed_ = true;
1120 1120
1121 // Reset underflow duration upon seek; this prevents looping videos and user 1121 // Reset underflow duration upon seek; this prevents looping videos and user
1122 // actions from artificially inflating the duration. 1122 // actions from artificially inflating the duration.
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 1352
1353 client_->durationChanged(); 1353 client_->durationChanged();
1354 } 1354 }
1355 1355
1356 void WebMediaPlayerImpl::OnAddTextTrack(const TextTrackConfig& config, 1356 void WebMediaPlayerImpl::OnAddTextTrack(const TextTrackConfig& config,
1357 const AddTextTrackDoneCB& done_cb) { 1357 const AddTextTrackDoneCB& done_cb) {
1358 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1358 DCHECK(main_task_runner_->BelongsToCurrentThread());
1359 1359
1360 const WebInbandTextTrackImpl::Kind web_kind = 1360 const WebInbandTextTrackImpl::Kind web_kind =
1361 static_cast<WebInbandTextTrackImpl::Kind>(config.kind()); 1361 static_cast<WebInbandTextTrackImpl::Kind>(config.kind());
1362 const blink::WebString web_label = 1362 const blink::WebString web_label = blink::WebString::fromUTF8(config.label());
1363 blink::WebString::fromUTF8(config.label());
1364 const blink::WebString web_language = 1363 const blink::WebString web_language =
1365 blink::WebString::fromUTF8(config.language()); 1364 blink::WebString::fromUTF8(config.language());
1366 const blink::WebString web_id = 1365 const blink::WebString web_id = blink::WebString::fromUTF8(config.id());
1367 blink::WebString::fromUTF8(config.id());
1368 1366
1369 std::unique_ptr<WebInbandTextTrackImpl> web_inband_text_track( 1367 std::unique_ptr<WebInbandTextTrackImpl> web_inband_text_track(
1370 new WebInbandTextTrackImpl(web_kind, web_label, web_language, web_id)); 1368 new WebInbandTextTrackImpl(web_kind, web_label, web_language, web_id));
1371 1369
1372 std::unique_ptr<media::TextTrack> text_track(new TextTrackImpl( 1370 std::unique_ptr<media::TextTrack> text_track(new TextTrackImpl(
1373 main_task_runner_, client_, std::move(web_inband_text_track))); 1371 main_task_runner_, client_, std::move(web_inband_text_track)));
1374 1372
1375 done_cb.Run(std::move(text_track)); 1373 done_cb.Run(std::move(text_track));
1376 } 1374 }
1377 1375
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 client_->playbackStateChanged(); 1511 client_->playbackStateChanged();
1514 } 1512 }
1515 1513
1516 void WebMediaPlayerImpl::OnVolumeMultiplierUpdate(double multiplier) { 1514 void WebMediaPlayerImpl::OnVolumeMultiplierUpdate(double multiplier) {
1517 volume_multiplier_ = multiplier; 1515 volume_multiplier_ = multiplier;
1518 setVolume(volume_); 1516 setVolume(volume_);
1519 } 1517 }
1520 1518
1521 void WebMediaPlayerImpl::ScheduleRestart() { 1519 void WebMediaPlayerImpl::ScheduleRestart() {
1522 // TODO(watk): All restart logic should be moved into PipelineController. 1520 // TODO(watk): All restart logic should be moved into PipelineController.
1523 if (pipeline_.IsRunning() && !pipeline_controller_.IsPipelineSuspended()) { 1521 if (pipeline_controller_.IsPipelineRunning() &&
1522 !pipeline_controller_.IsPipelineSuspended()) {
1524 pending_suspend_resume_cycle_ = true; 1523 pending_suspend_resume_cycle_ = true;
1525 UpdatePlayState(); 1524 UpdatePlayState();
1526 } 1525 }
1527 } 1526 }
1528 1527
1529 void WebMediaPlayerImpl::requestRemotePlaybackDisabled(bool disabled) { 1528 void WebMediaPlayerImpl::requestRemotePlaybackDisabled(bool disabled) {
1530 if (observer_) 1529 if (observer_)
1531 observer_->OnRemotePlaybackDisabled(disabled); 1530 observer_->OnRemotePlaybackDisabled(disabled);
1532 } 1531 }
1533 1532
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 StartPipeline(); 1640 StartPipeline();
1642 } 1641 }
1643 1642
1644 void WebMediaPlayerImpl::NotifyDownloading(bool is_downloading) { 1643 void WebMediaPlayerImpl::NotifyDownloading(bool is_downloading) {
1645 DVLOG(1) << __func__; 1644 DVLOG(1) << __func__;
1646 if (!is_downloading && network_state_ == WebMediaPlayer::NetworkStateLoading) 1645 if (!is_downloading && network_state_ == WebMediaPlayer::NetworkStateLoading)
1647 SetNetworkState(WebMediaPlayer::NetworkStateIdle); 1646 SetNetworkState(WebMediaPlayer::NetworkStateIdle);
1648 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) 1647 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle)
1649 SetNetworkState(WebMediaPlayer::NetworkStateLoading); 1648 SetNetworkState(WebMediaPlayer::NetworkStateLoading);
1650 media_log_->AddEvent( 1649 media_log_->AddEvent(
1651 media_log_->CreateBooleanEvent( 1650 media_log_->CreateBooleanEvent(MediaLogEvent::NETWORK_ACTIVITY_SET,
1652 MediaLogEvent::NETWORK_ACTIVITY_SET, 1651 "is_downloading_data", is_downloading));
1653 "is_downloading_data", is_downloading));
1654 } 1652 }
1655 1653
1656 void WebMediaPlayerImpl::OnSurfaceCreated(int surface_id) { 1654 void WebMediaPlayerImpl::OnSurfaceCreated(int surface_id) {
1657 overlay_surface_id_ = surface_id; 1655 overlay_surface_id_ = surface_id;
1658 if (!set_surface_cb_.is_null()) { 1656 if (!set_surface_cb_.is_null()) {
1659 // If restart is required, the callback is one-shot only. 1657 // If restart is required, the callback is one-shot only.
1660 if (decoder_requires_restart_for_overlay_) 1658 if (decoder_requires_restart_for_overlay_)
1661 base::ResetAndReturn(&set_surface_cb_).Run(surface_id); 1659 base::ResetAndReturn(&set_surface_cb_).Run(surface_id);
1662 else 1660 else
1663 set_surface_cb_.Run(surface_id); 1661 set_surface_cb_.Run(surface_id);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 highest_ready_state_ = std::max(highest_ready_state_, ready_state_); 1793 highest_ready_state_ = std::max(highest_ready_state_, ready_state_);
1796 1794
1797 // Always notify to ensure client has the latest value. 1795 // Always notify to ensure client has the latest value.
1798 client_->readyStateChanged(); 1796 client_->readyStateChanged();
1799 } 1797 }
1800 1798
1801 blink::WebAudioSourceProvider* WebMediaPlayerImpl::getAudioSourceProvider() { 1799 blink::WebAudioSourceProvider* WebMediaPlayerImpl::getAudioSourceProvider() {
1802 return audio_source_provider_.get(); 1800 return audio_source_provider_.get();
1803 } 1801 }
1804 1802
1805 static void GetCurrentFrameAndSignal( 1803 static void GetCurrentFrameAndSignal(VideoFrameCompositor* compositor,
1806 VideoFrameCompositor* compositor, 1804 scoped_refptr<VideoFrame>* video_frame_out,
1807 scoped_refptr<VideoFrame>* video_frame_out, 1805 base::WaitableEvent* event) {
1808 base::WaitableEvent* event) {
1809 TRACE_EVENT0("media", "GetCurrentFrameAndSignal"); 1806 TRACE_EVENT0("media", "GetCurrentFrameAndSignal");
1810 *video_frame_out = compositor->GetCurrentFrameAndUpdateIfStale(); 1807 *video_frame_out = compositor->GetCurrentFrameAndUpdateIfStale();
1811 event->Signal(); 1808 event->Signal();
1812 } 1809 }
1813 1810
1814 scoped_refptr<VideoFrame> 1811 scoped_refptr<VideoFrame> WebMediaPlayerImpl::GetCurrentFrameFromCompositor() {
1815 WebMediaPlayerImpl::GetCurrentFrameFromCompositor() {
1816 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1812 DCHECK(main_task_runner_->BelongsToCurrentThread());
1817 TRACE_EVENT0("media", "WebMediaPlayerImpl::GetCurrentFrameFromCompositor"); 1813 TRACE_EVENT0("media", "WebMediaPlayerImpl::GetCurrentFrameFromCompositor");
1818 1814
1819 // Needed when the |main_task_runner_| and |compositor_task_runner_| are the 1815 // Needed when the |main_task_runner_| and |compositor_task_runner_| are the
1820 // same to avoid deadlock in the Wait() below. 1816 // same to avoid deadlock in the Wait() below.
1821 if (compositor_task_runner_->BelongsToCurrentThread()) 1817 if (compositor_task_runner_->BelongsToCurrentThread())
1822 return compositor_->GetCurrentFrameAndUpdateIfStale(); 1818 return compositor_->GetCurrentFrameAndUpdateIfStale();
1823 1819
1824 // Use a posted task and waitable event instead of a lock otherwise 1820 // Use a posted task and waitable event instead of a lock otherwise
1825 // WebGL/Canvas can see different content than what the compositor is seeing. 1821 // WebGL/Canvas can see different content than what the compositor is seeing.
1826 scoped_refptr<VideoFrame> video_frame; 1822 scoped_refptr<VideoFrame> video_frame;
1827 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, 1823 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
1828 base::WaitableEvent::InitialState::NOT_SIGNALED); 1824 base::WaitableEvent::InitialState::NOT_SIGNALED);
1829 compositor_task_runner_->PostTask(FROM_HERE, 1825 compositor_task_runner_->PostTask(
1830 base::Bind(&GetCurrentFrameAndSignal, 1826 FROM_HERE,
1831 base::Unretained(compositor_), 1827 base::Bind(&GetCurrentFrameAndSignal, base::Unretained(compositor_),
1832 &video_frame, 1828 &video_frame, &event));
1833 &event));
1834 event.Wait(); 1829 event.Wait();
1835 return video_frame; 1830 return video_frame;
1836 } 1831 }
1837 1832
1838 void WebMediaPlayerImpl::UpdatePlayState() { 1833 void WebMediaPlayerImpl::UpdatePlayState() {
1839 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1834 DCHECK(main_task_runner_->BelongsToCurrentThread());
1840 1835
1841 #if defined(OS_ANDROID) // WMPI_CAST 1836 #if defined(OS_ANDROID) // WMPI_CAST
1842 bool is_remote = isRemote(); 1837 bool is_remote = isRemote();
1843 bool can_auto_suspend = true; 1838 bool can_auto_suspend = true;
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
2217 } else { 2212 } else {
2218 EnableVideoTrackIfNeeded(); 2213 EnableVideoTrackIfNeeded();
2219 } 2214 }
2220 } 2215 }
2221 2216
2222 void WebMediaPlayerImpl::PauseVideoIfNeeded() { 2217 void WebMediaPlayerImpl::PauseVideoIfNeeded() {
2223 DCHECK(IsHidden()); 2218 DCHECK(IsHidden());
2224 2219
2225 // Don't pause video while the pipeline is stopped, resuming or seeking. 2220 // Don't pause video while the pipeline is stopped, resuming or seeking.
2226 // Also if the video is paused already. 2221 // Also if the video is paused already.
2227 if (!pipeline_.IsRunning() || is_pipeline_resuming_ || seeking_ || paused_) 2222 if (!pipeline_controller_.IsPipelineRunning() || is_pipeline_resuming_ ||
2223 seeking_ || paused_)
2228 return; 2224 return;
2229 2225
2230 // OnPause() will set |paused_when_hidden_| to false and call 2226 // OnPause() will set |paused_when_hidden_| to false and call
2231 // UpdatePlayState(), so set the flag to true after and then return. 2227 // UpdatePlayState(), so set the flag to true after and then return.
2232 OnPause(); 2228 OnPause();
2233 paused_when_hidden_ = true; 2229 paused_when_hidden_ = true;
2234 } 2230 }
2235 2231
2236 void WebMediaPlayerImpl::EnableVideoTrackIfNeeded() { 2232 void WebMediaPlayerImpl::EnableVideoTrackIfNeeded() {
2237 // Don't change video track while the pipeline is stopped, resuming or 2233 // Don't change video track while the pipeline is stopped, resuming or
2238 // seeking. 2234 // seeking.
2239 if (!pipeline_.IsRunning() || is_pipeline_resuming_ || seeking_) 2235 if (!pipeline_controller_.IsPipelineRunning() || is_pipeline_resuming_ ||
2236 seeking_)
2240 return; 2237 return;
2241 2238
2242 if (video_track_disabled_) { 2239 if (video_track_disabled_) {
2243 video_track_disabled_ = false; 2240 video_track_disabled_ = false;
2244 if (client_->hasSelectedVideoTrack()) { 2241 if (client_->hasSelectedVideoTrack()) {
2245 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); 2242 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId();
2246 selectedVideoTrackChanged(&trackId); 2243 selectedVideoTrackChanged(&trackId);
2247 } 2244 }
2248 } 2245 }
2249 } 2246 }
(...skipping 12 matching lines...) Expand all
2262 } 2259 }
2263 2260
2264 void WebMediaPlayerImpl::SetPipelineStatisticsForTest( 2261 void WebMediaPlayerImpl::SetPipelineStatisticsForTest(
2265 const PipelineStatistics& stats) { 2262 const PipelineStatistics& stats) {
2266 pipeline_statistics_for_test_ = base::make_optional(stats); 2263 pipeline_statistics_for_test_ = base::make_optional(stats);
2267 } 2264 }
2268 2265
2269 PipelineStatistics WebMediaPlayerImpl::GetPipelineStatistics() const { 2266 PipelineStatistics WebMediaPlayerImpl::GetPipelineStatistics() const {
2270 DCHECK(main_task_runner_->BelongsToCurrentThread()); 2267 DCHECK(main_task_runner_->BelongsToCurrentThread());
2271 2268
2272 return pipeline_statistics_for_test_.value_or(pipeline_.GetStatistics()); 2269 return pipeline_statistics_for_test_.value_or(
2270 pipeline_controller_.GetStatistics());
2273 } 2271 }
2274 2272
2275 void WebMediaPlayerImpl::SetPipelineMediaDurationForTest( 2273 void WebMediaPlayerImpl::SetPipelineMediaDurationForTest(
2276 base::TimeDelta duration) { 2274 base::TimeDelta duration) {
2277 pipeline_media_duration_for_test_ = base::make_optional(duration); 2275 pipeline_media_duration_for_test_ = base::make_optional(duration);
2278 } 2276 }
2279 2277
2280 base::TimeDelta WebMediaPlayerImpl::GetPipelineMediaDuration() const { 2278 base::TimeDelta WebMediaPlayerImpl::GetPipelineMediaDuration() const {
2281 DCHECK(main_task_runner_->BelongsToCurrentThread()); 2279 DCHECK(main_task_runner_->BelongsToCurrentThread());
2282 2280
2283 return pipeline_media_duration_for_test_.value_or( 2281 return pipeline_media_duration_for_test_.value_or(
2284 pipeline_.GetMediaDuration()); 2282 pipeline_controller_.GetMediaDuration());
2285 } 2283 }
2286 2284
2287 void WebMediaPlayerImpl::ReportTimeFromForegroundToFirstFrame( 2285 void WebMediaPlayerImpl::ReportTimeFromForegroundToFirstFrame(
2288 base::TimeTicks foreground_time, 2286 base::TimeTicks foreground_time,
2289 base::TimeTicks new_frame_time) { 2287 base::TimeTicks new_frame_time) {
2290 base::TimeDelta time_to_first_frame = new_frame_time - foreground_time; 2288 base::TimeDelta time_to_first_frame = new_frame_time - foreground_time;
2291 if (hasAudio()) { 2289 if (hasAudio()) {
2292 UMA_HISTOGRAM_TIMES( 2290 UMA_HISTOGRAM_TIMES(
2293 "Media.Video.TimeFromForegroundToFirstFrame.DisableTrack", 2291 "Media.Video.TimeFromForegroundToFirstFrame.DisableTrack",
2294 time_to_first_frame); 2292 time_to_first_frame);
(...skipping 10 matching lines...) Expand all
2305 2303
2306 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) { 2304 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) {
2307 DCHECK(data_source_ || chunk_demuxer_); 2305 DCHECK(data_source_ || chunk_demuxer_);
2308 if (data_source_) 2306 if (data_source_)
2309 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration); 2307 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration);
2310 else 2308 else
2311 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration); 2309 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration);
2312 } 2310 }
2313 2311
2314 } // namespace media 2312 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | media/filters/pipeline_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698