summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Jiang <jianj@google.com>2023-01-25 19:25:12 -0500
committerJerome Jiang <jianj@google.com>2023-01-31 18:58:26 -0500
commitaa5b62236a4d40679372c28ce37b95f965260aec (patch)
tree21785167a14efcb9f12bbbcecb106db36ad98bcc
parent3f109f786a91a40bd6feb87ce133f351afeff63b (diff)
downloadlibvpx-aa5b62236a4d40679372c28ce37b95f965260aec.tar.gz
Fix per frame qp for temporal layers
Also add tests with fixed temporal layering mode. Change-Id: If516fe94e3fb7f5a745821d1788bfe6cf90edaac (cherry picked from commit db69ce6aea278bee88668fd9cc2af2e544516fdb)
-rw-r--r--test/vp9_datarate_test.cc66
-rw-r--r--vp9/encoder/vp9_svc_layercontext.c4
2 files changed, 59 insertions, 11 deletions
diff --git a/test/vp9_datarate_test.cc b/test/vp9_datarate_test.cc
index eccb00107..7e9180749 100644
--- a/test/vp9_datarate_test.cc
+++ b/test/vp9_datarate_test.cc
@@ -148,14 +148,16 @@ class DatarateTestVP9 : public ::libvpx_test::EncoderTest {
if (video->frame() == 0) {
encoder->Control(VP9E_SET_SVC, 1);
}
- vpx_svc_layer_id_t layer_id;
- layer_id.spatial_layer_id = 0;
- frame_flags_ = GetFrameFlags(video->frame(), cfg_.ts_number_layers);
- layer_id.temporal_layer_id =
- SetLayerId(video->frame(), cfg_.ts_number_layers);
- layer_id.temporal_layer_id_per_spatial[0] =
- SetLayerId(video->frame(), cfg_.ts_number_layers);
- encoder->Control(VP9E_SET_SVC_LAYER_ID, &layer_id);
+ if (cfg_.temporal_layering_mode == VP9E_TEMPORAL_LAYERING_MODE_BYPASS) {
+ vpx_svc_layer_id_t layer_id;
+ frame_flags_ = GetFrameFlags(video->frame(), cfg_.ts_number_layers);
+ layer_id.spatial_layer_id = 0;
+ layer_id.temporal_layer_id =
+ SetLayerId(video->frame(), cfg_.ts_number_layers);
+ layer_id.temporal_layer_id_per_spatial[0] =
+ SetLayerId(video->frame(), cfg_.ts_number_layers);
+ encoder->Control(VP9E_SET_SVC_LAYER_ID, &layer_id);
+ }
}
const vpx_rational_t tb = video->timebase();
timebase_ = static_cast<double>(tb.num) / tb.den;
@@ -830,25 +832,37 @@ class DatarateTestVP9FrameQp
::libvpx_test::Encoder *encoder) {
set_cpu_used_ = 7;
DatarateTestVP9::PreEncodeFrameHook(video, encoder);
- ACMRandom rnd;
- frame_qp_ = static_cast<int>(rnd.RandRange(64));
+ frame_qp_ = static_cast<int>(rnd_.RandRange(64));
encoder->Control(VP9E_SET_QUANTIZER_ONE_PASS, frame_qp_);
frame_++;
}
virtual void PostEncodeFrameHook(::libvpx_test::Encoder *encoder) {
int qp = 0;
+ vpx_svc_layer_id_t layer_id;
if (frame_ >= total_frame_) return;
encoder->Control(VP8E_GET_LAST_QUANTIZER_64, &qp);
ASSERT_EQ(frame_qp_, qp);
+ encoder->Control(VP9E_GET_SVC_LAYER_ID, &layer_id);
+ temporal_layer_id_ = layer_id.temporal_layer_id;
+ }
+
+ virtual void MismatchHook(const vpx_image_t * /*img1*/,
+ const vpx_image_t * /*img2*/) {
+ if (frame_ >= total_frame_) return;
+ ASSERT_TRUE(cfg_.temporal_layering_mode ==
+ VP9E_TEMPORAL_LAYERING_MODE_0212 &&
+ temporal_layer_id_ == 2);
}
protected:
int total_frame_;
private:
+ ACMRandom rnd_;
int frame_qp_;
int frame_;
+ int temporal_layer_id_;
};
TEST_P(DatarateTestVP9FrameQp, VP9SetFrameQp) {
@@ -868,7 +882,7 @@ TEST_P(DatarateTestVP9FrameQp, VP9SetFrameQp) {
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}
-TEST_P(DatarateTestVP9FrameQp, VP9SetFrameQp3TemporalLayers) {
+TEST_P(DatarateTestVP9FrameQp, VP9SetFrameQp3TemporalLayersBypass) {
cfg_.rc_buf_initial_sz = 500;
cfg_.rc_buf_optimal_sz = 500;
cfg_.rc_buf_sz = 1000;
@@ -897,6 +911,36 @@ TEST_P(DatarateTestVP9FrameQp, VP9SetFrameQp3TemporalLayers) {
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}
+TEST_P(DatarateTestVP9FrameQp, VP9SetFrameQp3TemporalLayersFixedMode) {
+ cfg_.rc_buf_initial_sz = 500;
+ cfg_.rc_buf_optimal_sz = 500;
+ cfg_.rc_buf_sz = 1000;
+ cfg_.rc_dropframe_thresh = 0;
+ cfg_.rc_max_quantizer = 63;
+ cfg_.rc_min_quantizer = 0;
+ cfg_.rc_end_usage = VPX_CBR;
+ cfg_.g_lag_in_frames = 0;
+
+ // 3 Temporal layers, no spatial layers: Framerate decimation (4, 2, 1).
+ cfg_.ss_number_layers = 1;
+ cfg_.ts_number_layers = 3;
+ cfg_.ts_rate_decimator[0] = 4;
+ cfg_.ts_rate_decimator[1] = 2;
+ cfg_.ts_rate_decimator[2] = 1;
+
+ cfg_.temporal_layering_mode = VP9E_TEMPORAL_LAYERING_MODE_0212;
+ cfg_.rc_target_bitrate = 200;
+ cfg_.g_error_resilient = 1;
+ total_frame_ = 400;
+ ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
+ 0, total_frame_);
+ ResetModel();
+ cfg_.layer_target_bitrate[0] = 40 * cfg_.rc_target_bitrate / 100;
+ cfg_.layer_target_bitrate[1] = 60 * cfg_.rc_target_bitrate / 100;
+ cfg_.layer_target_bitrate[2] = cfg_.rc_target_bitrate;
+ ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
+}
+
#if CONFIG_VP9_TEMPORAL_DENOISING
// Params: speed setting.
class DatarateTestVP9RealTimeDenoiser : public DatarateTestVP9RealTime {
diff --git a/vp9/encoder/vp9_svc_layercontext.c b/vp9/encoder/vp9_svc_layercontext.c
index 518c00b34..7e9435fb5 100644
--- a/vp9/encoder/vp9_svc_layercontext.c
+++ b/vp9/encoder/vp9_svc_layercontext.c
@@ -894,6 +894,10 @@ int vp9_one_pass_svc_start_layer(VP9_COMP *const cpi) {
RATE_CONTROL *const lrc = &lc->rc;
lrc->worst_quality = vp9_quantizer_to_qindex(lc->max_q);
lrc->best_quality = vp9_quantizer_to_qindex(lc->min_q);
+ if (cpi->fixed_qp_onepass) {
+ lrc->worst_quality = cpi->rc.worst_quality;
+ lrc->best_quality = cpi->rc.best_quality;
+ }
}
if (cpi->oxcf.resize_mode == RESIZE_DYNAMIC && svc->single_layer_svc == 1 &&