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/remoting/remoting_cdm_context.h" | 10 #include "media/remoting/remoting_cdm_context.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 case AudioCodec::kCodecALAC: | 197 case AudioCodec::kCodecALAC: |
198 case AudioCodec::kCodecAC3: | 198 case AudioCodec::kCodecAC3: |
199 return true; | 199 return true; |
200 default: | 200 default: |
201 VLOG(2) << "Remoting does not support audio codec: " | 201 VLOG(2) << "Remoting does not support audio codec: " |
202 << audio_decoder_config_.codec(); | 202 << audio_decoder_config_.codec(); |
203 return false; | 203 return false; |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
| 207 void RemotingRendererController::OnPlaying() { |
| 208 DCHECK(thread_checker_.CalledOnValidThread()); |
| 209 |
| 210 is_paused_ = false; |
| 211 UpdateAndMaybeSwitch(); |
| 212 } |
| 213 |
| 214 void RemotingRendererController::OnPaused() { |
| 215 DCHECK(thread_checker_.CalledOnValidThread()); |
| 216 |
| 217 is_paused_ = true; |
| 218 } |
| 219 |
207 bool RemotingRendererController::ShouldBeRemoting() { | 220 bool RemotingRendererController::ShouldBeRemoting() { |
208 DCHECK(thread_checker_.CalledOnValidThread()); | 221 DCHECK(thread_checker_.CalledOnValidThread()); |
209 | 222 |
210 if (switch_renderer_cb_.is_null()) | 223 if (switch_renderer_cb_.is_null()) |
211 return false; // No way to switch to a RemotingRenderImpl. | 224 return false; // No way to switch to a RemotingRenderImpl. |
212 | 225 |
213 const RemotingSessionState state = remoting_source_->state(); | 226 const RemotingSessionState state = remoting_source_->state(); |
214 if (is_encrypted_) { | 227 if (is_encrypted_) { |
215 // Due to technical limitations when playing encrypted content, once a | 228 // Due to technical limitations when playing encrypted content, once a |
216 // remoting session has been started, always return true here to indicate | 229 // remoting session has been started, always return true here to indicate |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 } | 271 } |
259 | 272 |
260 void RemotingRendererController::UpdateAndMaybeSwitch() { | 273 void RemotingRendererController::UpdateAndMaybeSwitch() { |
261 DCHECK(thread_checker_.CalledOnValidThread()); | 274 DCHECK(thread_checker_.CalledOnValidThread()); |
262 | 275 |
263 bool should_be_remoting = ShouldBeRemoting(); | 276 bool should_be_remoting = ShouldBeRemoting(); |
264 | 277 |
265 if (remote_rendering_started_ == should_be_remoting) | 278 if (remote_rendering_started_ == should_be_remoting) |
266 return; | 279 return; |
267 | 280 |
| 281 // Only switch to remoting when media is playing. Since the renderer is |
| 282 // created when video starts loading/playing, receiver will display a black |
| 283 // screen before video starts playing if switching to remoting when paused. |
| 284 // Keep mirroring the video in this case is good for the user experience. |
| 285 if (should_be_remoting && is_paused_) |
| 286 return; |
| 287 |
268 // Switch between local renderer and remoting renderer. | 288 // Switch between local renderer and remoting renderer. |
269 remote_rendering_started_ = should_be_remoting; | 289 remote_rendering_started_ = should_be_remoting; |
270 | 290 |
271 if (remote_rendering_started_) { | 291 if (remote_rendering_started_) { |
272 DCHECK(!switch_renderer_cb_.is_null()); | 292 DCHECK(!switch_renderer_cb_.is_null()); |
273 if (remoting_source_->state() == | 293 if (remoting_source_->state() == |
274 RemotingSessionState::SESSION_PERMANENTLY_STOPPED) { | 294 RemotingSessionState::SESSION_PERMANENTLY_STOPPED) { |
275 switch_renderer_cb_.Run(); | 295 switch_renderer_cb_.Run(); |
276 return; | 296 return; |
277 } | 297 } |
278 // |switch_renderer_cb_.Run()| will be called after remoting is started | 298 // |switch_renderer_cb_.Run()| will be called after remoting is started |
279 // successfully. | 299 // successfully. |
280 remoting_source_->StartRemoting(this); | 300 remoting_source_->StartRemoting(this); |
281 } else { | 301 } else { |
282 // For encrypted content, it's only valid to switch to remoting renderer, | 302 // For encrypted content, it's only valid to switch to remoting renderer, |
283 // and never back to the local renderer. The RemotingCdmController will | 303 // and never back to the local renderer. The RemotingCdmController will |
284 // force-stop the session when remoting has ended; so no need to call | 304 // force-stop the session when remoting has ended; so no need to call |
285 // StopRemoting() from here. | 305 // StopRemoting() from here. |
286 DCHECK(!is_encrypted_); | 306 DCHECK(!is_encrypted_); |
287 switch_renderer_cb_.Run(); | 307 switch_renderer_cb_.Run(); |
288 remoting_source_->StopRemoting(this); | 308 remoting_source_->StopRemoting(this); |
289 } | 309 } |
290 } | 310 } |
291 | 311 |
292 } // namespace media | 312 } // namespace media |
OLD | NEW |