]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/flacenc.c
Fix parser not to clobber has_b_frames when extradata is set.
[ffmpeg] / libavcodec / flacenc.c
index 8624a6d987a26f1e0fc554d2e0629d62ffff2a71..900714120ac91dfd1181ebf62742d2b1683fc827 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * FLAC audio encoder
  * Copyright (c) 2006  Justin Ruggles <justin.ruggles@gmail.com>
  *
@@ -295,29 +295,6 @@ 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];
 
-    /* set compression option overrides from AVCodecContext */
-#if FF_API_FLAC_GLOBAL_OPTS
-    if (avctx->lpc_type > FF_LPC_TYPE_DEFAULT) {
-        if (avctx->lpc_type > FF_LPC_TYPE_CHOLESKY) {
-            av_log(avctx, AV_LOG_ERROR, "unknown lpc type: %d\n", avctx->lpc_type);
-            return -1;
-        }
-        s->options.lpc_type = avctx->lpc_type;
-        if (s->options.lpc_type == FF_LPC_TYPE_CHOLESKY) {
-            if (avctx->lpc_passes < 0) {
-                // default number of passes for Cholesky
-                s->options.lpc_passes = 2;
-            } else if (avctx->lpc_passes == 0) {
-                av_log(avctx, AV_LOG_ERROR, "invalid number of lpc passes: %d\n",
-                       avctx->lpc_passes);
-                return -1;
-            } else {
-                s->options.lpc_passes = avctx->lpc_passes;
-            }
-        }
-    }
-#endif
-
     if (s->options.lpc_type == FF_LPC_TYPE_NONE) {
         s->options.min_prediction_order = 0;
     } else if (avctx->min_prediction_order >= 0) {
@@ -358,39 +335,6 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
         return -1;
     }
 
-#if FF_API_FLAC_GLOBAL_OPTS
-    if (avctx->prediction_order_method >= 0) {
-        if (avctx->prediction_order_method > ORDER_METHOD_LOG) {
-            av_log(avctx, AV_LOG_ERROR, "invalid prediction order method: %d\n",
-                   avctx->prediction_order_method);
-            return -1;
-        }
-        s->options.prediction_order_method = avctx->prediction_order_method;
-    }
-
-    if (avctx->min_partition_order >= 0) {
-        if (avctx->min_partition_order > MAX_PARTITION_ORDER) {
-            av_log(avctx, AV_LOG_ERROR, "invalid min partition order: %d\n",
-                   avctx->min_partition_order);
-            return -1;
-        }
-        s->options.min_partition_order = avctx->min_partition_order;
-    }
-    if (avctx->max_partition_order >= 0) {
-        if (avctx->max_partition_order > MAX_PARTITION_ORDER) {
-            av_log(avctx, AV_LOG_ERROR, "invalid max partition order: %d\n",
-                   avctx->max_partition_order);
-            return -1;
-        }
-        s->options.max_partition_order = avctx->max_partition_order;
-    }
-    if (s->options.max_partition_order < s->options.min_partition_order) {
-        av_log(avctx, AV_LOG_ERROR, "invalid partition orders: min=%d max=%d\n",
-               s->options.min_partition_order, s->options.max_partition_order);
-        return -1;
-    }
-#endif
-
     if (avctx->frame_size > 0) {
         if (avctx->frame_size < FLAC_MIN_BLOCKSIZE ||
                 avctx->frame_size > FLAC_MAX_BLOCKSIZE) {
@@ -403,18 +347,6 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
     }
     s->max_blocksize = s->avctx->frame_size;
 
-#if FF_API_FLAC_GLOBAL_OPTS
-    /* set LPC precision */
-    if (avctx->lpc_coeff_precision > 0) {
-        if (avctx->lpc_coeff_precision > MAX_LPC_PRECISION) {
-            av_log(avctx, AV_LOG_ERROR, "invalid lpc coeff precision: %d\n",
-                   avctx->lpc_coeff_precision);
-            return -1;
-        }
-        s->options.lpc_coeff_precision = avctx->lpc_coeff_precision;
-    }
-#endif
-
     /* set maximum encoded frame size in verbatim mode */
     s->max_framesize = ff_flac_get_max_frame_size(s->avctx->frame_size,
                                                   s->channels, 16);
@@ -980,7 +912,7 @@ static int encode_residual_ch(FlacEncodeContext *s, int ch)
 
 static int count_frame_header(FlacEncodeContext *s)
 {
-    uint8_t tmp;
+    uint8_t av_unused tmp;
     int count;
 
     /*
@@ -1330,22 +1262,22 @@ static av_cold int flac_encode_close(AVCodecContext *avctx)
 
 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
 static const AVOption options[] = {
-{ "lpc_coeff_precision", "LPC coefficient precision", offsetof(FlacEncodeContext, options.lpc_coeff_precision), FF_OPT_TYPE_INT, {.dbl = 15 }, 0, MAX_LPC_PRECISION, FLAGS },
-{ "lpc_type", "LPC algorithm", offsetof(FlacEncodeContext, options.lpc_type), FF_OPT_TYPE_INT, {.dbl = FF_LPC_TYPE_DEFAULT }, FF_LPC_TYPE_DEFAULT, FF_LPC_TYPE_NB-1, FLAGS, "lpc_type" },
-{ "none",     NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_NONE },     INT_MIN, INT_MAX, FLAGS, "lpc_type" },
-{ "fixed",    NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_FIXED },    INT_MIN, INT_MAX, FLAGS, "lpc_type" },
-{ "levinson", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_LEVINSON }, INT_MIN, INT_MAX, FLAGS, "lpc_type" },
-{ "cholesky", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_CHOLESKY }, INT_MIN, INT_MAX, FLAGS, "lpc_type" },
-{ "lpc_passes", "Number of passes to use for Cholesky factorization during LPC analysis", offsetof(FlacEncodeContext, options.lpc_passes),  FF_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, FLAGS },
-{ "min_partition_order",  NULL, offsetof(FlacEncodeContext, options.min_partition_order),  FF_OPT_TYPE_INT, {.dbl = -1 },      -1, MAX_PARTITION_ORDER, FLAGS },
-{ "max_partition_order",  NULL, offsetof(FlacEncodeContext, options.max_partition_order),  FF_OPT_TYPE_INT, {.dbl = -1 },      -1, MAX_PARTITION_ORDER, FLAGS },
-{ "prediction_order_method", "Search method for selecting prediction order", offsetof(FlacEncodeContext, options.prediction_order_method), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, ORDER_METHOD_LOG, FLAGS, "predm" },
-{ "estimation", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_EST },    INT_MIN, INT_MAX, FLAGS, "predm" },
-{ "2level",     NULL, 0, FF_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_2LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" },
-{ "4level",     NULL, 0, FF_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_4LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" },
-{ "8level",     NULL, 0, FF_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_8LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" },
-{ "search",     NULL, 0, FF_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_SEARCH }, INT_MIN, INT_MAX, FLAGS, "predm" },
-{ "log",        NULL, 0, FF_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_LOG },    INT_MIN, INT_MAX, FLAGS, "predm" },
+{ "lpc_coeff_precision", "LPC coefficient precision", offsetof(FlacEncodeContext, options.lpc_coeff_precision), AV_OPT_TYPE_INT, {.dbl = 15 }, 0, MAX_LPC_PRECISION, FLAGS },
+{ "lpc_type", "LPC algorithm", offsetof(FlacEncodeContext, options.lpc_type), AV_OPT_TYPE_INT, {.dbl = FF_LPC_TYPE_DEFAULT }, FF_LPC_TYPE_DEFAULT, FF_LPC_TYPE_NB-1, FLAGS, "lpc_type" },
+{ "none",     NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_NONE },     INT_MIN, INT_MAX, FLAGS, "lpc_type" },
+{ "fixed",    NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_FIXED },    INT_MIN, INT_MAX, FLAGS, "lpc_type" },
+{ "levinson", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_LEVINSON }, INT_MIN, INT_MAX, FLAGS, "lpc_type" },
+{ "cholesky", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_CHOLESKY }, INT_MIN, INT_MAX, FLAGS, "lpc_type" },
+{ "lpc_passes", "Number of passes to use for Cholesky factorization during LPC analysis", offsetof(FlacEncodeContext, options.lpc_passes),  AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, FLAGS },
+{ "min_partition_order",  NULL, offsetof(FlacEncodeContext, options.min_partition_order),  AV_OPT_TYPE_INT, {.dbl = -1 },      -1, MAX_PARTITION_ORDER, FLAGS },
+{ "max_partition_order",  NULL, offsetof(FlacEncodeContext, options.max_partition_order),  AV_OPT_TYPE_INT, {.dbl = -1 },      -1, MAX_PARTITION_ORDER, FLAGS },
+{ "prediction_order_method", "Search method for selecting prediction order", offsetof(FlacEncodeContext, options.prediction_order_method), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, ORDER_METHOD_LOG, FLAGS, "predm" },
+{ "estimation", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_EST },    INT_MIN, INT_MAX, FLAGS, "predm" },
+{ "2level",     NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_2LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" },
+{ "4level",     NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_4LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" },
+{ "8level",     NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_8LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" },
+{ "search",     NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_SEARCH }, INT_MIN, INT_MAX, FLAGS, "predm" },
+{ "log",        NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_LOG },    INT_MIN, INT_MAX, FLAGS, "predm" },
 { NULL },
 };
 
@@ -1357,14 +1289,13 @@ static const AVClass flac_encoder_class = {
 };
 
 AVCodec ff_flac_encoder = {
-    "flac",
-    AVMEDIA_TYPE_AUDIO,
-    CODEC_ID_FLAC,
-    sizeof(FlacEncodeContext),
-    flac_encode_init,
-    flac_encode_frame,
-    flac_encode_close,
-    NULL,
+    .name           = "flac",
+    .type           = AVMEDIA_TYPE_AUDIO,
+    .id             = CODEC_ID_FLAC,
+    .priv_data_size = sizeof(FlacEncodeContext),
+    .init           = flac_encode_init,
+    .encode         = flac_encode_frame,
+    .close          = flac_encode_close,
     .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY,
     .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
     .long_name = NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"),