diff --git a/src/encoder.c b/src/encoder.c index 87399703..5316c855 100644 --- a/src/encoder.c +++ b/src/encoder.c @@ -28,6 +28,7 @@ #include "cfg.h" #include "strategyselector.h" +#include "kvz_math.h" /** @@ -237,6 +238,8 @@ encoder_control_t* kvz_encoder_control_init(const kvz_config *const cfg) } } + encoder->poc_lsb_bits = MAX(4, kvz_math_ceil_log2(encoder->cfg.gop_len * 2 + 1)); + encoder->max_inter_ref_lcu.right = 1; encoder->max_inter_ref_lcu.down = 1; diff --git a/src/encoder.h b/src/encoder.h index 87896e29..57acdf74 100644 --- a/src/encoder.h +++ b/src/encoder.h @@ -133,6 +133,8 @@ typedef struct encoder_control_t int down; } max_inter_ref_lcu; + int32_t poc_lsb_bits; + } encoder_control_t; encoder_control_t* kvz_encoder_control_init(const kvz_config *cfg); diff --git a/src/encoder_state-bitstream.c b/src/encoder_state-bitstream.c index 483a22dc..94509f3c 100644 --- a/src/encoder_state-bitstream.c +++ b/src/encoder_state-bitstream.c @@ -377,7 +377,8 @@ static void encoder_state_write_bitstream_seq_parameter_set(bitstream_t* stream, WRITE_UE(stream, encoder->bitdepth-8, "bit_depth_luma_minus8"); WRITE_UE(stream, encoder->bitdepth-8, "bit_depth_chroma_minus8"); - WRITE_UE(stream, 1, "log2_max_pic_order_cnt_lsb_minus4"); + WRITE_UE(stream, encoder->poc_lsb_bits - 4, "log2_max_pic_order_cnt_lsb_minus4"); + WRITE_U(stream, 0, 1, "sps_sub_layer_ordering_info_present_flag"); //for each layer @@ -715,16 +716,18 @@ static void kvz_encoder_state_write_bitstream_slice_header_independent( if (state->frame->pictype != KVZ_NAL_IDR_W_RADL && state->frame->pictype != KVZ_NAL_IDR_N_LP) { + const int poc_lsb = state->frame->poc & ((1 << encoder->poc_lsb_bits) - 1); + WRITE_U(stream, poc_lsb, encoder->poc_lsb_bits, "pic_order_cnt_lsb"); + int last_poc = 0; int poc_shift = 0; - WRITE_U(stream, state->frame->poc&0x1f, 5, "pic_order_cnt_lsb"); - WRITE_U(stream, 0, 1, "short_term_ref_pic_set_sps_flag"); - WRITE_UE(stream, ref_negative, "num_negative_pics"); - WRITE_UE(stream, ref_positive, "num_positive_pics"); - for (j = 0; j < ref_negative; j++) { + WRITE_U(stream, 0, 1, "short_term_ref_pic_set_sps_flag"); + WRITE_UE(stream, ref_negative, "num_negative_pics"); + WRITE_UE(stream, ref_positive, "num_positive_pics"); + for (j = 0; j < ref_negative; j++) { int8_t delta_poc = 0; - + if (encoder->cfg.gop_len) { int8_t found = 0; do {