| 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_controller.h" | 5 #include "media/remoting/remoting_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 UpdateAndMaybeSwitch(); | 135 UpdateAndMaybeSwitch(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void RemotingController::OnExitedFullscreen() { | 138 void RemotingController::OnExitedFullscreen() { |
| 139 DCHECK(task_runner_->BelongsToCurrentThread()); | 139 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 140 | 140 |
| 141 is_fullscreen_ = false; | 141 is_fullscreen_ = false; |
| 142 UpdateAndMaybeSwitch(); | 142 UpdateAndMaybeSwitch(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void RemotingController::OnVideoViewportRatioChanged(double ratio) { |
| 146 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 147 |
| 148 // Reset on any notification, since this indicates the user is scrolling |
| 149 // around in the document, the document is changing layout, etc. |
| 150 viewport_fill_debouncer_timer_.Stop(); |
| 151 |
| 152 // Dropping below the threshold should instantly stop remote rendering. |
| 153 if (ratio < 0.85) { |
| 154 if (is_mostly_filling_viewport_) { |
| 155 is_mostly_filling_viewport_ = false; |
| 156 UpdateAndMaybeSwitch(); |
| 157 } |
| 158 return; |
| 159 } |
| 160 |
| 161 // Meeting/Exceeding the threshold should hold steady for 5 seconds before |
| 162 // starting remote rendering. |
| 163 if (!is_mostly_filling_viewport_) { |
| 164 viewport_fill_debouncer_timer_.Start( |
| 165 FROM_HERE, base::TimeDelta::FromSeconds(5), |
| 166 base::Bind(&RemotingController::OnViewportMostlyFilledAndUnchanging, |
| 167 weak_factory_.GetWeakPtr())); |
| 168 } |
| 169 } |
| 170 |
| 171 void RemotingController::OnViewportMostlyFilledAndUnchanging() { |
| 172 is_mostly_filling_viewport_ = true; |
| 173 UpdateAndMaybeSwitch(); |
| 174 } |
| 175 |
| 145 void RemotingController::OnSetCdm(CdmContext* cdm_context) { | 176 void RemotingController::OnSetCdm(CdmContext* cdm_context) { |
| 146 DCHECK(task_runner_->BelongsToCurrentThread()); | 177 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 147 | 178 |
| 148 // TODO(xjz): Not implemented. Will add in up-coming change. | 179 // TODO(xjz): Not implemented. Will add in up-coming change. |
| 149 NOTIMPLEMENTED(); | 180 NOTIMPLEMENTED(); |
| 150 } | 181 } |
| 151 | 182 |
| 152 void RemotingController::SetSwitchRendererCallback( | 183 void RemotingController::SetSwitchRendererCallback( |
| 153 const SwitchRendererCallback& cb) { | 184 const SwitchRendererCallback& cb) { |
| 154 DCHECK(task_runner_->BelongsToCurrentThread()); | 185 DCHECK(task_runner_->BelongsToCurrentThread()); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 | 256 |
| 226 bool RemotingController::ShouldBeRemoting() { | 257 bool RemotingController::ShouldBeRemoting() { |
| 227 DCHECK(task_runner_->BelongsToCurrentThread()); | 258 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 228 | 259 |
| 229 // TODO(xjz): The control logic for EME will be added in a later CL. | 260 // TODO(xjz): The control logic for EME will be added in a later CL. |
| 230 if (is_encrypted_) | 261 if (is_encrypted_) |
| 231 return false; | 262 return false; |
| 232 | 263 |
| 233 if (!is_sink_available_) | 264 if (!is_sink_available_) |
| 234 return false; | 265 return false; |
| 235 if (!is_fullscreen_) | |
| 236 return false; | |
| 237 if (has_video_ && !IsVideoCodecSupported()) | 266 if (has_video_ && !IsVideoCodecSupported()) |
| 238 return false; | 267 return false; |
| 239 if (has_audio_ && !IsAudioCodecSupported()) | 268 if (has_audio_ && !IsAudioCodecSupported()) |
| 240 return false; | 269 return false; |
| 241 return true; | 270 return is_fullscreen_ || is_mostly_filling_viewport_; |
| 242 } | 271 } |
| 243 | 272 |
| 244 void RemotingController::UpdateAndMaybeSwitch() { | 273 void RemotingController::UpdateAndMaybeSwitch() { |
| 245 DCHECK(task_runner_->BelongsToCurrentThread()); | 274 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 246 | 275 |
| 247 // TODO(xjz): The switching logic for encrypted content will be added in a | 276 // TODO(xjz): The switching logic for encrypted content will be added in a |
| 248 // later CL. | 277 // later CL. |
| 249 | 278 |
| 250 // Demuxer is not initialized yet. | 279 // Demuxer is not initialized yet. |
| 251 if (!has_audio_ && !has_video_) | 280 if (!has_audio_ && !has_video_) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 263 // |swithc_renderer_cb_.Run()| will be called after remoting is started | 292 // |swithc_renderer_cb_.Run()| will be called after remoting is started |
| 264 // successfully. | 293 // successfully. |
| 265 remoter_->Start(); | 294 remoter_->Start(); |
| 266 } else { | 295 } else { |
| 267 switch_renderer_cb_.Run(); | 296 switch_renderer_cb_.Run(); |
| 268 remoter_->Stop(mojom::RemotingStopReason::LOCAL_PLAYBACK); | 297 remoter_->Stop(mojom::RemotingStopReason::LOCAL_PLAYBACK); |
| 269 } | 298 } |
| 270 } | 299 } |
| 271 | 300 |
| 272 } // namespace media | 301 } // namespace media |
| OLD | NEW |