[FFmpeg-devel] [PATCH 1/4] avcodec/lpc: Don't use AAC defines directly

Lynne dev at lynne.ee
Sun Mar 3 23:44:55 EET 2024


Mar 3, 2024, 19:43 by andreas.rheinhardt at outlook.com:

> Andreas Rheinhardt:
>
>> It leads to defines for the AAC decoder being included
>> outside of the AAC decoder.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
>> ---
>>  libavcodec/aac_defines.h     | 11 +++++++++--
>>  libavcodec/aacdec_fixed.c    |  2 +-
>>  libavcodec/aacdec_template.c |  2 +-
>>  libavcodec/lpc.h             | 27 ++++++++++++++++++---------
>>  4 files changed, 29 insertions(+), 13 deletions(-)
>>
>> diff --git a/libavcodec/aac_defines.h b/libavcodec/aac_defines.h
>> index 59528f1f0d..8765939731 100644
>> --- a/libavcodec/aac_defines.h
>> +++ b/libavcodec/aac_defines.h
>> @@ -71,7 +71,15 @@ typedef int                 AAC_SIGNE;
>>  ((int64_t)(y) * (z)) + \
>>  0x40000000) >> 31)
>>  #define AAC_HALF_SUM(x, y)  (((x) >> 1) + ((y) >> 1))
>> -#define AAC_SRA_R(x, y)     (int)(((x) + (1 << ((y) - 1))) >> (y))
>> +
>> +#ifdef LPC_USE_FIXED
>> +#error aac_defines.h must be included before lpc.h for fixed point decoder
>> +#endif
>> +
>> +#define LPC_USE_FIXED 1
>> +#define LPC_MUL26(x, y)     AAC_MUL26((x), (y))
>> +#define LPC_FIXR(x)         FIXR(x)
>> +#define LPC_SRA_R(x, y)     (int)(((x) + (1 << ((y) - 1))) >> (y))
>>  
>>  #else
>>  
>> @@ -103,7 +111,6 @@ typedef unsigned            AAC_SIGNE;
>>  (c) * (d) - (e) * (f))
>>  #define AAC_MSUB31_V3(x, y, z)    ((x) - (y)) * (z)
>>  #define AAC_HALF_SUM(x, y)  ((x) + (y)) * 0.5f
>> -#define AAC_SRA_R(x, y)     (x)
>>  
>>  #endif /* USE_FIXED */
>>  
>> diff --git a/libavcodec/aacdec_fixed.c b/libavcodec/aacdec_fixed.c
>> index 57d3fc8bab..08343bf157 100644
>> --- a/libavcodec/aacdec_fixed.c
>> +++ b/libavcodec/aacdec_fixed.c
>> @@ -66,7 +66,6 @@
>>  #include "avcodec.h"
>>  #include "codec_internal.h"
>>  #include "get_bits.h"
>> -#include "lpc.h"
>>  #include "kbdwin.h"
>>  #include "sinewin_fixed_tablegen.h"
>>  
>> @@ -76,6 +75,7 @@
>>  #include "aacdectab.h"
>>  #include "adts_header.h"
>>  #include "cbrt_data.h"
>> +#include "lpc.h"
>>  #include "sbr.h"
>>  #include "aacsbr.h"
>>  #include "mpeg4audio.h"
>> diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
>> index 72c6e206a6..fb3a954aad 100644
>> --- a/libavcodec/aacdec_template.c
>> +++ b/libavcodec/aacdec_template.c
>> @@ -2516,7 +2516,7 @@ static void apply_tns(INTFLOAT coef_param[1024], TemporalNoiseShaping *tns,
>>  continue;
>>  
>>  // tns_decode_coef
>> -            AAC_RENAME(compute_lpc_coefs)(tns->coef[w][filt], order, lpc, 0, 0, 0);
>> +            compute_lpc_coefs(tns->coef[w][filt], order, lpc, 0, 0, 0);
>>  
>>  start = ics->swb_offset[FFMIN(bottom, mmm)];
>>  end   = ics->swb_offset[FFMIN(   top, mmm)];
>> diff --git a/libavcodec/lpc.h b/libavcodec/lpc.h
>> index 0200baea5c..907fab7508 100644
>> --- a/libavcodec/lpc.h
>> +++ b/libavcodec/lpc.h
>> @@ -26,7 +26,6 @@
>>  #include <stddef.h>
>>  #include "libavutil/avassert.h"
>>  #include "libavutil/lls.h"
>> -#include "aac_defines.h"
>>  
>>  #define ORDER_METHOD_EST     0
>>  #define ORDER_METHOD_2LEVEL  1
>> @@ -117,10 +116,20 @@ void ff_lpc_init_x86(LPCContext *s);
>>  */
>>  void ff_lpc_end(LPCContext *s);
>>  
>> -#if USE_FIXED
>> +#ifndef LPC_USE_FIXED
>> +#define LPC_USE_FIXED 0
>> +#endif
>> +
>> +#if LPC_USE_FIXED
>>  typedef int LPC_TYPE;
>>  typedef unsigned LPC_TYPE_U;
>>  #else
>> +#ifndef LPC_SRA_R
>> +#define LPC_SRA_R(x, y) (x)
>> +#define LPC_MUL26(x, y) ((x) * (y))
>> +#define LPC_FIXR(x)     ((float)(x))
>> +#endif
>> +
>>  #ifdef LPC_USE_DOUBLE
>>  typedef double LPC_TYPE;
>>  typedef double LPC_TYPE_U;
>> @@ -145,7 +154,7 @@ static inline void compute_ref_coefs(const LPC_TYPE *autoc, int max_order,
>>  gen0[i] = gen1[i] = autoc[i + 1];
>>  
>>  err    = autoc[0];
>> -    ref[0] = -gen1[0] / ((USE_FIXED || err) ? err : 1);
>> +    ref[0] = -gen1[0] / ((LPC_USE_FIXED || err) ? err : 1);
>>  err   +=  gen1[0] * ref[0];
>>  if (error)
>>  error[0] = err;
>> @@ -154,7 +163,7 @@ static inline void compute_ref_coefs(const LPC_TYPE *autoc, int max_order,
>>  gen1[j] = gen1[j + 1] + ref[i - 1] * gen0[j];
>>  gen0[j] = gen1[j + 1] * ref[i - 1] + gen0[j];
>>  }
>> -        ref[i] = -gen1[0] / ((USE_FIXED || err) ? err : 1);
>> +        ref[i] = -gen1[0] / ((LPC_USE_FIXED || err) ? err : 1);
>>  err   +=  gen1[0] * ref[i];
>>  if (error)
>>  error[i] = err;
>> @@ -165,7 +174,7 @@ static inline void compute_ref_coefs(const LPC_TYPE *autoc, int max_order,
>>  * Levinson-Durbin recursion.
>>  * Produce LPC coefficients from autocorrelation data.
>>  */
>> -static inline int AAC_RENAME(compute_lpc_coefs)(const LPC_TYPE *autoc, int max_order,
>> +static inline int compute_lpc_coefs(const LPC_TYPE *autoc, int max_order,
>>  LPC_TYPE *lpc, int lpc_stride, int fail,
>>  int normalize)
>>  {
>> @@ -182,7 +191,7 @@ static inline int AAC_RENAME(compute_lpc_coefs)(const LPC_TYPE *autoc, int max_o
>>  return -1;
>>  
>>  for(i=0; i<max_order; i++) {
>> -        LPC_TYPE r = AAC_SRA_R(-autoc[i], 5);
>> +        LPC_TYPE r = LPC_SRA_R(-autoc[i], 5);
>>  
>>  if (normalize) {
>>  for(j=0; j<i; j++)
>> @@ -190,7 +199,7 @@ static inline int AAC_RENAME(compute_lpc_coefs)(const LPC_TYPE *autoc, int max_o
>>  
>>  if (err)
>>  r /= err;
>> -            err *= FIXR(1.0) - (r * r);
>> +            err *= LPC_FIXR(1.0) - (r * r);
>>  }
>>  
>>  lpc[i] = r;
>> @@ -198,8 +207,8 @@ static inline int AAC_RENAME(compute_lpc_coefs)(const LPC_TYPE *autoc, int max_o
>>  for(j=0; j < (i+1)>>1; j++) {
>>  LPC_TYPE f = lpc_last[    j];
>>  LPC_TYPE b = lpc_last[i-1-j];
>> -            lpc[    j] = f + (LPC_TYPE_U)AAC_MUL26(r, b);
>> -            lpc[i-1-j] = b + (LPC_TYPE_U)AAC_MUL26(r, f);
>> +            lpc[    j] = f + (LPC_TYPE_U)LPC_MUL26(r, b);
>> +            lpc[i-1-j] = b + (LPC_TYPE_U)LPC_MUL26(r, f);
>>  }
>>  
>>  if (fail && err < 0)
>>
>
> Will apply this patchset tomorrow unless there are objections.
>

Patchset LGTM
Thanks


More information about the ffmpeg-devel mailing list