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

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

Issue 2338133003: Let ViEEncoder tell VideoSendStream about reconfigurations. (Closed)
Patch Set: Rebased Created 4 years, 3 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
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 default: 83 default:
84 return; 84 return;
85 } 85 }
86 } 86 }
87 87
88 } // namespace 88 } // namespace
89 89
90 PayloadRouter::PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules, 90 PayloadRouter::PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules,
91 int payload_type) 91 int payload_type)
92 : active_(false), 92 : active_(false),
93 num_sending_modules_(1),
94 rtp_modules_(rtp_modules), 93 rtp_modules_(rtp_modules),
95 payload_type_(payload_type) { 94 payload_type_(payload_type) {
96 UpdateModuleSendingState();
97 } 95 }
98 96
99 PayloadRouter::~PayloadRouter() {} 97 PayloadRouter::~PayloadRouter() {}
100 98
101 size_t PayloadRouter::DefaultMaxPayloadLength() { 99 size_t PayloadRouter::DefaultMaxPayloadLength() {
102 const size_t kIpUdpSrtpLength = 44; 100 const size_t kIpUdpSrtpLength = 44;
103 return IP_PACKET_SIZE - kIpUdpSrtpLength; 101 return IP_PACKET_SIZE - kIpUdpSrtpLength;
104 } 102 }
105 103
106 void PayloadRouter::set_active(bool active) { 104 void PayloadRouter::set_active(bool active) {
107 rtc::CritScope lock(&crit_); 105 rtc::CritScope lock(&crit_);
108 if (active_ == active) 106 if (active_ == active)
109 return; 107 return;
110 active_ = active; 108 active_ = active;
111 UpdateModuleSendingState(); 109
110 for (auto& module : rtp_modules_) {
111 module->SetSendingStatus(active_);
112 module->SetSendingMediaStatus(active_);
113 }
112 } 114 }
113 115
114 bool PayloadRouter::active() { 116 bool PayloadRouter::active() {
115 rtc::CritScope lock(&crit_); 117 rtc::CritScope lock(&crit_);
116 return active_ && !rtp_modules_.empty(); 118 return active_ && !rtp_modules_.empty();
117 } 119 }
118 120
119 void PayloadRouter::SetSendStreams(const std::vector<VideoStream>& streams) {
120 RTC_DCHECK_LE(streams.size(), rtp_modules_.size());
121 rtc::CritScope lock(&crit_);
122 num_sending_modules_ = streams.size();
123 streams_ = streams;
124 // TODO(perkj): Should SetSendStreams also call SetTargetSendBitrate?
125 UpdateModuleSendingState();
126 }
127
128 void PayloadRouter::UpdateModuleSendingState() {
129 for (size_t i = 0; i < num_sending_modules_; ++i) {
130 rtp_modules_[i]->SetSendingStatus(active_);
131 rtp_modules_[i]->SetSendingMediaStatus(active_);
132 }
133 // Disable inactive modules.
134 for (size_t i = num_sending_modules_; i < rtp_modules_.size(); ++i) {
135 rtp_modules_[i]->SetSendingStatus(false);
136 rtp_modules_[i]->SetSendingMediaStatus(false);
137 }
138 }
139
140 EncodedImageCallback::Result PayloadRouter::OnEncodedImage( 121 EncodedImageCallback::Result PayloadRouter::OnEncodedImage(
141 const EncodedImage& encoded_image, 122 const EncodedImage& encoded_image,
142 const CodecSpecificInfo* codec_specific_info, 123 const CodecSpecificInfo* codec_specific_info,
143 const RTPFragmentationHeader* fragmentation) { 124 const RTPFragmentationHeader* fragmentation) {
144 rtc::CritScope lock(&crit_); 125 rtc::CritScope lock(&crit_);
145 RTC_DCHECK(!rtp_modules_.empty()); 126 RTC_DCHECK(!rtp_modules_.empty());
146 if (!active_ || num_sending_modules_ == 0) 127 if (!active_)
147 return Result(Result::ERROR_SEND_FAILED); 128 return Result(Result::ERROR_SEND_FAILED);
148 129
149 int stream_index = 0; 130 int stream_index = 0;
150 131
151 RTPVideoHeader rtp_video_header; 132 RTPVideoHeader rtp_video_header;
152 memset(&rtp_video_header, 0, sizeof(RTPVideoHeader)); 133 memset(&rtp_video_header, 0, sizeof(RTPVideoHeader));
153 if (codec_specific_info) 134 if (codec_specific_info)
154 CopyCodecSpecific(codec_specific_info, &rtp_video_header); 135 CopyCodecSpecific(codec_specific_info, &rtp_video_header);
155 rtp_video_header.rotation = encoded_image.rotation_; 136 rtp_video_header.rotation = encoded_image.rotation_;
156 rtp_video_header.playout_delay = encoded_image.playout_delay_; 137 rtp_video_header.playout_delay = encoded_image.playout_delay_;
157
158 RTC_DCHECK_LT(rtp_video_header.simulcastIdx, rtp_modules_.size());
159 // The simulcast index might actually be larger than the number of modules
160 // in case the encoder was processing a frame during a codec reconfig.
161 if (rtp_video_header.simulcastIdx >= num_sending_modules_)
162 return Result(Result::ERROR_SEND_FAILED);
163 stream_index = rtp_video_header.simulcastIdx; 138 stream_index = rtp_video_header.simulcastIdx;
164 139
165 uint32_t frame_id; 140 uint32_t frame_id;
166 int send_result = rtp_modules_[stream_index]->SendOutgoingData( 141 int send_result = rtp_modules_[stream_index]->SendOutgoingData(
167 encoded_image._frameType, payload_type_, encoded_image._timeStamp, 142 encoded_image._frameType, payload_type_, encoded_image._timeStamp,
168 encoded_image.capture_time_ms_, encoded_image._buffer, 143 encoded_image.capture_time_ms_, encoded_image._buffer,
169 encoded_image._length, fragmentation, &rtp_video_header, &frame_id); 144 encoded_image._length, fragmentation, &rtp_video_header, &frame_id);
170 145
146 RTC_DCHECK_LT(rtp_video_header.simulcastIdx, rtp_modules_.size());
171 if (send_result < 0) 147 if (send_result < 0)
172 return Result(Result::ERROR_SEND_FAILED); 148 return Result(Result::ERROR_SEND_FAILED);
173 149
174 return Result(Result::OK, frame_id); 150 return Result(Result::OK, frame_id);
175 } 151 }
176 152
177 size_t PayloadRouter::MaxPayloadLength() const { 153 size_t PayloadRouter::MaxPayloadLength() const {
178 size_t min_payload_length = DefaultMaxPayloadLength(); 154 size_t min_payload_length = DefaultMaxPayloadLength();
179 rtc::CritScope lock(&crit_); 155 rtc::CritScope lock(&crit_);
180 for (size_t i = 0; i < num_sending_modules_; ++i) { 156 for (size_t i = 0; i < rtp_modules_.size(); ++i) {
181 size_t module_payload_length = rtp_modules_[i]->MaxDataPayloadLength(); 157 size_t module_payload_length = rtp_modules_[i]->MaxDataPayloadLength();
182 if (module_payload_length < min_payload_length) 158 if (module_payload_length < min_payload_length)
183 min_payload_length = module_payload_length; 159 min_payload_length = module_payload_length;
184 } 160 }
185 return min_payload_length; 161 return min_payload_length;
186 } 162 }
187 163
188 } // namespace webrtc 164 } // 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