40#define FLAC_SUBFRAME_CONSTANT 0
41#define FLAC_SUBFRAME_VERBATIM 1
42#define FLAC_SUBFRAME_FIXED 8
43#define FLAC_SUBFRAME_LPC 32
45#define MAX_FIXED_ORDER 4
46#define MAX_PARTITION_ORDER 8
47#define MAX_PARTITIONS (1 << MAX_PARTITION_ORDER)
48#define MAX_LPC_PRECISION 15
49#define MIN_LPC_SHIFT 0
50#define MAX_LPC_SHIFT 15
152 put_bits(&pb, 5,
s->avctx->bits_per_raw_sample - 1);
154 put_bits(&pb, 24, (
s->sample_count & 0xFFFFFF000LL) >> 12);
155 put_bits(&pb, 12,
s->sample_count & 0x000000FFFLL);
157 memcpy(&
header[18],
s->md5sum, 16);
176 count += ch * ((7+
bps+7)/8);
179 count += (( 2*
bps+1) * blocksize + 7) / 8;
181 count += ( ch*
bps * blocksize + 7) / 8;
201 target = (samplerate * block_time_ms) / 1000;
202 for (
i = 0;
i < 16;
i++) {
227 av_log(avctx,
AV_LOG_DEBUG,
" lpc type: Levinson-Durbin recursion with Welch window\n");
293 "encoding as 24 bits-per-sample, more is considered "
294 "experimental. Add -strict experimental if you want "
295 "to encode more than 24 bits-per-sample\n");
315 for (
i = 1;
i < 12;
i++) {
325 if (freq % 1000 == 0 && freq < 255000) {
327 s->sr_code[1] = freq / 1000;
328 }
else if (freq % 10 == 0 && freq < 655350) {
330 s->sr_code[1] = freq / 10;
331 }
else if (freq < 65535) {
333 s->sr_code[1] = freq;
334 }
else if (freq < 1048576) {
341 s->samplerate = freq;
346 s->options.compression_level = 5;
350 level =
s->options.compression_level;
353 s->options.compression_level);
357 s->options.block_time_ms = ((
int[]){ 27, 27, 27,105,105,105,105,105,105,105,105,105,105})[
level];
366 if (
s->options.min_prediction_order < 0)
367 s->options.min_prediction_order = ((
int[]){ 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[
level];
368 if (
s->options.max_prediction_order < 0)
369 s->options.max_prediction_order = ((
int[]){ 3, 4, 4, 6, 8, 8, 8, 8, 12, 12, 12, 32, 32})[
level];
371 if (
s->options.prediction_order_method < 0)
378 if (
s->options.min_partition_order >
s->options.max_partition_order) {
380 s->options.min_partition_order,
s->options.max_partition_order);
383 if (
s->options.min_partition_order < 0)
384 s->options.min_partition_order = ((
int[]){ 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})[
level];
385 if (
s->options.max_partition_order < 0)
386 s->options.max_partition_order = ((
int[]){ 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8})[
level];
389 s->options.min_prediction_order = 0;
390 s->options.max_prediction_order = 0;
394 "invalid min prediction order %d, clamped to %d\n",
400 "invalid max prediction order %d, clamped to %d\n",
406 "invalid min prediction order %d, clamped to %d\n",
411 if (
s->options.max_prediction_order <
s->options.min_prediction_order) {
413 s->options.min_prediction_order,
s->options.max_prediction_order);
427 s->max_blocksize =
s->avctx->frame_size;
432 s->avctx->bits_per_raw_sample);
448 s->min_framesize =
s->max_framesize;
463 "output stream will have incorrect "
464 "channel layout.\n");
467 "will use Flac channel layout for "
491 for (
i = 0;
i < 16;
i++) {
495 frame->bs_code[1] = 0;
500 frame->blocksize = nb_samples;
501 if (
frame->blocksize <= 256) {
502 frame->bs_code[0] = 6;
505 frame->bs_code[0] = 7;
510 for (ch = 0; ch <
s->channels; ch++) {
514 sub->
obits =
s->avctx->bits_per_raw_sample;
522 frame->verbatim_only = 0;
534#define COPY_SAMPLES(bits, shift0) do { \
535 const int ## bits ## _t *samples0 = samples; \
536 const int shift = shift0; \
538 for (i = 0, j = 0; i < frame->blocksize; i++) \
539 for (ch = 0; ch < s->channels; ch++, j++) \
540 frame->subframes[ch].samples[i] = samples0[j] >> shift; \
555 for (
i = 0;
i < n;
i++) {
556 unsigned v = ((unsigned)(res[
i]) << 1) ^ (res[
i] >> 31);
557 count += (v >> k) + 1 + k;
566 int p, porder, psize;
580 count +=
s->frame.blocksize * sub->
obits;
583 count += pred_order * sub->
obits;
587 count += 4 + 5 + pred_order *
s->options.lpc_coeff_precision;
594 psize =
s->frame.blocksize >> porder;
600 for (p = 0; p < 1 << porder; p++) {
605 part_end =
FFMIN(
s->frame.blocksize, part_end + psize);
613#define rice_encode_count(sum, n, k) (((n)*((k)+1))+((sum-(n>>1))>>(k)))
625 sum2 = sum - (n >> 1);
627 return FFMIN(k, max_param);
636 for (k = 0; k <= max_param; k++) {
638 if (
bits < bestbits) {
649 int n,
int pred_order,
int max_param,
int exact)
655 part = (1 << porder);
658 cnt = (n >> porder) - pred_order;
659 for (
i = 0;
i < part;
i++) {
662 all_bits += sums[k][
i];
682 const uint32_t *res, *res_end;
687 for (k = 0; k <= kmax; k++) {
688 res = &
data[pred_order];
689 res_end = &
data[n >> pmax];
690 for (
i = 0;
i < parts;
i++) {
692 uint64_t sum = (1LL + k) * (res_end - res);
693 while (res < res_end)
694 sum += *(res++) >> k;
698 while (res < res_end)
702 res_end += n >> pmax;
710 int parts = (1 <<
level);
711 for (
i = 0;
i < parts;
i++) {
712 for (k=0; k<=kmax; k++)
713 sums[k][
i] = sums[k][2*
i] + sums[k][2*
i+1];
721 const int32_t *
data,
int n,
int pred_order,
int exact)
735 for (
i = pred_order;
i < n;
i++)
736 udata[
i] = ((
unsigned)(
data[
i]) << 1) ^ (
data[
i] >> 31);
738 calc_sum_top(pmax, exact ? kmax : 0, udata, n, pred_order, sums);
741 bits[pmin] = UINT32_MAX;
744 if (
bits[
i] <
bits[opt_porder] || pmax == pmin) {
753 return bits[opt_porder];
770 s->frame.blocksize, pred_order);
772 s->frame.blocksize, pred_order);
776 bits += 4 + 5 + pred_order *
s->options.lpc_coeff_precision;
778 s->frame.blocksize, pred_order,
s->options.exact_rice_parameters);
788 for (
i = 0;
i < order;
i++)
792 for (
i = order;
i < n;
i++)
794 }
else if (order == 1) {
795 for (
i = order;
i < n;
i++)
796 res[
i] = smp[
i] - smp[
i-1];
797 }
else if (order == 2) {
798 int a = smp[order-1] - smp[order-2];
799 for (
i = order;
i < n;
i += 2) {
800 int b = smp[
i ] - smp[
i-1];
802 a = smp[
i+1] - smp[
i ];
805 }
else if (order == 3) {
806 int a = smp[order-1] - smp[order-2];
807 int c = smp[order-1] - 2*smp[order-2] + smp[order-3];
808 for (
i = order;
i < n;
i += 2) {
809 int b = smp[
i ] - smp[
i-1];
812 a = smp[
i+1] - smp[
i ];
817 int a = smp[order-1] - smp[order-2];
818 int c = smp[order-1] - 2*smp[order-2] + smp[order-3];
819 int e = smp[order-1] - 3*smp[order-2] + 3*smp[order-3] - smp[order-4];
820 for (
i = order;
i < n;
i += 2) {
821 int b = smp[
i ] - smp[
i-1];
825 a = smp[
i+1] - smp[
i ];
839#define ENCODE_RESIDUAL_FIXED_WITH_RESIDUAL_LIMIT() \
841 for (int i = 0; i < order; i++) \
844 for (int i = order; i < n; i++) { \
845 if (smp[i] == INT32_MIN) \
849 } else if (order == 1) { \
850 for (int i = order; i < n; i++) { \
851 int64_t res64 = (int64_t)smp[i] - smp[i-1]; \
852 if (res64 <= INT32_MIN || res64 > INT32_MAX) \
856 } else if (order == 2) { \
857 for (int i = order; i < n; i++) { \
858 int64_t res64 = (int64_t)smp[i] - 2*(int64_t)smp[i-1] + smp[i-2]; \
859 if (res64 <= INT32_MIN || res64 > INT32_MAX) \
863 } else if (order == 3) { \
864 for (int i = order; i < n; i++) { \
865 int64_t res64 = (int64_t)smp[i] - 3*(int64_t)smp[i-1] + 3*(int64_t)smp[i-2] - smp[i-3]; \
866 if (res64 <= INT32_MIN || res64 > INT32_MAX) \
871 for (int i = order; i < n; i++) { \
872 int64_t res64 = (int64_t)smp[i] - 4*(int64_t)smp[i-1] + 6*(int64_t)smp[i-2] - 4*(int64_t)smp[i-3] + smp[i-4]; \
873 if (res64 <= INT32_MIN || res64 > INT32_MAX) \
894#define LPC_ENCODE_WITH_RESIDUAL_LIMIT() \
896 for (int i = 0; i < order; i++) \
898 for (int i = order; i < len; i++) { \
899 int64_t p = 0, tmp; \
900 for (int j = 0; j < order; j++) \
901 p += (int64_t)coefs[j]*smp[(i-1)-j]; \
904 if (tmp <= INT32_MIN || tmp > INT32_MAX) \
928 uint64_t max_residual_value = 0;
932 for (
int i = 0;
i < order;
i++)
933 max_residual_value +=
FFABS(max_sample_value * coefs[
i]);
934 max_residual_value >>=
shift;
935 max_residual_value += max_sample_value;
939 }
else if (max_residual_value > INT32_MAX) {
942 }
else if (
bps +
s->options.lpc_coeff_precision +
av_log2(order) <= 32) {
943 s->flac_dsp.lpc16_encode(res, smp,
len, order, coefs,
shift);
945 s->flac_dsp.lpc32_encode(res, smp,
len, order, coefs,
shift);
950#define DEFAULT_TO_VERBATIM() \
952 sub->type = sub->type_code = FLAC_SUBFRAME_VERBATIM; \
953 if (sub->obits <= 32) \
954 memcpy(res, smp, n * sizeof(int32_t)); \
955 return subframe_count_exact(s, sub, 0); \
961 int min_order, max_order, opt_order, omethod;
970 sub = &
frame->subframes[ch];
973 smp_33bps =
frame->samples_33bps;
974 n =
frame->blocksize;
977 if (sub->
obits > 32) {
978 for (
i = 1;
i < n;
i++)
979 if(smp_33bps[
i] != smp_33bps[0])
986 for (
i = 1;
i < n;
i++)
997 if (
frame->verbatim_only || n < 5) {
1001 min_order =
s->options.min_prediction_order;
1002 max_order =
s->options.max_prediction_order;
1003 omethod =
s->options.prediction_order_method;
1013 bits[0] = UINT32_MAX;
1014 for (
i = min_order;
i <= max_order;
i++) {
1015 if (sub->
obits == 33) {
1018 }
else if (sub->
obits +
i >= 32) {
1027 if (opt_order == 0 &&
bits[0] == UINT32_MAX) {
1032 sub->
order = opt_order;
1034 if (sub->
order != max_order) {
1035 if (sub->
obits == 33)
1037 else if (sub->
obits +
i >= 32)
1048 if (sub->
obits == 33)
1053 for (
i = 0;
i < n;
i++)
1054 smp[
i] = smp_33bps[
i] >> 1;
1057 s->options.lpc_coeff_precision, coefs,
shift,
s->options.lpc_type,
1058 s->options.lpc_passes, omethod,
1064 int levels = 1 << omethod;
1067 int opt_index = levels-1;
1068 opt_order = max_order-1;
1069 bits[opt_index] = UINT32_MAX;
1070 for (
i = levels-1;
i >= 0;
i--) {
1071 int last_order = order;
1072 order = min_order + (((max_order-min_order+1) * (
i+1)) / levels)-1;
1073 order =
av_clip(order, min_order - 1, max_order - 1);
1074 if (order == last_order)
1089 bits[0] = UINT32_MAX;
1090 for (
i = min_order-1;
i < max_order;
i++) {
1102 opt_order = min_order - 1 + (max_order-min_order)/3;
1105 for (step = 16; step; step >>= 1) {
1106 int last = opt_order;
1107 for (
i = last-step;
i <= last+step;
i += step) {
1120 if (
s->options.multi_dim_quant) {
1122 int i, step, improved;
1123 int64_t best_score = INT64_MAX;
1126 qmax = (1 << (
s->options.lpc_coeff_precision - 1)) - 1;
1128 for (
i=0;
i<opt_order;
i++)
1133 for (step = 0; step < allsteps; step++) {
1139 for (
i=0;
i<opt_order;
i++) {
1140 int diff = ((
tmp + 1) % 3) - 1;
1141 lpc_try[
i] =
av_clip(coefs[opt_order - 1][
i] +
diff, -qmax, qmax);
1151 if (score < best_score) {
1153 memcpy(coefs[opt_order-1], lpc_try,
sizeof(*coefs));
1160 sub->
order = opt_order;
1199 if (
s->frame.bs_code[0] == 6)
1201 else if (
s->frame.bs_code[0] == 7)
1205 count += ((
s->sr_code[0] == 12) + (
s->sr_code[0] > 12) * 2) * 8;
1221 for (ch = 0; ch <
s->channels; ch++)
1224 count += (8 - (count & 7)) & 7;
1228 if (count > INT_MAX)
1236 int ch,
i, wasted_bits;
1238 for (ch = 0; ch <
s->channels; ch++) {
1241 if (sub->
obits > 32) {
1243 for (
i = 0;
i <
s->frame.blocksize;
i++) {
1244 v |=
s->frame.samples_33bps[
i];
1256 for (
i = 0;
i <
s->frame.blocksize;
i++)
1257 sub->
samples[
i] =
s->frame.samples_33bps[
i] >> v;
1261 for (
i = 0;
i <
s->frame.blocksize;
i++) {
1272 for (
i = 0;
i <
s->frame.blocksize;
i++)
1277 sub->
wasted = wasted_bits;
1278 sub->
obits -= wasted_bits;
1282 if (sub->
obits <= 17)
1289 int max_rice_param,
int bps)
1297 sum[0] = sum[1] = sum[2] = sum[3] = 0;
1300 for (
int i = 2;
i < n;
i++) {
1301 lt = left_ch[
i] - 2*left_ch[
i-1] + left_ch[
i-2];
1302 rt = right_ch[
i] - 2*right_ch[
i-1] + right_ch[
i-2];
1303 sum[2] +=
FFABS((lt + rt) >> 1);
1304 sum[3] +=
FFABS(lt - rt);
1305 sum[0] +=
FFABS(lt);
1306 sum[1] +=
FFABS(rt);
1310 for (
int i = 2;
i < n;
i++) {
1313 sum[2] +=
FFABS((lt + rt) >> 1);
1314 sum[3] +=
FFABS(lt - rt);
1315 sum[0] +=
FFABS(lt);
1316 sum[1] +=
FFABS(rt);
1320 for (
int i = 0;
i < 4;
i++) {
1326 score[0] = sum[0] + sum[1];
1327 score[1] = sum[0] + sum[3];
1328 score[2] = sum[1] + sum[3];
1329 score[3] = sum[2] + sum[3];
1333 for (
int i = 1;
i < 4;
i++)
1334 if (score[
i] < score[best])
1352 n =
frame->blocksize;
1354 right =
frame->subframes[1].samples;
1355 side_33bps =
frame->samples_33bps;
1357 if (
s->channels != 2) {
1362 if (
s->options.ch_mode < 0) {
1363 int max_rice_param = (1 <<
frame->subframes[0].rc.coding_mode) - 2;
1366 frame->ch_mode =
s->options.ch_mode;
1371 if(
s->avctx->bits_per_raw_sample == 32) {
1374 for (
int i = 0;
i < n;
i++) {
1377 side_33bps[
i] =
tmp - right[
i];
1379 frame->subframes[1].obits++;
1381 for (
int i = 0;
i < n;
i++)
1383 frame->subframes[1].obits++;
1385 for (
int i = 0;
i < n;
i++)
1387 frame->subframes[0].obits++;
1392 for (
int i = 0;
i < n;
i++) {
1395 right[
i] =
tmp - right[
i];
1397 frame->subframes[1].obits++;
1399 for (
int i = 0;
i < n;
i++)
1400 right[
i] =
left[
i] - right[
i];
1401 frame->subframes[1].obits++;
1403 for (
int i = 0;
i < n;
i++)
1405 frame->subframes[0].obits++;
1438 if (
frame->bs_code[0] == 6)
1440 else if (
frame->bs_code[0] == 7)
1443 if (
s->sr_code[0] == 12)
1445 else if (
s->sr_code[0] > 12)
1459 v = ((unsigned)(
i) << 1) ^ (
i >> 31);
1468 unsigned mask = UINT32_MAX >> (32-k);
1478 for (ch = 0; ch <
s->channels; ch++) {
1480 int p, porder, psize;
1494 if(sub->
obits == 33)
1496 else if(sub->
obits == 32)
1501 if (sub->
obits == 33) {
1502 int64_t *res64 =
s->frame.samples_33bps;
1503 int64_t *frame_end64 = &
s->frame.samples_33bps[
s->frame.blocksize];
1504 while (res64 < frame_end64)
1506 }
else if (sub->
obits == 32) {
1515 if (sub->
obits == 33) {
1516 for (
int i = 0;
i < sub->
order;
i++)
1519 }
else if (sub->
obits == 32) {
1520 for (
int i = 0;
i < sub->
order;
i++)
1523 for (
int i = 0;
i < sub->
order;
i++)
1529 int cbits =
s->options.lpc_coeff_precision;
1532 for (
int i = 0;
i < sub->
order;
i++)
1541 psize =
s->frame.blocksize >> porder;
1546 for (p = 0; p < 1 << porder; p++) {
1549 while (res < part_end)
1582 int buf_size =
s->frame.blocksize *
s->channels *
1583 ((
s->avctx->bits_per_raw_sample + 7) / 8);
1585 if (
s->avctx->bits_per_raw_sample > 16 || HAVE_BIGENDIAN) {
1591 if (
s->avctx->bits_per_raw_sample <= 16) {
1592 buf = (
const uint8_t *)samples;
1594 s->bdsp.bswap16_buf((uint16_t *)
s->md5_buffer,
1595 (
const uint16_t *) samples, buf_size / 2);
1596 buf =
s->md5_buffer;
1598 }
else if (
s->avctx->bits_per_raw_sample <= 24) {
1600 const int32_t *samples0 = samples;
1601 uint8_t *
tmp =
s->md5_buffer;
1603 for (
i = 0;
i <
s->frame.blocksize *
s->channels;
i++) {
1607 buf =
s->md5_buffer;
1611 const int32_t *samples0 = samples;
1612 uint8_t *
tmp =
s->md5_buffer;
1614 for (
i = 0;
i <
s->frame.blocksize *
s->channels;
i++)
1616 buf =
s->md5_buffer;
1628 int frame_bytes, out_bytes,
ret;
1634 s->max_framesize =
s->max_encoded_framesize;
1645 avpkt->
pts =
s->next_pts;
1647 *got_packet_ptr = 1;
1655 if (
frame->nb_samples <
s->frame.blocksize) {
1673 if (frame_bytes < 0 || frame_bytes >
s->max_framesize) {
1674 s->frame.verbatim_only = 1;
1676 if (frame_bytes < 0) {
1688 s->sample_count +=
frame->nb_samples;
1693 if (out_bytes >
s->max_encoded_framesize)
1694 s->max_encoded_framesize = out_bytes;
1695 if (out_bytes < s->min_framesize)
1696 s->min_framesize = out_bytes;
1702 *got_packet_ptr = 1;
1717#define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
1720{
"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, .unit =
"lpc_type" },
1728{
"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, .unit =
"predm" },
1735{
"ch_mode",
"Stereo decorrelation mode", offsetof(
FlacEncodeContext,
options.ch_mode),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1,
FLAC_CHMODE_MID_SIDE,
FLAGS, .unit =
"ch_mode" },
1750 .class_name =
"FLAC encoder",
static double val(void *priv, double ch)
const FFCodec ff_flac_encoder
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.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
#define FF_CODEC_CAP_EOF_FLUSH
The encoder has AV_CODEC_CAP_DELAY set, but does not actually have delay - it only wants to be flushe...
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define CODEC_SAMPLEFMTS(...)
#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.
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
int(* init)(AVBSFContext *ctx)
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
static av_always_inline int64_t ff_samples_to_time_base(const AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
static const uint8_t bits[8]
FLAC (Free Lossless Audio Codec) common stuff.
#define FLAC_MAX_BLOCKSIZE
@ FLAC_CHMODE_INDEPENDENT
#define FLAC_MIN_BLOCKSIZE
#define FLAC_MAX_CHANNELS
#define FLAC_STREAMINFO_SIZE
const int ff_flac_sample_rate_table[16]
const int32_t ff_flac_blocksize_table[16]
av_cold void ff_flacencdsp_init(FLACEncDSPContext *c)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#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_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#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...
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
#define AV_CHANNEL_LAYOUT_5POINT1_BACK
#define AV_CHANNEL_LAYOUT_5POINT0
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
#define AV_CHANNEL_LAYOUT_2_2
#define AV_CHANNEL_LAYOUT_5POINT0_BACK
#define AV_CHANNEL_LAYOUT_5POINT1
#define AV_CHANNEL_LAYOUT_SURROUND
#define AV_CHANNEL_LAYOUT_QUAD
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
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.
void av_md5_final(AVMD5 *ctx, uint8_t *dst)
Finish hashing and output digest value.
struct AVMD5 * av_md5_alloc(void)
Allocate an AVMD5 context.
void av_md5_update(AVMD5 *ctx, const uint8_t *src, size_t 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.
@ 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
static int shift(int a, int b)
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
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 lpc_encode_with_residual_limit(int32_t *res, const int32_t *smp, int len, int order, int32_t *coefs, int shift)
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 int estimate_stereo_mode(const int32_t *left_ch, const int32_t *right_ch, int n, int max_rice_param, int bps)
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 void set_sr_golomb_flac(PutBitContext *pb, int i, int k)
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.
static int encode_residual_fixed_with_residual_limit(int32_t *res, const int32_t *smp, int n, int order)
static int lpc_encode_choose_datapath(FlacEncodeContext *s, int32_t bps, int32_t *res, const int32_t *smp, const int64_t *smp_33bps, int len, int order, int32_t *coefs, int shift)
#define COPY_SAMPLES(bits, shift0)
static int encode_residual_fixed_with_residual_limit_33bps(int32_t *res, const int64_t *smp, int n, int order)
static int lpc_encode_with_residual_limit_33bps(int32_t *res, const int64_t *smp, int len, int order, int32_t *coefs, int shift)
#define ENCODE_RESIDUAL_FIXED_WITH_RESIDUAL_LIMIT()
static uint64_t rice_count_exact(const int32_t *res, int n, int k)
#define FLAC_SUBFRAME_LPC
#define LPC_ENCODE_WITH_RESIDUAL_LIMIT()
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 int flac_get_max_frame_size(int blocksize, int ch, int bps)
Calculate an estimate for the maximum frame size based on verbatim mode.
#define DEFAULT_TO_VERBATIM()
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)
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
@ 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
static const uint16_t mask[17]
Public header for MD5 hash function implementation.
Memory handling functions.
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 void put_sbits63(PutBitContext *pb, int n, int64_t value)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static int put_bytes_output(const PutBitContext *s)
static av_unused void put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
static const uint8_t header[24]
An AVChannelLayout holds information about the channel layout of audio data.
enum AVChannelOrder order
Channel order used in this layout.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int sample_rate
samples per second
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
int frame_size
Number of samples per channel in an audio frame.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
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
FLACEncDSPContext flac_dsp
int max_encoded_framesize
int64_t samples_33bps[FLAC_MAX_BLOCKSIZE]
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 int64_t frame_end(const SyncQueue *sq, SyncQueueFrame frame, int nb_samples)
Compute the end timestamp of a frame.
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)