74 int need32 = s->bps > 16;
78 if (need32 || want32) {
137 assert(s->max_blocksize);
162 int metadata_type, metadata_size, ret;
192 int metadata_last, metadata_size;
193 const uint8_t *buf_end = buf + buf_size;
197 if (buf_end - buf < 4)
201 if (buf_end - buf < metadata_size) {
205 buf += metadata_size;
206 }
while (!metadata_last);
208 return buf_size - (buf_end - buf);
213 int i, tmp, partition, method_type, rice_order;
214 int rice_bits, rice_esc;
218 if (method_type > 1) {
227 if (pred_order > samples) {
229 pred_order, samples);
233 rice_bits = 4 + method_type;
234 rice_esc = (1 << rice_bits) - 1;
236 decoded += pred_order;
238 for (partition = 0; partition < (1 << rice_order); partition++) {
240 if (tmp == rice_esc) {
256 int pred_order,
int bps)
262 for (i = 0; i < pred_order; i++) {
270 a = decoded[pred_order-1];
272 b = a - decoded[pred_order-2];
274 c = b - decoded[pred_order-2] + decoded[pred_order-3];
276 d = c - decoded[pred_order-2] + 2*decoded[pred_order-3] - decoded[pred_order-4];
278 switch (pred_order) {
282 for (i = pred_order; i < blocksize; i++)
283 decoded[i] = a += decoded[i];
286 for (i = pred_order; i < blocksize; i++)
287 decoded[i] = a += b += decoded[i];
290 for (i = pred_order; i < blocksize; i++)
291 decoded[i] = a += b += c += decoded[i];
294 for (i = pred_order; i < blocksize; i++)
295 decoded[i] = a += b += c += d += decoded[i];
309 int coeff_prec, qlevel;
313 for (i = 0; i < pred_order; i++) {
318 if (coeff_prec == 16) {
329 for (i = 0; i < pred_order; i++) {
330 coeffs[pred_order - i - 1] =
get_sbits(&s->
gb, coeff_prec);
344 int type, wasted = 0;
369 "Invalid number of wasted bits > available bits (%d) - left=%d\n",
387 }
else if (type == 1) {
390 }
else if ((type >= 8) && (type <= 12)) {
393 }
else if (type >= 32) {
404 decoded[i] <<= wasted;
421 if (s->channels && fi.channels != s->channels && s->
got_streaminfo) {
433 if (!s->bps && !fi.bps) {
439 }
else if (s->bps && fi.bps != s->bps) {
450 if (!s->max_blocksize)
459 if (!s->samplerate && !fi.samplerate) {
461 " or frame header\n");
464 if (fi.samplerate == 0)
465 fi.samplerate = s->samplerate;
480 for (i = 0; i < s->channels; i++) {
494 int *got_frame_ptr,
AVPacket *avpkt)
497 int buf_size = avpkt->
size;
504 if (s->max_framesize == 0) {
543 if (bytes_read > buf_size) {
547 if (bytes_read < buf_size) {
549 buf_size - bytes_read, buf_size);
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]
This structure describes decoded (raw) audio or video data.
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.
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.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
struct FLACContext FLACContext
AVFrame * coded_frame
the picture in the bitstream
static int allocate_buffers(FLACContext *s)
av_cold void ff_flacdsp_init(FLACDSPContext *c, enum AVSampleFormat fmt, int bps)
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.
int avpriv_flac_is_extradata_valid(AVCodecContext *avctx, enum FLACExtradataFormat *format, uint8_t **streaminfo_start)
Validate the FLAC extradata.
#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 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 ...
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
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 channel data pointers and linesize for samples with sample format sample_fmt.
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 void flac_set_bps(FLACContext *s)
static int get_bits_count(const GetBitContext *s)
bitstream reader API header.
unsigned int decoded_buffer_size
static int init(AVCodecParserContext *s)
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.
enum AVSampleFormat request_sample_fmt
Used to request a sample format from the decoder.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int decode_subframe_lpc(FLACContext *s, int32_t *decoded, int pred_order, int bps)
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)
void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, const uint8_t *buffer)
Parse the Streaminfo metadata block.
#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.
static int decode_subframe_fixed(FLACContext *s, int32_t *decoded, int pred_order, int bps)
uint64_t channel_layout
Audio channel layout.
audio channel layout utility functions
int got_streaminfo
indicates if the STREAMINFO has been read
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
#define FLAC_STREAMINFO_SIZE
int sample_shift
shift required to make output samples 16-bit or 32-bit
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
int sample_rate
samples per second
void(* lpc)(int32_t *samples, const int coeffs[32], int order, int qlevel, int len)
static int decode_frame(FLACContext *s)
main external API structure.
static void close(AVCodecParserContext *s)
void ff_flac_set_channel_layout(AVCodecContext *avctx)
#define MKBETAG(a, b, c, d)
static unsigned int get_bits1(GetBitContext *s)
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
static void skip_bits(GetBitContext *s, int n)
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
void av_log_missing_feature(void *avc, const char *feature, int want_sample)
Log a generic warning message about a missing feature.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static int parse_streaminfo(FLACContext *s, const uint8_t *buf, int buf_size)
Parse the STREAMINFO from an inline header.
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 AVERROR_INVALIDDATA
AVSampleFormat
Audio Sample Formats.
#define FLAC_MIN_FRAME_SIZE
#define AVERROR_PATCHWELCOME
int channels
number of audio channels
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
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)