[FFmpeg-soc] [soc]: r3522 - mlp/mlpenc.c
ramiro
subversion at mplayerhq.hu
Fri Aug 22 01:33:52 CEST 2008
Author: ramiro
Date: Fri Aug 22 01:33:52 2008
New Revision: 3522
Log:
Keep a DecodingParams struct for every subblock of frame.
Modified:
mlp/mlpenc.c
Modified: mlp/mlpenc.c
==============================================================================
--- mlp/mlpenc.c (original)
+++ mlp/mlpenc.c Fri Aug 22 01:33:52 2008
@@ -118,7 +118,7 @@ typedef struct {
ChannelParams channel_params[MAJOR_HEADER_INTERVAL][MAX_SUBBLOCKS][MAX_CHANNELS];
- DecodingParams decoding_params[MAJOR_HEADER_INTERVAL][MAX_SUBSTREAMS];
+ DecodingParams decoding_params[MAJOR_HEADER_INTERVAL][MAX_SUBBLOCKS][MAX_SUBSTREAMS];
RestartHeader restart_header [MAX_SUBSTREAMS];
DSPContext dsp;
@@ -413,9 +413,10 @@ static av_cold int mlp_encode_init(AVCod
for (index = 0; index < MAJOR_HEADER_INTERVAL; index++) {
- default_decoding_params(ctx, ctx->decoding_params[index]);
- for (subblock = 0; subblock < MAX_SUBBLOCKS; subblock++)
+ for (subblock = 0; subblock < MAX_SUBBLOCKS; subblock++) {
+ default_decoding_params(ctx, ctx->decoding_params[index][subblock]);
clear_channel_params(ctx->channel_params[index][subblock]);
+ }
}
dsputil_init(&ctx->dsp, avctx);
@@ -498,7 +499,7 @@ static void write_filter_params(MLPEncod
static void write_matrix_params(MLPEncodeContext *ctx, PutBitContext *pb,
unsigned int substr)
{
- DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][substr];
+ DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][ctx->subblock_index][substr];
unsigned int mat;
put_bits(pb, 4, dp->num_primitive_matrices);
@@ -532,7 +533,7 @@ static void write_matrix_params(MLPEncod
static void write_decoding_params(MLPEncodeContext *ctx, PutBitContext *pb,
unsigned int substr, int params_changed)
{
- DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][substr];
+ DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][ctx->subblock_index][substr];
RestartHeader *rh = &ctx->restart_header [substr];
unsigned int ch;
@@ -693,7 +694,7 @@ static void determine_quant_step_size(ML
RestartHeader *rh = &ctx->restart_header [substr];
int32_t *sample_buffer = ctx->sample_buffer;
int32_t sample_mask[MAX_CHANNELS];
- unsigned int channel, index;
+ unsigned int channel, index, subblock;
int i;
memset(sample_mask, 0x00, sizeof(sample_mask));
@@ -705,11 +706,13 @@ static void determine_quant_step_size(ML
sample_buffer += 2; /* noise channels */
}
+ for (subblock = 0; subblock < MAX_SUBBLOCKS; subblock++) {
for (index = 0; index < MAJOR_HEADER_INTERVAL; index++) {
- DecodingParams *dp = &ctx->decoding_params[index][substr];
+ DecodingParams *dp = &ctx->decoding_params[index][subblock][substr];
for (channel = 0; channel <= rh->max_channel; channel++)
dp->quant_step_size[channel] = number_trailing_zeroes(sample_mask[channel]);
}
+ }
}
static void copy_filter_params(FilterParams *dst, FilterParams *src)
@@ -787,7 +790,7 @@ static int apply_filter(MLPEncodeContext
FilterParams *fp[NUM_FILTERS] = { &ctx->channel_params[ctx->frame_index][1][channel].filter_params[FIR],
&ctx->channel_params[ctx->frame_index][1][channel].filter_params[IIR], };
int32_t filter_state_buffer[NUM_FILTERS][ctx->major_frame_size];
- int32_t mask = MSB_MASK(ctx->decoding_params[ctx->frame_index][substr].quant_step_size[channel]);
+ int32_t mask = MSB_MASK(ctx->decoding_params[ctx->frame_index][ctx->subblock_index][substr].quant_step_size[channel]);
int32_t *sample_buffer = ctx->sample_buffer + channel;
unsigned int major_frame_size = ctx->major_frame_size;
unsigned int filter_shift = fp[FIR]->shift;
@@ -859,9 +862,9 @@ static void generate_2_noise_channels(ML
* coefficients. Also shifts the coefficients to fit within 2.14 bits.
*/
static int code_matrix_coeffs(MLPEncodeContext *ctx,
- unsigned int substr, unsigned int index, unsigned int mat)
+ unsigned int substr, unsigned int index, unsigned int subblock, unsigned int mat)
{
- DecodingParams *dp = &ctx->decoding_params[index][substr];
+ DecodingParams *dp = &ctx->decoding_params[index][subblock][substr];
int32_t min = INT32_MAX, max = INT32_MIN;
int32_t coeff_mask = 0;
unsigned int channel;
@@ -905,12 +908,13 @@ static int code_matrix_coeffs(MLPEncodeC
/** Determines best coefficients to use for the lossless matrix. */
static void lossless_matrix_coeffs(MLPEncodeContext *ctx, unsigned int substr)
{
- unsigned int index;
+ unsigned int index, subblock;
generate_2_noise_channels(ctx, substr);
+ for (subblock = 0; subblock < MAX_SUBBLOCKS; subblock++) {
for (index = 0; index < MAJOR_HEADER_INTERVAL; index++) {
- DecodingParams *dp = &ctx->decoding_params[index][substr];
+ DecodingParams *dp = &ctx->decoding_params[index][subblock][substr];
/* TODO actual decorrelation. */
@@ -919,7 +923,8 @@ static void lossless_matrix_coeffs(MLPEn
dp->matrix_coeff[1][2] = 0 << 14;
dp->matrix_coeff[1][3] = 0 << 14;
- dp->num_primitive_matrices = code_matrix_coeffs(ctx, substr, index, 1);
+ dp->num_primitive_matrices = code_matrix_coeffs(ctx, substr, subblock, index, 1);
+ }
}
}
@@ -928,7 +933,7 @@ static void lossless_matrix_coeffs(MLPEn
*/
static void output_shift_channels(MLPEncodeContext *ctx, unsigned int substr)
{
- DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][substr];
+ DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][ctx->subblock_index][substr];
int32_t *sample_buffer = ctx->sample_buffer;
unsigned int i;
@@ -946,7 +951,7 @@ static void output_shift_channels(MLPEnc
/** Rematrixes all channels using chosen coefficients. */
static void rematrix_channels(MLPEncodeContext *ctx, unsigned int substr)
{
- DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][substr];
+ DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][ctx->subblock_index][substr];
int32_t *sample_buffer = ctx->sample_buffer;
unsigned int mat, i, maxchan;
@@ -996,7 +1001,7 @@ static void no_codebook_bits(MLPEncodeCo
BestOffset *bo)
{
ChannelParams *cp = &ctx->channel_params[ctx->frame_index][ctx->subblock_index][channel];
- DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][substr];
+ DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][ctx->subblock_index][substr];
int16_t offset;
int32_t unsign;
uint32_t diff;
@@ -1047,7 +1052,7 @@ static inline void codebook_bits_offset(
int32_t codebook_min = codebook_extremes[codebook][0];
int32_t codebook_max = codebook_extremes[codebook][1];
int32_t *sample_buffer = ctx->sample_buffer + channel;
- DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][substr];
+ DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][ctx->subblock_index][substr];
int codebook_offset = 7 + (2 - codebook);
int32_t unsign_offset = offset;
int lsb_bits = 0, bitcount = 0;
@@ -1151,7 +1156,7 @@ static inline void codebook_bits(MLPEnco
*/
static void determine_bits(MLPEncodeContext *ctx, unsigned int substr)
{
- DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][substr];
+ DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][ctx->subblock_index][substr];
RestartHeader *rh = &ctx->restart_header [substr];
unsigned int channel;
@@ -1205,7 +1210,7 @@ static void determine_bits(MLPEncodeCont
static void write_block_data(MLPEncodeContext *ctx, PutBitContext *pb,
unsigned int substr)
{
- DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][substr];
+ DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][ctx->subblock_index][substr];
RestartHeader *rh = &ctx->restart_header [substr];
int32_t *sample_buffer = ctx->sample_buffer;
int32_t sign_huff_offset[MAX_CHANNELS];
@@ -1306,7 +1311,7 @@ static int compare_decoding_params(MLPEn
ChannelParams channel_params[MAX_CHANNELS],
unsigned int substr)
{
- DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][substr];
+ DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][ctx->subblock_index][substr];
RestartHeader *rh = &ctx->restart_header [substr];
unsigned int ch;
int retval = 0;
@@ -1432,7 +1437,7 @@ static uint8_t *write_substrs(MLPEncodeC
for (substr = 0; substr < ctx->num_substreams; substr++) {
unsigned int subblock, num_subblocks = restart_frame;
- DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][substr];
+ DecodingParams *dp = &ctx->decoding_params[ctx->frame_index][ctx->subblock_index][substr];
RestartHeader *rh = &ctx->restart_header [substr];
int32_t *backup_sample_buffer;
uint8_t parity, checksum;
@@ -1452,11 +1457,14 @@ static uint8_t *write_substrs(MLPEncodeC
backup_sample_buffer = ctx->sample_buffer;
} else {
ctx->sample_buffer += ctx->num_channels * dp->blocksize;
- dp->blocksize = ctx->frame_size[ctx->frame_index] - dp->blocksize;
memcpy(channel_params, ctx->channel_params[ctx->frame_index][ctx->subblock_index], sizeof(ctx->channel_params[ctx->frame_index][ctx->subblock_index]));
ctx->subblock_index = 1;
+ dp = &ctx->decoding_params[ctx->frame_index][ctx->subblock_index][substr];
+
+ dp->blocksize = ctx->frame_size[ctx->frame_index] - 8;
+
restart_frame = 0;
}
} else {
@@ -1601,8 +1609,9 @@ static int mlp_encode_frame(AVCodecConte
ctx->next_major_frame_size = 0;
for (substr = 0; substr < ctx->num_substreams; substr++) {
+ for (subblock = 0; subblock < MAX_SUBBLOCKS; subblock++)
for (index = 0; index < MAJOR_HEADER_INTERVAL; index++) {
- DecodingParams *dp = &ctx->decoding_params[index][substr];
+ DecodingParams *dp = &ctx->decoding_params[index][subblock][substr];
dp->blocksize = ctx->frame_size[index];
}
lossless_matrix_coeffs (ctx, substr);
@@ -1617,7 +1626,7 @@ static int mlp_encode_frame(AVCodecConte
/* TODO Should these be a (DecodingParams *) in the context instead of
* memcpy'ing things around?
*/
- memcpy(decoding_params, ctx->decoding_params[ctx->prev_frame_index], sizeof(decoding_params));
+ memcpy(decoding_params, ctx->decoding_params[ctx->prev_frame_index][ctx->subblock_index], sizeof(decoding_params));
memcpy(channel_params, ctx->channel_params[ctx->prev_frame_index][ctx->subblock_index], sizeof(channel_params));
avctx->coded_frame->key_frame = 0;
More information about the FFmpeg-soc
mailing list