X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fflacenc.c;h=631f02f0dba24f0569cb309d5b9c1c707cc46dee;hb=1d12a545ce828eaf4fb37295400008ea37635ab8;hp=2277cf3f5fb9bd9401154e755ee50735f3c14117;hpb=70d246d5cc3d214da11f711d997d8cbd8c3a23d1;p=ffmpeg diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c index 2277cf3f5fb..631f02f0dba 100644 --- a/libavcodec/flacenc.c +++ b/libavcodec/flacenc.c @@ -23,9 +23,9 @@ #include "libavutil/intmath.h" #include "libavutil/md5.h" #include "libavutil/opt.h" + #include "avcodec.h" #include "bswapdsp.h" -#include "get_bits.h" #include "golomb.h" #include "internal.h" #include "lpc.h" @@ -67,6 +67,7 @@ typedef struct RiceContext { enum CodingMode coding_mode; int porder; int params[MAX_PARTITIONS]; + uint32_t udata[FLAC_MAX_BLOCKSIZE]; } RiceContext; typedef struct FlacSubframe { @@ -304,8 +305,10 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) FF_LPC_TYPE_LEVINSON, FF_LPC_TYPE_LEVINSON, FF_LPC_TYPE_LEVINSON, FF_LPC_TYPE_LEVINSON})[level]; - s->options.min_prediction_order = ((int[]){ 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[level]; - s->options.max_prediction_order = ((int[]){ 3, 4, 4, 6, 8, 8, 8, 8, 12, 12, 12, 32, 32})[level]; + if (s->options.min_prediction_order < 0) + s->options.min_prediction_order = ((int[]){ 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[level]; + if (s->options.max_prediction_order < 0) + s->options.max_prediction_order = ((int[]){ 3, 4, 4, 6, 8, 8, 8, 8, 12, 12, 12, 32, 32})[level]; if (s->options.prediction_order_method < 0) s->options.prediction_order_method = ((int[]){ ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST, @@ -324,14 +327,15 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) if (s->options.max_partition_order < 0) s->options.max_partition_order = ((int[]){ 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8})[level]; - if (s->options.lpc_type == FF_LPC_TYPE_NONE) { - s->options.min_prediction_order = 0; - } else if (avctx->min_prediction_order >= 0) { +#if FF_API_PRIVATE_OPT +FF_DISABLE_DEPRECATION_WARNINGS + if (avctx->min_prediction_order >= 0) { if (s->options.lpc_type == FF_LPC_TYPE_FIXED) { if (avctx->min_prediction_order > MAX_FIXED_ORDER) { - av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n", - avctx->min_prediction_order); - return -1; + av_log(avctx, AV_LOG_WARNING, + "invalid min prediction order %d, clamped to %d\n", + avctx->min_prediction_order, MAX_FIXED_ORDER); + avctx->min_prediction_order = MAX_FIXED_ORDER; } } else if (avctx->min_prediction_order < MIN_LPC_ORDER || avctx->min_prediction_order > MAX_LPC_ORDER) { @@ -341,14 +345,13 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) } s->options.min_prediction_order = avctx->min_prediction_order; } - if (s->options.lpc_type == FF_LPC_TYPE_NONE) { - s->options.max_prediction_order = 0; - } else if (avctx->max_prediction_order >= 0) { + if (avctx->max_prediction_order >= 0) { if (s->options.lpc_type == FF_LPC_TYPE_FIXED) { if (avctx->max_prediction_order > MAX_FIXED_ORDER) { - av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n", - avctx->max_prediction_order); - return -1; + av_log(avctx, AV_LOG_WARNING, + "invalid max prediction order %d, clamped to %d\n", + avctx->max_prediction_order, MAX_FIXED_ORDER); + avctx->max_prediction_order = MAX_FIXED_ORDER; } } else if (avctx->max_prediction_order < MIN_LPC_ORDER || avctx->max_prediction_order > MAX_LPC_ORDER) { @@ -358,6 +361,26 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) } s->options.max_prediction_order = avctx->max_prediction_order; } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (s->options.lpc_type == FF_LPC_TYPE_NONE) { + s->options.min_prediction_order = 0; + s->options.max_prediction_order = 0; + } else if (s->options.lpc_type == FF_LPC_TYPE_FIXED) { + if (s->options.min_prediction_order > MAX_FIXED_ORDER) { + av_log(avctx, AV_LOG_WARNING, + "invalid min prediction order %d, clamped to %d\n", + s->options.min_prediction_order, MAX_FIXED_ORDER); + s->options.min_prediction_order = MAX_FIXED_ORDER; + } + if (s->options.max_prediction_order > MAX_FIXED_ORDER) { + av_log(avctx, AV_LOG_WARNING, + "invalid max prediction order %d, clamped to %d\n", + s->options.max_prediction_order, MAX_FIXED_ORDER); + s->options.max_prediction_order = MAX_FIXED_ORDER; + } + } + if (s->options.max_prediction_order < s->options.min_prediction_order) { av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\n", s->options.min_prediction_order, s->options.max_prediction_order); @@ -616,7 +639,6 @@ static uint64_t calc_rice_params(RiceContext *rc, int pmin, int pmax, uint64_t bits[MAX_PARTITION_ORDER+1]; int opt_porder; RiceContext tmp_rc; - uint32_t *udata; uint64_t sums[MAX_PARTITION_ORDER + 1][MAX_PARTITIONS] = { { 0 } }; assert(pmin >= 0 && pmin <= MAX_PARTITION_ORDER); @@ -625,11 +647,10 @@ static uint64_t calc_rice_params(RiceContext *rc, int pmin, int pmax, tmp_rc.coding_mode = rc->coding_mode; - udata = av_malloc(n * sizeof(uint32_t)); for (i = 0; i < n; i++) - udata[i] = (2*data[i]) ^ (data[i]>>31); + rc->udata[i] = (2 * data[i]) ^ (data[i] >> 31); - calc_sums(pmin, pmax, udata, n, pred_order, sums); + calc_sums(pmin, pmax, rc->udata, n, pred_order, sums); opt_porder = pmin; bits[pmin] = UINT32_MAX; @@ -641,7 +662,6 @@ static uint64_t calc_rice_params(RiceContext *rc, int pmin, int pmax, } } - av_freep(&udata); return bits[opt_porder]; } @@ -1216,7 +1236,13 @@ static int flac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, av_md5_final(s->md5ctx, s->md5sum); write_streaminfo(s, avctx->extradata); +#if FF_API_SIDEDATA_ONLY_PKT +FF_DISABLE_DEPRECATION_WARNINGS if (avctx->side_data_only_packets && !s->flushed) { +FF_ENABLE_DEPRECATION_WARNINGS +#else + if (!s->flushed) { +#endif uint8_t *side_data = av_packet_new_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, avctx->extradata_size); if (!side_data) @@ -1326,14 +1352,17 @@ static const AVOption options[] = { { "left_side", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FLAC_CHMODE_LEFT_SIDE }, INT_MIN, INT_MAX, FLAGS, "ch_mode" }, { "right_side", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FLAC_CHMODE_RIGHT_SIDE }, INT_MIN, INT_MAX, FLAGS, "ch_mode" }, { "mid_side", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = FLAC_CHMODE_MID_SIDE }, INT_MIN, INT_MAX, FLAGS, "ch_mode" }, +{ "min_prediction_order", NULL, offsetof(FlacEncodeContext, options.min_prediction_order), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, MAX_LPC_ORDER, FLAGS }, +{ "max_prediction_order", NULL, offsetof(FlacEncodeContext, options.max_prediction_order), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, MAX_LPC_ORDER, FLAGS }, + { NULL }, }; static const AVClass flac_encoder_class = { - "FLAC encoder", - av_default_item_name, - options, - LIBAVUTIL_VERSION_INT, + .class_name = "FLAC encoder", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, }; AVCodec ff_flac_encoder = { @@ -1345,7 +1374,7 @@ AVCodec ff_flac_encoder = { .init = flac_encode_init, .encode2 = flac_encode_frame, .close = flac_encode_close, - .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY, + .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY, .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE },