Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH 3/5] avcodec/kbdwin: Support arbitrary sized windows
Date: Sat, 17 Jun 2023 00:20:46 +0200
Message-ID: <20230616222048.6562-4-michael@niedermayer.cc> (raw)
In-Reply-To: <20230616222048.6562-1-michael@niedermayer.cc>

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 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 */
-- 
2.17.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2023-06-16 23:17 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-16 22:20 [FFmpeg-devel] [PATCH 0/5] add sdr support Michael Niedermayer
2023-06-16 22:20 ` [FFmpeg-devel] [PATCH 1/5] avutil/tx_template: extend to 2M Michael Niedermayer
2023-07-22 15:40   ` Michael Niedermayer
2023-07-23 17:48     ` Tomas Härdin
2023-07-24  8:59       ` Michael Niedermayer
2023-07-24 11:06         ` Leo Izen
2023-07-24 12:39           ` Thilo Borgmann
2023-07-24 13:04             ` Rémi Denis-Courmont
2023-07-24 15:45               ` Thilo Borgmann
2023-07-24  8:35     ` Andreas Rheinhardt
2023-07-24  8:57       ` Paul B Mahol
2023-07-24 18:46         ` Tomas Härdin
2023-07-25  6:14           ` Paul B Mahol
2023-06-16 22:20 ` [FFmpeg-devel] [PATCH 2/5] avcodec/pcm: allow Changing parameters Michael Niedermayer
2023-06-16 22:20 ` Michael Niedermayer [this message]
2023-06-16 22:20 ` [FFmpeg-devel] [PATCH 4/5] avcodec: Rename ff_kbd_window_init() as it will be needed from outside libavcodec Michael Niedermayer
2023-06-16 22:20 ` [FFmpeg-devel] [PATCH 5/5] avformat: add sdr support Michael Niedermayer
2023-06-17  6:16   ` Paul B Mahol
2023-06-17  8:46     ` Michael Niedermayer
2023-06-17 11:08       ` Paul B Mahol
2023-06-17 12:48         ` Michael Niedermayer
2023-06-17 18:08           ` Paul B Mahol
2023-06-17 18:37             ` Michael Niedermayer
2023-06-17 18:43               ` Michael Niedermayer
2023-06-18 11:46               ` Paul B Mahol
2023-06-18 12:36                 ` Kieran Kunhya
2023-06-24 10:22                   ` Tomas Härdin
2023-06-18 12:59               ` Lynne
2023-06-18 13:30                 ` Hendrik Leppkes
2023-06-18 13:45                   ` Lynne
2023-06-18 13:48                 ` Michael Niedermayer
2023-06-17 13:30   ` Leo Izen
2023-06-17 18:10     ` Michael Niedermayer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230616222048.6562-4-michael@niedermayer.cc \
    --to=michael@niedermayer.cc \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git