[FFmpeg-cvslog] iir: change filter type if/else to a switch.

Justin Ruggles git
Fri Jan 21 20:40:04 CET 2011


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Thu Jan 20 21:59:23 2011 +0000| [a994f861965ce9837d0c7089b8f358c682604729] | committer: Michael Niedermayer

iir: change filter type if/else to a switch.

Simplifies error handling and makes it easier to add additional filter types.

Signed-off-by: Mans Rullgard <mans at mansr.com>
(cherry picked from commit 0361d13cf3956dcf38f31b9df97aca9301cdc86a)

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

 libavcodec/iirfilter.c |   25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/libavcodec/iirfilter.c b/libavcodec/iirfilter.c
index 0854820..6133a54 100644
--- a/libavcodec/iirfilter.c
+++ b/libavcodec/iirfilter.c
@@ -164,6 +164,7 @@ av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc,
                                                 float stopband, float ripple)
 {
     FFIIRFilterCoeffs *c;
+    int ret = 0;
 
     if (order <= 0 || order > MAXORDER || cutoff_ratio >= 1.0)
         return NULL;
@@ -176,22 +177,22 @@ av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc,
                       init_fail);
     c->order = order;
 
-    if (filt_type == FF_FILTER_TYPE_BUTTERWORTH) {
-        if (butterworth_init_coeffs(avc, c, filt_mode, order, cutoff_ratio,
-            stopband)) {
-            goto init_fail;
-        }
-    } else if (filt_type == FF_FILTER_TYPE_BIQUAD) {
-        if (biquad_init_coeffs(avc, c, filt_mode, order, cutoff_ratio,
-            stopband)) {
-            goto init_fail;
-        }
-    } else {
+    switch (filt_type) {
+    case FF_FILTER_TYPE_BUTTERWORTH:
+        ret = butterworth_init_coeffs(avc, c, filt_mode, order, cutoff_ratio,
+                                      stopband);
+        break;
+    case FF_FILTER_TYPE_BIQUAD:
+        ret = biquad_init_coeffs(avc, c, filt_mode, order, cutoff_ratio,
+                                 stopband);
+        break;
+    default:
         av_log(avc, AV_LOG_ERROR, "filter type is not currently implemented\n");
         goto init_fail;
     }
 
-    return c;
+    if (!ret)
+        return c;
 
 init_fail:
     ff_iir_filter_free_coeffs(c);




More information about the ffmpeg-cvslog mailing list