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

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

Powered by Google App Engine
This is Rietveld 408576698