69 uint8_t **streaminfo_start)
139 assert(s->max_blocksize);
141 for (i = 0; i < s->channels; i++) {
143 sizeof(int32_t)*s->max_blocksize);
154 s->max_blocksize =
get_bits(&gb, 16);
158 s->max_blocksize = 16;
182 int *last,
int *type,
int *
size)
184 int tmp = bytestream_get_byte(&block_header);
190 *size = bytestream_get_be24(&block_header);
202 int metadata_type, metadata_size;
228 int metadata_last, metadata_size;
229 const uint8_t *buf_end = buf + buf_size;
233 if (buf_end - buf < 4)
237 if (buf_end - buf < metadata_size) {
241 buf += metadata_size;
242 }
while (!metadata_last);
244 return buf_size - (buf_end - buf);
249 int i, tmp, partition, method_type, rice_order;
253 if (method_type > 1) {
270 for (partition = 0; partition < (1 << rice_order); partition++) {
271 tmp =
get_bits(&s->
gb, method_type == 0 ? 4 : 5);
272 if (tmp == (method_type == 0 ? 15 : 31)) {
274 for (; i <
samples; i++, sample++)
277 for (; i <
samples; i++, sample++) {
290 int32_t *decoded = s->
decoded[channel];
294 for (i = 0; i < pred_order; i++) {
302 a = decoded[pred_order-1];
304 b =
a - decoded[pred_order-2];
306 c =
b - decoded[pred_order-2] + decoded[pred_order-3];
308 d = c - decoded[pred_order-2] + 2*decoded[pred_order-3] - decoded[pred_order-4];
310 switch (pred_order) {
314 for (i = pred_order; i < blocksize; i++)
315 decoded[i] =
a += decoded[i];
318 for (i = pred_order; i < blocksize; i++)
319 decoded[i] =
a +=
b += decoded[i];
322 for (i = pred_order; i < blocksize; i++)
323 decoded[i] =
a +=
b += c += decoded[i];
326 for (i = pred_order; i < blocksize; i++)
327 decoded[i] =
a +=
b += c += d += decoded[i];
340 int coeff_prec, qlevel;
342 int32_t *decoded = s->
decoded[channel];
345 for (i = 0; i < pred_order; i++) {
350 if (coeff_prec == 16) {
361 for (i = 0; i < pred_order; i++) {
370 for (i = pred_order; i < s->
blocksize; i++) {
372 for (j = 0; j < pred_order; j++)
373 sum += (int64_t)coeffs[j] * decoded[i-j-1];
374 decoded[i] += sum >> qlevel;
377 for (i = pred_order; i < s->
blocksize-1; i += 2) {
379 int d = decoded[i-pred_order];
381 for (j = pred_order-1; j > 0; j--) {
389 d = decoded[i] += s0 >> qlevel;
391 decoded[i+1] +=
s1 >> qlevel;
393 if (i < s->blocksize) {
395 for (j = 0; j < pred_order; j++)
396 sum += coeffs[j] * decoded[i-j-1];
397 decoded[i] += sum >> qlevel;
406 int type, wasted = 0;
431 "Invalid number of wasted bits > available bits (%d) - left=%d\n",
449 }
else if (type == 1) {
452 }
else if ((type >= 8) && (type <= 12)) {
455 }
else if (type >= 32) {
466 s->
decoded[channel][i] <<= wasted;
483 if (s->channels && fi.channels != s->channels) {
485 "is not supported\n");
491 if (!s->bps && !fi.bps) {
497 }
else if (s->bps && fi.bps != s->bps) {
514 if (!s->max_blocksize)
523 if (!s->samplerate && !fi.samplerate) {
525 " or frame header\n");
528 if (fi.samplerate == 0) {
529 fi.samplerate = s->samplerate;
530 }
else if (s->samplerate && fi.samplerate != s->samplerate) {
532 s->samplerate, fi.samplerate);
545 for (i = 0; i < s->channels; i++) {
559 int *got_frame_ptr,
AVPacket *avpkt)
561 const uint8_t *buf = avpkt->
data;
562 int buf_size = avpkt->
size;
564 int i, j = 0, bytes_read = 0;
571 if (s->max_framesize == 0) {
606 samples_16 = (int16_t *)s->
frame.
data[0];
607 samples_32 = (int32_t *)s->
frame.
data[0];
609 #define DECORRELATE(left, right)\
610 assert(s->channels == 2);\
611 for (i = 0; i < s->blocksize; i++) {\
612 int a= s->decoded[0][i];\
613 int b= s->decoded[1][i];\
615 *samples_32++ = (left) << s->sample_shift;\
616 *samples_32++ = (right) << s->sample_shift;\
618 *samples_16++ = (left) << s->sample_shift;\
619 *samples_16++ = (right) << s->sample_shift;\
627 for (i = 0; i < s->channels; i++) {
643 if (bytes_read > buf_size) {
647 if (bytes_read < buf_size) {
649 buf_size - bytes_read, buf_size);
663 for (i = 0; i < s->channels; i++) {
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).
static const int16_t coeffs[28]
int is32
flag to indicate if output should be 32-bit instead of 16-bit
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AV_WL32 AV_WL24 AV_WL16 AV_RB32
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
struct FLACContext FLACContext
static int decode_subframe_fixed(FLACContext *s, int channel, int pred_order)
static void skip_bits_long(GetBitContext *s, int n)
AVFrame * coded_frame
the picture in the bitstream
#define AV_LOG_WARNING
Something somehow does not look correct.
static void align_get_bits(GetBitContext *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.
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
#define FLAC_MAX_BLOCKSIZE
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
FLACCOMMONINFO int blocksize
block size of the frame
static int get_sbits(GetBitContext *s, int n)
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
enum AVSampleFormat sample_fmt
audio sample format
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static int get_bits_count(const GetBitContext *s)
bitstream reader API header.
void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, const uint8_t *buffer)
Parse the Streaminfo metadata block.
#define FLAC_MIN_BLOCKSIZE
#define DECORRELATE(left, right)
static int init(AVCodecParserContext *s)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static int get_bits_left(GetBitContext *gb)
int32_t * decoded[FLAC_MAX_CHANNELS]
decoded samples
int ch_mode
channel decorrelation mode
FLAC (Free Lossless Audio Codec) decoder/demuxer common functions.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int get_metadata_size(const uint8_t *buf, int buf_size)
Determine the size of an inline header.
void av_log(void *avcl, int level, const char *fmt,...)
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)
#define FLACSTREAMINFO
Data needed from the Streaminfo header for use by the raw FLAC demuxer and/or the FLAC decoder...
int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, FLACFrameInfo *fi, int log_level_offset)
Validate and decode a frame header.
int avpriv_flac_is_extradata_valid(AVCodecContext *avctx, enum FLACExtradataFormat *format, uint8_t **streaminfo_start)
Validate the FLAC extradata.
int got_streaminfo
indicates if the STREAMINFO has been read
void avpriv_flac_parse_block_header(const uint8_t *block_header, int *last, int *type, int *size)
Parse the metadata block parameters from the header.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
static void allocate_buffers(FLACContext *s)
#define FLAC_STREAMINFO_SIZE
int sample_shift
shift required to make output samples 16-bit or 32-bit
int sample_rate
samples per second
static int decode_frame(FLACContext *s)
main external API structure.
static void close(AVCodecParserContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int parse_streaminfo(FLACContext *s, const uint8_t *buf, int buf_size)
Parse the STREAMINFO from an inline header.
static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int blocksize
number of samples in the current frame
static int decode_subframe(FLACContext *s, int channel)
FLACSTREAMINFO AVCodecContext * avctx
parent AVCodecContext
common internal api header.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define FLAC_MIN_FRAME_SIZE
#define MKBETAG(a, b, c, d)
int channels
number of audio channels
int curr_bps
bps for current subframe, adjusted for channel correlation and wasted bits
static av_cold int flac_decode_init(AVCodecContext *avctx)
void avcodec_get_frame_defaults(AVFrame *pic)
Set the fields of the given AVFrame to default values.
static int decode_residuals(FLACContext *s, int channel, int pred_order)
void av_log_missing_feature(void *avc, const char *feature, int want_sample)
Log a generic warning message about a missing feature.
#define MKTAG(a, b, c, d)
int nb_samples
number of audio samples (per channel) described by this frame
#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)