Skip to content

Commit

Permalink
Fix a bug when requesting encoder_headers before any frame has been p…
Browse files Browse the repository at this point in the history
…ushed in, Fixes #360

 - state->frame->max_qp_delta_depth was uninitialized and caused different PPS to be outputted than after pushing frames in
 - Caused problems e.g. in FFmpeg integration where the requested PPS was pushed to MP4 headers and causing decoding errors in some decoders
  • Loading branch information
fador committed Jul 3, 2023
1 parent 7385741 commit aaae5b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/encoder_state-bitstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ static void encoder_state_write_bitstream_pic_parameter_set(bitstream_t* stream,
WRITE_U(stream, 0, 1, "constrained_intra_pred_flag");
WRITE_U(stream, encoder->cfg.trskip_enable, 1, "transform_skip_enabled_flag");

if (state->frame->max_qp_delta_depth >= 0) {
// Check all the conditions for setting cu_qp_delta_enabled_flag here, since state->frame->max_qp_delta_depth might not be set yet.
if (encoder->cfg.target_bitrate > 0 || encoder->cfg.erp_aqp || encoder->cfg.roi.file_path ||
encoder->cfg.set_qp_in_cu || encoder->cfg.vaq || (state->tile->frame->source && state->tile->frame->source->roi.roi_array) ) {
// Use separate QP for each LCU when rate control is enabled.
WRITE_U(stream, 1, 1, "cu_qp_delta_enabled_flag");
WRITE_UE(stream, state->frame->max_qp_delta_depth, "diff_cu_qp_delta_depth");
Expand Down
3 changes: 3 additions & 0 deletions src/encoder_state-ctors_dtors.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ static int encoder_state_config_frame_init(encoder_state_t * const state) {
state->frame->rc_beta = -1.367;
state->frame->icost = 0;

// Reset max_qp_delta_depth here, was causing problems when headers are requested before input is fed in
state->frame->max_qp_delta_depth = 0;

const encoder_control_t * const encoder = state->encoder_control;
const int num_lcus = encoder->in.width_in_lcu * encoder->in.height_in_lcu;
state->frame->lcu_stats = calloc(num_lcus, sizeof(lcu_stats_t));
Expand Down

0 comments on commit aaae5b0

Please sign in to comment.