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_renderer_controller.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/threading/thread_checker.h" | |
| 10 #include "media/remoting/remoting_cdm.h" | |
| 11 | |
| 12 namespace media { | |
| 13 | |
| 14 RemotingRendererController::RemotingRendererController( | |
| 15 scoped_refptr<RemotingSourceImpl> remoting_source) | |
| 16 : remoting_source_(remoting_source), weak_factory_(this) { | |
| 17 remoting_source_->AddClient(this); | |
| 18 } | |
| 19 | |
| 20 RemotingRendererController::~RemotingRendererController() { | |
| 21 remoting_source_->RemoveClient(this); | |
|
miu
2016/10/25 04:21:26
Above this line: DCHECK(thread_checker_.CalledOnVa
xjz
2016/10/26 22:00:26
Done.
| |
| 22 } | |
| 23 | |
| 24 void RemotingRendererController::OnStarted(bool success) { | |
| 25 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 26 | |
| 27 if (success) { | |
| 28 VLOG(1) << "Remoting started successively."; | |
| 29 if (should_be_remoting_) | |
| 30 switch_renderer_cb_.Run(); | |
|
miu
2016/10/25 04:21:26
For safety, you might want to guard this:
if (!
xjz
2016/10/26 22:00:26
This callback should never be null here. Added DCH
| |
| 31 else | |
| 32 remoting_source_->StopRemoting(this); | |
| 33 } else { | |
| 34 VLOG(1) << "Failed to start remoting."; | |
| 35 should_be_remoting_ = false; | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 void RemotingRendererController::OnSessionStateChanged() { | |
| 40 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 41 | |
| 42 VLOG(1) << "OnSessionStateChanged: " << remoting_source_->state(); | |
| 43 bool can_start_remoting = can_start_remoting_; | |
|
miu
2016/10/25 04:21:26
naming nits: The class data member |can_start_remo
xjz
2016/10/26 22:00:26
Done.
| |
| 44 switch (remoting_source_->state()) { | |
| 45 case SESSION_CAN_START: | |
| 46 case SESSION_STARTING: | |
| 47 case SESSION_STARTED: | |
| 48 can_start_remoting_ = true; | |
| 49 break; | |
| 50 case SESSION_STOPPING: | |
| 51 case SESSION_UNAVAILABLE: | |
| 52 case SESSION_PERMANENTLY_STOPPED: | |
| 53 can_start_remoting_ = false; | |
| 54 break; | |
| 55 } | |
| 56 if (can_start_remoting_ != can_start_remoting) | |
| 57 UpdateAndMaybeSwitch(); | |
| 58 } | |
| 59 | |
| 60 void RemotingRendererController::OnEnteredFullscreen() { | |
| 61 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 62 | |
| 63 is_fullscreen_ = true; | |
| 64 UpdateAndMaybeSwitch(); | |
| 65 } | |
| 66 | |
| 67 void RemotingRendererController::OnExitedFullscreen() { | |
| 68 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 69 | |
| 70 is_fullscreen_ = false; | |
| 71 UpdateAndMaybeSwitch(); | |
| 72 } | |
| 73 | |
| 74 void RemotingRendererController::OnSetCdm(CdmContext* cdm_context) { | |
| 75 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 76 | |
| 77 auto* cdm = RemotingCdm::From(cdm_context); | |
| 78 if (!cdm) | |
| 79 return; | |
| 80 | |
| 81 remoting_source_ = cdm->GetRemotingSource(); | |
| 82 remoting_source_->AddClient(this); | |
|
miu
2016/10/25 04:21:26
Suggest adding this helpful comment for readabilit
xjz
2016/10/26 22:00:26
Done.
| |
| 83 UpdateAndMaybeSwitch(); | |
| 84 } | |
| 85 | |
| 86 void RemotingRendererController::SetSwitchRendererCallback( | |
| 87 const SwitchRendererCallback& cb) { | |
| 88 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 89 DCHECK(!cb.is_null()); | |
| 90 | |
| 91 switch_renderer_cb_ = cb; | |
| 92 UpdateAndMaybeSwitch(); | |
| 93 } | |
| 94 | |
| 95 void RemotingRendererController::OnMetadataChanged( | |
| 96 const PipelineMetadata& metadata) { | |
| 97 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 98 | |
| 99 has_video_ = | |
| 100 metadata.has_video && metadata.video_decoder_config.IsValidConfig(); | |
| 101 has_audio_ = | |
| 102 metadata.has_audio && metadata.audio_decoder_config.IsValidConfig(); | |
| 103 if (!has_video_ && !has_audio_) | |
| 104 return; | |
|
miu
2016/10/25 04:21:26
I think you should remove the early return here. L
xjz
2016/10/26 22:00:26
Done.
| |
| 105 | |
| 106 if (has_video_) { | |
|
miu
2016/10/25 04:21:26
Before this line, add:
is_encrypted_ = false;
xjz
2016/10/26 22:00:26
Done.
| |
| 107 video_decoder_config_ = metadata.video_decoder_config; | |
| 108 is_encrypted_ |= video_decoder_config_.is_encrypted(); | |
| 109 } | |
| 110 if (has_audio_) { | |
| 111 audio_decoder_config_ = metadata.audio_decoder_config; | |
| 112 is_encrypted_ |= audio_decoder_config_.is_encrypted(); | |
| 113 } | |
| 114 UpdateAndMaybeSwitch(); | |
| 115 } | |
| 116 | |
| 117 bool RemotingRendererController::IsVideoCodecSupported() { | |
| 118 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 119 DCHECK(has_video_); | |
| 120 | |
| 121 switch (video_decoder_config_.codec()) { | |
| 122 case VideoCodec::kCodecH264: | |
| 123 case VideoCodec::kCodecVP8: | |
| 124 return true; | |
| 125 default: | |
| 126 VLOG(2) << "Remoting does not support video codec: " | |
| 127 << video_decoder_config_.codec(); | |
| 128 return false; | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 bool RemotingRendererController::IsAudioCodecSupported() { | |
| 133 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 134 DCHECK(has_audio_); | |
| 135 | |
| 136 switch (audio_decoder_config_.codec()) { | |
| 137 case AudioCodec::kCodecAAC: | |
| 138 case AudioCodec::kCodecMP3: | |
| 139 case AudioCodec::kCodecPCM: | |
| 140 case AudioCodec::kCodecVorbis: | |
| 141 case AudioCodec::kCodecFLAC: | |
| 142 case AudioCodec::kCodecAMR_NB: | |
| 143 case AudioCodec::kCodecAMR_WB: | |
| 144 case AudioCodec::kCodecPCM_MULAW: | |
| 145 case AudioCodec::kCodecGSM_MS: | |
| 146 case AudioCodec::kCodecPCM_S16BE: | |
| 147 case AudioCodec::kCodecPCM_S24BE: | |
| 148 case AudioCodec::kCodecOpus: | |
| 149 case AudioCodec::kCodecEAC3: | |
| 150 case AudioCodec::kCodecPCM_ALAW: | |
| 151 case AudioCodec::kCodecALAC: | |
| 152 case AudioCodec::kCodecAC3: | |
| 153 return true; | |
| 154 default: | |
| 155 VLOG(2) << "Remoting does not support audio codec: " | |
| 156 << audio_decoder_config_.codec(); | |
| 157 return false; | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 bool RemotingRendererController::ShouldBeRemoting() { | |
| 162 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 163 | |
| 164 if (!can_start_remoting_) | |
| 165 return false; | |
| 166 if (has_video_ && !IsVideoCodecSupported()) | |
|
miu
2016/10/25 04:21:26
Before this, I think you should add (this will sim
xjz
2016/10/26 22:00:26
Done.
| |
| 167 return false; | |
| 168 if (has_audio_ && !IsAudioCodecSupported()) | |
| 169 return false; | |
| 170 if (is_encrypted_) | |
| 171 return remoting_source_->state() == RemotingSessionState::SESSION_STARTED; | |
|
miu
2016/10/25 04:21:26
Consider adding a comment like: "Explicitly ignori
xjz
2016/10/26 22:00:26
Done.
| |
| 172 return is_fullscreen_; | |
| 173 } | |
| 174 | |
| 175 void RemotingRendererController::UpdateAndMaybeSwitch() { | |
| 176 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 177 | |
| 178 if (switch_renderer_cb_.is_null()) | |
| 179 return; | |
| 180 | |
| 181 // Demuxer is not initialized yet. | |
| 182 if (!has_audio_ && !has_video_) | |
| 183 return; | |
|
miu
2016/10/25 04:21:26
If you take my suggestions in ShouldBeRemoting() (
xjz
2016/10/26 22:00:26
Done.
| |
| 184 | |
| 185 bool should_be_remoting = ShouldBeRemoting(); | |
| 186 if (should_be_remoting_ == should_be_remoting) | |
| 187 return; | |
| 188 | |
| 189 // Switch between local renderer and remoting renderer. | |
| 190 should_be_remoting_ = should_be_remoting; | |
| 191 | |
| 192 if (should_be_remoting_) { | |
| 193 // |switch_renderer_cb_.Run()| will be called after remoting is started | |
| 194 // successfully. | |
| 195 remoting_source_->StartRemoting(this); | |
| 196 } else { | |
| 197 switch_renderer_cb_.Run(); | |
| 198 remoting_source_->StopRemoting(this); | |
| 199 } | |
| 200 } | |
| 201 | |
| 202 bool RemotingRendererController::IsRemoting() const { | |
| 203 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 204 | |
| 205 return should_be_remoting_; | |
| 206 } | |
| 207 | |
| 208 bool RemotingRendererController::IsTerminated() const { | |
| 209 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 210 | |
| 211 return remoting_source_->state() == | |
| 212 RemotingSessionState::SESSION_PERMANENTLY_STOPPED; | |
| 213 } | |
| 214 | |
| 215 } // namespace media | |
| OLD | NEW |