[FFmpeg-cvslog] avfilter/af_atempo: improve RE_MALLOC_OR_FAIL macro

Paul B Mahol git at videolan.org
Sat Jul 15 11:45:52 EEST 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sat Jul 15 10:39:27 2023 +0200| [ef3b5789ece62c26c12697c588bbb34f3efbd437] | committer: Paul B Mahol

avfilter/af_atempo: improve RE_MALLOC_OR_FAIL macro

Make use of third parameter of av_calloc() call.

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

 libavfilter/af_atempo.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c
index 27f13638b0..4621b67b03 100644
--- a/libavfilter/af_atempo.c
+++ b/libavfilter/af_atempo.c
@@ -247,10 +247,10 @@ static void yae_release_buffers(ATempoContext *atempo)
 
 /* av_realloc is not aligned enough; fortunately, the data does not need to
  * be preserved */
-#define RE_MALLOC_OR_FAIL(field, field_size)                    \
+#define RE_MALLOC_OR_FAIL(field, field_size, element_size)      \
     do {                                                        \
         av_freep(&field);                                       \
-        field = av_calloc(field_size, 1);                       \
+        field = av_calloc(field_size, element_size);            \
         if (!field) {                                           \
             yae_release_buffers(atempo);                        \
             return AVERROR(ENOMEM);                             \
@@ -290,12 +290,12 @@ static int yae_reset(ATempoContext *atempo,
     }
 
     // initialize audio fragment buffers:
-    RE_MALLOC_OR_FAIL(atempo->frag[0].data, atempo->window * atempo->stride);
-    RE_MALLOC_OR_FAIL(atempo->frag[1].data, atempo->window * atempo->stride);
-    RE_MALLOC_OR_FAIL(atempo->frag[0].xdat_in, (atempo->window + 1) * sizeof(AVComplexFloat));
-    RE_MALLOC_OR_FAIL(atempo->frag[1].xdat_in, (atempo->window + 1) * sizeof(AVComplexFloat));
-    RE_MALLOC_OR_FAIL(atempo->frag[0].xdat, (atempo->window + 1) * sizeof(AVComplexFloat));
-    RE_MALLOC_OR_FAIL(atempo->frag[1].xdat, (atempo->window + 1) * sizeof(AVComplexFloat));
+    RE_MALLOC_OR_FAIL(atempo->frag[0].data, atempo->window, atempo->stride);
+    RE_MALLOC_OR_FAIL(atempo->frag[1].data, atempo->window, atempo->stride);
+    RE_MALLOC_OR_FAIL(atempo->frag[0].xdat_in, (atempo->window + 1), sizeof(AVComplexFloat));
+    RE_MALLOC_OR_FAIL(atempo->frag[1].xdat_in, (atempo->window + 1), sizeof(AVComplexFloat));
+    RE_MALLOC_OR_FAIL(atempo->frag[0].xdat, (atempo->window + 1), sizeof(AVComplexFloat));
+    RE_MALLOC_OR_FAIL(atempo->frag[1].xdat, (atempo->window + 1), sizeof(AVComplexFloat));
 
     // initialize rDFT contexts:
     av_tx_uninit(&atempo->real_to_complex);
@@ -313,14 +313,14 @@ static int yae_reset(ATempoContext *atempo,
         return AVERROR(ENOMEM);
     }
 
-    RE_MALLOC_OR_FAIL(atempo->correlation_in, (atempo->window + 1) * sizeof(AVComplexFloat));
-    RE_MALLOC_OR_FAIL(atempo->correlation, atempo->window * sizeof(AVComplexFloat));
+    RE_MALLOC_OR_FAIL(atempo->correlation_in, (atempo->window + 1), sizeof(AVComplexFloat));
+    RE_MALLOC_OR_FAIL(atempo->correlation, atempo->window, sizeof(AVComplexFloat));
 
     atempo->ring = atempo->window * 3;
-    RE_MALLOC_OR_FAIL(atempo->buffer, atempo->ring * atempo->stride);
+    RE_MALLOC_OR_FAIL(atempo->buffer, atempo->ring, atempo->stride);
 
     // initialize the Hann window function:
-    RE_MALLOC_OR_FAIL(atempo->hann, atempo->window * sizeof(float));
+    RE_MALLOC_OR_FAIL(atempo->hann, atempo->window, sizeof(float));
 
     for (i = 0; i < atempo->window; i++) {
         double t = (double)i / (double)(atempo->window - 1);



More information about the ffmpeg-cvslog mailing list