38 #define FLAC_SUBFRAME_CONSTANT 0
39 #define FLAC_SUBFRAME_VERBATIM 1
40 #define FLAC_SUBFRAME_FIXED 8
41 #define FLAC_SUBFRAME_LPC 32
43 #define MAX_FIXED_ORDER 4
44 #define MAX_PARTITION_ORDER 8
45 #define MAX_PARTITIONS (1 << MAX_PARTITION_ORDER)
46 #define MAX_LPC_PRECISION 15
47 #define MIN_LPC_SHIFT 0
48 #define MAX_LPC_SHIFT 15
149 put_bits(&pb, 5,
s->avctx->bits_per_raw_sample - 1);
151 put_bits(&pb, 24, (
s->sample_count & 0xFFFFFF000LL) >> 12);
152 put_bits(&pb, 12,
s->sample_count & 0x000000FFFLL);
154 memcpy(&
header[18],
s->md5sum, 16);
170 target = (samplerate * block_time_ms) / 1000;
171 for (
i = 0;
i < 16;
i++) {
196 av_log(avctx,
AV_LOG_DEBUG,
" lpc type: Levinson-Durbin recursion with Welch window\n");
272 for (
i = 4;
i < 12;
i++) {
282 if (freq % 1000 == 0 && freq < 255000) {
284 s->sr_code[1] = freq / 1000;
285 }
else if (freq % 10 == 0 && freq < 655350) {
287 s->sr_code[1] = freq / 10;
288 }
else if (freq < 65535) {
290 s->sr_code[1] = freq;
295 s->samplerate = freq;
300 s->options.compression_level = 5;
304 level =
s->options.compression_level;
307 s->options.compression_level);
311 s->options.block_time_ms = ((
int[]){ 27, 27, 27,105,105,105,105,105,105,105,105,105,105})[
level];
320 if (
s->options.min_prediction_order < 0)
321 s->options.min_prediction_order = ((
int[]){ 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[
level];
322 if (
s->options.max_prediction_order < 0)
323 s->options.max_prediction_order = ((
int[]){ 3, 4, 4, 6, 8, 8, 8, 8, 12, 12, 12, 32, 32})[
level];
325 if (
s->options.prediction_order_method < 0)
332 if (
s->options.min_partition_order >
s->options.max_partition_order) {
334 s->options.min_partition_order,
s->options.max_partition_order);
337 if (
s->options.min_partition_order < 0)
338 s->options.min_partition_order = ((
int[]){ 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})[
level];
339 if (
s->options.max_partition_order < 0)
340 s->options.max_partition_order = ((
int[]){ 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8})[
level];
342 #if FF_API_PRIVATE_OPT
348 "invalid min prediction order %d, clamped to %d\n",
364 "invalid max prediction order %d, clamped to %d\n",
379 s->options.min_prediction_order = 0;
380 s->options.max_prediction_order = 0;
384 "invalid min prediction order %d, clamped to %d\n",
390 "invalid max prediction order %d, clamped to %d\n",
396 if (
s->options.max_prediction_order <
s->options.min_prediction_order) {
398 s->options.min_prediction_order,
s->options.max_prediction_order);
412 s->max_blocksize =
s->avctx->frame_size;
417 s->avctx->bits_per_raw_sample);
433 s->min_framesize =
s->max_framesize;
448 "output stream will have incorrect "
449 "channel layout.\n");
452 "will use Flac channel layout for "
477 for (
i = 0;
i < 16;
i++) {
481 frame->bs_code[1] = 0;
486 frame->blocksize = nb_samples;
487 if (
frame->blocksize <= 256) {
488 frame->bs_code[0] = 6;
491 frame->bs_code[0] = 7;
496 for (ch = 0; ch <
s->channels; ch++) {
500 sub->obits =
s->avctx->bits_per_raw_sample;
508 frame->verbatim_only = 0;
520 s->avctx->bits_per_raw_sample;
522 #define COPY_SAMPLES(bits) do { \
523 const int ## bits ## _t *samples0 = samples; \
525 for (i = 0, j = 0; i < frame->blocksize; i++) \
526 for (ch = 0; ch < s->channels; ch++, j++) \
527 frame->subframes[ch].samples[i] = samples0[j] >> shift; \
542 for (
i = 0;
i < n;
i++) {
545 count += (v >> k) + 1 + k;
554 int p, porder, psize;
562 count +=
sub->wasted;
568 count +=
s->frame.blocksize *
sub->obits;
571 count += pred_order *
sub->obits;
575 count += 4 + 5 + pred_order *
s->options.lpc_coeff_precision;
581 porder =
sub->rc.porder;
582 psize =
s->frame.blocksize >> porder;
588 for (p = 0; p < 1 << porder; p++) {
589 int k =
sub->rc.params[p];
590 count +=
sub->rc.coding_mode;
593 part_end =
FFMIN(
s->frame.blocksize, part_end + psize);
601 #define rice_encode_count(sum, n, k) (((n)*((k)+1))+((sum-(n>>1))>>(k)))
613 sum2 = sum - (n >> 1);
615 return FFMIN(k, max_param);
624 for (k = 0; k <= max_param; k++) {
626 if (
bits < bestbits) {
637 int n,
int pred_order,
int max_param,
int exact)
643 part = (1 << porder);
646 cnt = (n >> porder) - pred_order;
647 for (
i = 0;
i < part;
i++) {
650 all_bits += sums[k][
i];
670 const uint32_t *res, *res_end;
675 for (k = 0; k <= kmax; k++) {
676 res = &
data[pred_order];
677 res_end = &
data[n >> pmax];
678 for (
i = 0;
i < parts;
i++) {
680 uint64_t sum = (1LL + k) * (res_end - res);
681 while (res < res_end)
682 sum += *(res++) >> k;
686 while (res < res_end)
690 res_end += n >> pmax;
698 int parts = (1 <<
level);
699 for (
i = 0;
i < parts;
i++) {
700 for (k=0; k<=kmax; k++)
701 sums[k][
i] = sums[k][2*
i] + sums[k][2*
i+1];
709 const int32_t *
data,
int n,
int pred_order,
int exact)
723 for (
i = 0;
i < n;
i++)
726 calc_sum_top(pmax, exact ? kmax : 0, udata, n, pred_order, sums);
729 bits[pmin] = UINT32_MAX;
732 if (
bits[
i] <
bits[opt_porder] || pmax == pmin) {
741 return bits[opt_porder];
758 s->frame.blocksize, pred_order);
760 s->frame.blocksize, pred_order);
762 uint64_t
bits = 8 + pred_order *
sub->obits + 2 +
sub->rc.coding_mode;
764 bits += 4 + 5 + pred_order *
s->options.lpc_coeff_precision;
766 s->frame.blocksize, pred_order,
s->options.exact_rice_parameters);
776 for (
i = 0;
i < order;
i++)
780 for (
i = order;
i < n;
i++)
782 }
else if (order == 1) {
783 for (
i = order;
i < n;
i++)
784 res[
i] = smp[
i] - smp[
i-1];
785 }
else if (order == 2) {
786 int a = smp[order-1] - smp[order-2];
787 for (
i = order;
i < n;
i += 2) {
788 int b = smp[
i ] - smp[
i-1];
790 a = smp[
i+1] - smp[
i ];
793 }
else if (order == 3) {
794 int a = smp[order-1] - smp[order-2];
795 int c = smp[order-1] - 2*smp[order-2] + smp[order-3];
796 for (
i = order;
i < n;
i += 2) {
797 int b = smp[
i ] - smp[
i-1];
800 a = smp[
i+1] - smp[
i ];
805 int a = smp[order-1] - smp[order-2];
806 int c = smp[order-1] - 2*smp[order-2] + smp[order-3];
807 int e = smp[order-1] - 3*smp[order-2] + 3*smp[order-3] - smp[order-4];
808 for (
i = order;
i < n;
i += 2) {
809 int b = smp[
i ] - smp[
i-1];
813 a = smp[
i+1] - smp[
i ];
825 int min_order, max_order, opt_order, omethod;
836 n =
frame->blocksize;
839 for (
i = 1;
i < n;
i++)
849 if (
frame->verbatim_only || n < 5) {
851 memcpy(res, smp, n *
sizeof(
int32_t));
855 min_order =
s->options.min_prediction_order;
856 max_order =
s->options.max_prediction_order;
857 omethod =
s->options.prediction_order_method;
867 bits[0] = UINT32_MAX;
868 for (
i = min_order;
i <= max_order;
i++) {
874 sub->order = opt_order;
876 if (
sub->order != max_order) {
886 s->options.lpc_coeff_precision, coefs,
shift,
s->options.lpc_type,
887 s->options.lpc_passes, omethod,
893 int levels = 1 << omethod;
896 int opt_index = levels-1;
897 opt_order = max_order-1;
898 bits[opt_index] = UINT32_MAX;
899 for (
i = levels-1;
i >= 0;
i--) {
900 int last_order = order;
901 order = min_order + (((max_order-min_order+1) * (
i+1)) / levels)-1;
902 order =
av_clip(order, min_order - 1, max_order - 1);
903 if (order == last_order)
905 if (
s->bps_code * 4 +
s->options.lpc_coeff_precision +
av_log2(order) <= 32) {
906 s->flac_dsp.lpc16_encode(res, smp, n, order+1, coefs[order],
909 s->flac_dsp.lpc32_encode(res, smp, n, order+1, coefs[order],
923 bits[0] = UINT32_MAX;
924 for (
i = min_order-1;
i < max_order;
i++) {
925 if (
s->bps_code * 4 +
s->options.lpc_coeff_precision +
av_log2(
i) <= 32) {
926 s->flac_dsp.lpc16_encode(res, smp, n,
i+1, coefs[
i],
shift[
i]);
928 s->flac_dsp.lpc32_encode(res, smp, n,
i+1, coefs[
i],
shift[
i]);
939 opt_order = min_order - 1 + (max_order-min_order)/3;
942 for (step = 16; step; step >>= 1) {
943 int last = opt_order;
944 for (
i = last-step;
i <= last+step;
i += step) {
945 if (i < min_order-1 || i >= max_order ||
bits[
i] < UINT32_MAX)
947 if (
s->bps_code * 4 +
s->options.lpc_coeff_precision +
av_log2(
i) <= 32) {
948 s->flac_dsp.lpc32_encode(res, smp, n,
i+1, coefs[
i],
shift[
i]);
950 s->flac_dsp.lpc16_encode(res, smp, n,
i+1, coefs[
i],
shift[
i]);
960 if (
s->options.multi_dim_quant) {
962 int i, step, improved;
963 int64_t best_score = INT64_MAX;
966 qmax = (1 << (
s->options.lpc_coeff_precision - 1)) - 1;
968 for (
i=0;
i<opt_order;
i++)
973 for (step = 0; step < allsteps; step++) {
979 for (
i=0;
i<opt_order;
i++) {
980 int diff = ((
tmp + 1) % 3) - 1;
981 lpc_try[
i] =
av_clip(coefs[opt_order - 1][
i] +
diff, -qmax, qmax);
988 if (
s->bps_code * 4 +
s->options.lpc_coeff_precision +
av_log2(opt_order - 1) <= 32) {
989 s->flac_dsp.lpc16_encode(res, smp, n, opt_order, lpc_try,
shift[opt_order-1]);
991 s->flac_dsp.lpc32_encode(res, smp, n, opt_order, lpc_try,
shift[opt_order-1]);
994 if (score < best_score) {
996 memcpy(coefs[opt_order-1], lpc_try,
sizeof(*coefs));
1003 sub->order = opt_order;
1004 sub->type_code =
sub->type | (
sub->order-1);
1006 for (
i = 0;
i <
sub->order;
i++)
1007 sub->coefs[
i] = coefs[
sub->order-1][
i];
1009 if (
s->bps_code * 4 +
s->options.lpc_coeff_precision +
av_log2(opt_order) <= 32) {
1010 s->flac_dsp.lpc16_encode(res, smp, n,
sub->order,
sub->coefs,
sub->shift);
1012 s->flac_dsp.lpc32_encode(res, smp, n,
sub->order,
sub->coefs,
sub->shift);
1042 if (
s->frame.bs_code[0] == 6)
1044 else if (
s->frame.bs_code[0] == 7)
1048 count += ((
s->sr_code[0] == 12) + (
s->sr_code[0] > 12) * 2) * 8;
1064 for (ch = 0; ch <
s->channels; ch++)
1067 count += (8 - (count & 7)) & 7;
1071 if (count > INT_MAX)
1081 for (ch = 0; ch <
s->channels; ch++) {
1085 for (
i = 0;
i <
s->frame.blocksize;
i++) {
1086 v |=
sub->samples[
i];
1091 if (v && !(v & 1)) {
1094 for (
i = 0;
i <
s->frame.blocksize;
i++)
1095 sub->samples[
i] >>= v;
1102 if (
sub->obits <= 17)
1119 sum[0] = sum[1] = sum[2] = sum[3] = 0;
1120 for (
i = 2;
i < n;
i++) {
1121 lt = left_ch[
i] - 2*left_ch[
i-1] + left_ch[
i-2];
1122 rt = right_ch[
i] - 2*right_ch[
i-1] + right_ch[
i-2];
1123 sum[2] +=
FFABS((lt + rt) >> 1);
1124 sum[3] +=
FFABS(lt - rt);
1125 sum[0] +=
FFABS(lt);
1126 sum[1] +=
FFABS(rt);
1129 for (
i = 0;
i < 4;
i++) {
1135 score[0] = sum[0] + sum[1];
1136 score[1] = sum[0] + sum[3];
1137 score[2] = sum[1] + sum[3];
1138 score[3] = sum[2] + sum[3];
1142 for (
i = 1;
i < 4;
i++)
1143 if (score[
i] < score[best])
1160 n =
frame->blocksize;
1161 left =
frame->subframes[0].samples;
1162 right =
frame->subframes[1].samples;
1164 if (
s->channels != 2) {
1169 if (
s->options.ch_mode < 0) {
1170 int max_rice_param = (1 <<
frame->subframes[0].rc.coding_mode) - 2;
1173 frame->ch_mode =
s->options.ch_mode;
1180 for (
i = 0;
i < n;
i++) {
1182 left[
i] = (
tmp + right[
i]) >> 1;
1183 right[
i] =
tmp - right[
i];
1185 frame->subframes[1].obits++;
1187 for (
i = 0;
i < n;
i++)
1188 right[
i] = left[
i] - right[
i];
1189 frame->subframes[1].obits++;
1191 for (
i = 0;
i < n;
i++)
1192 left[
i] -= right[
i];
1193 frame->subframes[0].obits++;
1225 if (
frame->bs_code[0] == 6)
1227 else if (
frame->bs_code[0] == 7)
1230 if (
s->sr_code[0] == 12)
1232 else if (
s->sr_code[0] > 12)
1246 for (ch = 0; ch <
s->channels; ch++) {
1248 int i, p, porder, psize;
1268 for (
i = 0;
i <
sub->order;
i++)
1273 int cbits =
s->options.lpc_coeff_precision;
1276 for (
i = 0;
i <
sub->order;
i++)
1284 porder =
sub->rc.porder;
1285 psize =
s->frame.blocksize >> porder;
1289 part_end = &
sub->residual[psize];
1290 for (p = 0; p < 1 << porder; p++) {
1291 int k =
sub->rc.params[p];
1293 while (res < part_end)
1326 int buf_size =
s->frame.blocksize *
s->channels *
1327 ((
s->avctx->bits_per_raw_sample + 7) / 8);
1335 if (
s->avctx->bits_per_raw_sample <= 16) {
1336 buf = (
const uint8_t *)samples;
1338 s->bdsp.bswap16_buf((uint16_t *)
s->md5_buffer,
1339 (
const uint16_t *) samples, buf_size / 2);
1340 buf =
s->md5_buffer;
1344 const int32_t *samples0 = samples;
1347 for (
i = 0;
i <
s->frame.blocksize *
s->channels;
i++) {
1351 buf =
s->md5_buffer;
1363 int frame_bytes, out_bytes, ret;
1369 s->max_framesize =
s->max_encoded_framesize;
1373 #if FF_API_SIDEDATA_ONLY_PKT
1386 avpkt->
pts =
s->next_pts;
1388 *got_packet_ptr = 1;
1414 if (frame_bytes < 0 || frame_bytes >
s->max_framesize) {
1415 s->frame.verbatim_only = 1;
1417 if (frame_bytes < 0) {
1434 if (out_bytes >
s->max_encoded_framesize)
1435 s->max_encoded_framesize = out_bytes;
1436 if (out_bytes < s->min_framesize)
1437 s->min_framesize = out_bytes;
1441 avpkt->
size = out_bytes;
1445 *got_packet_ptr = 1;
1463 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
1466 {
"lpc_type",
"LPC algorithm", offsetof(
FlacEncodeContext,
options.lpc_type),
AV_OPT_TYPE_INT, {.i64 =
FF_LPC_TYPE_DEFAULT },
FF_LPC_TYPE_DEFAULT,
FF_LPC_TYPE_NB-1,
FLAGS,
"lpc_type" },
1474 {
"prediction_order_method",
"Search method for selecting prediction order", offsetof(
FlacEncodeContext,
options.prediction_order_method),
AV_OPT_TYPE_INT, {.i64 = -1 }, -1,
ORDER_METHOD_LOG,
FLAGS,
"predm" },
1481 {
"ch_mode",
"Stereo decorrelation mode", offsetof(
FlacEncodeContext,
options.ch_mode),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1,
FLAC_CHMODE_MID_SIDE,
FLAGS,
"ch_mode" },
static enum AVSampleFormat sample_fmts[]
static double val(void *priv, double ch)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t size)
static av_cold int init(AVCodecContext *avctx)
#define PUT_UTF8(val, tmp, PUT_BYTE)
Convert a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long).
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Public header for CRC hash function implementation.
static float sub(float src0, float src1)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
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.
FLAC (Free Lossless Audio Codec) decoder/demuxer common functions.
#define FLAC_MAX_BLOCKSIZE
#define FLAC_MIN_BLOCKSIZE
@ FLAC_CHMODE_INDEPENDENT
#define FLAC_MAX_CHANNELS
#define FLAC_STREAMINFO_SIZE
const int ff_flac_sample_rate_table[16]
const int32_t ff_flac_blocksize_table[16]
static void set_sr_golomb_flac(PutBitContext *pb, int i, int k, int limit, int esc_len)
write signed golomb rice code (flac).
#define AV_CH_LAYOUT_QUAD
#define AV_CH_LAYOUT_5POINT0
#define AV_CH_LAYOUT_5POINT0_BACK
#define AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_5POINT1
#define AV_CH_LAYOUT_5POINT1_BACK
#define AV_CH_FRONT_CENTER
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
void av_md5_init(AVMD5 *ctx)
Initialize MD5 hashing.
struct AVMD5 * av_md5_alloc(void)
Allocate an AVMD5 context.
void av_md5_final(AVMD5 *ctx, uint8_t *dst)
Finish hashing and output digest value.
void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len)
Update hash value.
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_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S32
signed 32 bits
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define LIBAVUTIL_VERSION_INT
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
av_cold void ff_flacdsp_init(FLACDSPContext *c, enum AVSampleFormat fmt, int channels, int bps)
static void write_subframes(FlacEncodeContext *s)
#define MAX_PARTITION_ORDER
#define FLAC_SUBFRAME_CONSTANT
static void write_streaminfo(FlacEncodeContext *s, uint8_t *header)
Write streaminfo metadata block to byte array.
static void init_frame(FlacEncodeContext *s, int nb_samples)
static int encode_residual_ch(FlacEncodeContext *s, int ch)
static void write_frame_footer(FlacEncodeContext *s)
static av_cold int flac_encode_close(AVCodecContext *avctx)
#define FLAC_SUBFRAME_FIXED
static av_cold void dprint_compression_options(FlacEncodeContext *s)
static void copy_samples(FlacEncodeContext *s, const void *samples)
Copy channel-interleaved input samples into separate subframes.
#define MAX_LPC_PRECISION
static int estimate_stereo_mode(const int32_t *left_ch, const int32_t *right_ch, int n, int max_rice_param)
static const AVOption options[]
static uint64_t calc_optimal_rice_params(RiceContext *rc, int porder, uint64_t sums[32][MAX_PARTITIONS], int n, int pred_order, int max_param, int exact)
#define rice_encode_count(sum, n, k)
static void write_frame_header(FlacEncodeContext *s)
static uint64_t calc_rice_params(RiceContext *rc, uint32_t udata[FLAC_MAX_BLOCKSIZE], uint64_t sums[32][MAX_PARTITIONS], int pmin, int pmax, const int32_t *data, int n, int pred_order, int exact)
static const AVClass flac_encoder_class
static void encode_residual_fixed(int32_t *res, const int32_t *smp, int n, int order)
#define FLAC_SUBFRAME_VERBATIM
static void calc_sum_top(int pmax, int kmax, const uint32_t *data, int n, int pred_order, uint64_t sums[32][MAX_PARTITIONS])
static void write_utf8(PutBitContext *pb, uint32_t val)
static int write_frame(FlacEncodeContext *s, AVPacket *avpkt)
static int find_optimal_param(uint64_t sum, int n, int max_param)
Solve for d/dk(rice_encode_count) = n-((sum-(n>>1))>>(k+1)) = 0.
static int get_max_p_order(int max_porder, int n, int order)
static void channel_decorrelation(FlacEncodeContext *s)
Perform stereo channel decorrelation.
static av_cold int flac_encode_init(AVCodecContext *avctx)
static int encode_frame(FlacEncodeContext *s)
static uint64_t subframe_count_exact(FlacEncodeContext *s, FlacSubframe *sub, int pred_order)
static int select_blocksize(int samplerate, int block_time_ms)
Set blocksize based on samplerate.
#define COPY_SAMPLES(bits)
static uint64_t rice_count_exact(const int32_t *res, int n, int k)
#define FLAC_SUBFRAME_LPC
static int update_md5_sum(FlacEncodeContext *s, const void *samples)
static int find_optimal_param_exact(uint64_t sums[32][MAX_PARTITIONS], int i, int max_param)
static int count_frame_header(FlacEncodeContext *s)
static void remove_wasted_bits(FlacEncodeContext *s)
static void calc_sum_next(int level, uint64_t sums[32][MAX_PARTITIONS], int kmax)
static int flac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
static uint64_t find_subframe_rice_params(FlacEncodeContext *s, FlacSubframe *sub, int pred_order)
static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
av_cold void ff_lpc_end(LPCContext *s)
Uninitialize LPCContext.
int ff_lpc_calc_coefs(LPCContext *s, const int32_t *samples, int blocksize, int min_order, int max_order, int precision, int32_t coefs[][MAX_LPC_ORDER], int *shift, enum FFLPCType lpc_type, int lpc_passes, int omethod, int min_shift, int max_shift, int zero_shift)
Calculate LPC coefficients for multiple orders.
av_cold int ff_lpc_init(LPCContext *s, int blocksize, int max_order, enum FFLPCType lpc_type)
Initialize LPCContext.
#define ORDER_METHOD_4LEVEL
#define ORDER_METHOD_SEARCH
FFLPCType
LPC analysis type.
@ FF_LPC_TYPE_NONE
do not use LPC prediction or use all zero coefficients
@ FF_LPC_TYPE_CHOLESKY
Cholesky factorization.
@ FF_LPC_TYPE_FIXED
fixed LPC coefficients
@ FF_LPC_TYPE_LEVINSON
Levinson-Durbin recursion.
@ FF_LPC_TYPE_DEFAULT
use the codec default LPC type
@ FF_LPC_TYPE_NB
Not part of ABI.
#define ORDER_METHOD_8LEVEL
#define ORDER_METHOD_2LEVEL
Public header for MD5 hash function implementation.
static void frame_end(MpegEncContext *s)
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int put_bits_count(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static const uint8_t header[24]
static int shift(int a, int b)
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
attribute_deprecated int min_prediction_order
enum AVSampleFormat sample_fmt
audio sample format
attribute_deprecated int max_prediction_order
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int sample_rate
samples per second
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int channels
number of audio channels
attribute_deprecated int side_data_only_packets
Encoding only and set by default.
uint64_t channel_layout
Audio channel layout.
int frame_size
Number of samples per channel in an audio frame.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This structure stores compressed data.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int prediction_order_method
int exact_rice_parameters
unsigned int md5_buffer_size
CompressionOptions options
int max_encoded_framesize
FlacSubframe subframes[FLAC_MAX_CHANNELS]
uint32_t rc_udata[FLAC_MAX_BLOCKSIZE]
int32_t coefs[MAX_LPC_ORDER]
int32_t samples[FLAC_MAX_BLOCKSIZE]
uint64_t rc_sums[32][MAX_PARTITIONS]
int32_t residual[FLAC_MAX_BLOCKSIZE+11]
int params[MAX_PARTITIONS]
enum CodingMode coding_mode
static av_always_inline int diff(const uint32_t a, const uint32_t b)