summaryrefslogtreecommitdiff
path: root/vp9
diff options
context:
space:
mode:
authorWan-Teh Chang <wtc@google.com>2023-03-22 16:09:24 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-03-22 16:09:24 +0000
commita0bf98de0d7f7017bccc287bbf986d7518502e29 (patch)
treebca4e44c784653fd133bb32652d201bdfcb9c685 /vp9
parent882399bd54a82aa72ba766356d8fda31fbe40450 (diff)
parent430c6c1553df0abfe2dadc480b21dd691a98140f (diff)
downloadlibvpx-a0bf98de0d7f7017bccc287bbf986d7518502e29.tar
libvpx-a0bf98de0d7f7017bccc287bbf986d7518502e29.tar.gz
libvpx-a0bf98de0d7f7017bccc287bbf986d7518502e29.tar.bz2
libvpx-a0bf98de0d7f7017bccc287bbf986d7518502e29.zip
Merge "Change UpdateRateControl() to return bool" into main
Diffstat (limited to 'vp9')
-rw-r--r--vp9/ratectrl_rtc.cc30
-rw-r--r--vp9/ratectrl_rtc.h5
2 files changed, 21 insertions, 14 deletions
diff --git a/vp9/ratectrl_rtc.cc b/vp9/ratectrl_rtc.cc
index cc12ea336..29033d4ba 100644
--- a/vp9/ratectrl_rtc.cc
+++ b/vp9/ratectrl_rtc.cc
@@ -25,22 +25,16 @@ std::unique_ptr<VP9RateControlRTC> VP9RateControlRTC::Create(
VP9RateControlRTC());
if (!rc_api) return nullptr;
rc_api->cpi_ = static_cast<VP9_COMP *>(vpx_memalign(32, sizeof(*cpi_)));
- if (!rc_api->cpi_) {
- rc_api.reset();
- return nullptr;
- }
+ if (!rc_api->cpi_) return nullptr;
vp9_zero(*rc_api->cpi_);
- rc_api->InitRateControl(cfg);
+ if (!rc_api->InitRateControl(cfg)) return nullptr;
if (cfg.aq_mode) {
VP9_COMP *const cpi = rc_api->cpi_;
cpi->segmentation_map = static_cast<uint8_t *>(
vpx_calloc(cpi->common.mi_rows * cpi->common.mi_cols,
sizeof(*cpi->segmentation_map)));
- if (!cpi->segmentation_map) {
- rc_api.reset();
- return nullptr;
- }
+ if (!cpi->segmentation_map) return nullptr;
cpi->cyclic_refresh =
vp9_cyclic_refresh_alloc(cpi->common.mi_rows, cpi->common.mi_cols);
cpi->cyclic_refresh->content_mode = 0;
@@ -71,7 +65,7 @@ VP9RateControlRTC::~VP9RateControlRTC() {
}
}
-void VP9RateControlRTC::InitRateControl(const VP9RateControlRtcConfig &rc_cfg) {
+bool VP9RateControlRTC::InitRateControl(const VP9RateControlRtcConfig &rc_cfg) {
VP9_COMMON *cm = &cpi_->common;
VP9EncoderConfig *oxcf = &cpi_->oxcf;
RATE_CONTROL *const rc = &cpi_->rc;
@@ -88,7 +82,7 @@ void VP9RateControlRTC::InitRateControl(const VP9RateControlRtcConfig &rc_cfg) {
cm->current_video_frame = 0;
rc->kf_boost = DEFAULT_KF_BOOST;
- UpdateRateControl(rc_cfg);
+ if (!UpdateRateControl(rc_cfg)) return false;
vp9_set_mb_mi(cm, cm->width, cm->height);
cpi_->use_svc = (cpi_->svc.number_spatial_layers > 1 ||
@@ -102,10 +96,21 @@ void VP9RateControlRTC::InitRateControl(const VP9RateControlRtcConfig &rc_cfg) {
vp9_rc_init(oxcf, 0, rc);
rc->constrain_gf_key_freq_onepass_vbr = 0;
cpi_->sf.use_nonrd_pick_mode = 1;
+ return true;
}
-void VP9RateControlRTC::UpdateRateControl(
+bool VP9RateControlRTC::UpdateRateControl(
const VP9RateControlRtcConfig &rc_cfg) {
+ // Since VPX_MAX_LAYERS (12) is less than the product of VPX_SS_MAX_LAYERS (5)
+ // and VPX_TS_MAX_LAYERS (5), check all three.
+ if (rc_cfg.ss_number_layers < 1 ||
+ rc_cfg.ss_number_layers > VPX_SS_MAX_LAYERS ||
+ rc_cfg.ts_number_layers < 1 ||
+ rc_cfg.ts_number_layers > VPX_TS_MAX_LAYERS ||
+ rc_cfg.ss_number_layers * rc_cfg.ts_number_layers > VPX_MAX_LAYERS) {
+ return false;
+ }
+
VP9_COMMON *cm = &cpi_->common;
VP9EncoderConfig *oxcf = &cpi_->oxcf;
RATE_CONTROL *const rc = &cpi_->rc;
@@ -163,6 +168,7 @@ void VP9RateControlRTC::UpdateRateControl(
(int)cpi_->oxcf.target_bandwidth);
}
vp9_check_reset_rc_flag(cpi_);
+ return true;
}
void VP9RateControlRTC::ComputeQP(const VP9FrameParamsQpRTC &frame_params) {
diff --git a/vp9/ratectrl_rtc.h b/vp9/ratectrl_rtc.h
index a82c776f9..7f3c90045 100644
--- a/vp9/ratectrl_rtc.h
+++ b/vp9/ratectrl_rtc.h
@@ -30,6 +30,7 @@ namespace libvpx {
struct VP9RateControlRtcConfig : public VpxRateControlRtcConfig {
public:
VP9RateControlRtcConfig() {
+ ss_number_layers = 1;
vp9_zero(max_quantizers);
vp9_zero(min_quantizers);
vp9_zero(scaling_factor_den);
@@ -89,7 +90,7 @@ class VP9RateControlRTC {
const VP9RateControlRtcConfig &cfg);
~VP9RateControlRTC();
- void UpdateRateControl(const VP9RateControlRtcConfig &rc_cfg);
+ bool UpdateRateControl(const VP9RateControlRtcConfig &rc_cfg);
// GetQP() needs to be called after ComputeQP() to get the latest QP
int GetQP() const;
int GetLoopfilterLevel() const;
@@ -101,7 +102,7 @@ class VP9RateControlRTC {
private:
VP9RateControlRTC() {}
- void InitRateControl(const VP9RateControlRtcConfig &cfg);
+ bool InitRateControl(const VP9RateControlRtcConfig &cfg);
struct VP9_COMP *cpi_;
};