[FFmpeg-soc] [soc]: r3633 - mlp/mlpenc.c

ramiro subversion at mplayerhq.hu
Wed Aug 27 02:13:06 CEST 2008


Author: ramiro
Date: Wed Aug 27 02:13:06 2008
New Revision: 3633

Log:
Don't use double the memory for subblocks.

Modified:
   mlp/mlpenc.c

Modified: mlp/mlpenc.c
==============================================================================
--- mlp/mlpenc.c	(original)
+++ mlp/mlpenc.c	Wed Aug 27 02:13:06 2008
@@ -87,9 +87,6 @@ typedef struct BestOffset {
 #define HUFF_OFFSET_MIN    -16384
 #define HUFF_OFFSET_MAX     16383
 
-/** Maximum number of subblocks this implementation of the encoder uses. */
-#define MAX_SUBBLOCKS       2
-
 /** Number of possible codebooks (counting "no codebooks") */
 #define NUM_CODEBOOKS       4
 
@@ -133,16 +130,16 @@ typedef struct {
     uint8_t         mlp_channels3;  /**< TODO unknown channel-related field
                                      *   These values are correct for mono and stereo. */
 
-    ChannelParams   channel_params[MAJOR_HEADER_INTERVAL][MAJOR_HEADER_INTERVAL][MAJOR_HEADER_INTERVAL][MAX_SUBBLOCKS][MAX_CHANNELS];
+    ChannelParams   channel_params[MAJOR_HEADER_INTERVAL][MAJOR_HEADER_INTERVAL][MAJOR_HEADER_INTERVAL+1][MAX_CHANNELS];
 
-    BestOffset      best_offset[MAJOR_HEADER_INTERVAL][MAJOR_HEADER_INTERVAL][MAJOR_HEADER_INTERVAL][MAX_SUBBLOCKS][MAX_CHANNELS][NUM_CODEBOOKS];
+    BestOffset      best_offset[MAJOR_HEADER_INTERVAL][MAJOR_HEADER_INTERVAL][MAJOR_HEADER_INTERVAL+1][MAX_CHANNELS][NUM_CODEBOOKS];
 
-    DecodingParams  decoding_params[MAJOR_HEADER_INTERVAL][MAJOR_HEADER_INTERVAL][MAJOR_HEADER_INTERVAL][MAX_SUBBLOCKS][MAX_SUBSTREAMS];
+    DecodingParams  decoding_params[MAJOR_HEADER_INTERVAL][MAJOR_HEADER_INTERVAL][MAJOR_HEADER_INTERVAL+1][MAX_SUBSTREAMS];
     RestartHeader   restart_header [MAX_SUBSTREAMS];
 
-    ChannelParams   major_channel_params[MAJOR_HEADER_INTERVAL][MAX_SUBBLOCKS][MAX_CHANNELS];       ///< ChannelParams to be written to bitstream.
-    DecodingParams  major_decoding_params[MAJOR_HEADER_INTERVAL][MAX_SUBBLOCKS][MAX_SUBSTREAMS];    ///< DecodingParams to be written to bitstream.
-    int             major_params_changed[MAJOR_HEADER_INTERVAL][MAX_SUBBLOCKS][MAX_SUBSTREAMS];     ///< params_changed to be written to bitstream.
+    ChannelParams   major_channel_params[MAJOR_HEADER_INTERVAL+1][MAX_CHANNELS];       ///< ChannelParams to be written to bitstream.
+    DecodingParams  major_decoding_params[MAJOR_HEADER_INTERVAL+1][MAX_SUBSTREAMS];    ///< DecodingParams to be written to bitstream.
+    int             major_params_changed[MAJOR_HEADER_INTERVAL+1][MAX_SUBSTREAMS];     ///< params_changed to be written to bitstream.
 
     BestOffset    (*cur_best_offset)[NUM_CODEBOOKS];
     ChannelParams  *cur_channel_params;
@@ -338,14 +335,14 @@ static void copy_restart_frame_params(ML
 {
     unsigned int index;
 
-    for (index = 0; index < ctx->number_of_frames; index++) {
-        DecodingParams *dp = &ctx->decoding_params[ctx->seq_index][ctx->frame_index][index][0][substr];
+    for (index = 0; index < ctx->number_of_frames + 1; index++) {
+        DecodingParams *dp = &ctx->decoding_params[ctx->seq_index][ctx->frame_index][index][substr];
         unsigned int channel;
 
         copy_matrix_params(&dp->matrix_params, &ctx->cur_decoding_params->matrix_params);
 
         for (channel = 0; channel < MAX_CHANNELS; channel++) {
-            ChannelParams *cp = &ctx->channel_params[ctx->seq_index][ctx->frame_index][index][0][channel];
+            ChannelParams *cp = &ctx->channel_params[ctx->seq_index][ctx->frame_index][index][channel];
             unsigned int filter;
 
             dp->quant_step_size[channel] = ctx->cur_decoding_params->quant_step_size[channel];
@@ -460,7 +457,7 @@ static av_cold int mlp_encode_init(AVCod
     unsigned int lossless_check_data_size;
     unsigned int lpc_sample_buffer_size;
     unsigned int frame_size_size;
-    unsigned int substr, index, index2, index3, subblock;
+    unsigned int substr, index, index2, index3;
 
     if (avctx->strict_std_compliance > -1 /* inofficial */) {
         av_log(avctx, AV_LOG_ERROR, "The bitstream generated by this encoder "
@@ -587,11 +584,9 @@ static av_cold int mlp_encode_init(AVCod
 
     for (index3 = 0; index3 < MAJOR_HEADER_INTERVAL; index3++) {
     for (index2 = 0; index2 < MAJOR_HEADER_INTERVAL; index2++) {
-    for (index = 0; index < MAJOR_HEADER_INTERVAL; index++) {
-        for (subblock = 0; subblock < MAX_SUBBLOCKS; subblock++) {
-            default_decoding_params(ctx, ctx->decoding_params[index3][index2][index][subblock]);
-            clear_channel_params(ctx->channel_params[index3][index2][index][subblock]);
-        }
+    for (index = 0; index < MAJOR_HEADER_INTERVAL + 1; index++) {
+            default_decoding_params(ctx, ctx->decoding_params[index3][index2][index]);
+            clear_channel_params(ctx->channel_params[index3][index2][index]);
     }
     }
     }
@@ -917,10 +912,10 @@ static uint8_t *write_substrs(MLPEncodeC
 
         for (subblock = 0; subblock <= num_subblocks; subblock++) {
 
-            ctx->cur_decoding_params = &ctx->major_decoding_params[ctx->frame_index][subblock][substr];
-            ctx->cur_channel_params = ctx->major_channel_params[ctx->frame_index][subblock];
+            ctx->cur_decoding_params = &ctx->major_decoding_params[ctx->frame_index + 1 - num_subblocks + subblock][substr];
+            ctx->cur_channel_params = ctx->major_channel_params[ctx->frame_index + 1 - num_subblocks + subblock];
 
-            params_changed = ctx->major_params_changed[ctx->frame_index][subblock][substr];
+            params_changed = ctx->major_params_changed[ctx->frame_index + 1 - num_subblocks + subblock][substr];
 
             if (restart_frame || params_changed) {
                 put_bits(&pb, 1, 1);
@@ -1732,14 +1727,14 @@ static void rematrix_channels(MLPEncodeC
  **** Functions that deal with determining the best parameters and output ***
  ****************************************************************************/
 
-static void set_best_offset(MLPEncodeContext *ctx, int index, int subblock)
+static void set_best_offset(MLPEncodeContext *ctx, int index)
 {
     DecodingParams *dp = ctx->cur_decoding_params;
     RestartHeader *rh = ctx->cur_restart_header;
     unsigned int channel;
 
     for (channel = rh->min_channel; channel <= rh->max_channel; channel++) {
-        ChannelParams *major_cp = &ctx->major_channel_params[index][subblock][channel];
+        ChannelParams *major_cp = &ctx->major_channel_params[index][channel];
         ChannelParams *cp = &ctx->cur_channel_params[channel];
         BestOffset bo = { 0, INT_MAX, 0, 0, 0, };
         unsigned int best_codebook = 0, i;
@@ -1766,60 +1761,52 @@ static void set_best_offset(MLPEncodeCon
  */
 static void set_major_params(MLPEncodeContext *ctx)
 {
-    unsigned int index, subblock;
+    unsigned int index;
     unsigned int substr;
 
     memcpy(ctx->major_channel_params, ctx->channel_params[MAJOR_HEADER_INTERVAL-1][MAJOR_HEADER_INTERVAL-1], sizeof(ctx->major_channel_params));
     memcpy(ctx->major_decoding_params, ctx->decoding_params[MAJOR_HEADER_INTERVAL-1][MAJOR_HEADER_INTERVAL-1], sizeof(ctx->major_decoding_params));
 
     for (substr = 0; substr < ctx->num_substreams; substr++) {
-        unsigned int num_subblocks = 1;
 
         ctx->cur_restart_header = &ctx->restart_header[substr];
 
         ctx->prev_decoding_params = &restart_decoding_params[substr];
         ctx->prev_channel_params = restart_channel_params;
 
-        for (index = 0; index < MAJOR_HEADER_INTERVAL; index++) {
-            for (subblock = 0; subblock <= num_subblocks; subblock++) {
-                ctx->cur_decoding_params = &ctx->decoding_params[MAJOR_HEADER_INTERVAL-1][MAJOR_HEADER_INTERVAL-1][index][subblock][substr];
-                ctx->cur_channel_params = ctx->channel_params[MAJOR_HEADER_INTERVAL-1][MAJOR_HEADER_INTERVAL-1][index][subblock];
-                ctx->cur_best_offset = ctx->best_offset[MAJOR_HEADER_INTERVAL-1][MAJOR_HEADER_INTERVAL-1][index][subblock];
-
-                if (subblock)
-                    num_subblocks = 0;
+        for (index = 0; index < MAJOR_HEADER_INTERVAL + 1; index++) {
+                ctx->cur_decoding_params = &ctx->decoding_params[MAJOR_HEADER_INTERVAL-1][MAJOR_HEADER_INTERVAL-1][index][substr];
+                ctx->cur_channel_params = ctx->channel_params[MAJOR_HEADER_INTERVAL-1][MAJOR_HEADER_INTERVAL-1][index];
+                ctx->cur_best_offset = ctx->best_offset[MAJOR_HEADER_INTERVAL-1][MAJOR_HEADER_INTERVAL-1][index];
 
-                set_best_offset(ctx, index, subblock);
+                set_best_offset(ctx, index);
 
-                ctx->major_params_changed[index][subblock][substr] = compare_decoding_params(ctx);
+                ctx->major_params_changed[index][substr] = compare_decoding_params(ctx);
 
                 ctx->prev_decoding_params = ctx->cur_decoding_params;
                 ctx->prev_channel_params = ctx->cur_channel_params;
-            }
         }
     }
 }
 
 static void analyze_sample_buffer(MLPEncodeContext *ctx)
 {
-    unsigned int index, subblock;
+    unsigned int index;
     unsigned int substr;
 
     for (substr = 0; substr < ctx->num_substreams; substr++) {
-        unsigned int num_subblocks = 1;
 
         ctx->cur_restart_header = &ctx->restart_header[substr];
 
-        for (subblock = 0; subblock < MAX_SUBBLOCKS; subblock++)
         for (index = 0; index < ctx->number_of_frames; index++) {
-            DecodingParams *dp = &ctx->decoding_params[ctx->seq_index][ctx->frame_index][index][subblock][substr];
+            DecodingParams *dp = &ctx->decoding_params[ctx->seq_index][ctx->frame_index][index + 1][substr];
             dp->blocksize = ctx->frame_size[index];
         }
-        ctx->decoding_params[ctx->seq_index][ctx->frame_index][0][0][substr].blocksize = 8;
-        ctx->decoding_params[ctx->seq_index][ctx->frame_index][0][1][substr].blocksize = ctx->frame_size[ctx->frame_index] - 8;
+        ctx->decoding_params[ctx->seq_index][ctx->frame_index][0][substr].blocksize  = 8;
+        ctx->decoding_params[ctx->seq_index][ctx->frame_index][1][substr].blocksize -= 8;
 
-        ctx->cur_decoding_params = &ctx->decoding_params[ctx->seq_index][ctx->frame_index][0][1][substr];
-        ctx->cur_channel_params = ctx->channel_params[ctx->seq_index][ctx->frame_index][0][1];
+        ctx->cur_decoding_params = &ctx->decoding_params[ctx->seq_index][ctx->frame_index][1][substr];
+        ctx->cur_channel_params = ctx->channel_params[ctx->seq_index][ctx->frame_index][1];
 
         generate_2_noise_channels(ctx);
         lossless_matrix_coeffs   (ctx);
@@ -1830,16 +1817,12 @@ static void analyze_sample_buffer(MLPEnc
 
         copy_restart_frame_params(ctx, substr);
 
-        for (index = 0; index < ctx->number_of_frames; index++) {
-            for (subblock = 0; subblock <= num_subblocks; subblock++) {
-                ctx->cur_decoding_params = &ctx->decoding_params[ctx->seq_index][ctx->frame_index][index][subblock][substr];
-                ctx->cur_channel_params = ctx->channel_params[ctx->seq_index][ctx->frame_index][index][subblock];
-                ctx->cur_best_offset = ctx->best_offset[ctx->seq_index][ctx->frame_index][index][subblock];
+        for (index = 0; index < ctx->number_of_frames + 1; index++) {
+                ctx->cur_decoding_params = &ctx->decoding_params[ctx->seq_index][ctx->frame_index][index][substr];
+                ctx->cur_channel_params = ctx->channel_params[ctx->seq_index][ctx->frame_index][index];
+                ctx->cur_best_offset = ctx->best_offset[ctx->seq_index][ctx->frame_index][index];
                 determine_bits(ctx);
                 ctx->sample_buffer += ctx->cur_decoding_params->blocksize * ctx->num_channels;
-                if (subblock)
-                    num_subblocks = 0;
-            }
         }
     }
 }
@@ -1860,8 +1843,8 @@ static void process_major_frame(MLPEncod
 
         ctx->cur_restart_header = &ctx->restart_header[substr];
 
-        ctx->cur_decoding_params = &ctx->major_decoding_params[0][1][substr];
-        ctx->cur_channel_params = ctx->major_channel_params[0][1];
+        ctx->cur_decoding_params = &ctx->major_decoding_params[1][substr];
+        ctx->cur_channel_params = ctx->major_channel_params[1];
 
         generate_2_noise_channels(ctx);
         rematrix_channels        (ctx);
@@ -1951,7 +1934,7 @@ input_and_return:
          seq_index  > 0;
          seq_index -= ctx->major_header_subinterval) {
         unsigned int number_of_samples = 0;
-        unsigned int index, subblock;
+        unsigned int index;
 
         ctx->sample_buffer = ctx->major_scratch_buffer;
         ctx->inout_buffer = ctx->major_inout_buffer;
@@ -1965,9 +1948,8 @@ input_and_return:
         }
         ctx->number_of_samples = number_of_samples;
 
-        for (index = 0; index < ctx->number_of_frames; index++)
-            for (subblock = 0; subblock < MAX_SUBBLOCKS; subblock++)
-                clear_channel_params(ctx->channel_params[ctx->seq_index][ctx->frame_index][index][subblock]);
+        for (index = 0; index < ctx->number_of_frames + 1; index++)
+                clear_channel_params(ctx->channel_params[ctx->seq_index][ctx->frame_index][index]);
 
         input_to_sample_buffer(ctx);
 



More information about the FFmpeg-soc mailing list