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

Side by Side Diff: webrtc/modules/video_coding/main/source/video_sender.cc

Issue 1426953003: Remove redudant encoder rate calls. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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 22 matching lines...) Expand all
33 _encoder(nullptr), 33 _encoder(nullptr),
34 _encodedFrameCallback(post_encode_callback), 34 _encodedFrameCallback(post_encode_callback),
35 _nextFrameTypes(1, kVideoFrameDelta), 35 _nextFrameTypes(1, kVideoFrameDelta),
36 _mediaOpt(clock_), 36 _mediaOpt(clock_),
37 _sendStatsCallback(nullptr), 37 _sendStatsCallback(nullptr),
38 _codecDataBase(encoder_rate_observer), 38 _codecDataBase(encoder_rate_observer),
39 frame_dropper_enabled_(true), 39 frame_dropper_enabled_(true),
40 _sendStatsTimer(1000, clock_), 40 _sendStatsTimer(1000, clock_),
41 current_codec_(), 41 current_codec_(),
42 qm_settings_callback_(qm_settings_callback), 42 qm_settings_callback_(qm_settings_callback),
43 protection_callback_(nullptr) { 43 protection_callback_(nullptr),
44 encoder_params_ = {0, 0, 0, 0, false}; 44 encoder_params_({0, 0, 0, 0}) {
45 // Allow VideoSender to be created on one thread but used on another, post 45 // Allow VideoSender to be created on one thread but used on another, post
46 // construction. This is currently how this class is being used by at least 46 // construction. This is currently how this class is being used by at least
47 // one external project (diffractor). 47 // one external project (diffractor).
48 _mediaOpt.EnableQM(qm_settings_callback_ != nullptr); 48 _mediaOpt.EnableQM(qm_settings_callback_ != nullptr);
49 _mediaOpt.Reset(); 49 _mediaOpt.Reset();
50 main_thread_.DetachFromThread(); 50 main_thread_.DetachFromThread();
51 } 51 }
52 52
53 VideoSender::~VideoSender() {} 53 VideoSender::~VideoSender() {}
54 54
55 int32_t VideoSender::Process() { 55 int32_t VideoSender::Process() {
56 int32_t returnValue = VCM_OK; 56 int32_t returnValue = VCM_OK;
57 57
58 if (_sendStatsTimer.TimeUntilProcess() == 0) { 58 if (_sendStatsTimer.TimeUntilProcess() == 0) {
59 _sendStatsTimer.Processed(); 59 _sendStatsTimer.Processed();
60 CriticalSectionScoped cs(process_crit_sect_.get()); 60 CriticalSectionScoped cs(process_crit_sect_.get());
61 if (_sendStatsCallback != nullptr) { 61 if (_sendStatsCallback != nullptr) {
62 uint32_t bitRate = _mediaOpt.SentBitRate(); 62 uint32_t bitRate = _mediaOpt.SentBitRate();
63 uint32_t frameRate = _mediaOpt.SentFrameRate(); 63 uint32_t frameRate = _mediaOpt.SentFrameRate();
64 _sendStatsCallback->SendStatistics(bitRate, frameRate); 64 _sendStatsCallback->SendStatistics(bitRate, frameRate);
65 } 65 }
66 } 66 }
67 67
68 { 68 {
69 rtc::CritScope cs(&params_lock_); 69 rtc::CritScope cs(&params_lock_);
70 // Force an encoder parameters update, so that incoming frame rate is 70 // Force an encoder parameters update, so that incoming frame rate is
71 // updated even if bandwidth hasn't changed. 71 // updated even if bandwidth hasn't changed.
72 encoder_params_.input_frame_rate = _mediaOpt.InputFrameRate(); 72 encoder_params_.input_frame_rate = _mediaOpt.InputFrameRate();
73 encoder_params_.updated = true;
74 } 73 }
75 74
76 return returnValue; 75 return returnValue;
77 } 76 }
78 77
79 int64_t VideoSender::TimeUntilNextProcess() { 78 int64_t VideoSender::TimeUntilNextProcess() {
80 return _sendStatsTimer.TimeUntilProcess(); 79 return _sendStatsTimer.TimeUntilProcess();
81 } 80 }
82 81
83 // Register the send codec to be used. 82 // Register the send codec to be used.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // Make sure the VCM doesn't use the de-registered codec 172 // Make sure the VCM doesn't use the de-registered codec
174 _encoder = nullptr; 173 _encoder = nullptr;
175 } 174 }
176 return ret ? 0 : -1; 175 return ret ? 0 : -1;
177 } 176 }
178 _codecDataBase.RegisterExternalEncoder( 177 _codecDataBase.RegisterExternalEncoder(
179 externalEncoder, payloadType, internalSource); 178 externalEncoder, payloadType, internalSource);
180 return 0; 179 return 0;
181 } 180 }
182 181
183 // Get codec config parameters
184 int32_t VideoSender::CodecConfigParameters(uint8_t* buffer,
185 int32_t size) const {
186 rtc::CritScope lock(&send_crit_);
187 if (_encoder != nullptr) {
188 return _encoder->CodecConfigParameters(buffer, size);
189 }
190 return VCM_UNINITIALIZED;
191 }
192
193 // Get encode bitrate 182 // Get encode bitrate
194 int VideoSender::Bitrate(unsigned int* bitrate) const { 183 int VideoSender::Bitrate(unsigned int* bitrate) const {
195 RTC_DCHECK(main_thread_.CalledOnValidThread()); 184 RTC_DCHECK(main_thread_.CalledOnValidThread());
196 // Since we're running on the thread that's the only thread known to modify 185 // Since we're running on the thread that's the only thread known to modify
197 // the value of _encoder, we don't need to grab the lock here. 186 // the value of _encoder, we don't need to grab the lock here.
198 187
199 // return the bit rate which the encoder is set to 188 // return the bit rate which the encoder is set to
200 if (!_encoder) { 189 if (!_encoder) {
201 return VCM_UNINITIALIZED; 190 return VCM_UNINITIALIZED;
202 } 191 }
(...skipping 18 matching lines...) Expand all
221 int32_t VideoSender::SetChannelParameters(uint32_t target_bitrate, 210 int32_t VideoSender::SetChannelParameters(uint32_t target_bitrate,
222 uint8_t lossRate, 211 uint8_t lossRate,
223 int64_t rtt) { 212 int64_t rtt) {
224 uint32_t target_rate = 213 uint32_t target_rate =
225 _mediaOpt.SetTargetRates(target_bitrate, lossRate, rtt, 214 _mediaOpt.SetTargetRates(target_bitrate, lossRate, rtt,
226 protection_callback_, qm_settings_callback_); 215 protection_callback_, qm_settings_callback_);
227 216
228 uint32_t input_frame_rate = _mediaOpt.InputFrameRate(); 217 uint32_t input_frame_rate = _mediaOpt.InputFrameRate();
229 218
230 rtc::CritScope cs(&params_lock_); 219 rtc::CritScope cs(&params_lock_);
231 encoder_params_ = 220 encoder_params_ = {target_rate, lossRate, rtt, input_frame_rate};
232 EncoderParameters{target_rate, lossRate, rtt, input_frame_rate, true};
233 221
234 return VCM_OK; 222 return VCM_OK;
235 } 223 }
236 224
237 void VideoSender::SetEncoderParameters(EncoderParameters params) { 225 void VideoSender::SetEncoderParameters(EncoderParameters params) {
238 if (!params.updated || params.target_bitrate == 0) 226 if (params.target_bitrate == 0)
239 return; 227 return;
240 228
241 if (params.input_frame_rate == 0) { 229 if (params.input_frame_rate == 0) {
242 // No frame rate estimate available, use default. 230 // No frame rate estimate available, use default.
243 params.input_frame_rate = current_codec_.maxFramerate; 231 params.input_frame_rate = current_codec_.maxFramerate;
244 } 232 }
245 if (_encoder != nullptr) { 233 if (_encoder != nullptr)
246 _encoder->SetChannelParameters(params.loss_rate, params.rtt); 234 _encoder->SetEncoderParameters(params);
247 _encoder->SetRates(params.target_bitrate, params.input_frame_rate);
248 }
249 return;
250 } 235 }
251 236
252 int32_t VideoSender::RegisterTransportCallback( 237 int32_t VideoSender::RegisterTransportCallback(
253 VCMPacketizationCallback* transport) { 238 VCMPacketizationCallback* transport) {
254 rtc::CritScope lock(&send_crit_); 239 rtc::CritScope lock(&send_crit_);
255 _encodedFrameCallback.SetMediaOpt(&_mediaOpt); 240 _encodedFrameCallback.SetMediaOpt(&_mediaOpt);
256 _encodedFrameCallback.SetTransportCallback(transport); 241 _encodedFrameCallback.SetTransportCallback(transport);
257 return VCM_OK; 242 return VCM_OK;
258 } 243 }
259 244
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 } 282 }
298 } 283 }
299 // Add one raw video frame to the encoder, blocking. 284 // Add one raw video frame to the encoder, blocking.
300 int32_t VideoSender::AddVideoFrame(const VideoFrame& videoFrame, 285 int32_t VideoSender::AddVideoFrame(const VideoFrame& videoFrame,
301 const VideoContentMetrics* contentMetrics, 286 const VideoContentMetrics* contentMetrics,
302 const CodecSpecificInfo* codecSpecificInfo) { 287 const CodecSpecificInfo* codecSpecificInfo) {
303 EncoderParameters encoder_params; 288 EncoderParameters encoder_params;
304 { 289 {
305 rtc::CritScope lock(&params_lock_); 290 rtc::CritScope lock(&params_lock_);
306 encoder_params = encoder_params_; 291 encoder_params = encoder_params_;
307 encoder_params_.updated = false;
308 } 292 }
309 rtc::CritScope lock(&send_crit_); 293 rtc::CritScope lock(&send_crit_);
294 if (_encoder == nullptr)
295 return VCM_UNINITIALIZED;
310 SetEncoderParameters(encoder_params); 296 SetEncoderParameters(encoder_params);
311 if (_encoder == nullptr) {
312 return VCM_UNINITIALIZED;
313 }
314 // TODO(holmer): Add support for dropping frames per stream. Currently we 297 // TODO(holmer): Add support for dropping frames per stream. Currently we
315 // only have one frame dropper for all streams. 298 // only have one frame dropper for all streams.
316 if (_nextFrameTypes[0] == kEmptyFrame) { 299 if (_nextFrameTypes[0] == kEmptyFrame) {
317 return VCM_OK; 300 return VCM_OK;
318 } 301 }
319 if (_mediaOpt.DropFrame()) { 302 if (_mediaOpt.DropFrame()) {
320 _encoder->OnDroppedFrame(); 303 _encoder->OnDroppedFrame();
321 return VCM_OK; 304 return VCM_OK;
322 } 305 }
323 _mediaOpt.UpdateContentData(contentMetrics); 306 _mediaOpt.UpdateContentData(contentMetrics);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 int window_bps = std::max(threshold_bps / 10, 10000); 370 int window_bps = std::max(threshold_bps / 10, 10000);
388 _mediaOpt.SuspendBelowMinBitrate(threshold_bps, window_bps); 371 _mediaOpt.SuspendBelowMinBitrate(threshold_bps, window_bps);
389 } 372 }
390 373
391 bool VideoSender::VideoSuspended() const { 374 bool VideoSender::VideoSuspended() const {
392 rtc::CritScope lock(&send_crit_); 375 rtc::CritScope lock(&send_crit_);
393 return _mediaOpt.IsVideoSuspended(); 376 return _mediaOpt.IsVideoSuspended();
394 } 377 }
395 } // namespace vcm 378 } // namespace vcm
396 } // namespace webrtc 379 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698