]> git.sesse.net Git - ffmpeg/blob - libavcodec/dcaenc.c
Support reading 64bit sgi images.
[ffmpeg] / libavcodec / dcaenc.c
1 /*
2  * DCA encoder
3  * Copyright (C) 2008 Alexander E. Patrakov
4  *               2010 Benjamin Larsson
5  *               2011 Xiang Wang
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23
24 #include "libavutil/common.h"
25 #include "libavutil/avassert.h"
26 #include "libavutil/audioconvert.h"
27 #include "avcodec.h"
28 #include "get_bits.h"
29 #include "put_bits.h"
30 #include "dcaenc.h"
31 #include "dcadata.h"
32
33 #undef NDEBUG
34
35 #define MAX_CHANNELS 6
36 #define DCA_SUBBANDS_32 32
37 #define DCA_MAX_FRAME_SIZE 16383
38 #define DCA_HEADER_SIZE 13
39
40 #define DCA_SUBBANDS 32 ///< Subband activity count
41 #define QUANTIZER_BITS 16
42 #define SUBFRAMES 1
43 #define SUBSUBFRAMES 4
44 #define PCM_SAMPLES (SUBFRAMES*SUBSUBFRAMES*8)
45 #define LFE_BITS 8
46 #define LFE_INTERPOLATION 64
47 #define LFE_PRESENT 2
48 #define LFE_MISSING 0
49
50 static const int8_t dca_lfe_index[] = {
51     1,2,2,2,2,3,2,3,2,3,2,3,1,3,2,3
52 };
53
54 static const int8_t dca_channel_reorder_lfe[][9] = {
55     { 0, -1, -1, -1, -1, -1, -1, -1, -1 },
56     { 0,  1, -1, -1, -1, -1, -1, -1, -1 },
57     { 0,  1, -1, -1, -1, -1, -1, -1, -1 },
58     { 0,  1, -1, -1, -1, -1, -1, -1, -1 },
59     { 0,  1, -1, -1, -1, -1, -1, -1, -1 },
60     { 1,  2,  0, -1, -1, -1, -1, -1, -1 },
61     { 0,  1, -1,  2, -1, -1, -1, -1, -1 },
62     { 1,  2,  0, -1,  3, -1, -1, -1, -1 },
63     { 0,  1, -1,  2,  3, -1, -1, -1, -1 },
64     { 1,  2,  0, -1,  3,  4, -1, -1, -1 },
65     { 2,  3, -1,  0,  1,  4,  5, -1, -1 },
66     { 1,  2,  0, -1,  3,  4,  5, -1, -1 },
67     { 0, -1,  4,  5,  2,  3,  1, -1, -1 },
68     { 3,  4,  1, -1,  0,  2,  5,  6, -1 },
69     { 2,  3, -1,  5,  7,  0,  1,  4,  6 },
70     { 3,  4,  1, -1,  0,  2,  5,  7,  6 },
71 };
72
73 static const int8_t dca_channel_reorder_nolfe[][9] = {
74     { 0, -1, -1, -1, -1, -1, -1, -1, -1 },
75     { 0,  1, -1, -1, -1, -1, -1, -1, -1 },
76     { 0,  1, -1, -1, -1, -1, -1, -1, -1 },
77     { 0,  1, -1, -1, -1, -1, -1, -1, -1 },
78     { 0,  1, -1, -1, -1, -1, -1, -1, -1 },
79     { 1,  2,  0, -1, -1, -1, -1, -1, -1 },
80     { 0,  1,  2, -1, -1, -1, -1, -1, -1 },
81     { 1,  2,  0,  3, -1, -1, -1, -1, -1 },
82     { 0,  1,  2,  3, -1, -1, -1, -1, -1 },
83     { 1,  2,  0,  3,  4, -1, -1, -1, -1 },
84     { 2,  3,  0,  1,  4,  5, -1, -1, -1 },
85     { 1,  2,  0,  3,  4,  5, -1, -1, -1 },
86     { 0,  4,  5,  2,  3,  1, -1, -1, -1 },
87     { 3,  4,  1,  0,  2,  5,  6, -1, -1 },
88     { 2,  3,  5,  7,  0,  1,  4,  6, -1 },
89     { 3,  4,  1,  0,  2,  5,  7,  6, -1 },
90 };
91
92 typedef struct {
93     PutBitContext pb;
94     int32_t history[MAX_CHANNELS][512]; /* This is a circular buffer */
95     int start[MAX_CHANNELS];
96     int frame_size;
97     int prim_channels;
98     int lfe_channel;
99     int sample_rate_code;
100     int scale_factor[MAX_CHANNELS][DCA_SUBBANDS_32];
101     int lfe_scale_factor;
102     int lfe_data[SUBFRAMES*SUBSUBFRAMES*4];
103
104     int a_mode;                         ///< audio channels arrangement
105     int num_channel;
106     int lfe_state;
107     int lfe_offset;
108     const int8_t *channel_order_tab;    ///< channel reordering table, lfe and non lfe
109
110     int32_t pcm[FFMAX(LFE_INTERPOLATION, DCA_SUBBANDS_32)];
111     int32_t subband[PCM_SAMPLES][MAX_CHANNELS][DCA_SUBBANDS_32]; /* [sample][channel][subband] */
112 } DCAContext;
113
114 static int32_t cos_table[128];
115
116 static inline int32_t mul32(int32_t a, int32_t b)
117 {
118     int64_t r = (int64_t) a * b;
119     /* round the result before truncating - improves accuracy */
120     return (r + 0x80000000) >> 32;
121 }
122
123 /* Integer version of the cosine modulated Pseudo QMF */
124
125 static void qmf_init(void)
126 {
127     int i;
128     int32_t c[17], s[17];
129     s[0] = 0;           /* sin(index * PI / 64) * 0x7fffffff */
130     c[0] = 0x7fffffff;  /* cos(index * PI / 64) * 0x7fffffff */
131
132     for (i = 1; i <= 16; i++) {
133         s[i] = 2 * (mul32(c[i - 1], 105372028)  + mul32(s[i - 1], 2144896908));
134         c[i] = 2 * (mul32(c[i - 1], 2144896908) - mul32(s[i - 1], 105372028));
135     }
136
137     for (i = 0; i < 16; i++) {
138         cos_table[i      ]  =  c[i]      >> 3; /* avoid output overflow */
139         cos_table[i +  16]  =  s[16 - i] >> 3;
140         cos_table[i +  32]  = -s[i]      >> 3;
141         cos_table[i +  48]  = -c[16 - i] >> 3;
142         cos_table[i +  64]  = -c[i]      >> 3;
143         cos_table[i +  80]  = -s[16 - i] >> 3;
144         cos_table[i +  96]  =  s[i]      >> 3;
145         cos_table[i + 112]  =  c[16 - i] >> 3;
146     }
147 }
148
149 static int32_t band_delta_factor(int band, int sample_num)
150 {
151     int index = band * (2 * sample_num + 1);
152     if (band == 0)
153         return 0x07ffffff;
154     else
155         return cos_table[index & 127];
156 }
157
158 static void add_new_samples(DCAContext *c, const int32_t *in,
159                             int count, int channel)
160 {
161     int i;
162
163     /* Place new samples into the history buffer */
164     for (i = 0; i < count; i++) {
165         c->history[channel][c->start[channel] + i] = in[i];
166         av_assert0(c->start[channel] + i < 512);
167     }
168     c->start[channel] += count;
169     if (c->start[channel] == 512)
170         c->start[channel] = 0;
171     av_assert0(c->start[channel] < 512);
172 }
173
174 static void qmf_decompose(DCAContext *c, int32_t in[32], int32_t out[32],
175                           int channel)
176 {
177     int band, i, j, k;
178     int32_t resp;
179     int32_t accum[DCA_SUBBANDS_32] = {0};
180
181     add_new_samples(c, in, DCA_SUBBANDS_32, channel);
182
183     /* Calculate the dot product of the signal with the (possibly inverted)
184        reference decoder's response to this vector:
185        (0.0, 0.0, ..., 0.0, -1.0, 1.0, 0.0, ..., 0.0)
186        so that -1.0 cancels 1.0 from the previous step */
187
188     for (k = 48, j = 0, i = c->start[channel]; i < 512; k++, j++, i++)
189         accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += mul32(c->history[channel][i], UnQMF[j]);
190     for (i = 0; i < c->start[channel]; k++, j++, i++)
191         accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += mul32(c->history[channel][i], UnQMF[j]);
192
193     resp = 0;
194     /* TODO: implement FFT instead of this naive calculation */
195     for (band = 0; band < DCA_SUBBANDS_32; band++) {
196         for (j = 0; j < 32; j++)
197             resp += mul32(accum[j], band_delta_factor(band, j));
198
199         out[band] = (band & 2) ? (-resp) : resp;
200     }
201 }
202
203 static int32_t lfe_fir_64i[512];
204 static int lfe_downsample(DCAContext *c, int32_t in[LFE_INTERPOLATION])
205 {
206     int i, j;
207     int channel = c->prim_channels;
208     int32_t accum = 0;
209
210     add_new_samples(c, in, LFE_INTERPOLATION, channel);
211     for (i = c->start[channel], j = 0; i < 512; i++, j++)
212         accum += mul32(c->history[channel][i], lfe_fir_64i[j]);
213     for (i = 0; i < c->start[channel]; i++, j++)
214         accum += mul32(c->history[channel][i], lfe_fir_64i[j]);
215     return accum;
216 }
217
218 static void init_lfe_fir(void)
219 {
220     static int initialized = 0;
221     int i;
222     if (initialized)
223         return;
224
225     for (i = 0; i < 512; i++)
226         lfe_fir_64i[i] = lfe_fir_64[i] * (1 << 25); //float -> int32_t
227     initialized = 1;
228 }
229
230 static void put_frame_header(DCAContext *c)
231 {
232     /* SYNC */
233     put_bits(&c->pb, 16, 0x7ffe);
234     put_bits(&c->pb, 16, 0x8001);
235
236     /* Frame type: normal */
237     put_bits(&c->pb, 1, 1);
238
239     /* Deficit sample count: none */
240     put_bits(&c->pb, 5, 31);
241
242     /* CRC is not present */
243     put_bits(&c->pb, 1, 0);
244
245     /* Number of PCM sample blocks */
246     put_bits(&c->pb, 7, PCM_SAMPLES-1);
247
248     /* Primary frame byte size */
249     put_bits(&c->pb, 14, c->frame_size-1);
250
251     /* Audio channel arrangement: L + R (stereo) */
252     put_bits(&c->pb, 6, c->num_channel);
253
254     /* Core audio sampling frequency */
255     put_bits(&c->pb, 4, c->sample_rate_code);
256
257     /* Transmission bit rate: 1411.2 kbps */
258     put_bits(&c->pb, 5, 0x16); /* FIXME: magic number */
259
260     /* Embedded down mix: disabled */
261     put_bits(&c->pb, 1, 0);
262
263     /* Embedded dynamic range flag: not present */
264     put_bits(&c->pb, 1, 0);
265
266     /* Embedded time stamp flag: not present */
267     put_bits(&c->pb, 1, 0);
268
269     /* Auxiliary data flag: not present */
270     put_bits(&c->pb, 1, 0);
271
272     /* HDCD source: no */
273     put_bits(&c->pb, 1, 0);
274
275     /* Extension audio ID: N/A */
276     put_bits(&c->pb, 3, 0);
277
278     /* Extended audio data: not present */
279     put_bits(&c->pb, 1, 0);
280
281     /* Audio sync word insertion flag: after each sub-frame */
282     put_bits(&c->pb, 1, 0);
283
284     /* Low frequency effects flag: not present or interpolation factor=64 */
285     put_bits(&c->pb, 2, c->lfe_state);
286
287     /* Predictor history switch flag: on */
288     put_bits(&c->pb, 1, 1);
289
290     /* No CRC */
291     /* Multirate interpolator switch: non-perfect reconstruction */
292     put_bits(&c->pb, 1, 0);
293
294     /* Encoder software revision: 7 */
295     put_bits(&c->pb, 4, 7);
296
297     /* Copy history: 0 */
298     put_bits(&c->pb, 2, 0);
299
300     /* Source PCM resolution: 16 bits, not DTS ES */
301     put_bits(&c->pb, 3, 0);
302
303     /* Front sum/difference coding: no */
304     put_bits(&c->pb, 1, 0);
305
306     /* Surrounds sum/difference coding: no */
307     put_bits(&c->pb, 1, 0);
308
309     /* Dialog normalization: 0 dB */
310     put_bits(&c->pb, 4, 0);
311 }
312
313 static void put_primary_audio_header(DCAContext *c)
314 {
315     static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
316     static const int thr[11]    = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
317
318     int ch, i;
319     /* Number of subframes */
320     put_bits(&c->pb, 4, SUBFRAMES - 1);
321
322     /* Number of primary audio channels */
323     put_bits(&c->pb, 3, c->prim_channels - 1);
324
325     /* Subband activity count */
326     for (ch = 0; ch < c->prim_channels; ch++)
327         put_bits(&c->pb, 5, DCA_SUBBANDS - 2);
328
329     /* High frequency VQ start subband */
330     for (ch = 0; ch < c->prim_channels; ch++)
331         put_bits(&c->pb, 5, DCA_SUBBANDS - 1);
332
333     /* Joint intensity coding index: 0, 0 */
334     for (ch = 0; ch < c->prim_channels; ch++)
335         put_bits(&c->pb, 3, 0);
336
337     /* Transient mode codebook: A4, A4 (arbitrary) */
338     for (ch = 0; ch < c->prim_channels; ch++)
339         put_bits(&c->pb, 2, 0);
340
341     /* Scale factor code book: 7 bit linear, 7-bit sqrt table (for each channel) */
342     for (ch = 0; ch < c->prim_channels; ch++)
343         put_bits(&c->pb, 3, 6);
344
345     /* Bit allocation quantizer select: linear 5-bit */
346     for (ch = 0; ch < c->prim_channels; ch++)
347         put_bits(&c->pb, 3, 6);
348
349     /* Quantization index codebook select: dummy data
350        to avoid transmission of scale factor adjustment */
351
352     for (i = 1; i < 11; i++)
353         for (ch = 0; ch < c->prim_channels; ch++)
354             put_bits(&c->pb, bitlen[i], thr[i]);
355
356     /* Scale factor adjustment index: not transmitted */
357 }
358
359 /**
360  * 8-23 bits quantization
361  * @param sample
362  * @param bits
363  */
364 static inline uint32_t quantize(int32_t sample, int bits)
365 {
366     av_assert0(sample <    1 << (bits - 1));
367     av_assert0(sample >= -(1 << (bits - 1)));
368     return sample & ((1 << bits) - 1);
369 }
370
371 static inline int find_scale_factor7(int64_t max_value, int bits)
372 {
373     int i = 0, j = 128, q;
374     max_value = ((max_value << 15) / lossy_quant[bits + 3]) >> (bits - 1);
375     while (i < j) {
376         q = (i + j) >> 1;
377         if (max_value < scale_factor_quant7[q])
378             j = q;
379         else
380             i = q + 1;
381     }
382     av_assert1(i < 128);
383     return i;
384 }
385
386 static inline void put_sample7(DCAContext *c, int64_t sample, int bits,
387                                int scale_factor)
388 {
389     sample = (sample << 15) / ((int64_t) lossy_quant[bits + 3] * scale_factor_quant7[scale_factor]);
390     put_bits(&c->pb, bits, quantize((int) sample, bits));
391 }
392
393 static void put_subframe(DCAContext *c,
394                          int32_t subband_data[8 * SUBSUBFRAMES][MAX_CHANNELS][32],
395                          int subframe)
396 {
397     int i, sub, ss, ch, max_value;
398     int32_t *lfe_data = c->lfe_data + 4 * SUBSUBFRAMES * subframe;
399
400     /* Subsubframes count */
401     put_bits(&c->pb, 2, SUBSUBFRAMES -1);
402
403     /* Partial subsubframe sample count: dummy */
404     put_bits(&c->pb, 3, 0);
405
406     /* Prediction mode: no ADPCM, in each channel and subband */
407     for (ch = 0; ch < c->prim_channels; ch++)
408         for (sub = 0; sub < DCA_SUBBANDS; sub++)
409             put_bits(&c->pb, 1, 0);
410
411     /* Prediction VQ addres: not transmitted */
412     /* Bit allocation index */
413     for (ch = 0; ch < c->prim_channels; ch++)
414         for (sub = 0; sub < DCA_SUBBANDS; sub++)
415             put_bits(&c->pb, 5, QUANTIZER_BITS+3);
416
417     if (SUBSUBFRAMES > 1) {
418         /* Transition mode: none for each channel and subband */
419         for (ch = 0; ch < c->prim_channels; ch++)
420             for (sub = 0; sub < DCA_SUBBANDS; sub++)
421                 put_bits(&c->pb, 1, 0); /* codebook A4 */
422     }
423
424     /* Determine scale_factor */
425     for (ch = 0; ch < c->prim_channels; ch++)
426         for (sub = 0; sub < DCA_SUBBANDS; sub++) {
427             max_value = 0;
428             for (i = 0; i < 8 * SUBSUBFRAMES; i++)
429                 max_value = FFMAX(max_value, FFABS(subband_data[i][ch][sub]));
430             c->scale_factor[ch][sub] = find_scale_factor7(max_value, QUANTIZER_BITS);
431         }
432
433     if (c->lfe_channel) {
434         max_value = 0;
435         for (i = 0; i < 4 * SUBSUBFRAMES; i++)
436             max_value = FFMAX(max_value, FFABS(lfe_data[i]));
437         c->lfe_scale_factor = find_scale_factor7(max_value, LFE_BITS);
438     }
439
440     /* Scale factors: the same for each channel and subband,
441        encoded according to Table D.1.2 */
442     for (ch = 0; ch < c->prim_channels; ch++)
443         for (sub = 0; sub < DCA_SUBBANDS; sub++)
444             put_bits(&c->pb, 7, c->scale_factor[ch][sub]);
445
446     /* Joint subband scale factor codebook select: not transmitted */
447     /* Scale factors for joint subband coding: not transmitted */
448     /* Stereo down-mix coefficients: not transmitted */
449     /* Dynamic range coefficient: not transmitted */
450     /* Stde information CRC check word: not transmitted */
451     /* VQ encoded high frequency subbands: not transmitted */
452
453     /* LFE data */
454     if (c->lfe_channel) {
455         for (i = 0; i < 4 * SUBSUBFRAMES; i++)
456             put_sample7(c, lfe_data[i], LFE_BITS, c->lfe_scale_factor);
457         put_bits(&c->pb, 8, c->lfe_scale_factor);
458     }
459
460     /* Audio data (subsubframes) */
461
462     for (ss = 0; ss < SUBSUBFRAMES ; ss++)
463         for (ch = 0; ch < c->prim_channels; ch++)
464             for (sub = 0; sub < DCA_SUBBANDS; sub++)
465                 for (i = 0; i < 8; i++)
466                     put_sample7(c, subband_data[ss * 8 + i][ch][sub], QUANTIZER_BITS, c->scale_factor[ch][sub]);
467
468     /* DSYNC */
469     put_bits(&c->pb, 16, 0xffff);
470 }
471
472 static void put_frame(DCAContext *c,
473                       int32_t subband_data[PCM_SAMPLES][MAX_CHANNELS][32],
474                       uint8_t *frame)
475 {
476     int i;
477     init_put_bits(&c->pb, frame + DCA_HEADER_SIZE, DCA_MAX_FRAME_SIZE-DCA_HEADER_SIZE);
478
479     put_primary_audio_header(c);
480     for (i = 0; i < SUBFRAMES; i++)
481         put_subframe(c, &subband_data[SUBSUBFRAMES * 8 * i], i);
482
483     flush_put_bits(&c->pb);
484     c->frame_size = (put_bits_count(&c->pb) >> 3) + DCA_HEADER_SIZE;
485
486     init_put_bits(&c->pb, frame, DCA_HEADER_SIZE);
487     put_frame_header(c);
488     flush_put_bits(&c->pb);
489 }
490
491 static int encode_frame(AVCodecContext *avctx, uint8_t *frame,
492                         int buf_size, void *data)
493 {
494     int i, k, channel;
495     DCAContext *c = avctx->priv_data;
496     int16_t *samples = data;
497     int real_channel = 0;
498
499     for (i = 0; i < PCM_SAMPLES; i ++) { /* i is the decimated sample number */
500         for (channel = 0; channel < c->prim_channels + 1; channel++) {
501             /* Get 32 PCM samples */
502             for (k = 0; k < 32; k++) { /* k is the sample number in a 32-sample block */
503                 c->pcm[k] = samples[avctx->channels * (32 * i + k) + channel] << 16;
504             }
505             /* Put subband samples into the proper place */
506             real_channel = c->channel_order_tab[channel];
507             if (real_channel >= 0) {
508                 qmf_decompose(c, c->pcm, &c->subband[i][real_channel][0], real_channel);
509             }
510         }
511     }
512
513     if (c->lfe_channel) {
514         for (i = 0; i < PCM_SAMPLES / 2; i++) {
515             for (k = 0; k < LFE_INTERPOLATION; k++) /* k is the sample number in a 32-sample block */
516                 c->pcm[k] = samples[avctx->channels * (LFE_INTERPOLATION*i+k) + c->lfe_offset] << 16;
517             c->lfe_data[i] = lfe_downsample(c, c->pcm);
518         }
519     }
520
521     put_frame(c, c->subband, frame);
522
523     return c->frame_size;
524 }
525
526 static int encode_init(AVCodecContext *avctx)
527 {
528     DCAContext *c = avctx->priv_data;
529     int i;
530
531     c->prim_channels = avctx->channels;
532     c->lfe_channel   = (avctx->channels == 3 || avctx->channels == 6);
533
534     switch (avctx->channel_layout) {
535     case AV_CH_LAYOUT_STEREO:       c->a_mode = 2; c->num_channel = 2; break;
536     case AV_CH_LAYOUT_5POINT0:      c->a_mode = 9; c->num_channel = 9; break;
537     case AV_CH_LAYOUT_5POINT1:      c->a_mode = 9; c->num_channel = 9; break;
538     case AV_CH_LAYOUT_5POINT0_BACK: c->a_mode = 9; c->num_channel = 9; break;
539     case AV_CH_LAYOUT_5POINT1_BACK: c->a_mode = 9; c->num_channel = 9; break;
540     default:
541     av_log(avctx, AV_LOG_ERROR,
542            "Only stereo, 5.0, 5.1 channel layouts supported at the moment!\n");
543     return AVERROR_PATCHWELCOME;
544     }
545
546     if (c->lfe_channel) {
547         init_lfe_fir();
548         c->prim_channels--;
549         c->channel_order_tab = dca_channel_reorder_lfe[c->a_mode];
550         c->lfe_state         = LFE_PRESENT;
551         c->lfe_offset        = dca_lfe_index[c->a_mode];
552     } else {
553         c->channel_order_tab = dca_channel_reorder_nolfe[c->a_mode];
554         c->lfe_state         = LFE_MISSING;
555     }
556
557     for (i = 0; i < 16; i++) {
558         if (dca_sample_rates[i] && (dca_sample_rates[i] == avctx->sample_rate))
559             break;
560     }
561     if (i == 16) {
562         av_log(avctx, AV_LOG_ERROR, "Sample rate %iHz not supported, only ", avctx->sample_rate);
563         for (i = 0; i < 16; i++)
564             av_log(avctx, AV_LOG_ERROR, "%d, ", dca_sample_rates[i]);
565         av_log(avctx, AV_LOG_ERROR, "supported.\n");
566         return -1;
567     }
568     c->sample_rate_code = i;
569
570     avctx->frame_size = 32 * PCM_SAMPLES;
571
572     if (!cos_table[127])
573         qmf_init();
574     return 0;
575 }
576
577 AVCodec ff_dca_encoder = {
578     .name           = "dca",
579     .type           = AVMEDIA_TYPE_AUDIO,
580     .id             = CODEC_ID_DTS,
581     .priv_data_size = sizeof(DCAContext),
582     .init           = encode_init,
583     .encode         = encode_frame,
584     .capabilities   = CODEC_CAP_EXPERIMENTAL,
585     .sample_fmts    = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
586     .long_name      = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"),
587 };