Commit bc5254df authored by Mathis Rosenhauer's avatar Mathis Rosenhauer Committed by Thomas Jahns

Avoid double zero-checking block after zero blocks

parent 90e25ec4
......@@ -425,6 +425,31 @@ static int assess_se_option(uint64_t limit, struct aec_stream *strm)
return len;
}
static void init_output(struct aec_stream *strm)
{
/**
Direct output to next_out if next_out can hold a Coded Data
Set, use internal buffer otherwise.
*/
struct internal_state *state = strm->state;
if (strm->avail_out > state->cds_len) {
if (!state->direct_out) {
state->direct_out = 1;
*strm->next_out = *state->cds;
state->cds = strm->next_out;
}
} else {
if (state->zero_blocks == 0 || state->direct_out) {
/* copy leftover from last block */
*state->cds_buf = *state->cds;
state->cds = state->cds_buf;
}
state->direct_out = 0;
}
}
/*
*
* FSM functions
......@@ -596,10 +621,9 @@ static int m_check_zero_block(struct aec_stream *strm)
if (state->zero_blocks) {
/* The current block isn't zero but we have to emit a
* previous zero block first. The current block will be
* handled later.
* flagged and handled later.
*/
state->block -= strm->block_size;
state->blocks_avail++;
state->block_nonzero = 1;
state->mode = m_encode_zero;
return M_CONTINUE;
}
......@@ -682,19 +706,12 @@ static int m_get_block(struct aec_stream *strm)
struct internal_state *state = strm->state;
if (strm->avail_out > state->cds_len) {
if (!state->direct_out) {
state->direct_out = 1;
*strm->next_out = *state->cds;
state->cds = strm->next_out;
}
} else {
if (state->zero_blocks == 0 || state->direct_out) {
/* copy leftover from last block */
*state->cds_buf = *state->cds;
state->cds = state->cds_buf;
}
state->direct_out = 0;
init_output(strm);
if (state->block_nonzero) {
state->block_nonzero = 0;
state->mode = m_select_code_option;
return M_CONTINUE;
}
if (state->blocks_avail == 0) {
......
......@@ -95,6 +95,8 @@ struct internal_state {
int zero_ref; /* current zero block has a reference sample */
int64_t zero_ref_sample;/* reference sample of zero block */
int zero_blocks; /* number of contiguous zero blocks */
int block_nonzero; /* 1 if this is the first non-zero block
* after one or more zero blocks */
int k; /* splitting position */
int kmax; /* maximum number for k depending on id_len */
int flush; /* flush option copied from argument */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment