mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2015 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 | |
| 11 | #include "webrtc/video_engine/payload_router.h" |
| 12 | |
| 13 | #include "webrtc/base/checks.h" |
| 14 | #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" |
| 15 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 16 | |
| 17 | namespace webrtc { |
| 18 | |
| 19 | PayloadRouter::PayloadRouter() |
| 20 | : crit_(CriticalSectionWrapper::CreateCriticalSection()), |
| 21 | active_(false) {} |
| 22 | |
| 23 | PayloadRouter::~PayloadRouter() {} |
| 24 | |
| 25 | void PayloadRouter::SetSendingRtpModules( |
| 26 | const std::list<RtpRtcp*>& rtp_modules) { |
| 27 | CriticalSectionScoped cs(crit_.get()); |
| 28 | rtp_modules_.clear(); |
| 29 | rtp_modules_.reserve(rtp_modules.size()); |
| 30 | for (auto* rtp_module : rtp_modules) { |
| 31 | rtp_modules_.push_back(rtp_module); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | void PayloadRouter::set_active(bool active) { |
| 36 | CriticalSectionScoped cs(crit_.get()); |
| 37 | active_ = active; |
| 38 | } |
| 39 | |
| 40 | bool PayloadRouter::active() { |
| 41 | CriticalSectionScoped cs(crit_.get()); |
| 42 | return active_; |
| 43 | } |
| 44 | |
| 45 | bool PayloadRouter::RoutePayload(FrameType frame_type, |
| 46 | int8_t payload_type, |
| 47 | uint32_t time_stamp, |
| 48 | int64_t capture_time_ms, |
| 49 | const uint8_t* payload_data, |
| 50 | size_t payload_size, |
| 51 | const RTPFragmentationHeader* fragmentation, |
| 52 | const RTPVideoHeader* rtp_video_hdr) { |
| 53 | CriticalSectionScoped cs(crit_.get()); |
| 54 | DCHECK(rtp_video_hdr == NULL || |
| 55 | rtp_video_hdr->simulcastIdx <= rtp_modules_.size()); |
| 56 | |
| 57 | if (!active_ || rtp_modules_.empty()) |
| 58 | return false; |
| 59 | |
| 60 | int stream_idx = 0; |
| 61 | if (rtp_video_hdr != NULL) |
| 62 | stream_idx = rtp_video_hdr->simulcastIdx; |
| 63 | return rtp_modules_[stream_idx]->SendOutgoingData( |
| 64 | frame_type, payload_type, time_stamp, capture_time_ms, payload_data, |
| 65 | payload_size, fragmentation, rtp_video_hdr) == 0 ? true : false; |
| 66 | } |
| 67 | |
| 68 | } // namespace webrtc |