blob: 34ecfc4f16ab4c112b11a3628e0ffcfb003e1200 [file] [log] [blame]
pbos@webrtc.org29d58392013-05-16 12:08:03 +00001/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000011#include <string.h>
12
pbos@webrtc.org29d58392013-05-16 12:08:03 +000013#include <map>
14#include <vector>
15
Peter Boström5c389d32015-09-25 13:58:30 +020016#include "webrtc/audio/audio_receive_stream.h"
solenbergc7a8b082015-10-16 14:35:07 -070017#include "webrtc/audio/audio_send_stream.h"
solenberg566ef242015-11-06 15:34:49 -080018#include "webrtc/audio/audio_state.h"
19#include "webrtc/audio/scoped_voe_interface.h"
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +000020#include "webrtc/base/checks.h"
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000021#include "webrtc/base/scoped_ptr.h"
pbos@webrtc.org38344ed2014-09-24 06:05:00 +000022#include "webrtc/base/thread_annotations.h"
solenberg5a289392015-10-19 03:39:20 -070023#include "webrtc/base/thread_checker.h"
tommie4f96502015-10-20 23:00:48 -070024#include "webrtc/base/trace_event.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000025#include "webrtc/call.h"
mflodman0c478b32015-10-21 15:52:16 +020026#include "webrtc/call/congestion_controller.h"
Peter Boström5c389d32015-09-25 13:58:30 +020027#include "webrtc/call/rtc_event_log.h"
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +000028#include "webrtc/common.h"
pbos@webrtc.orgc49d5b72013-12-05 12:11:47 +000029#include "webrtc/config.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010030#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
sprang@webrtc.org2a6558c2015-01-28 12:37:36 +000031#include "webrtc/modules/rtp_rtcp/source/byte_io.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010032#include "webrtc/modules/utility/include/process_thread.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010033#include "webrtc/system_wrappers/include/cpu_info.h"
34#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
35#include "webrtc/system_wrappers/include/logging.h"
stefan91d92602015-11-11 10:13:02 -080036#include "webrtc/system_wrappers/include/metrics.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010037#include "webrtc/system_wrappers/include/rw_lock_wrapper.h"
38#include "webrtc/system_wrappers/include/trace.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000039#include "webrtc/video/video_receive_stream.h"
40#include "webrtc/video/video_send_stream.h"
mflodmane3787022015-10-21 13:24:28 +020041#include "webrtc/video_engine/call_stats.h"
ivocb04965c2015-09-09 00:09:43 -070042#include "webrtc/voice_engine/include/voe_codec.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000043
44namespace webrtc {
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000045
pbos@webrtc.orga73a6782014-10-14 11:52:10 +000046const int Call::Config::kDefaultStartBitrateBps = 300000;
47
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000048namespace internal {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000049
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000050class Call : public webrtc::Call, public PacketReceiver {
51 public:
Peter Boström45553ae2015-05-08 13:54:38 +020052 explicit Call(const Call::Config& config);
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000053 virtual ~Call();
54
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000055 PacketReceiver* Receiver() override;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000056
Fredrik Solenberg04f49312015-06-08 13:04:56 +020057 webrtc::AudioSendStream* CreateAudioSendStream(
58 const webrtc::AudioSendStream::Config& config) override;
59 void DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) override;
60
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020061 webrtc::AudioReceiveStream* CreateAudioReceiveStream(
62 const webrtc::AudioReceiveStream::Config& config) override;
63 void DestroyAudioReceiveStream(
64 webrtc::AudioReceiveStream* receive_stream) override;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000065
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020066 webrtc::VideoSendStream* CreateVideoSendStream(
67 const webrtc::VideoSendStream::Config& config,
68 const VideoEncoderConfig& encoder_config) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000069 void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) override;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000070
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020071 webrtc::VideoReceiveStream* CreateVideoReceiveStream(
72 const webrtc::VideoReceiveStream::Config& config) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000073 void DestroyVideoReceiveStream(
74 webrtc::VideoReceiveStream* receive_stream) override;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000075
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000076 Stats GetStats() const override;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000077
stefan68786d22015-09-08 05:36:15 -070078 DeliveryStatus DeliverPacket(MediaType media_type,
79 const uint8_t* packet,
80 size_t length,
81 const PacketTime& packet_time) override;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000082
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000083 void SetBitrateConfig(
84 const webrtc::Call::Config::BitrateConfig& bitrate_config) override;
85 void SignalNetworkState(NetworkState state) override;
pbos@webrtc.org26c0c412014-09-03 16:17:12 +000086
stefanc1aeaf02015-10-15 07:26:07 -070087 void OnSentPacket(const rtc::SentPacket& sent_packet) override;
88
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000089 private:
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020090 DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet,
91 size_t length);
stefan68786d22015-09-08 05:36:15 -070092 DeliveryStatus DeliverRtp(MediaType media_type,
93 const uint8_t* packet,
94 size_t length,
95 const PacketTime& packet_time);
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000096
pbos8fc7fa72015-07-15 08:02:58 -070097 void ConfigureSync(const std::string& sync_group)
98 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_);
99
solenberg566ef242015-11-06 15:34:49 -0800100 VoiceEngine* voice_engine() {
101 internal::AudioState* audio_state =
102 static_cast<internal::AudioState*>(config_.audio_state.get());
103 if (audio_state)
104 return audio_state->voice_engine();
105 else
106 return nullptr;
107 }
108
stefan91d92602015-11-11 10:13:02 -0800109 void UpdateHistograms();
110
111 const Clock* const clock_;
112
Peter Boström45553ae2015-05-08 13:54:38 +0200113 const int num_cpu_cores_;
114 const rtc::scoped_ptr<ProcessThread> module_process_thread_;
mflodmane3787022015-10-21 13:24:28 +0200115 const rtc::scoped_ptr<CallStats> call_stats_;
mflodman0c478b32015-10-21 15:52:16 +0200116 const rtc::scoped_ptr<CongestionController> congestion_controller_;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000117 Call::Config config_;
solenberg5a289392015-10-19 03:39:20 -0700118 rtc::ThreadChecker configuration_thread_checker_;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000119
mflodman717432f2015-10-26 16:34:46 +0100120 bool network_enabled_;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000121
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000122 rtc::scoped_ptr<RWLockWrapper> receive_crit_;
solenbergc7a8b082015-10-16 14:35:07 -0700123 // Audio and Video receive streams are owned by the client that creates them.
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200124 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000125 GUARDED_BY(receive_crit_);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200126 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_
127 GUARDED_BY(receive_crit_);
128 std::set<VideoReceiveStream*> video_receive_streams_
129 GUARDED_BY(receive_crit_);
pbos8fc7fa72015-07-15 08:02:58 -0700130 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_
131 GUARDED_BY(receive_crit_);
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000132
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000133 rtc::scoped_ptr<RWLockWrapper> send_crit_;
solenbergc7a8b082015-10-16 14:35:07 -0700134 // Audio and Video send streams are owned by the client that creates them.
135 std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200136 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_);
137 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_);
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000138
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200139 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000140
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200141 RtcEventLog* event_log_ = nullptr;
ivocb04965c2015-09-09 00:09:43 -0700142
stefan91d92602015-11-11 10:13:02 -0800143 // The RateTrackers are only accessed (exclusively) from DeliverRtp or
144 // DeliverRtcp, and from the destructor, and therefore doesn't need any
145 // explicit synchronization.
146 rtc::RateTracker received_video_bytes_per_sec_;
147 rtc::RateTracker received_audio_bytes_per_sec_;
148 rtc::RateTracker received_rtcp_bytes_per_sec_;
149 int64_t first_rtp_packet_received_ms_;
150
henrikg3c089d72015-09-16 05:37:44 -0700151 RTC_DISALLOW_COPY_AND_ASSIGN(Call);
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000152};
pbos@webrtc.orgc49d5b72013-12-05 12:11:47 +0000153} // namespace internal
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000154
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000155Call* Call::Create(const Call::Config& config) {
Peter Boström45553ae2015-05-08 13:54:38 +0200156 return new internal::Call(config);
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000157}
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000158
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000159namespace internal {
160
Peter Boström45553ae2015-05-08 13:54:38 +0200161Call::Call(const Call::Config& config)
stefan91d92602015-11-11 10:13:02 -0800162 : clock_(Clock::GetRealTimeClock()),
163 num_cpu_cores_(CpuInfo::DetectNumberOfCores()),
stefan847855b2015-09-11 09:52:15 -0700164 module_process_thread_(ProcessThread::Create("ModuleProcessThread")),
mflodmane3787022015-10-21 13:24:28 +0200165 call_stats_(new CallStats()),
stefan91d92602015-11-11 10:13:02 -0800166 congestion_controller_(
167 new CongestionController(module_process_thread_.get(),
168 call_stats_.get())),
Peter Boström45553ae2015-05-08 13:54:38 +0200169 config_(config),
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000170 network_enabled_(true),
171 receive_crit_(RWLockWrapper::CreateRWLock()),
stefan91d92602015-11-11 10:13:02 -0800172 send_crit_(RWLockWrapper::CreateRWLock()),
173 received_video_bytes_per_sec_(1000, 1),
174 received_audio_bytes_per_sec_(1000, 1),
175 received_rtcp_bytes_per_sec_(1000, 1),
176 first_rtp_packet_received_ms_(-1) {
solenberg56a34df2015-11-12 08:24:41 -0800177 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
henrikg91d6ede2015-09-17 00:24:34 -0700178 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0);
179 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps,
180 config.bitrate_config.min_bitrate_bps);
Stefan Holmere5904162015-03-26 11:11:06 +0100181 if (config.bitrate_config.max_bitrate_bps != -1) {
henrikg91d6ede2015-09-17 00:24:34 -0700182 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps,
183 config.bitrate_config.start_bitrate_bps);
pbos@webrtc.org00873182014-11-25 14:03:34 +0000184 }
solenberg566ef242015-11-06 15:34:49 -0800185 if (config.audio_state.get()) {
186 ScopedVoEInterface<VoECodec> voe_codec(voice_engine());
187 event_log_ = voe_codec->GetEventLog();
ivocb04965c2015-09-09 00:09:43 -0700188 }
pbos@webrtc.org00873182014-11-25 14:03:34 +0000189
Peter Boström45553ae2015-05-08 13:54:38 +0200190 Trace::CreateTrace();
191 module_process_thread_->Start();
mflodmane3787022015-10-21 13:24:28 +0200192 module_process_thread_->RegisterModule(call_stats_.get());
Peter Boström45553ae2015-05-08 13:54:38 +0200193
mflodman0c478b32015-10-21 15:52:16 +0200194 congestion_controller_->SetBweBitrates(
195 config_.bitrate_config.min_bitrate_bps,
196 config_.bitrate_config.start_bitrate_bps,
197 config_.bitrate_config.max_bitrate_bps);
terelius006d93d2015-11-05 12:02:15 -0800198
199 congestion_controller_->GetBitrateController()->SetEventLog(event_log_);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000200}
201
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000202Call::~Call() {
solenberg5a289392015-10-19 03:39:20 -0700203 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
solenberg56a34df2015-11-12 08:24:41 -0800204 UpdateHistograms();
solenbergc7a8b082015-10-16 14:35:07 -0700205 RTC_CHECK(audio_send_ssrcs_.empty());
206 RTC_CHECK(video_send_ssrcs_.empty());
207 RTC_CHECK(video_send_streams_.empty());
208 RTC_CHECK(audio_receive_ssrcs_.empty());
209 RTC_CHECK(video_receive_ssrcs_.empty());
210 RTC_CHECK(video_receive_streams_.empty());
pbos@webrtc.org9e4e5242015-02-12 10:48:23 +0000211
mflodmane3787022015-10-21 13:24:28 +0200212 module_process_thread_->DeRegisterModule(call_stats_.get());
Peter Boström45553ae2015-05-08 13:54:38 +0200213 module_process_thread_->Stop();
214 Trace::ReturnTrace();
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000215}
216
stefan91d92602015-11-11 10:13:02 -0800217void Call::UpdateHistograms() {
218 if (first_rtp_packet_received_ms_ == -1)
219 return;
220 int64_t elapsed_sec =
221 (clock_->TimeInMilliseconds() - first_rtp_packet_received_ms_) / 1000;
222 if (elapsed_sec < metrics::kMinRunTimeInSeconds)
223 return;
224 int audio_bitrate_kbps =
225 received_audio_bytes_per_sec_.ComputeTotalRate() * 8 / 1000;
226 int video_bitrate_kbps =
227 received_video_bytes_per_sec_.ComputeTotalRate() * 8 / 1000;
228 int rtcp_bitrate_bps = received_rtcp_bytes_per_sec_.ComputeTotalRate() * 8;
229 if (video_bitrate_kbps > 0) {
230 RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.VideoBitrateReceivedInKbps",
231 video_bitrate_kbps);
232 }
233 if (audio_bitrate_kbps > 0) {
234 RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.AudioBitrateReceivedInKbps",
235 audio_bitrate_kbps);
236 }
237 if (rtcp_bitrate_bps > 0) {
238 RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.RtcpBitrateReceivedInBps",
239 rtcp_bitrate_bps);
240 }
241 RTC_HISTOGRAM_COUNTS_100000(
242 "WebRTC.Call.BitrateReceivedInKbps",
243 audio_bitrate_kbps + video_bitrate_kbps + rtcp_bitrate_bps / 1000);
244}
245
solenberg5a289392015-10-19 03:39:20 -0700246PacketReceiver* Call::Receiver() {
247 // TODO(solenberg): Some test cases in EndToEndTest use this from a different
248 // thread. Re-enable once that is fixed.
249 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
250 return this;
251}
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000252
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200253webrtc::AudioSendStream* Call::CreateAudioSendStream(
254 const webrtc::AudioSendStream::Config& config) {
solenbergc7a8b082015-10-16 14:35:07 -0700255 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream");
solenberg5a289392015-10-19 03:39:20 -0700256 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
solenberg85a04962015-10-27 03:35:21 -0700257 AudioSendStream* send_stream =
solenberg566ef242015-11-06 15:34:49 -0800258 new AudioSendStream(config, config_.audio_state);
mflodman717432f2015-10-26 16:34:46 +0100259 if (!network_enabled_)
260 send_stream->SignalNetworkState(kNetworkDown);
solenbergc7a8b082015-10-16 14:35:07 -0700261 {
solenbergc7a8b082015-10-16 14:35:07 -0700262 WriteLockScoped write_lock(*send_crit_);
263 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) ==
264 audio_send_ssrcs_.end());
265 audio_send_ssrcs_[config.rtp.ssrc] = send_stream;
solenbergc7a8b082015-10-16 14:35:07 -0700266 }
267 return send_stream;
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200268}
269
270void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) {
solenbergc7a8b082015-10-16 14:35:07 -0700271 TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream");
solenberg5a289392015-10-19 03:39:20 -0700272 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
solenbergc7a8b082015-10-16 14:35:07 -0700273 RTC_DCHECK(send_stream != nullptr);
274
275 send_stream->Stop();
276
277 webrtc::internal::AudioSendStream* audio_send_stream =
278 static_cast<webrtc::internal::AudioSendStream*>(send_stream);
279 {
280 WriteLockScoped write_lock(*send_crit_);
281 size_t num_deleted = audio_send_ssrcs_.erase(
282 audio_send_stream->config().rtp.ssrc);
283 RTC_DCHECK(num_deleted == 1);
284 }
285 delete audio_send_stream;
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200286}
287
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200288webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream(
289 const webrtc::AudioReceiveStream::Config& config) {
290 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream");
solenberg5a289392015-10-19 03:39:20 -0700291 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200292 AudioReceiveStream* receive_stream = new AudioReceiveStream(
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200293 congestion_controller_->GetRemoteBitrateEstimator(false), config,
solenberg566ef242015-11-06 15:34:49 -0800294 config_.audio_state);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200295 {
296 WriteLockScoped write_lock(*receive_crit_);
henrikg91d6ede2015-09-17 00:24:34 -0700297 RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) ==
298 audio_receive_ssrcs_.end());
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200299 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream;
pbos8fc7fa72015-07-15 08:02:58 -0700300 ConfigureSync(config.sync_group);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200301 }
302 return receive_stream;
303}
304
305void Call::DestroyAudioReceiveStream(
306 webrtc::AudioReceiveStream* receive_stream) {
307 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream");
solenberg5a289392015-10-19 03:39:20 -0700308 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
henrikg91d6ede2015-09-17 00:24:34 -0700309 RTC_DCHECK(receive_stream != nullptr);
solenbergc7a8b082015-10-16 14:35:07 -0700310 webrtc::internal::AudioReceiveStream* audio_receive_stream =
311 static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200312 {
313 WriteLockScoped write_lock(*receive_crit_);
314 size_t num_deleted = audio_receive_ssrcs_.erase(
315 audio_receive_stream->config().rtp.remote_ssrc);
henrikg91d6ede2015-09-17 00:24:34 -0700316 RTC_DCHECK(num_deleted == 1);
pbos8fc7fa72015-07-15 08:02:58 -0700317 const std::string& sync_group = audio_receive_stream->config().sync_group;
318 const auto it = sync_stream_mapping_.find(sync_group);
319 if (it != sync_stream_mapping_.end() &&
320 it->second == audio_receive_stream) {
321 sync_stream_mapping_.erase(it);
322 ConfigureSync(sync_group);
323 }
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200324 }
325 delete audio_receive_stream;
326}
327
328webrtc::VideoSendStream* Call::CreateVideoSendStream(
329 const webrtc::VideoSendStream::Config& config,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000330 const VideoEncoderConfig& encoder_config) {
pbos@webrtc.org50fe3592015-01-29 12:33:07 +0000331 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream");
solenberg5a289392015-10-19 03:39:20 -0700332 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
pbos@webrtc.org1819fd72013-06-10 13:48:26 +0000333
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000334 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if
335 // the call has already started.
mflodman0c478b32015-10-21 15:52:16 +0200336 VideoSendStream* send_stream = new VideoSendStream(
337 num_cpu_cores_, module_process_thread_.get(), call_stats_.get(),
338 congestion_controller_.get(), config, encoder_config,
339 suspended_video_send_ssrcs_);
pbos@webrtc.org1819fd72013-06-10 13:48:26 +0000340
mflodman717432f2015-10-26 16:34:46 +0100341 if (!network_enabled_)
342 send_stream->SignalNetworkState(kNetworkDown);
343
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000344 WriteLockScoped write_lock(*send_crit_);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200345 for (uint32_t ssrc : config.rtp.ssrcs) {
henrikg91d6ede2015-09-17 00:24:34 -0700346 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end());
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200347 video_send_ssrcs_[ssrc] = send_stream;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000348 }
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200349 video_send_streams_.insert(send_stream);
350
ivocb04965c2015-09-09 00:09:43 -0700351 if (event_log_)
352 event_log_->LogVideoSendStreamConfig(config);
353
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000354 return send_stream;
355}
356
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000357void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) {
pbos@webrtc.org50fe3592015-01-29 12:33:07 +0000358 TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream");
henrikg91d6ede2015-09-17 00:24:34 -0700359 RTC_DCHECK(send_stream != nullptr);
solenberg5a289392015-10-19 03:39:20 -0700360 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000361
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000362 send_stream->Stop();
363
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +0000364 VideoSendStream* send_stream_impl = nullptr;
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000365 {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000366 WriteLockScoped write_lock(*send_crit_);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200367 auto it = video_send_ssrcs_.begin();
368 while (it != video_send_ssrcs_.end()) {
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000369 if (it->second == static_cast<VideoSendStream*>(send_stream)) {
370 send_stream_impl = it->second;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200371 video_send_ssrcs_.erase(it++);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000372 } else {
373 ++it;
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000374 }
375 }
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200376 video_send_streams_.erase(send_stream_impl);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000377 }
henrikg91d6ede2015-09-17 00:24:34 -0700378 RTC_CHECK(send_stream_impl != nullptr);
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000379
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000380 VideoSendStream::RtpStateMap rtp_state = send_stream_impl->GetRtpStates();
381
382 for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin();
383 it != rtp_state.end();
384 ++it) {
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200385 suspended_video_send_ssrcs_[it->first] = it->second;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000386 }
387
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000388 delete send_stream_impl;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000389}
390
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200391webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream(
392 const webrtc::VideoReceiveStream::Config& config) {
pbos@webrtc.org50fe3592015-01-29 12:33:07 +0000393 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream");
solenberg5a289392015-10-19 03:39:20 -0700394 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
Peter Boströmc4188fd2015-04-24 15:16:03 +0200395 VideoReceiveStream* receive_stream = new VideoReceiveStream(
mflodman0c478b32015-10-21 15:52:16 +0200396 num_cpu_cores_, congestion_controller_.get(), config,
solenberg566ef242015-11-06 15:34:49 -0800397 voice_engine(), module_process_thread_.get(), call_stats_.get());
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000398
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000399 WriteLockScoped write_lock(*receive_crit_);
henrikg91d6ede2015-09-17 00:24:34 -0700400 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) ==
401 video_receive_ssrcs_.end());
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200402 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000403 // TODO(pbos): Configure different RTX payloads per receive payload.
404 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it =
405 config.rtp.rtx.begin();
406 if (it != config.rtp.rtx.end())
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200407 video_receive_ssrcs_[it->second.ssrc] = receive_stream;
408 video_receive_streams_.insert(receive_stream);
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000409
pbos8fc7fa72015-07-15 08:02:58 -0700410 ConfigureSync(config.sync_group);
411
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000412 if (!network_enabled_)
413 receive_stream->SignalNetworkState(kNetworkDown);
pbos8fc7fa72015-07-15 08:02:58 -0700414
ivocb04965c2015-09-09 00:09:43 -0700415 if (event_log_)
416 event_log_->LogVideoReceiveStreamConfig(config);
417
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000418 return receive_stream;
419}
420
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000421void Call::DestroyVideoReceiveStream(
422 webrtc::VideoReceiveStream* receive_stream) {
pbos@webrtc.org50fe3592015-01-29 12:33:07 +0000423 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream");
solenberg5a289392015-10-19 03:39:20 -0700424 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
henrikg91d6ede2015-09-17 00:24:34 -0700425 RTC_DCHECK(receive_stream != nullptr);
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +0000426 VideoReceiveStream* receive_stream_impl = nullptr;
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000427 {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000428 WriteLockScoped write_lock(*receive_crit_);
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000429 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a
430 // separate SSRC there can be either one or two.
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200431 auto it = video_receive_ssrcs_.begin();
432 while (it != video_receive_ssrcs_.end()) {
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000433 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) {
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +0000434 if (receive_stream_impl != nullptr)
henrikg91d6ede2015-09-17 00:24:34 -0700435 RTC_DCHECK(receive_stream_impl == it->second);
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000436 receive_stream_impl = it->second;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200437 video_receive_ssrcs_.erase(it++);
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000438 } else {
439 ++it;
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000440 }
441 }
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200442 video_receive_streams_.erase(receive_stream_impl);
henrikg91d6ede2015-09-17 00:24:34 -0700443 RTC_CHECK(receive_stream_impl != nullptr);
pbos8fc7fa72015-07-15 08:02:58 -0700444 ConfigureSync(receive_stream_impl->config().sync_group);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000445 }
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000446 delete receive_stream_impl;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000447}
448
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000449Call::Stats Call::GetStats() const {
solenberg5a289392015-10-19 03:39:20 -0700450 // TODO(solenberg): Some test cases in EndToEndTest use this from a different
451 // thread. Re-enable once that is fixed.
452 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000453 Stats stats;
Peter Boström45553ae2015-05-08 13:54:38 +0200454 // Fetch available send/receive bitrates.
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000455 uint32_t send_bandwidth = 0;
mflodman0c478b32015-10-21 15:52:16 +0200456 congestion_controller_->GetBitrateController()->AvailableBandwidth(
457 &send_bandwidth);
Peter Boström45553ae2015-05-08 13:54:38 +0200458 std::vector<unsigned int> ssrcs;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000459 uint32_t recv_bandwidth = 0;
mflodman0c478b32015-10-21 15:52:16 +0200460 congestion_controller_->GetRemoteBitrateEstimator(false)->LatestEstimate(
mflodmana20de202015-10-18 22:08:19 -0700461 &ssrcs, &recv_bandwidth);
Peter Boström45553ae2015-05-08 13:54:38 +0200462 stats.send_bandwidth_bps = send_bandwidth;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000463 stats.recv_bandwidth_bps = recv_bandwidth;
mflodman0c478b32015-10-21 15:52:16 +0200464 stats.pacer_delay_ms = congestion_controller_->GetPacerQueuingDelayMs();
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000465 {
466 ReadLockScoped read_lock(*send_crit_);
solenbergc7a8b082015-10-16 14:35:07 -0700467 // TODO(solenberg): Add audio send streams.
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200468 for (const auto& kv : video_send_ssrcs_) {
469 int rtt_ms = kv.second->GetRtt();
pbos@webrtc.org2b19f062014-12-11 13:26:09 +0000470 if (rtt_ms > 0)
471 stats.rtt_ms = rtt_ms;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000472 }
473 }
474 return stats;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000475}
476
pbos@webrtc.org00873182014-11-25 14:03:34 +0000477void Call::SetBitrateConfig(
478 const webrtc::Call::Config::BitrateConfig& bitrate_config) {
pbos@webrtc.org50fe3592015-01-29 12:33:07 +0000479 TRACE_EVENT0("webrtc", "Call::SetBitrateConfig");
solenberg5a289392015-10-19 03:39:20 -0700480 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
henrikg91d6ede2015-09-17 00:24:34 -0700481 RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0);
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +0000482 if (bitrate_config.max_bitrate_bps != -1)
henrikg91d6ede2015-09-17 00:24:34 -0700483 RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0);
Stefan Holmere5904162015-03-26 11:11:06 +0100484 if (config_.bitrate_config.min_bitrate_bps ==
pbos@webrtc.org00873182014-11-25 14:03:34 +0000485 bitrate_config.min_bitrate_bps &&
486 (bitrate_config.start_bitrate_bps <= 0 ||
Stefan Holmere5904162015-03-26 11:11:06 +0100487 config_.bitrate_config.start_bitrate_bps ==
pbos@webrtc.org00873182014-11-25 14:03:34 +0000488 bitrate_config.start_bitrate_bps) &&
Stefan Holmere5904162015-03-26 11:11:06 +0100489 config_.bitrate_config.max_bitrate_bps ==
pbos@webrtc.org00873182014-11-25 14:03:34 +0000490 bitrate_config.max_bitrate_bps) {
491 // Nothing new to set, early abort to avoid encoder reconfigurations.
492 return;
493 }
Stefan Holmere5904162015-03-26 11:11:06 +0100494 config_.bitrate_config = bitrate_config;
mflodman0c478b32015-10-21 15:52:16 +0200495 congestion_controller_->SetBweBitrates(bitrate_config.min_bitrate_bps,
496 bitrate_config.start_bitrate_bps,
497 bitrate_config.max_bitrate_bps);
pbos@webrtc.org00873182014-11-25 14:03:34 +0000498}
499
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000500void Call::SignalNetworkState(NetworkState state) {
solenberg5a289392015-10-19 03:39:20 -0700501 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000502 network_enabled_ = state == kNetworkUp;
mflodman0c478b32015-10-21 15:52:16 +0200503 congestion_controller_->SignalNetworkState(state);
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000504 {
505 ReadLockScoped write_lock(*send_crit_);
solenbergc7a8b082015-10-16 14:35:07 -0700506 for (auto& kv : audio_send_ssrcs_) {
507 kv.second->SignalNetworkState(state);
508 }
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200509 for (auto& kv : video_send_ssrcs_) {
510 kv.second->SignalNetworkState(state);
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000511 }
512 }
513 {
514 ReadLockScoped write_lock(*receive_crit_);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200515 for (auto& kv : video_receive_ssrcs_) {
516 kv.second->SignalNetworkState(state);
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000517 }
518 }
519}
520
stefanc1aeaf02015-10-15 07:26:07 -0700521void Call::OnSentPacket(const rtc::SentPacket& sent_packet) {
mflodman0c478b32015-10-21 15:52:16 +0200522 congestion_controller_->OnSentPacket(sent_packet);
stefanc1aeaf02015-10-15 07:26:07 -0700523}
524
pbos8fc7fa72015-07-15 08:02:58 -0700525void Call::ConfigureSync(const std::string& sync_group) {
526 // Set sync only if there was no previous one.
solenberg566ef242015-11-06 15:34:49 -0800527 if (voice_engine() == nullptr || sync_group.empty())
pbos8fc7fa72015-07-15 08:02:58 -0700528 return;
529
530 AudioReceiveStream* sync_audio_stream = nullptr;
531 // Find existing audio stream.
532 const auto it = sync_stream_mapping_.find(sync_group);
533 if (it != sync_stream_mapping_.end()) {
534 sync_audio_stream = it->second;
535 } else {
536 // No configured audio stream, see if we can find one.
537 for (const auto& kv : audio_receive_ssrcs_) {
538 if (kv.second->config().sync_group == sync_group) {
539 if (sync_audio_stream != nullptr) {
540 LOG(LS_WARNING) << "Attempting to sync more than one audio stream "
541 "within the same sync group. This is not "
542 "supported in the current implementation.";
543 break;
544 }
545 sync_audio_stream = kv.second;
546 }
547 }
548 }
549 if (sync_audio_stream)
550 sync_stream_mapping_[sync_group] = sync_audio_stream;
551 size_t num_synced_streams = 0;
552 for (VideoReceiveStream* video_stream : video_receive_streams_) {
553 if (video_stream->config().sync_group != sync_group)
554 continue;
555 ++num_synced_streams;
556 if (num_synced_streams > 1) {
557 // TODO(pbos): Support synchronizing more than one A/V pair.
558 // https://code.google.com/p/webrtc/issues/detail?id=4762
559 LOG(LS_WARNING) << "Attempting to sync more than one audio/video pair "
560 "within the same sync group. This is not supported in "
561 "the current implementation.";
562 }
563 // Only sync the first A/V pair within this sync group.
564 if (sync_audio_stream != nullptr && num_synced_streams == 1) {
solenberg566ef242015-11-06 15:34:49 -0800565 video_stream->SetSyncChannel(voice_engine(),
pbos8fc7fa72015-07-15 08:02:58 -0700566 sync_audio_stream->config().voe_channel_id);
567 } else {
solenberg566ef242015-11-06 15:34:49 -0800568 video_stream->SetSyncChannel(voice_engine(), -1);
pbos8fc7fa72015-07-15 08:02:58 -0700569 }
570 }
571}
572
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200573PacketReceiver::DeliveryStatus Call::DeliverRtcp(MediaType media_type,
574 const uint8_t* packet,
575 size_t length) {
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000576 // TODO(pbos): Figure out what channel needs it actually.
577 // Do NOT broadcast! Also make sure it's a valid packet.
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000578 // Return DELIVERY_UNKNOWN_SSRC if it can be determined that
579 // there's no receiver of the packet.
stefan91d92602015-11-11 10:13:02 -0800580 received_rtcp_bytes_per_sec_.AddSamples(length);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000581 bool rtcp_delivered = false;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200582 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000583 ReadLockScoped read_lock(*receive_crit_);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200584 for (VideoReceiveStream* stream : video_receive_streams_) {
ivocb04965c2015-09-09 00:09:43 -0700585 if (stream->DeliverRtcp(packet, length)) {
pbos@webrtc.org40523702013-08-05 12:49:22 +0000586 rtcp_delivered = true;
ivocb04965c2015-09-09 00:09:43 -0700587 if (event_log_)
588 event_log_->LogRtcpPacket(true, media_type, packet, length);
589 }
pbos@webrtc.orgbbb07e62013-08-05 12:01:36 +0000590 }
591 }
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200592 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000593 ReadLockScoped read_lock(*send_crit_);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200594 for (VideoSendStream* stream : video_send_streams_) {
ivocb04965c2015-09-09 00:09:43 -0700595 if (stream->DeliverRtcp(packet, length)) {
pbos@webrtc.org40523702013-08-05 12:49:22 +0000596 rtcp_delivered = true;
ivocb04965c2015-09-09 00:09:43 -0700597 if (event_log_)
598 event_log_->LogRtcpPacket(false, media_type, packet, length);
599 }
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000600 }
601 }
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000602 return rtcp_delivered ? DELIVERY_OK : DELIVERY_PACKET_ERROR;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000603}
604
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200605PacketReceiver::DeliveryStatus Call::DeliverRtp(MediaType media_type,
606 const uint8_t* packet,
stefan68786d22015-09-08 05:36:15 -0700607 size_t length,
608 const PacketTime& packet_time) {
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000609 // Minimum RTP header size.
610 if (length < 12)
611 return DELIVERY_PACKET_ERROR;
612
stefan91d92602015-11-11 10:13:02 -0800613 if (first_rtp_packet_received_ms_ == -1)
614 first_rtp_packet_received_ms_ = clock_->TimeInMilliseconds();
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000615
stefan91d92602015-11-11 10:13:02 -0800616 uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]);
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000617 ReadLockScoped read_lock(*receive_crit_);
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200618 if (media_type == MediaType::ANY || media_type == MediaType::AUDIO) {
619 auto it = audio_receive_ssrcs_.find(ssrc);
620 if (it != audio_receive_ssrcs_.end()) {
stefan91d92602015-11-11 10:13:02 -0800621 received_audio_bytes_per_sec_.AddSamples(length);
ivocb04965c2015-09-09 00:09:43 -0700622 auto status = it->second->DeliverRtp(packet, length, packet_time)
623 ? DELIVERY_OK
624 : DELIVERY_PACKET_ERROR;
625 if (status == DELIVERY_OK && event_log_)
626 event_log_->LogRtpHeader(true, media_type, packet, length);
627 return status;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200628 }
629 }
630 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) {
631 auto it = video_receive_ssrcs_.find(ssrc);
632 if (it != video_receive_ssrcs_.end()) {
stefan91d92602015-11-11 10:13:02 -0800633 received_video_bytes_per_sec_.AddSamples(length);
ivocb04965c2015-09-09 00:09:43 -0700634 auto status = it->second->DeliverRtp(packet, length, packet_time)
635 ? DELIVERY_OK
636 : DELIVERY_PACKET_ERROR;
637 if (status == DELIVERY_OK && event_log_)
638 event_log_->LogRtpHeader(true, media_type, packet, length);
639 return status;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200640 }
641 }
642 return DELIVERY_UNKNOWN_SSRC;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000643}
644
stefan68786d22015-09-08 05:36:15 -0700645PacketReceiver::DeliveryStatus Call::DeliverPacket(
646 MediaType media_type,
647 const uint8_t* packet,
648 size_t length,
649 const PacketTime& packet_time) {
solenberg5a289392015-10-19 03:39:20 -0700650 // TODO(solenberg): Tests call this function on a network thread, libjingle
651 // calls on the worker thread. We should move towards always using a network
652 // thread. Then this check can be enabled.
653 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread());
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000654 if (RtpHeaderParser::IsRtcp(packet, length))
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200655 return DeliverRtcp(media_type, packet, length);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000656
stefan68786d22015-09-08 05:36:15 -0700657 return DeliverRtp(media_type, packet, length, packet_time);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000658}
659
660} // namespace internal
661} // namespace webrtc