diff mbox

[FFmpeg-devel,RFC] lswr/rematrix: Support s32p

Message ID CAB0OVGoHzHRJfQBXyOoFo5dMukV4YHiFXrO2Y=0pG=_a==EfPQ@mail.gmail.com
State Accepted
Headers show

Commit Message

Carl Eugen Hoyos Oct. 30, 2017, 11:40 p.m. UTC
2017-10-30 9:47 GMT+01:00 Muhammad Faiz <mfcc64@gmail.com>:
> On Sun, Oct 29, 2017 at 3:55 AM, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
>> Hi!
>>
>> Attached patch fixes a random testcase for ticket #6785 here but I
>> don't know if this is the correct fix.
>>
>> Please review, Carl Eugen
>>
>> From a93b9309d74f5eadece371ee1e682d266af6cd83 Mon Sep 17 00:00:00 2001
>> From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
>> Date: Sat, 28 Oct 2017 22:52:02 +0200
>> Subject: [PATCH] lswr/rematrix: Support s32p.
>>
>> Fixes ticket #6785.
>> ---
>>  libswresample/rematrix.c |   21 +++++++++++++++------
>>  1 file changed, 15 insertions(+), 6 deletions(-)
>>
>> diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
>> index 66a43c1..a6aa6b0 100644
>> --- a/libswresample/rematrix.c
>> +++ b/libswresample/rematrix.c
>> @@ -445,14 +445,23 @@ av_cold int swri_rematrix_init(SwrContext *s){
>>          s->mix_2_1_f = (mix_2_1_func_type*)sum2_double;
>>          s->mix_any_f = (mix_any_func_type*)get_mix_any_func_double(s);
>>      }else if(s->midbuf.fmt == AV_SAMPLE_FMT_S32P){
>> -        // Only for dithering currently
>> -//         s->native_matrix = av_calloc(nb_in * nb_out, sizeof(double));
>> -        s->native_one    = av_mallocz(sizeof(int));
>> +        s->native_one    = av_mallocz(sizeof(int64_t));
>>          if (!s->native_one)
>>              return AVERROR(ENOMEM);
>> -//         for (i = 0; i < nb_out; i++)
>> -//             for (j = 0; j < nb_in; j++)
>> -//                 ((double*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
>> +        s->native_matrix = av_calloc(nb_in * nb_out, sizeof(int));
>> +        if (!s->native_matrix) {
>> +            av_freep(&s->native_one);
>> +            return AVERROR(ENOMEM);
>> +        }
>> +        for (i = 0; i < nb_out; i++) {
>> +            double rem = 0;
>> +
>> +            for (j = 0; j < nb_in; j++) {
>> +                double target = s->matrix[i][j] * 32768 + rem;
>> +                ((int*)s->native_matrix)[i * nb_in + j] = lrintf(target);
>> +                rem += target - ((int64_t*)s->native_matrix)[i * nb_in + j];
>> +            }
>> +        }
>>          *((int*)s->native_one) = 32768;
>>          s->mix_1_1_f = (mix_1_1_func_type*)copy_s32;
>>          s->mix_2_1_f = (mix_2_1_func_type*)sum2_s32;
>
> The code is confusing.
> Which is the type of native_matrix and native_one? int or int64_t?

New patch attached.

Please review, Carl Eugen

Comments

Michael Niedermayer Oct. 31, 2017, 4:28 p.m. UTC | #1
On Tue, Oct 31, 2017 at 12:40:24AM +0100, Carl Eugen Hoyos wrote:
> 2017-10-30 9:47 GMT+01:00 Muhammad Faiz <mfcc64@gmail.com>:
> > On Sun, Oct 29, 2017 at 3:55 AM, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
> >> Hi!
> >>
> >> Attached patch fixes a random testcase for ticket #6785 here but I
> >> don't know if this is the correct fix.
> >>
> >> Please review, Carl Eugen
> >>
> >> From a93b9309d74f5eadece371ee1e682d266af6cd83 Mon Sep 17 00:00:00 2001
> >> From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
> >> Date: Sat, 28 Oct 2017 22:52:02 +0200
> >> Subject: [PATCH] lswr/rematrix: Support s32p.
> >>
> >> Fixes ticket #6785.
> >> ---
> >>  libswresample/rematrix.c |   21 +++++++++++++++------
> >>  1 file changed, 15 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
> >> index 66a43c1..a6aa6b0 100644
> >> --- a/libswresample/rematrix.c
> >> +++ b/libswresample/rematrix.c
> >> @@ -445,14 +445,23 @@ av_cold int swri_rematrix_init(SwrContext *s){
> >>          s->mix_2_1_f = (mix_2_1_func_type*)sum2_double;
> >>          s->mix_any_f = (mix_any_func_type*)get_mix_any_func_double(s);
> >>      }else if(s->midbuf.fmt == AV_SAMPLE_FMT_S32P){
> >> -        // Only for dithering currently
> >> -//         s->native_matrix = av_calloc(nb_in * nb_out, sizeof(double));
> >> -        s->native_one    = av_mallocz(sizeof(int));
> >> +        s->native_one    = av_mallocz(sizeof(int64_t));
> >>          if (!s->native_one)
> >>              return AVERROR(ENOMEM);
> >> -//         for (i = 0; i < nb_out; i++)
> >> -//             for (j = 0; j < nb_in; j++)
> >> -//                 ((double*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
> >> +        s->native_matrix = av_calloc(nb_in * nb_out, sizeof(int));
> >> +        if (!s->native_matrix) {
> >> +            av_freep(&s->native_one);
> >> +            return AVERROR(ENOMEM);
> >> +        }
> >> +        for (i = 0; i < nb_out; i++) {
> >> +            double rem = 0;
> >> +
> >> +            for (j = 0; j < nb_in; j++) {
> >> +                double target = s->matrix[i][j] * 32768 + rem;
> >> +                ((int*)s->native_matrix)[i * nb_in + j] = lrintf(target);
> >> +                rem += target - ((int64_t*)s->native_matrix)[i * nb_in + j];
> >> +            }
> >> +        }
> >>          *((int*)s->native_one) = 32768;
> >>          s->mix_1_1_f = (mix_1_1_func_type*)copy_s32;
> >>          s->mix_2_1_f = (mix_2_1_func_type*)sum2_s32;
> >
> > The code is confusing.
> > Which is the type of native_matrix and native_one? int or int64_t?
> 
> New patch attached.
> 
> Please review, Carl Eugen

>  rematrix.c |   21 +++++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)
> 9f50e61370cc72de000bb1174cbd8666388fdd9a  0001-lswr-Support-s32p.patch
> From a93b9309d74f5eadece371ee1e682d266af6cd83 Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
> Date: Sat, 28 Oct 2017 22:52:02 +0200
> Subject: [PATCH] lswr/rematrix: Support s32p.
> 
> Fixes ticket #6785.
> ---
>  libswresample/rematrix.c |   21 +++++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)

should be ok

[...]
Carl Eugen Hoyos Nov. 1, 2017, 12:07 a.m. UTC | #2
2017-10-31 17:28 GMT+01:00 Michael Niedermayer <michael@niedermayer.cc>:

>>  rematrix.c |   21 +++++++++++++++------
>>  1 file changed, 15 insertions(+), 6 deletions(-)
>> 9f50e61370cc72de000bb1174cbd8666388fdd9a  0001-lswr-Support-s32p.patch
>> From a93b9309d74f5eadece371ee1e682d266af6cd83 Mon Sep 17 00:00:00 2001
>> From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
>> Date: Sat, 28 Oct 2017 22:52:02 +0200
>> Subject: [PATCH] lswr/rematrix: Support s32p.
>>
>> Fixes ticket #6785.
>> ---
>>  libswresample/rematrix.c |   21 +++++++++++++++------
>>  1 file changed, 15 insertions(+), 6 deletions(-)
>
> should be ok

Patch applied.

Thank you, Carl Eugen
diff mbox

Patch

From a93b9309d74f5eadece371ee1e682d266af6cd83 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Date: Sat, 28 Oct 2017 22:52:02 +0200
Subject: [PATCH] lswr/rematrix: Support s32p.

Fixes ticket #6785.
---
 libswresample/rematrix.c |   21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
index 66a43c1..a6aa6b0 100644
--- a/libswresample/rematrix.c
+++ b/libswresample/rematrix.c
@@ -445,14 +445,23 @@  av_cold int swri_rematrix_init(SwrContext *s){
         s->mix_2_1_f = (mix_2_1_func_type*)sum2_double;
         s->mix_any_f = (mix_any_func_type*)get_mix_any_func_double(s);
     }else if(s->midbuf.fmt == AV_SAMPLE_FMT_S32P){
-        // Only for dithering currently
-//         s->native_matrix = av_calloc(nb_in * nb_out, sizeof(double));
-        s->native_one    = av_mallocz(sizeof(int));
+        s->native_one    = av_mallocz(sizeof(int));
         if (!s->native_one)
             return AVERROR(ENOMEM);
-//         for (i = 0; i < nb_out; i++)
-//             for (j = 0; j < nb_in; j++)
-//                 ((double*)s->native_matrix)[i * nb_in + j] = s->matrix[i][j];
+        s->native_matrix = av_calloc(nb_in * nb_out, sizeof(int));
+        if (!s->native_matrix) {
+            av_freep(&s->native_one);
+            return AVERROR(ENOMEM);
+        }
+        for (i = 0; i < nb_out; i++) {
+            double rem = 0;
+
+            for (j = 0; j < nb_in; j++) {
+                double target = s->matrix[i][j] * 32768 + rem;
+                ((int*)s->native_matrix)[i * nb_in + j] = lrintf(target);
+                rem += target - ((int*)s->native_matrix)[i * nb_in + j];
+            }
+        }
         *((int*)s->native_one) = 32768;
         s->mix_1_1_f = (mix_1_1_func_type*)copy_s32;
         s->mix_2_1_f = (mix_2_1_func_type*)sum2_s32;
-- 
1.7.10.4