History

avcodec/mlpenc: restructure code even more

Implement lsb_bypass for lossless rematrix.

Paul B Mahol committed 3 years ago

Commit 9adc5d81 parent 23619701 file · +317 −316Browse files

Unified · Split

libavcodec/mlpenc.c+317−316
@@ -38,6 +38,8 @@ · 37 unmodified lines
38#include "mlp.h"38#include "mlp.h"
39#include "lpc.h"39#include "lpc.h"
40 40
41#define MAX_NCHANNELS (MAX_CHANNELS + 2)
42
41#define MIN_HEADER_INTERVAL 843#define MIN_HEADER_INTERVAL 8
42#define MAX_HEADER_INTERVAL 12844#define MAX_HEADER_INTERVAL 128
43 45
@@ -66,11 +68,13 @@ typedef struct MatrixParams { · 22 unmodified lines
66 uint8_t count; ///< number of matrices to apply68 uint8_t count; ///< number of matrices to apply
67 69
68 uint8_t outch[MAX_MATRICES]; ///< output channel for each matrix70 uint8_t outch[MAX_MATRICES]; ///< output channel for each matrix
69 int32_t forco[MAX_MATRICES][MAX_CHANNELS+2]; ///< forward coefficients71 int32_t forco[MAX_MATRICES][MAX_NCHANNELS]; ///< forward coefficients
70 int32_t coeff[MAX_MATRICES][MAX_CHANNELS+2]; ///< decoding coefficients72 int32_t coeff[MAX_MATRICES][MAX_NCHANNELS]; ///< decoding coefficients
71 uint8_t fbits[MAX_CHANNELS]; ///< fraction bits73 uint8_t fbits[MAX_CHANNELS]; ///< fraction bits
72 74
73 int8_t shift[MAX_CHANNELS]; ///< Left shift to apply to decoded PCM values to get final 24-bit output.75 int8_t shift[MAX_CHANNELS]; ///< Left shift to apply to decoded PCM values to get final 24-bit output.
76 uint8_t lsb_bypass[MAX_MATRICES];
77 int8_t bypassed_lsbs[MAX_MATRICES][MAX_BLOCKSIZE];
74} MatrixParams;78} MatrixParams;
75 79
76enum ParamFlags {80enum ParamFlags {
@@ -93,6 +97,7 @@ typedef struct DecodingParams { · 16 unmodified lines
93 MatrixParams matrix_params;97 MatrixParams matrix_params;
94 98
95 uint8_t param_presence_flags; ///< Bitmask of which parameter sets are conveyed in a decoding parameter block.99 uint8_t param_presence_flags; ///< Bitmask of which parameter sets are conveyed in a decoding parameter block.
100 int32_t sample_buffer[MAX_NCHANNELS][MAX_BLOCKSIZE];
96} DecodingParams;101} DecodingParams;
97 102
98typedef struct BestOffset {103typedef struct BestOffset {
@@ -111,14 +116,15 @@ typedef struct BestOffset { · 12 unmodified lines
111 116
112typedef struct MLPBlock {117typedef struct MLPBlock {
113 unsigned int seq_size;118 unsigned int seq_size;
119 ChannelParams channel_params[MAX_CHANNELS];
114 DecodingParams decoding_params;120 DecodingParams decoding_params;
115 int32_t lossless_check_data; ///< Array with lossless_check_data for each access unit.121 int32_t lossless_check_data; ///< Array with lossless_check_data for each access unit.
116 unsigned int max_output_bits; ///< largest output bit-depth122 unsigned int max_output_bits; ///< largest output bit-depth
117 BestOffset best_offset[MAX_CHANNELS][NUM_CODEBOOKS];123 BestOffset best_offset[MAX_CHANNELS][NUM_CODEBOOKS];
118 ChannelParams channel_params[MAX_CHANNELS];
119 ChannelParams major_channel_params[MAX_CHANNELS]; ///< ChannelParams to be written to bitstream.124 ChannelParams major_channel_params[MAX_CHANNELS]; ///< ChannelParams to be written to bitstream.
120 DecodingParams major_decoding_params; ///< DecodingParams to be written to bitstream.125 DecodingParams major_decoding_params; ///< DecodingParams to be written to bitstream.
121 int major_params_changed; ///< params_changed to be written to bitstream.126 int major_params_changed; ///< params_changed to be written to bitstream.
127 int32_t inout_buffer[MAX_NCHANNELS][MAX_BLOCKSIZE];
122} MLPBlock;128} MLPBlock;
123 129
124typedef struct MLPEncodeContext {130typedef struct MLPEncodeContext {
@@ -127,6 +133,7 @@ typedef struct MLPEncodeContext { · 2 unmodified lines
127 133
128 int max_restart_interval; ///< Max interval of access units in between two major frames.134 int max_restart_interval; ///< Max interval of access units in between two major frames.
129 int min_restart_interval; ///< Min interval of access units in between two major frames.135 int min_restart_interval; ///< Min interval of access units in between two major frames.
136 int cur_restart_interval;
130 int lpc_coeff_precision;137 int lpc_coeff_precision;
131 int lpc_type;138 int lpc_type;
132 int lpc_passes;139 int lpc_passes;
@@ -152,11 +159,6 @@ typedef struct MLPEncodeContext { · 19 unmodified lines
152 int channel_occupancy;159 int channel_occupancy;
153 int summary_info;160 int summary_info;
154 161
155 int32_t *inout_buffer; ///< Pointer to data currently being read from lavc or written to bitstream.
156 int32_t *major_inout_buffer; ///< Buffer with all in/out data for one entire major frame interval.
157 int32_t *write_buffer; ///< Pointer to data currently being written to bitstream.
158 int32_t *sample_buffer; ///< Pointer to current access unit samples.
159 int32_t *major_scratch_buffer; ///< Scratch buffer big enough to fit all data for one entire major frame interval.
160 int32_t last_frames; ///< Signal last frames.162 int32_t last_frames; ///< Signal last frames.
161 163
162 unsigned int major_number_of_frames;164 unsigned int major_number_of_frames;
@@ -167,8 +169,6 @@ typedef struct MLPEncodeContext { · 4 unmodified lines
167 169
168 unsigned int frame_index; ///< Index of current frame being encoded.170 unsigned int frame_index; ///< Index of current frame being encoded.
169 171
170 unsigned int one_sample_buffer_size; ///< Number of samples*channel for one access unit.
171
172 unsigned int restart_intervals; ///< Number of possible major frame sizes.172 unsigned int restart_intervals; ///< Number of possible major frame sizes.
173 173
174 uint16_t output_timing; ///< Timestamp of current access unit.174 uint16_t output_timing; ///< Timestamp of current access unit.
@@ -185,28 +185,21 @@ typedef struct MLPEncodeContext { · 10 unmodified lines
185 RestartHeader restart_header;185 RestartHeader restart_header;
186 186
187 MLPBlock b[MAX_HEADER_INTERVAL + 1];187 MLPBlock b[MAX_HEADER_INTERVAL + 1];
188 int32_t filter_state[NUM_FILTERS][MAX_HEADER_INTERVAL * MAX_BLOCKSIZE];
188 int32_t lpc_sample_buffer[MAX_HEADER_INTERVAL * MAX_BLOCKSIZE];189 int32_t lpc_sample_buffer[MAX_HEADER_INTERVAL * MAX_BLOCKSIZE];
189 int32_t filter_state_buffer[NUM_FILTERS][MAX_BLOCKSIZE * MAX_HEADER_INTERVAL];
190 190
191 unsigned int major_cur_subblock_index;191 unsigned int major_cur_subblock_index;
192 unsigned int major_filter_state_subblock;192 unsigned int major_filter_state_subblock;
193 unsigned int major_number_of_subblocks;193 unsigned int major_number_of_subblocks;
194 194
195 BestOffset (*cur_best_offset)[NUM_CODEBOOKS];
196 ChannelParams *cur_channel_params;
197 DecodingParams *cur_decoding_params;
198 RestartHeader *cur_restart_header;195 RestartHeader *cur_restart_header;
199 196
200 AudioFrameQueue afq;197 AudioFrameQueue afq;
201 198
202 /* Analysis stage. */199 /* Analysis stage. */
203 unsigned int number_of_frames;200 unsigned int number_of_frames;
204 unsigned int number_of_samples;
205 unsigned int number_of_subblocks;201 unsigned int number_of_subblocks;
206 202
207 const ChannelParams *prev_channel_params;
208 const DecodingParams *prev_decoding_params;
209
210 int shorten_by;203 int shorten_by;
211 204
212 LPCContext lpc_ctx;205 LPCContext lpc_ctx;
@@ -278,6 +271,9 @@ static int compare_matrix_params(MLPEncodeContext *ctx, const MatrixParams *prev · 65 unmodified lines
278 if (prev->outch[mat] != mp->outch[mat])271 if (prev->outch[mat] != mp->outch[mat])
279 return 1;272 return 1;
280 273
274 if (prev->lsb_bypass[mat] != mp->lsb_bypass[mat])
275 return 1;
276
281 for (unsigned int channel = 0; channel < ctx->num_channels; channel++)277 for (unsigned int channel = 0; channel < ctx->num_channels; channel++)
282 if (prev->coeff[mat][channel] != mp->coeff[mat][channel])278 if (prev->coeff[mat][channel] != mp->coeff[mat][channel])
283 return 1;279 return 1;
@@ -289,13 +285,14 @@ static int compare_matrix_params(MLPEncodeContext *ctx, const MatrixParams *prev · 5 unmodified lines
289/** Compares two DecodingParams and ChannelParams structures to decide if a285/** Compares two DecodingParams and ChannelParams structures to decide if a
290 * new decoding params header has to be written.286 * new decoding params header has to be written.
291 */287 */
292static int compare_decoding_params(MLPEncodeContext *ctx)288static int compare_decoding_params(MLPEncodeContext *ctx,
289 unsigned int index)
293{290{
294 const DecodingParams *prev = ctx->prev_decoding_params;291 const DecodingParams *prev = index ? &ctx->b[index-1].major_decoding_params : restart_decoding_params;
295 DecodingParams *dp = ctx->cur_decoding_params;292 DecodingParams *dp = &ctx->b[index].major_decoding_params;
296 const MatrixParams *prev_mp = &prev->matrix_params;293 const MatrixParams *prev_mp = &prev->matrix_params;
297 MatrixParams *mp = &dp->matrix_params;294 MatrixParams *mp = &dp->matrix_params;
298 RestartHeader *rh = ctx->cur_restart_header;295 RestartHeader *rh = ctx->cur_restart_header;
299 int retval = 0;296 int retval = 0;
300 297
301 if (prev->param_presence_flags != dp->param_presence_flags)298 if (prev->param_presence_flags != dp->param_presence_flags)
@@ -320,8 +317,8 @@ static int compare_decoding_params(MLPEncodeContext *ctx) · 18 unmodified lines
320 }317 }
321 318
322 for (unsigned int ch = rh->min_channel; ch <= rh->max_channel; ch++) {319 for (unsigned int ch = rh->min_channel; ch <= rh->max_channel; ch++) {
323 const ChannelParams *prev_cp = &ctx->prev_channel_params[ch];320 const ChannelParams *prev_cp = index ? &ctx->b[index-1].major_channel_params[ch] : &restart_channel_params[ch];
324 ChannelParams *cp = &ctx->cur_channel_params[ch];321 ChannelParams *cp = &ctx->b[index].major_channel_params[ch];
325 322
326 if (!(retval & PARAM_FIR) &&323 if (!(retval & PARAM_FIR) &&
327 compare_filter_params(prev_cp, cp, FIR))324 compare_filter_params(prev_cp, cp, FIR))
@@ -374,8 +371,10 @@ static void copy_matrix_params(MatrixParams *dst, MatrixParams *src) · 46 unmodified lines
374 dst->coeff[count][channel] = src->coeff[count][channel];371 dst->coeff[count][channel] = src->coeff[count][channel];
375 }372 }
376 373
377 for (unsigned int count = 0; count < MAX_MATRICES; count++)374 for (unsigned int count = 0; count < MAX_MATRICES; count++) {
378 dst->outch[count] = src->outch[count];375 dst->outch[count] = src->outch[count];
376 dst->lsb_bypass[count] = src->lsb_bypass[count];
377 }
379 }378 }
380}379}
381 380
@@ -384,17 +383,17 @@ static void copy_restart_frame_params(MLPEncodeContext *ctx) · 2 unmodified lines
384 for (unsigned int index = 0; index < ctx->number_of_subblocks; index++) {383 for (unsigned int index = 0; index < ctx->number_of_subblocks; index++) {
385 DecodingParams *dp = &ctx->b[index].decoding_params;384 DecodingParams *dp = &ctx->b[index].decoding_params;
386 385
387 copy_matrix_params(&dp->matrix_params, &ctx->cur_decoding_params->matrix_params);386 copy_matrix_params(&dp->matrix_params, &ctx->b[1].decoding_params.matrix_params);
388 387
389 for (unsigned int channel = 0; channel < ctx->avctx->ch_layout.nb_channels; channel++) {388 for (unsigned int channel = 0; channel < ctx->avctx->ch_layout.nb_channels; channel++) {
390 ChannelParams *cp = &ctx->b[index].channel_params[channel];389 ChannelParams *cp = &ctx->b[index].channel_params[channel];
391 390
392 dp->quant_step_size[channel] = ctx->cur_decoding_params->quant_step_size[channel];391 dp->quant_step_size[channel] = ctx->b[1].decoding_params.quant_step_size[channel];
393 dp->matrix_params.shift[channel] = ctx->cur_decoding_params->matrix_params.shift[channel];392 dp->matrix_params.shift[channel] = ctx->b[1].decoding_params.matrix_params.shift[channel];
394 393
395 if (index)394 if (index)
396 for (unsigned int filter = 0; filter < NUM_FILTERS; filter++)395 for (unsigned int filter = 0; filter < NUM_FILTERS; filter++)
397 copy_filter_params(cp, &ctx->cur_channel_params[channel], filter);396 copy_filter_params(cp, &ctx->b[1].channel_params[channel], filter);
398 }397 }
399 }398 }
400}399}
@@ -405,10 +404,11 @@ static void clear_decoding_params(DecodingParams *decoding_params) · 4 unmodified lines
405 DecodingParams *dp = decoding_params;404 DecodingParams *dp = decoding_params;
406 405
407 dp->param_presence_flags = 0xff;406 dp->param_presence_flags = 0xff;
408 dp->blocksize = 8;407 dp->blocksize = 0;
409 408
410 memset(&dp->matrix_params , 0, sizeof(MatrixParams ));409 memset(&dp->matrix_params, 0, sizeof(dp->matrix_params ));
411 memset(dp->quant_step_size, 0, sizeof(dp->quant_step_size));410 memset(dp->quant_step_size, 0, sizeof(dp->quant_step_size));
411 memset(dp->sample_buffer, 0, sizeof(dp->sample_buffer ));
412}412}
413 413
414/** Clears a ChannelParams struct the way it should be after a restart header. */414/** Clears a ChannelParams struct the way it should be after a restart header. */
@@ -427,12 +427,11 @@ static void clear_channel_params(ChannelParams *channel_params, int nb_channels) · 12 unmodified lines
427}427}
428 428
429/** Sets default vales in our encoder for a DecodingParams struct. */429/** Sets default vales in our encoder for a DecodingParams struct. */
430static void default_decoding_params(MLPEncodeContext *ctx, DecodingParams *decoding_params)430static void default_decoding_params(MLPEncodeContext *ctx, DecodingParams *dp)
431{431{
432 DecodingParams *dp = decoding_params;
433 uint8_t param_presence_flags = 0;432 uint8_t param_presence_flags = 0;
434 433
435 clear_decoding_params(decoding_params);434 clear_decoding_params(dp);
436 435
437 param_presence_flags |= PARAM_BLOCKSIZE;436 param_presence_flags |= PARAM_BLOCKSIZE;
438 param_presence_flags |= PARAM_MATRIX;437 param_presence_flags |= PARAM_MATRIX;
@@ -480,7 +479,6 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx) · 41 unmodified lines
480 MLPEncodeContext *ctx = avctx->priv_data;479 MLPEncodeContext *ctx = avctx->priv_data;
481 RestartHeader *const rh = &ctx->restart_header;480 RestartHeader *const rh = &ctx->restart_header;
482 uint64_t channels_present;481 uint64_t channels_present;
483 size_t size;
484 int ret;482 int ret;
485 483
486 ctx->avctx = avctx;484 ctx->avctx = avctx;
@@ -555,21 +553,10 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx) · 68 unmodified lines
555 ctx->input_timing = -avctx->frame_size;553 ctx->input_timing = -avctx->frame_size;
556 554
557 ctx->num_channels = avctx->ch_layout.nb_channels + 2; /* +2 noise channels */555 ctx->num_channels = avctx->ch_layout.nb_channels + 2; /* +2 noise channels */
558 ctx->one_sample_buffer_size = avctx->frame_size
559 * ctx->num_channels;
560 556
561 ctx->min_restart_interval = ctx->max_restart_interval;557 ctx->min_restart_interval = ctx->cur_restart_interval = ctx->max_restart_interval;
562 ctx->restart_intervals = ctx->max_restart_interval / ctx->min_restart_interval;558 ctx->restart_intervals = ctx->max_restart_interval / ctx->min_restart_interval;
563 559
564 size = ctx->one_sample_buffer_size * ctx->max_restart_interval;
565 ctx->major_scratch_buffer = av_calloc(size, sizeof(*ctx->major_scratch_buffer));
566 if (!ctx->major_scratch_buffer)
567 return AVERROR(ENOMEM);
568
569 ctx->major_inout_buffer = av_calloc(size, sizeof(*ctx->major_inout_buffer));
570 if (!ctx->major_inout_buffer)
571 return AVERROR(ENOMEM);
572
573 ctx->num_substreams = 1; // TODO: change this after adding multi-channel support for TrueHD560 ctx->num_substreams = 1; // TODO: change this after adding multi-channel support for TrueHD
574 561
575 channels_present = av_channel_layout_subset(&avctx->ch_layout, ~(uint64_t)0);562 channels_present = av_channel_layout_subset(&avctx->ch_layout, ~(uint64_t)0);
@@ -643,9 +630,7 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx) · 67 unmodified lines
643 /* FIXME: this works for 1 and 2 channels, but check for more */630 /* FIXME: this works for 1 and 2 channels, but check for more */
644 rh->max_matrix_channel = rh->max_channel;631 rh->max_matrix_channel = rh->max_channel;
645 632
646 ctx->number_of_samples = avctx->frame_size * ctx->max_restart_interval;633 if ((ret = ff_lpc_init(&ctx->lpc_ctx, ctx->avctx->frame_size,
647
648 if ((ret = ff_lpc_init(&ctx->lpc_ctx, ctx->number_of_samples,
649 MLP_MAX_LPC_ORDER, ctx->lpc_type)) < 0)634 MLP_MAX_LPC_ORDER, ctx->lpc_type)) < 0)
650 return ret;635 return ret;
651 636
@@ -779,9 +764,10 @@ static void write_restart_header(MLPEncodeContext *ctx, PutBitContext *pb) · 127 unmodified lines
779}764}
780 765
781/** Writes matrix params for all primitive matrices to the bitstream. */766/** Writes matrix params for all primitive matrices to the bitstream. */
782static void write_matrix_params(MLPEncodeContext *ctx, PutBitContext *pb)767static void write_matrix_params(MLPEncodeContext *ctx,
768 DecodingParams *dp,
769 PutBitContext *pb)
783{770{
784 DecodingParams *dp = ctx->cur_decoding_params;
785 MatrixParams *mp = &dp->matrix_params;771 MatrixParams *mp = &dp->matrix_params;
786 772
787 put_bits(pb, 4, mp->count);773 put_bits(pb, 4, mp->count);
@@ -789,7 +775,7 @@ static void write_matrix_params(MLPEncodeContext *ctx, PutBitContext *pb) · 1 unmodified line
789 for (unsigned int mat = 0; mat < mp->count; mat++) {775 for (unsigned int mat = 0; mat < mp->count; mat++) {
790 put_bits(pb, 4, mp->outch[mat]); /* matrix_out_ch */776 put_bits(pb, 4, mp->outch[mat]); /* matrix_out_ch */
791 put_bits(pb, 4, mp->fbits[mat]);777 put_bits(pb, 4, mp->fbits[mat]);
792 put_bits(pb, 1, 0 ); /* lsb_bypass */778 put_bits(pb, 1, mp->lsb_bypass[mat]);
793 779
794 for (unsigned int channel = 0; channel < ctx->num_channels; channel++) {780 for (unsigned int channel = 0; channel < ctx->num_channels; channel++) {
795 int32_t coeff = mp->coeff[mat][channel];781 int32_t coeff = mp->coeff[mat][channel];
@@ -808,15 +794,17 @@ static void write_matrix_params(MLPEncodeContext *ctx, PutBitContext *pb) · 12 unmodified lines
808}794}
809 795
810/** Writes filter parameters for one filter to the bitstream. */796/** Writes filter parameters for one filter to the bitstream. */
811static void write_filter_params(MLPEncodeContext *ctx, PutBitContext *pb,797static void write_filter_params(MLPEncodeContext *ctx,
798 ChannelParams *cp,
799 PutBitContext *pb,
812 unsigned int channel, unsigned int filter)800 unsigned int channel, unsigned int filter)
813{801{
814 FilterParams *fp = &ctx->cur_channel_params[channel].filter_params[filter];802 FilterParams *fp = &cp->filter_params[filter];
815 803
816 put_bits(pb, 4, fp->order);804 put_bits(pb, 4, fp->order);
817 805
818 if (fp->order > 0) {806 if (fp->order > 0) {
819 int32_t *fcoeff = ctx->cur_channel_params[channel].coeff[filter];807 int32_t *fcoeff = cp->coeff[filter];
820 808
821 put_bits(pb, 4, fp->shift );809 put_bits(pb, 4, fp->shift );
822 put_bits(pb, 5, fp->coeff_bits );810 put_bits(pb, 5, fp->coeff_bits );
@@ -835,10 +823,11 @@ static void write_filter_params(MLPEncodeContext *ctx, PutBitContext *pb, · 12 unmodified lines
835 * usually at almost every frame.823 * usually at almost every frame.
836 */824 */
837static void write_decoding_params(MLPEncodeContext *ctx, PutBitContext *pb,825static void write_decoding_params(MLPEncodeContext *ctx, PutBitContext *pb,
838 int params_changed)826 int params_changed,
827 unsigned int subblock_index)
839{828{
840 DecodingParams *dp = ctx->cur_decoding_params;829 DecodingParams *dp = &ctx->b[subblock_index].major_decoding_params;
841 RestartHeader *rh = ctx->cur_restart_header;830 RestartHeader *rh = ctx->cur_restart_header;
842 MatrixParams *mp = &dp->matrix_params;831 MatrixParams *mp = &dp->matrix_params;
843 832
844 if (dp->param_presence_flags != PARAMS_DEFAULT &&833 if (dp->param_presence_flags != PARAMS_DEFAULT &&
@@ -861,7 +850,7 @@ static void write_decoding_params(MLPEncodeContext *ctx, PutBitContext *pb, · 16 unmodified lines
861 if (dp->param_presence_flags & PARAM_MATRIX) {850 if (dp->param_presence_flags & PARAM_MATRIX) {
862 if (params_changed & PARAM_MATRIX) {851 if (params_changed & PARAM_MATRIX) {
863 put_bits(pb, 1, 1);852 put_bits(pb, 1, 1);
864 write_matrix_params(ctx, pb);853 write_matrix_params(ctx, dp, pb);
865 } else {854 } else {
866 put_bits(pb, 1, 0);855 put_bits(pb, 1, 0);
867 }856 }
@@ -888,7 +877,7 @@ static void write_decoding_params(MLPEncodeContext *ctx, PutBitContext *pb, · 20 unmodified lines
888 }877 }
889 878
890 for (unsigned int ch = rh->min_channel; ch <= rh->max_channel; ch++) {879 for (unsigned int ch = rh->min_channel; ch <= rh->max_channel; ch++) {
891 ChannelParams *cp = &ctx->cur_channel_params[ch];880 ChannelParams *cp = &ctx->b[subblock_index].major_channel_params[ch];
892 881
893 if (dp->param_presence_flags & 0xF) {882 if (dp->param_presence_flags & 0xF) {
894 put_bits(pb, 1, 1);883 put_bits(pb, 1, 1);
@@ -896,7 +885,7 @@ static void write_decoding_params(MLPEncodeContext *ctx, PutBitContext *pb, · 1 unmodified line
896 if (dp->param_presence_flags & PARAM_FIR) {885 if (dp->param_presence_flags & PARAM_FIR) {
897 if (params_changed & PARAM_FIR) {886 if (params_changed & PARAM_FIR) {
898 put_bits(pb, 1, 1);887 put_bits(pb, 1, 1);
899 write_filter_params(ctx, pb, ch, FIR);888 write_filter_params(ctx, cp, pb, ch, FIR);
900 } else {889 } else {
901 put_bits(pb, 1, 0);890 put_bits(pb, 1, 0);
902 }891 }
@@ -905,7 +894,7 @@ static void write_decoding_params(MLPEncodeContext *ctx, PutBitContext *pb, · 2 unmodified lines
905 if (dp->param_presence_flags & PARAM_IIR) {894 if (dp->param_presence_flags & PARAM_IIR) {
906 if (params_changed & PARAM_IIR) {895 if (params_changed & PARAM_IIR) {
907 put_bits(pb, 1, 1);896 put_bits(pb, 1, 1);
908 write_filter_params(ctx, pb, ch, IIR);897 write_filter_params(ctx, cp, pb, ch, IIR);
909 } else {898 } else {
910 put_bits(pb, 1, 0);899 put_bits(pb, 1, 0);
911 }900 }
@@ -934,17 +923,18 @@ static void write_decoding_params(MLPEncodeContext *ctx, PutBitContext *pb, · 22 unmodified lines
934/** Writes the residuals to the bitstream. That is, the VLC codes from the923/** Writes the residuals to the bitstream. That is, the VLC codes from the
935 * codebooks (if any is used), and then the residual.924 * codebooks (if any is used), and then the residual.
936 */925 */
937static void write_block_data(MLPEncodeContext *ctx, PutBitContext *pb)926static void write_block_data(MLPEncodeContext *ctx, PutBitContext *pb,
927 unsigned int subblock_index)
938{928{
939 DecodingParams *dp = ctx->cur_decoding_params;929 RestartHeader *rh = ctx->cur_restart_header;
940 RestartHeader *rh = ctx->cur_restart_header;930 DecodingParams *dp = &ctx->b[subblock_index].major_decoding_params;
941 int32_t *sample_buffer = ctx->write_buffer;931 MatrixParams *mp = &dp->matrix_params;
942 int32_t sign_huff_offset[MAX_CHANNELS];932 int32_t sign_huff_offset[MAX_CHANNELS];
943 int codebook_index [MAX_CHANNELS];933 int codebook_index [MAX_CHANNELS];
944 int lsb_bits [MAX_CHANNELS];934 int lsb_bits [MAX_CHANNELS];
945 935
946 for (unsigned int ch = rh->min_channel; ch <= rh->max_channel; ch++) {936 for (unsigned int ch = rh->min_channel; ch <= rh->max_channel; ch++) {
947 ChannelParams *cp = &ctx->cur_channel_params[ch];937 ChannelParams *cp = &ctx->b[subblock_index].major_channel_params[ch];
948 int sign_shift;938 int sign_shift;
949 939
950 lsb_bits [ch] = cp->huff_lsbs - dp->quant_step_size[ch];940 lsb_bits [ch] = cp->huff_lsbs - dp->quant_step_size[ch];
@@ -962,8 +952,17 @@ static void write_block_data(MLPEncodeContext *ctx, PutBitContext *pb) · 11 unmodified lines
962 }952 }
963 953
964 for (unsigned int i = 0; i < dp->blocksize; i++) {954 for (unsigned int i = 0; i < dp->blocksize; i++) {
955 for (unsigned int mat = 0; mat < mp->count; mat++) {
956 if (mp->lsb_bypass[mat]) {
957 const int8_t *bypassed_lsbs = mp->bypassed_lsbs[mat];
958
959 put_bits(pb, 1, bypassed_lsbs[i]);
960 }
961 }
962
965 for (unsigned int ch = rh->min_channel; ch <= rh->max_channel; ch++) {963 for (unsigned int ch = rh->min_channel; ch <= rh->max_channel; ch++) {
966 int32_t sample = *sample_buffer++ >> dp->quant_step_size[ch];964 int32_t *sample_buffer = dp->sample_buffer[ch];
965 int32_t sample = sample_buffer[i] >> dp->quant_step_size[ch];
967 sample -= sign_huff_offset[ch];966 sample -= sign_huff_offset[ch];
968 967
969 if (codebook_index[ch] >= 0) {968 if (codebook_index[ch] >= 0) {
@@ -975,10 +974,7 @@ static void write_block_data(MLPEncodeContext *ctx, PutBitContext *pb) · 5 unmodified lines
975 974
976 put_bits(pb, lsb_bits[ch], sample);975 put_bits(pb, lsb_bits[ch], sample);
977 }976 }
978 sample_buffer += 2; /* noise channels */
979 }977 }
980
981 ctx->write_buffer = sample_buffer;
982}978}
983 979
984/** Writes the substream data to the bitstream. */980/** Writes the substream data to the bitstream. */
@@ -989,7 +985,7 @@ static uint8_t *write_substr(MLPEncodeContext *ctx, uint8_t *buf, int buf_size, · 4 unmodified lines
989 int32_t *lossless_check_data = &ctx->b[ctx->frame_index].lossless_check_data;985 int32_t *lossless_check_data = &ctx->b[ctx->frame_index].lossless_check_data;
990 unsigned int cur_subblock_index = ctx->major_cur_subblock_index;986 unsigned int cur_subblock_index = ctx->major_cur_subblock_index;
991 unsigned int num_subblocks = ctx->major_filter_state_subblock;987 unsigned int num_subblocks = ctx->major_filter_state_subblock;
992 RestartHeader *rh = &ctx->restart_header;988 RestartHeader *rh = &ctx->restart_header;
993 int substr_restart_frame = restart_frame;989 int substr_restart_frame = restart_frame;
994 uint8_t parity, checksum;990 uint8_t parity, checksum;
995 PutBitContext pb;991 PutBitContext pb;
@@ -1001,12 +997,7 @@ static uint8_t *write_substr(MLPEncodeContext *ctx, uint8_t *buf, int buf_size, · 5 unmodified lines
1001 init_put_bits(&pb, buf, buf_size);997 init_put_bits(&pb, buf, buf_size);
1002 998
1003 for (unsigned int subblock = 0; subblock <= num_subblocks; subblock++) {999 for (unsigned int subblock = 0; subblock <= num_subblocks; subblock++) {
1004 unsigned int subblock_index;1000 unsigned int subblock_index = cur_subblock_index++;
1005
1006 subblock_index = cur_subblock_index++;
1007
1008 ctx->cur_decoding_params = &ctx->b[subblock_index].major_decoding_params;
1009 ctx->cur_channel_params = ctx->b[subblock_index].major_channel_params;
1010 1001
1011 params_changed = ctx->b[subblock_index].major_params_changed;1002 params_changed = ctx->b[subblock_index].major_params_changed;
1012 1003
@@ -1022,12 +1013,13 @@ static uint8_t *write_substr(MLPEncodeContext *ctx, uint8_t *buf, int buf_size, · 9 unmodified lines
1022 put_bits(&pb, 1, 0);1013 put_bits(&pb, 1, 0);
1023 }1014 }
1024 1015
1025 write_decoding_params(ctx, &pb, params_changed);1016 write_decoding_params(ctx, &pb, params_changed,
1017 subblock_index);
1026 } else {1018 } else {
1027 put_bits(&pb, 1, 0);1019 put_bits(&pb, 1, 0);
1028 }1020 }
1029 1021
1030 write_block_data(ctx, &pb);1022 write_block_data(ctx, &pb, subblock_index);
1031 1023
1032 put_bits(&pb, 1, !substr_restart_frame);1024 put_bits(&pb, 1, !substr_restart_frame);
1033 1025
@@ -1159,23 +1151,21 @@ static void input_data_internal(MLPEncodeContext *ctx, const uint8_t *samples, · 125 unmodified lines
1159 const int32_t *samples_32 = (const int32_t *) samples;1151 const int32_t *samples_32 = (const int32_t *) samples;
1160 const int16_t *samples_16 = (const int16_t *) samples;1152 const int16_t *samples_16 = (const int16_t *) samples;
1161 RestartHeader *rh = &ctx->restart_header;1153 RestartHeader *rh = &ctx->restart_header;
1162 int32_t *sample_buffer = ctx->inout_buffer;
1163 int32_t temp_lossless_check_data = 0;1154 int32_t temp_lossless_check_data = 0;
1164 uint32_t bits = 0;1155 uint32_t bits = 0;
1165 1156
1166 for (int i = 0; i < nb_samples; i++) {1157 for (int i = 0; i < nb_samples; i++) {
1167 for (unsigned int channel = 0; channel <= rh->max_channel; channel++) {1158 for (unsigned int ch = 0; ch <= rh->max_channel; ch++) {
1159 int32_t *sample_buffer = ctx->b[ctx->frame_index].inout_buffer[ch];
1168 int32_t sample;1160 int32_t sample;
1169 1161
1170 sample = is24 ? *samples_32++ >> 8 : *samples_16++ * 256;1162 sample = is24 ? *samples_32++ >> 8 : *samples_16++ * 256;
1171 1163
1172 bits = FFMAX(number_sbits(sample), bits);1164 bits = FFMAX(number_sbits(sample), bits);
1173 1165
1174 temp_lossless_check_data ^= (sample & 0x00ffffff) << channel;1166 temp_lossless_check_data ^= (sample & 0x00ffffff) << ch;
1175 *sample_buffer++ = sample;1167 sample_buffer[i] = sample;
1176 }1168 }
1177
1178 sample_buffer += 2; /* noise channels */
1179 }1169 }
1180 1170
1181 ctx->b[ctx->frame_index].max_output_bits = bits;1171 ctx->b[ctx->frame_index].max_output_bits = bits;
@@ -1191,17 +1181,25 @@ static void input_data(MLPEncodeContext *ctx, const void *samples, int nb_sample · 9 unmodified lines
1191 1181
1192static void input_to_sample_buffer(MLPEncodeContext *ctx)1182static void input_to_sample_buffer(MLPEncodeContext *ctx)
1193{1183{
1194 int32_t *sample_buffer = ctx->sample_buffer;
1195
1196 for (unsigned int index = 0; index < ctx->number_of_frames; index++) {1184 for (unsigned int index = 0; index < ctx->number_of_frames; index++) {
1197 unsigned int cur_index = (ctx->frame_index + index + 1) % ctx->max_restart_interval;1185 unsigned int cur_index = (ctx->frame_index + index + 1) % ctx->cur_restart_interval;
1198 int32_t *input_buffer = ctx->inout_buffer + cur_index * ctx->one_sample_buffer_size;1186 DecodingParams *dp = &ctx->b[index+1].decoding_params;
1199 1187
1200 for (unsigned int i = 0; i < ctx->avctx->frame_size; i++) {1188 for (unsigned int ch = 0; ch < ctx->avctx->ch_layout.nb_channels; ch++) {
1201 for (unsigned int channel = 0; channel < ctx->avctx->ch_layout.nb_channels; channel++)1189 const int32_t *input_buffer = ctx->b[cur_index].inout_buffer[ch];
1202 *sample_buffer++ = *input_buffer++;1190 int32_t *sample_buffer = dp->sample_buffer[ch];
1203 sample_buffer += 2; /* noise_channels */1191 int off = 0;
1204 input_buffer += 2; /* noise_channels */1192
1193 if (dp->blocksize < ctx->avctx->frame_size) {
1194 DecodingParams *dp = &ctx->b[index].decoding_params;
1195 int32_t *sample_buffer = dp->sample_buffer[ch];
1196 for (unsigned int i = 0; i < dp->blocksize; i++)
1197 sample_buffer[i] = input_buffer[i];
1198 off = dp->blocksize;
1199 }
1200
1201 for (unsigned int i = 0; i < dp->blocksize; i++)
1202 sample_buffer[i] = input_buffer[i + off];
1205 }1203 }
1206 }1204 }
1207}1205}
@@ -1221,23 +1219,25 @@ static int number_trailing_zeroes(int32_t sample, unsigned int max, unsigned int · 13 unmodified lines
1221 */1219 */
1222static void determine_quant_step_size(MLPEncodeContext *ctx)1220static void determine_quant_step_size(MLPEncodeContext *ctx)
1223{1221{
1224 DecodingParams *dp = ctx->cur_decoding_params;1222 RestartHeader *rh = ctx->cur_restart_header;
1225 RestartHeader *rh = ctx->cur_restart_header;1223 DecodingParams *dp1 = &ctx->b[1].decoding_params;
1226 MatrixParams *mp = &dp->matrix_params;
1227 int32_t *sample_buffer = ctx->sample_buffer;
1228 int32_t sample_mask[MAX_CHANNELS];1224 int32_t sample_mask[MAX_CHANNELS];
1229 1225
1230 memset(sample_mask, 0x00, sizeof(sample_mask));1226 memset(sample_mask, 0, sizeof(sample_mask));
1231 1227
1232 for (unsigned int i = 0; i < ctx->number_of_samples; i++) {1228 for (unsigned int j = 0; j <= ctx->cur_restart_interval; j++) {
1233 for (unsigned int channel = 0; channel <= rh->max_channel; channel++)1229 DecodingParams *dp = &ctx->b[j].decoding_params;
1234 sample_mask[channel] |= *sample_buffer++;
1235 1230
1236 sample_buffer += 2; /* noise channels */1231 for (unsigned int ch = 0; ch <= rh->max_channel; ch++) {
1232 int32_t *sample_buffer = dp->sample_buffer[ch];
1233
1234 for (unsigned int i = 0; i < dp->blocksize; i++)
1235 sample_mask[ch] |= sample_buffer[i];
1236 }
1237 }1237 }
1238 1238
1239 for (unsigned int channel = 0; channel <= rh->max_channel; channel++)1239 for (unsigned int channel = 0; channel <= rh->max_channel; channel++)
1240 dp->quant_step_size[channel] = number_trailing_zeroes(sample_mask[channel], 15, 0) - mp->shift[channel];1240 dp1->quant_step_size[channel] = number_trailing_zeroes(sample_mask[channel], 15, 0);
1241}1241}
1242 1242
1243/** Determines the smallest number of bits needed to encode the filter1243/** Determines the smallest number of bits needed to encode the filter
@@ -1271,7 +1271,7 @@ static void set_filter_params(MLPEncodeContext *ctx, · 27 unmodified lines
1271 unsigned int channel, unsigned int filter,1271 unsigned int channel, unsigned int filter,
1272 int clear_filter)1272 int clear_filter)
1273{1273{
1274 ChannelParams *cp = &ctx->cur_channel_params[channel];1274 ChannelParams *cp = &ctx->b[1].channel_params[channel];
1275 FilterParams *fp = &cp->filter_params[filter];1275 FilterParams *fp = &cp->filter_params[filter];
1276 1276
1277 if (clear_filter) {1277 if (clear_filter) {
@@ -1280,21 +1280,26 @@ static void set_filter_params(MLPEncodeContext *ctx, · 2 unmodified lines
1280 fp->order = 0;1280 fp->order = 0;
1281 } else if (filter == FIR) {1281 } else if (filter == FIR) {
1282 const int max_order = MAX_FIR_ORDER;1282 const int max_order = MAX_FIR_ORDER;
1283 int32_t *sample_buffer = ctx->sample_buffer + channel;
1284 int32_t coefs[MAX_LPC_ORDER][MAX_LPC_ORDER];1283 int32_t coefs[MAX_LPC_ORDER][MAX_LPC_ORDER];
1285 int32_t *lpc_samples = ctx->lpc_sample_buffer;1284 int32_t *lpc_samples = ctx->lpc_sample_buffer;
1286 int32_t *fcoeff = ctx->cur_channel_params[channel].coeff[filter];1285 int32_t *fcoeff = cp->coeff[filter];
1287 int shift[MAX_LPC_ORDER];1286 int shift[MAX_LPC_ORDER];
1288 int order;1287 int order;
1289 1288
1290 for (unsigned int i = 0; i < ctx->number_of_samples; i++) {1289 for (unsigned int j = 0; j <= ctx->cur_restart_interval; j++) {
1291 *lpc_samples++ = *sample_buffer;1290 DecodingParams *dp = &ctx->b[j].decoding_params;
1292 sample_buffer += ctx->num_channels;1291 int32_t *sample_buffer = dp->sample_buffer[channel];
1292
1293 for (unsigned int i = 0; i < dp->blocksize; i++)
1294 lpc_samples[i] = sample_buffer[i];
1295 lpc_samples += dp->blocksize;
1293 }1296 }
1294 1297
1295 order = ff_lpc_calc_coefs(&ctx->lpc_ctx, ctx->lpc_sample_buffer,1298 order = ff_lpc_calc_coefs(&ctx->lpc_ctx, ctx->lpc_sample_buffer,
1296 ctx->number_of_samples, MLP_MIN_LPC_ORDER,1299 lpc_samples - ctx->lpc_sample_buffer,
1297 max_order, ctx->lpc_coeff_precision, coefs, shift, ctx->lpc_type, ctx->lpc_passes,1300 MLP_MIN_LPC_ORDER, max_order,
1301 ctx->lpc_coeff_precision,
1302 coefs, shift, ctx->lpc_type, ctx->lpc_passes,
1298 ctx->prediction_order, MLP_MIN_LPC_SHIFT,1303 ctx->prediction_order, MLP_MIN_LPC_SHIFT,
1299 MLP_MAX_LPC_SHIFT, MLP_MIN_LPC_SHIFT);1304 MLP_MAX_LPC_SHIFT, MLP_MIN_LPC_SHIFT);
1300 1305
@@ -1326,53 +1331,53 @@ static int estimate_coeff(MLPEncodeContext *ctx, · 25 unmodified lines
1326 MatrixParams *mp,1331 MatrixParams *mp,
1327 unsigned int ch0, unsigned int ch1)1332 unsigned int ch0, unsigned int ch1)
1328{1333{
1329 const int number_of_samples = ctx->number_of_samples;
1330 const int num_channels = ctx->num_channels;
1331 int first = 1, x, x0;1334 int first = 1, x, x0;
1332 const int32_t *ch[2];
1333 int64_t g = 0, g0 = 0;1335 int64_t g = 0, g0 = 0;
1334 1336
1335 ch[0] = ctx->sample_buffer + ch0;1337 for (int j = 0; j <= ctx->cur_restart_interval; j++) {
1336 ch[1] = ctx->sample_buffer + ch1;1338 DecodingParams *dp = &ctx->b[j].decoding_params;
1339 const int32_t *ch[2];
1337 1340
1338 for (int n = 0, i = 0; n < number_of_samples; n++) {1341 ch[0] = dp->sample_buffer[ch0];
1339 int64_t c0, c1;1342 ch[1] = dp->sample_buffer[ch1];
1340 int32_t a0, a1;
1341 1343
1342 c0 = ch[0][i];1344 for (int i = 0; i < dp->blocksize; i++) {
1343 c1 = ch[1][i];1345 int64_t c0, c1;
1346 int32_t a0, a1;
1344 1347
1345 if (!c0 && !c1)1348 c0 = ch[0][i];
1346 goto next;1349 c1 = ch[1][i];
1347 1350
1348 if (!c0 || !c1) {1351 if (!c0 && !c1)
1349 g0 = 0;1352 continue;
1350 break;
1351 }
1352 1353
1353 a0 = FFABS(c0);1354 if (!c0 || !c1) {
1354 a1 = FFABS(c1);1355 g0 = 0;
1356 goto end;
1357 }
1355 1358
1356 if (a0 >= a1) {1359 a0 = FFABS(c0);
1357 g = (c1 * (1 << 14)) / c0;1360 a1 = FFABS(c1);
1358 x = ch1;
1359 } else if (a0 < a1) {
1360 g = (c0 * (1 << 14)) / c1;
1361 x = ch0;
1362 }
1363 1361
1364 if (first) {1362 if (a0 >= a1) {
1365 g0 = g;1363 g = (c1 * (1 << 14)) / c0;
1366 x0 = x;1364 x = ch1;
1367 first = 0;1365 } else if (a0 < a1) {
1368 } else if (g != g0 || x != x0) {1366 g = (c0 * (1 << 14)) / c1;
1369 g0 = 0;1367 x = ch0;
1370 break;1368 }
1371 }
1372 1369
1373next:1370 if (first) {
1374 i += num_channels;1371 g0 = g;
1372 x0 = x;
1373 first = 0;
1374 } else if (g != g0 || x != x0) {
1375 g0 = 0;
1376 goto end;
1377 }
1378 }
1375 }1379 }
1380end:
1376 1381
1377 if (g0) {1382 if (g0) {
1378 mp->outch[0] = (x0 == ch0) ? ch0 : ch1;1383 mp->outch[0] = (x0 == ch0) ? ch0 : ch1;
@@ -1383,9 +1388,6 @@ next: · 4 unmodified lines
1383 mp->forco[0][ch0] = 0;1388 mp->forco[0][ch0] = 0;
1384 mp->forco[0][ch1] = 0;1389 mp->forco[0][ch1] = 0;
1385 1390
1386 mp->coeff[0][num_channels - 2] = mp->coeff[0][num_channels - 1] = 0;
1387 mp->forco[0][num_channels - 2] = mp->forco[0][num_channels - 1] = 0;
1388
1389 return 1;1391 return 1;
1390 }1392 }
1391 1393
@@ -1395,9 +1397,10 @@ next: · 3 unmodified lines
1395/** Determines how many fractional bits are needed to encode matrix1397/** Determines how many fractional bits are needed to encode matrix
1396 * coefficients. Also shifts the coefficients to fit within 2.14 bits.1398 * coefficients. Also shifts the coefficients to fit within 2.14 bits.
1397 */1399 */
1398static void code_matrix_coeffs(MLPEncodeContext *ctx, unsigned int mat)1400static void code_matrix_coeffs(MLPEncodeContext *ctx,
1401 DecodingParams *dp,
1402 unsigned int mat)
1399{1403{
1400 DecodingParams *dp = ctx->cur_decoding_params;
1401 MatrixParams *mp = &dp->matrix_params;1404 MatrixParams *mp = &dp->matrix_params;
1402 int32_t coeff_mask = 0;1405 int32_t coeff_mask = 0;
1403 1406
@@ -1411,9 +1414,8 @@ static void code_matrix_coeffs(MLPEncodeContext *ctx, unsigned int mat) · 7 unmodified lines
1411/** Determines best coefficients to use for the lossless matrix. */1414/** Determines best coefficients to use for the lossless matrix. */
1412static void lossless_matrix_coeffs(MLPEncodeContext *ctx)1415static void lossless_matrix_coeffs(MLPEncodeContext *ctx)
1413{1416{
1414 DecodingParams *dp = ctx->cur_decoding_params;1417 DecodingParams *dp = &ctx->b[1].decoding_params;
1415 MatrixParams *mp = &dp->matrix_params;1418 MatrixParams *mp = &dp->matrix_params;
1416 unsigned int shift = 0;
1417 1419
1418 mp->count = 0;1420 mp->count = 0;
1419 if (ctx->num_channels - 2 != 2)1421 if (ctx->num_channels - 2 != 2)
@@ -1422,10 +1424,7 @@ static void lossless_matrix_coeffs(MLPEncodeContext *ctx) · 2 unmodified lines
1422 mp->count = estimate_coeff(ctx, mp, 0, 1);1424 mp->count = estimate_coeff(ctx, mp, 0, 1);
1423 1425
1424 for (int mat = 0; mat < mp->count; mat++)1426 for (int mat = 0; mat < mp->count; mat++)
1425 code_matrix_coeffs(ctx, mat);1427 code_matrix_coeffs(ctx, dp, mat);
1426
1427 for (unsigned int channel = 0; channel < ctx->num_channels; channel++)
1428 mp->shift[channel] = shift;
1429}1428}
1430 1429
1431/** Min and max values that can be encoded with each codebook. The values for1430/** Min and max values that can be encoded with each codebook. The values for
@@ -1441,11 +1440,11 @@ static const int8_t codebook_extremes[3][2] = { · 9 unmodified lines
1441 * codebooks and a specified offset.1440 * codebooks and a specified offset.
1442 */1441 */
1443static void no_codebook_bits_offset(MLPEncodeContext *ctx,1442static void no_codebook_bits_offset(MLPEncodeContext *ctx,
1443 DecodingParams *dp,
1444 unsigned int channel, int32_t offset,1444 unsigned int channel, int32_t offset,
1445 int32_t min, int32_t max,1445 int32_t min, int32_t max,
1446 BestOffset *bo)1446 BestOffset *bo)
1447{1447{
1448 DecodingParams *dp = ctx->cur_decoding_params;
1449 int32_t unsign = 0;1448 int32_t unsign = 0;
1450 int lsb_bits;1449 int lsb_bits;
1451 1450
@@ -1470,11 +1469,11 @@ static void no_codebook_bits_offset(MLPEncodeContext *ctx, · 18 unmodified lines
1470 * codebooks.1469 * codebooks.
1471 */1470 */
1472static void no_codebook_bits(MLPEncodeContext *ctx,1471static void no_codebook_bits(MLPEncodeContext *ctx,
1472 DecodingParams *dp,
1473 unsigned int channel,1473 unsigned int channel,
1474 int32_t min, int32_t max,1474 int32_t min, int32_t max,
1475 BestOffset *bo)1475 BestOffset *bo)
1476{1476{
1477 DecodingParams *dp = ctx->cur_decoding_params;
1478 int32_t offset, unsign = 0;1477 int32_t offset, unsign = 0;
1479 uint8_t lsb_bits;1478 uint8_t lsb_bits;
1480 1479
@@ -1507,14 +1506,14 @@ static void no_codebook_bits(MLPEncodeContext *ctx, · 26 unmodified lines
1507 * given codebook and a given offset.1506 * given codebook and a given offset.
1508 */1507 */
1509static inline void codebook_bits_offset(MLPEncodeContext *ctx,1508static inline void codebook_bits_offset(MLPEncodeContext *ctx,
1509 DecodingParams *dp,
1510 unsigned int channel, int codebook,1510 unsigned int channel, int codebook,
1511 int32_t sample_min, int32_t sample_max,1511 int32_t sample_min, int32_t sample_max,
1512 int32_t offset, BestOffset *bo)1512 int32_t offset, BestOffset *bo)
1513{1513{
1514 int32_t codebook_min = codebook_extremes[codebook][0];1514 int32_t codebook_min = codebook_extremes[codebook][0];
1515 int32_t codebook_max = codebook_extremes[codebook][1];1515 int32_t codebook_max = codebook_extremes[codebook][1];
1516 int32_t *sample_buffer = ctx->sample_buffer + channel;1516 int32_t *sample_buffer = dp->sample_buffer[channel];
1517 DecodingParams *dp = ctx->cur_decoding_params;
1518 int codebook_offset = 7 + (2 - codebook);1517 int codebook_offset = 7 + (2 - codebook);
1519 int32_t unsign_offset = offset;1518 int32_t unsign_offset = offset;
1520 uint32_t bitcount = 0;1519 uint32_t bitcount = 0;
@@ -1540,7 +1539,7 @@ static inline void codebook_bits_offset(MLPEncodeContext *ctx, · 19 unmodified lines
1540 }1539 }
1541 1540
1542 for (int i = 0; i < dp->blocksize; i++) {1541 for (int i = 0; i < dp->blocksize; i++) {
1543 int32_t sample = *sample_buffer >> dp->quant_step_size[channel];1542 int32_t sample = sample_buffer[i] >> dp->quant_step_size[channel];
1544 int temp_min, temp_max;1543 int temp_min, temp_max;
1545 1544
1546 sample -= unsign_offset;1545 sample -= unsign_offset;
@@ -1556,8 +1555,6 @@ static inline void codebook_bits_offset(MLPEncodeContext *ctx, · 9 unmodified lines
1556 sample >>= lsb_bits;1555 sample >>= lsb_bits;
1557 1556
1558 bitcount += ff_mlp_huffman_tables[codebook][sample + codebook_offset][1];1557 bitcount += ff_mlp_huffman_tables[codebook][sample + codebook_offset][1];
1559
1560 sample_buffer += ctx->num_channels;
1561 }1558 }
1562 1559
1563 bo->offset = offset;1560 bo->offset = offset;
@@ -1571,6 +1568,7 @@ static inline void codebook_bits_offset(MLPEncodeContext *ctx, · 7 unmodified lines
1571 * given codebook. Searches for the best offset to minimize the bits.1568 * given codebook. Searches for the best offset to minimize the bits.
1572 */1569 */
1573static inline void codebook_bits(MLPEncodeContext *ctx,1570static inline void codebook_bits(MLPEncodeContext *ctx,
1571 DecodingParams *dp,
1574 unsigned int channel, int codebook,1572 unsigned int channel, int codebook,
1575 int offset, int32_t min, int32_t max,1573 int offset, int32_t min, int32_t max,
1576 BestOffset *bo, int direction)1574 BestOffset *bo, int direction)
@@ -1585,7 +1583,7 @@ static inline void codebook_bits(MLPEncodeContext *ctx, · 8 unmodified lines
1585 while (offset <= offset_max && offset >= offset_min) {1583 while (offset <= offset_max && offset >= offset_min) {
1586 BestOffset temp_bo;1584 BestOffset temp_bo;
1587 1585
1588 codebook_bits_offset(ctx, channel, codebook,1586 codebook_bits_offset(ctx, dp, channel, codebook,
1589 min, max, offset,1587 min, max, offset,
1590 &temp_bo);1588 &temp_bo);
1591 1589
@@ -1612,56 +1610,57 @@ static inline void codebook_bits(MLPEncodeContext *ctx, · 20 unmodified lines
1612 */1610 */
1613static void determine_bits(MLPEncodeContext *ctx)1611static void determine_bits(MLPEncodeContext *ctx)
1614{1612{
1615 DecodingParams *dp = ctx->cur_decoding_params;1613 RestartHeader *rh = ctx->cur_restart_header;
1616 RestartHeader *rh = ctx->cur_restart_header;1614 for (unsigned int index = 0; index < ctx->number_of_subblocks; index++) {
1617 1615 DecodingParams *dp = &ctx->b[index].decoding_params;
1618 for (unsigned int channel = 0; channel <= rh->max_channel; channel++) {
1619 ChannelParams *cp = &ctx->cur_channel_params[channel];
1620 int32_t *sample_buffer = ctx->sample_buffer + channel;
1621 int32_t min = INT32_MAX, max = INT32_MIN;
1622 int no_filters_used = !cp->filter_params[FIR].order;
1623 int average = 0;
1624 int offset = 0;
1625
1626 /* Determine extremes and average. */
1627 for (int i = 0; i < dp->blocksize; i++) {
1628 int32_t sample = *sample_buffer >> dp->quant_step_size[channel];
1629 if (sample < min)
1630 min = sample;
1631 if (sample > max)
1632 max = sample;
1633 average += sample;
1634 sample_buffer += ctx->num_channels;
1635 }
1636 average /= dp->blocksize;
1637 1616
1638 /* If filtering is used, we always set the offset to zero, otherwise1617 for (unsigned int channel = 0; channel <= rh->max_channel; channel++) {
1639 * we search for the offset that minimizes the bitcount. */1618 ChannelParams *cp = &ctx->b[index].channel_params[channel];
1640 if (no_filters_used) {1619 int32_t *sample_buffer = dp->sample_buffer[channel];
1641 no_codebook_bits(ctx, channel, min, max, &ctx->cur_best_offset[channel][0]);1620 int32_t min = INT32_MAX, max = INT32_MIN;
1642 offset = av_clip(average, HUFF_OFFSET_MIN, HUFF_OFFSET_MAX);1621 int no_filters_used = !cp->filter_params[FIR].order;
1643 } else {1622 int average = 0;
1644 no_codebook_bits_offset(ctx, channel, offset, min, max, &ctx->cur_best_offset[channel][0]);1623 int offset = 0;
1645 }1624
1625 /* Determine extremes and average. */
1626 for (int i = 0; i < dp->blocksize; i++) {
1627 int32_t sample = sample_buffer[i] >> dp->quant_step_size[channel];
1628 if (sample < min)
1629 min = sample;
1630 if (sample > max)
1631 max = sample;
1632 average += sample;
1633 }
1634 average /= dp->blocksize;
1635
1636 /* If filtering is used, we always set the offset to zero, otherwise
1637 * we search for the offset that minimizes the bitcount. */
1638 if (no_filters_used) {
1639 no_codebook_bits(ctx, dp, channel, min, max, &ctx->b[index].best_offset[channel][0]);
1640 offset = av_clip(average, HUFF_OFFSET_MIN, HUFF_OFFSET_MAX);
1641 } else {
1642 no_codebook_bits_offset(ctx, dp, channel, offset, min, max, &ctx->b[index].best_offset[channel][0]);
1643 }
1646 1644
1647 for (int i = 1; i < NUM_CODEBOOKS; i++) {1645 for (int i = 1; i < NUM_CODEBOOKS; i++) {
1648 BestOffset temp_bo = { 0, UINT32_MAX, 0, 0, 0, };1646 BestOffset temp_bo = { 0, UINT32_MAX, 0, 0, 0, };
1649 int32_t offset_max;1647 int32_t offset_max;
1650 1648
1651 codebook_bits_offset(ctx, channel, i - 1,1649 codebook_bits_offset(ctx, dp, channel, i - 1,
1652 min, max, offset,1650 min, max, offset,
1653 &temp_bo);1651 &temp_bo);
1654 1652
1655 if (no_filters_used) {1653 if (no_filters_used) {
1656 offset_max = temp_bo.max;1654 offset_max = temp_bo.max;
1657 1655
1658 codebook_bits(ctx, channel, i - 1, temp_bo.min - 1,1656 codebook_bits(ctx, dp, channel, i - 1, temp_bo.min - 1,
1659 min, max, &temp_bo, 0);1657 min, max, &temp_bo, 0);
1660 codebook_bits(ctx, channel, i - 1, offset_max + 1,1658 codebook_bits(ctx, dp, channel, i - 1, offset_max + 1,
1661 min, max, &temp_bo, 1);1659 min, max, &temp_bo, 1);
1662 }1660 }
1663 1661
1664 ctx->cur_best_offset[channel][i] = temp_bo;1662 ctx->b[index].best_offset[channel][i] = temp_bo;
1663 }
1665 }1664 }
1666 }1665 }
1667}1666}
@@ -1682,34 +1681,40 @@ static void determine_bits(MLPEncodeContext *ctx) · 14 unmodified lines
1682 */1681 */
1683static int apply_filter(MLPEncodeContext *ctx, unsigned int channel)1682static int apply_filter(MLPEncodeContext *ctx, unsigned int channel)
1684{1683{
1685 ChannelParams *cp = &ctx->cur_channel_params[channel];1684 DecodingParams *dp = &ctx->b[1].decoding_params;
1685 ChannelParams *cp = &ctx->b[1].channel_params[channel];
1686 FilterParams *fp[NUM_FILTERS] = { &cp->filter_params[FIR],1686 FilterParams *fp[NUM_FILTERS] = { &cp->filter_params[FIR],
1687 &cp->filter_params[IIR], };1687 &cp->filter_params[IIR], };
1688 const uint8_t codebook = cp->codebook;1688 const uint8_t codebook = cp->codebook;
1689 int32_t mask = MSB_MASK(ctx->cur_decoding_params->quant_step_size[channel]);1689 int32_t mask = MSB_MASK(dp->quant_step_size[channel]);
1690 int32_t *sample_buffer = ctx->sample_buffer + channel;1690 int32_t *sample_buffer = ctx->b[0].decoding_params.sample_buffer[channel];
1691 unsigned int number_of_samples = ctx->number_of_samples;
1692 unsigned int filter_shift = fp[FIR]->shift;1691 unsigned int filter_shift = fp[FIR]->shift;
1692 int32_t *filter_state[NUM_FILTERS] = { ctx->filter_state[FIR],
1693 ctx->filter_state[IIR], };
1694 int i, j = 1, k = 0;
1693 1695
1694 for (int i = 0; i < 8; i++) {1696 for (i = 0; i < 8; i++) {
1695 ctx->filter_state_buffer[FIR][i] = *sample_buffer;1697 filter_state[FIR][i] = sample_buffer[i];
1696 ctx->filter_state_buffer[IIR][i] = *sample_buffer;1698 filter_state[IIR][i] = sample_buffer[i];
1697
1698 sample_buffer += ctx->num_channels;
1699 }1699 }
1700 1700
1701 for (int i = 8; i < number_of_samples; i++) {1701 while (1) {
1702 int32_t sample = *sample_buffer;1702 int32_t *sample_buffer = ctx->b[j].decoding_params.sample_buffer[channel];
1703 unsigned int blocksize = ctx->b[j].decoding_params.blocksize;
1704 int32_t sample, residual;
1703 int64_t accum = 0;1705 int64_t accum = 0;
1704 int32_t residual;1706
1707 if (!blocksize)
1708 break;
1705 1709
1706 for (int filter = 0; filter < NUM_FILTERS; filter++) {1710 for (int filter = 0; filter < NUM_FILTERS; filter++) {
1707 int32_t *fcoeff = cp->coeff[filter];1711 int32_t *fcoeff = cp->coeff[filter];
1708 for (unsigned int order = 0; order < fp[filter]->order; order++)1712 for (unsigned int order = 0; order < fp[filter]->order; order++)
1709 accum += (int64_t)ctx->filter_state_buffer[filter][i - 1 - order] *1713 accum += (int64_t)filter_state[filter][i - 1 - order] *
1710 fcoeff[order];1714 fcoeff[order];
1711 }1715 }
1712 1716
1717 sample = sample_buffer[k];
1713 accum >>= filter_shift;1718 accum >>= filter_shift;
1714 residual = sample - (accum & mask);1719 residual = sample - (accum & mask);
1715 1720
@@ -1718,17 +1723,25 @@ static int apply_filter(MLPEncodeContext *ctx, unsigned int channel) · 2 unmodified lines
1718 residual > SAMPLE_MAX(24)))1723 residual > SAMPLE_MAX(24)))
1719 return -1;1724 return -1;
1720 1725
1721 ctx->filter_state_buffer[FIR][i] = sample;1726 filter_state[FIR][i] = sample;
1722 ctx->filter_state_buffer[IIR][i] = residual;1727 filter_state[IIR][i] = residual;
1723 1728
1724 sample_buffer += ctx->num_channels;1729 i++;
1730 k++;
1731 if (k >= blocksize) {
1732 k = 0;
1733 j++;
1734 if (j > ctx->cur_restart_interval)
1735 break;
1736 }
1725 }1737 }
1726 1738
1727 sample_buffer = ctx->sample_buffer + channel;1739 for (int l = 0, j = 0; j <= ctx->cur_restart_interval; j++) {
1728 for (int i = 0; i < number_of_samples; i++) {1740 int32_t *sample_buffer = ctx->b[j].decoding_params.sample_buffer[channel];
1729 *sample_buffer = ctx->filter_state_buffer[IIR][i];1741 unsigned int blocksize = ctx->b[j].decoding_params.blocksize;
1730 1742
1731 sample_buffer += ctx->num_channels;1743 for (int i = 0; i < blocksize; i++, l++)
1744 sample_buffer[i] = filter_state[IIR][l];
1732 }1745 }
1733 1746
1734 return 0;1747 return 0;
@@ -1752,18 +1765,21 @@ static void apply_filters(MLPEncodeContext *ctx) · 17 unmodified lines
1752/** Generates two noise channels worth of data. */1765/** Generates two noise channels worth of data. */
1753static void generate_2_noise_channels(MLPEncodeContext *ctx)1766static void generate_2_noise_channels(MLPEncodeContext *ctx)
1754{1767{
1755 int32_t *sample_buffer = ctx->sample_buffer + ctx->num_channels - 2;
1756 RestartHeader *rh = ctx->cur_restart_header;1768 RestartHeader *rh = ctx->cur_restart_header;
1757 uint32_t seed = rh->noisegen_seed;1769 uint32_t seed = rh->noisegen_seed;
1758 1770
1759 for (unsigned int i = 0; i < ctx->number_of_samples; i++) {1771 for (unsigned int j = 0; j <= ctx->cur_restart_interval; j++) {
1760 uint16_t seed_shr7 = seed >> 7;1772 DecodingParams *dp = &ctx->b[j].decoding_params;
1761 *sample_buffer++ = ((int8_t)(seed >> 15)) * (1 << rh->noise_shift);1773 int32_t *sample_buffer2 = dp->sample_buffer[ctx->num_channels-2];
1762 *sample_buffer++ = ((int8_t) seed_shr7) * (1 << rh->noise_shift);1774 int32_t *sample_buffer1 = dp->sample_buffer[ctx->num_channels-1];
1763 1775
1764 seed = (seed << 16) ^ seed_shr7 ^ (seed_shr7 << 5);1776 for (unsigned int i = 0; i < dp->blocksize; i++) {
1777 uint16_t seed_shr7 = seed >> 7;
1778 sample_buffer2[i] = ((int8_t)(seed >> 15)) * (1 << rh->noise_shift);
1779 sample_buffer1[i] = ((int8_t) seed_shr7) * (1 << rh->noise_shift);
1765 1780
1766 sample_buffer += ctx->num_channels - 2;1781 seed = (seed << 16) ^ seed_shr7 ^ (seed_shr7 << 5);
1782 }
1767 }1783 }
1768 1784
1769 rh->noisegen_seed = seed & ((1 << 24)-1);1785 rh->noisegen_seed = seed & ((1 << 24)-1);
@@ -1772,27 +1788,55 @@ static void generate_2_noise_channels(MLPEncodeContext *ctx) · 2 unmodified lines
1772/** Rematrixes all channels using chosen coefficients. */1788/** Rematrixes all channels using chosen coefficients. */
1773static void rematrix_channels(MLPEncodeContext *ctx)1789static void rematrix_channels(MLPEncodeContext *ctx)
1774{1790{
1775 DecodingParams *dp = ctx->cur_decoding_params;1791 DecodingParams *dp1 = &ctx->b[1].decoding_params;
1776 MatrixParams *mp = &dp->matrix_params;1792 MatrixParams *mp1 = &dp1->matrix_params;
1777 int32_t *sample_buffer = ctx->sample_buffer;
1778 unsigned int maxchan = ctx->num_channels;1793 unsigned int maxchan = ctx->num_channels;
1794 int32_t input_samples[MAX_NCHANNELS];
1795 uint8_t lsb_bypass[MAX_MATRICES] = { 0 };
1779 1796
1780 for (unsigned int mat = 0; mat < mp->count; mat++) {1797 for (unsigned int j = 0; j <= ctx->cur_restart_interval; j++) {
1781 unsigned int outch = mp->outch[mat];1798 DecodingParams *dp = &ctx->b[j].decoding_params;
1799 MatrixParams *mp = &dp->matrix_params;
1782 1800
1783 sample_buffer = ctx->sample_buffer;1801 for (unsigned int i = 0; i < dp->blocksize; i++) {
1784 for (unsigned int i = 0; i < ctx->number_of_samples; i++) {1802 for (unsigned int ch = 0; ch < maxchan; ch++)
1785 int64_t accum = 0;1803 input_samples[ch] = dp->sample_buffer[ch][i];
1786 1804
1787 for (unsigned int src_ch = 0; src_ch < maxchan; src_ch++) {1805 for (unsigned int mat = 0; mat < mp1->count; mat++) {
1788 int32_t sample = *(sample_buffer + src_ch);1806 unsigned int outch = mp1->outch[mat];
1789 accum += (int64_t) sample * mp->forco[mat][src_ch];1807 int64_t accum = 0;
1808
1809 for (unsigned int ch = 0; ch < maxchan; ch++) {
1810 int32_t sample = input_samples[ch];
1811
1812 accum += (int64_t)sample * mp1->forco[mat][ch];
1813 }
1814
1815 dp->sample_buffer[outch][i] = accum >> 14;
1790 }1816 }
1791 sample_buffer[outch] = accum >> 14;
1792 1817
1793 sample_buffer += ctx->num_channels;1818 for (unsigned int mat = 0; mat < mp1->count; mat++) {
1819 int8_t *bypassed_lsbs = mp->bypassed_lsbs[mat];
1820 unsigned int outch = mp1->outch[mat];
1821 int64_t accum = 0;
1822 int8_t bit;
1823
1824 for (unsigned int ch = 0; ch < maxchan; ch++) {
1825 int32_t sample = dp->sample_buffer[ch][i];
1826
1827 accum += (int64_t)sample * mp1->coeff[mat][ch];
1828 }
1829
1830 bit = (accum >> 14) != input_samples[outch];
1831
1832 bypassed_lsbs[i] = bit;
1833 lsb_bypass[mat] |= bit;
1834 }
1794 }1835 }
1795 }1836 }
1837
1838 for (unsigned int mat = 0; mat < mp1->count; mat++)
1839 mp1->lsb_bypass[mat] = lsb_bypass[mat];
1796}1840}
1797 1841
1798/****************************************************************************1842/****************************************************************************
@@ -1945,18 +1989,8 @@ static void set_major_params(MLPEncodeContext *ctx) · 146 unmodified lines
1945 1989
1946 ctx->cur_restart_header = &ctx->restart_header;1990 ctx->cur_restart_header = &ctx->restart_header;
1947 1991
1948 ctx->prev_decoding_params = restart_decoding_params;1992 for (unsigned int index = 0; index <= ctx->cur_restart_interval; index++)
1949 ctx->prev_channel_params = restart_channel_params;1993 ctx->b[index].major_params_changed = compare_decoding_params(ctx, index);
1950
1951 for (unsigned int index = 0; index < MAX_HEADER_INTERVAL + 1; index++) {
1952 ctx->cur_decoding_params = &ctx->b[index].major_decoding_params;
1953 ctx->cur_channel_params = ctx->b[index].major_channel_params;
1954
1955 ctx->b[index].major_params_changed = compare_decoding_params(ctx);
1956
1957 ctx->prev_decoding_params = ctx->cur_decoding_params;
1958 ctx->prev_channel_params = ctx->cur_channel_params;
1959 }
1960 1994
1961 ctx->major_number_of_subblocks = ctx->number_of_subblocks;1995 ctx->major_number_of_subblocks = ctx->number_of_subblocks;
1962 ctx->major_filter_state_subblock = 1;1996 ctx->major_filter_state_subblock = 1;
@@ -1966,23 +2000,12 @@ static void set_major_params(MLPEncodeContext *ctx) · 3 unmodified lines
1966static void analyze_sample_buffer(MLPEncodeContext *ctx)2000static void analyze_sample_buffer(MLPEncodeContext *ctx)
1967{2001{
1968 ctx->cur_restart_header = &ctx->restart_header;2002 ctx->cur_restart_header = &ctx->restart_header;
1969 ctx->cur_decoding_params = &ctx->b[1].decoding_params;
1970 ctx->cur_channel_params = ctx->b[1].channel_params;
1971
1972 determine_quant_step_size(ctx);
1973 generate_2_noise_channels(ctx);
1974 lossless_matrix_coeffs (ctx);
1975 rematrix_channels (ctx);
1976 determine_filters (ctx);
1977 apply_filters (ctx);
1978
1979 copy_restart_frame_params(ctx);
1980 2003
1981 /* Copy frame_size from frames 0...max to decoding_params 1...max + 12004 /* Copy frame_size from frames 0...max to decoding_params 1...max + 1
1982 * decoding_params[0] is for the filter state subblock.2005 * decoding_params[0] is for the filter state subblock.
1983 */2006 */
1984 for (unsigned int index = 0; index < ctx->number_of_frames; index++) {2007 for (unsigned int index = 0; index < ctx->number_of_frames; index++) {
1985 DecodingParams *dp = &ctx->b[index + 1].decoding_params;2008 DecodingParams *dp = &ctx->b[index+1].decoding_params;
1986 dp->blocksize = ctx->avctx->frame_size;2009 dp->blocksize = ctx->avctx->frame_size;
1987 }2010 }
1988 /* The official encoder seems to always encode a filter state subblock2011 /* The official encoder seems to always encode a filter state subblock
@@ -1992,29 +2015,27 @@ static void analyze_sample_buffer(MLPEncodeContext *ctx) · 3 unmodified lines
1992 ctx->b[0].decoding_params.blocksize = 8;2015 ctx->b[0].decoding_params.blocksize = 8;
1993 ctx->b[1].decoding_params.blocksize -= 8;2016 ctx->b[1].decoding_params.blocksize -= 8;
1994 2017
1995 for (unsigned int index = 0; index < ctx->number_of_subblocks; index++) {2018 input_to_sample_buffer (ctx);
1996 ctx->cur_decoding_params = &ctx->b[index].decoding_params;2019 generate_2_noise_channels(ctx);
1997 ctx->cur_channel_params = ctx->b[index].channel_params;2020 lossless_matrix_coeffs (ctx);
1998 ctx->cur_best_offset = ctx->b[index].best_offset;2021 rematrix_channels (ctx);
1999 determine_bits(ctx);2022 determine_quant_step_size(ctx);
2000 ctx->sample_buffer += ctx->cur_decoding_params->blocksize * ctx->num_channels;2023 determine_filters (ctx);
2001 }2024 apply_filters (ctx);
2025
2026 copy_restart_frame_params(ctx);
2027
2028 determine_bits(ctx);
2002 2029
2003 set_best_codebook(ctx);2030 set_best_codebook(ctx);
2004}2031}
2005 2032
2006static void process_major_frame(MLPEncodeContext *ctx)2033static void process_major_frame(MLPEncodeContext *ctx)
2007{2034{
2008 ctx->sample_buffer = ctx->major_inout_buffer;
2009
2010 ctx->number_of_frames = ctx->major_number_of_frames;2035 ctx->number_of_frames = ctx->major_number_of_frames;
2011 ctx->number_of_samples = ctx->major_frame_size;
2012 2036
2013 ctx->cur_restart_header = &ctx->restart_header;2037 ctx->cur_restart_header = &ctx->restart_header;
2014 2038
2015 ctx->cur_decoding_params = &ctx->b[1].major_decoding_params;
2016 ctx->cur_channel_params = ctx->b[1].major_channel_params;
2017
2018 generate_2_noise_channels(ctx);2039 generate_2_noise_channels(ctx);
2019 rematrix_channels (ctx);2040 rematrix_channels (ctx);
2020 2041
@@ -2049,17 +2070,9 @@ static int mlp_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 28 unmodified lines
2049 2070
2050 data = frame ? frame->data[0] : NULL;2071 data = frame ? frame->data[0] : NULL;
2051 2072
2052 ctx->frame_index = avctx->frame_num % ctx->max_restart_interval;2073 ctx->frame_index = avctx->frame_num % ctx->cur_restart_interval;
2053 2074
2054 ctx->inout_buffer = ctx->major_inout_buffer2075 if (avctx->frame_num < ctx->cur_restart_interval) {
2055 + ctx->frame_index * ctx->one_sample_buffer_size;
2056
2057 ctx->sample_buffer = ctx->major_scratch_buffer
2058 + ctx->frame_index * ctx->one_sample_buffer_size;
2059
2060 ctx->write_buffer = ctx->inout_buffer;
2061
2062 if (avctx->frame_num < ctx->max_restart_interval) {
2063 if (data)2076 if (data)
2064 goto input_and_return;2077 goto input_and_return;
2065 }2078 }
@@ -2069,13 +2082,10 @@ static int mlp_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 3 unmodified lines
2069 if (restart_frame) {2082 if (restart_frame) {
2070 avpkt->flags |= AV_PKT_FLAG_KEY;2083 avpkt->flags |= AV_PKT_FLAG_KEY;
2071 set_major_params(ctx);2084 set_major_params(ctx);
2072 if (ctx->min_restart_interval != ctx->max_restart_interval)2085 if (ctx->min_restart_interval != ctx->cur_restart_interval)
2073 process_major_frame(ctx);2086 process_major_frame(ctx);
2074 }2087 }
2075 2088
2076 if (ctx->min_restart_interval == ctx->max_restart_interval)
2077 ctx->write_buffer = ctx->sample_buffer;
2078
2079 bytes_written = write_access_unit(ctx, avpkt->data, avpkt->size, restart_frame);2089 bytes_written = write_access_unit(ctx, avpkt->data, avpkt->size, restart_frame);
2080 2090
2081 ctx->output_timing += avctx->frame_size;2091 ctx->output_timing += avctx->frame_size;
@@ -2097,27 +2107,21 @@ input_and_return: · 15 unmodified lines
2097 for (unsigned int seq_index = 0; seq_index < ctx->restart_intervals; seq_index++) {2107 for (unsigned int seq_index = 0; seq_index < ctx->restart_intervals; seq_index++) {
2098 unsigned int number_of_samples;2108 unsigned int number_of_samples;
2099 2109
2100 ctx->sample_buffer = ctx->major_scratch_buffer;
2101 ctx->inout_buffer = ctx->major_inout_buffer;
2102
2103 ctx->number_of_frames = ctx->next_major_number_of_frames;2110 ctx->number_of_frames = ctx->next_major_number_of_frames;
2104 ctx->number_of_subblocks = ctx->next_major_number_of_frames + 1;2111 ctx->number_of_subblocks = ctx->next_major_number_of_frames + 1;
2105 2112
2106 number_of_samples = avctx->frame_size * ctx->number_of_frames;2113 number_of_samples = avctx->frame_size * ctx->number_of_frames;
2107 ctx->number_of_samples = number_of_samples;
2108 2114
2109 for (unsigned int index = 0; index < ctx->b[seq_index].seq_size; index++) {2115 for (unsigned int index = 0; index < ctx->b[seq_index].seq_size; index++) {
2110 clear_channel_params(ctx->b[index].channel_params, channels);2116 clear_channel_params(ctx->b[index].channel_params, channels);
2111 default_decoding_params(ctx, &ctx->b[index].decoding_params);2117 default_decoding_params(ctx, &ctx->b[index].decoding_params);
2112 }2118 }
2113 2119
2114 input_to_sample_buffer(ctx);
2115
2116 if (number_of_samples > 0)2120 if (number_of_samples > 0)
2117 analyze_sample_buffer(ctx);2121 analyze_sample_buffer(ctx);
2118 }2122 }
2119 2123
2120 if (ctx->frame_index == (ctx->max_restart_interval - 1)) {2124 if (ctx->frame_index == (ctx->cur_restart_interval - 1)) {
2121 ctx->major_frame_size = ctx->next_major_frame_size;2125 ctx->major_frame_size = ctx->next_major_frame_size;
2122 ctx->next_major_frame_size = 0;2126 ctx->next_major_frame_size = 0;
2123 ctx->major_number_of_frames = ctx->next_major_number_of_frames;2127 ctx->major_number_of_frames = ctx->next_major_number_of_frames;
@@ -2125,7 +2129,7 @@ input_and_return: · 1 unmodified line
2125 }2129 }
2126 }2130 }
2127 2131
2128 if (!frame && ctx->last_frames < ctx->max_restart_interval - 1)2132 if (!frame && ctx->last_frames < ctx->cur_restart_interval - 1)
2129 avctx->frame_num++;2133 avctx->frame_num++;
2130 2134
2131 if (bytes_written > 0) {2135 if (bytes_written > 0) {
@@ -2149,9 +2153,6 @@ static av_cold int mlp_encode_close(AVCodecContext *avctx) · 17 unmodified lines
2149 MLPEncodeContext *ctx = avctx->priv_data;2153 MLPEncodeContext *ctx = avctx->priv_data;
2150 2154
2151 ff_lpc_end(&ctx->lpc_ctx);2155 ff_lpc_end(&ctx->lpc_ctx);
2152
2153 av_freep(&ctx->major_scratch_buffer);
2154 av_freep(&ctx->major_inout_buffer);
2155 ff_af_queue_close(&ctx->afq);2156 ff_af_queue_close(&ctx->afq);
2156 2157
2157 return 0;2158 return 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t