Commit a37ba46b authored by Josh Coalson's avatar Josh Coalson
Browse files

split off dynamically allocated stuff from...

split off dynamically allocated stuff from FLAC__EntropyCodingMethod_PartitionedRice to FLAC__EntropyCodingMethod_PartitionedRiceContent
parent 875b001f
......@@ -177,13 +177,10 @@ typedef enum {
extern const char * const FLAC__EntropyCodingMethodTypeString[];
/** Header for a Rice partition. (c.f. <A HREF="../format.html#partitioned_rice">format specification</A>)
/** Contents of a Rice partitioned residual
*/
typedef struct {
unsigned order;
/**< The partition order, i.e. # of contexts = 2 ^ \a order. */
unsigned *parameters;
/**< The Rice parameters for each context. */
......@@ -195,6 +192,18 @@ typedef struct {
* specified as an order, i.e. the number of array elements
* allocated is 2 ^ \a capacity_by_order.
*/
} FLAC__EntropyCodingMethod_PartitionedRiceContents;
/** Header for a Rice partitioned residual. (c.f. <A HREF="../format.html#partitioned_rice">format specification</A>)
*/
typedef struct {
unsigned order;
/**< The partition order, i.e. # of contexts = 2 ^ \a order. */
const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
/**< The context's Rice parameters and/or raw bits. */
} FLAC__EntropyCodingMethod_PartitionedRice;
extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
......
......@@ -76,9 +76,9 @@ void flac__analyze_frame(const FLAC__Frame *frame, unsigned frame_number, analys
if(aopts.do_residual_text) {
const unsigned partitions = (1u << subframe->data.fixed.entropy_coding_method.data.partitioned_rice.order);
for(i = 0; i < partitions; i++) {
unsigned parameter = subframe->data.fixed.entropy_coding_method.data.partitioned_rice.parameters[i];
unsigned parameter = subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents->parameters[i];
if(parameter == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER)
fprintf(fout, "\t\tparameter[%u]=ESCAPE, raw_bits=%u\n", i, subframe->data.fixed.entropy_coding_method.data.partitioned_rice.raw_bits[i]);
fprintf(fout, "\t\tparameter[%u]=ESCAPE, raw_bits=%u\n", i, subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents->raw_bits[i]);
else
fprintf(fout, "\t\tparameter[%u]=%u\n", i, parameter);
}
......@@ -93,9 +93,9 @@ void flac__analyze_frame(const FLAC__Frame *frame, unsigned frame_number, analys
if(aopts.do_residual_text) {
const unsigned partitions = (1u << subframe->data.lpc.entropy_coding_method.data.partitioned_rice.order);
for(i = 0; i < partitions; i++) {
unsigned parameter = subframe->data.lpc.entropy_coding_method.data.partitioned_rice.parameters[i];
unsigned parameter = subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents->parameters[i];
if(parameter == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER)
fprintf(fout, "\t\tparameter[%u]=ESCAPE, raw_bits=%u\n", i, subframe->data.lpc.entropy_coding_method.data.partitioned_rice.raw_bits[i]);
fprintf(fout, "\t\tparameter[%u]=ESCAPE, raw_bits=%u\n", i, subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents->raw_bits[i]);
else
fprintf(fout, "\t\tparameter[%u]=%u\n", i, parameter);
}
......
......@@ -234,17 +234,16 @@ unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_an
return max_rice_partition_order;
}
void FLAC__format_entropy_coding_method_partitioned_rice_init(FLAC__EntropyCodingMethod_PartitionedRice *object)
void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
{
FLAC__ASSERT(0 != object);
object->order = 0;
object->parameters = 0;
object->raw_bits = 0;
object->capacity_by_order = 0;
}
void FLAC__format_entropy_coding_method_partitioned_rice_clear(FLAC__EntropyCodingMethod_PartitionedRice *object)
void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
{
FLAC__ASSERT(0 != object);
......@@ -252,10 +251,10 @@ void FLAC__format_entropy_coding_method_partitioned_rice_clear(FLAC__EntropyCodi
free(object->parameters);
if(0 != object->raw_bits)
free(object->raw_bits);
FLAC__format_entropy_coding_method_partitioned_rice_init(object);
FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
}
FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_ensure_size(FLAC__EntropyCodingMethod_PartitionedRice *object, unsigned max_partition_order)
FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
{
FLAC__ASSERT(0 != object);
......
......@@ -25,8 +25,8 @@
unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
void FLAC__format_entropy_coding_method_partitioned_rice_init(FLAC__EntropyCodingMethod_PartitionedRice *object);
void FLAC__format_entropy_coding_method_partitioned_rice_clear(FLAC__EntropyCodingMethod_PartitionedRice *object);
FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_ensure_size(FLAC__EntropyCodingMethod_PartitionedRice *object, unsigned max_partition_order);
void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
#endif
......@@ -62,7 +62,7 @@ static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned
static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order);
static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order);
static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps);
static FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, FLAC__EntropyCodingMethod_PartitionedRice *partitioned_rice, FLAC__int32 *residual);
static FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual);
static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
static FLAC__bool read_callback_(FLAC__byte buffer[], unsigned *bytes, void *client_data);
......@@ -83,6 +83,7 @@ typedef struct FLAC__StreamDecoderPrivate {
FLAC__BitBuffer *input;
FLAC__int32 *output[FLAC__MAX_CHANNELS];
FLAC__int32 *residual[FLAC__MAX_CHANNELS];
FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
unsigned output_capacity, output_channels;
FLAC__uint32 last_frame_number;
FLAC__uint64 samples_decoded;
......@@ -93,7 +94,6 @@ typedef struct FLAC__StreamDecoderPrivate {
FLAC__byte *metadata_filter_ids;
unsigned metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
FLAC__Frame frame;
FLAC__EntropyCodingMethod_PartitionedRice allocated_ecm_pr;
FLAC__bool cached; /* true if there is a byte in lookahead */
FLAC__CPUInfo cpuinfo;
FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
......@@ -195,7 +195,9 @@ FLAC__StreamDecoder *FLAC__stream_decoder_new()
decoder->private_->output_capacity = 0;
decoder->private_->output_channels = 0;
decoder->private_->has_seek_table = false;
FLAC__format_entropy_coding_method_partitioned_rice_init(&decoder->private_->allocated_ecm_pr);
for(i = 0; i < FLAC__MAX_CHANNELS; i++)
FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
set_defaults_(decoder);
......@@ -206,6 +208,8 @@ FLAC__StreamDecoder *FLAC__stream_decoder_new()
void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
{
unsigned i;
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->protected_);
FLAC__ASSERT(0 != decoder->private_);
......@@ -218,7 +222,8 @@ void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
FLAC__bitbuffer_delete(decoder->private_->input);
FLAC__format_entropy_coding_method_partitioned_rice_clear(&decoder->private_->allocated_ecm_pr);
for(i = 0; i < FLAC__MAX_CHANNELS; i++)
FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
free(decoder->private_);
free(decoder->protected_);
......@@ -1641,6 +1646,7 @@ FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel,
if(!FLAC__bitbuffer_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN, read_callback_, decoder))
return false; /* the read_callback_ sets the state for us */
subframe->entropy_coding_method.data.partitioned_rice.order = u32;
subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
break;
default:
decoder->protected_->state = FLAC__STREAM_DECODER_UNPARSEABLE_STREAM;
......@@ -1650,7 +1656,7 @@ FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel,
/* read residual */
switch(subframe->entropy_coding_method.type) {
case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
if(!read_residual_partitioned_rice_(decoder, order, &subframe->entropy_coding_method.data.partitioned_rice, decoder->private_->residual[channel]))
if(!read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, &decoder->private_->partitioned_rice_contents[channel], decoder->private_->residual[channel]))
return false;
break;
default:
......@@ -1714,6 +1720,7 @@ FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, un
if(!FLAC__bitbuffer_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN, read_callback_, decoder))
return false; /* the read_callback_ sets the state for us */
subframe->entropy_coding_method.data.partitioned_rice.order = u32;
subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
break;
default:
decoder->protected_->state = FLAC__STREAM_DECODER_UNPARSEABLE_STREAM;
......@@ -1723,7 +1730,7 @@ FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, un
/* read residual */
switch(subframe->entropy_coding_method.type) {
case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
if(!read_residual_partitioned_rice_(decoder, order, &subframe->entropy_coding_method.data.partitioned_rice, decoder->private_->residual[channel]))
if(!read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, &decoder->private_->partitioned_rice_contents[channel], decoder->private_->residual[channel]))
return false;
break;
default:
......@@ -1762,27 +1769,24 @@ FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channe
return true;
}
FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, FLAC__EntropyCodingMethod_PartitionedRice *partitioned_rice, FLAC__int32 *residual)
FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual)
{
FLAC__uint32 rice_parameter;
int i;
unsigned partition, sample, u;
const unsigned partition_order = partitioned_rice->order;
const unsigned partitions = 1u << partition_order;
const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
if(!FLAC__format_entropy_coding_method_partitioned_rice_ensure_size(&decoder->private_->allocated_ecm_pr, max(6, partition_order))) {
if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
return false;
}
partitioned_rice->parameters = decoder->private_->allocated_ecm_pr.parameters;
partitioned_rice->raw_bits = decoder->private_->allocated_ecm_pr.raw_bits;
sample = 0;
for(partition = 0; partition < partitions; partition++) {
if(!FLAC__bitbuffer_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN, read_callback_, decoder))
return false; /* the read_callback_ sets the state for us */
partitioned_rice->parameters[partition] = rice_parameter;
partitioned_rice_contents->parameters[partition] = rice_parameter;
if(rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
#ifdef FLAC__SYMMETRIC_RICE
for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
......@@ -1800,7 +1804,7 @@ FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigne
else {
if(!FLAC__bitbuffer_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN, read_callback_, decoder))
return false; /* the read_callback_ sets the state for us */
partitioned_rice->raw_bits[partition] = rice_parameter;
partitioned_rice_contents->raw_bits[partition] = rice_parameter;
for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
if(!FLAC__bitbuffer_read_raw_int32(decoder->private_->input, &i, rice_parameter, read_callback_, decoder))
return false; /* the read_callback_ sets the state for us */
......
This diff is collapsed.
......@@ -283,7 +283,7 @@ FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsign
return false;
switch(subframe->entropy_coding_method.type) {
case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
if(!add_residual_partitioned_rice_(bb, subframe->residual, residual_samples, subframe->order, subframe->entropy_coding_method.data.partitioned_rice.parameters, subframe->entropy_coding_method.data.partitioned_rice.raw_bits, subframe->entropy_coding_method.data.partitioned_rice.order))
if(!add_residual_partitioned_rice_(bb, subframe->residual, residual_samples, subframe->order, subframe->entropy_coding_method.data.partitioned_rice.contents->parameters, subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits, subframe->entropy_coding_method.data.partitioned_rice.order))
return false;
break;
default:
......@@ -319,7 +319,7 @@ FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned r
return false;
switch(subframe->entropy_coding_method.type) {
case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
if(!add_residual_partitioned_rice_(bb, subframe->residual, residual_samples, subframe->order, subframe->entropy_coding_method.data.partitioned_rice.parameters, subframe->entropy_coding_method.data.partitioned_rice.raw_bits, subframe->entropy_coding_method.data.partitioned_rice.order))
if(!add_residual_partitioned_rice_(bb, subframe->residual, residual_samples, subframe->order, subframe->entropy_coding_method.data.partitioned_rice.contents->parameters, subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits, subframe->entropy_coding_method.data.partitioned_rice.order))
return false;
break;
default:
......
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