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 "media/remoting/remoting_renderer_controller.h" | 5 #include "media/remoting/remoting_renderer_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/threading/thread_checker.h" | 9 #include "base/threading/thread_checker.h" |
| 10 #include "media/base/video_util.h" |
10 #include "media/remoting/remoting_cdm_context.h" | 11 #include "media/remoting/remoting_cdm_context.h" |
11 | 12 |
12 namespace media { | 13 namespace media { |
13 | 14 |
| 15 namespace { |
| 16 |
| 17 gfx::Size GetRotatedVideoSize(VideoRotation rotation, gfx::Size natural_size) { |
| 18 if (rotation == VIDEO_ROTATION_90 || rotation == VIDEO_ROTATION_270) |
| 19 return gfx::Size(natural_size.height(), natural_size.width()); |
| 20 return natural_size; |
| 21 } |
| 22 |
| 23 } // namespace |
| 24 |
14 RemotingRendererController::RemotingRendererController( | 25 RemotingRendererController::RemotingRendererController( |
15 scoped_refptr<RemotingSourceImpl> remoting_source) | 26 scoped_refptr<RemotingSourceImpl> remoting_source) |
16 : remoting_source_(remoting_source), weak_factory_(this) { | 27 : remoting_source_(remoting_source), weak_factory_(this) { |
17 remoting_source_->AddClient(this); | 28 remoting_source_->AddClient(this); |
18 } | 29 } |
19 | 30 |
20 RemotingRendererController::~RemotingRendererController() { | 31 RemotingRendererController::~RemotingRendererController() { |
21 DCHECK(thread_checker_.CalledOnValidThread()); | 32 DCHECK(thread_checker_.CalledOnValidThread()); |
22 remoting_source_->RemoveClient(this); | 33 remoting_source_->RemoveClient(this); |
23 } | 34 } |
(...skipping 12 matching lines...) Expand all Loading... |
36 } else { | 47 } else { |
37 VLOG(1) << "Failed to start remoting."; | 48 VLOG(1) << "Failed to start remoting."; |
38 remote_rendering_started_ = false; | 49 remote_rendering_started_ = false; |
39 } | 50 } |
40 } | 51 } |
41 | 52 |
42 void RemotingRendererController::OnSessionStateChanged() { | 53 void RemotingRendererController::OnSessionStateChanged() { |
43 DCHECK(thread_checker_.CalledOnValidThread()); | 54 DCHECK(thread_checker_.CalledOnValidThread()); |
44 | 55 |
45 VLOG(1) << "OnSessionStateChanged: " << remoting_source_->state(); | 56 VLOG(1) << "OnSessionStateChanged: " << remoting_source_->state(); |
| 57 if (remoting_source_->state() == |
| 58 RemotingSessionState::SESSION_PERMANENTLY_STOPPED) |
| 59 UpdateAndMaybeShowInterstitial(); |
| 60 |
46 UpdateAndMaybeSwitch(); | 61 UpdateAndMaybeSwitch(); |
47 } | 62 } |
48 | 63 |
49 void RemotingRendererController::OnEnteredFullscreen() { | 64 void RemotingRendererController::OnEnteredFullscreen() { |
50 DCHECK(thread_checker_.CalledOnValidThread()); | 65 DCHECK(thread_checker_.CalledOnValidThread()); |
51 | 66 |
52 is_fullscreen_ = true; | 67 is_fullscreen_ = true; |
53 UpdateAndMaybeSwitch(); | 68 UpdateAndMaybeSwitch(); |
54 } | 69 } |
55 | 70 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 DCHECK(thread_checker_.CalledOnValidThread()); | 111 DCHECK(thread_checker_.CalledOnValidThread()); |
97 | 112 |
98 remoting_source_->StartDataPipe(std::move(audio_data_pipe), | 113 remoting_source_->StartDataPipe(std::move(audio_data_pipe), |
99 std::move(video_data_pipe), done_callback); | 114 std::move(video_data_pipe), done_callback); |
100 } | 115 } |
101 | 116 |
102 void RemotingRendererController::OnMetadataChanged( | 117 void RemotingRendererController::OnMetadataChanged( |
103 const PipelineMetadata& metadata) { | 118 const PipelineMetadata& metadata) { |
104 DCHECK(thread_checker_.CalledOnValidThread()); | 119 DCHECK(thread_checker_.CalledOnValidThread()); |
105 | 120 |
| 121 const gfx::Size old_size = pipeline_metadata_.natural_size; |
106 pipeline_metadata_ = metadata; | 122 pipeline_metadata_ = metadata; |
107 | 123 |
108 is_encrypted_ = false; | 124 is_encrypted_ = false; |
109 if (has_video()) { | 125 if (has_video()) { |
110 video_decoder_config_ = metadata.video_decoder_config; | 126 is_encrypted_ |= metadata.video_decoder_config.is_encrypted(); |
111 is_encrypted_ |= video_decoder_config_.is_encrypted(); | 127 pipeline_metadata_.natural_size = GetRotatedVideoSize( |
| 128 pipeline_metadata_.video_rotation, pipeline_metadata_.natural_size); |
112 } | 129 } |
113 if (has_audio()) { | 130 if (has_audio()) { |
114 audio_decoder_config_ = metadata.audio_decoder_config; | 131 is_encrypted_ |= metadata.audio_decoder_config.is_encrypted(); |
115 is_encrypted_ |= audio_decoder_config_.is_encrypted(); | |
116 } | 132 } |
| 133 |
| 134 if (pipeline_metadata_.natural_size != old_size) |
| 135 UpdateAndMaybeShowInterstitial(); |
| 136 |
117 UpdateAndMaybeSwitch(); | 137 UpdateAndMaybeSwitch(); |
118 } | 138 } |
119 | 139 |
120 bool RemotingRendererController::IsVideoCodecSupported() { | 140 bool RemotingRendererController::IsVideoCodecSupported() { |
121 DCHECK(thread_checker_.CalledOnValidThread()); | 141 DCHECK(thread_checker_.CalledOnValidThread()); |
122 DCHECK(has_video()); | 142 DCHECK(has_video()); |
123 | 143 |
124 switch (video_decoder_config_.codec()) { | 144 switch (pipeline_metadata_.video_decoder_config.codec()) { |
125 case VideoCodec::kCodecH264: | 145 case VideoCodec::kCodecH264: |
126 case VideoCodec::kCodecVP8: | 146 case VideoCodec::kCodecVP8: |
127 return true; | 147 return true; |
128 default: | 148 default: |
129 VLOG(2) << "Remoting does not support video codec: " | 149 VLOG(2) << "Remoting does not support video codec: " |
130 << video_decoder_config_.codec(); | 150 << pipeline_metadata_.video_decoder_config.codec(); |
131 return false; | 151 return false; |
132 } | 152 } |
133 } | 153 } |
134 | 154 |
135 bool RemotingRendererController::IsAudioCodecSupported() { | 155 bool RemotingRendererController::IsAudioCodecSupported() { |
136 DCHECK(thread_checker_.CalledOnValidThread()); | 156 DCHECK(thread_checker_.CalledOnValidThread()); |
137 DCHECK(has_audio()); | 157 DCHECK(has_audio()); |
138 | 158 |
139 switch (audio_decoder_config_.codec()) { | 159 switch (pipeline_metadata_.audio_decoder_config.codec()) { |
140 case AudioCodec::kCodecAAC: | 160 case AudioCodec::kCodecAAC: |
141 case AudioCodec::kCodecMP3: | 161 case AudioCodec::kCodecMP3: |
142 case AudioCodec::kCodecPCM: | 162 case AudioCodec::kCodecPCM: |
143 case AudioCodec::kCodecVorbis: | 163 case AudioCodec::kCodecVorbis: |
144 case AudioCodec::kCodecFLAC: | 164 case AudioCodec::kCodecFLAC: |
145 case AudioCodec::kCodecAMR_NB: | 165 case AudioCodec::kCodecAMR_NB: |
146 case AudioCodec::kCodecAMR_WB: | 166 case AudioCodec::kCodecAMR_WB: |
147 case AudioCodec::kCodecPCM_MULAW: | 167 case AudioCodec::kCodecPCM_MULAW: |
148 case AudioCodec::kCodecGSM_MS: | 168 case AudioCodec::kCodecGSM_MS: |
149 case AudioCodec::kCodecPCM_S16BE: | 169 case AudioCodec::kCodecPCM_S16BE: |
150 case AudioCodec::kCodecPCM_S24BE: | 170 case AudioCodec::kCodecPCM_S24BE: |
151 case AudioCodec::kCodecOpus: | 171 case AudioCodec::kCodecOpus: |
152 case AudioCodec::kCodecEAC3: | 172 case AudioCodec::kCodecEAC3: |
153 case AudioCodec::kCodecPCM_ALAW: | 173 case AudioCodec::kCodecPCM_ALAW: |
154 case AudioCodec::kCodecALAC: | 174 case AudioCodec::kCodecALAC: |
155 case AudioCodec::kCodecAC3: | 175 case AudioCodec::kCodecAC3: |
156 return true; | 176 return true; |
157 default: | 177 default: |
158 VLOG(2) << "Remoting does not support audio codec: " | 178 VLOG(2) << "Remoting does not support audio codec: " |
159 << audio_decoder_config_.codec(); | 179 << pipeline_metadata_.audio_decoder_config.codec(); |
160 return false; | 180 return false; |
161 } | 181 } |
162 } | 182 } |
163 | 183 |
164 bool RemotingRendererController::ShouldBeRemoting() { | 184 bool RemotingRendererController::ShouldBeRemoting() { |
165 DCHECK(thread_checker_.CalledOnValidThread()); | 185 DCHECK(thread_checker_.CalledOnValidThread()); |
166 | 186 |
167 if (switch_renderer_cb_.is_null()) | 187 if (switch_renderer_cb_.is_null()) |
168 return false; // No way to switch to a RemotingRenderImpl. | 188 return false; // No way to switch to a RemotingRenderImpl. |
169 | 189 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 251 } |
232 // |switch_renderer_cb_.Run()| will be called after remoting is started | 252 // |switch_renderer_cb_.Run()| will be called after remoting is started |
233 // successfully. | 253 // successfully. |
234 remoting_source_->StartRemoting(this); | 254 remoting_source_->StartRemoting(this); |
235 } else { | 255 } else { |
236 // For encrypted content, it's only valid to switch to remoting renderer, | 256 // For encrypted content, it's only valid to switch to remoting renderer, |
237 // and never back to the local renderer. The RemotingCdmController will | 257 // and never back to the local renderer. The RemotingCdmController will |
238 // force-stop the session when remoting has ended; so no need to call | 258 // force-stop the session when remoting has ended; so no need to call |
239 // StopRemoting() from here. | 259 // StopRemoting() from here. |
240 DCHECK(!is_encrypted_); | 260 DCHECK(!is_encrypted_); |
| 261 show_interstitial_cb_.Run(SkBitmap(), pipeline_metadata_.natural_size, |
| 262 RemotingInterstitialType::NONE); |
241 switch_renderer_cb_.Run(); | 263 switch_renderer_cb_.Run(); |
| 264 show_interstitial_cb_.Reset(); |
242 remoting_source_->StopRemoting(this); | 265 remoting_source_->StopRemoting(this); |
243 } | 266 } |
244 } | 267 } |
245 | 268 |
| 269 void RemotingRendererController::SetShowInterstitialCallback( |
| 270 const ShowInterstitialCallback& cb) { |
| 271 DCHECK(thread_checker_.CalledOnValidThread()); |
| 272 DCHECK(!cb.is_null()); |
| 273 DCHECK(show_interstitial_cb_.is_null()); |
| 274 show_interstitial_cb_ = cb; |
| 275 UpdateAndMaybeShowInterstitial(); |
| 276 } |
| 277 |
| 278 void RemotingRendererController::UpdateAndMaybeShowInterstitial() { |
| 279 DCHECK(thread_checker_.CalledOnValidThread()); |
| 280 if (show_interstitial_cb_.is_null() || |
| 281 pipeline_metadata_.natural_size.IsEmpty()) |
| 282 return; |
| 283 |
| 284 DCHECK(remote_rendering_started_); |
| 285 // TODO(xjz): Download poster image when available. |
| 286 show_interstitial_cb_.Run( |
| 287 SkBitmap(), pipeline_metadata_.natural_size, |
| 288 remoting_source_->state() == RemotingSessionState::SESSION_STARTED |
| 289 ? RemotingInterstitialType::SUCCESS |
| 290 : RemotingInterstitialType::FAIL); |
| 291 } |
| 292 |
246 } // namespace media | 293 } // namespace media |
OLD | NEW |