[FFmpeg-cvslog] swresample/resample: remove swri_resample function

Muhammad Faiz git at videolan.org
Wed Dec 14 01:58:46 EET 2016


ffmpeg | branch: master | Muhammad Faiz <mfcc64 at gmail.com> | Wed Dec 14 00:51:18 2016 +0700| [2b0112d42d4dfc8976be20b4d9729c0e077146c6] | committer: Muhammad Faiz

swresample/resample: remove swri_resample function

integrate it inside multiple_resample
allow some calculations to be performed outside loop

Suggested-by: Michael Niedermayer <michael at niedermayer.cc>
Reviewed-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: Muhammad Faiz <mfcc64 at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2b0112d42d4dfc8976be20b4d9729c0e077146c6
---

 libswresample/resample.c | 79 +++++++++++++++++++++---------------------------
 1 file changed, 35 insertions(+), 44 deletions(-)

diff --git a/libswresample/resample.c b/libswresample/resample.c
index ce6a82f..8e2f769 100644
--- a/libswresample/resample.c
+++ b/libswresample/resample.c
@@ -467,70 +467,61 @@ static int set_compensation(ResampleContext *c, int sample_delta, int compensati
     return 0;
 }
 
-static int swri_resample(ResampleContext *c,
-                         uint8_t *dst, const uint8_t *src, int *consumed,
-                         int src_size, int dst_size, int update_ctx)
-{
+static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed){
+    int i;
+    int av_unused mm_flags = av_get_cpu_flags();
+    int need_emms = c->format == AV_SAMPLE_FMT_S16P && ARCH_X86_32 &&
+                    (mm_flags & (AV_CPU_FLAG_MMX2 | AV_CPU_FLAG_SSE2)) == AV_CPU_FLAG_MMX2;
+    int64_t max_src_size = (INT64_MAX/2 / c->phase_count) / c->src_incr;
+
+    if (c->compensation_distance)
+        dst_size = FFMIN(dst_size, c->compensation_distance);
+    src_size = FFMIN(src_size, max_src_size);
+
+    *consumed = 0;
+
     if (c->filter_length == 1 && c->phase_count == 1) {
-        int index= c->index;
-        int frac= c->frac;
-        int64_t index2= (1LL<<32)*c->frac/c->src_incr + (1LL<<32)*index;
+        int64_t index2= (1LL<<32)*c->frac/c->src_incr + (1LL<<32)*c->index;
         int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr;
-        int new_size = (src_size * (int64_t)c->src_incr - frac + c->dst_incr - 1) / c->dst_incr;
+        int new_size = (src_size * (int64_t)c->src_incr - c->frac + c->dst_incr - 1) / c->dst_incr;
 
         dst_size = FFMAX(FFMIN(dst_size, new_size), 0);
-        if (dst_size > 0)
-            c->dsp.resample_one(dst, src, dst_size, index2, incr);
-
-        index += dst_size * c->dst_incr_div;
-        index += (frac + dst_size * (int64_t)c->dst_incr_mod) / c->src_incr;
-        av_assert2(index >= 0);
-        *consumed= index;
-        if (update_ctx) {
-            c->frac   = (frac + dst_size * (int64_t)c->dst_incr_mod) % c->src_incr;
-            c->index = 0;
+        if (dst_size > 0) {
+            for (i = 0; i < dst->ch_count; i++) {
+                c->dsp.resample_one(dst->ch[i], src->ch[i], dst_size, index2, incr);
+                if (i+1 == dst->ch_count) {
+                    c->index += dst_size * c->dst_incr_div;
+                    c->index += (c->frac + dst_size * (int64_t)c->dst_incr_mod) / c->src_incr;
+                    av_assert2(c->index >= 0);
+                    *consumed = c->index;
+                    c->frac   = (c->frac + dst_size * (int64_t)c->dst_incr_mod) % c->src_incr;
+                    c->index = 0;
+                }
+            }
         }
     } else {
         int64_t end_index = (1LL + src_size - c->filter_length) * c->phase_count;
         int64_t delta_frac = (end_index - c->index) * c->src_incr - c->frac;
         int delta_n = (delta_frac + c->dst_incr - 1) / c->dst_incr;
+        int (*resample_func)(struct ResampleContext *c, void *dst,
+                             const void *src, int n, int update_ctx);
 
         dst_size = FFMAX(FFMIN(dst_size, delta_n), 0);
         if (dst_size > 0) {
             /* resample_linear and resample_common should have same behavior
              * when frac and dst_incr_mod are zero */
-            if (c->linear && (c->frac || c->dst_incr_mod))
-                *consumed = c->dsp.resample_linear(c, dst, src, dst_size, update_ctx);
-            else
-                *consumed = c->dsp.resample_common(c, dst, src, dst_size, update_ctx);
-        } else {
-            *consumed = 0;
+            resample_func = (c->linear && (c->frac || c->dst_incr_mod)) ?
+                            c->dsp.resample_linear : c->dsp.resample_common;
+            for (i = 0; i < dst->ch_count; i++)
+                *consumed = resample_func(c, dst->ch[i], src->ch[i], dst_size, i+1 == dst->ch_count);
         }
     }
 
-    return dst_size;
-}
-
-static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed){
-    int i, ret= -1;
-    int av_unused mm_flags = av_get_cpu_flags();
-    int need_emms = c->format == AV_SAMPLE_FMT_S16P && ARCH_X86_32 &&
-                    (mm_flags & (AV_CPU_FLAG_MMX2 | AV_CPU_FLAG_SSE2)) == AV_CPU_FLAG_MMX2;
-    int64_t max_src_size = (INT64_MAX/2 / c->phase_count) / c->src_incr;
-
-    if (c->compensation_distance)
-        dst_size = FFMIN(dst_size, c->compensation_distance);
-    src_size = FFMIN(src_size, max_src_size);
-
-    for(i=0; i<dst->ch_count; i++){
-        ret= swri_resample(c, dst->ch[i], src->ch[i],
-                           consumed, src_size, dst_size, i+1==dst->ch_count);
-    }
     if(need_emms)
         emms_c();
 
     if (c->compensation_distance) {
-        c->compensation_distance -= ret;
+        c->compensation_distance -= dst_size;
         if (!c->compensation_distance) {
             c->dst_incr     = c->ideal_dst_incr;
             c->dst_incr_div = c->dst_incr / c->src_incr;
@@ -538,7 +529,7 @@ static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, A
         }
     }
 
-    return ret;
+    return dst_size;
 }
 
 static int64_t get_delay(struct SwrContext *s, int64_t base){



More information about the ffmpeg-cvslog mailing list