OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chromecast/browser/media/cast_renderer.h" | 5 #include "chromecast/browser/media/cast_renderer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "chromecast/base/task_runner_impl.h" | 9 #include "chromecast/base/task_runner_impl.h" |
| 10 #include "chromecast/browser/media/video_resolution_policy.h" |
10 #include "chromecast/media/cdm/cast_cdm_context.h" | 11 #include "chromecast/media/cdm/cast_cdm_context.h" |
11 #include "chromecast/media/cma/base/balanced_media_task_runner_factory.h" | 12 #include "chromecast/media/cma/base/balanced_media_task_runner_factory.h" |
12 #include "chromecast/media/cma/base/cma_logging.h" | 13 #include "chromecast/media/cma/base/cma_logging.h" |
13 #include "chromecast/media/cma/base/demuxer_stream_adapter.h" | 14 #include "chromecast/media/cma/base/demuxer_stream_adapter.h" |
14 #include "chromecast/media/cma/pipeline/media_pipeline_impl.h" | 15 #include "chromecast/media/cma/pipeline/media_pipeline_impl.h" |
15 #include "chromecast/media/cma/pipeline/video_pipeline_client.h" | 16 #include "chromecast/media/cma/pipeline/video_pipeline_client.h" |
16 #include "chromecast/public/media/media_pipeline_backend.h" | 17 #include "chromecast/public/media/media_pipeline_backend.h" |
17 #include "chromecast/public/media/media_pipeline_device_params.h" | 18 #include "chromecast/public/media/media_pipeline_device_params.h" |
18 #include "media/base/audio_decoder_config.h" | 19 #include "media/base/audio_decoder_config.h" |
19 #include "media/base/demuxer_stream.h" | 20 #include "media/base/demuxer_stream.h" |
20 #include "media/base/demuxer_stream_provider.h" | 21 #include "media/base/demuxer_stream_provider.h" |
21 #include "media/base/media_log.h" | 22 #include "media/base/media_log.h" |
22 #include "media/base/renderer_client.h" | 23 #include "media/base/renderer_client.h" |
23 | 24 |
24 namespace chromecast { | 25 namespace chromecast { |
25 namespace media { | 26 namespace media { |
26 | 27 |
27 namespace { | 28 namespace { |
28 // Maximum difference between audio frame PTS and video frame PTS | 29 // Maximum difference between audio frame PTS and video frame PTS |
29 // for frames read from the DemuxerStream. | 30 // for frames read from the DemuxerStream. |
30 const base::TimeDelta kMaxDeltaFetcher(base::TimeDelta::FromMilliseconds(2000)); | 31 const base::TimeDelta kMaxDeltaFetcher(base::TimeDelta::FromMilliseconds(2000)); |
31 } // namespace | 32 } // namespace |
32 | 33 |
33 CastRenderer::CastRenderer( | 34 CastRenderer::CastRenderer( |
34 const CreateMediaPipelineBackendCB& create_backend_cb, | 35 const CreateMediaPipelineBackendCB& create_backend_cb, |
35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 36 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
36 const std::string& audio_device_id) | 37 const std::string& audio_device_id, |
| 38 VideoResolutionPolicy* video_resolution_policy) |
37 : create_backend_cb_(create_backend_cb), | 39 : create_backend_cb_(create_backend_cb), |
38 task_runner_(task_runner), | 40 task_runner_(task_runner), |
39 audio_device_id_(audio_device_id), | 41 audio_device_id_(audio_device_id), |
| 42 video_resolution_policy_(video_resolution_policy), |
40 client_(nullptr), | 43 client_(nullptr), |
41 cast_cdm_context_(nullptr), | 44 cast_cdm_context_(nullptr), |
42 media_task_runner_factory_( | 45 media_task_runner_factory_( |
43 new BalancedMediaTaskRunnerFactory(kMaxDeltaFetcher)), | 46 new BalancedMediaTaskRunnerFactory(kMaxDeltaFetcher)), |
44 weak_factory_(this) { | 47 weak_factory_(this) { |
45 CMALOG(kLogControl) << __FUNCTION__ << ": " << this; | 48 CMALOG(kLogControl) << __FUNCTION__ << ": " << this; |
| 49 |
| 50 if (video_resolution_policy_) |
| 51 video_resolution_policy_->AddObserver(this); |
46 } | 52 } |
47 | 53 |
48 CastRenderer::~CastRenderer() { | 54 CastRenderer::~CastRenderer() { |
49 CMALOG(kLogControl) << __FUNCTION__ << ": " << this; | 55 CMALOG(kLogControl) << __FUNCTION__ << ": " << this; |
50 DCHECK(task_runner_->BelongsToCurrentThread()); | 56 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 57 |
| 58 if (video_resolution_policy_) |
| 59 video_resolution_policy_->RemoveObserver(this); |
51 } | 60 } |
52 | 61 |
53 void CastRenderer::Initialize( | 62 void CastRenderer::Initialize( |
54 ::media::DemuxerStreamProvider* demuxer_stream_provider, | 63 ::media::DemuxerStreamProvider* demuxer_stream_provider, |
55 ::media::RendererClient* client, | 64 ::media::RendererClient* client, |
56 const ::media::PipelineStatusCB& init_cb) { | 65 const ::media::PipelineStatusCB& init_cb) { |
57 CMALOG(kLogControl) << __FUNCTION__ << ": " << this; | 66 CMALOG(kLogControl) << __FUNCTION__ << ": " << this; |
58 DCHECK(task_runner_->BelongsToCurrentThread()); | 67 DCHECK(task_runner_->BelongsToCurrentThread()); |
59 | 68 |
60 // Create pipeline backend. | 69 // Create pipeline backend. |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 bool CastRenderer::HasAudio() { | 208 bool CastRenderer::HasAudio() { |
200 DCHECK(task_runner_->BelongsToCurrentThread()); | 209 DCHECK(task_runner_->BelongsToCurrentThread()); |
201 return pipeline_->HasAudio(); | 210 return pipeline_->HasAudio(); |
202 } | 211 } |
203 | 212 |
204 bool CastRenderer::HasVideo() { | 213 bool CastRenderer::HasVideo() { |
205 DCHECK(task_runner_->BelongsToCurrentThread()); | 214 DCHECK(task_runner_->BelongsToCurrentThread()); |
206 return pipeline_->HasVideo(); | 215 return pipeline_->HasVideo(); |
207 } | 216 } |
208 | 217 |
| 218 void CastRenderer::OnVideoResolutionPolicyChanged() { |
| 219 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 220 if (!video_resolution_policy_) |
| 221 return; |
| 222 |
| 223 if (video_resolution_policy_->ShouldBlock(video_res_)) |
| 224 OnError(::media::PIPELINE_ERROR_DECODE); |
| 225 } |
| 226 |
209 void CastRenderer::OnError(::media::PipelineStatus status) { | 227 void CastRenderer::OnError(::media::PipelineStatus status) { |
210 DCHECK(task_runner_->BelongsToCurrentThread()); | 228 DCHECK(task_runner_->BelongsToCurrentThread()); |
211 client_->OnError(status); | 229 client_->OnError(status); |
212 } | 230 } |
213 | 231 |
214 void CastRenderer::OnEnded(Stream stream) { | 232 void CastRenderer::OnEnded(Stream stream) { |
215 DCHECK(task_runner_->BelongsToCurrentThread()); | 233 DCHECK(task_runner_->BelongsToCurrentThread()); |
216 DCHECK(!eos_[stream]); | 234 DCHECK(!eos_[stream]); |
217 eos_[stream] = true; | 235 eos_[stream] = true; |
218 CMALOG(kLogControl) << __FUNCTION__ << ": eos_audio=" << eos_[STREAM_AUDIO] | 236 CMALOG(kLogControl) << __FUNCTION__ << ": eos_audio=" << eos_[STREAM_AUDIO] |
(...skipping 14 matching lines...) Expand all Loading... |
233 } | 251 } |
234 | 252 |
235 void CastRenderer::OnWaitingForDecryptionKey() { | 253 void CastRenderer::OnWaitingForDecryptionKey() { |
236 DCHECK(task_runner_->BelongsToCurrentThread()); | 254 DCHECK(task_runner_->BelongsToCurrentThread()); |
237 client_->OnWaitingForDecryptionKey(); | 255 client_->OnWaitingForDecryptionKey(); |
238 } | 256 } |
239 | 257 |
240 void CastRenderer::OnVideoNaturalSizeChange(const gfx::Size& size) { | 258 void CastRenderer::OnVideoNaturalSizeChange(const gfx::Size& size) { |
241 DCHECK(task_runner_->BelongsToCurrentThread()); | 259 DCHECK(task_runner_->BelongsToCurrentThread()); |
242 client_->OnVideoNaturalSizeChange(size); | 260 client_->OnVideoNaturalSizeChange(size); |
| 261 |
| 262 video_res_ = size; |
| 263 OnVideoResolutionPolicyChanged(); |
243 } | 264 } |
244 | 265 |
245 void CastRenderer::OnVideoOpacityChange(bool opaque) { | 266 void CastRenderer::OnVideoOpacityChange(bool opaque) { |
246 DCHECK(task_runner_->BelongsToCurrentThread()); | 267 DCHECK(task_runner_->BelongsToCurrentThread()); |
247 DCHECK(opaque); | 268 DCHECK(opaque); |
248 client_->OnVideoOpacityChange(opaque); | 269 client_->OnVideoOpacityChange(opaque); |
249 } | 270 } |
250 | 271 |
251 } // namespace media | 272 } // namespace media |
252 } // namespace chromecast | 273 } // namespace chromecast |
OLD | NEW |