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 |
11 #include "webrtc/video/vie_encoder.h" | 11 #include "webrtc/video/vie_encoder.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
19 #include "webrtc/base/trace_event.h" | 19 #include "webrtc/base/trace_event.h" |
20 #include "webrtc/common_video/include/frame_callback.h" | 20 #include "webrtc/common_video/include/frame_callback.h" |
21 #include "webrtc/common_video/include/video_image.h" | 21 #include "webrtc/common_video/include/video_image.h" |
22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
23 #include "webrtc/modules/pacing/paced_sender.h" | 23 #include "webrtc/modules/pacing/paced_sender.h" |
24 #include "webrtc/modules/utility/include/process_thread.h" | 24 #include "webrtc/modules/utility/include/process_thread.h" |
25 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 25 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
26 #include "webrtc/modules/video_coding/include/video_coding.h" | 26 #include "webrtc/modules/video_coding/include/video_coding.h" |
27 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 27 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
| 28 #include "webrtc/modules/video_coding/utility/simulcast_state.h" |
28 #include "webrtc/system_wrappers/include/clock.h" | 29 #include "webrtc/system_wrappers/include/clock.h" |
29 #include "webrtc/system_wrappers/include/metrics.h" | 30 #include "webrtc/system_wrappers/include/metrics.h" |
30 #include "webrtc/system_wrappers/include/tick_util.h" | 31 #include "webrtc/system_wrappers/include/tick_util.h" |
31 #include "webrtc/video/overuse_frame_detector.h" | 32 #include "webrtc/video/overuse_frame_detector.h" |
32 #include "webrtc/video/payload_router.h" | 33 #include "webrtc/video/payload_router.h" |
33 #include "webrtc/video/send_statistics_proxy.h" | 34 #include "webrtc/video/send_statistics_proxy.h" |
34 #include "webrtc/video_frame.h" | 35 #include "webrtc/video_frame.h" |
35 | 36 |
36 namespace webrtc { | 37 namespace webrtc { |
37 | 38 |
38 static const float kStopPaddingThresholdMs = 2000; | 39 static const float kStopPaddingThresholdMs = 2000; |
39 static const int kMinKeyFrameRequestIntervalMs = 300; | 40 static const int kMinKeyFrameRequestIntervalMs = 300; |
40 | 41 |
41 std::vector<uint32_t> AllocateStreamBitrates( | |
42 uint32_t total_bitrate, | |
43 const SimulcastStream* stream_configs, | |
44 size_t number_of_streams) { | |
45 if (number_of_streams == 0) { | |
46 std::vector<uint32_t> stream_bitrates(1, 0); | |
47 stream_bitrates[0] = total_bitrate; | |
48 return stream_bitrates; | |
49 } | |
50 std::vector<uint32_t> stream_bitrates(number_of_streams, 0); | |
51 uint32_t bitrate_remainder = total_bitrate; | |
52 for (size_t i = 0; i < stream_bitrates.size() && bitrate_remainder > 0; ++i) { | |
53 if (stream_configs[i].maxBitrate * 1000 > bitrate_remainder) { | |
54 stream_bitrates[i] = bitrate_remainder; | |
55 } else { | |
56 stream_bitrates[i] = stream_configs[i].maxBitrate * 1000; | |
57 } | |
58 bitrate_remainder -= stream_bitrates[i]; | |
59 } | |
60 return stream_bitrates; | |
61 } | |
62 | |
63 class QMVideoSettingsCallback : public VCMQMSettingsCallback { | 42 class QMVideoSettingsCallback : public VCMQMSettingsCallback { |
64 public: | 43 public: |
65 explicit QMVideoSettingsCallback(VideoProcessing* vpm); | 44 explicit QMVideoSettingsCallback(VideoProcessing* vpm); |
66 | 45 |
67 ~QMVideoSettingsCallback(); | 46 ~QMVideoSettingsCallback(); |
68 | 47 |
69 // Update VPM with QM (quality modes: frame size & frame rate) settings. | 48 // Update VPM with QM (quality modes: frame size & frame rate) settings. |
70 int32_t SetVideoQMSettings(const uint32_t frame_rate, | 49 int32_t SetVideoQMSettings(const uint32_t frame_rate, |
71 const uint32_t width, | 50 const uint32_t width, |
72 const uint32_t height); | 51 const uint32_t height); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 vp_->SetTargetResolution(video_codec.width, video_codec.height, | 155 vp_->SetTargetResolution(video_codec.width, video_codec.height, |
177 video_codec.maxFramerate)); | 156 video_codec.maxFramerate)); |
178 | 157 |
179 // Cache codec before calling AddBitrateObserver (which calls OnBitrateUpdated | 158 // Cache codec before calling AddBitrateObserver (which calls OnBitrateUpdated |
180 // that makes use of the number of simulcast streams configured). | 159 // that makes use of the number of simulcast streams configured). |
181 { | 160 { |
182 rtc::CritScope lock(&data_cs_); | 161 rtc::CritScope lock(&data_cs_); |
183 encoder_config_ = video_codec; | 162 encoder_config_ = video_codec; |
184 encoder_paused_ = true; | 163 encoder_paused_ = true; |
185 min_transmit_bitrate_bps_ = min_transmit_bitrate_bps; | 164 min_transmit_bitrate_bps_ = min_transmit_bitrate_bps; |
| 165 if (encoder_config_.codecType == kVideoCodecVP8) |
| 166 simulcast_rates_.reset(new SimulcastState(encoder_config_)); |
186 } | 167 } |
187 | 168 |
188 size_t max_data_payload_length = send_payload_router_->MaxPayloadLength(); | 169 size_t max_data_payload_length = send_payload_router_->MaxPayloadLength(); |
189 bool success = video_sender_.RegisterSendCodec( | 170 bool success = video_sender_.RegisterSendCodec( |
190 &video_codec, number_of_cores_, | 171 &video_codec, number_of_cores_, |
191 static_cast<uint32_t>(max_data_payload_length)) == VCM_OK; | 172 static_cast<uint32_t>(max_data_payload_length)) == VCM_OK; |
192 if (!success) { | 173 if (!success) { |
193 LOG(LS_ERROR) << "Failed to configure encoder."; | 174 LOG(LS_ERROR) << "Failed to configure encoder."; |
194 RTC_DCHECK(success); | 175 RTC_DCHECK(success); |
195 } | 176 } |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 int64_t round_trip_time_ms) { | 472 int64_t round_trip_time_ms) { |
492 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate" << bitrate_bps | 473 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate" << bitrate_bps |
493 << " packet loss " << static_cast<int>(fraction_lost) | 474 << " packet loss " << static_cast<int>(fraction_lost) |
494 << " rtt " << round_trip_time_ms; | 475 << " rtt " << round_trip_time_ms; |
495 RTC_DCHECK(send_payload_router_); | 476 RTC_DCHECK(send_payload_router_); |
496 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, | 477 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, |
497 round_trip_time_ms); | 478 round_trip_time_ms); |
498 bool video_is_suspended = video_sender_.VideoSuspended(); | 479 bool video_is_suspended = video_sender_.VideoSuspended(); |
499 bool video_suspension_changed; | 480 bool video_suspension_changed; |
500 VideoCodec send_codec; | 481 VideoCodec send_codec; |
| 482 std::vector<uint32_t> stream_bitrates; |
501 { | 483 { |
502 rtc::CritScope lock(&data_cs_); | 484 rtc::CritScope lock(&data_cs_); |
503 last_observed_bitrate_bps_ = bitrate_bps; | 485 last_observed_bitrate_bps_ = bitrate_bps; |
504 video_suspension_changed = video_suspended_ != video_is_suspended; | 486 video_suspension_changed = video_suspended_ != video_is_suspended; |
505 video_suspended_ = video_is_suspended; | 487 video_suspended_ = video_is_suspended; |
506 send_codec = encoder_config_; | 488 send_codec = encoder_config_; |
| 489 |
| 490 if (simulcast_rates_.get()) { |
| 491 simulcast_rates_->AllocateBitrate(bitrate_bps); |
| 492 for (auto stream : *simulcast_rates_) |
| 493 stream_bitrates.push_back(stream.allocated_rate_kbps * 1000); |
| 494 } else { |
| 495 stream_bitrates.push_back(bitrate_bps); |
| 496 } |
507 } | 497 } |
508 | 498 |
509 SimulcastStream* stream_configs = send_codec.simulcastStream; | |
510 // Allocate the bandwidth between the streams. | 499 // Allocate the bandwidth between the streams. |
511 std::vector<uint32_t> stream_bitrates = AllocateStreamBitrates( | |
512 bitrate_bps, stream_configs, send_codec.numberOfSimulcastStreams); | |
513 send_payload_router_->SetTargetSendBitrates(stream_bitrates); | 500 send_payload_router_->SetTargetSendBitrates(stream_bitrates); |
514 | 501 |
515 if (!video_suspension_changed) | 502 if (!video_suspension_changed) |
516 return; | 503 return; |
517 // Video suspend-state changed, inform codec observer. | 504 // Video suspend-state changed, inform codec observer. |
518 LOG(LS_INFO) << "Video suspend state changed " << video_is_suspended | 505 LOG(LS_INFO) << "Video suspend state changed " << video_is_suspended |
519 << " for ssrc " << ssrcs_[0]; | 506 << " for ssrc " << ssrcs_[0]; |
520 if (stats_proxy_) | 507 if (stats_proxy_) |
521 stats_proxy_->OnSuspendChange(video_is_suspended); | 508 stats_proxy_->OnSuspendChange(video_is_suspended); |
522 } | 509 } |
(...skipping 10 matching lines...) Expand all Loading... |
533 const uint32_t width, | 520 const uint32_t width, |
534 const uint32_t height) { | 521 const uint32_t height) { |
535 return vp_->SetTargetResolution(width, height, frame_rate); | 522 return vp_->SetTargetResolution(width, height, frame_rate); |
536 } | 523 } |
537 | 524 |
538 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { | 525 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { |
539 vp_->SetTargetFramerate(frame_rate); | 526 vp_->SetTargetFramerate(frame_rate); |
540 } | 527 } |
541 | 528 |
542 } // namespace webrtc | 529 } // namespace webrtc |
OLD | NEW |