[FFmpeg-cvslog] avcodec/kbdwin: Support arbitrary sized windows
Michael Niedermayer
git at videolan.org
Sat Jul 22 18:55:04 EEST 2023
ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Wed Jun 14 17:22:55 2023 +0200| [cf00f60bab1f79213c274a6cd4357b32bd5c0101] | committer: Michael Niedermayer
avcodec/kbdwin: Support arbitrary sized windows
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cf00f60bab1f79213c274a6cd4357b32bd5c0101
---
libavcodec/kbdwin.c | 22 ++++++++++++++--------
libavcodec/kbdwin.h | 8 +++++---
2 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/libavcodec/kbdwin.c b/libavcodec/kbdwin.c
index 163f9d5251..82755874d4 100644
--- a/libavcodec/kbdwin.c
+++ b/libavcodec/kbdwin.c
@@ -19,20 +19,23 @@
#include "libavutil/avassert.h"
#include "libavutil/mathematics.h"
#include "libavutil/attributes.h"
+#include "libavutil/mem.h"
#include "kbdwin.h"
-av_cold static void kbd_window_init(float *float_window, int *int_window, float alpha, int n)
+av_cold static int kbd_window_init(float *float_window, int *int_window, float alpha, int n)
{
int i;
double sum = 0.0, tmp;
double scale = 0.0;
- double temp[FF_KBD_WINDOW_MAX / 2 + 1];
+ double temp_small[FF_KBD_WINDOW_MAX / 2 + 1];
+ double *temp= n<=FF_KBD_WINDOW_MAX ? temp_small : av_malloc((n/2+1) * sizeof(*temp));
double alpha2 = 4 * (alpha * M_PI / n) * (alpha * M_PI / n);
- av_assert0(n <= FF_KBD_WINDOW_MAX);
+ if (!temp)
+ return AVERROR(ENOMEM);
for (i = 0; i <= n / 2; i++) {
- tmp = i * (n - i) * alpha2;
+ tmp = alpha2 * i * (n - i);
temp[i] = av_bessel_i0(sqrt(tmp));
scale += temp[i] * (1 + (i && i<n/2));
}
@@ -48,14 +51,17 @@ av_cold static void kbd_window_init(float *float_window, int *int_window, float
if (float_window) float_window[i] = sqrt(sum * scale);
else int_window[i] = lrint(2147483647 * sqrt(sum * scale));
}
+ if (temp != temp_small)
+ av_free(temp);
+ return 0;
}
-av_cold void ff_kbd_window_init(float *window, float alpha, int n)
+av_cold int ff_kbd_window_init(float *window, float alpha, int n)
{
- kbd_window_init(window, NULL, alpha, n);
+ return kbd_window_init(window, NULL, alpha, n);
}
-av_cold void ff_kbd_window_init_fixed(int32_t *window, float alpha, int n)
+av_cold int ff_kbd_window_init_fixed(int32_t *window, float alpha, int n)
{
- kbd_window_init(NULL, window, alpha, n);
+ return kbd_window_init(NULL, window, alpha, n);
}
diff --git a/libavcodec/kbdwin.h b/libavcodec/kbdwin.h
index 4185c4206f..452fc46596 100644
--- a/libavcodec/kbdwin.h
+++ b/libavcodec/kbdwin.h
@@ -30,9 +30,11 @@
* Generate a Kaiser-Bessel Derived Window.
* @param window pointer to half window
* @param alpha determines window shape
- * @param n size of half window, max FF_KBD_WINDOW_MAX
+ * @param n size of half window
+ *
+ * @return if n is larger than FF_KBD_WINDOW_MAX then AVERROR(ENOMEM) is possible
*/
-void ff_kbd_window_init(float *window, float alpha, int n);
-void ff_kbd_window_init_fixed(int32_t *window, float alpha, int n);
+int ff_kbd_window_init(float *window, float alpha, int n);
+int ff_kbd_window_init_fixed(int32_t *window, float alpha, int n);
#endif /* AVCODEC_KBDWIN_H */
More information about the ffmpeg-cvslog
mailing list