Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: webrtc/call/call.cc

Issue 1397123003: Add AudioSendStream to Call. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: comments+merge Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 volatile int next_channel_id_; 95 volatile int next_channel_id_;
95 Call::Config config_; 96 Call::Config config_;
96 97
97 // Needs to be held while write-locking |receive_crit_| or |send_crit_|. This 98 // Needs to be held while write-locking |receive_crit_| or |send_crit_|. This
98 // ensures that we have a consistent network state signalled to all senders 99 // ensures that we have a consistent network state signalled to all senders
99 // and receivers. 100 // and receivers.
100 rtc::CriticalSection network_enabled_crit_; 101 rtc::CriticalSection network_enabled_crit_;
101 bool network_enabled_ GUARDED_BY(network_enabled_crit_); 102 bool network_enabled_ GUARDED_BY(network_enabled_crit_);
102 103
103 rtc::scoped_ptr<RWLockWrapper> receive_crit_; 104 rtc::scoped_ptr<RWLockWrapper> receive_crit_;
105 // Audio and Video receive streams are owned by the client that creates them.
104 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ 106 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_
105 GUARDED_BY(receive_crit_); 107 GUARDED_BY(receive_crit_);
106 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ 108 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_
107 GUARDED_BY(receive_crit_); 109 GUARDED_BY(receive_crit_);
108 std::set<VideoReceiveStream*> video_receive_streams_ 110 std::set<VideoReceiveStream*> video_receive_streams_
109 GUARDED_BY(receive_crit_); 111 GUARDED_BY(receive_crit_);
110 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ 112 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_
111 GUARDED_BY(receive_crit_); 113 GUARDED_BY(receive_crit_);
112 114
113 rtc::scoped_ptr<RWLockWrapper> send_crit_; 115 rtc::scoped_ptr<RWLockWrapper> send_crit_;
116 // Audio and Video send streams are owned by the client that creates them.
117 std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_);
114 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); 118 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_);
115 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); 119 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_);
116 120
117 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; 121 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_;
118 122
119 RtcEventLog* event_log_; 123 RtcEventLog* event_log_;
120 124
121 RTC_DISALLOW_COPY_AND_ASSIGN(Call); 125 RTC_DISALLOW_COPY_AND_ASSIGN(Call);
122 }; 126 };
123 } // namespace internal 127 } // namespace internal
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 159
156 Trace::CreateTrace(); 160 Trace::CreateTrace();
157 module_process_thread_->Start(); 161 module_process_thread_->Start();
158 162
159 channel_group_->SetBweBitrates(config_.bitrate_config.min_bitrate_bps, 163 channel_group_->SetBweBitrates(config_.bitrate_config.min_bitrate_bps,
160 config_.bitrate_config.start_bitrate_bps, 164 config_.bitrate_config.start_bitrate_bps,
161 config_.bitrate_config.max_bitrate_bps); 165 config_.bitrate_config.max_bitrate_bps);
162 } 166 }
163 167
164 Call::~Call() { 168 Call::~Call() {
165 RTC_CHECK_EQ(0u, video_send_ssrcs_.size()); 169 RTC_CHECK(audio_send_ssrcs_.empty());
166 RTC_CHECK_EQ(0u, video_send_streams_.size()); 170 RTC_CHECK(video_send_ssrcs_.empty());
167 RTC_CHECK_EQ(0u, audio_receive_ssrcs_.size()); 171 RTC_CHECK(video_send_streams_.empty());
168 RTC_CHECK_EQ(0u, video_receive_ssrcs_.size()); 172 RTC_CHECK(audio_receive_ssrcs_.empty());
169 RTC_CHECK_EQ(0u, video_receive_streams_.size()); 173 RTC_CHECK(video_receive_ssrcs_.empty());
174 RTC_CHECK(video_receive_streams_.empty());
170 175
171 module_process_thread_->Stop(); 176 module_process_thread_->Stop();
172 Trace::ReturnTrace(); 177 Trace::ReturnTrace();
173 } 178 }
174 179
175 PacketReceiver* Call::Receiver() { return this; } 180 PacketReceiver* Call::Receiver() { return this; }
176 181
177 webrtc::AudioSendStream* Call::CreateAudioSendStream( 182 webrtc::AudioSendStream* Call::CreateAudioSendStream(
178 const webrtc::AudioSendStream::Config& config) { 183 const webrtc::AudioSendStream::Config& config) {
179 // TODO(pbos): When adding AudioSendStream, add both TRACE_EVENT0 and config 184 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream");
180 // logging to AudioSendStream constructor. 185 AudioSendStream* send_stream = new AudioSendStream(config);
181 return nullptr; 186 {
187 rtc::CritScope lock(&network_enabled_crit_);
188 WriteLockScoped write_lock(*send_crit_);
189 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) ==
190 audio_send_ssrcs_.end());
191 audio_send_ssrcs_[config.rtp.ssrc] = send_stream;
192
193 if (!network_enabled_)
194 send_stream->SignalNetworkState(kNetworkDown);
195 }
196 return send_stream;
182 } 197 }
183 198
184 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { 199 void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) {
185 // TODO(pbos): When adding AudioSendStream, add both TRACE_EVENT0 and config 200 TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream");
186 // logging to AudioSendStream destructor. 201 RTC_DCHECK(send_stream != nullptr);
202
203 send_stream->Stop();
204
205 webrtc::internal::AudioSendStream* audio_send_stream =
206 static_cast<webrtc::internal::AudioSendStream*>(send_stream);
207 {
208 WriteLockScoped write_lock(*send_crit_);
209 size_t num_deleted = audio_send_ssrcs_.erase(
210 audio_send_stream->config().rtp.ssrc);
211 RTC_DCHECK(num_deleted == 1);
212 }
213 delete audio_send_stream;
187 } 214 }
188 215
189 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( 216 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream(
190 const webrtc::AudioReceiveStream::Config& config) { 217 const webrtc::AudioReceiveStream::Config& config) {
191 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); 218 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream");
192 AudioReceiveStream* receive_stream = new AudioReceiveStream( 219 AudioReceiveStream* receive_stream = new AudioReceiveStream(
193 channel_group_->GetRemoteBitrateEstimator(), config); 220 channel_group_->GetRemoteBitrateEstimator(), config);
194 { 221 {
195 WriteLockScoped write_lock(*receive_crit_); 222 WriteLockScoped write_lock(*receive_crit_);
196 RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == 223 RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) ==
197 audio_receive_ssrcs_.end()); 224 audio_receive_ssrcs_.end());
198 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; 225 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream;
199 ConfigureSync(config.sync_group); 226 ConfigureSync(config.sync_group);
200 } 227 }
201 return receive_stream; 228 return receive_stream;
202 } 229 }
203 230
204 void Call::DestroyAudioReceiveStream( 231 void Call::DestroyAudioReceiveStream(
205 webrtc::AudioReceiveStream* receive_stream) { 232 webrtc::AudioReceiveStream* receive_stream) {
206 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); 233 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream");
207 RTC_DCHECK(receive_stream != nullptr); 234 RTC_DCHECK(receive_stream != nullptr);
208 AudioReceiveStream* audio_receive_stream = 235 webrtc::internal::AudioReceiveStream* audio_receive_stream =
209 static_cast<AudioReceiveStream*>(receive_stream); 236 static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream);
210 { 237 {
211 WriteLockScoped write_lock(*receive_crit_); 238 WriteLockScoped write_lock(*receive_crit_);
212 size_t num_deleted = audio_receive_ssrcs_.erase( 239 size_t num_deleted = audio_receive_ssrcs_.erase(
213 audio_receive_stream->config().rtp.remote_ssrc); 240 audio_receive_stream->config().rtp.remote_ssrc);
214 RTC_DCHECK(num_deleted == 1); 241 RTC_DCHECK(num_deleted == 1);
215 const std::string& sync_group = audio_receive_stream->config().sync_group; 242 const std::string& sync_group = audio_receive_stream->config().sync_group;
216 const auto it = sync_stream_mapping_.find(sync_group); 243 const auto it = sync_stream_mapping_.find(sync_group);
217 if (it != sync_stream_mapping_.end() && 244 if (it != sync_stream_mapping_.end() &&
218 it->second == audio_receive_stream) { 245 it->second == audio_receive_stream) {
219 sync_stream_mapping_.erase(it); 246 sync_stream_mapping_.erase(it);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 channel_group_->GetBitrateController()->AvailableBandwidth(&send_bandwidth); 380 channel_group_->GetBitrateController()->AvailableBandwidth(&send_bandwidth);
354 std::vector<unsigned int> ssrcs; 381 std::vector<unsigned int> ssrcs;
355 uint32_t recv_bandwidth = 0; 382 uint32_t recv_bandwidth = 0;
356 channel_group_->GetRemoteBitrateEstimator()->LatestEstimate(&ssrcs, 383 channel_group_->GetRemoteBitrateEstimator()->LatestEstimate(&ssrcs,
357 &recv_bandwidth); 384 &recv_bandwidth);
358 stats.send_bandwidth_bps = send_bandwidth; 385 stats.send_bandwidth_bps = send_bandwidth;
359 stats.recv_bandwidth_bps = recv_bandwidth; 386 stats.recv_bandwidth_bps = recv_bandwidth;
360 stats.pacer_delay_ms = channel_group_->GetPacerQueuingDelayMs(); 387 stats.pacer_delay_ms = channel_group_->GetPacerQueuingDelayMs();
361 { 388 {
362 ReadLockScoped read_lock(*send_crit_); 389 ReadLockScoped read_lock(*send_crit_);
390 // TODO(solenberg): Add audio send streams.
363 for (const auto& kv : video_send_ssrcs_) { 391 for (const auto& kv : video_send_ssrcs_) {
364 int rtt_ms = kv.second->GetRtt(); 392 int rtt_ms = kv.second->GetRtt();
365 if (rtt_ms > 0) 393 if (rtt_ms > 0)
366 stats.rtt_ms = rtt_ms; 394 stats.rtt_ms = rtt_ms;
367 } 395 }
368 } 396 }
369 return stats; 397 return stats;
370 } 398 }
371 399
372 void Call::SetBitrateConfig( 400 void Call::SetBitrateConfig(
(...skipping 19 matching lines...) Expand all
392 } 420 }
393 421
394 void Call::SignalNetworkState(NetworkState state) { 422 void Call::SignalNetworkState(NetworkState state) {
395 // Take crit for entire function, it needs to be held while updating streams 423 // Take crit for entire function, it needs to be held while updating streams
396 // to guarantee a consistent state across streams. 424 // to guarantee a consistent state across streams.
397 rtc::CritScope lock(&network_enabled_crit_); 425 rtc::CritScope lock(&network_enabled_crit_);
398 network_enabled_ = state == kNetworkUp; 426 network_enabled_ = state == kNetworkUp;
399 channel_group_->SignalNetworkState(state); 427 channel_group_->SignalNetworkState(state);
400 { 428 {
401 ReadLockScoped write_lock(*send_crit_); 429 ReadLockScoped write_lock(*send_crit_);
430 for (auto& kv : audio_send_ssrcs_) {
431 kv.second->SignalNetworkState(state);
432 }
402 for (auto& kv : video_send_ssrcs_) { 433 for (auto& kv : video_send_ssrcs_) {
403 kv.second->SignalNetworkState(state); 434 kv.second->SignalNetworkState(state);
404 } 435 }
405 } 436 }
406 { 437 {
407 ReadLockScoped write_lock(*receive_crit_); 438 ReadLockScoped write_lock(*receive_crit_);
408 for (auto& kv : video_receive_ssrcs_) { 439 for (auto& kv : video_receive_ssrcs_) {
409 kv.second->SignalNetworkState(state); 440 kv.second->SignalNetworkState(state);
410 } 441 }
411 } 442 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 size_t length, 563 size_t length,
533 const PacketTime& packet_time) { 564 const PacketTime& packet_time) {
534 if (RtpHeaderParser::IsRtcp(packet, length)) 565 if (RtpHeaderParser::IsRtcp(packet, length))
535 return DeliverRtcp(media_type, packet, length); 566 return DeliverRtcp(media_type, packet, length);
536 567
537 return DeliverRtp(media_type, packet, length, packet_time); 568 return DeliverRtp(media_type, packet, length, packet_time);
538 } 569 }
539 570
540 } // namespace internal 571 } // namespace internal
541 } // namespace webrtc 572 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698