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
127 rc_cfg_.max_quantizers[0] = 52;127 rc_cfg_.max_quantizers[0] = 52;
128 rc_cfg_.min_quantizers[0] = 2;128 rc_cfg_.min_quantizers[0] = 2;
129 rc_cfg_.rc_mode = rc_mode;129 rc_cfg_.rc_mode = rc_mode;
130 rc_cfg_.aq_mode = aq_mode_;
130 131
131 // Encoder settings for ground truth.132 // Encoder settings for ground truth.
132 cfg_.g_w = 1280;133 cfg_.g_w = 1280;
@@ -364,7 +365,7 @@ TEST_P(RcInterfaceTest, OneLayerVBRPeriodicKey) { RunOneLayerVBRPeriodicKey(); } · 231 unmodified lines
364 365
365TEST_P(RcInterfaceSvcTest, Svc) { RunSvc(); }366TEST_P(RcInterfaceSvcTest, Svc) { RunSvc(); }
366 367
367VP9_INSTANTIATE_TEST_SUITE(RcInterfaceTest, ::testing::Values(0),368VP9_INSTANTIATE_TEST_SUITE(RcInterfaceTest, ::testing::Values(0, 3),
368 ::testing::Values(VPX_CBR, VPX_VBR));369 ::testing::Values(VPX_CBR, VPX_VBR));
369VP9_INSTANTIATE_TEST_SUITE(RcInterfaceSvcTest, ::testing::Values(0));370VP9_INSTANTIATE_TEST_SUITE(RcInterfaceSvcTest, ::testing::Values(0));
370} // namespace371} // 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
516 cr->rate_ratio_qdelta = 3.0;516 cr->rate_ratio_qdelta = 3.0;
517 } else {517 } else {
518 cr->rate_ratio_qdelta = 2.0;518 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) {
520 // Reduce the delta-qp if the estimated source noise is above threshold.521 // Reduce the delta-qp if the estimated source noise is above threshold.
521 cr->rate_ratio_qdelta = 1.7;522 cr->rate_ratio_qdelta = 1.7;
522 cr->rate_boost_fac = 13;523 cr->rate_boost_fac = 13;
vp9/ratectrl_rtc.cc+26−1
@@ -11,6 +11,7 @@ · 10 unmodified lines
11 11
12#include <new>12#include <new>
13 13
14#include "vp9/common/vp9_common.h"
14#include "vp9/encoder/vp9_encoder.h"15#include "vp9/encoder/vp9_encoder.h"
15#include "vp9/encoder/vp9_picklpf.h"16#include "vp9/encoder/vp9_picklpf.h"
16#include "vpx/vp8cx.h"17#include "vpx/vp8cx.h"
@@ -28,6 +29,15 @@ std::unique_ptr<VP9RateControlRTC> VP9RateControlRTC::Create( · 11 unmodified lines
28 return nullptr;29 return nullptr;
29 }30 }
30 rc_api->InitRateControl(cfg);31 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 }
31 return rc_api;41 return rc_api;
32}42}
33 43
@@ -42,13 +52,14 @@ void VP9RateControlRTC::InitRateControl(const VP9RateControlRtcConfig &rc_cfg) { · 8 unmodified lines
42 oxcf->bit_depth = cm->bit_depth;52 oxcf->bit_depth = cm->bit_depth;
43 oxcf->rc_mode = rc_cfg.rc_mode;53 oxcf->rc_mode = rc_cfg.rc_mode;
44 oxcf->pass = 0;54 oxcf->pass = 0;
45 oxcf->aq_mode = NO_AQ;55 oxcf->aq_mode = rc_cfg.aq_mode ? CYCLIC_REFRESH_AQ : NO_AQ;
46 oxcf->content = VP9E_CONTENT_DEFAULT;56 oxcf->content = VP9E_CONTENT_DEFAULT;
47 oxcf->drop_frames_water_mark = 0;57 oxcf->drop_frames_water_mark = 0;
48 cm->current_video_frame = 0;58 cm->current_video_frame = 0;
49 rc->kf_boost = DEFAULT_KF_BOOST;59 rc->kf_boost = DEFAULT_KF_BOOST;
50 60
51 UpdateRateControl(rc_cfg);61 UpdateRateControl(rc_cfg);
62 vp9_set_mb_mi(cm, cm->width, cm->height);
52 63
53 cpi_->use_svc = (cpi_->svc.number_spatial_layers > 1 ||64 cpi_->use_svc = (cpi_->svc.number_spatial_layers > 1 ||
54 cpi_->svc.number_temporal_layers > 1)65 cpi_->svc.number_temporal_layers > 1)
@@ -146,6 +157,8 @@ void VP9RateControlRTC::ComputeQP(const VP9FrameParamsQpRTC &frame_params) { · 91 unmodified lines
146 cpi_->svc.number_temporal_layers == 1) {157 cpi_->svc.number_temporal_layers == 1) {
147 int target = 0;158 int target = 0;
148 if (cpi_->oxcf.rc_mode == VPX_CBR) {159 if (cpi_->oxcf.rc_mode == VPX_CBR) {
160 if (cpi_->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
161 vp9_cyclic_refresh_update_parameters(cpi_);
149 if (frame_is_intra_only(cm))162 if (frame_is_intra_only(cm))
150 target = vp9_calc_iframe_target_size_one_pass_cbr(cpi_);163 target = vp9_calc_iframe_target_size_one_pass_cbr(cpi_);
151 else164 else
@@ -156,6 +169,8 @@ void VP9RateControlRTC::ComputeQP(const VP9FrameParamsQpRTC &frame_params) { · 4 unmodified lines
156 cpi_->rc.frames_to_key = cpi_->oxcf.key_freq;169 cpi_->rc.frames_to_key = cpi_->oxcf.key_freq;
157 }170 }
158 vp9_set_gf_update_one_pass_vbr(cpi_);171 vp9_set_gf_update_one_pass_vbr(cpi_);
172 if (cpi_->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
173 vp9_cyclic_refresh_update_parameters(cpi_);
159 if (frame_is_intra_only(cm))174 if (frame_is_intra_only(cm))
160 target = vp9_calc_iframe_target_size_one_pass_vbr(cpi_);175 target = vp9_calc_iframe_target_size_one_pass_vbr(cpi_);
161 else176 else
@@ -171,6 +186,8 @@ void VP9RateControlRTC::ComputeQP(const VP9FrameParamsQpRTC &frame_params) { · 9 unmodified lines
171 int bottom_index, top_index;186 int bottom_index, top_index;
172 cpi_->common.base_qindex =187 cpi_->common.base_qindex =
173 vp9_rc_pick_q_and_bounds(cpi_, &bottom_index, &top_index);188 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_);
174}191}
175 192
176int VP9RateControlRTC::GetQP() const { return cpi_->common.base_qindex; }193int VP9RateControlRTC::GetQP() const { return cpi_->common.base_qindex; }
@@ -181,6 +198,14 @@ int VP9RateControlRTC::GetLoopfilterLevel() const { · 4 unmodified lines
181 return lf->filter_level;198 return lf->filter_level;
182}199}
183 200
201signed char *VP9RateControlRTC::GetCyclicRefreshMap() const {
202 return cpi_->cyclic_refresh->map;
203}
204
205int *VP9RateControlRTC::GetDeltaQ() const {
206 return cpi_->cyclic_refresh->qindex_delta;
207}
208
184void VP9RateControlRTC::PostEncodeUpdate(uint64_t encoded_frame_size) {209void VP9RateControlRTC::PostEncodeUpdate(uint64_t encoded_frame_size) {
185 vp9_rc_postencode_update(cpi_, encoded_frame_size);210 vp9_rc_postencode_update(cpi_, encoded_frame_size);
186 if (cpi_->svc.number_spatial_layers > 1 ||211 if (cpi_->svc.number_spatial_layers > 1 ||
vp9/ratectrl_rtc.h+10−0
@@ -18,6 +18,7 @@ · 17 unmodified lines
18#include "vp9/common/vp9_enums.h"18#include "vp9/common/vp9_enums.h"
19#include "vp9/common/vp9_onyxc_int.h"19#include "vp9/common/vp9_onyxc_int.h"
20#include "vp9/vp9_iface_common.h"20#include "vp9/vp9_iface_common.h"
21#include "vp9/encoder/vp9_aq_cyclicrefresh.h"
21#include "vp9/encoder/vp9_encoder.h"22#include "vp9/encoder/vp9_encoder.h"
22#include "vp9/encoder/vp9_firstpass.h"23#include "vp9/encoder/vp9_firstpass.h"
23#include "vp9/vp9_cx_iface.h"24#include "vp9/vp9_cx_iface.h"
@@ -42,6 +43,7 @@ struct VP9RateControlRtcConfig { · 18 unmodified lines
42 framerate = 30.0;43 framerate = 30.0;
43 ss_number_layers = ts_number_layers = 1;44 ss_number_layers = ts_number_layers = 1;
44 rc_mode = VPX_CBR;45 rc_mode = VPX_CBR;
46 aq_mode = 0;
45 vp9_zero(max_quantizers);47 vp9_zero(max_quantizers);
46 vp9_zero(min_quantizers);48 vp9_zero(min_quantizers);
47 vp9_zero(scaling_factor_den);49 vp9_zero(scaling_factor_den);
@@ -82,6 +84,7 @@ struct VP9RateControlRtcConfig { · 34 unmodified lines
82 int ts_rate_decimator[VPX_TS_MAX_LAYERS];84 int ts_rate_decimator[VPX_TS_MAX_LAYERS];
83 // vbr, cbr85 // vbr, cbr
84 enum vpx_rc_mode rc_mode;86 enum vpx_rc_mode rc_mode;
87 int aq_mode;
85};88};
86 89
87struct VP9FrameParamsQpRTC {90struct VP9FrameParamsQpRTC {
@@ -129,6 +132,11 @@ class VP9RateControlRTC { · 41 unmodified lines
129 }132 }
130 }133 }
131 }134 }
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 }
132 vpx_free(cpi_);140 vpx_free(cpi_);
133 }141 }
134 }142 }
@@ -137,6 +145,8 @@ class VP9RateControlRTC { · 2 unmodified lines
137 // GetQP() needs to be called after ComputeQP() to get the latest QP145 // GetQP() needs to be called after ComputeQP() to get the latest QP
138 int GetQP() const;146 int GetQP() const;
139 int GetLoopfilterLevel() const;147 int GetLoopfilterLevel() const;
148 signed char *GetCyclicRefreshMap() const;
149 int *GetDeltaQ() const;
140 void ComputeQP(const VP9FrameParamsQpRTC &frame_params);150 void ComputeQP(const VP9FrameParamsQpRTC &frame_params);
141 // Feedback to rate control with the size of current encoded frame151 // Feedback to rate control with the size of current encoded frame
142 void PostEncodeUpdate(uint64_t encoded_frame_size);152 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