History

Add ref frame info to vpx_rc_encodeframe_info_t

Bug: webm:1707

Angie Chiang committed 6 years ago

Commit 9bfdf4a1 parent 90271b27 files · +106 −54Browse files

Unified · Split

7 files
  1. test/vp9_ext_ratectrl_test.cc +26 −0
  2. vp9/common/vp9_onyxc_int.h +2 −4
  3. vp9/encoder/vp9_encoder.c +57 −45
  4. vp9/encoder/vp9_encoder.h +5 −0
  5. vp9/encoder/vp9_ext_ratectrl.c +10 −3
  6. vp9/encoder/vp9_ext_ratectrl.h +4 −2
  7. vpx/vpx_ext_ratectrl.h +2 −0
test/vp9_ext_ratectrl_test.cc+26−0
@@ -72,10 +72,24 @@ vpx_rc_status_t rc_get_encodeframe_decision( · 71 unmodified lines
7272
7373 if (encode_frame_info->coding_index == 0) {
7474 EXPECT_EQ(encode_frame_info->frame_type, 0 /*kFrameTypeKey*/);
75+ EXPECT_EQ(encode_frame_info->ref_frame_valid_list[0],
76+ 0); // kRefFrameTypeLast
77+ EXPECT_EQ(encode_frame_info->ref_frame_valid_list[1],
78+ 0); // kRefFrameTypePast
79+ EXPECT_EQ(encode_frame_info->ref_frame_valid_list[2],
80+ 0); // kRefFrameTypeFuture
7581 }
7682
7783 if (encode_frame_info->coding_index == 1) {
7884 EXPECT_EQ(encode_frame_info->frame_type, 2 /*kFrameTypeAltRef*/);
85+ EXPECT_EQ(encode_frame_info->ref_frame_valid_list[0],
86+ 1); // kRefFrameTypeLast
87+ EXPECT_EQ(encode_frame_info->ref_frame_valid_list[1],
88+ 0); // kRefFrameTypePast
89+ EXPECT_EQ(encode_frame_info->ref_frame_valid_list[2],
90+ 0); // kRefFrameTypeFuture
91+ EXPECT_EQ(encode_frame_info->ref_frame_coding_indexes[0],
92+ 0); // kRefFrameTypeLast
7993 }
8094
8195 if (encode_frame_info->coding_index >= 2 &&
@@ -85,6 +99,18 @@ vpx_rc_status_t rc_get_encodeframe_decision( · 3 unmodified lines
8599
86100 if (encode_frame_info->coding_index == 5) {
87101 EXPECT_EQ(encode_frame_info->frame_type, 3 /*kFrameTypeOverlay*/);
102+ EXPECT_EQ(encode_frame_info->ref_frame_valid_list[0],
103+ 1); // kRefFrameTypeLast
104+ EXPECT_EQ(encode_frame_info->ref_frame_valid_list[1],
105+ 1); // kRefFrameTypePast
106+ EXPECT_EQ(encode_frame_info->ref_frame_valid_list[2],
107+ 1); // kRefFrameTypeFuture
108+ EXPECT_EQ(encode_frame_info->ref_frame_coding_indexes[0],
109+ 4); // kRefFrameTypeLast
110+ EXPECT_EQ(encode_frame_info->ref_frame_coding_indexes[1],
111+ 0); // kRefFrameTypePast
112+ EXPECT_EQ(encode_frame_info->ref_frame_coding_indexes[2],
113+ 1); // kRefFrameTypeFuture
88114 }
89115 if (encode_frame_info->coding_index == kLosslessCodingIndex) {
90116 // We should get sse == 0 at rc_update_encodeframe_result()
vp9/common/vp9_onyxc_int.h+2−4
@@ -75,12 +75,10 @@ typedef struct { · 74 unmodified lines
7575
7676 // TODO(angiebird): Set frame_index/frame_coding_index on the decoder side
7777 // properly.
78− int frame_index; // Display order in the video, it's equivalent to the
79− // show_idx defined in EncodeFrameInfo.
80−#if CONFIG_RATE_CTRL
78+ int frame_index; // Display order in the video, it's equivalent to the
79+ // show_idx defined in EncodeFrameInfo.
8180 int frame_coding_index; // The coding order (starting from zero) of this
8281 // frame.
83−#endif // CONFIG_RATE_CTRL
8482 vpx_codec_frame_buffer_t raw_frame_buffer;
8583 YV12_BUFFER_CONFIG buf;
8684 } RefCntBuffer;
vp9/encoder/vp9_encoder.c+57−45
@@ -4205,6 +4205,27 @@ static int encode_without_recode_loop(VP9_COMP *cpi, size_t *size, · 4204 unmodified lines
42054205 return 1;
42064206 }
42074207
4208+static int get_ref_frame_flags(const VP9_COMP *cpi) {
4209+ const int *const map = cpi->common.ref_frame_map;
4210+ const int gold_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idx];
4211+ const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idx];
4212+ const int gold_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx];
4213+ int flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG;
4214+
4215+ if (gold_is_last) flags &= ~VP9_GOLD_FLAG;
4216+
4217+ if (cpi->rc.frames_till_gf_update_due == INT_MAX &&
4218+ (cpi->svc.number_temporal_layers == 1 &&
4219+ cpi->svc.number_spatial_layers == 1))
4220+ flags &= ~VP9_GOLD_FLAG;
4221+
4222+ if (alt_is_last) flags &= ~VP9_ALT_FLAG;
4223+
4224+ if (gold_is_alt) flags &= ~VP9_ALT_FLAG;
4225+
4226+ return flags;
4227+}
4228+
42084229 #if !CONFIG_REALTIME_ONLY
42094230 #define MAX_QSTEP_ADJ 4
42104231 static int get_qstep_adj(int rate_excess, int rate_limit) {
@@ -4481,9 +4502,14 @@ static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest · 270 unmodified lines
44814502 if (cpi->ext_ratectrl.ready) {
44824503 const GF_GROUP *gf_group = &cpi->twopass.gf_group;
44834504 vpx_rc_encodeframe_decision_t encode_frame_decision;
4505+ FRAME_UPDATE_TYPE update_type = gf_group->update_type[gf_group->index];
4506+ const int ref_frame_flags = get_ref_frame_flags(cpi);
4507+ RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES];
4508+ get_ref_frame_bufs(cpi, ref_frame_bufs);
44844509 vp9_extrc_get_encodeframe_decision(
4485− &cpi->ext_ratectrl, gf_group, cm->current_video_frame,
4486− cm->current_frame_coding_index, &encode_frame_decision);
4510+ &cpi->ext_ratectrl, cm->current_video_frame,
4511+ cm->current_frame_coding_index, update_type, ref_frame_bufs,
4512+ ref_frame_flags, &encode_frame_decision);
44874513 q = encode_frame_decision.q_index;
44884514 }
44894515
@@ -4772,27 +4798,6 @@ static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest · 282 unmodified lines
47724798 }
47734799 #endif // !CONFIG_REALTIME_ONLY
47744800
4775−static int get_ref_frame_flags(const VP9_COMP *cpi) {
4776− const int *const map = cpi->common.ref_frame_map;
4777− const int gold_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idx];
4778− const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idx];
4779− const int gold_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx];
4780− int flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG;
4781−
4782− if (gold_is_last) flags &= ~VP9_GOLD_FLAG;
4783−
4784− if (cpi->rc.frames_till_gf_update_due == INT_MAX &&
4785− (cpi->svc.number_temporal_layers == 1 &&
4786− cpi->svc.number_spatial_layers == 1))
4787− flags &= ~VP9_GOLD_FLAG;
4788−
4789− if (alt_is_last) flags &= ~VP9_ALT_FLAG;
4790−
4791− if (gold_is_alt) flags &= ~VP9_ALT_FLAG;
4792−
4793− return flags;
4794−}
4795−
47964801 static void set_ext_overrides(VP9_COMP *cpi) {
47974802 // Overrides the defaults with the externally supplied values with
47984803 // vp9_update_reference() and vp9_update_entropy() calls
@@ -5097,9 +5102,7 @@ static void set_frame_index(VP9_COMP *cpi, VP9_COMMON *cm) { · 298 unmodified lines
50975102 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
50985103 ref_buffer->frame_index =
50995104 cm->current_video_frame + gf_group->arf_src_offset[gf_group->index];
5100−#if CONFIG_RATE_CTRL
51015105 ref_buffer->frame_coding_index = cm->current_frame_coding_index;
5102−#endif // CONFIG_RATE_CTRL
51035106 }
51045107 }
51055108
@@ -7391,6 +7394,30 @@ static void setup_tpl_stats(VP9_COMP *cpi) { · 2285 unmodified lines
73917394 #endif // CONFIG_NON_GREEDY_MV
73927395 }
73937396
7397+void vp9_get_ref_frame_info(FRAME_UPDATE_TYPE update_type, int ref_frame_flags,
7398+ RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES],
7399+ int *ref_frame_coding_indexes,
7400+ int *ref_frame_valid_list) {
7401+ if (update_type != KF_UPDATE) {
7402+ const VP9_REFFRAME inter_ref_flags[MAX_INTER_REF_FRAMES] = { VP9_LAST_FLAG,
7403+ VP9_GOLD_FLAG,
7404+ VP9_ALT_FLAG };
7405+ int i;
7406+ for (i = 0; i < MAX_INTER_REF_FRAMES; ++i) {
7407+ assert(ref_frame_bufs[i] != NULL);
7408+ ref_frame_coding_indexes[i] = ref_frame_bufs[i]->frame_coding_index;
7409+ ref_frame_valid_list[i] = (ref_frame_flags & inter_ref_flags[i]) != 0;
7410+ }
7411+ } else {
7412+ // No reference frame is available when this is a key frame.
7413+ int i;
7414+ for (i = 0; i < MAX_INTER_REF_FRAMES; ++i) {
7415+ ref_frame_coding_indexes[i] = -1;
7416+ ref_frame_valid_list[i] = 0;
7417+ }
7418+ }
7419+}
7420+
73947421 #if !CONFIG_REALTIME_ONLY
73957422 #if CONFIG_RATE_CTRL
73967423 static void copy_frame_counts(const FRAME_COUNTS *input_counts,
@@ -7538,6 +7565,7 @@ static void yv12_buffer_to_image_buffer(const YV12_BUFFER_CONFIG *yv12_buffer, · 141 unmodified lines
75387565 }
75397566 }
75407567 #endif // CONFIG_RATE_CTRL
7568+
75417569 static void update_encode_frame_result(
75427570 int ref_frame_flags, FRAME_UPDATE_TYPE update_type,
75437571 const YV12_BUFFER_CONFIG *source_frame, const RefCntBuffer *coded_frame_buf,
@@ -7560,26 +7588,10 @@ static void update_encode_frame_result( · 16 unmodified lines
75607588 #endif // CONFIG_VP9_HIGHBITDEPTH
75617589 encode_frame_result->frame_coding_index = coded_frame_buf->frame_coding_index;
75627590
7563− if (update_type != KF_UPDATE) {
7564− const VP9_REFFRAME inter_ref_flags[MAX_INTER_REF_FRAMES] = { VP9_LAST_FLAG,
7565− VP9_GOLD_FLAG,
7566− VP9_ALT_FLAG };
7567− int i;
7568− for (i = 0; i < MAX_INTER_REF_FRAMES; ++i) {
7569− assert(ref_frame_bufs[i] != NULL);
7570− encode_frame_result->ref_frame_coding_indexes[i] =
7571− ref_frame_bufs[i]->frame_coding_index;
7572− encode_frame_result->ref_frame_valid_list[i] =
7573− (ref_frame_flags & inter_ref_flags[i]) != 0;
7574− }
7575− } else {
7576− // No reference frame is available when this is a key frame.
7577− int i;
7578− for (i = 0; i < MAX_INTER_REF_FRAMES; ++i) {
7579− encode_frame_result->ref_frame_coding_indexes[i] = -1;
7580− encode_frame_result->ref_frame_valid_list[i] = 0;
7581− }
7582− }
7591+ vp9_get_ref_frame_info(update_type, ref_frame_flags, ref_frame_bufs,
7592+ encode_frame_result->ref_frame_coding_indexes,
7593+ encode_frame_result->ref_frame_valid_list);
7594+
75837595 encode_frame_result->psnr = psnr.psnr[0];
75847596 encode_frame_result->sse = psnr.sse[0];
75857597 copy_frame_counts(counts, &encode_frame_result->frame_counts);
vp9/encoder/vp9_encoder.h+5−0
@@ -1268,6 +1268,11 @@ void vp9_scale_references(VP9_COMP *cpi); · 1267 unmodified lines
12681268
12691269 void vp9_update_reference_frames(VP9_COMP *cpi);
12701270
1271+void vp9_get_ref_frame_info(FRAME_UPDATE_TYPE update_type, int ref_frame_flags,
1272+ RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES],
1273+ int *ref_frame_coding_indexes,
1274+ int *ref_frame_valid_list);
1275+
12711276 void vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv);
12721277
12731278 YV12_BUFFER_CONFIG *vp9_svc_twostage_scale(
vp9/encoder/vp9_ext_ratectrl.c+10−3
@@ -9,6 +9,7 @@ · 8 unmodified lines
99 */
1010
1111 #include "vp9/encoder/vp9_ext_ratectrl.h"
12+#include "vp9/encoder/vp9_encoder.h"
1213 #include "vp9/common/vp9_common.h"
1314 #include "vpx_dsp/psnr.h"
1415
@@ -102,14 +103,20 @@ static int extrc_get_frame_type(FRAME_UPDATE_TYPE update_type) { · 87 unmodified lines
102103 }
103104
104105 void vp9_extrc_get_encodeframe_decision(
105− EXT_RATECTRL *ext_ratectrl, const GF_GROUP *gf_group, int show_index,
106− int coding_index, vpx_rc_encodeframe_decision_t *encode_frame_decision) {
106+ EXT_RATECTRL *ext_ratectrl, int show_index, int coding_index,
107+ FRAME_UPDATE_TYPE update_type,
108+ RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES], int ref_frame_flags,
109+ vpx_rc_encodeframe_decision_t *encode_frame_decision) {
107110 if (ext_ratectrl->ready) {
108− FRAME_UPDATE_TYPE update_type = gf_group->update_type[gf_group->index];
109111 vpx_rc_encodeframe_info_t encode_frame_info;
110112 encode_frame_info.show_index = show_index;
111113 encode_frame_info.coding_index = coding_index;
112114 encode_frame_info.frame_type = extrc_get_frame_type(update_type);
115+
116+ vp9_get_ref_frame_info(update_type, ref_frame_flags, ref_frame_bufs,
117+ encode_frame_info.ref_frame_coding_indexes,
118+ encode_frame_info.ref_frame_valid_list);
119+
113120 ext_ratectrl->funcs.get_encodeframe_decision(
114121 ext_ratectrl->model, &encode_frame_info, encode_frame_decision);
115122 }
vp9/encoder/vp9_ext_ratectrl.h+4−2
@@ -33,8 +33,10 @@ void vp9_extrc_send_firstpass_stats(EXT_RATECTRL *ext_ratectrl, · 32 unmodified lines
3333 const FIRST_PASS_INFO *first_pass_info);
3434
3535 void vp9_extrc_get_encodeframe_decision(
36− EXT_RATECTRL *ext_ratectrl, const GF_GROUP *gf_group, int show_index,
37− int coding_index, vpx_rc_encodeframe_decision_t *encode_frame_decision);
36+ EXT_RATECTRL *ext_ratectrl, int show_index, int coding_index,
37+ FRAME_UPDATE_TYPE update_type,
38+ RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES], int ref_frame_flags,
39+ vpx_rc_encodeframe_decision_t *encode_frame_decision);
3840
3941 void vp9_extrc_update_encodeframe_result(EXT_RATECTRL *ext_ratectrl,
4042 int64_t bit_count,
vpx/vpx_ext_ratectrl.h+2−0
@@ -31,6 +31,8 @@ typedef struct vpx_rc_encodeframe_info { · 30 unmodified lines
3131 int frame_type;
3232 int show_index;
3333 int coding_index;
34+ int ref_frame_coding_indexes[3];
35+ int ref_frame_valid_list[3];
3436 } vpx_rc_encodeframe_info_t;
3537
3638 typedef struct vpx_rc_encodeframe_result {

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