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

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

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

Powered by Google App Engine
This is Rietveld 408576698