Implement lsb_bypass for lossless rematrix.
Unified · Split
| @@ -38,6 +38,8 @@ · 37 unmodified lines | ||
| 38 | 38 | #include "mlp.h" |
| 39 | 39 | #include "lpc.h" |
| 40 | 40 | |
| 41 | +#define MAX_NCHANNELS (MAX_CHANNELS + 2) | |
| 42 | + | |
| 41 | 43 | #define MIN_HEADER_INTERVAL 8 |
| 42 | 44 | #define MAX_HEADER_INTERVAL 128 |
| 43 | 45 | |
| @@ -66,11 +68,13 @@ typedef struct MatrixParams { · 22 unmodified lines | ||
| 66 | 68 | uint8_t count; ///< number of matrices to apply |
| 67 | 69 | |
| 68 | 70 | uint8_t outch[MAX_MATRICES]; ///< output channel for each matrix |
| 69 | − int32_t forco[MAX_MATRICES][MAX_CHANNELS+2]; ///< forward coefficients | |
| 70 | − int32_t coeff[MAX_MATRICES][MAX_CHANNELS+2]; ///< decoding coefficients | |
| 71 | + int32_t forco[MAX_MATRICES][MAX_NCHANNELS]; ///< forward coefficients | |
| 72 | + int32_t coeff[MAX_MATRICES][MAX_NCHANNELS]; ///< decoding coefficients | |
| 71 | 73 | uint8_t fbits[MAX_CHANNELS]; ///< fraction bits |
| 72 | 74 | |
| 73 | 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 | 78 | } MatrixParams; |
| 75 | 79 | |
| 76 | 80 | enum ParamFlags { |
| @@ -93,6 +97,7 @@ typedef struct DecodingParams { · 16 unmodified lines | ||
| 93 | 97 | MatrixParams matrix_params; |
| 94 | 98 | |
| 95 | 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 | 101 | } DecodingParams; |
| 97 | 102 | |
| 98 | 103 | typedef struct BestOffset { |
| @@ -111,14 +116,15 @@ typedef struct BestOffset { · 12 unmodified lines | ||
| 111 | 116 | |
| 112 | 117 | typedef struct MLPBlock { |
| 113 | 118 | unsigned int seq_size; |
| 119 | + ChannelParams channel_params[MAX_CHANNELS]; | |
| 114 | 120 | DecodingParams decoding_params; |
| 115 | 121 | int32_t lossless_check_data; ///< Array with lossless_check_data for each access unit. |
| 116 | 122 | unsigned int max_output_bits; ///< largest output bit-depth |
| 117 | 123 | BestOffset best_offset[MAX_CHANNELS][NUM_CODEBOOKS]; |
| 118 | − ChannelParams channel_params[MAX_CHANNELS]; | |
| 119 | 124 | ChannelParams major_channel_params[MAX_CHANNELS]; ///< ChannelParams to be written to bitstream. |
| 120 | 125 | DecodingParams major_decoding_params; ///< DecodingParams to be written to bitstream. |
| 121 | 126 | int major_params_changed; ///< params_changed to be written to bitstream. |
| 127 | + int32_t inout_buffer[MAX_NCHANNELS][MAX_BLOCKSIZE]; | |
| 122 | 128 | } MLPBlock; |
| 123 | 129 | |
| 124 | 130 | typedef struct MLPEncodeContext { |
| @@ -127,6 +133,7 @@ typedef struct MLPEncodeContext { · 2 unmodified lines | ||
| 127 | 133 | |
| 128 | 134 | int max_restart_interval; ///< Max interval of access units in between two major frames. |
| 129 | 135 | int min_restart_interval; ///< Min interval of access units in between two major frames. |
| 136 | + int cur_restart_interval; | |
| 130 | 137 | int lpc_coeff_precision; |
| 131 | 138 | int lpc_type; |
| 132 | 139 | int lpc_passes; |
| @@ -152,11 +159,6 @@ typedef struct MLPEncodeContext { · 19 unmodified lines | ||
| 152 | 159 | int channel_occupancy; |
| 153 | 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 | 162 | int32_t last_frames; ///< Signal last frames. |
| 161 | 163 | |
| 162 | 164 | unsigned int major_number_of_frames; |
| @@ -167,8 +169,6 @@ typedef struct MLPEncodeContext { · 4 unmodified lines | ||
| 167 | 169 | |
| 168 | 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 | 172 | unsigned int restart_intervals; ///< Number of possible major frame sizes. |
| 173 | 173 | |
| 174 | 174 | uint16_t output_timing; ///< Timestamp of current access unit. |
| @@ -185,28 +185,21 @@ typedef struct MLPEncodeContext { · 10 unmodified lines | ||
| 185 | 185 | RestartHeader restart_header; |
| 186 | 186 | |
| 187 | 187 | MLPBlock b[MAX_HEADER_INTERVAL + 1]; |
| 188 | + int32_t filter_state[NUM_FILTERS][MAX_HEADER_INTERVAL * MAX_BLOCKSIZE]; | |
| 188 | 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 | 191 | unsigned int major_cur_subblock_index; |
| 192 | 192 | unsigned int major_filter_state_subblock; |
| 193 | 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 | 195 | RestartHeader *cur_restart_header; |
| 199 | 196 | |
| 200 | 197 | AudioFrameQueue afq; |
| 201 | 198 | |
| 202 | 199 | /* Analysis stage. */ |
| 203 | 200 | unsigned int number_of_frames; |
| 204 | − unsigned int number_of_samples; | |
| 205 | 201 | unsigned int number_of_subblocks; |
| 206 | 202 | |
| 207 | − const ChannelParams *prev_channel_params; | |
| 208 | − const DecodingParams *prev_decoding_params; | |
| 209 | − | |
| 210 | 203 | int shorten_by; |
| 211 | 204 | |
| 212 | 205 | LPCContext lpc_ctx; |
| @@ -278,6 +271,9 @@ static int compare_matrix_params(MLPEncodeContext *ctx, const MatrixParams *prev · 65 unmodified lines | ||
| 278 | 271 | if (prev->outch[mat] != mp->outch[mat]) |
| 279 | 272 | return 1; |
| 280 | 273 | |
| 274 | + if (prev->lsb_bypass[mat] != mp->lsb_bypass[mat]) | |
| 275 | + return 1; | |
| 276 | + | |
| 281 | 277 | for (unsigned int channel = 0; channel < ctx->num_channels; channel++) |
| 282 | 278 | if (prev->coeff[mat][channel] != mp->coeff[mat][channel]) |
| 283 | 279 | return 1; |
| @@ -289,13 +285,14 @@ static int compare_matrix_params(MLPEncodeContext *ctx, const MatrixParams *prev · 5 unmodified lines | ||
| 289 | 285 | /** Compares two DecodingParams and ChannelParams structures to decide if a |
| 290 | 286 | * new decoding params header has to be written. |
| 291 | 287 | */ |
| 292 | −static int compare_decoding_params(MLPEncodeContext *ctx) | |
| 288 | +static int compare_decoding_params(MLPEncodeContext *ctx, | |
| 289 | + unsigned int index) | |
| 293 | 290 | { |
| 294 | − const DecodingParams *prev = ctx->prev_decoding_params; | |
| 295 | − DecodingParams *dp = ctx->cur_decoding_params; | |
| 291 | + const DecodingParams *prev = index ? &ctx->b[index-1].major_decoding_params : restart_decoding_params; | |
| 292 | + DecodingParams *dp = &ctx->b[index].major_decoding_params; | |
| 296 | 293 | const MatrixParams *prev_mp = &prev->matrix_params; |
| 297 | 294 | MatrixParams *mp = &dp->matrix_params; |
| 298 | − RestartHeader *rh = ctx->cur_restart_header; | |
| 295 | + RestartHeader *rh = ctx->cur_restart_header; | |
| 299 | 296 | int retval = 0; |
| 300 | 297 | |
| 301 | 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 | 319 | for (unsigned int ch = rh->min_channel; ch <= rh->max_channel; ch++) { |
| 323 | − const ChannelParams *prev_cp = &ctx->prev_channel_params[ch]; | |
| 324 | − ChannelParams *cp = &ctx->cur_channel_params[ch]; | |
| 320 | + const ChannelParams *prev_cp = index ? &ctx->b[index-1].major_channel_params[ch] : &restart_channel_params[ch]; | |
| 321 | + ChannelParams *cp = &ctx->b[index].major_channel_params[ch]; | |
| 325 | 322 | |
| 326 | 323 | if (!(retval & PARAM_FIR) && |
| 327 | 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 | 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 | 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 | 383 | for (unsigned int index = 0; index < ctx->number_of_subblocks; index++) { |
| 385 | 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 | 388 | for (unsigned int channel = 0; channel < ctx->avctx->ch_layout.nb_channels; channel++) { |
| 390 | 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]; | |
| 393 | − dp->matrix_params.shift[channel] = ctx->cur_decoding_params->matrix_params.shift[channel]; | |
| 391 | + dp->quant_step_size[channel] = ctx->b[1].decoding_params.quant_step_size[channel]; | |
| 392 | + dp->matrix_params.shift[channel] = ctx->b[1].decoding_params.matrix_params.shift[channel]; | |
| 394 | 393 | |
| 395 | 394 | if (index) |
| 396 | 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 | 404 | DecodingParams *dp = decoding_params; |
| 406 | 405 | |
| 407 | 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 | 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 | 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 | 429 | /** Sets default vales in our encoder for a DecodingParams struct. */ |
| 430 | −static void default_decoding_params(MLPEncodeContext *ctx, DecodingParams *decoding_params) | |
| 430 | +static void default_decoding_params(MLPEncodeContext *ctx, DecodingParams *dp) | |
| 431 | 431 | { |
| 432 | − DecodingParams *dp = decoding_params; | |
| 433 | 432 | uint8_t param_presence_flags = 0; |
| 434 | 433 | |
| 435 | − clear_decoding_params(decoding_params); | |
| 434 | + clear_decoding_params(dp); | |
| 436 | 435 | |
| 437 | 436 | param_presence_flags |= PARAM_BLOCKSIZE; |
| 438 | 437 | param_presence_flags |= PARAM_MATRIX; |
| @@ -480,7 +479,6 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx) · 41 unmodified lines | ||
| 480 | 479 | MLPEncodeContext *ctx = avctx->priv_data; |
| 481 | 480 | RestartHeader *const rh = &ctx->restart_header; |
| 482 | 481 | uint64_t channels_present; |
| 483 | − size_t size; | |
| 484 | 482 | int ret; |
| 485 | 483 | |
| 486 | 484 | ctx->avctx = avctx; |
| @@ -555,21 +553,10 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx) · 68 unmodified lines | ||
| 555 | 553 | ctx->input_timing = -avctx->frame_size; |
| 556 | 554 | |
| 557 | 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 | 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 | 560 | ctx->num_substreams = 1; // TODO: change this after adding multi-channel support for TrueHD |
| 574 | 561 | |
| 575 | 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 | 630 | /* FIXME: this works for 1 and 2 channels, but check for more */ |
| 644 | 631 | rh->max_matrix_channel = rh->max_channel; |
| 645 | 632 | |
| 646 | − ctx->number_of_samples = avctx->frame_size * ctx->max_restart_interval; | |
| 647 | − | |
| 648 | − if ((ret = ff_lpc_init(&ctx->lpc_ctx, ctx->number_of_samples, | |
| 633 | + if ((ret = ff_lpc_init(&ctx->lpc_ctx, ctx->avctx->frame_size, | |
| 649 | 634 | MLP_MAX_LPC_ORDER, ctx->lpc_type)) < 0) |
| 650 | 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 | 766 | /** Writes matrix params for all primitive matrices to the bitstream. */ |
| 782 | −static void write_matrix_params(MLPEncodeContext *ctx, PutBitContext *pb) | |
| 767 | +static void write_matrix_params(MLPEncodeContext *ctx, | |
| 768 | + DecodingParams *dp, | |
| 769 | + PutBitContext *pb) | |
| 783 | 770 | { |
| 784 | − DecodingParams *dp = ctx->cur_decoding_params; | |
| 785 | 771 | MatrixParams *mp = &dp->matrix_params; |
| 786 | 772 | |
| 787 | 773 | put_bits(pb, 4, mp->count); |
| @@ -789,7 +775,7 @@ static void write_matrix_params(MLPEncodeContext *ctx, PutBitContext *pb) · 1 unmodified line | ||
| 789 | 775 | for (unsigned int mat = 0; mat < mp->count; mat++) { |
| 790 | 776 | put_bits(pb, 4, mp->outch[mat]); /* matrix_out_ch */ |
| 791 | 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 | 780 | for (unsigned int channel = 0; channel < ctx->num_channels; channel++) { |
| 795 | 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 | 796 | /** Writes filter parameters for one filter to the bitstream. */ |
| 811 | −static void write_filter_params(MLPEncodeContext *ctx, PutBitContext *pb, | |
| 797 | +static void write_filter_params(MLPEncodeContext *ctx, | |
| 798 | + ChannelParams *cp, | |
| 799 | + PutBitContext *pb, | |
| 812 | 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 | 804 | put_bits(pb, 4, fp->order); |
| 817 | 805 | |
| 818 | 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 | 809 | put_bits(pb, 4, fp->shift ); |
| 822 | 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 | 823 | * usually at almost every frame. |
| 836 | 824 | */ |
| 837 | 825 | static 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; | |
| 841 | − RestartHeader *rh = ctx->cur_restart_header; | |
| 829 | + DecodingParams *dp = &ctx->b[subblock_index].major_decoding_params; | |
| 830 | + RestartHeader *rh = ctx->cur_restart_header; | |
| 842 | 831 | MatrixParams *mp = &dp->matrix_params; |
| 843 | 832 | |
| 844 | 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 | 850 | if (dp->param_presence_flags & PARAM_MATRIX) { |
| 862 | 851 | if (params_changed & PARAM_MATRIX) { |
| 863 | 852 | put_bits(pb, 1, 1); |
| 864 | − write_matrix_params(ctx, pb); | |
| 853 | + write_matrix_params(ctx, dp, pb); | |
| 865 | 854 | } else { |
| 866 | 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 | 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 | 882 | if (dp->param_presence_flags & 0xF) { |
| 894 | 883 | put_bits(pb, 1, 1); |
| @@ -896,7 +885,7 @@ static void write_decoding_params(MLPEncodeContext *ctx, PutBitContext *pb, · 1 unmodified line | ||
| 896 | 885 | if (dp->param_presence_flags & PARAM_FIR) { |
| 897 | 886 | if (params_changed & PARAM_FIR) { |
| 898 | 887 | put_bits(pb, 1, 1); |
| 899 | − write_filter_params(ctx, pb, ch, FIR); | |
| 888 | + write_filter_params(ctx, cp, pb, ch, FIR); | |
| 900 | 889 | } else { |
| 901 | 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 | 894 | if (dp->param_presence_flags & PARAM_IIR) { |
| 906 | 895 | if (params_changed & PARAM_IIR) { |
| 907 | 896 | put_bits(pb, 1, 1); |
| 908 | − write_filter_params(ctx, pb, ch, IIR); | |
| 897 | + write_filter_params(ctx, cp, pb, ch, IIR); | |
| 909 | 898 | } else { |
| 910 | 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 | 923 | /** Writes the residuals to the bitstream. That is, the VLC codes from the |
| 935 | 924 | * codebooks (if any is used), and then the residual. |
| 936 | 925 | */ |
| 937 | −static void write_block_data(MLPEncodeContext *ctx, PutBitContext *pb) | |
| 926 | +static void write_block_data(MLPEncodeContext *ctx, PutBitContext *pb, | |
| 927 | + unsigned int subblock_index) | |
| 938 | 928 | { |
| 939 | − DecodingParams *dp = ctx->cur_decoding_params; | |
| 940 | − RestartHeader *rh = ctx->cur_restart_header; | |
| 941 | − int32_t *sample_buffer = ctx->write_buffer; | |
| 929 | + RestartHeader *rh = ctx->cur_restart_header; | |
| 930 | + DecodingParams *dp = &ctx->b[subblock_index].major_decoding_params; | |
| 931 | + MatrixParams *mp = &dp->matrix_params; | |
| 942 | 932 | int32_t sign_huff_offset[MAX_CHANNELS]; |
| 943 | 933 | int codebook_index [MAX_CHANNELS]; |
| 944 | 934 | int lsb_bits [MAX_CHANNELS]; |
| 945 | 935 | |
| 946 | 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 | 938 | int sign_shift; |
| 949 | 939 | |
| 950 | 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 | 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 | 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 | 966 | sample -= sign_huff_offset[ch]; |
| 968 | 967 | |
| 969 | 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 | 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 | 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 | 985 | int32_t *lossless_check_data = &ctx->b[ctx->frame_index].lossless_check_data; |
| 990 | 986 | unsigned int cur_subblock_index = ctx->major_cur_subblock_index; |
| 991 | 987 | unsigned int num_subblocks = ctx->major_filter_state_subblock; |
| 992 | − RestartHeader *rh = &ctx->restart_header; | |
| 988 | + RestartHeader *rh = &ctx->restart_header; | |
| 993 | 989 | int substr_restart_frame = restart_frame; |
| 994 | 990 | uint8_t parity, checksum; |
| 995 | 991 | PutBitContext pb; |
| @@ -1001,12 +997,7 @@ static uint8_t *write_substr(MLPEncodeContext *ctx, uint8_t *buf, int buf_size, · 5 unmodified lines | ||
| 1001 | 997 | init_put_bits(&pb, buf, buf_size); |
| 1002 | 998 | |
| 1003 | 999 | for (unsigned int subblock = 0; subblock <= num_subblocks; subblock++) { |
| 1004 | − unsigned int 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; | |
| 1000 | + unsigned int subblock_index = cur_subblock_index++; | |
| 1010 | 1001 | |
| 1011 | 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 | 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 | 1018 | } else { |
| 1027 | 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 | 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 | 1151 | const int32_t *samples_32 = (const int32_t *) samples; |
| 1160 | 1152 | const int16_t *samples_16 = (const int16_t *) samples; |
| 1161 | 1153 | RestartHeader *rh = &ctx->restart_header; |
| 1162 | − int32_t *sample_buffer = ctx->inout_buffer; | |
| 1163 | 1154 | int32_t temp_lossless_check_data = 0; |
| 1164 | 1155 | uint32_t bits = 0; |
| 1165 | 1156 | |
| 1166 | 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 | 1160 | int32_t sample; |
| 1169 | 1161 | |
| 1170 | 1162 | sample = is24 ? *samples_32++ >> 8 : *samples_16++ * 256; |
| 1171 | 1163 | |
| 1172 | 1164 | bits = FFMAX(number_sbits(sample), bits); |
| 1173 | 1165 | |
| 1174 | − temp_lossless_check_data ^= (sample & 0x00ffffff) << channel; | |
| 1175 | − *sample_buffer++ = sample; | |
| 1166 | + temp_lossless_check_data ^= (sample & 0x00ffffff) << ch; | |
| 1167 | + sample_buffer[i] = sample; | |
| 1176 | 1168 | } |
| 1177 | − | |
| 1178 | − sample_buffer += 2; /* noise channels */ | |
| 1179 | 1169 | } |
| 1180 | 1170 | |
| 1181 | 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 | |
| 1192 | 1182 | static void input_to_sample_buffer(MLPEncodeContext *ctx) |
| 1193 | 1183 | { |
| 1194 | − int32_t *sample_buffer = ctx->sample_buffer; | |
| 1195 | − | |
| 1196 | 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; | |
| 1198 | − int32_t *input_buffer = ctx->inout_buffer + cur_index * ctx->one_sample_buffer_size; | |
| 1199 | − | |
| 1200 | − for (unsigned int i = 0; i < ctx->avctx->frame_size; i++) { | |
| 1201 | − for (unsigned int channel = 0; channel < ctx->avctx->ch_layout.nb_channels; channel++) | |
| 1202 | − *sample_buffer++ = *input_buffer++; | |
| 1203 | − sample_buffer += 2; /* noise_channels */ | |
| 1204 | − input_buffer += 2; /* noise_channels */ | |
| 1185 | + unsigned int cur_index = (ctx->frame_index + index + 1) % ctx->cur_restart_interval; | |
| 1186 | + DecodingParams *dp = &ctx->b[index+1].decoding_params; | |
| 1187 | + | |
| 1188 | + for (unsigned int ch = 0; ch < ctx->avctx->ch_layout.nb_channels; ch++) { | |
| 1189 | + const int32_t *input_buffer = ctx->b[cur_index].inout_buffer[ch]; | |
| 1190 | + int32_t *sample_buffer = dp->sample_buffer[ch]; | |
| 1191 | + int off = 0; | |
| 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 | */ |
| 1222 | 1220 | static void determine_quant_step_size(MLPEncodeContext *ctx) |
| 1223 | 1221 | { |
| 1224 | − DecodingParams *dp = ctx->cur_decoding_params; | |
| 1225 | − RestartHeader *rh = ctx->cur_restart_header; | |
| 1226 | − MatrixParams *mp = &dp->matrix_params; | |
| 1227 | − int32_t *sample_buffer = ctx->sample_buffer; | |
| 1222 | + RestartHeader *rh = ctx->cur_restart_header; | |
| 1223 | + DecodingParams *dp1 = &ctx->b[1].decoding_params; | |
| 1228 | 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++) { | |
| 1233 | − for (unsigned int channel = 0; channel <= rh->max_channel; channel++) | |
| 1234 | − sample_mask[channel] |= *sample_buffer++; | |
| 1228 | + for (unsigned int j = 0; j <= ctx->cur_restart_interval; j++) { | |
| 1229 | + DecodingParams *dp = &ctx->b[j].decoding_params; | |
| 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 | 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 | 1243 | /** 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 | 1271 | unsigned int channel, unsigned int filter, |
| 1272 | 1272 | int clear_filter) |
| 1273 | 1273 | { |
| 1274 | − ChannelParams *cp = &ctx->cur_channel_params[channel]; | |
| 1274 | + ChannelParams *cp = &ctx->b[1].channel_params[channel]; | |
| 1275 | 1275 | FilterParams *fp = &cp->filter_params[filter]; |
| 1276 | 1276 | |
| 1277 | 1277 | if (clear_filter) { |
| @@ -1280,21 +1280,26 @@ static void set_filter_params(MLPEncodeContext *ctx, · 2 unmodified lines | ||
| 1280 | 1280 | fp->order = 0; |
| 1281 | 1281 | } else if (filter == FIR) { |
| 1282 | 1282 | const int max_order = MAX_FIR_ORDER; |
| 1283 | − int32_t *sample_buffer = ctx->sample_buffer + channel; | |
| 1284 | 1283 | int32_t coefs[MAX_LPC_ORDER][MAX_LPC_ORDER]; |
| 1285 | 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 | 1286 | int shift[MAX_LPC_ORDER]; |
| 1288 | 1287 | int order; |
| 1289 | 1288 | |
| 1290 | − for (unsigned int i = 0; i < ctx->number_of_samples; i++) { | |
| 1291 | − *lpc_samples++ = *sample_buffer; | |
| 1292 | − sample_buffer += ctx->num_channels; | |
| 1289 | + for (unsigned int j = 0; j <= ctx->cur_restart_interval; j++) { | |
| 1290 | + DecodingParams *dp = &ctx->b[j].decoding_params; | |
| 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 | 1298 | order = ff_lpc_calc_coefs(&ctx->lpc_ctx, ctx->lpc_sample_buffer, |
| 1296 | − ctx->number_of_samples, MLP_MIN_LPC_ORDER, | |
| 1297 | − max_order, ctx->lpc_coeff_precision, coefs, shift, ctx->lpc_type, ctx->lpc_passes, | |
| 1299 | + lpc_samples - ctx->lpc_sample_buffer, | |
| 1300 | + MLP_MIN_LPC_ORDER, max_order, | |
| 1301 | + ctx->lpc_coeff_precision, | |
| 1302 | + coefs, shift, ctx->lpc_type, ctx->lpc_passes, | |
| 1298 | 1303 | ctx->prediction_order, MLP_MIN_LPC_SHIFT, |
| 1299 | 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 | 1331 | MatrixParams *mp, |
| 1327 | 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 | 1334 | int first = 1, x, x0; |
| 1332 | − const int32_t *ch[2]; | |
| 1333 | 1335 | int64_t g = 0, g0 = 0; |
| 1334 | 1336 | |
| 1335 | − ch[0] = ctx->sample_buffer + ch0; | |
| 1336 | − ch[1] = ctx->sample_buffer + ch1; | |
| 1337 | + for (int j = 0; j <= ctx->cur_restart_interval; j++) { | |
| 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++) { | |
| 1339 | − int64_t c0, c1; | |
| 1340 | − int32_t a0, a1; | |
| 1341 | + ch[0] = dp->sample_buffer[ch0]; | |
| 1342 | + ch[1] = dp->sample_buffer[ch1]; | |
| 1341 | 1343 | |
| 1342 | − c0 = ch[0][i]; | |
| 1343 | − c1 = ch[1][i]; | |
| 1344 | + for (int i = 0; i < dp->blocksize; i++) { | |
| 1345 | + int64_t c0, c1; | |
| 1346 | + int32_t a0, a1; | |
| 1344 | 1347 | |
| 1345 | − if (!c0 && !c1) | |
| 1346 | − goto next; | |
| 1348 | + c0 = ch[0][i]; | |
| 1349 | + c1 = ch[1][i]; | |
| 1347 | 1350 | |
| 1348 | − if (!c0 || !c1) { | |
| 1349 | − g0 = 0; | |
| 1350 | − break; | |
| 1351 | − } | |
| 1351 | + if (!c0 && !c1) | |
| 1352 | + continue; | |
| 1352 | 1353 | |
| 1353 | − a0 = FFABS(c0); | |
| 1354 | − a1 = FFABS(c1); | |
| 1354 | + if (!c0 || !c1) { | |
| 1355 | + g0 = 0; | |
| 1356 | + goto end; | |
| 1357 | + } | |
| 1355 | 1358 | |
| 1356 | − if (a0 >= a1) { | |
| 1357 | − g = (c1 * (1 << 14)) / c0; | |
| 1358 | − x = ch1; | |
| 1359 | − } else if (a0 < a1) { | |
| 1360 | − g = (c0 * (1 << 14)) / c1; | |
| 1361 | − x = ch0; | |
| 1362 | − } | |
| 1359 | + a0 = FFABS(c0); | |
| 1360 | + a1 = FFABS(c1); | |
| 1363 | 1361 | |
| 1364 | − if (first) { | |
| 1365 | − g0 = g; | |
| 1366 | − x0 = x; | |
| 1367 | − first = 0; | |
| 1368 | − } else if (g != g0 || x != x0) { | |
| 1369 | − g0 = 0; | |
| 1370 | − break; | |
| 1371 | − } | |
| 1362 | + if (a0 >= a1) { | |
| 1363 | + g = (c1 * (1 << 14)) / c0; | |
| 1364 | + x = ch1; | |
| 1365 | + } else if (a0 < a1) { | |
| 1366 | + g = (c0 * (1 << 14)) / c1; | |
| 1367 | + x = ch0; | |
| 1368 | + } | |
| 1372 | 1369 | |
| 1373 | −next: | |
| 1374 | − i += num_channels; | |
| 1370 | + if (first) { | |
| 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 | } |
| 1380 | +end: | |
| 1376 | 1381 | |
| 1377 | 1382 | if (g0) { |
| 1378 | 1383 | mp->outch[0] = (x0 == ch0) ? ch0 : ch1; |
| @@ -1383,9 +1388,6 @@ next: · 4 unmodified lines | ||
| 1383 | 1388 | mp->forco[0][ch0] = 0; |
| 1384 | 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 | 1391 | return 1; |
| 1390 | 1392 | } |
| 1391 | 1393 | |
| @@ -1395,9 +1397,10 @@ next: · 3 unmodified lines | ||
| 1395 | 1397 | /** Determines how many fractional bits are needed to encode matrix |
| 1396 | 1398 | * coefficients. Also shifts the coefficients to fit within 2.14 bits. |
| 1397 | 1399 | */ |
| 1398 | −static void code_matrix_coeffs(MLPEncodeContext *ctx, unsigned int mat) | |
| 1400 | +static void code_matrix_coeffs(MLPEncodeContext *ctx, | |
| 1401 | + DecodingParams *dp, | |
| 1402 | + unsigned int mat) | |
| 1399 | 1403 | { |
| 1400 | − DecodingParams *dp = ctx->cur_decoding_params; | |
| 1401 | 1404 | MatrixParams *mp = &dp->matrix_params; |
| 1402 | 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 | 1414 | /** Determines best coefficients to use for the lossless matrix. */ |
| 1412 | 1415 | static void lossless_matrix_coeffs(MLPEncodeContext *ctx) |
| 1413 | 1416 | { |
| 1414 | − DecodingParams *dp = ctx->cur_decoding_params; | |
| 1417 | + DecodingParams *dp = &ctx->b[1].decoding_params; | |
| 1415 | 1418 | MatrixParams *mp = &dp->matrix_params; |
| 1416 | − unsigned int shift = 0; | |
| 1417 | 1419 | |
| 1418 | 1420 | mp->count = 0; |
| 1419 | 1421 | if (ctx->num_channels - 2 != 2) |
| @@ -1422,10 +1424,7 @@ static void lossless_matrix_coeffs(MLPEncodeContext *ctx) · 2 unmodified lines | ||
| 1422 | 1424 | mp->count = estimate_coeff(ctx, mp, 0, 1); |
| 1423 | 1425 | |
| 1424 | 1426 | for (int mat = 0; mat < mp->count; mat++) |
| 1425 | − code_matrix_coeffs(ctx, mat); | |
| 1426 | − | |
| 1427 | − for (unsigned int channel = 0; channel < ctx->num_channels; channel++) | |
| 1428 | − mp->shift[channel] = shift; | |
| 1427 | + code_matrix_coeffs(ctx, dp, mat); | |
| 1429 | 1428 | } |
| 1430 | 1429 | |
| 1431 | 1430 | /** 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 | 1440 | * codebooks and a specified offset. |
| 1442 | 1441 | */ |
| 1443 | 1442 | static void no_codebook_bits_offset(MLPEncodeContext *ctx, |
| 1443 | + DecodingParams *dp, | |
| 1444 | 1444 | unsigned int channel, int32_t offset, |
| 1445 | 1445 | int32_t min, int32_t max, |
| 1446 | 1446 | BestOffset *bo) |
| 1447 | 1447 | { |
| 1448 | − DecodingParams *dp = ctx->cur_decoding_params; | |
| 1449 | 1448 | int32_t unsign = 0; |
| 1450 | 1449 | int lsb_bits; |
| 1451 | 1450 | |
| @@ -1470,11 +1469,11 @@ static void no_codebook_bits_offset(MLPEncodeContext *ctx, · 18 unmodified lines | ||
| 1470 | 1469 | * codebooks. |
| 1471 | 1470 | */ |
| 1472 | 1471 | static void no_codebook_bits(MLPEncodeContext *ctx, |
| 1472 | + DecodingParams *dp, | |
| 1473 | 1473 | unsigned int channel, |
| 1474 | 1474 | int32_t min, int32_t max, |
| 1475 | 1475 | BestOffset *bo) |
| 1476 | 1476 | { |
| 1477 | − DecodingParams *dp = ctx->cur_decoding_params; | |
| 1478 | 1477 | int32_t offset, unsign = 0; |
| 1479 | 1478 | uint8_t lsb_bits; |
| 1480 | 1479 | |
| @@ -1507,14 +1506,14 @@ static void no_codebook_bits(MLPEncodeContext *ctx, · 26 unmodified lines | ||
| 1507 | 1506 | * given codebook and a given offset. |
| 1508 | 1507 | */ |
| 1509 | 1508 | static inline void codebook_bits_offset(MLPEncodeContext *ctx, |
| 1509 | + DecodingParams *dp, | |
| 1510 | 1510 | unsigned int channel, int codebook, |
| 1511 | 1511 | int32_t sample_min, int32_t sample_max, |
| 1512 | 1512 | int32_t offset, BestOffset *bo) |
| 1513 | 1513 | { |
| 1514 | 1514 | int32_t codebook_min = codebook_extremes[codebook][0]; |
| 1515 | 1515 | int32_t codebook_max = codebook_extremes[codebook][1]; |
| 1516 | − int32_t *sample_buffer = ctx->sample_buffer + channel; | |
| 1517 | − DecodingParams *dp = ctx->cur_decoding_params; | |
| 1516 | + int32_t *sample_buffer = dp->sample_buffer[channel]; | |
| 1518 | 1517 | int codebook_offset = 7 + (2 - codebook); |
| 1519 | 1518 | int32_t unsign_offset = offset; |
| 1520 | 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 | 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 | 1543 | int temp_min, temp_max; |
| 1545 | 1544 | |
| 1546 | 1545 | sample -= unsign_offset; |
| @@ -1556,8 +1555,6 @@ static inline void codebook_bits_offset(MLPEncodeContext *ctx, · 9 unmodified lines | ||
| 1556 | 1555 | sample >>= lsb_bits; |
| 1557 | 1556 | |
| 1558 | 1557 | bitcount += ff_mlp_huffman_tables[codebook][sample + codebook_offset][1]; |
| 1559 | − | |
| 1560 | − sample_buffer += ctx->num_channels; | |
| 1561 | 1558 | } |
| 1562 | 1559 | |
| 1563 | 1560 | bo->offset = offset; |
| @@ -1571,6 +1568,7 @@ static inline void codebook_bits_offset(MLPEncodeContext *ctx, · 7 unmodified lines | ||
| 1571 | 1568 | * given codebook. Searches for the best offset to minimize the bits. |
| 1572 | 1569 | */ |
| 1573 | 1570 | static inline void codebook_bits(MLPEncodeContext *ctx, |
| 1571 | + DecodingParams *dp, | |
| 1574 | 1572 | unsigned int channel, int codebook, |
| 1575 | 1573 | int offset, int32_t min, int32_t max, |
| 1576 | 1574 | BestOffset *bo, int direction) |
| @@ -1585,7 +1583,7 @@ static inline void codebook_bits(MLPEncodeContext *ctx, · 8 unmodified lines | ||
| 1585 | 1583 | while (offset <= offset_max && offset >= offset_min) { |
| 1586 | 1584 | BestOffset temp_bo; |
| 1587 | 1585 | |
| 1588 | − codebook_bits_offset(ctx, channel, codebook, | |
| 1586 | + codebook_bits_offset(ctx, dp, channel, codebook, | |
| 1589 | 1587 | min, max, offset, |
| 1590 | 1588 | &temp_bo); |
| 1591 | 1589 | |
| @@ -1612,56 +1610,57 @@ static inline void codebook_bits(MLPEncodeContext *ctx, · 20 unmodified lines | ||
| 1612 | 1610 | */ |
| 1613 | 1611 | static void determine_bits(MLPEncodeContext *ctx) |
| 1614 | 1612 | { |
| 1615 | − DecodingParams *dp = ctx->cur_decoding_params; | |
| 1616 | − RestartHeader *rh = ctx->cur_restart_header; | |
| 1617 | − | |
| 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; | |
| 1613 | + RestartHeader *rh = ctx->cur_restart_header; | |
| 1614 | + for (unsigned int index = 0; index < ctx->number_of_subblocks; index++) { | |
| 1615 | + DecodingParams *dp = &ctx->b[index].decoding_params; | |
| 1637 | 1616 | |
| 1638 | − /* If filtering is used, we always set the offset to zero, otherwise | |
| 1639 | − * we search for the offset that minimizes the bitcount. */ | |
| 1640 | − if (no_filters_used) { | |
| 1641 | − no_codebook_bits(ctx, channel, min, max, &ctx->cur_best_offset[channel][0]); | |
| 1642 | − offset = av_clip(average, HUFF_OFFSET_MIN, HUFF_OFFSET_MAX); | |
| 1643 | − } else { | |
| 1644 | − no_codebook_bits_offset(ctx, channel, offset, min, max, &ctx->cur_best_offset[channel][0]); | |
| 1645 | − } | |
| 1617 | + for (unsigned int channel = 0; channel <= rh->max_channel; channel++) { | |
| 1618 | + ChannelParams *cp = &ctx->b[index].channel_params[channel]; | |
| 1619 | + int32_t *sample_buffer = dp->sample_buffer[channel]; | |
| 1620 | + int32_t min = INT32_MAX, max = INT32_MIN; | |
| 1621 | + int no_filters_used = !cp->filter_params[FIR].order; | |
| 1622 | + int average = 0; | |
| 1623 | + int offset = 0; | |
| 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++) { | |
| 1648 | − BestOffset temp_bo = { 0, UINT32_MAX, 0, 0, 0, }; | |
| 1649 | − int32_t offset_max; | |
| 1645 | + for (int i = 1; i < NUM_CODEBOOKS; i++) { | |
| 1646 | + BestOffset temp_bo = { 0, UINT32_MAX, 0, 0, 0, }; | |
| 1647 | + int32_t offset_max; | |
| 1650 | 1648 | |
| 1651 | − codebook_bits_offset(ctx, channel, i - 1, | |
| 1652 | − min, max, offset, | |
| 1653 | − &temp_bo); | |
| 1649 | + codebook_bits_offset(ctx, dp, channel, i - 1, | |
| 1650 | + min, max, offset, | |
| 1651 | + &temp_bo); | |
| 1654 | 1652 | |
| 1655 | − if (no_filters_used) { | |
| 1656 | − offset_max = temp_bo.max; | |
| 1653 | + if (no_filters_used) { | |
| 1654 | + offset_max = temp_bo.max; | |
| 1657 | 1655 | |
| 1658 | − codebook_bits(ctx, channel, i - 1, temp_bo.min - 1, | |
| 1659 | − min, max, &temp_bo, 0); | |
| 1660 | − codebook_bits(ctx, channel, i - 1, offset_max + 1, | |
| 1661 | − min, max, &temp_bo, 1); | |
| 1662 | − } | |
| 1656 | + codebook_bits(ctx, dp, channel, i - 1, temp_bo.min - 1, | |
| 1657 | + min, max, &temp_bo, 0); | |
| 1658 | + codebook_bits(ctx, dp, channel, i - 1, offset_max + 1, | |
| 1659 | + min, max, &temp_bo, 1); | |
| 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 | */ |
| 1683 | 1682 | static 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 | 1686 | FilterParams *fp[NUM_FILTERS] = { &cp->filter_params[FIR], |
| 1687 | 1687 | &cp->filter_params[IIR], }; |
| 1688 | 1688 | const uint8_t codebook = cp->codebook; |
| 1689 | − int32_t mask = MSB_MASK(ctx->cur_decoding_params->quant_step_size[channel]); | |
| 1690 | − int32_t *sample_buffer = ctx->sample_buffer + channel; | |
| 1691 | − unsigned int number_of_samples = ctx->number_of_samples; | |
| 1689 | + int32_t mask = MSB_MASK(dp->quant_step_size[channel]); | |
| 1690 | + int32_t *sample_buffer = ctx->b[0].decoding_params.sample_buffer[channel]; | |
| 1692 | 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++) { | |
| 1695 | − ctx->filter_state_buffer[FIR][i] = *sample_buffer; | |
| 1696 | − ctx->filter_state_buffer[IIR][i] = *sample_buffer; | |
| 1697 | − | |
| 1698 | − sample_buffer += ctx->num_channels; | |
| 1696 | + for (i = 0; i < 8; i++) { | |
| 1697 | + filter_state[FIR][i] = sample_buffer[i]; | |
| 1698 | + filter_state[IIR][i] = sample_buffer[i]; | |
| 1699 | 1699 | } |
| 1700 | 1700 | |
| 1701 | − for (int i = 8; i < number_of_samples; i++) { | |
| 1702 | − int32_t sample = *sample_buffer; | |
| 1701 | + while (1) { | |
| 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 | 1705 | int64_t accum = 0; |
| 1704 | − int32_t residual; | |
| 1706 | + | |
| 1707 | + if (!blocksize) | |
| 1708 | + break; | |
| 1705 | 1709 | |
| 1706 | 1710 | for (int filter = 0; filter < NUM_FILTERS; filter++) { |
| 1707 | 1711 | int32_t *fcoeff = cp->coeff[filter]; |
| 1708 | 1712 | for (unsigned int order = 0; order < fp[filter]->order; order++) |
| 1709 | − accum += (int64_t)ctx->filter_state_buffer[filter][i - 1 - order] * | |
| 1710 | − fcoeff[order]; | |
| 1713 | + accum += (int64_t)filter_state[filter][i - 1 - order] * | |
| 1714 | + fcoeff[order]; | |
| 1711 | 1715 | } |
| 1712 | 1716 | |
| 1717 | + sample = sample_buffer[k]; | |
| 1713 | 1718 | accum >>= filter_shift; |
| 1714 | 1719 | residual = sample - (accum & mask); |
| 1715 | 1720 | |
| @@ -1718,17 +1723,25 @@ static int apply_filter(MLPEncodeContext *ctx, unsigned int channel) · 2 unmodified lines | ||
| 1718 | 1723 | residual > SAMPLE_MAX(24))) |
| 1719 | 1724 | return -1; |
| 1720 | 1725 | |
| 1721 | − ctx->filter_state_buffer[FIR][i] = sample; | |
| 1722 | − ctx->filter_state_buffer[IIR][i] = residual; | |
| 1726 | + filter_state[FIR][i] = sample; | |
| 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; | |
| 1728 | − for (int i = 0; i < number_of_samples; i++) { | |
| 1729 | − *sample_buffer = ctx->filter_state_buffer[IIR][i]; | |
| 1739 | + for (int l = 0, j = 0; j <= ctx->cur_restart_interval; j++) { | |
| 1740 | + int32_t *sample_buffer = ctx->b[j].decoding_params.sample_buffer[channel]; | |
| 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 | 1747 | return 0; |
| @@ -1752,18 +1765,21 @@ static void apply_filters(MLPEncodeContext *ctx) · 17 unmodified lines | ||
| 1752 | 1765 | /** Generates two noise channels worth of data. */ |
| 1753 | 1766 | static void generate_2_noise_channels(MLPEncodeContext *ctx) |
| 1754 | 1767 | { |
| 1755 | − int32_t *sample_buffer = ctx->sample_buffer + ctx->num_channels - 2; | |
| 1756 | 1768 | RestartHeader *rh = ctx->cur_restart_header; |
| 1757 | 1769 | uint32_t seed = rh->noisegen_seed; |
| 1758 | 1770 | |
| 1759 | − for (unsigned int i = 0; i < ctx->number_of_samples; i++) { | |
| 1760 | − uint16_t seed_shr7 = seed >> 7; | |
| 1761 | − *sample_buffer++ = ((int8_t)(seed >> 15)) * (1 << rh->noise_shift); | |
| 1762 | − *sample_buffer++ = ((int8_t) seed_shr7) * (1 << rh->noise_shift); | |
| 1771 | + for (unsigned int j = 0; j <= ctx->cur_restart_interval; j++) { | |
| 1772 | + DecodingParams *dp = &ctx->b[j].decoding_params; | |
| 1773 | + int32_t *sample_buffer2 = dp->sample_buffer[ctx->num_channels-2]; | |
| 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 | 1785 | rh->noisegen_seed = seed & ((1 << 24)-1); |
| @@ -1772,27 +1788,55 @@ static void generate_2_noise_channels(MLPEncodeContext *ctx) · 2 unmodified lines | ||
| 1772 | 1788 | /** Rematrixes all channels using chosen coefficients. */ |
| 1773 | 1789 | static void rematrix_channels(MLPEncodeContext *ctx) |
| 1774 | 1790 | { |
| 1775 | − DecodingParams *dp = ctx->cur_decoding_params; | |
| 1776 | − MatrixParams *mp = &dp->matrix_params; | |
| 1777 | − int32_t *sample_buffer = ctx->sample_buffer; | |
| 1791 | + DecodingParams *dp1 = &ctx->b[1].decoding_params; | |
| 1792 | + MatrixParams *mp1 = &dp1->matrix_params; | |
| 1778 | 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++) { | |
| 1781 | − unsigned int outch = mp->outch[mat]; | |
| 1797 | + for (unsigned int j = 0; j <= ctx->cur_restart_interval; j++) { | |
| 1798 | + DecodingParams *dp = &ctx->b[j].decoding_params; | |
| 1799 | + MatrixParams *mp = &dp->matrix_params; | |
| 1782 | 1800 | |
| 1783 | − sample_buffer = ctx->sample_buffer; | |
| 1784 | − for (unsigned int i = 0; i < ctx->number_of_samples; i++) { | |
| 1785 | − int64_t accum = 0; | |
| 1801 | + for (unsigned int i = 0; i < dp->blocksize; i++) { | |
| 1802 | + for (unsigned int ch = 0; ch < maxchan; ch++) | |
| 1803 | + input_samples[ch] = dp->sample_buffer[ch][i]; | |
| 1786 | 1804 | |
| 1787 | − for (unsigned int src_ch = 0; src_ch < maxchan; src_ch++) { | |
| 1788 | − int32_t sample = *(sample_buffer + src_ch); | |
| 1789 | − accum += (int64_t) sample * mp->forco[mat][src_ch]; | |
| 1805 | + for (unsigned int mat = 0; mat < mp1->count; mat++) { | |
| 1806 | + unsigned int outch = mp1->outch[mat]; | |
| 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 | 1990 | ctx->cur_restart_header = &ctx->restart_header; |
| 1947 | 1991 | |
| 1948 | − ctx->prev_decoding_params = restart_decoding_params; | |
| 1949 | − ctx->prev_channel_params = restart_channel_params; | |
| 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 | − } | |
| 1992 | + for (unsigned int index = 0; index <= ctx->cur_restart_interval; index++) | |
| 1993 | + ctx->b[index].major_params_changed = compare_decoding_params(ctx, index); | |
| 1960 | 1994 | |
| 1961 | 1995 | ctx->major_number_of_subblocks = ctx->number_of_subblocks; |
| 1962 | 1996 | ctx->major_filter_state_subblock = 1; |
| @@ -1966,23 +2000,12 @@ static void set_major_params(MLPEncodeContext *ctx) · 3 unmodified lines | ||
| 1966 | 2000 | static void analyze_sample_buffer(MLPEncodeContext *ctx) |
| 1967 | 2001 | { |
| 1968 | 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 | 2004 | /* Copy frame_size from frames 0...max to decoding_params 1...max + 1 |
| 1982 | 2005 | * decoding_params[0] is for the filter state subblock. |
| 1983 | 2006 | */ |
| 1984 | 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 | 2009 | dp->blocksize = ctx->avctx->frame_size; |
| 1987 | 2010 | } |
| 1988 | 2011 | /* 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 | 2015 | ctx->b[0].decoding_params.blocksize = 8; |
| 1993 | 2016 | ctx->b[1].decoding_params.blocksize -= 8; |
| 1994 | 2017 | |
| 1995 | − for (unsigned int index = 0; index < ctx->number_of_subblocks; index++) { | |
| 1996 | − ctx->cur_decoding_params = &ctx->b[index].decoding_params; | |
| 1997 | − ctx->cur_channel_params = ctx->b[index].channel_params; | |
| 1998 | − ctx->cur_best_offset = ctx->b[index].best_offset; | |
| 1999 | − determine_bits(ctx); | |
| 2000 | − ctx->sample_buffer += ctx->cur_decoding_params->blocksize * ctx->num_channels; | |
| 2001 | − } | |
| 2018 | + input_to_sample_buffer (ctx); | |
| 2019 | + generate_2_noise_channels(ctx); | |
| 2020 | + lossless_matrix_coeffs (ctx); | |
| 2021 | + rematrix_channels (ctx); | |
| 2022 | + determine_quant_step_size(ctx); | |
| 2023 | + determine_filters (ctx); | |
| 2024 | + apply_filters (ctx); | |
| 2025 | + | |
| 2026 | + copy_restart_frame_params(ctx); | |
| 2027 | + | |
| 2028 | + determine_bits(ctx); | |
| 2002 | 2029 | |
| 2003 | 2030 | set_best_codebook(ctx); |
| 2004 | 2031 | } |
| 2005 | 2032 | |
| 2006 | 2033 | static void process_major_frame(MLPEncodeContext *ctx) |
| 2007 | 2034 | { |
| 2008 | − ctx->sample_buffer = ctx->major_inout_buffer; | |
| 2009 | − | |
| 2010 | 2035 | ctx->number_of_frames = ctx->major_number_of_frames; |
| 2011 | − ctx->number_of_samples = ctx->major_frame_size; | |
| 2012 | 2036 | |
| 2013 | 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 | 2039 | generate_2_noise_channels(ctx); |
| 2019 | 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 | 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_buffer | |
| 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) { | |
| 2075 | + if (avctx->frame_num < ctx->cur_restart_interval) { | |
| 2063 | 2076 | if (data) |
| 2064 | 2077 | goto input_and_return; |
| 2065 | 2078 | } |
| @@ -2069,13 +2082,10 @@ static int mlp_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 3 unmodified lines | ||
| 2069 | 2082 | if (restart_frame) { |
| 2070 | 2083 | avpkt->flags |= AV_PKT_FLAG_KEY; |
| 2071 | 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 | 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 | 2089 | bytes_written = write_access_unit(ctx, avpkt->data, avpkt->size, restart_frame); |
| 2080 | 2090 | |
| 2081 | 2091 | ctx->output_timing += avctx->frame_size; |
| @@ -2097,27 +2107,21 @@ input_and_return: · 15 unmodified lines | ||
| 2097 | 2107 | for (unsigned int seq_index = 0; seq_index < ctx->restart_intervals; seq_index++) { |
| 2098 | 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 | 2110 | ctx->number_of_frames = ctx->next_major_number_of_frames; |
| 2104 | 2111 | ctx->number_of_subblocks = ctx->next_major_number_of_frames + 1; |
| 2105 | 2112 | |
| 2106 | 2113 | number_of_samples = avctx->frame_size * ctx->number_of_frames; |
| 2107 | − ctx->number_of_samples = number_of_samples; | |
| 2108 | 2114 | |
| 2109 | 2115 | for (unsigned int index = 0; index < ctx->b[seq_index].seq_size; index++) { |
| 2110 | 2116 | clear_channel_params(ctx->b[index].channel_params, channels); |
| 2111 | 2117 | default_decoding_params(ctx, &ctx->b[index].decoding_params); |
| 2112 | 2118 | } |
| 2113 | 2119 | |
| 2114 | − input_to_sample_buffer(ctx); | |
| 2115 | − | |
| 2116 | 2120 | if (number_of_samples > 0) |
| 2117 | 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 | 2125 | ctx->major_frame_size = ctx->next_major_frame_size; |
| 2122 | 2126 | ctx->next_major_frame_size = 0; |
| 2123 | 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 | 2133 | avctx->frame_num++; |
| 2130 | 2134 | |
| 2131 | 2135 | if (bytes_written > 0) { |
| @@ -2149,9 +2153,6 @@ static av_cold int mlp_encode_close(AVCodecContext *avctx) · 17 unmodified lines | ||
| 2149 | 2153 | MLPEncodeContext *ctx = avctx->priv_data; |
| 2150 | 2154 | |
| 2151 | 2155 | ff_lpc_end(&ctx->lpc_ctx); |
| 2152 | − | |
| 2153 | − av_freep(&ctx->major_scratch_buffer); | |
| 2154 | − av_freep(&ctx->major_inout_buffer); | |
| 2155 | 2156 | ff_af_queue_close(&ctx->afq); |
| 2156 | 2157 | |
| 2157 | 2158 | return 0; |