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/modules/video_coding/codecs/vp8/vp8_impl.h" | 11 #include "webrtc/modules/video_coding/codecs/vp8/vp8_impl.h" |
12 | 12 |
13 #include <stdlib.h> | 13 #include <stdlib.h> |
14 #include <string.h> | 14 #include <string.h> |
15 #include <time.h> | 15 #include <time.h> |
16 #include <algorithm> | 16 #include <algorithm> |
| 17 #include <string> |
17 | 18 |
18 // NOTE(ajm): Path provided by gyp. | 19 // NOTE(ajm): Path provided by gyp. |
19 #include "libyuv/scale.h" // NOLINT | 20 #include "libyuv/scale.h" // NOLINT |
20 #include "libyuv/convert.h" // NOLINT | 21 #include "libyuv/convert.h" // NOLINT |
21 | 22 |
22 #include "webrtc/base/checks.h" | 23 #include "webrtc/base/checks.h" |
23 #include "webrtc/base/timeutils.h" | 24 #include "webrtc/base/timeutils.h" |
24 #include "webrtc/base/trace_event.h" | 25 #include "webrtc/base/trace_event.h" |
25 #include "webrtc/common_types.h" | 26 #include "webrtc/common_types.h" |
26 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 27 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
27 #include "webrtc/modules/include/module_common_types.h" | 28 #include "webrtc/modules/include/module_common_types.h" |
28 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 29 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
29 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h" | 30 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h" |
30 #include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h" | 31 #include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h" |
31 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" | 32 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" |
32 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" | 33 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" |
33 #include "webrtc/system_wrappers/include/clock.h" | 34 #include "webrtc/system_wrappers/include/clock.h" |
34 #include "webrtc/system_wrappers/include/field_trial.h" | 35 #include "webrtc/system_wrappers/include/field_trial.h" |
35 #include "webrtc/system_wrappers/include/metrics.h" | 36 #include "webrtc/system_wrappers/include/metrics.h" |
36 | 37 |
37 namespace webrtc { | 38 namespace webrtc { |
38 namespace { | 39 namespace { |
39 | 40 |
40 const char kVp8PostProcArmFieldTrial[] = "WebRTC-VP8-Postproc-Arm"; | 41 const char kVp8PostProcArmFieldTrial[] = "WebRTC-VP8-Postproc-Arm"; |
| 42 const char kVp8GfBoostFieldTrial[] = "WebRTC-VP8-GfBoost"; |
41 | 43 |
42 enum { kVp8ErrorPropagationTh = 30 }; | 44 enum { kVp8ErrorPropagationTh = 30 }; |
43 enum { kVp832ByteAlign = 32 }; | 45 enum { kVp832ByteAlign = 32 }; |
44 | 46 |
45 // VP8 denoiser states. | 47 // VP8 denoiser states. |
46 enum denoiserState { | 48 enum denoiserState { |
47 kDenoiserOff, | 49 kDenoiserOff, |
48 kDenoiserOnYOnly, | 50 kDenoiserOnYOnly, |
49 kDenoiserOnYUV, | 51 kDenoiserOnYUV, |
50 kDenoiserOnYUVAggressive, | 52 kDenoiserOnYUVAggressive, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 99 } |
98 | 100 |
99 int NumStreamsDisabled(const std::vector<bool>& streams) { | 101 int NumStreamsDisabled(const std::vector<bool>& streams) { |
100 int num_disabled = 0; | 102 int num_disabled = 0; |
101 for (bool stream : streams) { | 103 for (bool stream : streams) { |
102 if (!stream) | 104 if (!stream) |
103 ++num_disabled; | 105 ++num_disabled; |
104 } | 106 } |
105 return num_disabled; | 107 return num_disabled; |
106 } | 108 } |
| 109 |
| 110 bool GetGfBoostPercentageFromFieldTrialGroup(int* boost_percentage) { |
| 111 std::string group = webrtc::field_trial::FindFullName(kVp8GfBoostFieldTrial); |
| 112 if (group.empty()) |
| 113 return false; |
| 114 |
| 115 if (sscanf(group.c_str(), "Enabled-%d", boost_percentage) != 1) |
| 116 return false; |
| 117 |
| 118 if (*boost_percentage < 0 || *boost_percentage > 100) |
| 119 return false; |
| 120 |
| 121 return true; |
| 122 } |
107 } // namespace | 123 } // namespace |
108 | 124 |
109 VP8Encoder* VP8Encoder::Create() { | 125 VP8Encoder* VP8Encoder::Create() { |
110 return new VP8EncoderImpl(); | 126 return new VP8EncoderImpl(); |
111 } | 127 } |
112 | 128 |
113 VP8Decoder* VP8Decoder::Create() { | 129 VP8Decoder* VP8Decoder::Create() { |
114 return new VP8DecoderImpl(); | 130 return new VP8DecoderImpl(); |
115 } | 131 } |
116 | 132 |
117 VP8EncoderImpl::VP8EncoderImpl() | 133 VP8EncoderImpl::VP8EncoderImpl() |
118 : encoded_complete_callback_(nullptr), | 134 : encoded_complete_callback_(nullptr), |
119 inited_(false), | 135 inited_(false), |
120 timestamp_(0), | 136 timestamp_(0), |
121 feedback_mode_(false), | 137 feedback_mode_(false), |
122 qp_max_(56), // Setting for max quantizer. | 138 qp_max_(56), // Setting for max quantizer. |
123 cpu_speed_default_(-6), | 139 cpu_speed_default_(-6), |
124 number_of_cores_(0), | 140 number_of_cores_(0), |
125 rc_max_intra_target_(0), | 141 rc_max_intra_target_(0), |
126 token_partitions_(VP8_ONE_TOKENPARTITION), | 142 token_partitions_(VP8_ONE_TOKENPARTITION), |
127 down_scale_requested_(false), | 143 down_scale_requested_(false), |
128 down_scale_bitrate_(0), | 144 down_scale_bitrate_(0), |
| 145 use_gf_boost_(webrtc::field_trial::IsEnabled(kVp8GfBoostFieldTrial)), |
129 key_frame_request_(kMaxSimulcastStreams, false) { | 146 key_frame_request_(kMaxSimulcastStreams, false) { |
130 uint32_t seed = rtc::Time32(); | 147 uint32_t seed = rtc::Time32(); |
131 srand(seed); | 148 srand(seed); |
132 | 149 |
133 picture_id_.reserve(kMaxSimulcastStreams); | 150 picture_id_.reserve(kMaxSimulcastStreams); |
134 last_key_frame_picture_id_.reserve(kMaxSimulcastStreams); | 151 last_key_frame_picture_id_.reserve(kMaxSimulcastStreams); |
135 temporal_layers_.reserve(kMaxSimulcastStreams); | 152 temporal_layers_.reserve(kMaxSimulcastStreams); |
136 raw_images_.reserve(kMaxSimulcastStreams); | 153 raw_images_.reserve(kMaxSimulcastStreams); |
137 encoded_images_.reserve(kMaxSimulcastStreams); | 154 encoded_images_.reserve(kMaxSimulcastStreams); |
138 send_stream_.reserve(kMaxSimulcastStreams); | 155 send_stream_.reserve(kMaxSimulcastStreams); |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 codec_.mode == kScreensharing ? 300 : 1); | 644 codec_.mode == kScreensharing ? 300 : 1); |
628 vpx_codec_control(&(encoders_[i]), VP8E_SET_CPUUSED, cpu_speed_[i]); | 645 vpx_codec_control(&(encoders_[i]), VP8E_SET_CPUUSED, cpu_speed_[i]); |
629 vpx_codec_control(&(encoders_[i]), VP8E_SET_TOKEN_PARTITIONS, | 646 vpx_codec_control(&(encoders_[i]), VP8E_SET_TOKEN_PARTITIONS, |
630 static_cast<vp8e_token_partitions>(token_partitions_)); | 647 static_cast<vp8e_token_partitions>(token_partitions_)); |
631 vpx_codec_control(&(encoders_[i]), VP8E_SET_MAX_INTRA_BITRATE_PCT, | 648 vpx_codec_control(&(encoders_[i]), VP8E_SET_MAX_INTRA_BITRATE_PCT, |
632 rc_max_intra_target_); | 649 rc_max_intra_target_); |
633 // VP8E_SET_SCREEN_CONTENT_MODE 2 = screen content with more aggressive | 650 // VP8E_SET_SCREEN_CONTENT_MODE 2 = screen content with more aggressive |
634 // rate control (drop frames on large target bitrate overshoot) | 651 // rate control (drop frames on large target bitrate overshoot) |
635 vpx_codec_control(&(encoders_[i]), VP8E_SET_SCREEN_CONTENT_MODE, | 652 vpx_codec_control(&(encoders_[i]), VP8E_SET_SCREEN_CONTENT_MODE, |
636 codec_.mode == kScreensharing ? 2 : 0); | 653 codec_.mode == kScreensharing ? 2 : 0); |
| 654 // Apply boost on golden frames (has only effect when resilience is off). |
| 655 if (use_gf_boost_ && codec_.VP8()->resilience == kResilienceOff) { |
| 656 int gf_boost_percent; |
| 657 if (GetGfBoostPercentageFromFieldTrialGroup(&gf_boost_percent)) { |
| 658 vpx_codec_control(&(encoders_[i]), VP8E_SET_GF_CBR_BOOST_PCT, |
| 659 gf_boost_percent); |
| 660 } |
| 661 } |
637 } | 662 } |
638 inited_ = true; | 663 inited_ = true; |
639 return WEBRTC_VIDEO_CODEC_OK; | 664 return WEBRTC_VIDEO_CODEC_OK; |
640 } | 665 } |
641 | 666 |
642 uint32_t VP8EncoderImpl::MaxIntraTarget(uint32_t optimalBuffersize) { | 667 uint32_t VP8EncoderImpl::MaxIntraTarget(uint32_t optimalBuffersize) { |
643 // Set max to the optimal buffer level (normalized by target BR), | 668 // Set max to the optimal buffer level (normalized by target BR), |
644 // and scaled by a scalePar. | 669 // and scaled by a scalePar. |
645 // Max target size = scalePar * optimalBufferSize * targetBR[Kbps]. | 670 // Max target size = scalePar * optimalBufferSize * targetBR[Kbps]. |
646 // This values is presented in percentage of perFrameBw: | 671 // This values is presented in percentage of perFrameBw: |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 return -1; | 1327 return -1; |
1303 } | 1328 } |
1304 if (vpx_codec_control(copy->decoder_, VP8_SET_REFERENCE, ref_frame_) != | 1329 if (vpx_codec_control(copy->decoder_, VP8_SET_REFERENCE, ref_frame_) != |
1305 VPX_CODEC_OK) { | 1330 VPX_CODEC_OK) { |
1306 return -1; | 1331 return -1; |
1307 } | 1332 } |
1308 return 0; | 1333 return 0; |
1309 } | 1334 } |
1310 | 1335 |
1311 } // namespace webrtc | 1336 } // namespace webrtc |
OLD | NEW |