4857338e9c5efcbb5a100a1509ad7c002b45678f
[libav.git] / libavcodec / alacenc.c
1 /*
2 * ALAC audio encoder
3 * Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
4 *
5 * This file is part of Libav.
6 *
7 * Libav is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * Libav is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "libavutil/opt.h"
23
24 #include "avcodec.h"
25 #include "put_bits.h"
26 #include "internal.h"
27 #include "lpc.h"
28 #include "mathops.h"
29 #include "alac_data.h"
30
31 #define DEFAULT_FRAME_SIZE 4096
32 #define ALAC_EXTRADATA_SIZE 36
33 #define ALAC_FRAME_HEADER_SIZE 55
34 #define ALAC_FRAME_FOOTER_SIZE 3
35
36 #define ALAC_ESCAPE_CODE 0x1FF
37 #define ALAC_MAX_LPC_ORDER 30
38 #define DEFAULT_MAX_PRED_ORDER 6
39 #define DEFAULT_MIN_PRED_ORDER 4
40 #define ALAC_MAX_LPC_PRECISION 9
41 #define ALAC_MAX_LPC_SHIFT 9
42
43 #define ALAC_CHMODE_LEFT_RIGHT 0
44 #define ALAC_CHMODE_LEFT_SIDE 1
45 #define ALAC_CHMODE_RIGHT_SIDE 2
46 #define ALAC_CHMODE_MID_SIDE 3
47
48 typedef struct RiceContext {
49 int history_mult;
50 int initial_history;
51 int k_modifier;
52 int rice_modifier;
53 } RiceContext;
54
55 typedef struct AlacLPCContext {
56 int lpc_order;
57 int lpc_coeff[ALAC_MAX_LPC_ORDER+1];
58 int lpc_quant;
59 } AlacLPCContext;
60
61 typedef struct AlacEncodeContext {
62 AVCodecContext *avctx;
63 int frame_size; /**< current frame size */
64 int verbatim; /**< current frame verbatim mode flag */
65 int compression_level;
66 int min_prediction_order;
67 int max_prediction_order;
68 int max_coded_frame_size;
69 int write_sample_size;
70 int extra_bits;
71 int32_t sample_buf[2][DEFAULT_FRAME_SIZE];
72 int32_t predictor_buf[DEFAULT_FRAME_SIZE];
73 int interlacing_shift;
74 int interlacing_leftweight;
75 PutBitContext pbctx;
76 RiceContext rc;
77 AlacLPCContext lpc[2];
78 LPCContext lpc_ctx;
79 } AlacEncodeContext;
80
81
82 static void init_sample_buffers(AlacEncodeContext *s, int channels,
83 uint8_t const *samples[2])
84 {
85 int ch, i;
86 int shift = av_get_bytes_per_sample(s->avctx->sample_fmt) * 8 -
87 s->avctx->bits_per_raw_sample;
88
89 #define COPY_SAMPLES(type) do { \
90 for (ch = 0; ch < channels; ch++) { \
91 int32_t *bptr = s->sample_buf[ch]; \
92 const type *sptr = (const type *)samples[ch]; \
93 for (i = 0; i < s->frame_size; i++) \
94 bptr[i] = sptr[i] >> shift; \
95 } \
96 } while (0)
97
98 if (s->avctx->sample_fmt == AV_SAMPLE_FMT_S32P)
99 COPY_SAMPLES(int32_t);
100 else
101 COPY_SAMPLES(int16_t);
102 }
103
104 static void encode_scalar(AlacEncodeContext *s, int x,
105 int k, int write_sample_size)
106 {
107 int divisor, q, r;
108
109 k = FFMIN(k, s->rc.k_modifier);
110 divisor = (1<<k) - 1;
111 q = x / divisor;
112 r = x % divisor;
113
114 if (q > 8) {
115 // write escape code and sample value directly
116 put_bits(&s->pbctx, 9, ALAC_ESCAPE_CODE);
117 put_bits(&s->pbctx, write_sample_size, x);
118 } else {
119 if (q)
120 put_bits(&s->pbctx, q, (1<<q) - 1);
121 put_bits(&s->pbctx, 1, 0);
122
123 if (k != 1) {
124 if (r > 0)
125 put_bits(&s->pbctx, k, r+1);
126 else
127 put_bits(&s->pbctx, k-1, 0);
128 }
129 }
130 }
131
132 static void write_element_header(AlacEncodeContext *s,
133 enum AlacRawDataBlockType element,
134 int instance)
135 {
136 int encode_fs = 0;
137
138 if (s->frame_size < DEFAULT_FRAME_SIZE)
139 encode_fs = 1;
140
141 put_bits(&s->pbctx, 3, element); // element type
142 put_bits(&s->pbctx, 4, instance); // element instance
143 put_bits(&s->pbctx, 12, 0); // unused header bits
144 put_bits(&s->pbctx, 1, encode_fs); // Sample count is in the header
145 put_bits(&s->pbctx, 2, s->extra_bits >> 3); // Extra bytes (for 24-bit)
146 put_bits(&s->pbctx, 1, s->verbatim); // Audio block is verbatim
147 if (encode_fs)
148 put_bits32(&s->pbctx, s->frame_size); // No. of samples in the frame
149 }
150
151 static void calc_predictor_params(AlacEncodeContext *s, int ch)
152 {
153 int32_t coefs[MAX_LPC_ORDER][MAX_LPC_ORDER];
154 int shift[MAX_LPC_ORDER];
155 int opt_order;
156
157 if (s->compression_level == 1) {
158 s->lpc[ch].lpc_order = 6;
159 s->lpc[ch].lpc_quant = 6;
160 s->lpc[ch].lpc_coeff[0] = 160;
161 s->lpc[ch].lpc_coeff[1] = -190;
162 s->lpc[ch].lpc_coeff[2] = 170;
163 s->lpc[ch].lpc_coeff[3] = -130;
164 s->lpc[ch].lpc_coeff[4] = 80;
165 s->lpc[ch].lpc_coeff[5] = -25;
166 } else {
167 opt_order = ff_lpc_calc_coefs(&s->lpc_ctx, s->sample_buf[ch],
168 s->frame_size,
169 s->min_prediction_order,
170 s->max_prediction_order,
171 ALAC_MAX_LPC_PRECISION, coefs, shift,
172 FF_LPC_TYPE_LEVINSON, 0,
173 ORDER_METHOD_EST, ALAC_MAX_LPC_SHIFT, 1);
174
175 s->lpc[ch].lpc_order = opt_order;
176 s->lpc[ch].lpc_quant = shift[opt_order-1];
177 memcpy(s->lpc[ch].lpc_coeff, coefs[opt_order-1], opt_order*sizeof(int));
178 }
179 }
180
181 static int estimate_stereo_mode(int32_t *left_ch, int32_t *right_ch, int n)
182 {
183 int i, best;
184 int32_t lt, rt;
185 uint64_t sum[4];
186 uint64_t score[4];
187
188 /* calculate sum of 2nd order residual for each channel */
189 sum[0] = sum[1] = sum[2] = sum[3] = 0;
190 for (i = 2; i < n; i++) {
191 lt = left_ch[i] - 2 * left_ch[i - 1] + left_ch[i - 2];
192 rt = right_ch[i] - 2 * right_ch[i - 1] + right_ch[i - 2];
193 sum[2] += FFABS((lt + rt) >> 1);
194 sum[3] += FFABS(lt - rt);
195 sum[0] += FFABS(lt);
196 sum[1] += FFABS(rt);
197 }
198
199 /* calculate score for each mode */
200 score[0] = sum[0] + sum[1];
201 score[1] = sum[0] + sum[3];
202 score[2] = sum[1] + sum[3];
203 score[3] = sum[2] + sum[3];
204
205 /* return mode with lowest score */
206 best = 0;
207 for (i = 1; i < 4; i++) {
208 if (score[i] < score[best])
209 best = i;
210 }
211 return best;
212 }
213
214 static void alac_stereo_decorrelation(AlacEncodeContext *s)
215 {
216 int32_t *left = s->sample_buf[0], *right = s->sample_buf[1];
217 int i, mode, n = s->frame_size;
218 int32_t tmp;
219
220 mode = estimate_stereo_mode(left, right, n);
221
222 switch (mode) {
223 case ALAC_CHMODE_LEFT_RIGHT:
224 s->interlacing_leftweight = 0;
225 s->interlacing_shift = 0;
226 break;
227 case ALAC_CHMODE_LEFT_SIDE:
228 for (i = 0; i < n; i++)
229 right[i] = left[i] - right[i];
230 s->interlacing_leftweight = 1;
231 s->interlacing_shift = 0;
232 break;
233 case ALAC_CHMODE_RIGHT_SIDE:
234 for (i = 0; i < n; i++) {
235 tmp = right[i];
236 right[i] = left[i] - right[i];
237 left[i] = tmp + (right[i] >> 31);
238 }
239 s->interlacing_leftweight = 1;
240 s->interlacing_shift = 31;
241 break;
242 default:
243 for (i = 0; i < n; i++) {
244 tmp = left[i];
245 left[i] = (tmp + right[i]) >> 1;
246 right[i] = tmp - right[i];
247 }
248 s->interlacing_leftweight = 1;
249 s->interlacing_shift = 1;
250 break;
251 }
252 }
253
254 static void alac_linear_predictor(AlacEncodeContext *s, int ch)
255 {
256 int i;
257 AlacLPCContext lpc = s->lpc[ch];
258
259 if (lpc.lpc_order == 31) {
260 s->predictor_buf[0] = s->sample_buf[ch][0];
261
262 for (i = 1; i < s->frame_size; i++) {
263 s->predictor_buf[i] = s->sample_buf[ch][i ] -
264 s->sample_buf[ch][i - 1];
265 }
266
267 return;
268 }
269
270 // generalised linear predictor
271
272 if (lpc.lpc_order > 0) {
273 int32_t *samples = s->sample_buf[ch];
274 int32_t *residual = s->predictor_buf;
275
276 // generate warm-up samples
277 residual[0] = samples[0];
278 for (i = 1; i <= lpc.lpc_order; i++)
279 residual[i] = samples[i] - samples[i-1];
280
281 // perform lpc on remaining samples
282 for (i = lpc.lpc_order + 1; i < s->frame_size; i++) {
283 int sum = 1 << (lpc.lpc_quant - 1), res_val, j;
284
285 for (j = 0; j < lpc.lpc_order; j++) {
286 sum += (samples[lpc.lpc_order-j] - samples[0]) *
287 lpc.lpc_coeff[j];
288 }
289
290 sum >>= lpc.lpc_quant;
291 sum += samples[0];
292 residual[i] = sign_extend(samples[lpc.lpc_order+1] - sum,
293 s->write_sample_size);
294 res_val = residual[i];
295
296 if (res_val) {
297 int index = lpc.lpc_order - 1;
298 int neg = (res_val < 0);
299
300 while (index >= 0 && (neg ? (res_val < 0) : (res_val > 0))) {
301 int val = samples[0] - samples[lpc.lpc_order - index];
302 int sign = (val ? FFSIGN(val) : 0);
303
304 if (neg)
305 sign *= -1;
306
307 lpc.lpc_coeff[index] -= sign;
308 val *= sign;
309 res_val -= (val >> lpc.lpc_quant) * (lpc.lpc_order - index);
310 index--;
311 }
312 }
313 samples++;
314 }
315 }
316 }
317
318 static void alac_entropy_coder(AlacEncodeContext *s)
319 {
320 unsigned int history = s->rc.initial_history;
321 int sign_modifier = 0, i, k;
322 int32_t *samples = s->predictor_buf;
323
324 for (i = 0; i < s->frame_size;) {
325 int x;
326
327 k = av_log2((history >> 9) + 3);
328
329 x = -2 * (*samples) -1;
330 x ^= x >> 31;
331
332 samples++;
333 i++;
334
335 encode_scalar(s, x - sign_modifier, k, s->write_sample_size);
336
337 history += x * s->rc.history_mult -
338 ((history * s->rc.history_mult) >> 9);
339
340 sign_modifier = 0;
341 if (x > 0xFFFF)
342 history = 0xFFFF;
343
344 if (history < 128 && i < s->frame_size) {
345 unsigned int block_size = 0;
346
347 k = 7 - av_log2(history) + ((history + 16) >> 6);
348
349 while (*samples == 0 && i < s->frame_size) {
350 samples++;
351 i++;
352 block_size++;
353 }
354 encode_scalar(s, block_size, k, 16);
355 sign_modifier = (block_size <= 0xFFFF);
356 history = 0;
357 }
358
359 }
360 }
361
362 static void write_element(AlacEncodeContext *s,
363 enum AlacRawDataBlockType element, int instance,
364 const uint8_t *samples0, const uint8_t *samples1)
365 {
366 uint8_t const *samples[2] = { samples0, samples1 };
367 int i, j, channels;
368 int prediction_type = 0;
369 PutBitContext *pb = &s->pbctx;
370
371 channels = element == TYPE_CPE ? 2 : 1;
372
373 if (s->verbatim) {
374 write_element_header(s, element, instance);
375 /* samples are channel-interleaved in verbatim mode */
376 if (s->avctx->sample_fmt == AV_SAMPLE_FMT_S32P) {
377 int shift = 32 - s->avctx->bits_per_raw_sample;
378 int32_t const *samples_s32[2] = { (const int32_t *)samples0,
379 (const int32_t *)samples1 };
380 for (i = 0; i < s->frame_size; i++)
381 for (j = 0; j < channels; j++)
382 put_sbits(pb, s->avctx->bits_per_raw_sample,
383 samples_s32[j][i] >> shift);
384 } else {
385 int16_t const *samples_s16[2] = { (const int16_t *)samples0,
386 (const int16_t *)samples1 };
387 for (i = 0; i < s->frame_size; i++)
388 for (j = 0; j < channels; j++)
389 put_sbits(pb, s->avctx->bits_per_raw_sample,
390 samples_s16[j][i]);
391 }
392 } else {
393 s->write_sample_size = s->avctx->bits_per_raw_sample - s->extra_bits +
394 channels - 1;
395
396 init_sample_buffers(s, channels, samples);
397 write_element_header(s, element, instance);
398
399 if (channels == 2)
400 alac_stereo_decorrelation(s);
401 else
402 s->interlacing_shift = s->interlacing_leftweight = 0;
403 put_bits(pb, 8, s->interlacing_shift);
404 put_bits(pb, 8, s->interlacing_leftweight);
405
406 for (i = 0; i < channels; i++) {
407 calc_predictor_params(s, i);
408
409 put_bits(pb, 4, prediction_type);
410 put_bits(pb, 4, s->lpc[i].lpc_quant);
411
412 put_bits(pb, 3, s->rc.rice_modifier);
413 put_bits(pb, 5, s->lpc[i].lpc_order);
414 // predictor coeff. table
415 for (j = 0; j < s->lpc[i].lpc_order; j++)
416 put_sbits(pb, 16, s->lpc[i].lpc_coeff[j]);
417 }
418
419 // write extra bits if needed
420 if (s->extra_bits) {
421 uint32_t mask = (1 << s->extra_bits) - 1;
422 for (i = 0; i < s->frame_size; i++) {
423 for (j = 0; j < channels; j++) {
424 put_bits(pb, s->extra_bits, s->sample_buf[j][i] & mask);
425 s->sample_buf[j][i] >>= s->extra_bits;
426 }
427 }
428 }
429
430 // apply lpc and entropy coding to audio samples
431 for (i = 0; i < channels; i++) {
432 alac_linear_predictor(s, i);
433
434 // TODO: determine when this will actually help. for now it's not used.
435 if (prediction_type == 15) {
436 // 2nd pass 1st order filter
437 for (j = s->frame_size - 1; j > 0; j--)
438 s->predictor_buf[j] -= s->predictor_buf[j - 1];
439 }
440 alac_entropy_coder(s);
441 }
442 }
443 }
444
445 static int write_frame(AlacEncodeContext *s, AVPacket *avpkt,
446 uint8_t * const *samples)
447 {
448 PutBitContext *pb = &s->pbctx;
449 const enum AlacRawDataBlockType *ch_elements = ff_alac_channel_elements[s->avctx->channels - 1];
450 const uint8_t *ch_map = ff_alac_channel_layout_offsets[s->avctx->channels - 1];
451 int ch, element, sce, cpe;
452
453 init_put_bits(pb, avpkt->data, avpkt->size);
454
455 ch = element = sce = cpe = 0;
456 while (ch < s->avctx->channels) {
457 if (ch_elements[element] == TYPE_CPE) {
458 write_element(s, TYPE_CPE, cpe, samples[ch_map[ch]],
459 samples[ch_map[ch + 1]]);
460 cpe++;
461 ch += 2;
462 } else {
463 write_element(s, TYPE_SCE, sce, samples[ch_map[ch]], NULL);
464 sce++;
465 ch++;
466 }
467 element++;
468 }
469
470 put_bits(pb, 3, TYPE_END);
471 flush_put_bits(pb);
472
473 return put_bits_count(pb) >> 3;
474 }
475
476 static av_always_inline int get_max_frame_size(int frame_size, int ch, int bps)
477 {
478 int header_bits = 23 + 32 * (frame_size < DEFAULT_FRAME_SIZE);
479 return FFALIGN(header_bits + bps * ch * frame_size + 3, 8) / 8;
480 }
481
482 static av_cold int alac_encode_close(AVCodecContext *avctx)
483 {
484 AlacEncodeContext *s = avctx->priv_data;
485 ff_lpc_end(&s->lpc_ctx);
486 av_freep(&avctx->extradata);
487 avctx->extradata_size = 0;
488 return 0;
489 }
490
491 static av_cold int alac_encode_init(AVCodecContext *avctx)
492 {
493 AlacEncodeContext *s = avctx->priv_data;
494 int ret;
495 uint8_t *alac_extradata;
496
497 avctx->frame_size = s->frame_size = DEFAULT_FRAME_SIZE;
498
499 if (avctx->sample_fmt == AV_SAMPLE_FMT_S32P) {
500 if (avctx->bits_per_raw_sample != 24)
501 av_log(avctx, AV_LOG_WARNING, "encoding as 24 bits-per-sample\n");
502 avctx->bits_per_raw_sample = 24;
503 } else {
504 avctx->bits_per_raw_sample = 16;
505 s->extra_bits = 0;
506 }
507
508 // Set default compression level
509 if (avctx->compression_level == FF_COMPRESSION_DEFAULT)
510 s->compression_level = 2;
511 else
512 s->compression_level = av_clip(avctx->compression_level, 0, 2);
513
514 // Initialize default Rice parameters
515 s->rc.history_mult = 40;
516 s->rc.initial_history = 10;
517 s->rc.k_modifier = 14;
518 s->rc.rice_modifier = 4;
519
520 s->max_coded_frame_size = get_max_frame_size(avctx->frame_size,
521 avctx->channels,
522 avctx->bits_per_raw_sample);
523
524 avctx->extradata = av_mallocz(ALAC_EXTRADATA_SIZE + AV_INPUT_BUFFER_PADDING_SIZE);
525 if (!avctx->extradata) {
526 ret = AVERROR(ENOMEM);
527 goto error;
528 }
529 avctx->extradata_size = ALAC_EXTRADATA_SIZE;
530
531 alac_extradata = avctx->extradata;
532 AV_WB32(alac_extradata, ALAC_EXTRADATA_SIZE);
533 AV_WB32(alac_extradata+4, MKBETAG('a','l','a','c'));
534 AV_WB32(alac_extradata+12, avctx->frame_size);
535 AV_WB8 (alac_extradata+17, avctx->bits_per_raw_sample);
536 AV_WB8 (alac_extradata+21, avctx->channels);
537 AV_WB32(alac_extradata+24, s->max_coded_frame_size);
538 AV_WB32(alac_extradata+28,
539 avctx->sample_rate * avctx->channels * avctx->bits_per_raw_sample); // average bitrate
540 AV_WB32(alac_extradata+32, avctx->sample_rate);
541
542 // Set relevant extradata fields
543 if (s->compression_level > 0) {
544 AV_WB8(alac_extradata+18, s->rc.history_mult);
545 AV_WB8(alac_extradata+19, s->rc.initial_history);
546 AV_WB8(alac_extradata+20, s->rc.k_modifier);
547 }
548
549 #if FF_API_PRIVATE_OPT
550 FF_DISABLE_DEPRECATION_WARNINGS
551 if (avctx->min_prediction_order >= 0) {
552 if (avctx->min_prediction_order < MIN_LPC_ORDER ||
553 avctx->min_prediction_order > ALAC_MAX_LPC_ORDER) {
554 av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n",
555 avctx->min_prediction_order);
556 ret = AVERROR(EINVAL);
557 goto error;
558 }
559
560 s->min_prediction_order = avctx->min_prediction_order;
561 }
562
563 if (avctx->max_prediction_order >= 0) {
564 if (avctx->max_prediction_order < MIN_LPC_ORDER ||
565 avctx->max_prediction_order > ALAC_MAX_LPC_ORDER) {
566 av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n",
567 avctx->max_prediction_order);
568 ret = AVERROR(EINVAL);
569 goto error;
570 }
571
572 s->max_prediction_order = avctx->max_prediction_order;
573 }
574 FF_ENABLE_DEPRECATION_WARNINGS
575 #endif
576
577 if (s->max_prediction_order < s->min_prediction_order) {
578 av_log(avctx, AV_LOG_ERROR,
579 "invalid prediction orders: min=%d max=%d\n",
580 s->min_prediction_order, s->max_prediction_order);
581 ret = AVERROR(EINVAL);
582 goto error;
583 }
584
585 s->avctx = avctx;
586
587 if ((ret = ff_lpc_init(&s->lpc_ctx, avctx->frame_size,
588 s->max_prediction_order,
589 FF_LPC_TYPE_LEVINSON)) < 0) {
590 goto error;
591 }
592
593 return 0;
594 error:
595 alac_encode_close(avctx);
596 return ret;
597 }
598
599 static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
600 const AVFrame *frame, int *got_packet_ptr)
601 {
602 AlacEncodeContext *s = avctx->priv_data;
603 int out_bytes, max_frame_size, ret;
604
605 s->frame_size = frame->nb_samples;
606
607 if (frame->nb_samples < DEFAULT_FRAME_SIZE)
608 max_frame_size = get_max_frame_size(s->frame_size, avctx->channels,
609 avctx->bits_per_raw_sample);
610 else
611 max_frame_size = s->max_coded_frame_size;
612
613 if ((ret = ff_alloc_packet(avpkt, 2 * max_frame_size))) {
614 av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
615 return ret;
616 }
617
618 /* use verbatim mode for compression_level 0 */
619 if (s->compression_level) {
620 s->verbatim = 0;
621 s->extra_bits = avctx->bits_per_raw_sample - 16;
622 } else {
623 s->verbatim = 1;
624 s->extra_bits = 0;
625 }
626
627 out_bytes = write_frame(s, avpkt, frame->extended_data);
628
629 if (out_bytes > max_frame_size) {
630 /* frame too large. use verbatim mode */
631 s->verbatim = 1;
632 s->extra_bits = 0;
633 out_bytes = write_frame(s, avpkt, frame->extended_data);
634 }
635
636 avpkt->size = out_bytes;
637 *got_packet_ptr = 1;
638 return 0;
639 }
640
641 #define OFFSET(x) offsetof(AlacEncodeContext, x)
642 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
643 static const AVOption options[] = {
644 { "min_prediction_order", NULL, OFFSET(min_prediction_order), AV_OPT_TYPE_INT, { .i64 = DEFAULT_MIN_PRED_ORDER }, MIN_LPC_ORDER, ALAC_MAX_LPC_ORDER, AE },
645 { "max_prediction_order", NULL, OFFSET(max_prediction_order), AV_OPT_TYPE_INT, { .i64 = DEFAULT_MAX_PRED_ORDER }, MIN_LPC_ORDER, ALAC_MAX_LPC_ORDER, AE },
646
647 { NULL },
648 };
649
650 static const AVClass alacenc_class = {
651 .class_name = "alacenc",
652 .item_name = av_default_item_name,
653 .option = options,
654 .version = LIBAVUTIL_VERSION_INT,
655 };
656
657 AVCodec ff_alac_encoder = {
658 .name = "alac",
659 .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"),
660 .type = AVMEDIA_TYPE_AUDIO,
661 .id = AV_CODEC_ID_ALAC,
662 .priv_data_size = sizeof(AlacEncodeContext),
663 .priv_class = &alacenc_class,
664 .init = alac_encode_init,
665 .encode2 = alac_encode_frame,
666 .close = alac_encode_close,
667 .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME,
668 .channel_layouts = ff_alac_channel_layouts,
669 .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32P,
670 AV_SAMPLE_FMT_S16P,
671 AV_SAMPLE_FMT_NONE },
672 };