diff mbox series

[FFmpeg-devel,4/8] avcodec/flacdsp: split off wasted bit handling into dsp functions

Message ID 20240512160657.2733-2-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] checkasm/flacdsp: run lpc benchmarks with an unmodified buffer | expand

Commit Message

James Almer May 12, 2024, 4:06 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/flacdec.c |  8 ++------
 libavcodec/flacdsp.c | 20 ++++++++++++++++++++
 libavcodec/flacdsp.h |  3 +++
 3 files changed, 25 insertions(+), 6 deletions(-)

Comments

Andreas Rheinhardt May 12, 2024, 4:15 p.m. UTC | #1
James Almer:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/flacdec.c |  8 ++------
>  libavcodec/flacdsp.c | 20 ++++++++++++++++++++
>  libavcodec/flacdsp.h |  3 +++
>  3 files changed, 25 insertions(+), 6 deletions(-)
> 
> diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c
> index 91bbdc657d..6e6a2896b4 100644
> --- a/libavcodec/flacdec.c
> +++ b/libavcodec/flacdec.c
> @@ -602,13 +602,9 @@ static inline int decode_subframe(FLACContext *s, int channel)
>  
>      if (wasted) {
>          if (wasted+bps == 33) {
> -            int i;
> -            for (i = 0; i < s->blocksize; i++)
> -                s->decoded_33bps[i] = (uint64_t)decoded[i] << wasted;
> +            s->dsp.wasted33(s->decoded_33bps, decoded, wasted, s->blocksize);
>          } else if (wasted < 32) {
> -            int i;
> -            for (i = 0; i < s->blocksize; i++)
> -                decoded[i] = (unsigned)decoded[i] << wasted;
> +            s->dsp.wasted32(decoded, wasted, s->blocksize);
>          }
>      }
>  
> diff --git a/libavcodec/flacdsp.c b/libavcodec/flacdsp.c
> index 71b4ac44aa..610831348a 100644
> --- a/libavcodec/flacdsp.c
> +++ b/libavcodec/flacdsp.c
> @@ -84,11 +84,31 @@ static void flac_lpc_32_c(int32_t *decoded, const int coeffs[32],
>  
>  }
>  
> +static void flac_wasted_32_c(int32_t *decoded, int wasted, int len)
> +{
> +    int i;
> +
> +    for (i = 0; i < len; i++)
> +        decoded[i] = (unsigned)decoded[i] << wasted;
> +}
> +
> +static void flac_wasted_33_c(int64_t *decoded, const int32_t *residual,
> +                             int wasted, int len)
> +{
> +    int i;
> +
> +    for (i = 0; i < len; i++)

for (int i = 0

> +        decoded[i] = (uint64_t)residual[i] << wasted;
> +}
> +
>  av_cold void ff_flacdsp_init(FLACDSPContext *c, enum AVSampleFormat fmt, int channels)
>  {
>      c->lpc16        = flac_lpc_16_c;
>      c->lpc32        = flac_lpc_32_c;
>  
> +    c->wasted32     = flac_wasted_32_c;
> +    c->wasted33     = flac_wasted_33_c;
> +
>      switch (fmt) {
>      case AV_SAMPLE_FMT_S32:
>          c->decorrelate[0] = flac_decorrelate_indep_c_32;
> diff --git a/libavcodec/flacdsp.h b/libavcodec/flacdsp.h
> index 15149c026e..5a59c0c864 100644
> --- a/libavcodec/flacdsp.h
> +++ b/libavcodec/flacdsp.h
> @@ -30,6 +30,9 @@ typedef struct FLACDSPContext {
>                    int qlevel, int len);
>      void (*lpc32)(int32_t *samples, const int coeffs[32], int order,
>                    int qlevel, int len);
> +    void (*wasted32)(int32_t *decoded, int wasted, int len);
> +    void (*wasted33)(int64_t *decoded, const int32_t *residual,
> +                     int wasted, int len);
>      void (*lpc16_encode)(int32_t *res, const int32_t *smp, int len, int order,
>                           const int32_t coefs[32], int shift);
>      void (*lpc32_encode)(int32_t *res, const int32_t *smp, int len, int order,
James Almer May 12, 2024, 4:44 p.m. UTC | #2
On 5/12/2024 1:15 PM, Andreas Rheinhardt wrote:
> James Almer:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavcodec/flacdec.c |  8 ++------
>>   libavcodec/flacdsp.c | 20 ++++++++++++++++++++
>>   libavcodec/flacdsp.h |  3 +++
>>   3 files changed, 25 insertions(+), 6 deletions(-)
>>
>> diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c
>> index 91bbdc657d..6e6a2896b4 100644
>> --- a/libavcodec/flacdec.c
>> +++ b/libavcodec/flacdec.c
>> @@ -602,13 +602,9 @@ static inline int decode_subframe(FLACContext *s, int channel)
>>   
>>       if (wasted) {
>>           if (wasted+bps == 33) {
>> -            int i;
>> -            for (i = 0; i < s->blocksize; i++)
>> -                s->decoded_33bps[i] = (uint64_t)decoded[i] << wasted;
>> +            s->dsp.wasted33(s->decoded_33bps, decoded, wasted, s->blocksize);
>>           } else if (wasted < 32) {
>> -            int i;
>> -            for (i = 0; i < s->blocksize; i++)
>> -                decoded[i] = (unsigned)decoded[i] << wasted;
>> +            s->dsp.wasted32(decoded, wasted, s->blocksize);
>>           }
>>       }
>>   
>> diff --git a/libavcodec/flacdsp.c b/libavcodec/flacdsp.c
>> index 71b4ac44aa..610831348a 100644
>> --- a/libavcodec/flacdsp.c
>> +++ b/libavcodec/flacdsp.c
>> @@ -84,11 +84,31 @@ static void flac_lpc_32_c(int32_t *decoded, const int coeffs[32],
>>   
>>   }
>>   
>> +static void flac_wasted_32_c(int32_t *decoded, int wasted, int len)
>> +{
>> +    int i;
>> +
>> +    for (i = 0; i < len; i++)
>> +        decoded[i] = (unsigned)decoded[i] << wasted;
>> +}
>> +
>> +static void flac_wasted_33_c(int64_t *decoded, const int32_t *residual,
>> +                             int wasted, int len)
>> +{
>> +    int i;
>> +
>> +    for (i = 0; i < len; i++)
> 
> for (int i = 0

Fixed locally.
diff mbox series

Patch

diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c
index 91bbdc657d..6e6a2896b4 100644
--- a/libavcodec/flacdec.c
+++ b/libavcodec/flacdec.c
@@ -602,13 +602,9 @@  static inline int decode_subframe(FLACContext *s, int channel)
 
     if (wasted) {
         if (wasted+bps == 33) {
-            int i;
-            for (i = 0; i < s->blocksize; i++)
-                s->decoded_33bps[i] = (uint64_t)decoded[i] << wasted;
+            s->dsp.wasted33(s->decoded_33bps, decoded, wasted, s->blocksize);
         } else if (wasted < 32) {
-            int i;
-            for (i = 0; i < s->blocksize; i++)
-                decoded[i] = (unsigned)decoded[i] << wasted;
+            s->dsp.wasted32(decoded, wasted, s->blocksize);
         }
     }
 
diff --git a/libavcodec/flacdsp.c b/libavcodec/flacdsp.c
index 71b4ac44aa..610831348a 100644
--- a/libavcodec/flacdsp.c
+++ b/libavcodec/flacdsp.c
@@ -84,11 +84,31 @@  static void flac_lpc_32_c(int32_t *decoded, const int coeffs[32],
 
 }
 
+static void flac_wasted_32_c(int32_t *decoded, int wasted, int len)
+{
+    int i;
+
+    for (i = 0; i < len; i++)
+        decoded[i] = (unsigned)decoded[i] << wasted;
+}
+
+static void flac_wasted_33_c(int64_t *decoded, const int32_t *residual,
+                             int wasted, int len)
+{
+    int i;
+
+    for (i = 0; i < len; i++)
+        decoded[i] = (uint64_t)residual[i] << wasted;
+}
+
 av_cold void ff_flacdsp_init(FLACDSPContext *c, enum AVSampleFormat fmt, int channels)
 {
     c->lpc16        = flac_lpc_16_c;
     c->lpc32        = flac_lpc_32_c;
 
+    c->wasted32     = flac_wasted_32_c;
+    c->wasted33     = flac_wasted_33_c;
+
     switch (fmt) {
     case AV_SAMPLE_FMT_S32:
         c->decorrelate[0] = flac_decorrelate_indep_c_32;
diff --git a/libavcodec/flacdsp.h b/libavcodec/flacdsp.h
index 15149c026e..5a59c0c864 100644
--- a/libavcodec/flacdsp.h
+++ b/libavcodec/flacdsp.h
@@ -30,6 +30,9 @@  typedef struct FLACDSPContext {
                   int qlevel, int len);
     void (*lpc32)(int32_t *samples, const int coeffs[32], int order,
                   int qlevel, int len);
+    void (*wasted32)(int32_t *decoded, int wasted, int len);
+    void (*wasted33)(int64_t *decoded, const int32_t *residual,
+                     int wasted, int len);
     void (*lpc16_encode)(int32_t *res, const int32_t *smp, int len, int order,
                          const int32_t coefs[32], int shift);
     void (*lpc32_encode)(int32_t *res, const int32_t *smp, int len, int order,