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 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 StatsCollector* stats) | 50 StatsCollector* stats) |
51 : id_(track->id()), | 51 : id_(track->id()), |
52 stream_id_(stream_id), | 52 stream_id_(stream_id), |
53 channel_(channel), | 53 channel_(channel), |
54 stats_(stats), | 54 stats_(stats), |
55 track_(track), | 55 track_(track), |
56 cached_track_enabled_(track->enabled()), | 56 cached_track_enabled_(track->enabled()), |
57 sink_adapter_(new LocalAudioSinkAdapter()) { | 57 sink_adapter_(new LocalAudioSinkAdapter()) { |
58 track_->RegisterObserver(this); | 58 track_->RegisterObserver(this); |
59 track_->AddSink(sink_adapter_.get()); | 59 track_->AddSink(sink_adapter_.get()); |
| 60 CreateDtmfSender(); |
60 } | 61 } |
61 | 62 |
62 AudioRtpSender::AudioRtpSender(AudioTrackInterface* track, | 63 AudioRtpSender::AudioRtpSender(AudioTrackInterface* track, |
63 cricket::VoiceChannel* channel, | 64 cricket::VoiceChannel* channel, |
64 StatsCollector* stats) | 65 StatsCollector* stats) |
65 : id_(track->id()), | 66 : id_(track->id()), |
66 stream_id_(rtc::CreateRandomUuid()), | 67 stream_id_(rtc::CreateRandomUuid()), |
67 channel_(channel), | 68 channel_(channel), |
68 stats_(stats), | 69 stats_(stats), |
69 track_(track), | 70 track_(track), |
70 cached_track_enabled_(track->enabled()), | 71 cached_track_enabled_(track->enabled()), |
71 sink_adapter_(new LocalAudioSinkAdapter()) { | 72 sink_adapter_(new LocalAudioSinkAdapter()) { |
72 track_->RegisterObserver(this); | 73 track_->RegisterObserver(this); |
73 track_->AddSink(sink_adapter_.get()); | 74 track_->AddSink(sink_adapter_.get()); |
| 75 CreateDtmfSender(); |
74 } | 76 } |
75 | 77 |
76 AudioRtpSender::AudioRtpSender(cricket::VoiceChannel* channel, | 78 AudioRtpSender::AudioRtpSender(cricket::VoiceChannel* channel, |
77 StatsCollector* stats) | 79 StatsCollector* stats) |
78 : id_(rtc::CreateRandomUuid()), | 80 : id_(rtc::CreateRandomUuid()), |
79 stream_id_(rtc::CreateRandomUuid()), | 81 stream_id_(rtc::CreateRandomUuid()), |
80 channel_(channel), | 82 channel_(channel), |
81 stats_(stats), | 83 stats_(stats), |
82 sink_adapter_(new LocalAudioSinkAdapter()) {} | 84 sink_adapter_(new LocalAudioSinkAdapter()) { |
| 85 CreateDtmfSender(); |
| 86 } |
83 | 87 |
84 AudioRtpSender::~AudioRtpSender() { | 88 AudioRtpSender::~AudioRtpSender() { |
| 89 // For DtmfSender. |
| 90 SignalDestroyed(); |
85 Stop(); | 91 Stop(); |
86 } | 92 } |
87 | 93 |
| 94 bool AudioRtpSender::CanInsertDtmf() { |
| 95 if (!channel_) { |
| 96 LOG(LS_ERROR) << "CanInsertDtmf: No audio channel exists."; |
| 97 return false; |
| 98 } |
| 99 // Check that this RTP sender is active (description has been applied that |
| 100 // matches an SSRC to its ID). |
| 101 if (!ssrc_) { |
| 102 LOG(LS_ERROR) << "CanInsertDtmf: Sender does not have SSRC."; |
| 103 return false; |
| 104 } |
| 105 return channel_->CanInsertDtmf(); |
| 106 } |
| 107 |
| 108 bool AudioRtpSender::InsertDtmf(int code, int duration) { |
| 109 if (!channel_) { |
| 110 LOG(LS_ERROR) << "CanInsertDtmf: No audio channel exists."; |
| 111 return false; |
| 112 } |
| 113 if (!ssrc_) { |
| 114 LOG(LS_ERROR) << "CanInsertDtmf: Sender does not have SSRC."; |
| 115 return false; |
| 116 } |
| 117 if (!channel_->InsertDtmf(ssrc_, code, duration)) { |
| 118 LOG(LS_ERROR) << "Failed to insert DTMF to channel."; |
| 119 return false; |
| 120 } |
| 121 return true; |
| 122 } |
| 123 |
| 124 sigslot::signal0<>* AudioRtpSender::GetOnDestroyedSignal() { |
| 125 return &SignalDestroyed; |
| 126 } |
| 127 |
88 void AudioRtpSender::OnChanged() { | 128 void AudioRtpSender::OnChanged() { |
89 TRACE_EVENT0("webrtc", "AudioRtpSender::OnChanged"); | 129 TRACE_EVENT0("webrtc", "AudioRtpSender::OnChanged"); |
90 RTC_DCHECK(!stopped_); | 130 RTC_DCHECK(!stopped_); |
91 if (cached_track_enabled_ != track_->enabled()) { | 131 if (cached_track_enabled_ != track_->enabled()) { |
92 cached_track_enabled_ = track_->enabled(); | 132 cached_track_enabled_ = track_->enabled(); |
93 if (can_send_track()) { | 133 if (can_send_track()) { |
94 SetAudioSend(); | 134 SetAudioSend(); |
95 } | 135 } |
96 } | 136 } |
97 } | 137 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 } | 191 } |
152 | 192 |
153 bool AudioRtpSender::SetParameters(const RtpParameters& parameters) { | 193 bool AudioRtpSender::SetParameters(const RtpParameters& parameters) { |
154 TRACE_EVENT0("webrtc", "AudioRtpSender::SetParameters"); | 194 TRACE_EVENT0("webrtc", "AudioRtpSender::SetParameters"); |
155 if (!channel_ || stopped_) { | 195 if (!channel_ || stopped_) { |
156 return false; | 196 return false; |
157 } | 197 } |
158 return channel_->SetRtpSendParameters(ssrc_, parameters); | 198 return channel_->SetRtpSendParameters(ssrc_, parameters); |
159 } | 199 } |
160 | 200 |
| 201 rtc::scoped_refptr<DtmfSenderInterface> AudioRtpSender::GetDtmfSender() const { |
| 202 return dtmf_sender_proxy_; |
| 203 } |
| 204 |
161 void AudioRtpSender::SetSsrc(uint32_t ssrc) { | 205 void AudioRtpSender::SetSsrc(uint32_t ssrc) { |
162 TRACE_EVENT0("webrtc", "AudioRtpSender::SetSsrc"); | 206 TRACE_EVENT0("webrtc", "AudioRtpSender::SetSsrc"); |
163 if (stopped_ || ssrc == ssrc_) { | 207 if (stopped_ || ssrc == ssrc_) { |
164 return; | 208 return; |
165 } | 209 } |
166 // If we are already sending with a particular SSRC, stop sending. | 210 // If we are already sending with a particular SSRC, stop sending. |
167 if (can_send_track()) { | 211 if (can_send_track()) { |
168 ClearAudioSend(); | 212 ClearAudioSend(); |
169 if (stats_) { | 213 if (stats_) { |
170 stats_->RemoveLocalAudioTrack(track_.get(), ssrc_); | 214 stats_->RemoveLocalAudioTrack(track_.get(), ssrc_); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 if (!channel_) { | 274 if (!channel_) { |
231 LOG(LS_WARNING) << "ClearAudioSend: No audio channel exists."; | 275 LOG(LS_WARNING) << "ClearAudioSend: No audio channel exists."; |
232 return; | 276 return; |
233 } | 277 } |
234 cricket::AudioOptions options; | 278 cricket::AudioOptions options; |
235 if (!channel_->SetAudioSend(ssrc_, false, &options, nullptr)) { | 279 if (!channel_->SetAudioSend(ssrc_, false, &options, nullptr)) { |
236 LOG(LS_WARNING) << "ClearAudioSend: ssrc is incorrect: " << ssrc_; | 280 LOG(LS_WARNING) << "ClearAudioSend: ssrc is incorrect: " << ssrc_; |
237 } | 281 } |
238 } | 282 } |
239 | 283 |
| 284 void AudioRtpSender::CreateDtmfSender() { |
| 285 // Should be on signaling thread. |
| 286 // TODO(deadbeef): Add thread checking to RtpSender/RtpReceiver |
| 287 // implementations. |
| 288 rtc::scoped_refptr<DtmfSenderInterface> sender( |
| 289 DtmfSender::Create(track_, rtc::Thread::Current(), this)); |
| 290 if (!sender.get()) { |
| 291 LOG(LS_ERROR) << "CreateDtmfSender failed on DtmfSender::Create."; |
| 292 RTC_NOTREACHED(); |
| 293 } |
| 294 dtmf_sender_proxy_ = |
| 295 DtmfSenderProxy::Create(rtc::Thread::Current(), sender.get()); |
| 296 } |
| 297 |
240 VideoRtpSender::VideoRtpSender(VideoTrackInterface* track, | 298 VideoRtpSender::VideoRtpSender(VideoTrackInterface* track, |
241 const std::string& stream_id, | 299 const std::string& stream_id, |
242 cricket::VideoChannel* channel) | 300 cricket::VideoChannel* channel) |
243 : id_(track->id()), | 301 : id_(track->id()), |
244 stream_id_(stream_id), | 302 stream_id_(stream_id), |
245 channel_(channel), | 303 channel_(channel), |
246 track_(track), | 304 track_(track), |
247 cached_track_enabled_(track->enabled()), | 305 cached_track_enabled_(track->enabled()), |
248 cached_track_content_hint_(track->content_hint()) { | 306 cached_track_content_hint_(track->content_hint()) { |
249 track_->RegisterObserver(this); | 307 track_->RegisterObserver(this); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 387 } |
330 | 388 |
331 bool VideoRtpSender::SetParameters(const RtpParameters& parameters) { | 389 bool VideoRtpSender::SetParameters(const RtpParameters& parameters) { |
332 TRACE_EVENT0("webrtc", "VideoRtpSender::SetParameters"); | 390 TRACE_EVENT0("webrtc", "VideoRtpSender::SetParameters"); |
333 if (!channel_ || stopped_) { | 391 if (!channel_ || stopped_) { |
334 return false; | 392 return false; |
335 } | 393 } |
336 return channel_->SetRtpSendParameters(ssrc_, parameters); | 394 return channel_->SetRtpSendParameters(ssrc_, parameters); |
337 } | 395 } |
338 | 396 |
| 397 rtc::scoped_refptr<DtmfSenderInterface> VideoRtpSender::GetDtmfSender() const { |
| 398 LOG(LS_ERROR) << "Tried to get DTMF sender from video sender."; |
| 399 return nullptr; |
| 400 } |
| 401 |
339 void VideoRtpSender::SetSsrc(uint32_t ssrc) { | 402 void VideoRtpSender::SetSsrc(uint32_t ssrc) { |
340 TRACE_EVENT0("webrtc", "VideoRtpSender::SetSsrc"); | 403 TRACE_EVENT0("webrtc", "VideoRtpSender::SetSsrc"); |
341 if (stopped_ || ssrc == ssrc_) { | 404 if (stopped_ || ssrc == ssrc_) { |
342 return; | 405 return; |
343 } | 406 } |
344 // If we are already sending with a particular SSRC, stop sending. | 407 // If we are already sending with a particular SSRC, stop sending. |
345 if (can_send_track()) { | 408 if (can_send_track()) { |
346 ClearVideoSend(); | 409 ClearVideoSend(); |
347 } | 410 } |
348 ssrc_ = ssrc; | 411 ssrc_ = ssrc; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 LOG(LS_WARNING) << "SetVideoSend: No video channel exists."; | 463 LOG(LS_WARNING) << "SetVideoSend: No video channel exists."; |
401 return; | 464 return; |
402 } | 465 } |
403 // Allow SetVideoSend to fail since |enable| is false and |source| is null. | 466 // Allow SetVideoSend to fail since |enable| is false and |source| is null. |
404 // This the normal case when the underlying media channel has already been | 467 // This the normal case when the underlying media channel has already been |
405 // deleted. | 468 // deleted. |
406 channel_->SetVideoSend(ssrc_, false, nullptr, nullptr); | 469 channel_->SetVideoSend(ssrc_, false, nullptr, nullptr); |
407 } | 470 } |
408 | 471 |
409 } // namespace webrtc | 472 } // namespace webrtc |
OLD | NEW |