Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/remoting/remoting_controller.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "media/base/bind_to_current_loop.h" | |
| 9 | |
| 10 namespace media { | |
| 11 | |
| 12 RemotingController::RemotingController(mojom::RemoterFactory* remoter_factory) | |
| 13 : is_fullscreen_(false), | |
| 14 is_sink_available_(false), | |
| 15 use_remoting_renderer_(false), | |
| 16 binding_(this), | |
| 17 task_runner_(base::ThreadTaskRunnerHandle::Get()) { | |
| 18 remoter_factory->Create(binding_.CreateInterfacePtrAndBind(), | |
|
miu
2016/09/28 07:23:09
This issue came up on Eric's change: We should be
xjz
2016/09/29 22:54:22
As discussed offline, keep this on main thread for
| |
| 19 mojo::GetProxy(&remoter_)); | |
| 20 } | |
| 21 | |
| 22 RemotingController::~RemotingController() {} | |
| 23 | |
| 24 void RemotingController::OnSinkAvailable() { | |
| 25 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 26 | |
| 27 is_sink_available_ = true; | |
| 28 Update(); | |
| 29 } | |
| 30 | |
| 31 void RemotingController::OnSinkGone() { | |
| 32 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 33 | |
| 34 is_sink_available_ = false; | |
| 35 Update(); | |
| 36 } | |
| 37 | |
| 38 void RemotingController::OnStarted() { | |
| 39 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 40 | |
| 41 VLOG(1) << "Remoting started successively."; | |
| 42 if (use_remoting_renderer_) { | |
| 43 if (!switch_renderer_cb_.is_null()) | |
| 44 switch_renderer_cb_.Run(); | |
| 45 } else { | |
| 46 remoter_->Stop(mojom::RemotingStopReason::LOCAL_PLAYBACK); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 void RemotingController::OnStartFailed(mojom::RemotingStartFailReason reason) { | |
| 51 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 52 | |
| 53 VLOG(1) << "Failed to start remoting: " << reason; | |
| 54 use_remoting_renderer_ = false; | |
| 55 } | |
| 56 | |
| 57 void RemotingController::OnMessageFromSink( | |
| 58 const std::vector<uint8_t>& message) { | |
| 59 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 60 // TODO(xjz): Merge with Eric's CL to handle the RPC messages here. | |
| 61 } | |
| 62 | |
| 63 void RemotingController::OnStopped(mojom::RemotingStopReason reason) { | |
| 64 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 65 | |
| 66 VLOG(1) << "Remoting stopped: " << reason; | |
| 67 if (use_remoting_renderer_) | |
| 68 remoter_->Start(); | |
|
miu
2016/09/28 01:33:32
Thinking aloud: Maybe this method should just set
xjz
2016/09/29 22:54:22
Done.
| |
| 69 } | |
| 70 | |
| 71 void RemotingController::OnEnteredFullscreen() { | |
| 72 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 73 is_fullscreen_ = true; | |
| 74 Update(); | |
| 75 } | |
| 76 | |
| 77 void RemotingController::OnExitedFullscreen() { | |
| 78 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 79 is_fullscreen_ = false; | |
| 80 Update(); | |
| 81 } | |
| 82 | |
| 83 void RemotingController::OnSetCdm(CdmContext* cdm_context) { | |
| 84 // TODO(xjz): Not implemented. Will add in up-coming change. | |
|
miu
2016/09/28 01:33:32
Note: Please use the NOTIMPLEMENTED() logging macr
xjz
2016/09/29 22:54:22
Done.
| |
| 85 } | |
| 86 | |
| 87 void RemotingController::SetSwitchRenderCallback( | |
| 88 const RendererController::SwitchRendererCallback& cb) { | |
| 89 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 90 DCHECK(!cb.is_null()); | |
| 91 | |
| 92 switch_renderer_cb_ = BindToCurrentLoop(cb); | |
| 93 } | |
| 94 | |
| 95 void RemotingController::OnSetDecoderConfig( | |
| 96 const AudioDecoderConfig& audio_config, | |
| 97 const VideoDecoderConfig& video_config) { | |
| 98 audio_decoder_config_ = audio_config; | |
|
miu
2016/09/28 01:33:32
Please add DCHECK(task_runner->Belongs()) here.
B
xjz
2016/09/29 22:54:21
Done.
| |
| 99 video_decoder_config_ = video_config; | |
| 100 Update(); | |
| 101 } | |
| 102 | |
| 103 bool RemotingController::isVideoConfigSupported() { | |
| 104 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 105 | |
| 106 if (!video_decoder_config_.IsValidConfig()) | |
| 107 return false; | |
| 108 | |
| 109 switch (video_decoder_config_.codec()) { | |
| 110 case VideoCodec::kCodecH264: | |
| 111 case VideoCodec::kCodecVP8: | |
| 112 return true; | |
| 113 default: | |
| 114 VLOG(2) << "Remoting does not support video codec: " | |
| 115 << video_decoder_config_.codec(); | |
| 116 return false; | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 bool RemotingController::isAudioConfigSupported() { | |
| 121 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 122 | |
| 123 if (!audio_decoder_config_.IsValidConfig()) | |
| 124 return false; | |
| 125 | |
| 126 switch (audio_decoder_config_.codec()) { | |
| 127 case AudioCodec::kCodecAAC: | |
| 128 case AudioCodec::kCodecMP3: | |
| 129 case AudioCodec::kCodecPCM: | |
| 130 case AudioCodec::kCodecVorbis: | |
| 131 case AudioCodec::kCodecFLAC: | |
| 132 case AudioCodec::kCodecAMR_NB: | |
| 133 case AudioCodec::kCodecAMR_WB: | |
| 134 case AudioCodec::kCodecPCM_MULAW: | |
| 135 case AudioCodec::kCodecGSM_MS: | |
| 136 case AudioCodec::kCodecPCM_S16BE: | |
| 137 case AudioCodec::kCodecPCM_S24BE: | |
| 138 case AudioCodec::kCodecOpus: | |
| 139 case AudioCodec::kCodecEAC3: | |
| 140 case AudioCodec::kCodecPCM_ALAW: | |
| 141 case AudioCodec::kCodecALAC: | |
| 142 case AudioCodec::kCodecAC3: | |
| 143 return true; | |
| 144 default: | |
| 145 VLOG(2) << "Remoting does not support audio codec: " | |
| 146 << audio_decoder_config_.codec(); | |
| 147 return false; | |
| 148 } | |
| 149 } | |
| 150 | |
| 151 void RemotingController::Update() { | |
| 152 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 153 | |
| 154 // TODO(xjz): The swithcing logic for encrypted content will be added in a | |
|
miu
2016/09/28 01:33:32
typo: s/swithcing/switching/
xjz
2016/09/29 22:54:21
Done.
| |
| 155 // later CL. | |
| 156 if (video_decoder_config_.is_encrypted()) | |
|
miu
2016/09/28 01:33:32
Instead of returning early, I'd suggest you add it
xjz
2016/09/29 22:54:22
Done.
| |
| 157 return; | |
| 158 | |
| 159 bool should_remoting = is_sink_available_ && is_fullscreen_ && | |
|
miu
2016/09/28 01:33:32
naming: should_be_remoting
xjz
2016/09/29 22:54:21
Done.
| |
| 160 isVideoConfigSupported() && isAudioConfigSupported(); | |
| 161 if (use_remoting_renderer_ == should_remoting) | |
| 162 return; | |
| 163 | |
| 164 // Switch between local and remoting. | |
| 165 use_remoting_renderer_ = should_remoting; | |
| 166 if (use_remoting_renderer_) { | |
| 167 remoter_->Start(); | |
| 168 } else { | |
| 169 if (!switch_renderer_cb_.is_null()) | |
|
miu
2016/09/28 01:33:32
In the "should" boolean above, I'd suggest adding:
xjz
2016/09/29 22:54:22
Done.
| |
| 170 switch_renderer_cb_.Run(); | |
| 171 // TODO(xjz): Send RPC message to notify ChromeCast. | |
| 172 remoter_->Stop(mojom::RemotingStopReason::LOCAL_PLAYBACK); | |
| 173 } | |
| 174 } | |
| 175 | |
| 176 bool RemotingController::ShouldUseRemotingRenderer() { | |
| 177 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 178 | |
| 179 return use_remoting_renderer_; | |
| 180 } | |
| 181 | |
| 182 } // namespace media | |
| OLD | NEW |