| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/cast/cast_sender_impl.h" | 5 #include "media/cast/cast_sender_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 scoped_refptr<CastEnvironment> cast_environment, | 100 scoped_refptr<CastEnvironment> cast_environment, |
| 101 CastTransportSender* const transport_sender) | 101 CastTransportSender* const transport_sender) |
| 102 : cast_environment_(cast_environment), | 102 : cast_environment_(cast_environment), |
| 103 transport_sender_(transport_sender), | 103 transport_sender_(transport_sender), |
| 104 weak_factory_(this) { | 104 weak_factory_(this) { |
| 105 CHECK(cast_environment.get()); | 105 CHECK(cast_environment.get()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void CastSenderImpl::InitializeAudio( | 108 void CastSenderImpl::InitializeAudio( |
| 109 const AudioSenderConfig& audio_config, | 109 const AudioSenderConfig& audio_config, |
| 110 const CastInitializationCallback& cast_initialization_cb) { | 110 const StatusChangeCallback& status_change_cb) { |
| 111 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 111 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 112 CHECK(audio_config.use_external_encoder || | 112 CHECK(audio_config.use_external_encoder || |
| 113 cast_environment_->HasAudioThread()); | 113 cast_environment_->HasAudioThread()); |
| 114 | 114 |
| 115 VLOG(1) << "CastSenderImpl@" << this << "::InitializeAudio()"; | 115 VLOG(1) << "CastSenderImpl@" << this << "::InitializeAudio()"; |
| 116 | 116 |
| 117 audio_sender_.reset( | 117 audio_sender_.reset( |
| 118 new AudioSender(cast_environment_, audio_config, transport_sender_)); | 118 new AudioSender(cast_environment_, |
| 119 | 119 audio_config, |
| 120 const CastInitializationStatus status = audio_sender_->InitializationResult(); | 120 base::Bind(&CastSenderImpl::OnAudioStatusChange, |
| 121 if (status == STATUS_AUDIO_INITIALIZED) { | 121 weak_factory_.GetWeakPtr(), |
| 122 audio_frame_input_ = | 122 status_change_cb), |
| 123 new LocalAudioFrameInput(cast_environment_, audio_sender_->AsWeakPtr()); | 123 transport_sender_)); |
| 124 } | |
| 125 cast_initialization_cb.Run(status); | |
| 126 if (video_sender_) { | 124 if (video_sender_) { |
| 127 DCHECK(audio_sender_->GetTargetPlayoutDelay() == | 125 DCHECK(audio_sender_->GetTargetPlayoutDelay() == |
| 128 video_sender_->GetTargetPlayoutDelay()); | 126 video_sender_->GetTargetPlayoutDelay()); |
| 129 } | 127 } |
| 130 } | 128 } |
| 131 | 129 |
| 132 void CastSenderImpl::InitializeVideo( | 130 void CastSenderImpl::InitializeVideo( |
| 133 const VideoSenderConfig& video_config, | 131 const VideoSenderConfig& video_config, |
| 134 const CastInitializationCallback& cast_initialization_cb, | 132 const StatusChangeCallback& status_change_cb, |
| 135 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, | 133 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, |
| 136 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb) { | 134 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb) { |
| 137 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 135 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 138 | 136 |
| 139 VLOG(1) << "CastSenderImpl@" << this << "::InitializeVideo()"; | 137 VLOG(1) << "CastSenderImpl@" << this << "::InitializeVideo()"; |
| 140 | 138 |
| 141 video_sender_.reset(new VideoSender( | 139 video_sender_.reset(new VideoSender( |
| 142 cast_environment_, | 140 cast_environment_, |
| 143 video_config, | 141 video_config, |
| 144 base::Bind(&CastSenderImpl::OnVideoInitialized, | 142 base::Bind(&CastSenderImpl::OnVideoStatusChange, |
| 145 weak_factory_.GetWeakPtr(), cast_initialization_cb), | 143 weak_factory_.GetWeakPtr(), |
| 144 status_change_cb), |
| 146 create_vea_cb, | 145 create_vea_cb, |
| 147 create_video_encode_mem_cb, | 146 create_video_encode_mem_cb, |
| 148 transport_sender_, | 147 transport_sender_, |
| 149 base::Bind(&CastSenderImpl::SetTargetPlayoutDelay, | 148 base::Bind(&CastSenderImpl::SetTargetPlayoutDelay, |
| 150 weak_factory_.GetWeakPtr()))); | 149 weak_factory_.GetWeakPtr()))); |
| 151 if (audio_sender_) { | 150 if (audio_sender_) { |
| 152 DCHECK(audio_sender_->GetTargetPlayoutDelay() == | 151 DCHECK(audio_sender_->GetTargetPlayoutDelay() == |
| 153 video_sender_->GetTargetPlayoutDelay()); | 152 video_sender_->GetTargetPlayoutDelay()); |
| 154 } | 153 } |
| 155 } | 154 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 171 VLOG(1) << "CastSenderImpl@" << this << "::SetTargetPlayoutDelay(" | 170 VLOG(1) << "CastSenderImpl@" << this << "::SetTargetPlayoutDelay(" |
| 172 << new_target_playout_delay.InMilliseconds() << " ms)"; | 171 << new_target_playout_delay.InMilliseconds() << " ms)"; |
| 173 if (audio_sender_) { | 172 if (audio_sender_) { |
| 174 audio_sender_->SetTargetPlayoutDelay(new_target_playout_delay); | 173 audio_sender_->SetTargetPlayoutDelay(new_target_playout_delay); |
| 175 } | 174 } |
| 176 if (video_sender_) { | 175 if (video_sender_) { |
| 177 video_sender_->SetTargetPlayoutDelay(new_target_playout_delay); | 176 video_sender_->SetTargetPlayoutDelay(new_target_playout_delay); |
| 178 } | 177 } |
| 179 } | 178 } |
| 180 | 179 |
| 181 void CastSenderImpl::OnVideoInitialized( | 180 void CastSenderImpl::OnAudioStatusChange( |
| 182 const CastInitializationCallback& initialization_cb, | 181 const StatusChangeCallback& status_change_cb, |
| 183 media::cast::CastInitializationStatus result) { | 182 OperationalStatus status) { |
| 184 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 183 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 185 if (result == STATUS_VIDEO_INITIALIZED) { | 184 if (status == STATUS_INITIALIZED && !audio_frame_input_) { |
| 185 audio_frame_input_ = |
| 186 new LocalAudioFrameInput(cast_environment_, audio_sender_->AsWeakPtr()); |
| 187 } |
| 188 status_change_cb.Run(status); |
| 189 } |
| 190 |
| 191 void CastSenderImpl::OnVideoStatusChange( |
| 192 const StatusChangeCallback& status_change_cb, |
| 193 OperationalStatus status) { |
| 194 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 195 if (status == STATUS_INITIALIZED && !video_frame_input_) { |
| 186 video_frame_input_ = | 196 video_frame_input_ = |
| 187 new LocalVideoFrameInput(cast_environment_, video_sender_->AsWeakPtr(), | 197 new LocalVideoFrameInput(cast_environment_, video_sender_->AsWeakPtr(), |
| 188 video_sender_->CreateVideoFrameFactory()); | 198 video_sender_->CreateVideoFrameFactory()); |
| 189 } | 199 } |
| 190 initialization_cb.Run(result); | 200 status_change_cb.Run(status); |
| 191 } | 201 } |
| 192 | 202 |
| 193 } // namespace cast | 203 } // namespace cast |
| 194 } // namespace media | 204 } // namespace media |
| OLD | NEW |