1 /*
2 * FLAC (Free Lossless Audio Codec) decoder
3 * Copyright (c) 2003 Alex Beregszaszi
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * FLAC (Free Lossless Audio Codec) decoder
25 * @author Alex Beregszaszi
26 * @see http://flac.sourceforge.net/
27 *
28 * This decoder can be used in 1 of 2 ways: Either raw FLAC data can be fed
29 * through, starting from the initial 'fLaC' signature; or by passing the
30 * 34-byte streaminfo structure through avctx->extradata[_size] followed
31 * by data starting with the 0xFFF8 marker.
32 */
33
35
49
50
54
57
58 int blocksize;
///< number of samples in the current frame
59 int sample_shift;
///< shift required to make output samples 16-bit or 32-bit
60 int ch_mode;
///< channel decorrelation type in the current frame
62
66 int buggy_lpc;
///< use workaround for old lavc encoded files
67
70
72
74 {
79
80 if (need32 || want32) {
81 if (planar)
83 else
86 } else {
87 if (planar)
89 else
92 }
93 }
94
96 {
99 int ret;
102
103 /* for now, the raw FLAC header is allowed to be passed to the decoder as
104 frame data instead of extradata. */
106 return 0;
107
110
111 /* initialize based on the demuxer-supplied streamdata header */
113 if (ret < 0)
114 return ret;
116 if (ret < 0)
117 return ret;
122
123 return 0;
124 }
125
127 {
133 }
134
136 {
137 int buf_size;
138 int ret;
139
141
145 if (buf_size < 0)
146 return buf_size;
147
151
157 return ret < 0 ? ret : 0;
158 }
159
160 /**
161 * Parse the STREAMINFO from an inline header.
162 * @param s the flac decoding context
163 * @param buf input buffer, starting with the "fLaC" marker
164 * @param buf_size buffer size
165 * @return non-zero if metadata is invalid
166 */
168 {
169 int metadata_type, metadata_size, ret;
170
172 /* need more data */
173 return 0;
174 }
179 }
181 if (ret < 0)
182 return ret;
184 if (ret < 0)
185 return ret;
190
191 return 0;
192 }
193
194 /**
195 * Determine the size of an inline header.
196 * @param buf input buffer, starting with the "fLaC" marker
197 * @param buf_size buffer size
198 * @return number of bytes in the header, or 0 if more data is needed
199 */
201 {
202 int metadata_last, metadata_size;
203 const uint8_t *buf_end = buf + buf_size;
204
205 buf += 4;
206 do {
207 if (buf_end - buf < 4)
210 buf += 4;
211 if (buf_end - buf < metadata_size) {
212 /* need more data in order to read the complete header */
214 }
215 buf += metadata_size;
216 } while (!metadata_last);
217
218 return buf_size - (buf_end -
buf);
219 }
220
222 {
224 int i,
tmp, partition, method_type, rice_order;
225 int rice_bits, rice_esc;
226 int samples;
227
230
232 rice_bits = 4 + method_type;
233 rice_esc = (1 << rice_bits) - 1;
234
235 decoded += pred_order;
236 i = pred_order;
237
238 if (method_type > 1) {
240 method_type);
242 }
243
244 if (samples << rice_order != s->
blocksize) {
248 }
249
250 if (pred_order > samples) {
252 pred_order, samples);
254 }
255
256 for (partition = 0; partition < (1 << rice_order); partition++) {
258 if (tmp == rice_esc) {
260 for (; i < samples; i++)
262 } else {
263 int real_limit = tmp ? (INT_MAX >>
tmp) + 2 : INT_MAX;
264 for (; i < samples; i++) {
266 if (v == 0x80000000){
269 }
270
271 *decoded++ = v;
272 }
273 }
274 i= 0;
275 }
276
278
279 return 0;
280 }
281
283 int pred_order,
int bps)
284 {
287 int i;
288 int ret;
289
290 /* warm up samples */
291 for (i = 0; i < pred_order; i++) {
293 }
294
296 return ret;
297
298 if (pred_order > 0)
299 a = decoded[pred_order-1];
300 if (pred_order > 1)
301 b =
a - decoded[pred_order-2];
302 if (pred_order > 2)
303 c =
b - decoded[pred_order-2] + decoded[pred_order-3];
304 if (pred_order > 3)
305 d =
c - decoded[pred_order-2] + 2
U*decoded[pred_order-3] - decoded[pred_order-4];
306
307 switch (pred_order) {
308 case 0:
309 break;
310 case 1:
311 for (i = pred_order; i < blocksize; i++)
312 decoded[i] =
a += decoded[i];
313 break;
314 case 2:
315 for (i = pred_order; i < blocksize; i++)
316 decoded[i] =
a +=
b += decoded[i];
317 break;
318 case 3:
319 for (i = pred_order; i < blocksize; i++)
320 decoded[i] =
a +=
b +=
c += decoded[i];
321 break;
322 case 4:
323 for (i = pred_order; i < blocksize; i++)
324 decoded[i] =
a +=
b +=
c += d += decoded[i];
325 break;
326 default:
329 }
330
331 return 0;
332 }
333
335 int order,
int qlevel,
int len,
int bps)
336 {
337 int i, j;
338 int ebps = 1 << (bps-1);
339 unsigned sigma = 0;
340
341 for (i = order; i <
len; i++)
342 sigma |= decoded[i] + ebps;
343
344 if (sigma < 2*ebps)
345 return;
346
347 for (i = len - 1; i >= order; i--) {
348 int64_t p = 0;
349 for (j = 0; j < order; j++)
350 p += coeffs[j] * (int64_t)(
int32_t)decoded[i-order+j];
351 decoded[i] -= p >> qlevel;
352 }
353 for (i = order; i <
len; i++, decoded++) {
355 for (j = 0; j < order; j++)
356 p += coeffs[j] * (uint32_t)decoded[j];
357 decoded[j] += p >> qlevel;
358 }
359 }
360
363 {
364 int i, ret;
365 int coeff_prec, qlevel;
367
368 /* warm up samples */
369 for (i = 0; i < pred_order; i++) {
371 }
372
374 if (coeff_prec == 16) {
377 }
379 if (qlevel < 0) {
381 qlevel);
383 }
384
385 for (i = 0; i < pred_order; i++) {
386 coeffs[pred_order - i - 1] =
get_sbits(&s->
gb, coeff_prec);
387 }
388
390 return ret;
391
394 && bps + coeff_prec +
av_log2(pred_order) <= 32)) {
396 } else {
400 }
401
402 return 0;
403 }
404
406 {
408 int type, wasted = 0;
411
412 if (channel == 0) {
414 bps++;
415 } else {
417 bps++;
418 }
419
423 }
425
428 if ( left <= 0 ||
432 "Invalid number of wasted bits > available bits (%d) - left=%d\n",
433 bps, left);
435 }
437 bps -= wasted;
438 }
439 if (bps > 32) {
442 }
443
444 //FIXME use av_log2 for types
445 if (type == 0) {
448 decoded[i] = tmp;
449 } else if (type == 1) {
452 } else if ((type >= 8) && (type <= 12)) {
454 return ret;
455 } else if (type >= 32) {
457 return ret;
458 } else {
461 }
462
463 if (wasted && wasted < 32) {
464 int i;
466 decoded[i] = (unsigned)decoded[i] << wasted;
467 }
468
469 return 0;
470 }
471
473 {
474 int i, ret;
477
480 return ret;
481 }
482
489 if (ret < 0)
490 return ret;
491 }
496
500 }
501 if (!fi.bps) {
505 "supported\n");
507 }
508
512 }
513
520 }
522
525 " or frame header\n");
527 }
528 if (fi.samplerate == 0)
531
534 if (ret < 0)
535 return ret;
538 }
541
542 // dump_headers(s->avctx, &s->flac_stream_info);
543
544 /* subframes */
547 return ret;
548 }
549
551
552 /* frame footer */
554
555 return 0;
556 }
557
559 int *got_frame_ptr,
AVPacket *avpkt)
560 {
564 int buf_size = avpkt->
size;
566 int bytes_read = 0;
567 int ret;
568
569 *got_frame_ptr = 0;
570
575 }
576
577 if (buf_size > 5 && !memcmp(buf, "177円FLAC", 5)) {
579 return buf_size;
580 }
581
584 return buf_size;
585 }
586
587 /* check that there is at least the smallest decodable amount of data.
588 this amount corresponds to the smallest valid FLAC frame possible.
589 FF F8 69 02 00 00 9A 00 00 34 46 */
591 return buf_size;
592
593 /* check for inline header */
597 return ret;
598 }
600 }
601
602 /* decode frame */
604 return ret;
607 return ret;
608 }
610
613 0, buf, bytes_read)) {
617 }
618
619 /* get output buffer */
622 return ret;
623
627
628 if (bytes_read > buf_size) {
631 }
632 if (bytes_read < buf_size) {
634 buf_size - bytes_read, buf_size);
635 }
636
637 *got_frame_ptr = 1;
638
639 return bytes_read;
640 }
641
642 #if HAVE_THREADS
644 {
651 return 0;
652 }
653 #endif
654
656 {
658
660
661 return 0;
662 }
663
667 };
668
670 "FLAC decoder",
674 };
675
693 };
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
static int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len)
read signed golomb rice code (flac).
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static const char * format[]
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int init_thread_copy(AVCodecContext *avctx)
#define LIBAVUTIL_VERSION_INT
av_cold void ff_flacdsp_init(FLACDSPContext *c, enum AVSampleFormat fmt, int channels, int bps)
static av_cold int init(AVCodecContext *avctx)
static int allocate_buffers(FLACContext *s)
int ff_flac_get_max_frame_size(int blocksize, int ch, int bps)
Calculate an estimate for the maximum frame size based on verbatim mode.
#define AV_OPT_FLAG_AUDIO_PARAM
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
const char * av_default_item_name(void *ptr)
Return the context name.
AVCodecContext * avctx
parent AVCodecContext
#define FLAC_MAX_BLOCKSIZE
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
static int decode_residuals(FLACContext *s, int32_t *decoded, int pred_order)
FLACCOMMONINFO int blocksize
block size of the frame
static int get_sbits(GetBitContext *s, int n)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
int ff_flac_is_extradata_valid(AVCodecContext *avctx, enum FLACExtradataFormat *format, uint8_t **streaminfo_start)
Validate the FLAC extradata.
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void(* lpc32)(int32_t *samples, const int coeffs[32], int order, int qlevel, int len)
enum AVSampleFormat sample_fmt
audio sample format
static const AVClass flac_decoder_class
Multithreading support functions.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
static void flac_set_bps(FLACContext *s)
Public header for CRC hash function implementation.
static int get_bits_count(const GetBitContext *s)
bitstream reader API header.
unsigned int decoded_buffer_size
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
static int get_bits_left(GetBitContext *gb)
int32_t * decoded[FLAC_MAX_CHANNELS]
decoded samples
int ch_mode
channel decorrelation mode
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
FLAC (Free Lossless Audio Codec) decoder/demuxer common functions.
enum AVSampleFormat request_sample_fmt
desired sample format
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int decode_subframe_lpc(FLACContext *s, int32_t *decoded, int pred_order, int bps)
simple assert() macros that are a bit more flexible than ISO C assert().
static int get_metadata_size(const uint8_t *buf, int buf_size)
Determine the size of an inline header.
GetBitContext gb
GetBitContext initialized to start at the current frame.
const char * name
Name of the codec implementation.
static void dump_headers(AVCodecContext *avctx, FLACStreaminfo *s)
int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, FLACFrameInfo *fi, int log_level_offset)
Validate and decode a frame header.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
static int decode_subframe_fixed(FLACContext *s, int32_t *decoded, int pred_order, int bps)
uint64_t channel_layout
Audio channel layout.
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
int buggy_lpc
use workaround for old lavc encoded files
int got_streaminfo
indicates if the STREAMINFO has been read
int ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, const uint8_t *buffer)
Parse the Streaminfo metadata block.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
#define FLAC_STREAMINFO_SIZE
#define AV_EF_EXPLODE
abort decoding on minor error detection
int sample_shift
shift required to make output samples 16-bit or 32-bit
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
int sample_rate
samples per second
static const AVOption options[]
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
static int decode_frame(FLACContext *s)
main external API structure.
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch const uint8_t **in ch off *out planar
void ff_flac_set_channel_layout(AVCodecContext *avctx)
static unsigned int get_bits1(GetBitContext *s)
Describe the class of an AVClass context structure.
static void skip_bits(GetBitContext *s, int n)
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Get the required buffer size for the given audio parameters.
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
static av_always_inline void flac_parse_block_header(const uint8_t *block_header, int *last, int *type, int *size)
Parse the metadata block parameters from the header.
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data...
static void lpc_analyze_remodulate(SUINT32 *decoded, const int coeffs[32], int order, int qlevel, int len, int bps)
static int parse_streaminfo(FLACContext *s, const uint8_t *buf, int buf_size)
Parse the STREAMINFO from an inline header.
struct FLACStreaminfo flac_stream_info
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
int blocksize
number of samples in the current frame
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
static int decode_subframe(FLACContext *s, int channel)
void(* lpc16)(int32_t *samples, const int coeffs[32], int order, int qlevel, int len)
common internal api header.
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
channel
Use these values when setting the channel map with ebur128_set_channel().
#define FLAC_MIN_FRAME_SIZE
#define MKBETAG(a, b, c, d)
int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, const uint8_t *buf, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Fill plane data pointers and linesize for samples with sample format sample_fmt.
static const int16_t coeffs[]
int channels
number of audio channels
static const uint8_t * align_get_bits(GetBitContext *s)
static av_cold int flac_decode_init(AVCodecContext *avctx)
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
void(* decorrelate[4])(uint8_t **out, int32_t **in, int channels, int len, int shift)
#define FLAC_MAX_CHANNELS
static av_cold int flac_decode_close(AVCodecContext *avctx)
int ch_mode
channel decorrelation type in the current frame
static int flac_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)