| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/api/rtpsender.h" | 11 #include "webrtc/api/rtpsender.h" |
| 12 | 12 |
| 13 #include "webrtc/api/localaudiosource.h" | 13 #include "webrtc/api/localaudiosource.h" |
| 14 #include "webrtc/api/mediastreaminterface.h" | 14 #include "webrtc/api/mediastreaminterface.h" |
| 15 #include "webrtc/base/helpers.h" | 15 #include "webrtc/base/helpers.h" |
| 16 #include "webrtc/base/trace_event.h" |
| 16 | 17 |
| 17 namespace webrtc { | 18 namespace webrtc { |
| 18 | 19 |
| 19 LocalAudioSinkAdapter::LocalAudioSinkAdapter() : sink_(nullptr) {} | 20 LocalAudioSinkAdapter::LocalAudioSinkAdapter() : sink_(nullptr) {} |
| 20 | 21 |
| 21 LocalAudioSinkAdapter::~LocalAudioSinkAdapter() { | 22 LocalAudioSinkAdapter::~LocalAudioSinkAdapter() { |
| 22 rtc::CritScope lock(&lock_); | 23 rtc::CritScope lock(&lock_); |
| 23 if (sink_) | 24 if (sink_) |
| 24 sink_->OnClose(); | 25 sink_->OnClose(); |
| 25 } | 26 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 stream_id_(rtc::CreateRandomUuid()), | 80 stream_id_(rtc::CreateRandomUuid()), |
| 80 provider_(provider), | 81 provider_(provider), |
| 81 stats_(stats), | 82 stats_(stats), |
| 82 sink_adapter_(new LocalAudioSinkAdapter()) {} | 83 sink_adapter_(new LocalAudioSinkAdapter()) {} |
| 83 | 84 |
| 84 AudioRtpSender::~AudioRtpSender() { | 85 AudioRtpSender::~AudioRtpSender() { |
| 85 Stop(); | 86 Stop(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 void AudioRtpSender::OnChanged() { | 89 void AudioRtpSender::OnChanged() { |
| 90 TRACE_EVENT0("webrtc", "AudioRtpSender::OnChanged"); |
| 89 RTC_DCHECK(!stopped_); | 91 RTC_DCHECK(!stopped_); |
| 90 if (cached_track_enabled_ != track_->enabled()) { | 92 if (cached_track_enabled_ != track_->enabled()) { |
| 91 cached_track_enabled_ = track_->enabled(); | 93 cached_track_enabled_ = track_->enabled(); |
| 92 if (can_send_track()) { | 94 if (can_send_track()) { |
| 93 SetAudioSend(); | 95 SetAudioSend(); |
| 94 } | 96 } |
| 95 } | 97 } |
| 96 } | 98 } |
| 97 | 99 |
| 98 bool AudioRtpSender::SetTrack(MediaStreamTrackInterface* track) { | 100 bool AudioRtpSender::SetTrack(MediaStreamTrackInterface* track) { |
| 101 TRACE_EVENT0("webrtc", "AudioRtpSender::SetTrack"); |
| 99 if (stopped_) { | 102 if (stopped_) { |
| 100 LOG(LS_ERROR) << "SetTrack can't be called on a stopped RtpSender."; | 103 LOG(LS_ERROR) << "SetTrack can't be called on a stopped RtpSender."; |
| 101 return false; | 104 return false; |
| 102 } | 105 } |
| 103 if (track && track->kind() != MediaStreamTrackInterface::kAudioKind) { | 106 if (track && track->kind() != MediaStreamTrackInterface::kAudioKind) { |
| 104 LOG(LS_ERROR) << "SetTrack called on audio RtpSender with " << track->kind() | 107 LOG(LS_ERROR) << "SetTrack called on audio RtpSender with " << track->kind() |
| 105 << " track."; | 108 << " track."; |
| 106 return false; | 109 return false; |
| 107 } | 110 } |
| 108 AudioTrackInterface* audio_track = static_cast<AudioTrackInterface*>(track); | 111 AudioTrackInterface* audio_track = static_cast<AudioTrackInterface*>(track); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 133 stats_->AddLocalAudioTrack(track_.get(), ssrc_); | 136 stats_->AddLocalAudioTrack(track_.get(), ssrc_); |
| 134 } | 137 } |
| 135 } else if (prev_can_send_track) { | 138 } else if (prev_can_send_track) { |
| 136 cricket::AudioOptions options; | 139 cricket::AudioOptions options; |
| 137 provider_->SetAudioSend(ssrc_, false, options, nullptr); | 140 provider_->SetAudioSend(ssrc_, false, options, nullptr); |
| 138 } | 141 } |
| 139 return true; | 142 return true; |
| 140 } | 143 } |
| 141 | 144 |
| 142 void AudioRtpSender::SetSsrc(uint32_t ssrc) { | 145 void AudioRtpSender::SetSsrc(uint32_t ssrc) { |
| 146 TRACE_EVENT0("webrtc", "AudioRtpSender::SetSsrc"); |
| 143 if (stopped_ || ssrc == ssrc_) { | 147 if (stopped_ || ssrc == ssrc_) { |
| 144 return; | 148 return; |
| 145 } | 149 } |
| 146 // If we are already sending with a particular SSRC, stop sending. | 150 // If we are already sending with a particular SSRC, stop sending. |
| 147 if (can_send_track()) { | 151 if (can_send_track()) { |
| 148 cricket::AudioOptions options; | 152 cricket::AudioOptions options; |
| 149 provider_->SetAudioSend(ssrc_, false, options, nullptr); | 153 provider_->SetAudioSend(ssrc_, false, options, nullptr); |
| 150 if (stats_) { | 154 if (stats_) { |
| 151 stats_->RemoveLocalAudioTrack(track_.get(), ssrc_); | 155 stats_->RemoveLocalAudioTrack(track_.get(), ssrc_); |
| 152 } | 156 } |
| 153 } | 157 } |
| 154 ssrc_ = ssrc; | 158 ssrc_ = ssrc; |
| 155 if (can_send_track()) { | 159 if (can_send_track()) { |
| 156 SetAudioSend(); | 160 SetAudioSend(); |
| 157 if (stats_) { | 161 if (stats_) { |
| 158 stats_->AddLocalAudioTrack(track_.get(), ssrc_); | 162 stats_->AddLocalAudioTrack(track_.get(), ssrc_); |
| 159 } | 163 } |
| 160 } | 164 } |
| 161 } | 165 } |
| 162 | 166 |
| 163 void AudioRtpSender::Stop() { | 167 void AudioRtpSender::Stop() { |
| 168 TRACE_EVENT0("webrtc", "AudioRtpSender::Stop"); |
| 164 // TODO(deadbeef): Need to do more here to fully stop sending packets. | 169 // TODO(deadbeef): Need to do more here to fully stop sending packets. |
| 165 if (stopped_) { | 170 if (stopped_) { |
| 166 return; | 171 return; |
| 167 } | 172 } |
| 168 if (track_) { | 173 if (track_) { |
| 169 track_->RemoveSink(sink_adapter_.get()); | 174 track_->RemoveSink(sink_adapter_.get()); |
| 170 track_->UnregisterObserver(this); | 175 track_->UnregisterObserver(this); |
| 171 } | 176 } |
| 172 if (can_send_track()) { | 177 if (can_send_track()) { |
| 173 cricket::AudioOptions options; | 178 cricket::AudioOptions options; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 197 cricket::AudioSource* source = sink_adapter_.get(); | 202 cricket::AudioSource* source = sink_adapter_.get(); |
| 198 ASSERT(source != nullptr); | 203 ASSERT(source != nullptr); |
| 199 provider_->SetAudioSend(ssrc_, track_->enabled(), options, source); | 204 provider_->SetAudioSend(ssrc_, track_->enabled(), options, source); |
| 200 } | 205 } |
| 201 | 206 |
| 202 RtpParameters AudioRtpSender::GetParameters() const { | 207 RtpParameters AudioRtpSender::GetParameters() const { |
| 203 return provider_->GetAudioRtpParameters(ssrc_); | 208 return provider_->GetAudioRtpParameters(ssrc_); |
| 204 } | 209 } |
| 205 | 210 |
| 206 bool AudioRtpSender::SetParameters(const RtpParameters& parameters) { | 211 bool AudioRtpSender::SetParameters(const RtpParameters& parameters) { |
| 212 TRACE_EVENT0("webrtc", "AudioRtpSender::SetParameters"); |
| 207 return provider_->SetAudioRtpParameters(ssrc_, parameters); | 213 return provider_->SetAudioRtpParameters(ssrc_, parameters); |
| 208 } | 214 } |
| 209 | 215 |
| 210 VideoRtpSender::VideoRtpSender(VideoTrackInterface* track, | 216 VideoRtpSender::VideoRtpSender(VideoTrackInterface* track, |
| 211 const std::string& stream_id, | 217 const std::string& stream_id, |
| 212 VideoProviderInterface* provider) | 218 VideoProviderInterface* provider) |
| 213 : id_(track->id()), | 219 : id_(track->id()), |
| 214 stream_id_(stream_id), | 220 stream_id_(stream_id), |
| 215 provider_(provider), | 221 provider_(provider), |
| 216 track_(track), | 222 track_(track), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 233 VideoRtpSender::VideoRtpSender(VideoProviderInterface* provider) | 239 VideoRtpSender::VideoRtpSender(VideoProviderInterface* provider) |
| 234 : id_(rtc::CreateRandomUuid()), | 240 : id_(rtc::CreateRandomUuid()), |
| 235 stream_id_(rtc::CreateRandomUuid()), | 241 stream_id_(rtc::CreateRandomUuid()), |
| 236 provider_(provider) {} | 242 provider_(provider) {} |
| 237 | 243 |
| 238 VideoRtpSender::~VideoRtpSender() { | 244 VideoRtpSender::~VideoRtpSender() { |
| 239 Stop(); | 245 Stop(); |
| 240 } | 246 } |
| 241 | 247 |
| 242 void VideoRtpSender::OnChanged() { | 248 void VideoRtpSender::OnChanged() { |
| 249 TRACE_EVENT0("webrtc", "VideoRtpSender::OnChanged"); |
| 243 RTC_DCHECK(!stopped_); | 250 RTC_DCHECK(!stopped_); |
| 244 if (cached_track_enabled_ != track_->enabled()) { | 251 if (cached_track_enabled_ != track_->enabled()) { |
| 245 cached_track_enabled_ = track_->enabled(); | 252 cached_track_enabled_ = track_->enabled(); |
| 246 if (can_send_track()) { | 253 if (can_send_track()) { |
| 247 SetVideoSend(); | 254 SetVideoSend(); |
| 248 } | 255 } |
| 249 } | 256 } |
| 250 } | 257 } |
| 251 | 258 |
| 252 bool VideoRtpSender::SetTrack(MediaStreamTrackInterface* track) { | 259 bool VideoRtpSender::SetTrack(MediaStreamTrackInterface* track) { |
| 260 TRACE_EVENT0("webrtc", "VideoRtpSender::SetTrack"); |
| 253 if (stopped_) { | 261 if (stopped_) { |
| 254 LOG(LS_ERROR) << "SetTrack can't be called on a stopped RtpSender."; | 262 LOG(LS_ERROR) << "SetTrack can't be called on a stopped RtpSender."; |
| 255 return false; | 263 return false; |
| 256 } | 264 } |
| 257 if (track && track->kind() != MediaStreamTrackInterface::kVideoKind) { | 265 if (track && track->kind() != MediaStreamTrackInterface::kVideoKind) { |
| 258 LOG(LS_ERROR) << "SetTrack called on video RtpSender with " << track->kind() | 266 LOG(LS_ERROR) << "SetTrack called on video RtpSender with " << track->kind() |
| 259 << " track."; | 267 << " track."; |
| 260 return false; | 268 return false; |
| 261 } | 269 } |
| 262 VideoTrackInterface* video_track = static_cast<VideoTrackInterface*>(track); | 270 VideoTrackInterface* video_track = static_cast<VideoTrackInterface*>(track); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 285 provider_->SetSource(ssrc_, track_); | 293 provider_->SetSource(ssrc_, track_); |
| 286 SetVideoSend(); | 294 SetVideoSend(); |
| 287 } else if (prev_can_send_track) { | 295 } else if (prev_can_send_track) { |
| 288 provider_->SetSource(ssrc_, nullptr); | 296 provider_->SetSource(ssrc_, nullptr); |
| 289 provider_->SetVideoSend(ssrc_, false, nullptr); | 297 provider_->SetVideoSend(ssrc_, false, nullptr); |
| 290 } | 298 } |
| 291 return true; | 299 return true; |
| 292 } | 300 } |
| 293 | 301 |
| 294 void VideoRtpSender::SetSsrc(uint32_t ssrc) { | 302 void VideoRtpSender::SetSsrc(uint32_t ssrc) { |
| 303 TRACE_EVENT0("webrtc", "VideoRtpSender::SetSsrc"); |
| 295 if (stopped_ || ssrc == ssrc_) { | 304 if (stopped_ || ssrc == ssrc_) { |
| 296 return; | 305 return; |
| 297 } | 306 } |
| 298 // If we are already sending with a particular SSRC, stop sending. | 307 // If we are already sending with a particular SSRC, stop sending. |
| 299 if (can_send_track()) { | 308 if (can_send_track()) { |
| 300 provider_->SetSource(ssrc_, nullptr); | 309 provider_->SetSource(ssrc_, nullptr); |
| 301 provider_->SetVideoSend(ssrc_, false, nullptr); | 310 provider_->SetVideoSend(ssrc_, false, nullptr); |
| 302 } | 311 } |
| 303 ssrc_ = ssrc; | 312 ssrc_ = ssrc; |
| 304 if (can_send_track()) { | 313 if (can_send_track()) { |
| 305 provider_->SetSource(ssrc_, track_); | 314 provider_->SetSource(ssrc_, track_); |
| 306 SetVideoSend(); | 315 SetVideoSend(); |
| 307 } | 316 } |
| 308 } | 317 } |
| 309 | 318 |
| 310 void VideoRtpSender::Stop() { | 319 void VideoRtpSender::Stop() { |
| 320 TRACE_EVENT0("webrtc", "VideoRtpSender::Stop"); |
| 311 // TODO(deadbeef): Need to do more here to fully stop sending packets. | 321 // TODO(deadbeef): Need to do more here to fully stop sending packets. |
| 312 if (stopped_) { | 322 if (stopped_) { |
| 313 return; | 323 return; |
| 314 } | 324 } |
| 315 if (track_) { | 325 if (track_) { |
| 316 track_->UnregisterObserver(this); | 326 track_->UnregisterObserver(this); |
| 317 } | 327 } |
| 318 if (can_send_track()) { | 328 if (can_send_track()) { |
| 319 provider_->SetSource(ssrc_, nullptr); | 329 provider_->SetSource(ssrc_, nullptr); |
| 320 provider_->SetVideoSend(ssrc_, false, nullptr); | 330 provider_->SetVideoSend(ssrc_, false, nullptr); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 331 options.video_noise_reduction = source->needs_denoising(); | 341 options.video_noise_reduction = source->needs_denoising(); |
| 332 } | 342 } |
| 333 provider_->SetVideoSend(ssrc_, track_->enabled(), &options); | 343 provider_->SetVideoSend(ssrc_, track_->enabled(), &options); |
| 334 } | 344 } |
| 335 | 345 |
| 336 RtpParameters VideoRtpSender::GetParameters() const { | 346 RtpParameters VideoRtpSender::GetParameters() const { |
| 337 return provider_->GetVideoRtpParameters(ssrc_); | 347 return provider_->GetVideoRtpParameters(ssrc_); |
| 338 } | 348 } |
| 339 | 349 |
| 340 bool VideoRtpSender::SetParameters(const RtpParameters& parameters) { | 350 bool VideoRtpSender::SetParameters(const RtpParameters& parameters) { |
| 351 TRACE_EVENT0("webrtc", "VideoRtpSender::SetParameters"); |
| 341 return provider_->SetVideoRtpParameters(ssrc_, parameters); | 352 return provider_->SetVideoRtpParameters(ssrc_, parameters); |
| 342 } | 353 } |
| 343 | 354 |
| 344 } // namespace webrtc | 355 } // namespace webrtc |
| OLD | NEW |