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