pbos@webrtc.org | 2a9108f | 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 | 3f45c2e | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 11 | #include <assert.h> |
| 12 | #include <string.h> |
| 13 | |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 14 | #include <map> |
| 15 | #include <vector> |
| 16 | |
pbos@webrtc.org | 24e2089 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 17 | #include "webrtc/call.h" |
| 18 | #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" |
pbos@webrtc.org | b5d2d16 | 2013-10-02 13:36:09 +0000 | [diff] [blame] | 19 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
pbos@webrtc.org | 24e2089 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 20 | #include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" |
pbos@webrtc.org | b5d2d16 | 2013-10-02 13:36:09 +0000 | [diff] [blame] | 21 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 22 | #include "webrtc/system_wrappers/interface/trace.h" |
pbos@webrtc.org | 24e2089 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 23 | #include "webrtc/video/video_receive_stream.h" |
| 24 | #include "webrtc/video/video_send_stream.h" |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 25 | #include "webrtc/video_engine/include/vie_base.h" |
| 26 | #include "webrtc/video_engine/include/vie_codec.h" |
| 27 | #include "webrtc/video_engine/include/vie_rtp_rtcp.h" |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 28 | |
| 29 | namespace webrtc { |
pbos@webrtc.org | 24e2089 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 30 | namespace internal { |
| 31 | class Call : public webrtc::Call, public PacketReceiver { |
| 32 | public: |
| 33 | Call(webrtc::VideoEngine* video_engine, const Call::Config& config); |
| 34 | virtual ~Call(); |
| 35 | |
| 36 | virtual PacketReceiver* Receiver() OVERRIDE; |
| 37 | virtual std::vector<VideoCodec> GetVideoCodecs() OVERRIDE; |
| 38 | |
| 39 | virtual VideoSendStream::Config GetDefaultSendConfig() OVERRIDE; |
| 40 | |
pbos@webrtc.org | 964d78e | 2013-11-20 10:40:25 +0000 | [diff] [blame] | 41 | virtual VideoSendStream* CreateVideoSendStream( |
pbos@webrtc.org | 24e2089 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 42 | const VideoSendStream::Config& config) OVERRIDE; |
| 43 | |
pbos@webrtc.org | 12a93e0 | 2013-11-21 13:49:43 +0000 | [diff] [blame^] | 44 | virtual void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) |
| 45 | OVERRIDE; |
pbos@webrtc.org | 24e2089 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 46 | |
| 47 | virtual VideoReceiveStream::Config GetDefaultReceiveConfig() OVERRIDE; |
| 48 | |
pbos@webrtc.org | 964d78e | 2013-11-20 10:40:25 +0000 | [diff] [blame] | 49 | virtual VideoReceiveStream* CreateVideoReceiveStream( |
pbos@webrtc.org | 24e2089 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 50 | const VideoReceiveStream::Config& config) OVERRIDE; |
| 51 | |
pbos@webrtc.org | 12a93e0 | 2013-11-21 13:49:43 +0000 | [diff] [blame^] | 52 | virtual void DestroyVideoReceiveStream( |
pbos@webrtc.org | 24e2089 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 53 | webrtc::VideoReceiveStream* receive_stream) OVERRIDE; |
| 54 | |
| 55 | virtual uint32_t SendBitrateEstimate() OVERRIDE; |
| 56 | virtual uint32_t ReceiveBitrateEstimate() OVERRIDE; |
| 57 | |
| 58 | virtual bool DeliverPacket(const uint8_t* packet, size_t length) OVERRIDE; |
| 59 | |
| 60 | private: |
| 61 | bool DeliverRtcp(const uint8_t* packet, size_t length); |
| 62 | bool DeliverRtp(const RTPHeader& header, |
| 63 | const uint8_t* packet, |
| 64 | size_t length); |
| 65 | |
| 66 | Call::Config config_; |
| 67 | |
| 68 | std::map<uint32_t, VideoReceiveStream*> receive_ssrcs_; |
| 69 | scoped_ptr<RWLockWrapper> receive_lock_; |
| 70 | |
| 71 | std::map<uint32_t, VideoSendStream*> send_ssrcs_; |
| 72 | scoped_ptr<RWLockWrapper> send_lock_; |
| 73 | |
| 74 | scoped_ptr<RtpHeaderParser> rtp_header_parser_; |
| 75 | |
| 76 | webrtc::VideoEngine* video_engine_; |
| 77 | ViERTP_RTCP* rtp_rtcp_; |
| 78 | ViECodec* codec_; |
| 79 | |
| 80 | DISALLOW_COPY_AND_ASSIGN(Call); |
| 81 | }; |
| 82 | } // internal |
pbos@webrtc.org | c2014fd | 2013-08-14 13:52:52 +0000 | [diff] [blame] | 83 | |
pbos@webrtc.org | b5d2d16 | 2013-10-02 13:36:09 +0000 | [diff] [blame] | 84 | class TraceDispatcher : public TraceCallback { |
| 85 | public: |
| 86 | TraceDispatcher() |
| 87 | : crit_(CriticalSectionWrapper::CreateCriticalSection()), |
pbos@webrtc.org | a6063fd | 2013-10-02 16:22:18 +0000 | [diff] [blame] | 88 | initialized_(false), |
pbos@webrtc.org | b5d2d16 | 2013-10-02 13:36:09 +0000 | [diff] [blame] | 89 | filter_(kTraceNone) {} |
| 90 | |
pbos@webrtc.org | a6063fd | 2013-10-02 16:22:18 +0000 | [diff] [blame] | 91 | ~TraceDispatcher() { |
| 92 | if (initialized_) { |
| 93 | Trace::ReturnTrace(); |
| 94 | VideoEngine::SetTraceCallback(NULL); |
| 95 | } |
| 96 | } |
| 97 | |
pbos@webrtc.org | b5d2d16 | 2013-10-02 13:36:09 +0000 | [diff] [blame] | 98 | virtual void Print(TraceLevel level, |
| 99 | const char* message, |
| 100 | int length) OVERRIDE { |
| 101 | CriticalSectionScoped lock(crit_.get()); |
| 102 | for (std::map<Call*, Call::Config*>::iterator it = callbacks_.begin(); |
| 103 | it != callbacks_.end(); |
| 104 | ++it) { |
| 105 | if ((level & it->second->trace_filter) != kTraceNone) |
| 106 | it->second->trace_callback->Print(level, message, length); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | void RegisterCallback(Call* call, Call::Config* config) { |
| 111 | if (config->trace_callback == NULL) |
| 112 | return; |
| 113 | |
| 114 | CriticalSectionScoped lock(crit_.get()); |
| 115 | callbacks_[call] = config; |
| 116 | |
pbos@webrtc.org | a6063fd | 2013-10-02 16:22:18 +0000 | [diff] [blame] | 117 | filter_ |= config->trace_filter; |
| 118 | if (filter_ != kTraceNone && !initialized_) { |
| 119 | initialized_ = true; |
| 120 | Trace::CreateTrace(); |
| 121 | VideoEngine::SetTraceCallback(this); |
pbos@webrtc.org | b5d2d16 | 2013-10-02 13:36:09 +0000 | [diff] [blame] | 122 | } |
pbos@webrtc.org | a6063fd | 2013-10-02 16:22:18 +0000 | [diff] [blame] | 123 | VideoEngine::SetTraceFilter(filter_); |
pbos@webrtc.org | b5d2d16 | 2013-10-02 13:36:09 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void DeregisterCallback(Call* call) { |
| 127 | CriticalSectionScoped lock(crit_.get()); |
| 128 | callbacks_.erase(call); |
pbos@webrtc.org | b5d2d16 | 2013-10-02 13:36:09 +0000 | [diff] [blame] | 129 | |
| 130 | filter_ = kTraceNone; |
| 131 | for (std::map<Call*, Call::Config*>::iterator it = callbacks_.begin(); |
| 132 | it != callbacks_.end(); |
| 133 | ++it) { |
| 134 | filter_ |= it->second->trace_filter; |
| 135 | } |
| 136 | |
| 137 | VideoEngine::SetTraceFilter(filter_); |
pbos@webrtc.org | b5d2d16 | 2013-10-02 13:36:09 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | private: |
| 141 | scoped_ptr<CriticalSectionWrapper> crit_; |
pbos@webrtc.org | a6063fd | 2013-10-02 16:22:18 +0000 | [diff] [blame] | 142 | bool initialized_; |
pbos@webrtc.org | b5d2d16 | 2013-10-02 13:36:09 +0000 | [diff] [blame] | 143 | unsigned int filter_; |
| 144 | std::map<Call*, Call::Config*> callbacks_; |
| 145 | }; |
| 146 | |
| 147 | namespace internal { |
pbos@webrtc.org | 24e2089 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 148 | TraceDispatcher* global_trace_dispatcher = NULL; |
pbos@webrtc.org | b5d2d16 | 2013-10-02 13:36:09 +0000 | [diff] [blame] | 149 | } // internal |
| 150 | |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 151 | Call* Call::Create(const Call::Config& config) { |
pbos@webrtc.org | b5d2d16 | 2013-10-02 13:36:09 +0000 | [diff] [blame] | 152 | if (internal::global_trace_dispatcher == NULL) { |
| 153 | TraceDispatcher* dispatcher = new TraceDispatcher(); |
| 154 | // TODO(pbos): Atomic compare and exchange. |
| 155 | if (internal::global_trace_dispatcher == NULL) { |
| 156 | internal::global_trace_dispatcher = dispatcher; |
| 157 | } else { |
| 158 | delete dispatcher; |
| 159 | } |
| 160 | } |
| 161 | |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 162 | VideoEngine* video_engine = VideoEngine::Create(); |
pbos@webrtc.org | c2014fd | 2013-08-14 13:52:52 +0000 | [diff] [blame] | 163 | assert(video_engine != NULL); |
| 164 | |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 165 | return new internal::Call(video_engine, config); |
pbos@webrtc.org | c2014fd | 2013-08-14 13:52:52 +0000 | [diff] [blame] | 166 | } |
pbos@webrtc.org | c2014fd | 2013-08-14 13:52:52 +0000 | [diff] [blame] | 167 | |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 168 | namespace internal { |
| 169 | |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 170 | Call::Call(webrtc::VideoEngine* video_engine, const Call::Config& config) |
mflodman@webrtc.org | bf76ae2 | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 171 | : config_(config), |
pbos@webrtc.org | 63988b2 | 2013-06-10 13:48:26 +0000 | [diff] [blame] | 172 | receive_lock_(RWLockWrapper::CreateRWLock()), |
| 173 | send_lock_(RWLockWrapper::CreateRWLock()), |
pbos@webrtc.org | 78ab511 | 2013-08-05 12:49:22 +0000 | [diff] [blame] | 174 | rtp_header_parser_(RtpHeaderParser::Create()), |
pbos@webrtc.org | 63988b2 | 2013-06-10 13:48:26 +0000 | [diff] [blame] | 175 | video_engine_(video_engine) { |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 176 | assert(video_engine != NULL); |
mflodman@webrtc.org | bf76ae2 | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 177 | assert(config.send_transport != NULL); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 178 | |
pbos@webrtc.org | b5d2d16 | 2013-10-02 13:36:09 +0000 | [diff] [blame] | 179 | global_trace_dispatcher->RegisterCallback(this, &config_); |
| 180 | |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 181 | rtp_rtcp_ = ViERTP_RTCP::GetInterface(video_engine_); |
| 182 | assert(rtp_rtcp_ != NULL); |
| 183 | |
| 184 | codec_ = ViECodec::GetInterface(video_engine_); |
| 185 | assert(codec_ != NULL); |
| 186 | } |
| 187 | |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 188 | Call::~Call() { |
pbos@webrtc.org | b5d2d16 | 2013-10-02 13:36:09 +0000 | [diff] [blame] | 189 | global_trace_dispatcher->DeregisterCallback(this); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 190 | codec_->Release(); |
pbos@webrtc.org | c2014fd | 2013-08-14 13:52:52 +0000 | [diff] [blame] | 191 | rtp_rtcp_->Release(); |
| 192 | webrtc::VideoEngine::Delete(video_engine_); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 193 | } |
| 194 | |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 195 | PacketReceiver* Call::Receiver() { return this; } |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 196 | |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 197 | std::vector<VideoCodec> Call::GetVideoCodecs() { |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 198 | std::vector<VideoCodec> codecs; |
| 199 | |
| 200 | VideoCodec codec; |
| 201 | for (size_t i = 0; i < static_cast<size_t>(codec_->NumberOfCodecs()); ++i) { |
pbos@webrtc.org | 24e2089 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 202 | if (codec_->GetCodec(static_cast<unsigned char>(i), codec) == 0) { |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 203 | codecs.push_back(codec); |
| 204 | } |
| 205 | } |
| 206 | return codecs; |
| 207 | } |
| 208 | |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 209 | VideoSendStream::Config Call::GetDefaultSendConfig() { |
pbos@webrtc.org | 6f1c3ef | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 210 | VideoSendStream::Config config; |
| 211 | codec_->GetCodec(0, config.codec); |
| 212 | return config; |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 213 | } |
| 214 | |
pbos@webrtc.org | 964d78e | 2013-11-20 10:40:25 +0000 | [diff] [blame] | 215 | VideoSendStream* Call::CreateVideoSendStream( |
| 216 | const VideoSendStream::Config& config) { |
pbos@webrtc.org | 63988b2 | 2013-06-10 13:48:26 +0000 | [diff] [blame] | 217 | assert(config.rtp.ssrcs.size() > 0); |
| 218 | assert(config.codec.numberOfSimulcastStreams == 0 || |
| 219 | config.codec.numberOfSimulcastStreams == config.rtp.ssrcs.size()); |
| 220 | |
pbos@webrtc.org | 78ab511 | 2013-08-05 12:49:22 +0000 | [diff] [blame] | 221 | VideoSendStream* send_stream = new VideoSendStream( |
| 222 | config_.send_transport, config_.overuse_detection, video_engine_, config); |
pbos@webrtc.org | 63988b2 | 2013-06-10 13:48:26 +0000 | [diff] [blame] | 223 | |
| 224 | WriteLockScoped write_lock(*send_lock_); |
| 225 | for (size_t i = 0; i < config.rtp.ssrcs.size(); ++i) { |
| 226 | assert(send_ssrcs_.find(config.rtp.ssrcs[i]) == send_ssrcs_.end()); |
| 227 | send_ssrcs_[config.rtp.ssrcs[i]] = send_stream; |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 228 | } |
| 229 | return send_stream; |
| 230 | } |
| 231 | |
pbos@webrtc.org | 12a93e0 | 2013-11-21 13:49:43 +0000 | [diff] [blame^] | 232 | void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { |
pbos@webrtc.org | 0020858 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 233 | assert(send_stream != NULL); |
| 234 | |
| 235 | VideoSendStream* send_stream_impl = NULL; |
| 236 | { |
| 237 | WriteLockScoped write_lock(*send_lock_); |
| 238 | for (std::map<uint32_t, VideoSendStream*>::iterator it = |
| 239 | send_ssrcs_.begin(); |
| 240 | it != send_ssrcs_.end(); |
| 241 | ++it) { |
| 242 | if (it->second == static_cast<VideoSendStream*>(send_stream)) { |
| 243 | send_stream_impl = it->second; |
| 244 | send_ssrcs_.erase(it); |
| 245 | break; |
| 246 | } |
| 247 | } |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 248 | } |
pbos@webrtc.org | 0020858 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 249 | |
| 250 | assert(send_stream_impl != NULL); |
| 251 | delete send_stream_impl; |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 252 | } |
| 253 | |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 254 | VideoReceiveStream::Config Call::GetDefaultReceiveConfig() { |
pbos@webrtc.org | c179706 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 255 | return VideoReceiveStream::Config(); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 256 | } |
| 257 | |
pbos@webrtc.org | 964d78e | 2013-11-20 10:40:25 +0000 | [diff] [blame] | 258 | VideoReceiveStream* Call::CreateVideoReceiveStream( |
pbos@webrtc.org | c179706 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 259 | const VideoReceiveStream::Config& config) { |
stefan@webrtc.org | e028410 | 2013-11-18 11:45:11 +0000 | [diff] [blame] | 260 | VideoReceiveStream* receive_stream = new VideoReceiveStream( |
| 261 | video_engine_, config, config_.send_transport, config_.voice_engine); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 262 | |
pbos@webrtc.org | 63988b2 | 2013-06-10 13:48:26 +0000 | [diff] [blame] | 263 | WriteLockScoped write_lock(*receive_lock_); |
| 264 | assert(receive_ssrcs_.find(config.rtp.ssrc) == receive_ssrcs_.end()); |
| 265 | receive_ssrcs_[config.rtp.ssrc] = receive_stream; |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 266 | return receive_stream; |
| 267 | } |
| 268 | |
pbos@webrtc.org | 12a93e0 | 2013-11-21 13:49:43 +0000 | [diff] [blame^] | 269 | void Call::DestroyVideoReceiveStream( |
| 270 | webrtc::VideoReceiveStream* receive_stream) { |
pbos@webrtc.org | 0020858 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 271 | assert(receive_stream != NULL); |
| 272 | |
| 273 | VideoReceiveStream* receive_stream_impl = NULL; |
| 274 | { |
| 275 | WriteLockScoped write_lock(*receive_lock_); |
| 276 | for (std::map<uint32_t, VideoReceiveStream*>::iterator it = |
| 277 | receive_ssrcs_.begin(); |
| 278 | it != receive_ssrcs_.end(); |
| 279 | ++it) { |
| 280 | if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { |
| 281 | receive_stream_impl = it->second; |
| 282 | receive_ssrcs_.erase(it); |
| 283 | break; |
| 284 | } |
| 285 | } |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 286 | } |
pbos@webrtc.org | 0020858 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 287 | |
| 288 | assert(receive_stream_impl != NULL); |
| 289 | delete receive_stream_impl; |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 290 | } |
| 291 | |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 292 | uint32_t Call::SendBitrateEstimate() { |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 293 | // TODO(pbos): Return send-bitrate estimate |
| 294 | return 0; |
| 295 | } |
| 296 | |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 297 | uint32_t Call::ReceiveBitrateEstimate() { |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 298 | // TODO(pbos): Return receive-bitrate estimate |
| 299 | return 0; |
| 300 | } |
| 301 | |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 302 | bool Call::DeliverRtcp(const uint8_t* packet, size_t length) { |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 303 | // TODO(pbos): Figure out what channel needs it actually. |
| 304 | // Do NOT broadcast! Also make sure it's a valid packet. |
| 305 | bool rtcp_delivered = false; |
pbos@webrtc.org | 78ab511 | 2013-08-05 12:49:22 +0000 | [diff] [blame] | 306 | { |
| 307 | ReadLockScoped read_lock(*receive_lock_); |
| 308 | for (std::map<uint32_t, VideoReceiveStream*>::iterator it = |
| 309 | receive_ssrcs_.begin(); |
| 310 | it != receive_ssrcs_.end(); |
| 311 | ++it) { |
pbos@webrtc.org | 0011252 | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 312 | if (it->second->DeliverRtcp(packet, length)) |
pbos@webrtc.org | 78ab511 | 2013-08-05 12:49:22 +0000 | [diff] [blame] | 313 | rtcp_delivered = true; |
pbos@webrtc.org | ce85109 | 2013-08-05 12:01:36 +0000 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
pbos@webrtc.org | 78ab511 | 2013-08-05 12:49:22 +0000 | [diff] [blame] | 317 | { |
| 318 | ReadLockScoped read_lock(*send_lock_); |
| 319 | for (std::map<uint32_t, VideoSendStream*>::iterator it = |
| 320 | send_ssrcs_.begin(); |
| 321 | it != send_ssrcs_.end(); |
| 322 | ++it) { |
pbos@webrtc.org | 0011252 | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 323 | if (it->second->DeliverRtcp(packet, length)) |
pbos@webrtc.org | 78ab511 | 2013-08-05 12:49:22 +0000 | [diff] [blame] | 324 | rtcp_delivered = true; |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | return rtcp_delivered; |
| 328 | } |
| 329 | |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 330 | bool Call::DeliverRtp(const RTPHeader& header, |
| 331 | const uint8_t* packet, |
| 332 | size_t length) { |
pbos@webrtc.org | 78ab511 | 2013-08-05 12:49:22 +0000 | [diff] [blame] | 333 | VideoReceiveStream* receiver; |
| 334 | { |
| 335 | ReadLockScoped read_lock(*receive_lock_); |
| 336 | std::map<uint32_t, VideoReceiveStream*>::iterator it = |
| 337 | receive_ssrcs_.find(header.ssrc); |
| 338 | if (it == receive_ssrcs_.end()) { |
| 339 | // TODO(pbos): Log some warning, SSRC without receiver. |
| 340 | return false; |
| 341 | } |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 342 | |
pbos@webrtc.org | 78ab511 | 2013-08-05 12:49:22 +0000 | [diff] [blame] | 343 | receiver = it->second; |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 344 | } |
pbos@webrtc.org | ce85109 | 2013-08-05 12:01:36 +0000 | [diff] [blame] | 345 | return receiver->DeliverRtp(static_cast<const uint8_t*>(packet), length); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 346 | } |
| 347 | |
pbos@webrtc.org | bf6d572 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 348 | bool Call::DeliverPacket(const uint8_t* packet, size_t length) { |
pbos@webrtc.org | 78ab511 | 2013-08-05 12:49:22 +0000 | [diff] [blame] | 349 | // TODO(pbos): ExtensionMap if there are extensions. |
| 350 | if (RtpHeaderParser::IsRtcp(packet, static_cast<int>(length))) |
| 351 | return DeliverRtcp(packet, length); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 352 | |
pbos@webrtc.org | 78ab511 | 2013-08-05 12:49:22 +0000 | [diff] [blame] | 353 | RTPHeader rtp_header; |
| 354 | if (!rtp_header_parser_->Parse(packet, static_cast<int>(length), &rtp_header)) |
| 355 | return false; |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 356 | |
pbos@webrtc.org | 78ab511 | 2013-08-05 12:49:22 +0000 | [diff] [blame] | 357 | return DeliverRtp(rtp_header, packet, length); |
pbos@webrtc.org | 2a9108f | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | } // namespace internal |
| 361 | } // namespace webrtc |