This fixes a segfault when using the C version of ac3dsp.float_to_fixed24().
---
On 06/12/2011 04:26 PM, Ronald S. Bultje wrote:
> Hi,
>
> On Sat, Jun 11, 2011 at 12:04 PM, Justin Ruggles
> <[email protected]> wrote:
>>
>> This fixes a segfault with assembly optimizations disabled.
>> ---
>> libavcodec/ac3enc.c | 18 +++++++++++-------
>> 1 files changed, 11 insertions(+), 7 deletions(-)
>
> I'm assuming that the "padded" entries at start/end are not only
> allocated to zero (which they are), but also that it is not possible
> that they get "unzeroed" somehow in a previous iteration of this code
> (e.g. previous frame), and that we then assume them to be zero even
> when they're not, and therefore get invalid results?
>
> If that's all taken care of, then patch OK.
well, it's not taken care of but the invalid results aren't used. here is a
revised patch that's a bit nicer and also takes care of all that.
libavcodec/ac3enc_template.c | 24 +++++++++++++-----------
1 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index 0547165..f6248a8 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -134,36 +134,38 @@ void AC3_NAME(apply_channel_coupling)(AC3EncodeContext *s)
LOCAL_ALIGNED_16(int32_t, fixed_cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]);
int blk, ch, bnd, i, j;
CoefSumType energy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][16] = {{{0}}};
- int num_cpl_coefs = s->num_cpl_subbands * 12;
+ int cpl_start, num_cpl_coefs;
memset(cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*cpl_coords));
memset(fixed_cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*fixed_cpl_coords));
+ /* align start to 16-byte boundary. align length to multiple of 32.
+ note: coupling start bin % 4 will always be 1 */
+ cpl_start = s->start_freq[CPL_CH] - 1;
+ num_cpl_coefs = FFALIGN(s->num_cpl_subbands * 12 + 1, 32);
+ cpl_start = FFMIN(256, cpl_start + num_cpl_coefs) - num_cpl_coefs;
+
/* calculate coupling channel from fbw channels */
for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
AC3Block *block = &s->blocks[blk];
- CoefType *cpl_coef = &block->mdct_coef[CPL_CH][s->start_freq[CPL_CH]];
+ CoefType *cpl_coef = &block->mdct_coef[CPL_CH][cpl_start];
if (!block->cpl_in_use)
continue;
- memset(cpl_coef-1, 0, (num_cpl_coefs+4) * sizeof(*cpl_coef));
+ memset(cpl_coef, 0, num_cpl_coefs * sizeof(*cpl_coef));
for (ch = 1; ch <= s->fbw_channels; ch++) {
- CoefType *ch_coef = &block->mdct_coef[ch][s->start_freq[CPL_CH]];
+ CoefType *ch_coef = &block->mdct_coef[ch][cpl_start];
if (!block->channel_in_cpl[ch])
continue;
for (i = 0; i < num_cpl_coefs; i++)
cpl_coef[i] += ch_coef[i];
}
- /* note: coupling start bin % 4 will always be 1 and num_cpl_coefs
- will always be a multiple of 12, so we need to subtract 1 from
- the start and add 4 to the length when using optimized
- functions which require 16-byte alignment. */
/* coefficients must be clipped to +/- 1.0 in order to be encoded */
- s->dsp.vector_clipf(cpl_coef-1, cpl_coef-1, -1.0f, 1.0f, num_cpl_coefs+4);
+ s->dsp.vector_clipf(cpl_coef, cpl_coef, -1.0f, 1.0f, num_cpl_coefs);
/* scale coupling coefficients from float to 24-bit fixed-point */
- s->ac3dsp.float_to_fixed24(&block->fixed_coef[CPL_CH][s->start_freq[CPL_CH]-1],
- cpl_coef-1, num_cpl_coefs+4);
+ s->ac3dsp.float_to_fixed24(&block->fixed_coef[CPL_CH][cpl_start],
+ cpl_coef, num_cpl_coefs);
}
/* calculate energy in each band in coupling channel and each fbw channel */
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel