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
72 72
73 if (encode_frame_info->coding_index == 0) {73 if (encode_frame_info->coding_index == 0) {
74 EXPECT_EQ(encode_frame_info->frame_type, 0 /*kFrameTypeKey*/);74 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
75 }81 }
76 82
77 if (encode_frame_info->coding_index == 1) {83 if (encode_frame_info->coding_index == 1) {
78 EXPECT_EQ(encode_frame_info->frame_type, 2 /*kFrameTypeAltRef*/);84 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
79 }93 }
80 94
81 if (encode_frame_info->coding_index >= 2 &&95 if (encode_frame_info->coding_index >= 2 &&
@@ -85,6 +99,18 @@ vpx_rc_status_t rc_get_encodeframe_decision( · 3 unmodified lines
85 99
86 if (encode_frame_info->coding_index == 5) {100 if (encode_frame_info->coding_index == 5) {
87 EXPECT_EQ(encode_frame_info->frame_type, 3 /*kFrameTypeOverlay*/);101 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
88 }114 }
89 if (encode_frame_info->coding_index == kLosslessCodingIndex) {115 if (encode_frame_info->coding_index == kLosslessCodingIndex) {
90 // We should get sse == 0 at rc_update_encodeframe_result()116 // 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
75 75
76 // TODO(angiebird): Set frame_index/frame_coding_index on the decoder side76 // TODO(angiebird): Set frame_index/frame_coding_index on the decoder side
77 // properly.77 // properly.
78 int frame_index; // Display order in the video, it's equivalent to the78 int frame_index; // Display order in the video, it's equivalent to the
79 // show_idx defined in EncodeFrameInfo.79 // show_idx defined in EncodeFrameInfo.
80#if CONFIG_RATE_CTRL
81 int frame_coding_index; // The coding order (starting from zero) of this80 int frame_coding_index; // The coding order (starting from zero) of this
82 // frame.81 // frame.
83#endif // CONFIG_RATE_CTRL
84 vpx_codec_frame_buffer_t raw_frame_buffer;82 vpx_codec_frame_buffer_t raw_frame_buffer;
85 YV12_BUFFER_CONFIG buf;83 YV12_BUFFER_CONFIG buf;
86} RefCntBuffer;84} 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
4205 return 1;4205 return 1;
4206}4206}
4207 4207
4208static 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
4208#if !CONFIG_REALTIME_ONLY4229#if !CONFIG_REALTIME_ONLY
4209#define MAX_QSTEP_ADJ 44230#define MAX_QSTEP_ADJ 4
4210static int get_qstep_adj(int rate_excess, int rate_limit) {4231static 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
4481 if (cpi->ext_ratectrl.ready) {4502 if (cpi->ext_ratectrl.ready) {
4482 const GF_GROUP *gf_group = &cpi->twopass.gf_group;4503 const GF_GROUP *gf_group = &cpi->twopass.gf_group;
4483 vpx_rc_encodeframe_decision_t encode_frame_decision;4504 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);
4484 vp9_extrc_get_encodeframe_decision(4509 vp9_extrc_get_encodeframe_decision(
4485 &cpi->ext_ratectrl, gf_group, cm->current_video_frame,4510 &cpi->ext_ratectrl, cm->current_video_frame,
4486 cm->current_frame_coding_index, &encode_frame_decision);4511 cm->current_frame_coding_index, update_type, ref_frame_bufs,
4512 ref_frame_flags, &encode_frame_decision);
4487 q = encode_frame_decision.q_index;4513 q = encode_frame_decision.q_index;
4488 }4514 }
4489 4515
@@ -4772,27 +4798,6 @@ static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest · 282 unmodified lines
4772}4798}
4773#endif // !CONFIG_REALTIME_ONLY4799#endif // !CONFIG_REALTIME_ONLY
4774 4800
4775static 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
4796static void set_ext_overrides(VP9_COMP *cpi) {4801static void set_ext_overrides(VP9_COMP *cpi) {
4797 // Overrides the defaults with the externally supplied values with4802 // Overrides the defaults with the externally supplied values with
4798 // vp9_update_reference() and vp9_update_entropy() calls4803 // 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
5097 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;5102 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
5098 ref_buffer->frame_index =5103 ref_buffer->frame_index =
5099 cm->current_video_frame + gf_group->arf_src_offset[gf_group->index];5104 cm->current_video_frame + gf_group->arf_src_offset[gf_group->index];
5100#if CONFIG_RATE_CTRL
5101 ref_buffer->frame_coding_index = cm->current_frame_coding_index;5105 ref_buffer->frame_coding_index = cm->current_frame_coding_index;
5102#endif // CONFIG_RATE_CTRL
5103 }5106 }
5104}5107}
5105 5108
@@ -7391,6 +7394,30 @@ static void setup_tpl_stats(VP9_COMP *cpi) { · 2285 unmodified lines
7391#endif // CONFIG_NON_GREEDY_MV7394#endif // CONFIG_NON_GREEDY_MV
7392}7395}
7393 7396
7397void 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
7394#if !CONFIG_REALTIME_ONLY7421#if !CONFIG_REALTIME_ONLY
7395#if CONFIG_RATE_CTRL7422#if CONFIG_RATE_CTRL
7396static void copy_frame_counts(const FRAME_COUNTS *input_counts,7423static 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
7538 }7565 }
7539}7566}
7540#endif // CONFIG_RATE_CTRL7567#endif // CONFIG_RATE_CTRL
7568
7541static void update_encode_frame_result(7569static void update_encode_frame_result(
7542 int ref_frame_flags, FRAME_UPDATE_TYPE update_type,7570 int ref_frame_flags, FRAME_UPDATE_TYPE update_type,
7543 const YV12_BUFFER_CONFIG *source_frame, const RefCntBuffer *coded_frame_buf,7571 const YV12_BUFFER_CONFIG *source_frame, const RefCntBuffer *coded_frame_buf,
@@ -7560,26 +7588,10 @@ static void update_encode_frame_result( · 16 unmodified lines
7560#endif // CONFIG_VP9_HIGHBITDEPTH7588#endif // CONFIG_VP9_HIGHBITDEPTH
7561 encode_frame_result->frame_coding_index = coded_frame_buf->frame_coding_index;7589 encode_frame_result->frame_coding_index = coded_frame_buf->frame_coding_index;
7562 7590
7563 if (update_type != KF_UPDATE) {7591 vp9_get_ref_frame_info(update_type, ref_frame_flags, ref_frame_bufs,
7564 const VP9_REFFRAME inter_ref_flags[MAX_INTER_REF_FRAMES] = { VP9_LAST_FLAG,7592 encode_frame_result->ref_frame_coding_indexes,
7565 VP9_GOLD_FLAG,7593 encode_frame_result->ref_frame_valid_list);
7566 VP9_ALT_FLAG };7594
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 }
7583 encode_frame_result->psnr = psnr.psnr[0];7595 encode_frame_result->psnr = psnr.psnr[0];
7584 encode_frame_result->sse = psnr.sse[0];7596 encode_frame_result->sse = psnr.sse[0];
7585 copy_frame_counts(counts, &encode_frame_result->frame_counts);7597 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
1268 1268
1269void vp9_update_reference_frames(VP9_COMP *cpi);1269void vp9_update_reference_frames(VP9_COMP *cpi);
1270 1270
1271void 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
1271void vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv);1276void vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv);
1272 1277
1273YV12_BUFFER_CONFIG *vp9_svc_twostage_scale(1278YV12_BUFFER_CONFIG *vp9_svc_twostage_scale(
vp9/encoder/vp9_ext_ratectrl.c+10−3
@@ -9,6 +9,7 @@ · 8 unmodified lines
9 */9 */
10 10
11#include "vp9/encoder/vp9_ext_ratectrl.h"11#include "vp9/encoder/vp9_ext_ratectrl.h"
12#include "vp9/encoder/vp9_encoder.h"
12#include "vp9/common/vp9_common.h"13#include "vp9/common/vp9_common.h"
13#include "vpx_dsp/psnr.h"14#include "vpx_dsp/psnr.h"
14 15
@@ -102,14 +103,20 @@ static int extrc_get_frame_type(FRAME_UPDATE_TYPE update_type) { · 87 unmodified lines
102}103}
103 104
104void vp9_extrc_get_encodeframe_decision(105void vp9_extrc_get_encodeframe_decision(
105 EXT_RATECTRL *ext_ratectrl, const GF_GROUP *gf_group, int show_index,106 EXT_RATECTRL *ext_ratectrl, int show_index, int coding_index,
106 int coding_index, vpx_rc_encodeframe_decision_t *encode_frame_decision) {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) {
107 if (ext_ratectrl->ready) {110 if (ext_ratectrl->ready) {
108 FRAME_UPDATE_TYPE update_type = gf_group->update_type[gf_group->index];
109 vpx_rc_encodeframe_info_t encode_frame_info;111 vpx_rc_encodeframe_info_t encode_frame_info;
110 encode_frame_info.show_index = show_index;112 encode_frame_info.show_index = show_index;
111 encode_frame_info.coding_index = coding_index;113 encode_frame_info.coding_index = coding_index;
112 encode_frame_info.frame_type = extrc_get_frame_type(update_type);114 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
113 ext_ratectrl->funcs.get_encodeframe_decision(120 ext_ratectrl->funcs.get_encodeframe_decision(
114 ext_ratectrl->model, &encode_frame_info, encode_frame_decision);121 ext_ratectrl->model, &encode_frame_info, encode_frame_decision);
115 }122 }
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
33 const FIRST_PASS_INFO *first_pass_info);33 const FIRST_PASS_INFO *first_pass_info);
34 34
35void vp9_extrc_get_encodeframe_decision(35void vp9_extrc_get_encodeframe_decision(
36 EXT_RATECTRL *ext_ratectrl, const GF_GROUP *gf_group, int show_index,36 EXT_RATECTRL *ext_ratectrl, int show_index, int coding_index,
37 int coding_index, vpx_rc_encodeframe_decision_t *encode_frame_decision);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);
38 40
39void vp9_extrc_update_encodeframe_result(EXT_RATECTRL *ext_ratectrl,41void vp9_extrc_update_encodeframe_result(EXT_RATECTRL *ext_ratectrl,
40 int64_t bit_count,42 int64_t bit_count,
vpx/vpx_ext_ratectrl.h+2−0
@@ -31,6 +31,8 @@ typedef struct vpx_rc_encodeframe_info { · 30 unmodified lines
31 int frame_type;31 int frame_type;
32 int show_index;32 int show_index;
33 int coding_index;33 int coding_index;
34 int ref_frame_coding_indexes[3];
35 int ref_frame_valid_list[3];
34} vpx_rc_encodeframe_info_t;36} vpx_rc_encodeframe_info_t;
35 37
36typedef struct vpx_rc_encodeframe_result {38typedef 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