blob: 442e75bd7adb9948e3bb9deda100ce88963e532f [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 <assert.h>
12#include <string.h>
13
pbos@webrtc.org29d58392013-05-16 12:08:03 +000014#include <map>
15#include <vector>
16
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000017#include "webrtc/call.h"
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +000018#include "webrtc/common.h"
pbos@webrtc.orgc49d5b72013-12-05 12:11:47 +000019#include "webrtc/config.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000020#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000021#include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
pbos@webrtc.orgde74b642013-10-02 13:36:09 +000022#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000023#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h"
pbos@webrtc.orgde74b642013-10-02 13:36:09 +000024#include "webrtc/system_wrappers/interface/scoped_ptr.h"
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000025#include "webrtc/system_wrappers/interface/thread_annotations.h"
pbos@webrtc.orgde74b642013-10-02 13:36:09 +000026#include "webrtc/system_wrappers/interface/trace.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000027#include "webrtc/video/video_receive_stream.h"
28#include "webrtc/video/video_send_stream.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000029#include "webrtc/video_engine/include/vie_base.h"
30#include "webrtc/video_engine/include/vie_codec.h"
31#include "webrtc/video_engine/include/vie_rtp_rtcp.h"
pbos@webrtc.org26c0c412014-09-03 16:17:12 +000032#include "webrtc/video_engine/include/vie_network.h"
33#include "webrtc/video_engine/include/vie_rtp_rtcp.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000034
35namespace webrtc {
pbos@webrtc.orgc49d5b72013-12-05 12:11:47 +000036const char* RtpExtension::kTOffset = "urn:ietf:params:rtp-hdrext:toffset";
37const char* RtpExtension::kAbsSendTime =
38 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
pbos@webrtc.org3c107582014-07-20 15:27:35 +000039
40bool RtpExtension::IsSupported(const std::string& name) {
41 return name == webrtc::RtpExtension::kTOffset ||
42 name == webrtc::RtpExtension::kAbsSendTime;
43}
44
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +000045VideoEncoder* VideoEncoder::Create(VideoEncoder::EncoderType codec_type) {
46 switch (codec_type) {
47 case kVp8:
48 return VP8Encoder::Create();
49 }
50 assert(false);
51 return NULL;
52}
53
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000054namespace internal {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000055
56class CpuOveruseObserverProxy : public webrtc::CpuOveruseObserver {
57 public:
pbos@webrtc.orgdde16f12014-08-05 23:35:43 +000058 explicit CpuOveruseObserverProxy(OveruseCallback* overuse_callback)
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000059 : crit_(CriticalSectionWrapper::CreateCriticalSection()),
60 overuse_callback_(overuse_callback) {
61 assert(overuse_callback != NULL);
62 }
63
64 virtual ~CpuOveruseObserverProxy() {}
65
66 virtual void OveruseDetected() OVERRIDE {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000067 CriticalSectionScoped lock(crit_.get());
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000068 overuse_callback_->OnOveruse();
69 }
70
71 virtual void NormalUsage() OVERRIDE {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000072 CriticalSectionScoped lock(crit_.get());
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000073 overuse_callback_->OnNormalUse();
74 }
75
76 private:
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000077 const scoped_ptr<CriticalSectionWrapper> crit_;
78 OveruseCallback* overuse_callback_ GUARDED_BY(crit_);
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000079};
80
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000081class Call : public webrtc::Call, public PacketReceiver {
82 public:
83 Call(webrtc::VideoEngine* video_engine, const Call::Config& config);
84 virtual ~Call();
85
86 virtual PacketReceiver* Receiver() OVERRIDE;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000087
pbos@webrtc.org5a636552013-11-20 10:40:25 +000088 virtual VideoSendStream* CreateVideoSendStream(
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +000089 const VideoSendStream::Config& config,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +000090 const VideoEncoderConfig& encoder_config) OVERRIDE;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000091
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +000092 virtual void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream)
93 OVERRIDE;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000094
pbos@webrtc.org5a636552013-11-20 10:40:25 +000095 virtual VideoReceiveStream* CreateVideoReceiveStream(
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000096 const VideoReceiveStream::Config& config) OVERRIDE;
97
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +000098 virtual void DestroyVideoReceiveStream(
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000099 webrtc::VideoReceiveStream* receive_stream) OVERRIDE;
100
101 virtual uint32_t SendBitrateEstimate() OVERRIDE;
102 virtual uint32_t ReceiveBitrateEstimate() OVERRIDE;
103
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000104 virtual DeliveryStatus DeliverPacket(const uint8_t* packet,
105 size_t length) OVERRIDE;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000106
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000107 virtual void SignalNetworkState(NetworkState state) OVERRIDE;
108
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000109 private:
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000110 DeliveryStatus DeliverRtcp(const uint8_t* packet, size_t length);
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000111 DeliveryStatus DeliverRtp(const uint8_t* packet, size_t length);
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000112
113 Call::Config config_;
114
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000115 // Needs to be held while write-locking |receive_crit_| or |send_crit_|. This
116 // ensures that we have a consistent network state signalled to all senders
117 // and receivers.
118 scoped_ptr<CriticalSectionWrapper> network_enabled_crit_;
119 bool network_enabled_ GUARDED_BY(network_enabled_crit_);
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000120
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000121 scoped_ptr<RWLockWrapper> receive_crit_;
122 std::map<uint32_t, VideoReceiveStream*> receive_ssrcs_
123 GUARDED_BY(receive_crit_);
124
125 scoped_ptr<RWLockWrapper> send_crit_;
126 std::map<uint32_t, VideoSendStream*> send_ssrcs_ GUARDED_BY(send_crit_);
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000127
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +0000128 scoped_ptr<CpuOveruseObserverProxy> overuse_observer_proxy_;
129
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000130 VideoSendStream::RtpStateMap suspended_send_ssrcs_;
131
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000132 VideoEngine* video_engine_;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000133 ViERTP_RTCP* rtp_rtcp_;
134 ViECodec* codec_;
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000135 ViEBase* base_;
136 int base_channel_id_;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000137
138 DISALLOW_COPY_AND_ASSIGN(Call);
139};
pbos@webrtc.orgc49d5b72013-12-05 12:11:47 +0000140} // namespace internal
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000141
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000142Call* Call::Create(const Call::Config& config) {
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000143 VideoEngine* video_engine = config.webrtc_config != NULL
144 ? VideoEngine::Create(*config.webrtc_config)
145 : VideoEngine::Create();
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000146 assert(video_engine != NULL);
147
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000148 return new internal::Call(video_engine, config);
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000149}
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000150
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000151namespace internal {
152
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000153const int kDefaultVideoStreamBitrateBps = 300000;
154
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000155Call::Call(webrtc::VideoEngine* video_engine, const Call::Config& config)
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000156 : config_(config),
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000157 network_enabled_crit_(CriticalSectionWrapper::CreateCriticalSection()),
158 network_enabled_(true),
159 receive_crit_(RWLockWrapper::CreateRWLock()),
160 send_crit_(RWLockWrapper::CreateRWLock()),
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000161 video_engine_(video_engine),
162 base_channel_id_(-1) {
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000163 assert(video_engine != NULL);
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000164 assert(config.send_transport != NULL);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000165
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +0000166 if (config.overuse_callback) {
167 overuse_observer_proxy_.reset(
168 new CpuOveruseObserverProxy(config.overuse_callback));
169 }
170
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000171 rtp_rtcp_ = ViERTP_RTCP::GetInterface(video_engine_);
172 assert(rtp_rtcp_ != NULL);
173
174 codec_ = ViECodec::GetInterface(video_engine_);
175 assert(codec_ != NULL);
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000176
177 // As a workaround for non-existing calls in the old API, create a base
178 // channel used as default channel when creating send and receive streams.
179 base_ = ViEBase::GetInterface(video_engine_);
180 assert(base_ != NULL);
181
182 base_->CreateChannel(base_channel_id_);
183 assert(base_channel_id_ != -1);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000184}
185
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000186Call::~Call() {
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000187 base_->DeleteChannel(base_channel_id_);
188 base_->Release();
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000189 codec_->Release();
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000190 rtp_rtcp_->Release();
191 webrtc::VideoEngine::Delete(video_engine_);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000192}
193
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000194PacketReceiver* Call::Receiver() { return this; }
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000195
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000196VideoSendStream* Call::CreateVideoSendStream(
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000197 const VideoSendStream::Config& config,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000198 const VideoEncoderConfig& encoder_config) {
pbos@webrtc.org1819fd72013-06-10 13:48:26 +0000199 assert(config.rtp.ssrcs.size() > 0);
pbos@webrtc.org1819fd72013-06-10 13:48:26 +0000200
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000201 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if
202 // the call has already started.
203 VideoSendStream* send_stream = new VideoSendStream(
204 config_.send_transport,
205 overuse_observer_proxy_.get(),
206 video_engine_,
207 config,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000208 encoder_config,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000209 suspended_send_ssrcs_,
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000210 base_channel_id_,
211 config_.start_bitrate_bps != -1 ? config_.start_bitrate_bps
212 : kDefaultVideoStreamBitrateBps);
pbos@webrtc.org1819fd72013-06-10 13:48:26 +0000213
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000214 // This needs to be taken before send_crit_ as both locks need to be held
215 // while changing network state.
216 CriticalSectionScoped lock(network_enabled_crit_.get());
217 WriteLockScoped write_lock(*send_crit_);
pbos@webrtc.org1819fd72013-06-10 13:48:26 +0000218 for (size_t i = 0; i < config.rtp.ssrcs.size(); ++i) {
219 assert(send_ssrcs_.find(config.rtp.ssrcs[i]) == send_ssrcs_.end());
220 send_ssrcs_[config.rtp.ssrcs[i]] = send_stream;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000221 }
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000222 if (!network_enabled_)
223 send_stream->SignalNetworkState(kNetworkDown);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000224 return send_stream;
225}
226
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000227void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) {
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000228 assert(send_stream != NULL);
229
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000230 send_stream->Stop();
231
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000232 VideoSendStream* send_stream_impl = NULL;
233 {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000234 WriteLockScoped write_lock(*send_crit_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000235 std::map<uint32_t, VideoSendStream*>::iterator it = send_ssrcs_.begin();
236 while (it != send_ssrcs_.end()) {
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000237 if (it->second == static_cast<VideoSendStream*>(send_stream)) {
238 send_stream_impl = it->second;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000239 send_ssrcs_.erase(it++);
240 } else {
241 ++it;
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000242 }
243 }
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000244 }
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000245
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000246 VideoSendStream::RtpStateMap rtp_state = send_stream_impl->GetRtpStates();
247
248 for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin();
249 it != rtp_state.end();
250 ++it) {
251 suspended_send_ssrcs_[it->first] = it->second;
252 }
253
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000254 assert(send_stream_impl != NULL);
255 delete send_stream_impl;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000256}
257
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000258VideoReceiveStream* Call::CreateVideoReceiveStream(
pbos@webrtc.org74fa4892013-08-23 09:19:30 +0000259 const VideoReceiveStream::Config& config) {
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000260 VideoReceiveStream* receive_stream =
261 new VideoReceiveStream(video_engine_,
262 config,
263 config_.send_transport,
264 config_.voice_engine,
265 base_channel_id_);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000266
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000267 // This needs to be taken before receive_crit_ as both locks need to be held
268 // while changing network state.
269 CriticalSectionScoped lock(network_enabled_crit_.get());
270 WriteLockScoped write_lock(*receive_crit_);
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000271 assert(receive_ssrcs_.find(config.rtp.remote_ssrc) == receive_ssrcs_.end());
272 receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000273 // TODO(pbos): Configure different RTX payloads per receive payload.
274 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it =
275 config.rtp.rtx.begin();
276 if (it != config.rtp.rtx.end())
277 receive_ssrcs_[it->second.ssrc] = receive_stream;
278
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000279 if (!network_enabled_)
280 receive_stream->SignalNetworkState(kNetworkDown);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000281 return receive_stream;
282}
283
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000284void Call::DestroyVideoReceiveStream(
285 webrtc::VideoReceiveStream* receive_stream) {
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000286 assert(receive_stream != NULL);
287
288 VideoReceiveStream* receive_stream_impl = NULL;
289 {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000290 WriteLockScoped write_lock(*receive_crit_);
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000291 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a
292 // separate SSRC there can be either one or two.
293 std::map<uint32_t, VideoReceiveStream*>::iterator it =
294 receive_ssrcs_.begin();
295 while (it != receive_ssrcs_.end()) {
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000296 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) {
solenberg@webrtc.org094ac392014-01-29 11:21:58 +0000297 assert(receive_stream_impl == NULL ||
298 receive_stream_impl == it->second);
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000299 receive_stream_impl = it->second;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000300 receive_ssrcs_.erase(it++);
301 } else {
302 ++it;
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000303 }
304 }
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000305 }
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000306
307 assert(receive_stream_impl != NULL);
308 delete receive_stream_impl;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000309}
310
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000311uint32_t Call::SendBitrateEstimate() {
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000312 // TODO(pbos): Return send-bitrate estimate
313 return 0;
314}
315
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000316uint32_t Call::ReceiveBitrateEstimate() {
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000317 // TODO(pbos): Return receive-bitrate estimate
318 return 0;
319}
320
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000321void Call::SignalNetworkState(NetworkState state) {
322 // Take crit for entire function, it needs to be held while updating streams
323 // to guarantee a consistent state across streams.
324 CriticalSectionScoped lock(network_enabled_crit_.get());
325 network_enabled_ = state == kNetworkUp;
326 {
327 ReadLockScoped write_lock(*send_crit_);
328 for (std::map<uint32_t, VideoSendStream*>::iterator it =
329 send_ssrcs_.begin();
330 it != send_ssrcs_.end();
331 ++it) {
332 it->second->SignalNetworkState(state);
333 }
334 }
335 {
336 ReadLockScoped write_lock(*receive_crit_);
337 for (std::map<uint32_t, VideoReceiveStream*>::iterator it =
338 receive_ssrcs_.begin();
339 it != receive_ssrcs_.end();
340 ++it) {
341 it->second->SignalNetworkState(state);
342 }
343 }
344}
345
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000346PacketReceiver::DeliveryStatus Call::DeliverRtcp(const uint8_t* packet,
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000347 size_t length) {
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000348 // TODO(pbos): Figure out what channel needs it actually.
349 // Do NOT broadcast! Also make sure it's a valid packet.
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000350 // Return DELIVERY_UNKNOWN_SSRC if it can be determined that
351 // there's no receiver of the packet.
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000352 bool rtcp_delivered = false;
pbos@webrtc.org40523702013-08-05 12:49:22 +0000353 {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000354 ReadLockScoped read_lock(*receive_crit_);
pbos@webrtc.org40523702013-08-05 12:49:22 +0000355 for (std::map<uint32_t, VideoReceiveStream*>::iterator it =
356 receive_ssrcs_.begin();
357 it != receive_ssrcs_.end();
358 ++it) {
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000359 if (it->second->DeliverRtcp(packet, length))
pbos@webrtc.org40523702013-08-05 12:49:22 +0000360 rtcp_delivered = true;
pbos@webrtc.orgbbb07e62013-08-05 12:01:36 +0000361 }
362 }
363
pbos@webrtc.org40523702013-08-05 12:49:22 +0000364 {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000365 ReadLockScoped read_lock(*send_crit_);
pbos@webrtc.org40523702013-08-05 12:49:22 +0000366 for (std::map<uint32_t, VideoSendStream*>::iterator it =
367 send_ssrcs_.begin();
368 it != send_ssrcs_.end();
369 ++it) {
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000370 if (it->second->DeliverRtcp(packet, length))
pbos@webrtc.org40523702013-08-05 12:49:22 +0000371 rtcp_delivered = true;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000372 }
373 }
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000374 return rtcp_delivered ? DELIVERY_OK : DELIVERY_PACKET_ERROR;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000375}
376
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000377PacketReceiver::DeliveryStatus Call::DeliverRtp(const uint8_t* packet,
378 size_t length) {
379 // Minimum RTP header size.
380 if (length < 12)
381 return DELIVERY_PACKET_ERROR;
382
383 const uint8_t* ptr = &packet[8];
pbos@webrtc.orgdde16f12014-08-05 23:35:43 +0000384 uint32_t ssrc = ptr[0] << 24 | ptr[1] << 16 | ptr[2] << 8 | ptr[3];
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000385
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000386 ReadLockScoped read_lock(*receive_crit_);
solenberg@webrtc.org094ac392014-01-29 11:21:58 +0000387 std::map<uint32_t, VideoReceiveStream*>::iterator it =
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000388 receive_ssrcs_.find(ssrc);
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000389
390 if (it == receive_ssrcs_.end())
391 return DELIVERY_UNKNOWN_SSRC;
392
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000393 return it->second->DeliverRtp(packet, length) ? DELIVERY_OK
394 : DELIVERY_PACKET_ERROR;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000395}
396
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000397PacketReceiver::DeliveryStatus Call::DeliverPacket(const uint8_t* packet,
398 size_t length) {
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000399 if (RtpHeaderParser::IsRtcp(packet, length))
pbos@webrtc.org40523702013-08-05 12:49:22 +0000400 return DeliverRtcp(packet, length);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000401
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000402 return DeliverRtp(packet, length);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000403}
404
405} // namespace internal
406} // namespace webrtc