Originally committed as revision 24142 to svn://svn.ffmpeg.org/ffmpeg/trunk
Måns Rullgård authored on 2010/07/10 01:05:58... | ... |
@@ -94,12 +94,17 @@ static double bessel(double x){ |
94 | 94 |
* @param factor resampling factor |
95 | 95 |
* @param scale wanted sum of coefficients for each filter |
96 | 96 |
* @param type 0->cubic, 1->blackman nuttall windowed sinc, 2..16->kaiser windowed sinc beta=2..16 |
97 |
+ * @return 0 on success, negative on error |
|
97 | 98 |
*/ |
98 |
-static void build_filter(FELEM *filter, double factor, int tap_count, int phase_count, int scale, int type){ |
|
99 |
+static int build_filter(FELEM *filter, double factor, int tap_count, int phase_count, int scale, int type){ |
|
99 | 100 |
int ph, i; |
100 |
- double x, y, w, tab[tap_count]; |
|
101 |
+ double x, y, w; |
|
102 |
+ double *tab = av_malloc(tap_count * sizeof(*tab)); |
|
101 | 103 |
const int center= (tap_count-1)/2; |
102 | 104 |
|
105 |
+ if (!tab) |
|
106 |
+ return AVERROR(ENOMEM); |
|
107 |
+ |
|
103 | 108 |
/* if upsampling, only need to interpolate, no filter */ |
104 | 109 |
if (factor > 1.0) |
105 | 110 |
factor = 1.0; |
... | ... |
@@ -176,6 +181,9 @@ static void build_filter(FELEM *filter, double factor, int tap_count, int phase_ |
176 | 176 |
} |
177 | 177 |
} |
178 | 178 |
#endif |
179 |
+ |
|
180 |
+ av_free(tab); |
|
181 |
+ return 0; |
|
179 | 182 |
} |
180 | 183 |
|
181 | 184 |
AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff){ |
... | ... |
@@ -194,7 +202,8 @@ AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size, |
194 | 194 |
c->filter_bank= av_mallocz(c->filter_length*(phase_count+1)*sizeof(FELEM)); |
195 | 195 |
if (!c->filter_bank) |
196 | 196 |
goto error; |
197 |
- build_filter(c->filter_bank, factor, c->filter_length, phase_count, 1<<FILTER_SHIFT, WINDOW_TYPE); |
|
197 |
+ if (build_filter(c->filter_bank, factor, c->filter_length, phase_count, 1<<FILTER_SHIFT, WINDOW_TYPE)) |
|
198 |
+ goto error; |
|
198 | 199 |
memcpy(&c->filter_bank[c->filter_length*phase_count+1], c->filter_bank, (c->filter_length-1)*sizeof(FELEM)); |
199 | 200 |
c->filter_bank[c->filter_length*phase_count]= c->filter_bank[c->filter_length - 1]; |
200 | 201 |
|
... | ... |
@@ -204,6 +213,7 @@ AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size, |
204 | 204 |
|
205 | 205 |
return c; |
206 | 206 |
error: |
207 |
+ av_free(c->filter_bank); |
|
207 | 208 |
av_free(c); |
208 | 209 |
return NULL; |
209 | 210 |
} |