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