]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/asrc_sinc.c
avfilter: Constify all AVFilters
[ffmpeg] / libavfilter / asrc_sinc.c
index 0135eb9023ba0da7fd1bc38742bd7a45c4ef2630..e4aa51c0d0bd526c3bc8a895c10e404d7c0fe613 100644 (file)
@@ -84,7 +84,7 @@ static int query_formats(AVFilterContext *ctx)
     if (ret < 0)
         return ret;
 
-    layouts = avfilter_make_format64_list(chlayouts);
+    layouts = ff_make_format64_list(chlayouts);
     if (!layouts)
         return AVERROR(ENOMEM);
     ret = ff_set_common_channel_layouts(ctx, layouts);
@@ -227,10 +227,11 @@ static int fir_to_phase(SincContext *s, float **h, int *len, int *post_len, floa
 
     for (i = *len, work_len = 2 * 2 * 8; i > 1; work_len <<= 1, i >>= 1);
 
-    work = av_calloc(work_len + 2, sizeof(*work));    /* +2: (UN)PACK */
-    pi_wraps = av_calloc(((work_len + 2) / 2), sizeof(*pi_wraps));
-    if (!work || !pi_wraps)
+    /* The first part is for work (+2 for (UN)PACK), the latter for pi_wraps. */
+    work = av_calloc((work_len + 2) + (work_len / 2 + 1), sizeof(float));
+    if (!work)
         return AVERROR(ENOMEM);
+    pi_wraps = &work[work_len + 2];
 
     memcpy(work, *h, *len * sizeof(*work));
 
@@ -239,8 +240,10 @@ static int fir_to_phase(SincContext *s, float **h, int *len, int *post_len, floa
     s->rdft = s->irdft = NULL;
     s->rdft  = av_rdft_init(av_log2(work_len), DFT_R2C);
     s->irdft = av_rdft_init(av_log2(work_len), IDFT_C2R);
-    if (!s->rdft || !s->irdft)
+    if (!s->rdft || !s->irdft) {
+        av_free(work);
         return AVERROR(ENOMEM);
+    }
 
     av_rdft_calc(s->rdft, work);   /* Cepstral: */
     UNPACK(work, work_len);
@@ -320,7 +323,6 @@ static int fir_to_phase(SincContext *s, float **h, int *len, int *post_len, floa
         *len = end - begin;
         *h = av_realloc_f(*h, *len, sizeof(**h));
         if (!*h) {
-            av_free(pi_wraps);
             av_free(work);
             return AVERROR(ENOMEM);
         }
@@ -335,7 +337,6 @@ static int fir_to_phase(SincContext *s, float **h, int *len, int *post_len, floa
            work_len, pi_wraps[work_len >> 1] / M_PI, peak, peak_imp_sum, imp_peak,
            work[imp_peak], *len, *post_len, 100.f - 100.f * *post_len / (*len - 1));
 
-    av_free(pi_wraps);
     av_free(work);
 
     return 0;
@@ -443,7 +444,7 @@ static const AVOption sinc_options[] = {
 
 AVFILTER_DEFINE_CLASS(sinc);
 
-AVFilter ff_asrc_sinc = {
+const AVFilter ff_asrc_sinc = {
     .name          = "sinc",
     .description   = NULL_IF_CONFIG_SMALL("Generate a sinc kaiser-windowed low-pass, high-pass, band-pass, or band-reject FIR coefficients."),
     .priv_size     = sizeof(SincContext),