OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 <string.h> | 11 #include <string.h> |
12 | 12 |
13 #include <map> | 13 #include <map> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "webrtc/audio/audio_receive_stream.h" | 16 #include "webrtc/audio/audio_receive_stream.h" |
17 #include "webrtc/audio/audio_send_stream.h" | |
17 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/scoped_ptr.h" | 19 #include "webrtc/base/scoped_ptr.h" |
19 #include "webrtc/base/thread_annotations.h" | 20 #include "webrtc/base/thread_annotations.h" |
20 #include "webrtc/call.h" | 21 #include "webrtc/call.h" |
21 #include "webrtc/call/rtc_event_log.h" | 22 #include "webrtc/call/rtc_event_log.h" |
22 #include "webrtc/common.h" | 23 #include "webrtc/common.h" |
23 #include "webrtc/config.h" | 24 #include "webrtc/config.h" |
24 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" | 25 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" |
25 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 26 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
26 #include "webrtc/modules/utility/interface/process_thread.h" | 27 #include "webrtc/modules/utility/interface/process_thread.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ | 105 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ |
105 GUARDED_BY(receive_crit_); | 106 GUARDED_BY(receive_crit_); |
106 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ | 107 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ |
107 GUARDED_BY(receive_crit_); | 108 GUARDED_BY(receive_crit_); |
108 std::set<VideoReceiveStream*> video_receive_streams_ | 109 std::set<VideoReceiveStream*> video_receive_streams_ |
109 GUARDED_BY(receive_crit_); | 110 GUARDED_BY(receive_crit_); |
110 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ | 111 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ |
111 GUARDED_BY(receive_crit_); | 112 GUARDED_BY(receive_crit_); |
112 | 113 |
113 rtc::scoped_ptr<RWLockWrapper> send_crit_; | 114 rtc::scoped_ptr<RWLockWrapper> send_crit_; |
115 std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_); | |
tommi
2015/10/14 13:21:18
document where ownership of the send stream lies?
the sun
2015/10/14 14:25:24
Done.
| |
114 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); | 116 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); |
115 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); | 117 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); |
116 | 118 |
117 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; | 119 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; |
118 | 120 |
119 RtcEventLog* event_log_; | 121 RtcEventLog* event_log_; |
120 | 122 |
121 RTC_DISALLOW_COPY_AND_ASSIGN(Call); | 123 RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
122 }; | 124 }; |
123 } // namespace internal | 125 } // namespace internal |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 | 157 |
156 Trace::CreateTrace(); | 158 Trace::CreateTrace(); |
157 module_process_thread_->Start(); | 159 module_process_thread_->Start(); |
158 | 160 |
159 channel_group_->SetBweBitrates(config_.bitrate_config.min_bitrate_bps, | 161 channel_group_->SetBweBitrates(config_.bitrate_config.min_bitrate_bps, |
160 config_.bitrate_config.start_bitrate_bps, | 162 config_.bitrate_config.start_bitrate_bps, |
161 config_.bitrate_config.max_bitrate_bps); | 163 config_.bitrate_config.max_bitrate_bps); |
162 } | 164 } |
163 | 165 |
164 Call::~Call() { | 166 Call::~Call() { |
167 RTC_CHECK_EQ(0u, audio_send_ssrcs_.size()); | |
tommi
2015/10/14 13:21:18
nit: RTC_CHECK(audio_send_ssrcs_.empty()); I see
the sun
2015/10/14 14:25:24
Done.
| |
165 RTC_CHECK_EQ(0u, video_send_ssrcs_.size()); | 168 RTC_CHECK_EQ(0u, video_send_ssrcs_.size()); |
166 RTC_CHECK_EQ(0u, video_send_streams_.size()); | 169 RTC_CHECK_EQ(0u, video_send_streams_.size()); |
167 RTC_CHECK_EQ(0u, audio_receive_ssrcs_.size()); | 170 RTC_CHECK_EQ(0u, audio_receive_ssrcs_.size()); |
168 RTC_CHECK_EQ(0u, video_receive_ssrcs_.size()); | 171 RTC_CHECK_EQ(0u, video_receive_ssrcs_.size()); |
169 RTC_CHECK_EQ(0u, video_receive_streams_.size()); | 172 RTC_CHECK_EQ(0u, video_receive_streams_.size()); |
170 | 173 |
171 module_process_thread_->Stop(); | 174 module_process_thread_->Stop(); |
172 Trace::ReturnTrace(); | 175 Trace::ReturnTrace(); |
173 } | 176 } |
174 | 177 |
175 PacketReceiver* Call::Receiver() { return this; } | 178 PacketReceiver* Call::Receiver() { return this; } |
176 | 179 |
177 webrtc::AudioSendStream* Call::CreateAudioSendStream( | 180 webrtc::AudioSendStream* Call::CreateAudioSendStream( |
178 const webrtc::AudioSendStream::Config& config) { | 181 const webrtc::AudioSendStream::Config& config) { |
179 return nullptr; | 182 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream"); |
183 LOG(LS_INFO) << "CreateAudioSendStream: " << config.ToString(); | |
184 AudioSendStream* send_stream = new AudioSendStream(config); | |
185 { | |
186 rtc::CritScope lock(&network_enabled_crit_); | |
187 WriteLockScoped write_lock(*send_crit_); | |
188 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == | |
189 audio_send_ssrcs_.end()); | |
190 audio_send_ssrcs_[config.rtp.ssrc] = send_stream; | |
191 | |
192 if (!network_enabled_) | |
193 send_stream->SignalNetworkState(kNetworkDown); | |
194 } | |
195 return send_stream; | |
tommi
2015/10/14 13:21:18
is it guaranteed that CreateAudioSendStream() and
the sun
2015/10/14 14:25:24
Well, from what I can make out, in libjingle only
| |
180 } | 196 } |
181 | 197 |
182 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { | 198 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { |
199 TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream"); | |
200 RTC_DCHECK(send_stream != nullptr); | |
201 | |
202 send_stream->Stop(); | |
203 | |
204 AudioSendStream* audio_send_stream = | |
205 static_cast<AudioSendStream*>(send_stream); | |
tommi
2015/10/14 13:21:18
I'm not groking this cast :)
the sun
2015/10/14 14:25:24
We're casting a webrtc::AudioSendStream to a webrt
tommi
2015/10/14 14:49:28
Ah :) that wasn't obvious to me especially since
the sun
2015/10/15 12:56:06
I've added explicit casts for the audio functions;
| |
206 { | |
207 WriteLockScoped write_lock(*send_crit_); | |
208 size_t num_deleted = audio_send_ssrcs_.erase( | |
209 audio_send_stream->config().rtp.ssrc); | |
210 RTC_DCHECK(num_deleted == 1); | |
211 } | |
212 delete audio_send_stream; | |
183 } | 213 } |
184 | 214 |
185 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( | 215 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( |
186 const webrtc::AudioReceiveStream::Config& config) { | 216 const webrtc::AudioReceiveStream::Config& config) { |
187 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); | 217 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); |
188 LOG(LS_INFO) << "CreateAudioReceiveStream: " << config.ToString(); | 218 LOG(LS_INFO) << "CreateAudioReceiveStream: " << config.ToString(); |
189 AudioReceiveStream* receive_stream = new AudioReceiveStream( | 219 AudioReceiveStream* receive_stream = new AudioReceiveStream( |
190 channel_group_->GetRemoteBitrateEstimator(), config); | 220 channel_group_->GetRemoteBitrateEstimator(), config); |
191 { | 221 { |
192 WriteLockScoped write_lock(*receive_crit_); | 222 WriteLockScoped write_lock(*receive_crit_); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 channel_group_->GetBitrateController()->AvailableBandwidth(&send_bandwidth); | 383 channel_group_->GetBitrateController()->AvailableBandwidth(&send_bandwidth); |
354 std::vector<unsigned int> ssrcs; | 384 std::vector<unsigned int> ssrcs; |
355 uint32_t recv_bandwidth = 0; | 385 uint32_t recv_bandwidth = 0; |
356 channel_group_->GetRemoteBitrateEstimator()->LatestEstimate(&ssrcs, | 386 channel_group_->GetRemoteBitrateEstimator()->LatestEstimate(&ssrcs, |
357 &recv_bandwidth); | 387 &recv_bandwidth); |
358 stats.send_bandwidth_bps = send_bandwidth; | 388 stats.send_bandwidth_bps = send_bandwidth; |
359 stats.recv_bandwidth_bps = recv_bandwidth; | 389 stats.recv_bandwidth_bps = recv_bandwidth; |
360 stats.pacer_delay_ms = channel_group_->GetPacerQueuingDelayMs(); | 390 stats.pacer_delay_ms = channel_group_->GetPacerQueuingDelayMs(); |
361 { | 391 { |
362 ReadLockScoped read_lock(*send_crit_); | 392 ReadLockScoped read_lock(*send_crit_); |
393 // TODO(solenberg): Add audio send streams. | |
363 for (const auto& kv : video_send_ssrcs_) { | 394 for (const auto& kv : video_send_ssrcs_) { |
364 int rtt_ms = kv.second->GetRtt(); | 395 int rtt_ms = kv.second->GetRtt(); |
365 if (rtt_ms > 0) | 396 if (rtt_ms > 0) |
366 stats.rtt_ms = rtt_ms; | 397 stats.rtt_ms = rtt_ms; |
367 } | 398 } |
368 } | 399 } |
369 return stats; | 400 return stats; |
370 } | 401 } |
371 | 402 |
372 void Call::SetBitrateConfig( | 403 void Call::SetBitrateConfig( |
(...skipping 19 matching lines...) Expand all Loading... | |
392 } | 423 } |
393 | 424 |
394 void Call::SignalNetworkState(NetworkState state) { | 425 void Call::SignalNetworkState(NetworkState state) { |
395 // Take crit for entire function, it needs to be held while updating streams | 426 // Take crit for entire function, it needs to be held while updating streams |
396 // to guarantee a consistent state across streams. | 427 // to guarantee a consistent state across streams. |
397 rtc::CritScope lock(&network_enabled_crit_); | 428 rtc::CritScope lock(&network_enabled_crit_); |
398 network_enabled_ = state == kNetworkUp; | 429 network_enabled_ = state == kNetworkUp; |
399 channel_group_->SignalNetworkState(state); | 430 channel_group_->SignalNetworkState(state); |
400 { | 431 { |
401 ReadLockScoped write_lock(*send_crit_); | 432 ReadLockScoped write_lock(*send_crit_); |
433 for (auto& kv : audio_send_ssrcs_) { | |
tommi
2015/10/14 13:21:18
no chance ov avoiding holding these locks (network
the sun
2015/10/14 14:25:24
See above comment...
| |
434 kv.second->SignalNetworkState(state); | |
435 } | |
402 for (auto& kv : video_send_ssrcs_) { | 436 for (auto& kv : video_send_ssrcs_) { |
403 kv.second->SignalNetworkState(state); | 437 kv.second->SignalNetworkState(state); |
404 } | 438 } |
405 } | 439 } |
406 { | 440 { |
407 ReadLockScoped write_lock(*receive_crit_); | 441 ReadLockScoped write_lock(*receive_crit_); |
408 for (auto& kv : video_receive_ssrcs_) { | 442 for (auto& kv : video_receive_ssrcs_) { |
409 kv.second->SignalNetworkState(state); | 443 kv.second->SignalNetworkState(state); |
410 } | 444 } |
411 } | 445 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 size_t length, | 566 size_t length, |
533 const PacketTime& packet_time) { | 567 const PacketTime& packet_time) { |
534 if (RtpHeaderParser::IsRtcp(packet, length)) | 568 if (RtpHeaderParser::IsRtcp(packet, length)) |
535 return DeliverRtcp(media_type, packet, length); | 569 return DeliverRtcp(media_type, packet, length); |
536 | 570 |
537 return DeliverRtp(media_type, packet, length, packet_time); | 571 return DeliverRtp(media_type, packet, length, packet_time); |
538 } | 572 } |
539 | 573 |
540 } // namespace internal | 574 } // namespace internal |
541 } // namespace webrtc | 575 } // namespace webrtc |
OLD | NEW |