| OLD | NEW |
| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 std::unique_ptr<RendererFactory> renderer_factory, | 174 std::unique_ptr<RendererFactory> renderer_factory, |
| 175 linked_ptr<UrlIndex> url_index, | 175 linked_ptr<UrlIndex> url_index, |
| 176 const WebMediaPlayerParams& params) | 176 const WebMediaPlayerParams& params) |
| 177 : frame_(frame), | 177 : frame_(frame), |
| 178 delegate_state_(DelegateState::GONE), | 178 delegate_state_(DelegateState::GONE), |
| 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), | |
| 185 main_task_runner_(frame->loadingTaskRunner()), | 184 main_task_runner_(frame->loadingTaskRunner()), |
| 186 media_task_runner_(params.media_task_runner()), | 185 media_task_runner_(params.media_task_runner()), |
| 187 worker_task_runner_(params.worker_task_runner()), | 186 worker_task_runner_(params.worker_task_runner()), |
| 188 media_log_(params.media_log()), | 187 media_log_(params.media_log()), |
| 189 pipeline_controller_( | 188 pipeline_controller_( |
| 190 base::MakeUnique<PipelineImpl>(media_task_runner_, media_log_.get()), | 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()), |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 // Media source pipelines can start immediately. | 411 // Media source pipelines can start immediately. |
| 413 if (load_type == LoadTypeMediaSource) { | 412 if (load_type == LoadTypeMediaSource) { |
| 414 supports_save_ = false; | 413 supports_save_ = false; |
| 415 StartPipeline(); | 414 StartPipeline(); |
| 416 } else { | 415 } else { |
| 417 data_source_.reset(new MultibufferDataSource( | 416 data_source_.reset(new MultibufferDataSource( |
| 418 url, static_cast<UrlData::CORSMode>(cors_mode), main_task_runner_, | 417 url, static_cast<UrlData::CORSMode>(cors_mode), main_task_runner_, |
| 419 url_index_, frame_, media_log_.get(), &buffered_data_source_host_, | 418 url_index_, frame_, media_log_.get(), &buffered_data_source_host_, |
| 420 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); | 419 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); |
| 421 data_source_->SetPreload(preload_); | 420 data_source_->SetPreload(preload_); |
| 422 data_source_->SetBufferingStrategy(buffering_strategy_); | |
| 423 data_source_->Initialize( | 421 data_source_->Initialize( |
| 424 base::Bind(&WebMediaPlayerImpl::DataSourceInitialized, AsWeakPtr())); | 422 base::Bind(&WebMediaPlayerImpl::DataSourceInitialized, AsWeakPtr())); |
| 425 } | 423 } |
| 426 | 424 |
| 427 #if defined(OS_ANDROID) // WMPI_CAST | 425 #if defined(OS_ANDROID) // WMPI_CAST |
| 428 cast_impl_.Initialize(url, frame_, delegate_id_); | 426 cast_impl_.Initialize(url, frame_, delegate_id_); |
| 429 #endif | 427 #endif |
| 430 } | 428 } |
| 431 | 429 |
| 432 void WebMediaPlayerImpl::play() { | 430 void WebMediaPlayerImpl::play() { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 | 629 |
| 632 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { | 630 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { |
| 633 DVLOG(1) << __func__ << "(" << preload << ")"; | 631 DVLOG(1) << __func__ << "(" << preload << ")"; |
| 634 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 632 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 635 | 633 |
| 636 preload_ = static_cast<MultibufferDataSource::Preload>(preload); | 634 preload_ = static_cast<MultibufferDataSource::Preload>(preload); |
| 637 if (data_source_) | 635 if (data_source_) |
| 638 data_source_->SetPreload(preload_); | 636 data_source_->SetPreload(preload_); |
| 639 } | 637 } |
| 640 | 638 |
| 641 STATIC_ASSERT_ENUM(WebMediaPlayer::BufferingStrategy::Normal, | |
| 642 MultibufferDataSource::BUFFERING_STRATEGY_NORMAL); | |
| 643 STATIC_ASSERT_ENUM(WebMediaPlayer::BufferingStrategy::Aggressive, | |
| 644 MultibufferDataSource::BUFFERING_STRATEGY_AGGRESSIVE); | |
| 645 | |
| 646 void WebMediaPlayerImpl::setBufferingStrategy( | |
| 647 WebMediaPlayer::BufferingStrategy buffering_strategy) { | |
| 648 DVLOG(1) << __func__; | |
| 649 DCHECK(main_task_runner_->BelongsToCurrentThread()); | |
| 650 | |
| 651 #if defined(OS_ANDROID) | |
| 652 // We disallow aggressive buffering on Android since it matches the behavior | |
| 653 // of the platform media player and may have data usage penalties. | |
| 654 // TODO(dalecurtis, hubbe): We should probably stop using "pause-and-buffer" | |
| 655 // everywhere. See http://crbug.com/594669 for more details. | |
| 656 buffering_strategy_ = MultibufferDataSource::BUFFERING_STRATEGY_NORMAL; | |
| 657 #else | |
| 658 buffering_strategy_ = | |
| 659 static_cast<MultibufferDataSource::BufferingStrategy>(buffering_strategy); | |
| 660 #endif | |
| 661 | |
| 662 if (data_source_) | |
| 663 data_source_->SetBufferingStrategy(buffering_strategy_); | |
| 664 } | |
| 665 | |
| 666 bool WebMediaPlayerImpl::hasVideo() const { | 639 bool WebMediaPlayerImpl::hasVideo() const { |
| 667 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 640 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 668 | 641 |
| 669 return pipeline_metadata_.has_video; | 642 return pipeline_metadata_.has_video; |
| 670 } | 643 } |
| 671 | 644 |
| 672 bool WebMediaPlayerImpl::hasAudio() const { | 645 bool WebMediaPlayerImpl::hasAudio() const { |
| 673 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 646 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 674 | 647 |
| 675 return pipeline_metadata_.has_audio; | 648 return pipeline_metadata_.has_audio; |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 | 1119 |
| 1147 void WebMediaPlayerImpl::OnPipelineSuspended() { | 1120 void WebMediaPlayerImpl::OnPipelineSuspended() { |
| 1148 #if defined(OS_ANDROID) | 1121 #if defined(OS_ANDROID) |
| 1149 if (isRemote()) { | 1122 if (isRemote()) { |
| 1150 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); | 1123 scoped_refptr<VideoFrame> frame = cast_impl_.GetCastingBanner(); |
| 1151 if (frame) | 1124 if (frame) |
| 1152 compositor_->PaintSingleFrame(frame); | 1125 compositor_->PaintSingleFrame(frame); |
| 1153 } | 1126 } |
| 1154 #endif | 1127 #endif |
| 1155 | 1128 |
| 1156 // If we're not in an aggressive buffering state, tell the data source we have | 1129 // Tell the data source we have enough data so that it may release the |
| 1157 // enough data so that it may release the connection. | 1130 // connection. |
| 1158 if (buffering_strategy_ != | 1131 if (data_source_) |
| 1159 MultibufferDataSource::BUFFERING_STRATEGY_AGGRESSIVE) { | 1132 data_source_->OnBufferingHaveEnough(true); |
| 1160 if (data_source_) | |
| 1161 data_source_->OnBufferingHaveEnough(true); | |
| 1162 } | |
| 1163 | 1133 |
| 1164 ReportMemoryUsage(); | 1134 ReportMemoryUsage(); |
| 1165 | 1135 |
| 1166 if (pending_suspend_resume_cycle_) { | 1136 if (pending_suspend_resume_cycle_) { |
| 1167 pending_suspend_resume_cycle_ = false; | 1137 pending_suspend_resume_cycle_ = false; |
| 1168 UpdatePlayState(); | 1138 UpdatePlayState(); |
| 1169 } | 1139 } |
| 1170 } | 1140 } |
| 1171 | 1141 |
| 1172 void WebMediaPlayerImpl::OnBeforePipelineResume() { | 1142 void WebMediaPlayerImpl::OnBeforePipelineResume() { |
| (...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2332 | 2302 |
| 2333 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) { | 2303 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) { |
| 2334 DCHECK(data_source_ || chunk_demuxer_); | 2304 DCHECK(data_source_ || chunk_demuxer_); |
| 2335 if (data_source_) | 2305 if (data_source_) |
| 2336 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration); | 2306 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration); |
| 2337 else | 2307 else |
| 2338 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration); | 2308 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration); |
| 2339 } | 2309 } |
| 2340 | 2310 |
| 2341 } // namespace media | 2311 } // namespace media |
| OLD | NEW |