History

Add cyclic refresh to vp9 rtc external ratecontrol

Jerome Jiang committed 5 years ago

Commit cd260eb1 parent 0702d5a4 files · +40 −3Browse files

Unified · Split

4 files
  1. test/ratectrl_rtc_test.cc +2 −1
  2. vp9/encoder/vp9_aq_cyclicrefresh.c +2 −1
  3. vp9/ratectrl_rtc.cc +26 −1
  4. vp9/ratectrl_rtc.h +10 −0
test/ratectrl_rtc_test.cc+2−1
@@ -127,6 +127,7 @@ class RcInterfaceTest · 126 unmodified lines
127127 rc_cfg_.max_quantizers[0] = 52;
128128 rc_cfg_.min_quantizers[0] = 2;
129129 rc_cfg_.rc_mode = rc_mode;
130+ rc_cfg_.aq_mode = aq_mode_;
130131
131132 // Encoder settings for ground truth.
132133 cfg_.g_w = 1280;
@@ -364,7 +365,7 @@ TEST_P(RcInterfaceTest, OneLayerVBRPeriodicKey) { RunOneLayerVBRPeriodicKey(); } · 231 unmodified lines
364365
365366 TEST_P(RcInterfaceSvcTest, Svc) { RunSvc(); }
366367
367−VP9_INSTANTIATE_TEST_SUITE(RcInterfaceTest, ::testing::Values(0),
368+VP9_INSTANTIATE_TEST_SUITE(RcInterfaceTest, ::testing::Values(0, 3),
368369 ::testing::Values(VPX_CBR, VPX_VBR));
369370 VP9_INSTANTIATE_TEST_SUITE(RcInterfaceSvcTest, ::testing::Values(0));
370371 } // namespace
vp9/encoder/vp9_aq_cyclicrefresh.c+2−1
@@ -516,7 +516,8 @@ void vp9_cyclic_refresh_update_parameters(VP9_COMP *const cpi) { · 515 unmodified lines
516516 cr->rate_ratio_qdelta = 3.0;
517517 } else {
518518 cr->rate_ratio_qdelta = 2.0;
519− if (cpi->noise_estimate.enabled && cpi->noise_estimate.level >= kMedium) {
519+ if (cr->content_mode && cpi->noise_estimate.enabled &&
520+ cpi->noise_estimate.level >= kMedium) {
520521 // Reduce the delta-qp if the estimated source noise is above threshold.
521522 cr->rate_ratio_qdelta = 1.7;
522523 cr->rate_boost_fac = 13;
vp9/ratectrl_rtc.cc+26−1
@@ -11,6 +11,7 @@ · 10 unmodified lines
1111
1212 #include <new>
1313
14+#include "vp9/common/vp9_common.h"
1415 #include "vp9/encoder/vp9_encoder.h"
1516 #include "vp9/encoder/vp9_picklpf.h"
1617 #include "vpx/vp8cx.h"
@@ -28,6 +29,15 @@ std::unique_ptr<VP9RateControlRTC> VP9RateControlRTC::Create( · 11 unmodified lines
2829 return nullptr;
2930 }
3031 rc_api->InitRateControl(cfg);
32+ if (cfg.aq_mode) {
33+ VP9_COMP *const cpi = rc_api->cpi_;
34+ cpi->segmentation_map = static_cast<uint8_t *>(
35+ vpx_calloc(cpi->common.mi_rows * cpi->common.mi_cols,
36+ sizeof(*cpi->segmentation_map)));
37+ cpi->cyclic_refresh =
38+ vp9_cyclic_refresh_alloc(cpi->common.mi_rows, cpi->common.mi_cols);
39+ cpi->cyclic_refresh->content_mode = 0;
40+ }
3141 return rc_api;
3242 }
3343
@@ -42,13 +52,14 @@ void VP9RateControlRTC::InitRateControl(const VP9RateControlRtcConfig &rc_cfg) { · 8 unmodified lines
4252 oxcf->bit_depth = cm->bit_depth;
4353 oxcf->rc_mode = rc_cfg.rc_mode;
4454 oxcf->pass = 0;
45− oxcf->aq_mode = NO_AQ;
55+ oxcf->aq_mode = rc_cfg.aq_mode ? CYCLIC_REFRESH_AQ : NO_AQ;
4656 oxcf->content = VP9E_CONTENT_DEFAULT;
4757 oxcf->drop_frames_water_mark = 0;
4858 cm->current_video_frame = 0;
4959 rc->kf_boost = DEFAULT_KF_BOOST;
5060
5161 UpdateRateControl(rc_cfg);
62+ vp9_set_mb_mi(cm, cm->width, cm->height);
5263
5364 cpi_->use_svc = (cpi_->svc.number_spatial_layers > 1 ||
5465 cpi_->svc.number_temporal_layers > 1)
@@ -146,6 +157,8 @@ void VP9RateControlRTC::ComputeQP(const VP9FrameParamsQpRTC &frame_params) { · 91 unmodified lines
146157 cpi_->svc.number_temporal_layers == 1) {
147158 int target = 0;
148159 if (cpi_->oxcf.rc_mode == VPX_CBR) {
160+ if (cpi_->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
161+ vp9_cyclic_refresh_update_parameters(cpi_);
149162 if (frame_is_intra_only(cm))
150163 target = vp9_calc_iframe_target_size_one_pass_cbr(cpi_);
151164 else
@@ -156,6 +169,8 @@ void VP9RateControlRTC::ComputeQP(const VP9FrameParamsQpRTC &frame_params) { · 4 unmodified lines
156169 cpi_->rc.frames_to_key = cpi_->oxcf.key_freq;
157170 }
158171 vp9_set_gf_update_one_pass_vbr(cpi_);
172+ if (cpi_->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
173+ vp9_cyclic_refresh_update_parameters(cpi_);
159174 if (frame_is_intra_only(cm))
160175 target = vp9_calc_iframe_target_size_one_pass_vbr(cpi_);
161176 else
@@ -171,6 +186,8 @@ void VP9RateControlRTC::ComputeQP(const VP9FrameParamsQpRTC &frame_params) { · 9 unmodified lines
171186 int bottom_index, top_index;
172187 cpi_->common.base_qindex =
173188 vp9_rc_pick_q_and_bounds(cpi_, &bottom_index, &top_index);
189+
190+ if (cpi_->oxcf.aq_mode == CYCLIC_REFRESH_AQ) vp9_cyclic_refresh_setup(cpi_);
174191 }
175192
176193 int VP9RateControlRTC::GetQP() const { return cpi_->common.base_qindex; }
@@ -181,6 +198,14 @@ int VP9RateControlRTC::GetLoopfilterLevel() const { · 4 unmodified lines
181198 return lf->filter_level;
182199 }
183200
201+signed char *VP9RateControlRTC::GetCyclicRefreshMap() const {
202+ return cpi_->cyclic_refresh->map;
203+}
204+
205+int *VP9RateControlRTC::GetDeltaQ() const {
206+ return cpi_->cyclic_refresh->qindex_delta;
207+}
208+
184209 void VP9RateControlRTC::PostEncodeUpdate(uint64_t encoded_frame_size) {
185210 vp9_rc_postencode_update(cpi_, encoded_frame_size);
186211 if (cpi_->svc.number_spatial_layers > 1 ||
vp9/ratectrl_rtc.h+10−0
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818 #include "vp9/common/vp9_enums.h"
1919 #include "vp9/common/vp9_onyxc_int.h"
2020 #include "vp9/vp9_iface_common.h"
21+#include "vp9/encoder/vp9_aq_cyclicrefresh.h"
2122 #include "vp9/encoder/vp9_encoder.h"
2223 #include "vp9/encoder/vp9_firstpass.h"
2324 #include "vp9/vp9_cx_iface.h"
@@ -42,6 +43,7 @@ struct VP9RateControlRtcConfig { · 18 unmodified lines
4243 framerate = 30.0;
4344 ss_number_layers = ts_number_layers = 1;
4445 rc_mode = VPX_CBR;
46+ aq_mode = 0;
4547 vp9_zero(max_quantizers);
4648 vp9_zero(min_quantizers);
4749 vp9_zero(scaling_factor_den);
@@ -82,6 +84,7 @@ struct VP9RateControlRtcConfig { · 34 unmodified lines
8284 int ts_rate_decimator[VPX_TS_MAX_LAYERS];
8385 // vbr, cbr
8486 enum vpx_rc_mode rc_mode;
87+ int aq_mode;
8588 };
8689
8790 struct VP9FrameParamsQpRTC {
@@ -129,6 +132,11 @@ class VP9RateControlRTC { · 41 unmodified lines
129132 }
130133 }
131134 }
135+ if (cpi_->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
136+ vpx_free(cpi_->segmentation_map);
137+ cpi_->segmentation_map = NULL;
138+ vp9_cyclic_refresh_free(cpi_->cyclic_refresh);
139+ }
132140 vpx_free(cpi_);
133141 }
134142 }
@@ -137,6 +145,8 @@ class VP9RateControlRTC { · 2 unmodified lines
137145 // GetQP() needs to be called after ComputeQP() to get the latest QP
138146 int GetQP() const;
139147 int GetLoopfilterLevel() const;
148+ signed char *GetCyclicRefreshMap() const;
149+ int *GetDeltaQ() const;
140150 void ComputeQP(const VP9FrameParamsQpRTC &frame_params);
141151 // Feedback to rate control with the size of current encoded frame
142152 void PostEncodeUpdate(uint64_t encoded_frame_size);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t