Verified with profiling that this doesn't have a measurable effect upon overall performance.
Unified · Split
| @@ -360,6 +360,10 @@ static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb) · 359 unmodified lines | ||
| 360 | 360 | m->avctx->sample_fmt = AV_SAMPLE_FMT_S32; |
| 361 | 361 | else |
| 362 | 362 | m->avctx->sample_fmt = AV_SAMPLE_FMT_S16; |
| 363 | + m->dsp.mlp_pack_output = m->dsp.mlp_select_pack_output(m->substream[m->max_decoded_substream].ch_assign, | |
| 364 | + m->substream[m->max_decoded_substream].output_shift, | |
| 365 | + m->substream[m->max_decoded_substream].max_matrix_channel, | |
| 366 | + m->avctx->sample_fmt == AV_SAMPLE_FMT_S32); | |
| 363 | 367 | |
| 364 | 368 | m->params_valid = 1; |
| 365 | 369 | for (substr = 0; substr < MAX_SUBSTREAMS; substr++) |
| @@ -588,6 +592,10 @@ FF_ENABLE_DEPRECATION_WARNINGS · 222 unmodified lines | ||
| 588 | 592 | if (substr == m->max_decoded_substream) { |
| 589 | 593 | m->avctx->channels = s->max_matrix_channel + 1; |
| 590 | 594 | m->avctx->channel_layout = s->ch_layout; |
| 595 | + m->dsp.mlp_pack_output = m->dsp.mlp_select_pack_output(s->ch_assign, | |
| 596 | + s->output_shift, | |
| 597 | + s->max_matrix_channel, | |
| 598 | + m->avctx->sample_fmt == AV_SAMPLE_FMT_S32); | |
| 591 | 599 | } |
| 592 | 600 | |
| 593 | 601 | return 0; |
| @@ -818,9 +826,15 @@ static int read_decoding_params(MLPDecodeContext *m, GetBitContext *gbp, · 224 unmodified lines | ||
| 818 | 826 | return ret; |
| 819 | 827 | |
| 820 | 828 | if (s->param_presence_flags & PARAM_OUTSHIFT) |
| 821 | − if (get_bits1(gbp)) | |
| 829 | + if (get_bits1(gbp)) { | |
| 822 | 830 | for (ch = 0; ch <= s->max_matrix_channel; ch++) |
| 823 | 831 | s->output_shift[ch] = get_sbits(gbp, 4); |
| 832 | + if (substr == m->max_decoded_substream) | |
| 833 | + m->dsp.mlp_pack_output = m->dsp.mlp_select_pack_output(s->ch_assign, | |
| 834 | + s->output_shift, | |
| 835 | + s->max_matrix_channel, | |
| 836 | + m->avctx->sample_fmt == AV_SAMPLE_FMT_S32); | |
| 837 | + } | |
| 824 | 838 | |
| 825 | 839 | if (s->param_presence_flags & PARAM_QUANTSTEP) |
| 826 | 840 | if (get_bits1(gbp)) |
| @@ -1019,9 +1033,6 @@ static int output_data(MLPDecodeContext *m, unsigned int substr, · 192 unmodified lines | ||
| 1019 | 1033 | { |
| 1020 | 1034 | AVCodecContext *avctx = m->avctx; |
| 1021 | 1035 | SubStream *s = &m->substream[substr]; |
| 1022 | − unsigned int i, out_ch = 0; | |
| 1023 | − int32_t *data_32; | |
| 1024 | − int16_t *data_16; | |
| 1025 | 1036 | int ret; |
| 1026 | 1037 | int is32 = (m->avctx->sample_fmt == AV_SAMPLE_FMT_S32); |
| 1027 | 1038 | |
| @@ -1041,19 +1052,14 @@ static int output_data(MLPDecodeContext *m, unsigned int substr, · 13 unmodified lines | ||
| 1041 | 1052 | av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
| 1042 | 1053 | return ret; |
| 1043 | 1054 | } |
| 1044 | − data_32 = (int32_t *)frame->data[0]; | |
| 1045 | − data_16 = (int16_t *)frame->data[0]; | |
| 1046 | − | |
| 1047 | − for (i = 0; i < s->blockpos; i++) { | |
| 1048 | − for (out_ch = 0; out_ch <= s->max_matrix_channel; out_ch++) { | |
| 1049 | − int mat_ch = s->ch_assign[out_ch]; | |
| 1050 | − int32_t sample = m->sample_buffer[i][mat_ch] | |
| 1051 | − << s->output_shift[mat_ch]; | |
| 1052 | − s->lossless_check_data ^= (sample & 0xffffff) << mat_ch; | |
| 1053 | − if (is32) *data_32++ = sample << 8; | |
| 1054 | − else *data_16++ = sample >> 8; | |
| 1055 | − } | |
| 1056 | − } | |
| 1055 | + s->lossless_check_data = m->dsp.mlp_pack_output(s->lossless_check_data, | |
| 1056 | + s->blockpos, | |
| 1057 | + m->sample_buffer, | |
| 1058 | + frame->data[0], | |
| 1059 | + s->ch_assign, | |
| 1060 | + s->output_shift, | |
| 1061 | + s->max_matrix_channel, | |
| 1062 | + is32); | |
| 1057 | 1063 | |
| 1058 | 1064 | /* Update matrix encoding side data */ |
| 1059 | 1065 | if ((ret = ff_side_data_update_matrix_encoding(frame, s->matrix_encoding)) < 0) |
| @@ -89,10 +89,48 @@ void ff_mlp_rematrix_channel(int32_t *samples, · 88 unmodified lines | ||
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | +static int32_t (*mlp_select_pack_output(uint8_t *ch_assign, | |
| 93 | + int8_t *output_shift, | |
| 94 | + uint8_t max_matrix_channel, | |
| 95 | + int is32))(int32_t, uint16_t, int32_t (*)[], void *, uint8_t*, int8_t *, uint8_t, int) | |
| 96 | +{ | |
| 97 | + return ff_mlp_pack_output; | |
| 98 | +} | |
| 99 | + | |
| 100 | +int32_t ff_mlp_pack_output(int32_t lossless_check_data, | |
| 101 | + uint16_t blockpos, | |
| 102 | + int32_t (*sample_buffer)[MAX_CHANNELS], | |
| 103 | + void *data, | |
| 104 | + uint8_t *ch_assign, | |
| 105 | + int8_t *output_shift, | |
| 106 | + uint8_t max_matrix_channel, | |
| 107 | + int is32) | |
| 108 | +{ | |
| 109 | + unsigned int i, out_ch = 0; | |
| 110 | + int32_t *data_32 = data; | |
| 111 | + int16_t *data_16 = data; | |
| 112 | + | |
| 113 | + for (i = 0; i < blockpos; i++) { | |
| 114 | + for (out_ch = 0; out_ch <= max_matrix_channel; out_ch++) { | |
| 115 | + int mat_ch = ch_assign[out_ch]; | |
| 116 | + int32_t sample = sample_buffer[i][mat_ch] | |
| 117 | + << output_shift[mat_ch]; | |
| 118 | + lossless_check_data ^= (sample & 0xffffff) << mat_ch; | |
| 119 | + if (is32) | |
| 120 | + *data_32++ = sample << 8; | |
| 121 | + else | |
| 122 | + *data_16++ = sample >> 8; | |
| 123 | + } | |
| 124 | + } | |
| 125 | + return lossless_check_data; | |
| 126 | +} | |
| 127 | + | |
| 92 | 128 | av_cold void ff_mlpdsp_init(MLPDSPContext *c) |
| 93 | 129 | { |
| 94 | 130 | c->mlp_filter_channel = mlp_filter_channel; |
| 95 | 131 | c->mlp_rematrix_channel = ff_mlp_rematrix_channel; |
| 132 | + c->mlp_select_pack_output = mlp_select_pack_output; | |
| 133 | + c->mlp_pack_output = ff_mlp_pack_output; | |
| 96 | 134 | if (ARCH_ARM) |
| 97 | 135 | ff_mlpdsp_init_arm(c); |
| 98 | 136 | if (ARCH_X86) |
| @@ -23,6 +23,7 @@ · 22 unmodified lines | ||
| 23 | 23 | #define AVCODEC_MLPDSP_H |
| 24 | 24 | |
| 25 | 25 | #include <stdint.h> |
| 26 | +#include "mlp.h" | |
| 26 | 27 | |
| 27 | 28 | void ff_mlp_rematrix_channel(int32_t *samples, |
| 28 | 29 | const int32_t *coeffs, |
| @@ -36,6 +37,15 @@ void ff_mlp_rematrix_channel(int32_t *samples, · 7 unmodified lines | ||
| 36 | 37 | int access_unit_size_pow2, |
| 37 | 38 | int32_t mask); |
| 38 | 39 | |
| 40 | +int32_t ff_mlp_pack_output(int32_t lossless_check_data, | |
| 41 | + uint16_t blockpos, | |
| 42 | + int32_t (*sample_buffer)[MAX_CHANNELS], | |
| 43 | + void *data, | |
| 44 | + uint8_t *ch_assign, | |
| 45 | + int8_t *output_shift, | |
| 46 | + uint8_t max_matrix_channel, | |
| 47 | + int is32); | |
| 48 | + | |
| 39 | 49 | typedef struct MLPDSPContext { |
| 40 | 50 | void (*mlp_filter_channel)(int32_t *state, const int32_t *coeff, |
| 41 | 51 | int firorder, int iirorder, |
| @@ -52,6 +62,18 @@ typedef struct MLPDSPContext { · 10 unmodified lines | ||
| 52 | 62 | int matrix_noise_shift, |
| 53 | 63 | int access_unit_size_pow2, |
| 54 | 64 | int32_t mask); |
| 65 | + int32_t (*(*mlp_select_pack_output)(uint8_t *ch_assign, | |
| 66 | + int8_t *output_shift, | |
| 67 | + uint8_t max_matrix_channel, | |
| 68 | + int is32))(int32_t, uint16_t, int32_t (*)[], void *, uint8_t*, int8_t *, uint8_t, int); | |
| 69 | + int32_t (*mlp_pack_output)(int32_t lossless_check_data, | |
| 70 | + uint16_t blockpos, | |
| 71 | + int32_t (*sample_buffer)[MAX_CHANNELS], | |
| 72 | + void *data, | |
| 73 | + uint8_t *ch_assign, | |
| 74 | + int8_t *output_shift, | |
| 75 | + uint8_t max_matrix_channel, | |
| 76 | + int is32); | |
| 55 | 77 | } MLPDSPContext; |
| 56 | 78 | |
| 57 | 79 | void ff_mlpdsp_init(MLPDSPContext *c); |