History

avfft: wrap lavu/tx instead of ff_dct

Lynne committed 3 years ago

Commit 86aa34d1 parent 83ede011 file · +51 −11Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/avfft.c+51−11
@@ -34,6 +34,9 @@ typedef struct AVTXWrapper { · 33 unmodified lines
3434 ptrdiff_t stride;
3535 int len;
3636 int inv;
37+
38+ float *tmp;
39+ int out_of_place;
3740 } AVTXWrapper;
3841
3942 /* FFT */
@@ -179,29 +182,66 @@ av_cold void av_rdft_end(RDFTContext *s) · 139 unmodified lines
179182 }
180183 }
181184
182−#if CONFIG_DCT
183−
184185 DCTContext *av_dct_init(int nbits, enum DCTTransformType inverse)
185186 {
186− DCTContext *s = av_malloc(sizeof(*s));
187+ int ret;
188+ const float scale_map[] = {
189+ [DCT_II] = 0.5f,
190+ [DCT_III] = 1.0f / (1 << nbits),
191+ [DCT_I] = 0.5f,
192+ [DST_I] = 2.0f,
193+ };
194+ static const enum AVTXType type_map[] = {
195+ [DCT_II] = AV_TX_FLOAT_DCT,
196+ [DCT_III] = AV_TX_FLOAT_DCT,
197+ [DCT_I] = AV_TX_FLOAT_DCT_I,
198+ [DST_I] = AV_TX_FLOAT_DST_I,
199+ };
200+
201+ AVTXWrapper *s = av_malloc(sizeof(*s));
202+ if (!s)
203+ return NULL;
187204
188− if (s && ff_dct_init(s, nbits, inverse))
189− av_freep(&s);
205+ s->len = (1 << nbits);
206+ s->out_of_place = (inverse == DCT_I) || (inverse == DST_I);
190207
191− return s;
208+ ret = av_tx_init(&s->ctx, &s->fn, type_map[inverse],
209+ (inverse == DCT_III), 1 << (nbits - (inverse == DCT_III)),
210+ &scale_map[inverse], s->out_of_place ? 0 : AV_TX_INPLACE);
211+ if (ret < 0) {
212+ av_free(s);
213+ return NULL;
214+ }
215+
216+ if (s->out_of_place) {
217+ s->tmp = av_malloc((1 << (nbits + 1))*sizeof(float));
218+ if (!s->tmp) {
219+ av_tx_uninit(&s->ctx);
220+ av_free(s);
221+ return NULL;
222+ }
223+ }
224+
225+ return (DCTContext *)s;
192226 }
193227
194228 void av_dct_calc(DCTContext *s, FFTSample *data)
195229 {
196− s->dct_calc(s, data);
230+ AVTXWrapper *w = (AVTXWrapper *)s;
231+ if (w->out_of_place) {
232+ memcpy(w->tmp, data, w->len*sizeof(float));
233+ w->fn(w->ctx, (void *)data, w->tmp, sizeof(float));
234+ } else {
235+ w->fn(w->ctx, data, (void *)data, sizeof(float));
236+ }
197237 }
198238
199239 av_cold void av_dct_end(DCTContext *s)
200240 {
201241 if (s) {
202− ff_dct_end(s);
203− av_free(s);
242+ AVTXWrapper *w = (AVTXWrapper *)s;
243+ av_tx_uninit(&w->ctx);
244+ av_free(w->tmp);
245+ av_free(w);
204246 }
205247 }
206−
207−#endif /* CONFIG_DCT */

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