* [FFmpeg-devel] [PATCH] ffplay: port to lavu/tx
@ 2023-02-18 12:20 Lynne
2023-02-19 21:41 ` Marton Balint
0 siblings, 1 reply; 2+ messages in thread
From: Lynne @ 2023-02-18 12:20 UTC (permalink / raw)
To: Ffmpeg Devel
[-- Attachment #1: Type: text/plain, Size: 74 bytes --]
This ports the last user of the avfft/avdct/avrdft API.
Patch attached.
[-- Attachment #2: 0001-ffplay-port-to-lavu-tx.patch --]
[-- Type: text/x-diff, Size: 5038 bytes --]
From 85dd7ac926d298217f3d57cd389351993a6ef39c Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
Date: Sat, 18 Feb 2023 13:14:31 +0100
Subject: [PATCH] ffplay: port to lavu/tx
---
fftools/ffplay.c | 42 +++++++++++++++++++++++++++---------------
1 file changed, 27 insertions(+), 15 deletions(-)
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index d6479aef5f..234c09e074 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -47,7 +47,7 @@
#include "libavdevice/avdevice.h"
#include "libswscale/swscale.h"
#include "libavutil/opt.h"
-#include "libavcodec/avfft.h"
+#include "libavutil/tx.h"
#include "libswresample/swresample.h"
#if CONFIG_AVFILTER
@@ -264,9 +264,11 @@ typedef struct VideoState {
int16_t sample_array[SAMPLE_ARRAY_SIZE];
int sample_array_index;
int last_i_start;
- RDFTContext *rdft;
+ AVTXContext *rdft;
+ av_tx_fn rdft_fn;
int rdft_bits;
- FFTSample *rdft_data;
+ float *real_data;
+ AVComplexFloat *rdft_data;
int xpos;
double last_vis_time;
SDL_Texture *vis_texture;
@@ -1133,6 +1135,7 @@ static void video_audio_display(VideoState *s)
fill_rectangle(s->xleft, y, s->width, 1);
}
} else {
+ int err = 0;
if (realloc_texture(&s->vis_texture, SDL_PIXELFORMAT_ARGB8888, s->width, s->height, SDL_BLENDMODE_NONE, 1) < 0)
return;
@@ -1140,31 +1143,39 @@ static void video_audio_display(VideoState *s)
s->xpos = 0;
nb_display_channels= FFMIN(nb_display_channels, 2);
if (rdft_bits != s->rdft_bits) {
- av_rdft_end(s->rdft);
- av_free(s->rdft_data);
- s->rdft = av_rdft_init(rdft_bits, DFT_R2C);
+ const float rdft_scale = 1.0;
+ av_tx_uninit(&s->rdft);
+ av_freep(&s->real_data);
+ av_freep(&s->rdft_data);
s->rdft_bits = rdft_bits;
- s->rdft_data = av_malloc_array(nb_freq, 4 *sizeof(*s->rdft_data));
+ s->real_data = av_malloc_array(nb_freq, 4 *sizeof(*s->real_data));
+ s->rdft_data = av_malloc_array(nb_freq + 1, 2 *sizeof(*s->rdft_data));
+ err = av_tx_init(&s->rdft, &s->rdft_fn, AV_TX_FLOAT_RDFT,
+ 0, 1 << rdft_bits, &rdft_scale, 0);
}
- if (!s->rdft || !s->rdft_data){
+ if (err < 0 || !s->rdft_data) {
av_log(NULL, AV_LOG_ERROR, "Failed to allocate buffers for RDFT, switching to waves display\n");
s->show_mode = SHOW_MODE_WAVES;
} else {
- FFTSample *data[2];
+ float *data_in[2];
+ AVComplexFloat *data[2];
SDL_Rect rect = {.x = s->xpos, .y = 0, .w = 1, .h = s->height};
uint32_t *pixels;
int pitch;
for (ch = 0; ch < nb_display_channels; ch++) {
- data[ch] = s->rdft_data + 2 * nb_freq * ch;
+ data_in[ch] = s->real_data + 2 * nb_freq * ch;
+ data[ch] = s->rdft_data + nb_freq * ch;
i = i_start + ch;
for (x = 0; x < 2 * nb_freq; x++) {
double w = (x-nb_freq) * (1.0 / nb_freq);
- data[ch][x] = s->sample_array[i] * (1.0 - w * w);
+ data_in[ch][x] = s->sample_array[i] * (1.0 - w * w);
i += channels;
if (i >= SAMPLE_ARRAY_SIZE)
i -= SAMPLE_ARRAY_SIZE;
}
- av_rdft_calc(s->rdft, data[ch]);
+ s->rdft_fn(s->rdft, data[ch], data_in[ch], sizeof(float));
+ data[ch][0].im = data[ch][nb_freq].re;
+ data[ch][nb_freq].re = 0;
}
/* Least efficient way to do this, we should of course
* directly access it but it is more than fast enough. */
@@ -1173,8 +1184,8 @@ static void video_audio_display(VideoState *s)
pixels += pitch * s->height;
for (y = 0; y < s->height; y++) {
double w = 1 / sqrt(nb_freq);
- int a = sqrt(w * sqrt(data[0][2 * y + 0] * data[0][2 * y + 0] + data[0][2 * y + 1] * data[0][2 * y + 1]));
- int b = (nb_display_channels == 2 ) ? sqrt(w * hypot(data[1][2 * y + 0], data[1][2 * y + 1]))
+ int a = sqrt(w * sqrt(data[0][y].re * data[0][y].re + data[0][y].im * data[0][y].im));
+ int b = (nb_display_channels == 2 ) ? sqrt(w * hypot(data[1][y].re, data[1][y].im))
: a;
a = FFMIN(a, 255);
b = FFMIN(b, 255);
@@ -1210,7 +1221,8 @@ static void stream_component_close(VideoState *is, int stream_index)
is->audio_buf = NULL;
if (is->rdft) {
- av_rdft_end(is->rdft);
+ av_tx_uninit(&is->rdft);
+ av_freep(&is->real_data);
av_freep(&is->rdft_data);
is->rdft = NULL;
is->rdft_bits = 0;
--
2.39.2
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH] ffplay: port to lavu/tx
2023-02-18 12:20 [FFmpeg-devel] [PATCH] ffplay: port to lavu/tx Lynne
@ 2023-02-19 21:41 ` Marton Balint
0 siblings, 0 replies; 2+ messages in thread
From: Marton Balint @ 2023-02-19 21:41 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sat, 18 Feb 2023, Lynne wrote:
> This ports the last user of the avfft/avdct/avrdft API.
LGTM, thanks.
Marton
>
> Patch attached.
>
>
_______________________________________________
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-02-19 21:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-18 12:20 [FFmpeg-devel] [PATCH] ffplay: port to lavu/tx Lynne
2023-02-19 21:41 ` Marton Balint
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