blob: b4adafd75bad4a2684b09a8b496875e8d9d71125 [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,
90 const std::vector<VideoStream>& video_streams,
91 const void* encoder_settings) OVERRIDE;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000092
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +000093 virtual void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream)
94 OVERRIDE;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000095
pbos@webrtc.org5a636552013-11-20 10:40:25 +000096 virtual VideoReceiveStream* CreateVideoReceiveStream(
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000097 const VideoReceiveStream::Config& config) OVERRIDE;
98
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +000099 virtual void DestroyVideoReceiveStream(
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000100 webrtc::VideoReceiveStream* receive_stream) OVERRIDE;
101
102 virtual uint32_t SendBitrateEstimate() OVERRIDE;
103 virtual uint32_t ReceiveBitrateEstimate() OVERRIDE;
104
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000105 virtual DeliveryStatus DeliverPacket(const uint8_t* packet,
106 size_t length) OVERRIDE;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000107
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000108 virtual void SignalNetworkState(NetworkState state) OVERRIDE;
109
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000110 private:
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000111 DeliveryStatus DeliverRtcp(const uint8_t* packet, size_t length);
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000112 DeliveryStatus DeliverRtp(const uint8_t* packet, size_t length);
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000113
114 Call::Config config_;
115
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000116 // Needs to be held while write-locking |receive_crit_| or |send_crit_|. This
117 // ensures that we have a consistent network state signalled to all senders
118 // and receivers.
119 scoped_ptr<CriticalSectionWrapper> network_enabled_crit_;
120 bool network_enabled_ GUARDED_BY(network_enabled_crit_);
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000121
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000122 scoped_ptr<RWLockWrapper> receive_crit_;
123 std::map<uint32_t, VideoReceiveStream*> receive_ssrcs_
124 GUARDED_BY(receive_crit_);
125
126 scoped_ptr<RWLockWrapper> send_crit_;
127 std::map<uint32_t, VideoSendStream*> send_ssrcs_ GUARDED_BY(send_crit_);
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000128
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +0000129 scoped_ptr<CpuOveruseObserverProxy> overuse_observer_proxy_;
130
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000131 VideoSendStream::RtpStateMap suspended_send_ssrcs_;
132
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000133 VideoEngine* video_engine_;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000134 ViERTP_RTCP* rtp_rtcp_;
135 ViECodec* codec_;
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000136 ViEBase* base_;
137 int base_channel_id_;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000138
139 DISALLOW_COPY_AND_ASSIGN(Call);
140};
pbos@webrtc.orgc49d5b72013-12-05 12:11:47 +0000141} // namespace internal
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000142
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000143Call* Call::Create(const Call::Config& config) {
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000144 VideoEngine* video_engine = config.webrtc_config != NULL
145 ? VideoEngine::Create(*config.webrtc_config)
146 : VideoEngine::Create();
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000147 assert(video_engine != NULL);
148
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000149 return new internal::Call(video_engine, config);
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000150}
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000151
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000152namespace internal {
153
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000154const int kDefaultVideoStreamBitrateBps = 300000;
155
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000156Call::Call(webrtc::VideoEngine* video_engine, const Call::Config& config)
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000157 : config_(config),
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000158 network_enabled_crit_(CriticalSectionWrapper::CreateCriticalSection()),
159 network_enabled_(true),
160 receive_crit_(RWLockWrapper::CreateRWLock()),
161 send_crit_(RWLockWrapper::CreateRWLock()),
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000162 video_engine_(video_engine),
163 base_channel_id_(-1) {
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000164 assert(video_engine != NULL);
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000165 assert(config.send_transport != NULL);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000166
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +0000167 if (config.overuse_callback) {
168 overuse_observer_proxy_.reset(
169 new CpuOveruseObserverProxy(config.overuse_callback));
170 }
171
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000172 rtp_rtcp_ = ViERTP_RTCP::GetInterface(video_engine_);
173 assert(rtp_rtcp_ != NULL);
174
175 codec_ = ViECodec::GetInterface(video_engine_);
176 assert(codec_ != NULL);
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000177
178 // As a workaround for non-existing calls in the old API, create a base
179 // channel used as default channel when creating send and receive streams.
180 base_ = ViEBase::GetInterface(video_engine_);
181 assert(base_ != NULL);
182
183 base_->CreateChannel(base_channel_id_);
184 assert(base_channel_id_ != -1);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000185}
186
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000187Call::~Call() {
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000188 base_->DeleteChannel(base_channel_id_);
189 base_->Release();
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000190 codec_->Release();
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000191 rtp_rtcp_->Release();
192 webrtc::VideoEngine::Delete(video_engine_);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000193}
194
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000195PacketReceiver* Call::Receiver() { return this; }
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000196
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000197VideoSendStream* Call::CreateVideoSendStream(
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000198 const VideoSendStream::Config& config,
199 const std::vector<VideoStream>& video_streams,
200 const void* encoder_settings) {
pbos@webrtc.org1819fd72013-06-10 13:48:26 +0000201 assert(config.rtp.ssrcs.size() > 0);
pbos@webrtc.org1819fd72013-06-10 13:48:26 +0000202
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000203 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if
204 // the call has already started.
205 VideoSendStream* send_stream = new VideoSendStream(
206 config_.send_transport,
207 overuse_observer_proxy_.get(),
208 video_engine_,
209 config,
210 video_streams,
211 encoder_settings,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000212 suspended_send_ssrcs_,
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000213 base_channel_id_,
214 config_.start_bitrate_bps != -1 ? config_.start_bitrate_bps
215 : kDefaultVideoStreamBitrateBps);
pbos@webrtc.org1819fd72013-06-10 13:48:26 +0000216
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000217 // This needs to be taken before send_crit_ as both locks need to be held
218 // while changing network state.
219 CriticalSectionScoped lock(network_enabled_crit_.get());
220 WriteLockScoped write_lock(*send_crit_);
pbos@webrtc.org1819fd72013-06-10 13:48:26 +0000221 for (size_t i = 0; i < config.rtp.ssrcs.size(); ++i) {
222 assert(send_ssrcs_.find(config.rtp.ssrcs[i]) == send_ssrcs_.end());
223 send_ssrcs_[config.rtp.ssrcs[i]] = send_stream;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000224 }
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000225 if (!network_enabled_)
226 send_stream->SignalNetworkState(kNetworkDown);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000227 return send_stream;
228}
229
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000230void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) {
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000231 assert(send_stream != NULL);
232
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000233 send_stream->Stop();
234
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000235 VideoSendStream* send_stream_impl = NULL;
236 {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000237 WriteLockScoped write_lock(*send_crit_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000238 std::map<uint32_t, VideoSendStream*>::iterator it = send_ssrcs_.begin();
239 while (it != send_ssrcs_.end()) {
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000240 if (it->second == static_cast<VideoSendStream*>(send_stream)) {
241 send_stream_impl = it->second;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000242 send_ssrcs_.erase(it++);
243 } else {
244 ++it;
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000245 }
246 }
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000247 }
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000248
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000249 VideoSendStream::RtpStateMap rtp_state = send_stream_impl->GetRtpStates();
250
251 for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin();
252 it != rtp_state.end();
253 ++it) {
254 suspended_send_ssrcs_[it->first] = it->second;
255 }
256
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000257 assert(send_stream_impl != NULL);
258 delete send_stream_impl;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000259}
260
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000261VideoReceiveStream* Call::CreateVideoReceiveStream(
pbos@webrtc.org74fa4892013-08-23 09:19:30 +0000262 const VideoReceiveStream::Config& config) {
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000263 VideoReceiveStream* receive_stream =
264 new VideoReceiveStream(video_engine_,
265 config,
266 config_.send_transport,
267 config_.voice_engine,
268 base_channel_id_);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000269
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000270 // This needs to be taken before receive_crit_ as both locks need to be held
271 // while changing network state.
272 CriticalSectionScoped lock(network_enabled_crit_.get());
273 WriteLockScoped write_lock(*receive_crit_);
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000274 assert(receive_ssrcs_.find(config.rtp.remote_ssrc) == receive_ssrcs_.end());
275 receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000276 // TODO(pbos): Configure different RTX payloads per receive payload.
277 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it =
278 config.rtp.rtx.begin();
279 if (it != config.rtp.rtx.end())
280 receive_ssrcs_[it->second.ssrc] = receive_stream;
281
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000282 if (!network_enabled_)
283 receive_stream->SignalNetworkState(kNetworkDown);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000284 return receive_stream;
285}
286
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000287void Call::DestroyVideoReceiveStream(
288 webrtc::VideoReceiveStream* receive_stream) {
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000289 assert(receive_stream != NULL);
290
291 VideoReceiveStream* receive_stream_impl = NULL;
292 {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000293 WriteLockScoped write_lock(*receive_crit_);
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000294 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a
295 // separate SSRC there can be either one or two.
296 std::map<uint32_t, VideoReceiveStream*>::iterator it =
297 receive_ssrcs_.begin();
298 while (it != receive_ssrcs_.end()) {
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000299 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) {
solenberg@webrtc.org094ac392014-01-29 11:21:58 +0000300 assert(receive_stream_impl == NULL ||
301 receive_stream_impl == it->second);
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000302 receive_stream_impl = it->second;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000303 receive_ssrcs_.erase(it++);
304 } else {
305 ++it;
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000306 }
307 }
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000308 }
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000309
310 assert(receive_stream_impl != NULL);
311 delete receive_stream_impl;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000312}
313
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000314uint32_t Call::SendBitrateEstimate() {
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000315 // TODO(pbos): Return send-bitrate estimate
316 return 0;
317}
318
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000319uint32_t Call::ReceiveBitrateEstimate() {
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000320 // TODO(pbos): Return receive-bitrate estimate
321 return 0;
322}
323
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000324void Call::SignalNetworkState(NetworkState state) {
325 // Take crit for entire function, it needs to be held while updating streams
326 // to guarantee a consistent state across streams.
327 CriticalSectionScoped lock(network_enabled_crit_.get());
328 network_enabled_ = state == kNetworkUp;
329 {
330 ReadLockScoped write_lock(*send_crit_);
331 for (std::map<uint32_t, VideoSendStream*>::iterator it =
332 send_ssrcs_.begin();
333 it != send_ssrcs_.end();
334 ++it) {
335 it->second->SignalNetworkState(state);
336 }
337 }
338 {
339 ReadLockScoped write_lock(*receive_crit_);
340 for (std::map<uint32_t, VideoReceiveStream*>::iterator it =
341 receive_ssrcs_.begin();
342 it != receive_ssrcs_.end();
343 ++it) {
344 it->second->SignalNetworkState(state);
345 }
346 }
347}
348
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000349PacketReceiver::DeliveryStatus Call::DeliverRtcp(const uint8_t* packet,
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000350 size_t length) {
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000351 // TODO(pbos): Figure out what channel needs it actually.
352 // Do NOT broadcast! Also make sure it's a valid packet.
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000353 // Return DELIVERY_UNKNOWN_SSRC if it can be determined that
354 // there's no receiver of the packet.
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000355 bool rtcp_delivered = false;
pbos@webrtc.org40523702013-08-05 12:49:22 +0000356 {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000357 ReadLockScoped read_lock(*receive_crit_);
pbos@webrtc.org40523702013-08-05 12:49:22 +0000358 for (std::map<uint32_t, VideoReceiveStream*>::iterator it =
359 receive_ssrcs_.begin();
360 it != receive_ssrcs_.end();
361 ++it) {
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000362 if (it->second->DeliverRtcp(packet, length))
pbos@webrtc.org40523702013-08-05 12:49:22 +0000363 rtcp_delivered = true;
pbos@webrtc.orgbbb07e62013-08-05 12:01:36 +0000364 }
365 }
366
pbos@webrtc.org40523702013-08-05 12:49:22 +0000367 {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000368 ReadLockScoped read_lock(*send_crit_);
pbos@webrtc.org40523702013-08-05 12:49:22 +0000369 for (std::map<uint32_t, VideoSendStream*>::iterator it =
370 send_ssrcs_.begin();
371 it != send_ssrcs_.end();
372 ++it) {
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000373 if (it->second->DeliverRtcp(packet, length))
pbos@webrtc.org40523702013-08-05 12:49:22 +0000374 rtcp_delivered = true;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000375 }
376 }
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000377 return rtcp_delivered ? DELIVERY_OK : DELIVERY_PACKET_ERROR;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000378}
379
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000380PacketReceiver::DeliveryStatus Call::DeliverRtp(const uint8_t* packet,
381 size_t length) {
382 // Minimum RTP header size.
383 if (length < 12)
384 return DELIVERY_PACKET_ERROR;
385
386 const uint8_t* ptr = &packet[8];
pbos@webrtc.orgdde16f12014-08-05 23:35:43 +0000387 uint32_t ssrc = ptr[0] << 24 | ptr[1] << 16 | ptr[2] << 8 | ptr[3];
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000388
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000389 ReadLockScoped read_lock(*receive_crit_);
solenberg@webrtc.org094ac392014-01-29 11:21:58 +0000390 std::map<uint32_t, VideoReceiveStream*>::iterator it =
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000391 receive_ssrcs_.find(ssrc);
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000392
393 if (it == receive_ssrcs_.end())
394 return DELIVERY_UNKNOWN_SSRC;
395
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000396 return it->second->DeliverRtp(packet, length) ? DELIVERY_OK
397 : DELIVERY_PACKET_ERROR;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000398}
399
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000400PacketReceiver::DeliveryStatus Call::DeliverPacket(const uint8_t* packet,
401 size_t length) {
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000402 if (RtpHeaderParser::IsRtcp(packet, length))
pbos@webrtc.org40523702013-08-05 12:49:22 +0000403 return DeliverRtcp(packet, length);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000404
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000405 return DeliverRtp(packet, length);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000406}
407
408} // namespace internal
409} // namespace webrtc