Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: webrtc/video/payload_router.cc

Issue 1725363003: Move RTP module activation into PayloadRouter. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: nuke comment Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/payload_router.h ('k') | webrtc/video/payload_router_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 16
17 namespace webrtc { 17 namespace webrtc {
18 18
19 PayloadRouter::PayloadRouter() 19 PayloadRouter::PayloadRouter()
20 : active_(false) {} 20 : active_(false), num_sending_modules_(0) {}
21 21
22 PayloadRouter::~PayloadRouter() {} 22 PayloadRouter::~PayloadRouter() {}
23 23
24 size_t PayloadRouter::DefaultMaxPayloadLength() { 24 size_t PayloadRouter::DefaultMaxPayloadLength() {
25 const size_t kIpUdpSrtpLength = 44; 25 const size_t kIpUdpSrtpLength = 44;
26 return IP_PACKET_SIZE - kIpUdpSrtpLength; 26 return IP_PACKET_SIZE - kIpUdpSrtpLength;
27 } 27 }
28 28
29 void PayloadRouter::SetSendingRtpModules( 29 void PayloadRouter::Init(
30 const std::vector<RtpRtcp*>& rtp_modules) { 30 const std::vector<RtpRtcp*>& rtp_modules) {
31 rtc::CritScope lock(&crit_); 31 RTC_DCHECK(rtp_modules_.empty());
32 rtp_modules_ = rtp_modules; 32 rtp_modules_ = rtp_modules;
33 } 33 }
34 34
35 void PayloadRouter::set_active(bool active) { 35 void PayloadRouter::set_active(bool active) {
36 rtc::CritScope lock(&crit_); 36 rtc::CritScope lock(&crit_);
37 if (active_ == active)
38 return;
37 active_ = active; 39 active_ = active;
40 UpdateModuleSendingState();
38 } 41 }
39 42
40 bool PayloadRouter::active() { 43 bool PayloadRouter::active() {
41 rtc::CritScope lock(&crit_); 44 rtc::CritScope lock(&crit_);
42 return active_ && !rtp_modules_.empty(); 45 return active_ && !rtp_modules_.empty();
43 } 46 }
44 47
48 void PayloadRouter::SetSendingRtpModules(size_t num_sending_modules) {
49 RTC_DCHECK_LE(num_sending_modules, rtp_modules_.size());
50 rtc::CritScope lock(&crit_);
51 num_sending_modules_ = num_sending_modules;
52 UpdateModuleSendingState();
53 }
54
55 void PayloadRouter::UpdateModuleSendingState() {
56 for (size_t i = 0; i < num_sending_modules_; ++i) {
57 rtp_modules_[i]->SetSendingStatus(active_);
58 rtp_modules_[i]->SetSendingMediaStatus(active_);
59 }
60 // Disable inactive modules.
61 for (size_t i = num_sending_modules_; i < rtp_modules_.size(); ++i) {
62 rtp_modules_[i]->SetSendingStatus(false);
63 rtp_modules_[i]->SetSendingMediaStatus(false);
64 }
65 }
66
45 bool PayloadRouter::RoutePayload(FrameType frame_type, 67 bool PayloadRouter::RoutePayload(FrameType frame_type,
46 int8_t payload_type, 68 int8_t payload_type,
47 uint32_t time_stamp, 69 uint32_t time_stamp,
48 int64_t capture_time_ms, 70 int64_t capture_time_ms,
49 const uint8_t* payload_data, 71 const uint8_t* payload_data,
50 size_t payload_length, 72 size_t payload_length,
51 const RTPFragmentationHeader* fragmentation, 73 const RTPFragmentationHeader* fragmentation,
52 const RTPVideoHeader* rtp_video_hdr) { 74 const RTPVideoHeader* rtp_video_hdr) {
53 rtc::CritScope lock(&crit_); 75 rtc::CritScope lock(&crit_);
54 if (!active_ || rtp_modules_.empty()) 76 RTC_DCHECK(!rtp_modules_.empty());
55 return false; 77 if (!active_ || num_sending_modules_ == 0)
56
57 // The simulcast index might actually be larger than the number of modules in
58 // case the encoder was processing a frame during a codec reconfig.
59 if (rtp_video_hdr != NULL &&
60 rtp_video_hdr->simulcastIdx >= rtp_modules_.size())
61 return false; 78 return false;
62 79
63 int stream_idx = 0; 80 int stream_idx = 0;
64 if (rtp_video_hdr != NULL) 81 if (rtp_video_hdr) {
82 RTC_DCHECK_LT(rtp_video_hdr->simulcastIdx, rtp_modules_.size());
83 // The simulcast index might actually be larger than the number of modules
84 // in case the encoder was processing a frame during a codec reconfig.
85 if (rtp_video_hdr->simulcastIdx >= num_sending_modules_)
86 return false;
65 stream_idx = rtp_video_hdr->simulcastIdx; 87 stream_idx = rtp_video_hdr->simulcastIdx;
88 }
66 return rtp_modules_[stream_idx]->SendOutgoingData( 89 return rtp_modules_[stream_idx]->SendOutgoingData(
67 frame_type, payload_type, time_stamp, capture_time_ms, payload_data, 90 frame_type, payload_type, time_stamp, capture_time_ms, payload_data,
68 payload_length, fragmentation, rtp_video_hdr) == 0 ? true : false; 91 payload_length, fragmentation, rtp_video_hdr) == 0 ? true : false;
69 } 92 }
70 93
71 void PayloadRouter::SetTargetSendBitrates( 94 void PayloadRouter::SetTargetSendBitrates(
72 const std::vector<uint32_t>& stream_bitrates) { 95 const std::vector<uint32_t>& stream_bitrates) {
73 rtc::CritScope lock(&crit_); 96 rtc::CritScope lock(&crit_);
74 if (stream_bitrates.size() < rtp_modules_.size()) { 97 RTC_DCHECK_LE(stream_bitrates.size(), rtp_modules_.size());
75 // There can be a size mis-match during codec reconfiguration. 98 for (size_t i = 0; i < stream_bitrates.size(); ++i) {
76 return; 99 rtp_modules_[i]->SetTargetSendBitrate(stream_bitrates[i]);
77 }
78 int idx = 0;
79 for (auto* rtp_module : rtp_modules_) {
80 rtp_module->SetTargetSendBitrate(stream_bitrates[idx++]);
81 } 100 }
82 } 101 }
83 102
84 size_t PayloadRouter::MaxPayloadLength() const { 103 size_t PayloadRouter::MaxPayloadLength() const {
85 size_t min_payload_length = DefaultMaxPayloadLength(); 104 size_t min_payload_length = DefaultMaxPayloadLength();
86 rtc::CritScope lock(&crit_); 105 rtc::CritScope lock(&crit_);
87 for (auto* rtp_module : rtp_modules_) { 106 for (size_t i = 0; i < num_sending_modules_; ++i) {
88 size_t module_payload_length = rtp_module->MaxDataPayloadLength(); 107 size_t module_payload_length = rtp_modules_[i]->MaxDataPayloadLength();
89 if (module_payload_length < min_payload_length) 108 if (module_payload_length < min_payload_length)
90 min_payload_length = module_payload_length; 109 min_payload_length = module_payload_length;
91 } 110 }
92 return min_payload_length; 111 return min_payload_length;
93 } 112 }
94 113
95 } // namespace webrtc 114 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/payload_router.h ('k') | webrtc/video/payload_router_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698