ref: 65f9ded3951f4ae7bda634e308862d5fd3bea730
parent: 46fa3d6b5b0a01d6a68ade4287848ee2a098d9a4
author: angiebird <angiebird@google.com>
date: Fri Oct 25 07:45:34 EDT 2019
vp9_get_coding_frame_num() Change-Id: I36fa92d9acfc272fc9a2f700bcd1466e95f1443c
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -3630,3 +3630,63 @@
}
}
}
+
+#if CONFIG_RATE_CTRL
+// Under CONFIG_RATE_CTRL, once the first_pass_info is ready, the number of
+// coding frames (including show frame and alt ref) can be determined.
+int vp9_get_coding_frame_num(const struct VP9EncoderConfig *oxcf,
+ const FRAME_INFO *frame_info,
+ const FIRST_PASS_INFO *first_pass_info,
+ int multi_layer_arf, int allow_alt_ref) {
+ int coding_frame_num = 0;
+ RATE_CONTROL rc;
+ RANGE active_gf_interval;
+ int arf_layers;
+ double gop_intra_factor;
+ int use_alt_ref;
+ int gop_coding_frames;
+ int gop_show_frames;
+ int show_idx = 0;
+ int arf_active_or_kf = 1;
+ rc.static_scene_max_gf_interval = 250;
+ vp9_rc_init(oxcf, 1, &rc);
+
+ while (show_idx < first_pass_info->num_frames) {
+ if (rc.frames_to_key == 0) {
+ rc.frames_to_key = get_frames_to_next_key(
+ oxcf, frame_info, first_pass_info, show_idx, rc.min_gf_interval);
+ arf_active_or_kf = 1;
+ } else {
+ }
+
+ {
+ int dummy = 0;
+ active_gf_interval = get_active_gf_inverval_range(
+ frame_info, &rc, arf_active_or_kf, show_idx, dummy, dummy);
+ }
+
+ arf_layers = get_arf_layers(multi_layer_arf, oxcf->enable_auto_arf,
+ active_gf_interval.max);
+ if (multi_layer_arf) {
+ gop_intra_factor = 1.0 + 0.25 * arf_layers;
+ } else {
+ gop_intra_factor = 1.0;
+ }
+
+ gop_coding_frames = get_gop_coding_frame_num(
+ &use_alt_ref, frame_info, first_pass_info, &rc, show_idx,
+ &active_gf_interval, gop_intra_factor, oxcf->lag_in_frames);
+
+ use_alt_ref &= allow_alt_ref;
+
+ rc.source_alt_ref_active = use_alt_ref;
+ arf_active_or_kf = use_alt_ref;
+ gop_show_frames = gop_coding_frames - use_alt_ref;
+ rc.frames_to_key -= gop_show_frames;
+ rc.frames_since_key += gop_show_frames;
+ show_idx += gop_show_frames;
+ coding_frame_num += gop_show_frames + use_alt_ref;
+ }
+ return coding_frame_num;
+}
+#endif
--- a/vp9/encoder/vp9_firstpass.h
+++ b/vp9/encoder/vp9_firstpass.h
@@ -13,6 +13,9 @@
#include <assert.h>
+#if CONFIG_RATE_CTRL
+#include "vp9/common/vp9_onyxc_int.h"
+#endif
#include "vp9/encoder/vp9_lookahead.h"
#include "vp9/encoder/vp9_ratectrl.h"
@@ -244,6 +247,14 @@
void calculate_coded_size(struct VP9_COMP *cpi, int *scaled_frame_width,
int *scaled_frame_height);
+
+#if CONFIG_RATE_CTRL
+struct VP9EncoderConfig;
+int vp9_get_coding_frame_num(const struct VP9EncoderConfig *oxcf,
+ const FRAME_INFO *frame_info,
+ const FIRST_PASS_INFO *first_pass_info,
+ int multi_layer_arf, int allow_alt_ref);
+#endif
#ifdef __cplusplus
} // extern "C"