Commit 6cd141a9 authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

Split off end of RSI checking from m_id

parent ad908448
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
#endif #endif
#define ROS 5 #define ROS 5
#define RSI_USED(state) ((size_t)(state->rsip - state->rsi_buffer)) #define RSI_USED_SIZE(state) ((size_t)(state->rsip - state->rsi_buffer))
#define BUFFERSPACE(strm) (strm->avail_in >= strm->state->in_blklen \ #define BUFFERSPACE(strm) (strm->avail_in >= strm->state->in_blklen \
&& strm->avail_out >= strm->state->out_blklen) && strm->avail_out >= strm->state->out_blklen)
...@@ -386,34 +386,41 @@ static inline uint32_t copysample(struct aec_stream *strm) ...@@ -386,34 +386,41 @@ static inline uint32_t copysample(struct aec_stream *strm)
return 1; return 1;
} }
static int m_id(struct aec_stream *strm) static inline int m_id(struct aec_stream *strm)
{ {
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
if (strm->avail_in >= strm->state->in_blklen) {
state->id = direct_get(strm, state->id_len);
} else {
if (bits_ask(strm, state->id_len) == 0) {
state->mode = m_id;
return M_EXIT;
}
state->id = bits_get(strm, state->id_len);
bits_drop(strm, state->id_len);
}
state->mode = state->id_table[state->id];
return(state->mode(strm));
}
if (state->rsi_size == RSI_USED(state)) { static int m_next_cds(struct aec_stream *strm)
{
struct internal_state *state = strm->state;
if (state->rsi_size == RSI_USED_SIZE(state)) {
state->flush_output(strm); state->flush_output(strm);
state->flush_start = state->rsi_buffer; state->flush_start = state->rsi_buffer;
state->rsip = state->rsi_buffer; state->rsip = state->rsi_buffer;
}
if (state->rsip == state->rsi_buffer) {
if (strm->flags & AEC_PAD_RSI)
state->bitp -= state->bitp % 8;
if (state->pp) { if (state->pp) {
state->ref = 1; state->ref = 1;
state->encoded_block_size = strm->block_size - 1; state->encoded_block_size = strm->block_size - 1;
} }
if (strm->flags & AEC_PAD_RSI)
state->bitp -= state->bitp % 8;
} else { } else {
state->ref = 0; state->ref = 0;
state->encoded_block_size = strm->block_size; state->encoded_block_size = strm->block_size;
} }
return m_id(strm);
if (bits_ask(strm, state->id_len) == 0)
return M_EXIT;
state->id = bits_get(strm, state->id_len);
bits_drop(strm, state->id_len);
state->mode = state->id_table[state->id];
return M_CONTINUE;
} }
static int m_split_output(struct aec_stream *strm) static int m_split_output(struct aec_stream *strm)
...@@ -432,7 +439,7 @@ static int m_split_output(struct aec_stream *strm) ...@@ -432,7 +439,7 @@ static int m_split_output(struct aec_stream *strm)
bits_drop(strm, k); bits_drop(strm, k);
} while(++state->i < state->n); } while(++state->i < state->n);
state->mode = m_id; state->mode = m_next_cds;
return M_CONTINUE; return M_CONTINUE;
} }
...@@ -482,7 +489,7 @@ static int m_split(struct aec_stream *strm) ...@@ -482,7 +489,7 @@ static int m_split(struct aec_stream *strm)
} }
strm->avail_out -= state->out_blklen; strm->avail_out -= state->out_blklen;
state->mode = m_id; state->mode = m_next_cds;
} else { } else {
if (state->ref && (copysample(strm) == 0)) if (state->ref && (copysample(strm) == 0))
return M_EXIT; return M_EXIT;
...@@ -503,7 +510,7 @@ static int m_zero_output(struct aec_stream *strm) ...@@ -503,7 +510,7 @@ static int m_zero_output(struct aec_stream *strm)
put_sample(strm, 0); put_sample(strm, 0);
} while(--state->i); } while(--state->i);
state->mode = m_id; state->mode = m_next_cds;
return M_CONTINUE; return M_CONTINUE;
} }
...@@ -518,7 +525,7 @@ static int m_zero_block(struct aec_stream *strm) ...@@ -518,7 +525,7 @@ static int m_zero_block(struct aec_stream *strm)
fs_drop(strm); fs_drop(strm);
if (zero_blocks == ROS) { if (zero_blocks == ROS) {
b = (int)RSI_USED(state) / strm->block_size; b = (int)RSI_USED_SIZE(state) / strm->block_size;
zero_blocks = MIN(strm->rsi - b, 64 - (b % 64)); zero_blocks = MIN(strm->rsi - b, 64 - (b % 64));
} else if (zero_blocks > ROS) { } else if (zero_blocks > ROS) {
zero_blocks--; zero_blocks--;
...@@ -527,14 +534,14 @@ static int m_zero_block(struct aec_stream *strm) ...@@ -527,14 +534,14 @@ static int m_zero_block(struct aec_stream *strm)
i = zero_blocks * strm->block_size - state->ref; i = zero_blocks * strm->block_size - state->ref;
zero_bytes = i * state->bytes_per_sample; zero_bytes = i * state->bytes_per_sample;
if (state->rsi_size - RSI_USED(state) < i) if (state->rsi_size - RSI_USED_SIZE(state) < i)
return M_ERROR; return M_ERROR;
if (strm->avail_out >= zero_bytes) { if (strm->avail_out >= zero_bytes) {
memset(state->rsip, 0, i * sizeof(uint32_t)); memset(state->rsip, 0, i * sizeof(uint32_t));
state->rsip += i; state->rsip += i;
strm->avail_out -= zero_bytes; strm->avail_out -= zero_bytes;
state->mode = m_id; state->mode = m_next_cds;
return M_CONTINUE; return M_CONTINUE;
} }
...@@ -570,7 +577,7 @@ static int m_se_decode(struct aec_stream *strm) ...@@ -570,7 +577,7 @@ static int m_se_decode(struct aec_stream *strm)
fs_drop(strm); fs_drop(strm);
} }
state->mode = m_id; state->mode = m_next_cds;
return M_CONTINUE; return M_CONTINUE;
} }
...@@ -599,7 +606,7 @@ static int m_se(struct aec_stream *strm) ...@@ -599,7 +606,7 @@ static int m_se(struct aec_stream *strm)
put_sample(strm, d1); put_sample(strm, d1);
i++; i++;
} }
state->mode = m_id; state->mode = m_next_cds;
} else { } else {
state->mode = m_se_decode; state->mode = m_se_decode;
state->i = state->ref; state->i = state->ref;
...@@ -644,7 +651,7 @@ static int m_uncomp_copy(struct aec_stream *strm) ...@@ -644,7 +651,7 @@ static int m_uncomp_copy(struct aec_stream *strm)
return M_EXIT; return M_EXIT;
} while(--state->i); } while(--state->i);
state->mode = m_id; state->mode = m_next_cds;
return M_CONTINUE; return M_CONTINUE;
} }
...@@ -657,7 +664,7 @@ static int m_uncomp(struct aec_stream *strm) ...@@ -657,7 +664,7 @@ static int m_uncomp(struct aec_stream *strm)
for (i = 0; i < strm->block_size; i++) for (i = 0; i < strm->block_size; i++)
*state->rsip++ = direct_get(strm, strm->bits_per_sample); *state->rsip++ = direct_get(strm, strm->bits_per_sample);
strm->avail_out -= state->out_blklen; strm->avail_out -= state->out_blklen;
state->mode = m_id; state->mode = m_next_cds;
} else { } else {
state->i = strm->block_size; state->i = strm->block_size;
state->mode = m_uncomp_copy; state->mode = m_uncomp_copy;
...@@ -770,8 +777,13 @@ int aec_decode_init(struct aec_stream *strm) ...@@ -770,8 +777,13 @@ int aec_decode_init(struct aec_stream *strm)
return AEC_MEM_ERROR; return AEC_MEM_ERROR;
state->pp = strm->flags & AEC_DATA_PREPROCESS; state->pp = strm->flags & AEC_DATA_PREPROCESS;
state->ref = 0; if (state->pp) {
state->encoded_block_size = strm->block_size; state->ref = 1;
state->encoded_block_size = strm->block_size - 1;
} else {
state->ref = 0;
state->encoded_block_size = strm->block_size;
}
strm->total_in = 0; strm->total_in = 0;
strm->total_out = 0; strm->total_out = 0;
......
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