| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 19 matching lines...) Expand all Loading... |
| 30 #include "webrtc/system_wrappers/include/clock.h" | 30 #include "webrtc/system_wrappers/include/clock.h" |
| 31 #include "webrtc/system_wrappers/include/metrics.h" | 31 #include "webrtc/system_wrappers/include/metrics.h" |
| 32 #include "webrtc/system_wrappers/include/tick_util.h" | 32 #include "webrtc/system_wrappers/include/tick_util.h" |
| 33 #include "webrtc/video/overuse_frame_detector.h" | 33 #include "webrtc/video/overuse_frame_detector.h" |
| 34 #include "webrtc/video/payload_router.h" | 34 #include "webrtc/video/payload_router.h" |
| 35 #include "webrtc/video/send_statistics_proxy.h" | 35 #include "webrtc/video/send_statistics_proxy.h" |
| 36 #include "webrtc/video_frame.h" | 36 #include "webrtc/video_frame.h" |
| 37 | 37 |
| 38 namespace webrtc { | 38 namespace webrtc { |
| 39 | 39 |
| 40 // Margin on when we pause the encoder when the pacing buffer overflows relative | |
| 41 // to the configured buffer delay. | |
| 42 static const float kEncoderPausePacerMargin = 2.0f; | |
| 43 | |
| 44 // Don't stop the encoder unless the delay is above this configured value. | |
| 45 static const int kMinPacingDelayMs = 200; | |
| 46 | |
| 47 static const float kStopPaddingThresholdMs = 2000; | 40 static const float kStopPaddingThresholdMs = 2000; |
| 48 | |
| 49 static const int kMinKeyFrameRequestIntervalMs = 300; | 41 static const int kMinKeyFrameRequestIntervalMs = 300; |
| 50 | 42 |
| 51 std::vector<uint32_t> AllocateStreamBitrates( | 43 std::vector<uint32_t> AllocateStreamBitrates( |
| 52 uint32_t total_bitrate, | 44 uint32_t total_bitrate, |
| 53 const SimulcastStream* stream_configs, | 45 const SimulcastStream* stream_configs, |
| 54 size_t number_of_streams) { | 46 size_t number_of_streams) { |
| 55 if (number_of_streams == 0) { | 47 if (number_of_streams == 0) { |
| 56 std::vector<uint32_t> stream_bitrates(1, 0); | 48 std::vector<uint32_t> stream_bitrates(1, 0); |
| 57 stream_bitrates[0] = total_bitrate; | 49 stream_bitrates[0] = total_bitrate; |
| 58 return stream_bitrates; | 50 return stream_bitrates; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 stats_proxy_(stats_proxy), | 115 stats_proxy_(stats_proxy), |
| 124 pre_encode_callback_(pre_encode_callback), | 116 pre_encode_callback_(pre_encode_callback), |
| 125 overuse_detector_(overuse_detector), | 117 overuse_detector_(overuse_detector), |
| 126 pacer_(pacer), | 118 pacer_(pacer), |
| 127 send_payload_router_(payload_router), | 119 send_payload_router_(payload_router), |
| 128 bitrate_allocator_(bitrate_allocator), | 120 bitrate_allocator_(bitrate_allocator), |
| 129 time_of_last_frame_activity_ms_(0), | 121 time_of_last_frame_activity_ms_(0), |
| 130 encoder_config_(), | 122 encoder_config_(), |
| 131 min_transmit_bitrate_kbps_(0), | 123 min_transmit_bitrate_kbps_(0), |
| 132 last_observed_bitrate_bps_(0), | 124 last_observed_bitrate_bps_(0), |
| 133 target_delay_ms_(0), | |
| 134 network_is_transmitting_(true), | 125 network_is_transmitting_(true), |
| 135 encoder_paused_(false), | 126 encoder_paused_(false), |
| 136 encoder_paused_and_dropped_frame_(false), | 127 encoder_paused_and_dropped_frame_(false), |
| 137 time_last_intra_request_ms_(ssrcs.size(), -1), | 128 time_last_intra_request_ms_(ssrcs.size(), -1), |
| 138 module_process_thread_(module_process_thread), | 129 module_process_thread_(module_process_thread), |
| 139 has_received_sli_(false), | 130 has_received_sli_(false), |
| 140 picture_id_sli_(0), | 131 picture_id_sli_(0), |
| 141 has_received_rpsi_(false), | 132 has_received_rpsi_(false), |
| 142 picture_id_rpsi_(0), | 133 picture_id_rpsi_(0), |
| 143 video_suspended_(false) { | 134 video_suspended_(false) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 284 |
| 294 return pad_up_to_bitrate_bps; | 285 return pad_up_to_bitrate_bps; |
| 295 } | 286 } |
| 296 | 287 |
| 297 bool ViEEncoder::EncoderPaused() const { | 288 bool ViEEncoder::EncoderPaused() const { |
| 298 // Pause video if paused by caller or as long as the network is down or the | 289 // Pause video if paused by caller or as long as the network is down or the |
| 299 // pacer queue has grown too large in buffered mode. | 290 // pacer queue has grown too large in buffered mode. |
| 300 if (encoder_paused_) { | 291 if (encoder_paused_) { |
| 301 return true; | 292 return true; |
| 302 } | 293 } |
| 303 if (target_delay_ms_ > 0) { | |
| 304 // Buffered mode. | |
| 305 // TODO(pwestin): Workaround until nack is configured as a time and not | |
| 306 // number of packets. | |
| 307 return pacer_->QueueInMs() >= | |
| 308 std::max( | |
| 309 static_cast<int>(target_delay_ms_ * kEncoderPausePacerMargin), | |
| 310 kMinPacingDelayMs); | |
| 311 } | |
| 312 if (pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs) { | 294 if (pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs) { |
| 313 // Too much data in pacer queue, drop frame. | 295 // Too much data in pacer queue, drop frame. |
| 314 return true; | 296 return true; |
| 315 } | 297 } |
| 316 return !network_is_transmitting_; | 298 return !network_is_transmitting_; |
| 317 } | 299 } |
| 318 | 300 |
| 319 void ViEEncoder::TraceFrameDropStart() { | 301 void ViEEncoder::TraceFrameDropStart() { |
| 320 // Start trace event only on the first frame after encoder is paused. | 302 // Start trace event only on the first frame after encoder is paused. |
| 321 if (!encoder_paused_and_dropped_frame_) { | 303 if (!encoder_paused_and_dropped_frame_) { |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 const uint32_t width, | 545 const uint32_t width, |
| 564 const uint32_t height) { | 546 const uint32_t height) { |
| 565 return vp_->SetTargetResolution(width, height, frame_rate); | 547 return vp_->SetTargetResolution(width, height, frame_rate); |
| 566 } | 548 } |
| 567 | 549 |
| 568 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { | 550 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { |
| 569 vp_->SetTargetFramerate(frame_rate); | 551 vp_->SetTargetFramerate(frame_rate); |
| 570 } | 552 } |
| 571 | 553 |
| 572 } // namespace webrtc | 554 } // namespace webrtc |
| OLD | NEW |