Chromium Code Reviews| 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 if (should_be_remoting && is_paused_) | |
|
miu
2016/12/19 22:56:53
Let's add a comment to explain why this is good fo
xjz
2016/12/20 00:12:36
Done.
| |
| 282 return; // Only switches to remoting when media is playing. | |
|
miu
2016/12/19 22:56:53
s/switches/switch/
xjz
2016/12/20 00:12:36
Done.
| |
| 283 | |
| 268 // Switch between local renderer and remoting renderer. | 284 // Switch between local renderer and remoting renderer. |
| 269 remote_rendering_started_ = should_be_remoting; | 285 remote_rendering_started_ = should_be_remoting; |
| 270 | 286 |
| 271 if (remote_rendering_started_) { | 287 if (remote_rendering_started_) { |
| 272 DCHECK(!switch_renderer_cb_.is_null()); | 288 DCHECK(!switch_renderer_cb_.is_null()); |
| 273 if (remoting_source_->state() == | 289 if (remoting_source_->state() == |
| 274 RemotingSessionState::SESSION_PERMANENTLY_STOPPED) { | 290 RemotingSessionState::SESSION_PERMANENTLY_STOPPED) { |
| 275 switch_renderer_cb_.Run(); | 291 switch_renderer_cb_.Run(); |
| 276 return; | 292 return; |
| 277 } | 293 } |
| 278 // |switch_renderer_cb_.Run()| will be called after remoting is started | 294 // |switch_renderer_cb_.Run()| will be called after remoting is started |
| 279 // successfully. | 295 // successfully. |
| 280 remoting_source_->StartRemoting(this); | 296 remoting_source_->StartRemoting(this); |
| 281 } else { | 297 } else { |
| 282 // For encrypted content, it's only valid to switch to remoting renderer, | 298 // For encrypted content, it's only valid to switch to remoting renderer, |
| 283 // and never back to the local renderer. The RemotingCdmController will | 299 // and never back to the local renderer. The RemotingCdmController will |
| 284 // force-stop the session when remoting has ended; so no need to call | 300 // force-stop the session when remoting has ended; so no need to call |
| 285 // StopRemoting() from here. | 301 // StopRemoting() from here. |
| 286 DCHECK(!is_encrypted_); | 302 DCHECK(!is_encrypted_); |
| 287 switch_renderer_cb_.Run(); | 303 switch_renderer_cb_.Run(); |
| 288 remoting_source_->StopRemoting(this); | 304 remoting_source_->StopRemoting(this); |
| 289 } | 305 } |
| 290 } | 306 } |
| 291 | 307 |
| 292 } // namespace media | 308 } // namespace media |
| OLD | NEW |