Chromium Code Reviews| Index: media/remoting/remoting_renderer_controller.cc |
| diff --git a/media/remoting/remoting_renderer_controller.cc b/media/remoting/remoting_renderer_controller.cc |
| index 5f0d37eacdbc7a5939d49d5b0941e7077d07da8f..277db0e16ecefee3dd9c2cf69963358c55906bfb 100644 |
| --- a/media/remoting/remoting_renderer_controller.cc |
| +++ b/media/remoting/remoting_renderer_controller.cc |
| @@ -7,10 +7,21 @@ |
| #include "base/bind.h" |
| #include "base/logging.h" |
| #include "base/threading/thread_checker.h" |
| +#include "media/base/video_util.h" |
| #include "media/remoting/remoting_cdm_context.h" |
| namespace media { |
| +namespace { |
| + |
| +gfx::Size GetRotatedVideoSize(VideoRotation rotation, gfx::Size natural_size) { |
| + if (rotation == VIDEO_ROTATION_90 || rotation == VIDEO_ROTATION_270) |
| + return gfx::Size(natural_size.height(), natural_size.width()); |
| + return natural_size; |
| +} |
| + |
| +} // namespace |
| + |
| RemotingRendererController::RemotingRendererController( |
| scoped_refptr<RemotingSourceImpl> remoting_source) |
| : remoting_source_(remoting_source), weak_factory_(this) { |
| @@ -43,6 +54,8 @@ void RemotingRendererController::OnSessionStateChanged() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| VLOG(1) << "OnSessionStateChanged: " << remoting_source_->state(); |
| + |
| + UpdateInterstitial(); |
| UpdateAndMaybeSwitch(); |
| } |
| @@ -103,17 +116,22 @@ void RemotingRendererController::OnMetadataChanged( |
| const PipelineMetadata& metadata) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| + const gfx::Size old_size = pipeline_metadata_.natural_size; |
| pipeline_metadata_ = metadata; |
| is_encrypted_ = false; |
| if (has_video()) { |
| - video_decoder_config_ = metadata.video_decoder_config; |
| - is_encrypted_ |= video_decoder_config_.is_encrypted(); |
| + is_encrypted_ |= metadata.video_decoder_config.is_encrypted(); |
| + pipeline_metadata_.natural_size = GetRotatedVideoSize( |
| + pipeline_metadata_.video_rotation, pipeline_metadata_.natural_size); |
| } |
| if (has_audio()) { |
| - audio_decoder_config_ = metadata.audio_decoder_config; |
| - is_encrypted_ |= audio_decoder_config_.is_encrypted(); |
| + is_encrypted_ |= metadata.audio_decoder_config.is_encrypted(); |
| } |
| + |
| + if (pipeline_metadata_.natural_size != old_size) |
| + UpdateInterstitial(); |
| + |
| UpdateAndMaybeSwitch(); |
| } |
| @@ -121,13 +139,13 @@ bool RemotingRendererController::IsVideoCodecSupported() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(has_video()); |
| - switch (video_decoder_config_.codec()) { |
| + switch (pipeline_metadata_.video_decoder_config.codec()) { |
| case VideoCodec::kCodecH264: |
| case VideoCodec::kCodecVP8: |
| return true; |
| default: |
| VLOG(2) << "Remoting does not support video codec: " |
| - << video_decoder_config_.codec(); |
| + << pipeline_metadata_.video_decoder_config.codec(); |
| return false; |
| } |
| } |
| @@ -136,7 +154,7 @@ bool RemotingRendererController::IsAudioCodecSupported() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(has_audio()); |
| - switch (audio_decoder_config_.codec()) { |
| + switch (pipeline_metadata_.audio_decoder_config.codec()) { |
| case AudioCodec::kCodecAAC: |
| case AudioCodec::kCodecMP3: |
| case AudioCodec::kCodecPCM: |
| @@ -156,7 +174,7 @@ bool RemotingRendererController::IsAudioCodecSupported() { |
| return true; |
| default: |
| VLOG(2) << "Remoting does not support audio codec: " |
| - << audio_decoder_config_.codec(); |
| + << pipeline_metadata_.audio_decoder_config.codec(); |
| return false; |
| } |
| } |
| @@ -243,4 +261,36 @@ void RemotingRendererController::UpdateAndMaybeSwitch() { |
| } |
| } |
| +void RemotingRendererController::SetShowInterstitialCallback( |
| + const ShowInterstitialCallback& cb) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + show_interstitial_cb_ = cb; |
| + UpdateInterstitial(); |
| +} |
| + |
| +void RemotingRendererController::UpdateInterstitial() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (!remote_rendering_started_ || show_interstitial_cb_.is_null() || |
| + pipeline_metadata_.natural_size.IsEmpty()) |
| + return; |
| + |
| + RemotingInterstitialType type = RemotingInterstitialType::BETWEEN_SESSIONS; |
| + switch (remoting_source_->state()) { |
| + case SESSION_STARTED: |
| + type = RemotingInterstitialType::IN_SESSION; |
| + break; |
| + case SESSION_PERMANENTLY_STOPPED: |
| + type = RemotingInterstitialType::ENCRYPTED_MEDIA_FATAL_ERROR; |
| + break; |
| + case SESSION_UNAVAILABLE: |
| + case SESSION_CAN_START: |
| + case SESSION_STARTING: |
|
miu
2016/12/20 21:21:04
IMHO, we should show the "IN_SESSION" interstitial
xjz
2016/12/20 22:15:37
Why? We only need (and can only) show interstitial
miu
2016/12/20 23:15:49
tl;dr: Don't bake assumptions into your code when
xjz
2016/12/20 23:54:54
Thanks for the explanation. Learned a lot from you
|
| + case SESSION_STOPPING: |
| + return; |
|
miu
2016/12/20 21:21:04
I think you meant "break" instead of "return" here
xjz
2016/12/20 22:15:37
I mean "return" because we don't need to paint int
miu
2016/12/20 23:15:49
This is another flavor of the prior comment: Don't
xjz
2016/12/20 23:54:54
Done. Thanks for the explanation.
|
| + } |
| + |
| + // TODO(xjz): Download poster image when available. |
| + show_interstitial_cb_.Run(SkBitmap(), pipeline_metadata_.natural_size, type); |
| +} |
| + |
| } // namespace media |