OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/video/payload_router.h" | 11 #include "webrtc/video/payload_router.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 14 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
16 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | |
17 | 16 |
18 namespace webrtc { | 17 namespace webrtc { |
19 | 18 |
20 PayloadRouter::PayloadRouter() | 19 PayloadRouter::PayloadRouter() |
21 : crit_(CriticalSectionWrapper::CreateCriticalSection()), | 20 : active_(false) {} |
22 active_(false) {} | |
23 | 21 |
24 PayloadRouter::~PayloadRouter() {} | 22 PayloadRouter::~PayloadRouter() {} |
25 | 23 |
26 size_t PayloadRouter::DefaultMaxPayloadLength() { | 24 size_t PayloadRouter::DefaultMaxPayloadLength() { |
27 const size_t kIpUdpSrtpLength = 44; | 25 const size_t kIpUdpSrtpLength = 44; |
28 return IP_PACKET_SIZE - kIpUdpSrtpLength; | 26 return IP_PACKET_SIZE - kIpUdpSrtpLength; |
29 } | 27 } |
30 | 28 |
31 void PayloadRouter::SetSendingRtpModules( | 29 void PayloadRouter::SetSendingRtpModules( |
32 const std::list<RtpRtcp*>& rtp_modules) { | 30 const std::list<RtpRtcp*>& rtp_modules) { |
33 CriticalSectionScoped cs(crit_.get()); | 31 rtc::CritScope lock(&crit_); |
34 rtp_modules_.clear(); | 32 rtp_modules_.clear(); |
35 rtp_modules_.reserve(rtp_modules.size()); | 33 rtp_modules_.reserve(rtp_modules.size()); |
36 for (auto* rtp_module : rtp_modules) { | 34 for (auto* rtp_module : rtp_modules) { |
37 rtp_modules_.push_back(rtp_module); | 35 rtp_modules_.push_back(rtp_module); |
38 } | 36 } |
39 } | 37 } |
40 | 38 |
41 void PayloadRouter::set_active(bool active) { | 39 void PayloadRouter::set_active(bool active) { |
42 CriticalSectionScoped cs(crit_.get()); | 40 rtc::CritScope lock(&crit_); |
43 active_ = active; | 41 active_ = active; |
44 } | 42 } |
45 | 43 |
46 bool PayloadRouter::active() { | 44 bool PayloadRouter::active() { |
47 CriticalSectionScoped cs(crit_.get()); | 45 rtc::CritScope lock(&crit_); |
48 return active_ && !rtp_modules_.empty(); | 46 return active_ && !rtp_modules_.empty(); |
49 } | 47 } |
50 | 48 |
51 bool PayloadRouter::RoutePayload(FrameType frame_type, | 49 bool PayloadRouter::RoutePayload(FrameType frame_type, |
52 int8_t payload_type, | 50 int8_t payload_type, |
53 uint32_t time_stamp, | 51 uint32_t time_stamp, |
54 int64_t capture_time_ms, | 52 int64_t capture_time_ms, |
55 const uint8_t* payload_data, | 53 const uint8_t* payload_data, |
56 size_t payload_length, | 54 size_t payload_length, |
57 const RTPFragmentationHeader* fragmentation, | 55 const RTPFragmentationHeader* fragmentation, |
58 const RTPVideoHeader* rtp_video_hdr) { | 56 const RTPVideoHeader* rtp_video_hdr) { |
59 CriticalSectionScoped cs(crit_.get()); | 57 rtc::CritScope lock(&crit_); |
60 if (!active_ || rtp_modules_.empty()) | 58 if (!active_ || rtp_modules_.empty()) |
61 return false; | 59 return false; |
62 | 60 |
63 // The simulcast index might actually be larger than the number of modules in | 61 // The simulcast index might actually be larger than the number of modules in |
64 // case the encoder was processing a frame during a codec reconfig. | 62 // case the encoder was processing a frame during a codec reconfig. |
65 if (rtp_video_hdr != NULL && | 63 if (rtp_video_hdr != NULL && |
66 rtp_video_hdr->simulcastIdx >= rtp_modules_.size()) | 64 rtp_video_hdr->simulcastIdx >= rtp_modules_.size()) |
67 return false; | 65 return false; |
68 | 66 |
69 int stream_idx = 0; | 67 int stream_idx = 0; |
70 if (rtp_video_hdr != NULL) | 68 if (rtp_video_hdr != NULL) |
71 stream_idx = rtp_video_hdr->simulcastIdx; | 69 stream_idx = rtp_video_hdr->simulcastIdx; |
72 return rtp_modules_[stream_idx]->SendOutgoingData( | 70 return rtp_modules_[stream_idx]->SendOutgoingData( |
73 frame_type, payload_type, time_stamp, capture_time_ms, payload_data, | 71 frame_type, payload_type, time_stamp, capture_time_ms, payload_data, |
74 payload_length, fragmentation, rtp_video_hdr) == 0 ? true : false; | 72 payload_length, fragmentation, rtp_video_hdr) == 0 ? true : false; |
75 } | 73 } |
76 | 74 |
77 void PayloadRouter::SetTargetSendBitrates( | 75 void PayloadRouter::SetTargetSendBitrates( |
78 const std::vector<uint32_t>& stream_bitrates) { | 76 const std::vector<uint32_t>& stream_bitrates) { |
79 CriticalSectionScoped cs(crit_.get()); | 77 rtc::CritScope lock(&crit_); |
80 if (stream_bitrates.size() < rtp_modules_.size()) { | 78 if (stream_bitrates.size() < rtp_modules_.size()) { |
81 // There can be a size mis-match during codec reconfiguration. | 79 // There can be a size mis-match during codec reconfiguration. |
82 return; | 80 return; |
83 } | 81 } |
84 int idx = 0; | 82 int idx = 0; |
85 for (auto* rtp_module : rtp_modules_) { | 83 for (auto* rtp_module : rtp_modules_) { |
86 rtp_module->SetTargetSendBitrate(stream_bitrates[idx++]); | 84 rtp_module->SetTargetSendBitrate(stream_bitrates[idx++]); |
87 } | 85 } |
88 } | 86 } |
89 | 87 |
90 size_t PayloadRouter::MaxPayloadLength() const { | 88 size_t PayloadRouter::MaxPayloadLength() const { |
91 size_t min_payload_length = DefaultMaxPayloadLength(); | 89 size_t min_payload_length = DefaultMaxPayloadLength(); |
92 CriticalSectionScoped cs(crit_.get()); | 90 rtc::CritScope lock(&crit_); |
93 for (auto* rtp_module : rtp_modules_) { | 91 for (auto* rtp_module : rtp_modules_) { |
94 size_t module_payload_length = rtp_module->MaxDataPayloadLength(); | 92 size_t module_payload_length = rtp_module->MaxDataPayloadLength(); |
95 if (module_payload_length < min_payload_length) | 93 if (module_payload_length < min_payload_length) |
96 min_payload_length = module_payload_length; | 94 min_payload_length = module_payload_length; |
97 } | 95 } |
98 return min_payload_length; | 96 return min_payload_length; |
99 } | 97 } |
100 | 98 |
101 } // namespace webrtc | 99 } // namespace webrtc |
OLD | NEW |