blob: 8b71acfddfaf4eefb81217df2cc20d26b56e424c [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.orgde74b642013-10-02 13:36:09 +000021#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000022#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h"
pbos@webrtc.orgde74b642013-10-02 13:36:09 +000023#include "webrtc/system_wrappers/interface/scoped_ptr.h"
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000024#include "webrtc/system_wrappers/interface/thread_annotations.h"
pbos@webrtc.orgde74b642013-10-02 13:36:09 +000025#include "webrtc/system_wrappers/interface/trace.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000026#include "webrtc/video/video_receive_stream.h"
27#include "webrtc/video/video_send_stream.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000028#include "webrtc/video_engine/include/vie_base.h"
29#include "webrtc/video_engine/include/vie_codec.h"
30#include "webrtc/video_engine/include/vie_rtp_rtcp.h"
pbos@webrtc.org26c0c412014-09-03 16:17:12 +000031#include "webrtc/video_engine/include/vie_network.h"
32#include "webrtc/video_engine/include/vie_rtp_rtcp.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000033
34namespace webrtc {
pbos@webrtc.orgc49d5b72013-12-05 12:11:47 +000035const char* RtpExtension::kTOffset = "urn:ietf:params:rtp-hdrext:toffset";
36const char* RtpExtension::kAbsSendTime =
37 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
pbos@webrtc.org3c107582014-07-20 15:27:35 +000038
39bool RtpExtension::IsSupported(const std::string& name) {
40 return name == webrtc::RtpExtension::kTOffset ||
41 name == webrtc::RtpExtension::kAbsSendTime;
42}
43
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000044namespace internal {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000045
46class CpuOveruseObserverProxy : public webrtc::CpuOveruseObserver {
47 public:
pbos@webrtc.orgdde16f12014-08-05 23:35:43 +000048 explicit CpuOveruseObserverProxy(OveruseCallback* overuse_callback)
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000049 : crit_(CriticalSectionWrapper::CreateCriticalSection()),
50 overuse_callback_(overuse_callback) {
51 assert(overuse_callback != NULL);
52 }
53
54 virtual ~CpuOveruseObserverProxy() {}
55
56 virtual void OveruseDetected() OVERRIDE {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000057 CriticalSectionScoped lock(crit_.get());
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000058 overuse_callback_->OnOveruse();
59 }
60
61 virtual void NormalUsage() OVERRIDE {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000062 CriticalSectionScoped lock(crit_.get());
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000063 overuse_callback_->OnNormalUse();
64 }
65
66 private:
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000067 const scoped_ptr<CriticalSectionWrapper> crit_;
68 OveruseCallback* overuse_callback_ GUARDED_BY(crit_);
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000069};
70
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000071class Call : public webrtc::Call, public PacketReceiver {
72 public:
73 Call(webrtc::VideoEngine* video_engine, const Call::Config& config);
74 virtual ~Call();
75
76 virtual PacketReceiver* Receiver() OVERRIDE;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000077
pbos@webrtc.org5a636552013-11-20 10:40:25 +000078 virtual VideoSendStream* CreateVideoSendStream(
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +000079 const VideoSendStream::Config& config,
80 const std::vector<VideoStream>& video_streams,
81 const void* encoder_settings) OVERRIDE;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000082
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +000083 virtual void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream)
84 OVERRIDE;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000085
pbos@webrtc.org5a636552013-11-20 10:40:25 +000086 virtual VideoReceiveStream* CreateVideoReceiveStream(
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000087 const VideoReceiveStream::Config& config) OVERRIDE;
88
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +000089 virtual void DestroyVideoReceiveStream(
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000090 webrtc::VideoReceiveStream* receive_stream) OVERRIDE;
91
92 virtual uint32_t SendBitrateEstimate() OVERRIDE;
93 virtual uint32_t ReceiveBitrateEstimate() OVERRIDE;
94
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +000095 virtual DeliveryStatus DeliverPacket(const uint8_t* packet,
96 size_t length) OVERRIDE;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000097
pbos@webrtc.org26c0c412014-09-03 16:17:12 +000098 virtual void SignalNetworkState(NetworkState state) OVERRIDE;
99
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000100 private:
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000101 DeliveryStatus DeliverRtcp(const uint8_t* packet, size_t length);
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000102 DeliveryStatus DeliverRtp(const uint8_t* packet, size_t length);
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000103
104 Call::Config config_;
105
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000106 // Needs to be held while write-locking |receive_crit_| or |send_crit_|. This
107 // ensures that we have a consistent network state signalled to all senders
108 // and receivers.
109 scoped_ptr<CriticalSectionWrapper> network_enabled_crit_;
110 bool network_enabled_ GUARDED_BY(network_enabled_crit_);
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000111
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000112 scoped_ptr<RWLockWrapper> receive_crit_;
113 std::map<uint32_t, VideoReceiveStream*> receive_ssrcs_
114 GUARDED_BY(receive_crit_);
115
116 scoped_ptr<RWLockWrapper> send_crit_;
117 std::map<uint32_t, VideoSendStream*> send_ssrcs_ GUARDED_BY(send_crit_);
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000118
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +0000119 scoped_ptr<CpuOveruseObserverProxy> overuse_observer_proxy_;
120
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000121 VideoSendStream::RtpStateMap suspended_send_ssrcs_;
122
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000123 VideoEngine* video_engine_;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000124 ViERTP_RTCP* rtp_rtcp_;
125 ViECodec* codec_;
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000126 ViEBase* base_;
127 int base_channel_id_;
pbos@webrtc.org16e03b72013-10-28 16:32:01 +0000128
129 DISALLOW_COPY_AND_ASSIGN(Call);
130};
pbos@webrtc.orgc49d5b72013-12-05 12:11:47 +0000131} // namespace internal
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000132
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000133Call* Call::Create(const Call::Config& config) {
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000134 VideoEngine* video_engine = config.webrtc_config != NULL
135 ? VideoEngine::Create(*config.webrtc_config)
136 : VideoEngine::Create();
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000137 assert(video_engine != NULL);
138
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000139 return new internal::Call(video_engine, config);
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000140}
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000141
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000142namespace internal {
143
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000144const int kDefaultVideoStreamBitrateBps = 300000;
145
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000146Call::Call(webrtc::VideoEngine* video_engine, const Call::Config& config)
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000147 : config_(config),
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000148 network_enabled_crit_(CriticalSectionWrapper::CreateCriticalSection()),
149 network_enabled_(true),
150 receive_crit_(RWLockWrapper::CreateRWLock()),
151 send_crit_(RWLockWrapper::CreateRWLock()),
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000152 video_engine_(video_engine),
153 base_channel_id_(-1) {
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000154 assert(video_engine != NULL);
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000155 assert(config.send_transport != NULL);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000156
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +0000157 if (config.overuse_callback) {
158 overuse_observer_proxy_.reset(
159 new CpuOveruseObserverProxy(config.overuse_callback));
160 }
161
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000162 rtp_rtcp_ = ViERTP_RTCP::GetInterface(video_engine_);
163 assert(rtp_rtcp_ != NULL);
164
165 codec_ = ViECodec::GetInterface(video_engine_);
166 assert(codec_ != NULL);
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000167
168 // As a workaround for non-existing calls in the old API, create a base
169 // channel used as default channel when creating send and receive streams.
170 base_ = ViEBase::GetInterface(video_engine_);
171 assert(base_ != NULL);
172
173 base_->CreateChannel(base_channel_id_);
174 assert(base_channel_id_ != -1);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000175}
176
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000177Call::~Call() {
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000178 base_->DeleteChannel(base_channel_id_);
179 base_->Release();
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000180 codec_->Release();
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000181 rtp_rtcp_->Release();
182 webrtc::VideoEngine::Delete(video_engine_);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000183}
184
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000185PacketReceiver* Call::Receiver() { return this; }
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000186
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000187VideoSendStream* Call::CreateVideoSendStream(
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000188 const VideoSendStream::Config& config,
189 const std::vector<VideoStream>& video_streams,
190 const void* encoder_settings) {
pbos@webrtc.org1819fd72013-06-10 13:48:26 +0000191 assert(config.rtp.ssrcs.size() > 0);
pbos@webrtc.org1819fd72013-06-10 13:48:26 +0000192
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000193 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if
194 // the call has already started.
195 VideoSendStream* send_stream = new VideoSendStream(
196 config_.send_transport,
197 overuse_observer_proxy_.get(),
198 video_engine_,
199 config,
200 video_streams,
201 encoder_settings,
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000202 suspended_send_ssrcs_,
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +0000203 base_channel_id_,
204 config_.start_bitrate_bps != -1 ? config_.start_bitrate_bps
205 : kDefaultVideoStreamBitrateBps);
pbos@webrtc.org1819fd72013-06-10 13:48:26 +0000206
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000207 // This needs to be taken before send_crit_ as both locks need to be held
208 // while changing network state.
209 CriticalSectionScoped lock(network_enabled_crit_.get());
210 WriteLockScoped write_lock(*send_crit_);
pbos@webrtc.org1819fd72013-06-10 13:48:26 +0000211 for (size_t i = 0; i < config.rtp.ssrcs.size(); ++i) {
212 assert(send_ssrcs_.find(config.rtp.ssrcs[i]) == send_ssrcs_.end());
213 send_ssrcs_[config.rtp.ssrcs[i]] = send_stream;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000214 }
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000215 if (!network_enabled_)
216 send_stream->SignalNetworkState(kNetworkDown);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000217 return send_stream;
218}
219
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000220void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) {
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000221 assert(send_stream != NULL);
222
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000223 send_stream->Stop();
224
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000225 VideoSendStream* send_stream_impl = NULL;
226 {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000227 WriteLockScoped write_lock(*send_crit_);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000228 std::map<uint32_t, VideoSendStream*>::iterator it = send_ssrcs_.begin();
229 while (it != send_ssrcs_.end()) {
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000230 if (it->second == static_cast<VideoSendStream*>(send_stream)) {
231 send_stream_impl = it->second;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000232 send_ssrcs_.erase(it++);
233 } else {
234 ++it;
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000235 }
236 }
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000237 }
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000238
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000239 VideoSendStream::RtpStateMap rtp_state = send_stream_impl->GetRtpStates();
240
241 for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin();
242 it != rtp_state.end();
243 ++it) {
244 suspended_send_ssrcs_[it->first] = it->second;
245 }
246
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000247 assert(send_stream_impl != NULL);
248 delete send_stream_impl;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000249}
250
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000251VideoReceiveStream* Call::CreateVideoReceiveStream(
pbos@webrtc.org74fa4892013-08-23 09:19:30 +0000252 const VideoReceiveStream::Config& config) {
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000253 VideoReceiveStream* receive_stream =
254 new VideoReceiveStream(video_engine_,
255 config,
256 config_.send_transport,
257 config_.voice_engine,
258 base_channel_id_);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000259
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000260 // This needs to be taken before receive_crit_ as both locks need to be held
261 // while changing network state.
262 CriticalSectionScoped lock(network_enabled_crit_.get());
263 WriteLockScoped write_lock(*receive_crit_);
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +0000264 assert(receive_ssrcs_.find(config.rtp.remote_ssrc) == receive_ssrcs_.end());
265 receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000266 // TODO(pbos): Configure different RTX payloads per receive payload.
267 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it =
268 config.rtp.rtx.begin();
269 if (it != config.rtp.rtx.end())
270 receive_ssrcs_[it->second.ssrc] = receive_stream;
271
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000272 if (!network_enabled_)
273 receive_stream->SignalNetworkState(kNetworkDown);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000274 return receive_stream;
275}
276
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000277void Call::DestroyVideoReceiveStream(
278 webrtc::VideoReceiveStream* receive_stream) {
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000279 assert(receive_stream != NULL);
280
281 VideoReceiveStream* receive_stream_impl = NULL;
282 {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000283 WriteLockScoped write_lock(*receive_crit_);
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000284 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a
285 // separate SSRC there can be either one or two.
286 std::map<uint32_t, VideoReceiveStream*>::iterator it =
287 receive_ssrcs_.begin();
288 while (it != receive_ssrcs_.end()) {
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000289 if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) {
solenberg@webrtc.org094ac392014-01-29 11:21:58 +0000290 assert(receive_stream_impl == NULL ||
291 receive_stream_impl == it->second);
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000292 receive_stream_impl = it->second;
pbos@webrtc.orgc279a5d2014-01-24 09:30:53 +0000293 receive_ssrcs_.erase(it++);
294 } else {
295 ++it;
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000296 }
297 }
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000298 }
pbos@webrtc.org95e51f52013-09-05 12:38:54 +0000299
300 assert(receive_stream_impl != NULL);
301 delete receive_stream_impl;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000302}
303
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000304uint32_t Call::SendBitrateEstimate() {
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000305 // TODO(pbos): Return send-bitrate estimate
306 return 0;
307}
308
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000309uint32_t Call::ReceiveBitrateEstimate() {
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000310 // TODO(pbos): Return receive-bitrate estimate
311 return 0;
312}
313
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000314void Call::SignalNetworkState(NetworkState state) {
315 // Take crit for entire function, it needs to be held while updating streams
316 // to guarantee a consistent state across streams.
317 CriticalSectionScoped lock(network_enabled_crit_.get());
318 network_enabled_ = state == kNetworkUp;
319 {
320 ReadLockScoped write_lock(*send_crit_);
321 for (std::map<uint32_t, VideoSendStream*>::iterator it =
322 send_ssrcs_.begin();
323 it != send_ssrcs_.end();
324 ++it) {
325 it->second->SignalNetworkState(state);
326 }
327 }
328 {
329 ReadLockScoped write_lock(*receive_crit_);
330 for (std::map<uint32_t, VideoReceiveStream*>::iterator it =
331 receive_ssrcs_.begin();
332 it != receive_ssrcs_.end();
333 ++it) {
334 it->second->SignalNetworkState(state);
335 }
336 }
337}
338
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000339PacketReceiver::DeliveryStatus Call::DeliverRtcp(const uint8_t* packet,
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000340 size_t length) {
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000341 // TODO(pbos): Figure out what channel needs it actually.
342 // Do NOT broadcast! Also make sure it's a valid packet.
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000343 // Return DELIVERY_UNKNOWN_SSRC if it can be determined that
344 // there's no receiver of the packet.
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000345 bool rtcp_delivered = false;
pbos@webrtc.org40523702013-08-05 12:49:22 +0000346 {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000347 ReadLockScoped read_lock(*receive_crit_);
pbos@webrtc.org40523702013-08-05 12:49:22 +0000348 for (std::map<uint32_t, VideoReceiveStream*>::iterator it =
349 receive_ssrcs_.begin();
350 it != receive_ssrcs_.end();
351 ++it) {
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000352 if (it->second->DeliverRtcp(packet, length))
pbos@webrtc.org40523702013-08-05 12:49:22 +0000353 rtcp_delivered = true;
pbos@webrtc.orgbbb07e62013-08-05 12:01:36 +0000354 }
355 }
356
pbos@webrtc.org40523702013-08-05 12:49:22 +0000357 {
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000358 ReadLockScoped read_lock(*send_crit_);
pbos@webrtc.org40523702013-08-05 12:49:22 +0000359 for (std::map<uint32_t, VideoSendStream*>::iterator it =
360 send_ssrcs_.begin();
361 it != send_ssrcs_.end();
362 ++it) {
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000363 if (it->second->DeliverRtcp(packet, length))
pbos@webrtc.org40523702013-08-05 12:49:22 +0000364 rtcp_delivered = true;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000365 }
366 }
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000367 return rtcp_delivered ? DELIVERY_OK : DELIVERY_PACKET_ERROR;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000368}
369
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000370PacketReceiver::DeliveryStatus Call::DeliverRtp(const uint8_t* packet,
371 size_t length) {
372 // Minimum RTP header size.
373 if (length < 12)
374 return DELIVERY_PACKET_ERROR;
375
376 const uint8_t* ptr = &packet[8];
pbos@webrtc.orgdde16f12014-08-05 23:35:43 +0000377 uint32_t ssrc = ptr[0] << 24 | ptr[1] << 16 | ptr[2] << 8 | ptr[3];
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000378
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000379 ReadLockScoped read_lock(*receive_crit_);
solenberg@webrtc.org094ac392014-01-29 11:21:58 +0000380 std::map<uint32_t, VideoReceiveStream*>::iterator it =
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000381 receive_ssrcs_.find(ssrc);
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000382
383 if (it == receive_ssrcs_.end())
384 return DELIVERY_UNKNOWN_SSRC;
385
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000386 return it->second->DeliverRtp(packet, length) ? DELIVERY_OK
387 : DELIVERY_PACKET_ERROR;
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000388}
389
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000390PacketReceiver::DeliveryStatus Call::DeliverPacket(const uint8_t* packet,
391 size_t length) {
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000392 if (RtpHeaderParser::IsRtcp(packet, length))
pbos@webrtc.org40523702013-08-05 12:49:22 +0000393 return DeliverRtcp(packet, length);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000394
pbos@webrtc.orgaf38f4e2014-07-08 07:38:12 +0000395 return DeliverRtp(packet, length);
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000396}
397
398} // namespace internal
399} // namespace webrtc