pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 1 | /* |
| 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.org | 12dc1a3 | 2013-08-05 16:22:53 | [diff] [blame] | 11 | #include <string.h> |
| 12 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 13 | #include <map> |
| 14 | #include <vector> |
| 15 | |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 | [diff] [blame] | 16 | #include "webrtc/base/checks.h" |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 | [diff] [blame] | 17 | #include "webrtc/base/scoped_ptr.h" |
pbos@webrtc.org | 38344ed | 2014-09-24 06:05:00 | [diff] [blame] | 18 | #include "webrtc/base/thread_annotations.h" |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 19 | #include "webrtc/call.h" |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 | [diff] [blame] | 20 | #include "webrtc/common.h" |
pbos@webrtc.org | c49d5b7 | 2013-12-05 12:11:47 | [diff] [blame] | 21 | #include "webrtc/config.h" |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 22 | #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" |
sprang@webrtc.org | 2a6558c | 2015-01-28 12:37:36 | [diff] [blame] | 23 | #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 24 | #include "webrtc/modules/utility/interface/process_thread.h" |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 | [diff] [blame] | 25 | #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" |
marpan@webrtc.org | 5b88317 | 2014-11-01 06:10:48 | [diff] [blame] | 26 | #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" |
pbos@webrtc.org | 9e4e524 | 2015-02-12 10:48:23 | [diff] [blame] | 27 | #include "webrtc/modules/video_render/include/video_render.h" |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 28 | #include "webrtc/system_wrappers/interface/cpu_info.h" |
pbos@webrtc.org | de74b64 | 2013-10-02 13:36:09 | [diff] [blame] | 29 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
pbos@webrtc.org | 32e8528 | 2015-01-15 10:09:39 | [diff] [blame] | 30 | #include "webrtc/system_wrappers/interface/logging.h" |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 31 | #include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" |
pbos@webrtc.org | de74b64 | 2013-10-02 13:36:09 | [diff] [blame] | 32 | #include "webrtc/system_wrappers/interface/trace.h" |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 | [diff] [blame] | 33 | #include "webrtc/system_wrappers/interface/trace_event.h" |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 34 | #include "webrtc/video/audio_receive_stream.h" |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 35 | #include "webrtc/video/video_receive_stream.h" |
| 36 | #include "webrtc/video/video_send_stream.h" |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 37 | |
| 38 | namespace webrtc { |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 | [diff] [blame] | 39 | VideoEncoder* VideoEncoder::Create(VideoEncoder::EncoderType codec_type) { |
| 40 | switch (codec_type) { |
| 41 | case kVp8: |
| 42 | return VP8Encoder::Create(); |
marpan@webrtc.org | 5b88317 | 2014-11-01 06:10:48 | [diff] [blame] | 43 | case kVp9: |
| 44 | return VP9Encoder::Create(); |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 | [diff] [blame] | 45 | } |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 | [diff] [blame] | 46 | RTC_NOTREACHED(); |
| 47 | return nullptr; |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 | [diff] [blame] | 48 | } |
| 49 | |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 | [diff] [blame] | 50 | VideoDecoder* VideoDecoder::Create(VideoDecoder::DecoderType codec_type) { |
| 51 | switch (codec_type) { |
| 52 | case kVp8: |
| 53 | return VP8Decoder::Create(); |
stefan@webrtc.org | 7c29e8c | 2014-11-04 19:41:15 | [diff] [blame] | 54 | case kVp9: |
| 55 | return VP9Decoder::Create(); |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 | [diff] [blame] | 56 | } |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 | [diff] [blame] | 57 | RTC_NOTREACHED(); |
| 58 | return nullptr; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 | [diff] [blame] | 59 | } |
| 60 | |
pbos@webrtc.org | a73a678 | 2014-10-14 11:52:10 | [diff] [blame] | 61 | const int Call::Config::kDefaultStartBitrateBps = 300000; |
| 62 | |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 63 | namespace internal { |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 | [diff] [blame] | 64 | |
| 65 | class CpuOveruseObserverProxy : public webrtc::CpuOveruseObserver { |
| 66 | public: |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 | [diff] [blame] | 67 | explicit CpuOveruseObserverProxy(LoadObserver* overuse_callback) |
Peter Boström | f2f8283 | 2015-05-01 11:00:41 | [diff] [blame] | 68 | : overuse_callback_(overuse_callback) { |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 | [diff] [blame] | 69 | DCHECK(overuse_callback != nullptr); |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | virtual ~CpuOveruseObserverProxy() {} |
| 73 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 74 | void OveruseDetected() override { |
Peter Boström | f2f8283 | 2015-05-01 11:00:41 | [diff] [blame] | 75 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 | [diff] [blame] | 76 | overuse_callback_->OnLoadUpdate(LoadObserver::kOveruse); |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 | [diff] [blame] | 77 | } |
| 78 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 79 | void NormalUsage() override { |
Peter Boström | f2f8283 | 2015-05-01 11:00:41 | [diff] [blame] | 80 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 | [diff] [blame] | 81 | overuse_callback_->OnLoadUpdate(LoadObserver::kUnderuse); |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | private: |
Peter Boström | f2f8283 | 2015-05-01 11:00:41 | [diff] [blame] | 85 | rtc::CriticalSection crit_; |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 | [diff] [blame] | 86 | LoadObserver* overuse_callback_ GUARDED_BY(crit_); |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 | [diff] [blame] | 87 | }; |
| 88 | |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 89 | class Call : public webrtc::Call, public PacketReceiver { |
| 90 | public: |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 91 | explicit Call(const Call::Config& config); |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 92 | virtual ~Call(); |
| 93 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 94 | PacketReceiver* Receiver() override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 95 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 96 | webrtc::AudioReceiveStream* CreateAudioReceiveStream( |
| 97 | const webrtc::AudioReceiveStream::Config& config) override; |
| 98 | void DestroyAudioReceiveStream( |
| 99 | webrtc::AudioReceiveStream* receive_stream) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 100 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 101 | webrtc::VideoSendStream* CreateVideoSendStream( |
| 102 | const webrtc::VideoSendStream::Config& config, |
| 103 | const VideoEncoderConfig& encoder_config) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 104 | void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 105 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 106 | webrtc::VideoReceiveStream* CreateVideoReceiveStream( |
| 107 | const webrtc::VideoReceiveStream::Config& config) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 108 | void DestroyVideoReceiveStream( |
| 109 | webrtc::VideoReceiveStream* receive_stream) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 110 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 111 | Stats GetStats() const override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 112 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 113 | DeliveryStatus DeliverPacket(MediaType media_type, const uint8_t* packet, |
| 114 | size_t length) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 115 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 116 | void SetBitrateConfig( |
| 117 | const webrtc::Call::Config::BitrateConfig& bitrate_config) override; |
| 118 | void SignalNetworkState(NetworkState state) override; |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 119 | |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 120 | private: |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 121 | DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet, |
| 122 | size_t length); |
| 123 | DeliveryStatus DeliverRtp(MediaType media_type, const uint8_t* packet, |
| 124 | size_t length); |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 125 | |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 126 | void SetBitrateControllerConfig( |
| 127 | const webrtc::Call::Config::BitrateConfig& bitrate_config); |
| 128 | |
| 129 | const int num_cpu_cores_; |
| 130 | const rtc::scoped_ptr<ProcessThread> module_process_thread_; |
| 131 | const rtc::scoped_ptr<ChannelGroup> channel_group_; |
| 132 | const int base_channel_id_; |
| 133 | volatile int next_channel_id_; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 134 | Call::Config config_; |
| 135 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 136 | // Needs to be held while write-locking |receive_crit_| or |send_crit_|. This |
| 137 | // ensures that we have a consistent network state signalled to all senders |
| 138 | // and receivers. |
Peter Boström | f2f8283 | 2015-05-01 11:00:41 | [diff] [blame] | 139 | rtc::CriticalSection network_enabled_crit_; |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 140 | bool network_enabled_ GUARDED_BY(network_enabled_crit_); |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 141 | |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 | [diff] [blame] | 142 | rtc::scoped_ptr<RWLockWrapper> receive_crit_; |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 143 | std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 144 | GUARDED_BY(receive_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 145 | std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ |
| 146 | GUARDED_BY(receive_crit_); |
| 147 | std::set<VideoReceiveStream*> video_receive_streams_ |
| 148 | GUARDED_BY(receive_crit_); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 149 | |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 | [diff] [blame] | 150 | rtc::scoped_ptr<RWLockWrapper> send_crit_; |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 151 | std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); |
| 152 | std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 153 | |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 | [diff] [blame] | 154 | rtc::scoped_ptr<CpuOveruseObserverProxy> overuse_observer_proxy_; |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 | [diff] [blame] | 155 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 156 | VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 | [diff] [blame] | 157 | |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 158 | DISALLOW_COPY_AND_ASSIGN(Call); |
| 159 | }; |
pbos@webrtc.org | c49d5b7 | 2013-12-05 12:11:47 | [diff] [blame] | 160 | } // namespace internal |
pbos@webrtc.org | fd39e13 | 2013-08-14 13:52:52 | [diff] [blame] | 161 | |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 | [diff] [blame] | 162 | Call* Call::Create(const Call::Config& config) { |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 163 | return new internal::Call(config); |
pbos@webrtc.org | fd39e13 | 2013-08-14 13:52:52 | [diff] [blame] | 164 | } |
pbos@webrtc.org | fd39e13 | 2013-08-14 13:52:52 | [diff] [blame] | 165 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 166 | namespace internal { |
| 167 | |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 168 | Call::Call(const Call::Config& config) |
| 169 | : num_cpu_cores_(CpuInfo::DetectNumberOfCores()), |
| 170 | module_process_thread_(ProcessThread::Create()), |
| 171 | channel_group_(new ChannelGroup(module_process_thread_.get(), nullptr)), |
| 172 | base_channel_id_(0), |
| 173 | next_channel_id_(base_channel_id_ + 1), |
| 174 | config_(config), |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 175 | network_enabled_(true), |
| 176 | receive_crit_(RWLockWrapper::CreateRWLock()), |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 177 | send_crit_(RWLockWrapper::CreateRWLock()) { |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 | [diff] [blame] | 178 | DCHECK(config.send_transport != nullptr); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 179 | |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 180 | DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
| 181 | DCHECK_GE(config.bitrate_config.start_bitrate_bps, |
| 182 | config.bitrate_config.min_bitrate_bps); |
| 183 | if (config.bitrate_config.max_bitrate_bps != -1) { |
| 184 | DCHECK_GE(config.bitrate_config.max_bitrate_bps, |
| 185 | config.bitrate_config.start_bitrate_bps); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 | [diff] [blame] | 186 | } |
| 187 | |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 188 | Trace::CreateTrace(); |
| 189 | module_process_thread_->Start(); |
| 190 | |
| 191 | // TODO(pbos): Remove base channel when CreateReceiveChannel no longer |
| 192 | // requires one. |
| 193 | CHECK(channel_group_->CreateSendChannel(base_channel_id_, 0, num_cpu_cores_, |
| 194 | true)); |
| 195 | |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 | [diff] [blame] | 196 | if (config.overuse_callback) { |
| 197 | overuse_observer_proxy_.reset( |
| 198 | new CpuOveruseObserverProxy(config.overuse_callback)); |
| 199 | } |
| 200 | |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 201 | SetBitrateControllerConfig(config_.bitrate_config); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 202 | } |
| 203 | |
pbos@webrtc.org | 841c8a4 | 2013-09-09 15:04:25 | [diff] [blame] | 204 | Call::~Call() { |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 205 | CHECK_EQ(0u, video_send_ssrcs_.size()); |
| 206 | CHECK_EQ(0u, video_send_streams_.size()); |
| 207 | CHECK_EQ(0u, audio_receive_ssrcs_.size()); |
| 208 | CHECK_EQ(0u, video_receive_ssrcs_.size()); |
| 209 | CHECK_EQ(0u, video_receive_streams_.size()); |
pbos@webrtc.org | 9e4e524 | 2015-02-12 10:48:23 | [diff] [blame] | 210 | |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 211 | channel_group_->DeleteChannel(base_channel_id_); |
| 212 | module_process_thread_->Stop(); |
| 213 | Trace::ReturnTrace(); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 214 | } |
| 215 | |
pbos@webrtc.org | 841c8a4 | 2013-09-09 15:04:25 | [diff] [blame] | 216 | PacketReceiver* Call::Receiver() { return this; } |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 217 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 218 | webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( |
| 219 | const webrtc::AudioReceiveStream::Config& config) { |
| 220 | TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); |
| 221 | LOG(LS_INFO) << "CreateAudioReceiveStream: " << config.ToString(); |
| 222 | AudioReceiveStream* receive_stream = new AudioReceiveStream( |
| 223 | channel_group_->GetRemoteBitrateEstimator(), config); |
| 224 | { |
| 225 | WriteLockScoped write_lock(*receive_crit_); |
| 226 | DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
| 227 | audio_receive_ssrcs_.end()); |
| 228 | audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
| 229 | } |
| 230 | return receive_stream; |
| 231 | } |
| 232 | |
| 233 | void Call::DestroyAudioReceiveStream( |
| 234 | webrtc::AudioReceiveStream* receive_stream) { |
| 235 | TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); |
| 236 | DCHECK(receive_stream != nullptr); |
| 237 | AudioReceiveStream* audio_receive_stream = |
| 238 | static_cast<AudioReceiveStream*>(receive_stream); |
| 239 | { |
| 240 | WriteLockScoped write_lock(*receive_crit_); |
| 241 | size_t num_deleted = audio_receive_ssrcs_.erase( |
| 242 | audio_receive_stream->config().rtp.remote_ssrc); |
| 243 | DCHECK(num_deleted == 1); |
| 244 | } |
| 245 | delete audio_receive_stream; |
| 246 | } |
| 247 | |
| 248 | webrtc::VideoSendStream* Call::CreateVideoSendStream( |
| 249 | const webrtc::VideoSendStream::Config& config, |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 | [diff] [blame] | 250 | const VideoEncoderConfig& encoder_config) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 | [diff] [blame] | 251 | TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); |
pbos@webrtc.org | 32e8528 | 2015-01-15 10:09:39 | [diff] [blame] | 252 | LOG(LS_INFO) << "CreateVideoSendStream: " << config.ToString(); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 | [diff] [blame] | 253 | DCHECK(!config.rtp.ssrcs.empty()); |
pbos@webrtc.org | 1819fd7 | 2013-06-10 13:48:26 | [diff] [blame] | 254 | |
mflodman@webrtc.org | eb16b81 | 2014-06-16 08:57:39 | [diff] [blame] | 255 | // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if |
| 256 | // the call has already started. |
Peter Boström | f16fcbe | 2015-04-30 10:16:05 | [diff] [blame] | 257 | VideoSendStream* send_stream = new VideoSendStream( |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 258 | config_.send_transport, overuse_observer_proxy_.get(), num_cpu_cores_, |
| 259 | module_process_thread_.get(), channel_group_.get(), |
| 260 | rtc::AtomicOps::Increment(&next_channel_id_), config, encoder_config, |
| 261 | suspended_video_send_ssrcs_); |
pbos@webrtc.org | 1819fd7 | 2013-06-10 13:48:26 | [diff] [blame] | 262 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 263 | // This needs to be taken before send_crit_ as both locks need to be held |
| 264 | // while changing network state. |
Peter Boström | f2f8283 | 2015-05-01 11:00:41 | [diff] [blame] | 265 | rtc::CritScope lock(&network_enabled_crit_); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 266 | WriteLockScoped write_lock(*send_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 267 | for (uint32_t ssrc : config.rtp.ssrcs) { |
| 268 | DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); |
| 269 | video_send_ssrcs_[ssrc] = send_stream; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 270 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 271 | video_send_streams_.insert(send_stream); |
| 272 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 273 | if (!network_enabled_) |
| 274 | send_stream->SignalNetworkState(kNetworkDown); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 275 | return send_stream; |
| 276 | } |
| 277 | |
pbos@webrtc.org | 2c46f8d | 2013-11-21 13:49:43 | [diff] [blame] | 278 | void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 | [diff] [blame] | 279 | TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream"); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 | [diff] [blame] | 280 | DCHECK(send_stream != nullptr); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 281 | |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 | [diff] [blame] | 282 | send_stream->Stop(); |
| 283 | |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 | [diff] [blame] | 284 | VideoSendStream* send_stream_impl = nullptr; |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 285 | { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 286 | WriteLockScoped write_lock(*send_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 287 | auto it = video_send_ssrcs_.begin(); |
| 288 | while (it != video_send_ssrcs_.end()) { |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 289 | if (it->second == static_cast<VideoSendStream*>(send_stream)) { |
| 290 | send_stream_impl = it->second; |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 291 | video_send_ssrcs_.erase(it++); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 | [diff] [blame] | 292 | } else { |
| 293 | ++it; |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 294 | } |
| 295 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 296 | video_send_streams_.erase(send_stream_impl); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 297 | } |
Peter Boström | 9b5f96e | 2015-03-26 10:25:49 | [diff] [blame] | 298 | CHECK(send_stream_impl != nullptr); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 299 | |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 | [diff] [blame] | 300 | VideoSendStream::RtpStateMap rtp_state = send_stream_impl->GetRtpStates(); |
| 301 | |
| 302 | for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin(); |
| 303 | it != rtp_state.end(); |
| 304 | ++it) { |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 305 | suspended_video_send_ssrcs_[it->first] = it->second; |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 | [diff] [blame] | 306 | } |
| 307 | |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 308 | delete send_stream_impl; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 309 | } |
| 310 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 311 | webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( |
| 312 | const webrtc::VideoReceiveStream::Config& config) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 | [diff] [blame] | 313 | TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); |
pbos@webrtc.org | 32e8528 | 2015-01-15 10:09:39 | [diff] [blame] | 314 | LOG(LS_INFO) << "CreateVideoReceiveStream: " << config.ToString(); |
Peter Boström | c4188fd | 2015-04-24 13:16:03 | [diff] [blame] | 315 | VideoReceiveStream* receive_stream = new VideoReceiveStream( |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 316 | num_cpu_cores_, base_channel_id_, channel_group_.get(), |
| 317 | rtc::AtomicOps::Increment(&next_channel_id_), config, |
| 318 | config_.send_transport, config_.voice_engine); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 319 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 320 | // This needs to be taken before receive_crit_ as both locks need to be held |
| 321 | // while changing network state. |
Peter Boström | f2f8283 | 2015-05-01 11:00:41 | [diff] [blame] | 322 | rtc::CritScope lock(&network_enabled_crit_); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 323 | WriteLockScoped write_lock(*receive_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 324 | DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
| 325 | video_receive_ssrcs_.end()); |
| 326 | video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 | [diff] [blame] | 327 | // TODO(pbos): Configure different RTX payloads per receive payload. |
| 328 | VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it = |
| 329 | config.rtp.rtx.begin(); |
| 330 | if (it != config.rtp.rtx.end()) |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 331 | video_receive_ssrcs_[it->second.ssrc] = receive_stream; |
| 332 | video_receive_streams_.insert(receive_stream); |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 | [diff] [blame] | 333 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 334 | if (!network_enabled_) |
| 335 | receive_stream->SignalNetworkState(kNetworkDown); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 336 | return receive_stream; |
| 337 | } |
| 338 | |
pbos@webrtc.org | 2c46f8d | 2013-11-21 13:49:43 | [diff] [blame] | 339 | void Call::DestroyVideoReceiveStream( |
| 340 | webrtc::VideoReceiveStream* receive_stream) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 | [diff] [blame] | 341 | TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 | [diff] [blame] | 342 | DCHECK(receive_stream != nullptr); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 343 | |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 | [diff] [blame] | 344 | VideoReceiveStream* receive_stream_impl = nullptr; |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 345 | { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 346 | WriteLockScoped write_lock(*receive_crit_); |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 | [diff] [blame] | 347 | // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a |
| 348 | // separate SSRC there can be either one or two. |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 349 | auto it = video_receive_ssrcs_.begin(); |
| 350 | while (it != video_receive_ssrcs_.end()) { |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 351 | if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 | [diff] [blame] | 352 | if (receive_stream_impl != nullptr) |
| 353 | DCHECK(receive_stream_impl == it->second); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 354 | receive_stream_impl = it->second; |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 355 | video_receive_ssrcs_.erase(it++); |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 | [diff] [blame] | 356 | } else { |
| 357 | ++it; |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 358 | } |
| 359 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 360 | video_receive_streams_.erase(receive_stream_impl); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 361 | } |
Peter Boström | 9b5f96e | 2015-03-26 10:25:49 | [diff] [blame] | 362 | CHECK(receive_stream_impl != nullptr); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 363 | delete receive_stream_impl; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 364 | } |
| 365 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 | [diff] [blame] | 366 | Call::Stats Call::GetStats() const { |
| 367 | Stats stats; |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 368 | // Fetch available send/receive bitrates. |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 | [diff] [blame] | 369 | uint32_t send_bandwidth = 0; |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 370 | channel_group_->GetBitrateController()->AvailableBandwidth(&send_bandwidth); |
| 371 | std::vector<unsigned int> ssrcs; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 | [diff] [blame] | 372 | uint32_t recv_bandwidth = 0; |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 373 | channel_group_->GetRemoteBitrateEstimator()->LatestEstimate(&ssrcs, |
| 374 | &recv_bandwidth); |
| 375 | stats.send_bandwidth_bps = send_bandwidth; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 | [diff] [blame] | 376 | stats.recv_bandwidth_bps = recv_bandwidth; |
Peter Boström | 59d91dc | 2015-04-27 15:24:33 | [diff] [blame] | 377 | stats.pacer_delay_ms = channel_group_->GetPacerQueuingDelayMs(); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 | [diff] [blame] | 378 | { |
| 379 | ReadLockScoped read_lock(*send_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 380 | for (const auto& kv : video_send_ssrcs_) { |
| 381 | int rtt_ms = kv.second->GetRtt(); |
pbos@webrtc.org | 2b19f06 | 2014-12-11 13:26:09 | [diff] [blame] | 382 | if (rtt_ms > 0) |
| 383 | stats.rtt_ms = rtt_ms; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | return stats; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 387 | } |
| 388 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 | [diff] [blame] | 389 | void Call::SetBitrateConfig( |
| 390 | const webrtc::Call::Config::BitrateConfig& bitrate_config) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 | [diff] [blame] | 391 | TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 | [diff] [blame] | 392 | DCHECK_GE(bitrate_config.min_bitrate_bps, 0); |
| 393 | if (bitrate_config.max_bitrate_bps != -1) |
| 394 | DCHECK_GT(bitrate_config.max_bitrate_bps, 0); |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 395 | if (config_.bitrate_config.min_bitrate_bps == |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 | [diff] [blame] | 396 | bitrate_config.min_bitrate_bps && |
| 397 | (bitrate_config.start_bitrate_bps <= 0 || |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 398 | config_.bitrate_config.start_bitrate_bps == |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 | [diff] [blame] | 399 | bitrate_config.start_bitrate_bps) && |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 400 | config_.bitrate_config.max_bitrate_bps == |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 | [diff] [blame] | 401 | bitrate_config.max_bitrate_bps) { |
| 402 | // Nothing new to set, early abort to avoid encoder reconfigurations. |
| 403 | return; |
| 404 | } |
Stefan Holmer | e590416 | 2015-03-26 10:11:06 | [diff] [blame] | 405 | config_.bitrate_config = bitrate_config; |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame^] | 406 | SetBitrateControllerConfig(bitrate_config); |
| 407 | } |
| 408 | |
| 409 | void Call::SetBitrateControllerConfig( |
| 410 | const webrtc::Call::Config::BitrateConfig& bitrate_config) { |
| 411 | BitrateController* bitrate_controller = |
| 412 | channel_group_->GetBitrateController(); |
| 413 | if (bitrate_config.start_bitrate_bps > 0) |
| 414 | bitrate_controller->SetStartBitrate(bitrate_config.start_bitrate_bps); |
| 415 | bitrate_controller->SetMinMaxBitrate(bitrate_config.min_bitrate_bps, |
| 416 | bitrate_config.max_bitrate_bps); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 | [diff] [blame] | 417 | } |
| 418 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 419 | void Call::SignalNetworkState(NetworkState state) { |
| 420 | // Take crit for entire function, it needs to be held while updating streams |
| 421 | // to guarantee a consistent state across streams. |
Peter Boström | f2f8283 | 2015-05-01 11:00:41 | [diff] [blame] | 422 | rtc::CritScope lock(&network_enabled_crit_); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 423 | network_enabled_ = state == kNetworkUp; |
| 424 | { |
| 425 | ReadLockScoped write_lock(*send_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 426 | for (auto& kv : video_send_ssrcs_) { |
| 427 | kv.second->SignalNetworkState(state); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | { |
| 431 | ReadLockScoped write_lock(*receive_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 432 | for (auto& kv : video_receive_ssrcs_) { |
| 433 | kv.second->SignalNetworkState(state); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | } |
| 437 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 438 | PacketReceiver::DeliveryStatus Call::DeliverRtcp(MediaType media_type, |
| 439 | const uint8_t* packet, |
| 440 | size_t length) { |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 441 | // TODO(pbos): Figure out what channel needs it actually. |
| 442 | // Do NOT broadcast! Also make sure it's a valid packet. |
pbos@webrtc.org | caba2d2 | 2014-05-14 13:57:12 | [diff] [blame] | 443 | // Return DELIVERY_UNKNOWN_SSRC if it can be determined that |
| 444 | // there's no receiver of the packet. |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 445 | bool rtcp_delivered = false; |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 446 | if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 447 | ReadLockScoped read_lock(*receive_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 448 | for (VideoReceiveStream* stream : video_receive_streams_) { |
Peter Boström | 3f4eed0 | 2015-04-16 13:59:43 | [diff] [blame] | 449 | if (stream->DeliverRtcp(packet, length)) |
pbos@webrtc.org | 4052370 | 2013-08-05 12:49:22 | [diff] [blame] | 450 | rtcp_delivered = true; |
pbos@webrtc.org | bbb07e6 | 2013-08-05 12:01:36 | [diff] [blame] | 451 | } |
| 452 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 453 | if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 454 | ReadLockScoped read_lock(*send_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 455 | for (VideoSendStream* stream : video_send_streams_) { |
Peter Boström | 74b9769 | 2015-04-14 11:31:46 | [diff] [blame] | 456 | if (stream->DeliverRtcp(packet, length)) |
pbos@webrtc.org | 4052370 | 2013-08-05 12:49:22 | [diff] [blame] | 457 | rtcp_delivered = true; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 458 | } |
| 459 | } |
pbos@webrtc.org | caba2d2 | 2014-05-14 13:57:12 | [diff] [blame] | 460 | return rtcp_delivered ? DELIVERY_OK : DELIVERY_PACKET_ERROR; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 461 | } |
| 462 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 463 | PacketReceiver::DeliveryStatus Call::DeliverRtp(MediaType media_type, |
| 464 | const uint8_t* packet, |
pbos@webrtc.org | af38f4e | 2014-07-08 07:38:12 | [diff] [blame] | 465 | size_t length) { |
| 466 | // Minimum RTP header size. |
| 467 | if (length < 12) |
| 468 | return DELIVERY_PACKET_ERROR; |
| 469 | |
sprang@webrtc.org | 2a6558c | 2015-01-28 12:37:36 | [diff] [blame] | 470 | uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]); |
pbos@webrtc.org | af38f4e | 2014-07-08 07:38:12 | [diff] [blame] | 471 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 472 | ReadLockScoped read_lock(*receive_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 473 | if (media_type == MediaType::ANY || media_type == MediaType::AUDIO) { |
| 474 | auto it = audio_receive_ssrcs_.find(ssrc); |
| 475 | if (it != audio_receive_ssrcs_.end()) { |
| 476 | return it->second->DeliverRtp(packet, length) ? DELIVERY_OK |
| 477 | : DELIVERY_PACKET_ERROR; |
| 478 | } |
| 479 | } |
| 480 | if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { |
| 481 | auto it = video_receive_ssrcs_.find(ssrc); |
| 482 | if (it != video_receive_ssrcs_.end()) { |
| 483 | return it->second->DeliverRtp(packet, length) ? DELIVERY_OK |
| 484 | : DELIVERY_PACKET_ERROR; |
| 485 | } |
| 486 | } |
| 487 | return DELIVERY_UNKNOWN_SSRC; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 488 | } |
| 489 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 490 | PacketReceiver::DeliveryStatus Call::DeliverPacket(MediaType media_type, |
| 491 | const uint8_t* packet, |
pbos@webrtc.org | af38f4e | 2014-07-08 07:38:12 | [diff] [blame] | 492 | size_t length) { |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 | [diff] [blame] | 493 | if (RtpHeaderParser::IsRtcp(packet, length)) |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 494 | return DeliverRtcp(media_type, packet, length); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 495 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 496 | return DeliverRtp(media_type, packet, length); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | } // namespace internal |
| 500 | } // namespace webrtc |