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
47#include "libavdevice/avdevice.h"47#include "libavdevice/avdevice.h"
48#include "libswscale/swscale.h"48#include "libswscale/swscale.h"
49#include "libavutil/opt.h"49#include "libavutil/opt.h"
50#include "libavcodec/avfft.h"50#include "libavutil/tx.h"
51#include "libswresample/swresample.h"51#include "libswresample/swresample.h"
52 52
53#include "libavfilter/avfilter.h"53#include "libavfilter/avfilter.h"
@@ -262,9 +262,11 @@ typedef struct VideoState { · 208 unmodified lines
262 int16_t sample_array[SAMPLE_ARRAY_SIZE];262 int16_t sample_array[SAMPLE_ARRAY_SIZE];
263 int sample_array_index;263 int sample_array_index;
264 int last_i_start;264 int last_i_start;
265 RDFTContext *rdft;265 AVTXContext *rdft;
266 av_tx_fn rdft_fn;
266 int rdft_bits;267 int rdft_bits;
267 FFTSample *rdft_data;268 float *real_data;
269 AVComplexFloat *rdft_data;
268 int xpos;270 int xpos;
269 double last_vis_time;271 double last_vis_time;
270 SDL_Texture *vis_texture;272 SDL_Texture *vis_texture;
@@ -1120,6 +1122,7 @@ static void video_audio_display(VideoState *s) · 849 unmodified lines
1120 fill_rectangle(s->xleft, y, s->width, 1);1122 fill_rectangle(s->xleft, y, s->width, 1);
1121 }1123 }
1122 } else {1124 } else {
1125 int err = 0;
1123 if (realloc_texture(&s->vis_texture, SDL_PIXELFORMAT_ARGB8888, s->width, s->height, SDL_BLENDMODE_NONE, 1) < 0)1126 if (realloc_texture(&s->vis_texture, SDL_PIXELFORMAT_ARGB8888, s->width, s->height, SDL_BLENDMODE_NONE, 1) < 0)
1124 return;1127 return;
1125 1128
@@ -1127,31 +1130,39 @@ static void video_audio_display(VideoState *s) · 1 unmodified line
1127 s->xpos = 0;1130 s->xpos = 0;
1128 nb_display_channels= FFMIN(nb_display_channels, 2);1131 nb_display_channels= FFMIN(nb_display_channels, 2);
1129 if (rdft_bits != s->rdft_bits) {1132 if (rdft_bits != s->rdft_bits) {
1130 av_rdft_end(s->rdft);1133 const float rdft_scale = 1.0;
1131 av_free(s->rdft_data);1134 av_tx_uninit(&s->rdft);
1132 s->rdft = av_rdft_init(rdft_bits, DFT_R2C);1135 av_freep(&s->real_data);
1136 av_freep(&s->rdft_data);
1133 s->rdft_bits = rdft_bits;1137 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);
1135 }1142 }
1136 if (!s->rdft || !s->rdft_data){1143 if (err < 0 || !s->rdft_data) {
1137 av_log(NULL, AV_LOG_ERROR, "Failed to allocate buffers for RDFT, switching to waves display\n");1144 av_log(NULL, AV_LOG_ERROR, "Failed to allocate buffers for RDFT, switching to waves display\n");
1138 s->show_mode = SHOW_MODE_WAVES;1145 s->show_mode = SHOW_MODE_WAVES;
1139 } else {1146 } else {
1140 FFTSample *data[2];1147 float *data_in[2];
1148 AVComplexFloat *data[2];
1141 SDL_Rect rect = {.x = s->xpos, .y = 0, .w = 1, .h = s->height};1149 SDL_Rect rect = {.x = s->xpos, .y = 0, .w = 1, .h = s->height};
1142 uint32_t *pixels;1150 uint32_t *pixels;
1143 int pitch;1151 int pitch;
1144 for (ch = 0; ch < nb_display_channels; ch++) {1152 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;
1146 i = i_start + ch;1155 i = i_start + ch;
1147 for (x = 0; x < 2 * nb_freq; x++) {1156 for (x = 0; x < 2 * nb_freq; x++) {
1148 double w = (x-nb_freq) * (1.0 / nb_freq);1157 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);
1150 i += channels;1159 i += channels;
1151 if (i >= SAMPLE_ARRAY_SIZE)1160 if (i >= SAMPLE_ARRAY_SIZE)
1152 i -= SAMPLE_ARRAY_SIZE;1161 i -= SAMPLE_ARRAY_SIZE;
1153 }1162 }
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;
1155 }1166 }
1156 /* Least efficient way to do this, we should of course1167 /* Least efficient way to do this, we should of course
1157 * directly access it but it is more than fast enough. */1168 * directly access it but it is more than fast enough. */
@@ -1160,8 +1171,8 @@ static void video_audio_display(VideoState *s) · 2 unmodified lines
1160 pixels += pitch * s->height;1171 pixels += pitch * s->height;
1161 for (y = 0; y < s->height; y++) {1172 for (y = 0; y < s->height; y++) {
1162 double w = 1 / sqrt(nb_freq);1173 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]));1174 int a = sqrt(w * sqrt(data[0][y].re * data[0][y].re + data[0][y].im * data[0][y].im));
1164 int b = (nb_display_channels == 2 ) ? sqrt(w * hypot(data[1][2 * y + 0], data[1][2 * y + 1]))1175 int b = (nb_display_channels == 2 ) ? sqrt(w * hypot(data[1][y].re, data[1][y].im))
1165 : a;1176 : a;
1166 a = FFMIN(a, 255);1177 a = FFMIN(a, 255);
1167 b = FFMIN(b, 255);1178 b = FFMIN(b, 255);
@@ -1197,7 +1208,8 @@ static void stream_component_close(VideoState *is, int stream_index) · 29 unmodified lines
1197 is->audio_buf = NULL;1208 is->audio_buf = NULL;
1198 1209
1199 if (is->rdft) {1210 if (is->rdft) {
1200 av_rdft_end(is->rdft);1211 av_tx_uninit(&is->rdft);
1212 av_freep(&is->real_data);
1201 av_freep(&is->rdft_data);1213 av_freep(&is->rdft_data);
1202 is->rdft = NULL;1214 is->rdft = NULL;
1203 is->rdft_bits = 0;1215 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