History

ffplay: port to lavu/tx

Lynne committed 3 years ago

Commit 4acd08b1 parent a8101261 file · +27 −15Browse files

Unified · Split

fftools/ffplay.c+27−15
@@ -47,7 +47,7 @@ · 46 unmodified lines
4747 #include "libavdevice/avdevice.h"
4848 #include "libswscale/swscale.h"
4949 #include "libavutil/opt.h"
50−#include "libavcodec/avfft.h"
50+#include "libavutil/tx.h"
5151 #include "libswresample/swresample.h"
5252
5353 #include "libavfilter/avfilter.h"
@@ -262,9 +262,11 @@ typedef struct VideoState { · 208 unmodified lines
262262 int16_t sample_array[SAMPLE_ARRAY_SIZE];
263263 int sample_array_index;
264264 int last_i_start;
265− RDFTContext *rdft;
265+ AVTXContext *rdft;
266+ av_tx_fn rdft_fn;
266267 int rdft_bits;
267− FFTSample *rdft_data;
268+ float *real_data;
269+ AVComplexFloat *rdft_data;
268270 int xpos;
269271 double last_vis_time;
270272 SDL_Texture *vis_texture;
@@ -1120,6 +1122,7 @@ static void video_audio_display(VideoState *s) · 849 unmodified lines
11201122 fill_rectangle(s->xleft, y, s->width, 1);
11211123 }
11221124 } else {
1125+ int err = 0;
11231126 if (realloc_texture(&s->vis_texture, SDL_PIXELFORMAT_ARGB8888, s->width, s->height, SDL_BLENDMODE_NONE, 1) < 0)
11241127 return;
11251128
@@ -1127,31 +1130,39 @@ static void video_audio_display(VideoState *s) · 1 unmodified line
11271130 s->xpos = 0;
11281131 nb_display_channels= FFMIN(nb_display_channels, 2);
11291132 if (rdft_bits != s->rdft_bits) {
1130− av_rdft_end(s->rdft);
1131− av_free(s->rdft_data);
1132− s->rdft = av_rdft_init(rdft_bits, DFT_R2C);
1133+ const float rdft_scale = 1.0;
1134+ av_tx_uninit(&s->rdft);
1135+ av_freep(&s->real_data);
1136+ av_freep(&s->rdft_data);
11331137 s->rdft_bits = rdft_bits;
1134− s->rdft_data = av_malloc_array(nb_freq, 4 *sizeof(*s->rdft_data));
1138+ s->real_data = av_malloc_array(nb_freq, 4 *sizeof(*s->real_data));
1139+ s->rdft_data = av_malloc_array(nb_freq + 1, 2 *sizeof(*s->rdft_data));
1140+ err = av_tx_init(&s->rdft, &s->rdft_fn, AV_TX_FLOAT_RDFT,
1141+ 0, 1 << rdft_bits, &rdft_scale, 0);
11351142 }
1136− if (!s->rdft || !s->rdft_data){
1143+ if (err < 0 || !s->rdft_data) {
11371144 av_log(NULL, AV_LOG_ERROR, "Failed to allocate buffers for RDFT, switching to waves display\n");
11381145 s->show_mode = SHOW_MODE_WAVES;
11391146 } else {
1140− FFTSample *data[2];
1147+ float *data_in[2];
1148+ AVComplexFloat *data[2];
11411149 SDL_Rect rect = {.x = s->xpos, .y = 0, .w = 1, .h = s->height};
11421150 uint32_t *pixels;
11431151 int pitch;
11441152 for (ch = 0; ch < nb_display_channels; ch++) {
1145− data[ch] = s->rdft_data + 2 * nb_freq * ch;
1153+ data_in[ch] = s->real_data + 2 * nb_freq * ch;
1154+ data[ch] = s->rdft_data + nb_freq * ch;
11461155 i = i_start + ch;
11471156 for (x = 0; x < 2 * nb_freq; x++) {
11481157 double w = (x-nb_freq) * (1.0 / nb_freq);
1149− data[ch][x] = s->sample_array[i] * (1.0 - w * w);
1158+ data_in[ch][x] = s->sample_array[i] * (1.0 - w * w);
11501159 i += channels;
11511160 if (i >= SAMPLE_ARRAY_SIZE)
11521161 i -= SAMPLE_ARRAY_SIZE;
11531162 }
1154− av_rdft_calc(s->rdft, data[ch]);
1163+ s->rdft_fn(s->rdft, data[ch], data_in[ch], sizeof(float));
1164+ data[ch][0].im = data[ch][nb_freq].re;
1165+ data[ch][nb_freq].re = 0;
11551166 }
11561167 /* Least efficient way to do this, we should of course
11571168 * directly access it but it is more than fast enough. */
@@ -1160,8 +1171,8 @@ static void video_audio_display(VideoState *s) · 2 unmodified lines
11601171 pixels += pitch * s->height;
11611172 for (y = 0; y < s->height; y++) {
11621173 double w = 1 / sqrt(nb_freq);
1163− 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]));
1164− int b = (nb_display_channels == 2 ) ? sqrt(w * hypot(data[1][2 * y + 0], data[1][2 * y + 1]))
1174+ int a = sqrt(w * sqrt(data[0][y].re * data[0][y].re + data[0][y].im * data[0][y].im));
1175+ int b = (nb_display_channels == 2 ) ? sqrt(w * hypot(data[1][y].re, data[1][y].im))
11651176 : a;
11661177 a = FFMIN(a, 255);
11671178 b = FFMIN(b, 255);
@@ -1197,7 +1208,8 @@ static void stream_component_close(VideoState *is, int stream_index) · 29 unmodified lines
11971208 is->audio_buf = NULL;
11981209
11991210 if (is->rdft) {
1200− av_rdft_end(is->rdft);
1211+ av_tx_uninit(&is->rdft);
1212+ av_freep(&is->real_data);
12011213 av_freep(&is->rdft_data);
12021214 is->rdft = NULL;
12031215 is->rdft_bits = 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t