Factor out a function for building ref lists.

The code for building the reference picture lists was duplicated in
functions encoder_state_ref_sort and print_frame_info. This commit moves
it to a new function kvz_encoder_get_ref_lists. Also makes
encoder_ref_insertion_sort static since it is not used outside the
encoderstate module any more.
This commit is contained in:
Arttu Ylä-Outinen 2015-09-09 10:01:02 +03:00
parent c856a6b598
commit d5dceb45f1
3 changed files with 48 additions and 30 deletions

View file

@ -364,28 +364,19 @@ void print_frame_info(encoder_state_t *state, double frame_psnr[3])
"BPI"[state->global->slicetype % 3], state->stats_bitstream_length << 3,
frame_psnr[0], frame_psnr[1], frame_psnr[2]);
// Print reference picture lists
if (state->global->slicetype != KVZ_SLICE_I) {
int j, ref_list[2] = { 0, 0 }, ref_list_poc[2][16];
// List all pocs of lists
for (j = 0; j < state->global->ref->used_size; j++) {
if (state->global->ref->pocs[j] < state->global->poc) {
ref_list_poc[0][ref_list[0]] = state->global->ref->pocs[j];
ref_list[0]++;
} else {
ref_list_poc[1][ref_list[1]] = state->global->ref->pocs[j];
ref_list[1]++;
}
}
kvz_encoder_ref_insertion_sort(ref_list_poc[0], ref_list[0]);
kvz_encoder_ref_insertion_sort(ref_list_poc[1], ref_list[1]);
// Print reference picture lists
int ref_list_len[2];
int ref_list_poc[2][16];
kvz_encoder_get_ref_lists(state, ref_list_len, ref_list_poc);
fprintf(stderr, " [L0 ");
for (j = ref_list[0] - 1; j >= 0; j--) {
for (int j = ref_list_len[0] - 1; j >= 0; j--) {
fprintf(stderr, "%d ", ref_list_poc[0][j]);
}
fprintf(stderr, "] [L1 ");
for (j = 0; j < ref_list[1]; j++) {
for (int j = 0; j < ref_list_len[1]; j++) {
fprintf(stderr, "%d ", ref_list_poc[1][j]);
}
fprintf(stderr, "]");

View file

@ -629,7 +629,7 @@ static void encoder_state_encode(encoder_state_t * const main_state) {
}
void kvz_encoder_ref_insertion_sort(int reflist[16], int length) {
static void encoder_ref_insertion_sort(int reflist[16], int length) {
for (uint8_t i = 1; i < length; ++i) {
const int16_t cur_poc = reflist[i];
@ -641,35 +641,60 @@ void kvz_encoder_ref_insertion_sort(int reflist[16], int length) {
reflist[j] = cur_poc;
}
}
static void encoder_state_ref_sort(encoder_state_t *state) {
int j, ref_list[2] = { 0, 0 }, ref_list_poc[2][16];
/**
* \brief Return reference picture lists.
*
* \param state main encoder state
* \param ref_list_len_out Returns the lengths of the reference lists.
* \param ref_list_poc_out Returns two lists of POCs of the reference pictures.
*/
void kvz_encoder_get_ref_lists(const encoder_state_t *const state,
int ref_list_len_out[2],
int ref_list_poc_out[2][16])
{
FILL_ARRAY(ref_list_len_out, 0, 2);
// List all pocs of lists
int j = 0;
for (j = 0; j < state->global->ref->used_size; j++) {
if (state->global->ref->pocs[j] < state->global->poc) {
ref_list_poc[0][ref_list[0]] = state->global->ref->pocs[j];
ref_list[0]++;
ref_list_poc_out[0][ref_list_len_out[0]] = state->global->ref->pocs[j];
ref_list_len_out[0]++;
} else {
ref_list_poc[1][ref_list[1]] = state->global->ref->pocs[j];
ref_list[1]++;
ref_list_poc_out[1][ref_list_len_out[1]] = state->global->ref->pocs[j];
ref_list_len_out[1]++;
}
}
kvz_encoder_ref_insertion_sort(ref_list_poc[0], ref_list[0]);
kvz_encoder_ref_insertion_sort(ref_list_poc[1], ref_list[1]);
// Fill the rest of ref_list_poc_out array with -1s.
for (; j < 16; j++) {
ref_list_poc_out[0][j] = -1;
ref_list_poc_out[1][j] = -1;
}
for (j = 0; j < state->global->ref->used_size; j++) {
encoder_ref_insertion_sort(ref_list_poc_out[0], ref_list_len_out[0]);
encoder_ref_insertion_sort(ref_list_poc_out[1], ref_list_len_out[1]);
}
static void encoder_state_ref_sort(encoder_state_t *state) {
int ref_list_len[2];
int ref_list_poc[2][16];
kvz_encoder_get_ref_lists(state, ref_list_len, ref_list_poc);
for (int j = 0; j < state->global->ref->used_size; j++) {
if (state->global->ref->pocs[j] < state->global->poc) {
for (int ref_idx = 0; ref_idx < ref_list[0]; ref_idx++) {
for (int ref_idx = 0; ref_idx < ref_list_len[0]; ref_idx++) {
if (ref_list_poc[0][ref_idx] == state->global->ref->pocs[j]) {
state->global->refmap[j].idx = ref_list[0] - ref_idx - 1;
state->global->refmap[j].idx = ref_list_len[0] - ref_idx - 1;
break;
}
}
state->global->refmap[j].list = 1;
} else {
for (int ref_idx = 0; ref_idx < ref_list[1]; ref_idx++) {
for (int ref_idx = 0; ref_idx < ref_list_len[1]; ref_idx++) {
if (ref_list_poc[1][ref_idx] == state->global->ref->pocs[j]) {
state->global->refmap[j].idx = ref_idx;
break;

View file

@ -228,7 +228,9 @@ int kvz_encoder_state_match_children_of_previous_frame(encoder_state_t * const s
coeff_scan_order_t kvz_get_scan_order(int8_t cu_type, int intra_mode, int depth);
void kvz_encoder_ref_insertion_sort(int reflist[16], int length);
void kvz_encoder_get_ref_lists(const encoder_state_t *const state,
int ref_list_len_out[2],
int ref_list_poc_out[2][16]);
static const uint8_t g_group_idx[32] = {
0, 1, 2, 3, 4, 4, 5, 5, 6, 6,