---
 libavcodec/avcodec.h |   29 ++++++++++----
 libavcodec/flacenc.c |  104 +++++++++++++++++++++++++++++++++++++++++++------
 libavcodec/options.c |   18 +++++---
 libavcodec/version.h |    3 +
 4 files changed, 126 insertions(+), 28 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index f1402d0..c625448 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2545,43 +2545,54 @@ typedef struct AVCodecContext {
     int use_lpc;
 #endif
 
+#if FF_API_FLAC_GLOBAL_OPTS
+    /**
+     * @defgroup flac_opts FLAC options
+     * @deprecated Use FLAC encoder private options instead.
+     * @}
+     */
+
     /**
      * LPC coefficient precision - used by FLAC encoder
      * - encoding: Set by user.
      * - decoding: unused
      */
-    int lpc_coeff_precision;
+    attribute_deprecated int lpc_coeff_precision;
 
     /**
      * - encoding: Set by user.
      * - decoding: unused
      */
-    int min_prediction_order;
+    attribute_deprecated int min_prediction_order;
 
     /**
      * - encoding: Set by user.
      * - decoding: unused
      */
-    int max_prediction_order;
+    attribute_deprecated int max_prediction_order;
 
     /**
      * search method for selecting prediction order
      * - encoding: Set by user.
      * - decoding: unused
      */
-    int prediction_order_method;
+    attribute_deprecated int prediction_order_method;
 
     /**
      * - encoding: Set by user.
      * - decoding: unused
      */
-    int min_partition_order;
+    attribute_deprecated int min_partition_order;
 
     /**
      * - encoding: Set by user.
      * - decoding: unused
      */
-    int max_partition_order;
+    attribute_deprecated int max_partition_order;
+    /**
+     * @}
+     */
+#endif
 
     /**
      * GOP timecode frame start number, in non drop frame format
@@ -2801,19 +2812,21 @@ typedef struct AVCodecContext {
 
     int log_level_offset;
 
+#if FF_API_FLAC_GLOBAL_OPTS
     /**
      * Determines which LPC analysis algorithm to use.
      * - encoding: Set by user
      * - decoding: unused
      */
-    enum AVLPCType lpc_type;
+    attribute_deprecated enum AVLPCType lpc_type;
 
     /**
      * Number of passes to use for Cholesky factorization during LPC analysis
      * - encoding: Set by user
      * - decoding: unused
      */
-    int lpc_passes;
+    attribute_deprecated int lpc_passes;
+#endif
 
     /**
      * Number of slices.
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index d93bfb5..458e4b8 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -21,6 +21,7 @@
 
 #include "libavutil/crc.h"
 #include "libavutil/md5.h"
+#include "libavutil/opt.h"
 #include "avcodec.h"
 #include "get_bits.h"
 #include "golomb.h"
@@ -80,6 +81,7 @@ typedef struct FlacFrame {
 } FlacFrame;
 
 typedef struct FlacEncodeContext {
+    AVClass *class;
     PutBitContext pb;
     int channels;
     int samplerate;
@@ -266,23 +268,59 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
 
     s->options.block_time_ms = ((int[]){ 27, 27, 
27,105,105,105,105,105,105,105,105,105,105})[level];
 
-    s->options.lpc_type      = ((int[]){ AV_LPC_TYPE_FIXED,    
AV_LPC_TYPE_FIXED,    AV_LPC_TYPE_FIXED,
+    if (s->options.lpc_type == AV_LPC_TYPE_DEFAULT)
+        s->options.lpc_type  = ((int[]){ AV_LPC_TYPE_FIXED,    
AV_LPC_TYPE_FIXED,    AV_LPC_TYPE_FIXED,
                                          AV_LPC_TYPE_LEVINSON, 
AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON,
                                          AV_LPC_TYPE_LEVINSON, 
AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON,
                                          AV_LPC_TYPE_LEVINSON, 
AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON,
                                          AV_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 > s->options.max_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);
+        return AVERROR(EINVAL);
+    }
+    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];
+    switch (s->options.lpc_type) {
+    case AV_LPC_TYPE_NONE:
+        s->options.max_prediction_order = 0;
+        s->options.min_prediction_order = 0;
+        break;
+    case AV_LPC_TYPE_FIXED:
+        if (s->options.max_prediction_order > MAX_FIXED_ORDER) {
+            av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d > 
%d\n",
+                   s->options.max_prediction_order, MAX_FIXED_ORDER);
+            return AVERROR(EINVAL);
+        }
+        break;
+    default:
+        if (s->options.min_prediction_order < MIN_LPC_ORDER ||
+            s->options.max_prediction_order > MAX_LPC_ORDER) {
+            av_log(avctx, AV_LOG_ERROR, "prediction orders outside of allowed 
%d - %d\n"
+                   MIN_LPC_ORDER, MAX_LPC_ORDER);
+            return AVERROR(EINVAL);
+        }
+    }
 
-    s->options.prediction_order_method = ((int[]){ ORDER_METHOD_EST,    
ORDER_METHOD_EST,    ORDER_METHOD_EST,
-                                                   ORDER_METHOD_EST,    
ORDER_METHOD_EST,    ORDER_METHOD_EST,
-                                                   ORDER_METHOD_4LEVEL, 
ORDER_METHOD_LOG,    ORDER_METHOD_4LEVEL,
-                                                   ORDER_METHOD_LOG,    
ORDER_METHOD_SEARCH, ORDER_METHOD_LOG,
-                                                   
ORDER_METHOD_SEARCH})[level];
+    if (s->options.prediction_order_method < 0)
+        s->options.prediction_order_method = ((int[]){ ORDER_METHOD_EST,    
ORDER_METHOD_EST,    ORDER_METHOD_EST,
+                                                       ORDER_METHOD_EST,    
ORDER_METHOD_EST,    ORDER_METHOD_EST,
+                                                       ORDER_METHOD_4LEVEL, 
ORDER_METHOD_LOG,    ORDER_METHOD_4LEVEL,
+                                                       ORDER_METHOD_LOG,    
ORDER_METHOD_SEARCH, ORDER_METHOD_LOG,
+                                                       
ORDER_METHOD_SEARCH})[level];
 
-    s->options.min_partition_order = ((int[]){  2,  2,  0,  0,  0,  0,  0,  0, 
 0,  0,  0,  0,  0})[level];
-    s->options.max_partition_order = ((int[]){  2,  2,  3,  3,  3,  8,  8,  8, 
 8,  8,  8,  8,  8})[level];
+    if (s->options.min_partition_order > s->option.max_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 AVERROR(EINVAL);
+    }
+    if (s->option.min_partition_order < 0)
+        s->options.min_partition_order = ((int[]){  2,  2,  0,  0,  0,  0,  0, 
 0,  0,  0,  0,  0,  0})[level];
+    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_USE_LPC
@@ -296,6 +334,7 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
         s->options.lpc_passes = avctx->use_lpc - 1;
     }
 #endif
+#if FF_API_FLAC_GLOBAL_OPTS
     if (avctx->lpc_type > AV_LPC_TYPE_DEFAULT) {
         if (avctx->lpc_type > AV_LPC_TYPE_CHOLESKY) {
             av_log(avctx, AV_LOG_ERROR, "unknown lpc type: %d\n", 
avctx->lpc_type);
@@ -386,6 +425,7 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
                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 ||
@@ -399,6 +439,7 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
     }
     s->max_blocksize = s->avctx->frame_size;
 
+#if FF_API_GLOBAL_LPC
     /* set LPC precision */
     if (avctx->lpc_coeff_precision > 0) {
         if (avctx->lpc_coeff_precision > MAX_LPC_PRECISION) {
@@ -407,10 +448,8 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
             return -1;
         }
         s->options.lpc_coeff_precision = avctx->lpc_coeff_precision;
-    } else {
-        /* default LPC precision */
-        s->options.lpc_coeff_precision = 15;
     }
+#endif
 
     /* set maximum encoded frame size in verbatim mode */
     s->max_framesize = ff_flac_get_max_frame_size(s->avctx->frame_size,
@@ -1325,6 +1364,44 @@ static av_cold int flac_encode_close(AVCodecContext 
*avctx)
     return 0;
 }
 
+#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, 15, 0, MAX_LPC_PRECISION, FLAGS },
+    { "lpc_type", "LPC algorithm", offsetof(FlacEncodeContext, 
options.lpc_type),
+      FF_OPT_TYPE_INT, AV_LPC_TYPE_DEFAULT, AV_LPC_TYPE_DEFAULT, 
AV_LPC_TYPE_NB-1, FLAGS },
+    { "none",     NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_NONE,     INT_MIN, 
INT_MAX, FLAGS, "lpc_type" },
+    { "fixed",    NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_FIXED,    INT_MIN, 
INT_MAX, FLAGS, "lpc_type" },
+    { "levinson", NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_LEVINSON, INT_MIN, 
INT_MAX, FLAGS, "lpc_type" },
+    { "cholesky", NULL, 0, FF_OPT_TYPE_CONST, AV_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, -1, 
INT_MIN, INT_MAX, FLAGS },
+    { "min_partition_order", NULL, offsetof(FlacEncodeContext, 
options.min_partition_order),
+      FF_OPT_TYPE_INT, -1, -1, MAX_PARTITION_ORDER, FLAGS },
+    { "max_partition_order", NULL, offsetof(FlacEncodeContext, 
options.max_partition_order),
+      FF_OPT_TYPE_INT, -1, -1, MAX_PARTITION_ORDER, FLAGS },
+    { "min_prediction_order", NULL, offsetof(FlacEncodeContext, 
options.min_prediction_order),
+      FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, FLAGS },
+    { "max_prediction_order", NULL, offsetof(FlacEncodeContext, 
options.max_prediction_order),
+      FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, FLAGS },
+    { "prediction_order_method", "Search method for selecting prediction 
order",
+      offsetof(FlacEncodeContext, options.prediction_order_method), 
FF_OPT_TYPE_INT,
+      -1, -1, ORDER_METHOD_LOG, FLAGS, "predm" },
+    { "estimation", NULL, 0, FF_OPT_TYPE_CONST, ORDER_METHOD_EST,    INT_MIN, 
INT_MAX, FLAGS, "predm" },
+    { "2level",     NULL, 0, FF_OPT_TYPE_CONST, ORDER_METHOD_2LEVEL, INT_MIN, 
INT_MAX, FLAGS, "predm" },
+    { "4level",     NULL, 0, FF_OPT_TYPE_CONST, ORDER_METHOD_4LEVEL, INT_MIN, 
INT_MAX, FLAGS, "predm" },
+    { "8level",     NULL, 0, FF_OPT_TYPE_CONST, ORDER_METHOD_8LEVEL, INT_MIN, 
INT_MAX, FLAGS, "predm" },
+    { "search",     NULL, 0, FF_OPT_TYPE_CONST, ORDER_METHOD_SEARCH, INT_MIN, 
INT_MAX, FLAGS, "predm" },
+    { "log",        NULL, 0, FF_OPT_TYPE_CONST, ORDER_METHOD_LOG,    INT_MIN, 
INT_MAX, FLAGS, "predm" },
+    { NULL },
+};
+
+static const AVClass flac_encoder_class = {
+    "FLAC encoder",
+    av_default_item_name,
+    options,
+    LIBAVUTIL_VERSION_INT,
+};
 
 AVCodec ff_flac_encoder = {
     "flac",
@@ -1338,4 +1415,5 @@ AVCodec ff_flac_encoder = {
     .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)"),
+    .priv_class= &flac_encoder_class,
 };
diff --git a/libavcodec/options.c b/libavcodec/options.c
index dc6c032..aeae7a1 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -401,12 +401,14 @@ static const AVOption options[]={
 #if FF_API_USE_LPC
 {"use_lpc", "sets whether to use LPC mode (FLAC)", OFFSET(use_lpc), 
FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
 #endif
+#if FF_API_FLAC_GLOBAL_OPTS
 {"lpc_coeff_precision", "LPC coefficient precision (FLAC)", 
OFFSET(lpc_coeff_precision), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|E},
-{"min_prediction_order", NULL, OFFSET(min_prediction_order), FF_OPT_TYPE_INT, 
-1, INT_MIN, INT_MAX, A|E},
-{"max_prediction_order", NULL, OFFSET(max_prediction_order), FF_OPT_TYPE_INT, 
-1, INT_MIN, INT_MAX, A|E},
-{"prediction_order_method", "search method for selecting prediction order", 
OFFSET(prediction_order_method), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
-{"min_partition_order", NULL, OFFSET(min_partition_order), FF_OPT_TYPE_INT, 
-1, INT_MIN, INT_MAX, A|E},
-{"max_partition_order", NULL, OFFSET(max_partition_order), FF_OPT_TYPE_INT, 
-1, INT_MIN, INT_MAX, A|E},
+{"min_prediction_order", "deprecated, use flac-specific options", 
OFFSET(min_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"max_prediction_order", "deprecated, use flac-specific options", 
OFFSET(max_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"prediction_order_method", "deprecated, use flac-specific options", 
OFFSET(prediction_order_method), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"min_partition_order", "deprecated, use flac-specific options", 
OFFSET(min_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"max_partition_order", "deprecated, use flac-specific options", 
OFFSET(max_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+#endif
 {"timecode_frame_start", "GOP timecode frame start number, in non drop frame 
format", OFFSET(timecode_frame_start), FF_OPT_TYPE_INT64, 0, 0, INT64_MAX, V|E},
 {"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, 
CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"},
 {"non_linear_q", "use non linear quantizer", 0, FF_OPT_TYPE_CONST, 
CODEC_FLAG2_NON_LINEAR_QUANT, INT_MIN, INT_MAX, V|E, "flags2"},
@@ -439,12 +441,14 @@ static const AVOption options[]={
 {"crf_max", "deprecated, use x264-specific options", OFFSET(crf_max), 
FF_OPT_TYPE_FLOAT, -1.0, -1.0, 51, V|E},
 #endif
 {"log_level_offset", "set the log level offset", OFFSET(log_level_offset), 
FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX },
-{"lpc_type", "specify LPC algorithm", OFFSET(lpc_type), FF_OPT_TYPE_INT, 
AV_LPC_TYPE_DEFAULT, AV_LPC_TYPE_DEFAULT, AV_LPC_TYPE_NB-1, A|E},
+#if FF_API_FLAC_GLOBAL_OPTS
+{"lpc_type", "deprecated, use flac-specific options", OFFSET(lpc_type), 
FF_OPT_TYPE_INT, AV_LPC_TYPE_DEFAULT, AV_LPC_TYPE_DEFAULT, AV_LPC_TYPE_NB-1, 
A|E},
 {"none",     NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_NONE,     INT_MIN, 
INT_MAX, A|E, "lpc_type"},
 {"fixed",    NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_FIXED,    INT_MIN, 
INT_MAX, A|E, "lpc_type"},
 {"levinson", NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_LEVINSON, INT_MIN, 
INT_MAX, A|E, "lpc_type"},
 {"cholesky", NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_CHOLESKY, INT_MIN, 
INT_MAX, A|E, "lpc_type"},
-{"lpc_passes", "number of passes to use for Cholesky factorization during LPC 
analysis", OFFSET(lpc_passes), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+{"lpc_passes", "deprecated, use flac-specific options", OFFSET(lpc_passes), 
FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
+#endif
 {"slices", "number of slices, used in parallelized decoding", OFFSET(slices), 
FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|E},
 {"thread_type", "select multithreading type", OFFSET(thread_type), 
FF_OPT_TYPE_INT, FF_THREAD_SLICE|FF_THREAD_FRAME, 0, INT_MAX, V|E|D, 
"thread_type"},
 {"slice", NULL, 0, FF_OPT_TYPE_CONST, FF_THREAD_SLICE, INT_MIN, INT_MAX, 
V|E|D, "thread_type"},
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 61935be..3806468 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -86,5 +86,8 @@
 #ifndef FF_API_X264_GLOBAL_OPTS
 #define FF_API_X264_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54)
 #endif
+#ifndef FF_API_FLAC_GLOBAL_OPTS
+#define FF_API_FLAC_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54)
+#endif
 
 #endif /* AVCODEC_VERSION_H */
-- 
1.7.4.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to