[FFmpeg-devel] [PATCH] Rewrite COMMON_CORE resampling loop.

Ronald S. Bultje rsbultje at gmail.com
Tue May 27 00:09:56 CEST 2014


This moves a condition in the loop outside. In one particular fate
test (fate-swr-resample-s32p-8000-2626), this makes the code about
10% faster. It also simplifies the loop, allowing us to rewrite it
in yasm at some later point.
---
 libswresample/resample_template.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/libswresample/resample_template.c b/libswresample/resample_template.c
index becff12..44fb667 100644
--- a/libswresample/resample_template.c
+++ b/libswresample/resample_template.c
@@ -135,34 +135,36 @@ int RENAME(swri_resample)(ResampleContext *c, DELEM *dst, const DELEM *src, int
         *consumed= index;
         index = 0;
     }else if(compensation_distance == 0 && !c->linear && index >= 0){
+        int64_t end_index = (1 + src_size - c->filter_length) << c->phase_shift;
+        int64_t delta_frac = (end_index - index) * c->src_incr - c->frac;
+        int delta_n = (delta_frac + c->dst_incr - 1) / c->dst_incr;
+        int n = FFMIN(dst_size, delta_n);
         int sample_index = 0;
-        for(dst_index=0; dst_index < dst_size; dst_index++){
+
+        for (dst_index = 0; dst_index < n; dst_index++) {
             FELEM *filter;
-            sample_index += index >> c->phase_shift;
-            index &= c->phase_mask;
             filter= ((FELEM*)c->filter_bank) + c->filter_alloc*index;
 
-            if(sample_index + c->filter_length > src_size){
-                break;
-            }else{
 #ifdef COMMON_CORE
-                COMMON_CORE
+            COMMON_CORE
 #else
-                FELEM2 val=0;
-                for(i=0; i<c->filter_length; i++){
-                    val += src[sample_index + i] * (FELEM2)filter[i];
-                }
-                OUT(dst[dst_index], val);
-#endif
+            FELEM2 val=0;
+            for (i = 0; i < c->filter_length; i++) {
+                val += src[sample_index + i] * (FELEM2)filter[i];
             }
+            OUT(dst[dst_index], val);
+#endif
 
             frac += dst_incr_frac;
             index += dst_incr;
-            if(frac >= c->src_incr){
+            if (frac >= c->src_incr) {
                 frac -= c->src_incr;
                 index++;
             }
+            sample_index += index >> c->phase_shift;
+            index &= c->phase_mask;
         }
+
         *consumed = sample_index;
     }else{
         int sample_index = 0;
-- 
1.8.5.5



More information about the ffmpeg-devel mailing list