]> git.sesse.net Git - ffmpeg/commitdiff
lavc: make rc_eq into private options of mpegvideo encoders
authorAnton Khirnov <anton@khirnov.net>
Sun, 27 Oct 2013 12:51:16 +0000 (13:51 +0100)
committerAnton Khirnov <anton@khirnov.net>
Sat, 18 Oct 2014 03:23:51 +0000 (05:23 +0200)
libavcodec/avcodec.h
libavcodec/mpegvideo.h
libavcodec/mpegvideo_enc.c
libavcodec/options.c
libavcodec/options_table.h
libavcodec/ratecontrol.c

index c025c5c3dcde6cfc4c103e768194e97e0057f7d4..bd1a0e53cb556c98f70d92fd77f7fbb4baf1f5e3 100644 (file)
@@ -2110,12 +2110,13 @@ typedef struct AVCodecContext {
     int rc_override_count;
     RcOverride *rc_override;
 
+#if FF_API_MPV_OPT
     /**
-     * rate control equation
-     * - encoding: Set by user
-     * - decoding: unused
+     * @deprecated use encoder private options instead
      */
+    attribute_deprecated
     const char *rc_eq;
+#endif
 
     /**
      * maximum bitrate
index e96671be14cea10edcfba438e5c08410aae6e5be..1b72960e4908308d5ee74bf4fea5ad1b7af1b38a 100644 (file)
@@ -638,6 +638,8 @@ typedef struct MpegEncContext {
     float rc_qmod_amp;
     int   rc_qmod_freq;
 
+    char *rc_eq;
+
     /* temp buffers for rate control */
     float *cplx_tab, *bits_tab;
 
@@ -686,7 +688,12 @@ typedef struct MpegEncContext {
 {"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)",                                                                          \
                                                                     FF_MPV_OFFSET(rc_qsquish), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, 0, 99, FF_MPV_OPT_FLAGS},                        \
 {"rc_qmod_amp", "experimental quantizer modulation",                FF_MPV_OFFSET(rc_qmod_amp), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, FF_MPV_OPT_FLAGS},           \
-{"rc_qmod_freq", "experimental quantizer modulation",               FF_MPV_OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS},
+{"rc_qmod_freq", "experimental quantizer modulation",               FF_MPV_OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS},             \
+{"rc_eq", "Set rate control equation. When computing the expression, besides the standard functions "                                                                           \
+          "defined in the section 'Expression Evaluation', the following functions are available: "                                                                             \
+          "bits2qp(bits), qp2bits(qp). Also the following constants are available: iTex pTex tex mv "                                                                           \
+          "fCode iCount mcVar var isI isP isB avgQP qComp avgIITex avgPITex avgPPTex avgBPTex avgTex.",                                                                         \
+                                                                    FF_MPV_OFFSET(rc_eq), AV_OPT_TYPE_STRING,                           .flags = FF_MPV_OPT_FLAGS },
 
 extern const AVOption ff_mpv_generic_options[];
 
index 952a34a8c31451b10772a3913b354f4405e4d8fb..2a2554586901ce078bea93cab5e07c3b69a02e1c 100644 (file)
@@ -830,6 +830,13 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         s->rc_qmod_amp = avctx->rc_qmod_amp;
     if (avctx->rc_qmod_freq)
         s->rc_qmod_freq = avctx->rc_qmod_freq;
+
+    if (avctx->rc_eq) {
+        av_freep(&s->rc_eq);
+        s->rc_eq = av_strdup(avctx->rc_eq);
+        if (!s->rc_eq)
+            return AVERROR(ENOMEM);
+    }
     FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
index 3acf3afdf095aebb20519431ad9ed0fbf61d8e94..c00dca078e59b1d52b4ae9ee5485e1c5dde22058 100644 (file)
@@ -27,6 +27,7 @@
 #include "avcodec.h"
 #include "internal.h"
 #include "libavutil/avassert.h"
+#include "libavutil/internal.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
 #include <float.h>              /* FLT_MIN, FLT_MAX */
@@ -174,17 +175,21 @@ int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
     dest->internal        = NULL;
 
     /* reallocate values that should be allocated separately */
-    dest->rc_eq           = NULL;
     dest->extradata       = NULL;
     dest->intra_matrix    = NULL;
     dest->inter_matrix    = NULL;
     dest->rc_override     = NULL;
     dest->subtitle_header = NULL;
+#if FF_API_MPV_OPT
+    FF_DISABLE_DEPRECATION_WARNINGS
+    dest->rc_eq           = NULL;
     if (src->rc_eq) {
         dest->rc_eq = av_strdup(src->rc_eq);
         if (!dest->rc_eq)
             return AVERROR(ENOMEM);
     }
+    FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
 #define alloc_and_copy_or_fail(obj, size, pad) \
     if (src->obj && size > 0) { \
@@ -211,7 +216,11 @@ fail:
     av_freep(&dest->intra_matrix);
     av_freep(&dest->inter_matrix);
     av_freep(&dest->extradata);
+#if FF_API_MPV_OPT
+    FF_DISABLE_DEPRECATION_WARNINGS
     av_freep(&dest->rc_eq);
+    FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     return AVERROR(ENOMEM);
 }
 
index ef89e7a8cd4d80630c5e3392e7a142bdaa47ea64..bf33f9ae8f574cbc8f4234a057aeae4b330b5fea 100644 (file)
@@ -169,11 +169,9 @@ static const AVOption avcodec_options[] = {
 {"rc_qmod_freq", "deprecated, use encoder private options instead", OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E},
 #endif
 {"rc_override_count", NULL, OFFSET(rc_override_count), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX},
-{"rc_eq", "Set rate control equation. When computing the expression, besides the standard functions "
-          "defined in the section 'Expression Evaluation', the following functions are available: "
-          "bits2qp(bits), qp2bits(qp). Also the following constants are available: iTex pTex tex mv "
-          "fCode iCount mcVar var isI isP isB avgQP qComp avgIITex avgPITex avgPPTex avgBPTex avgTex.",
-          OFFSET(rc_eq), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, V|E},
+#if FF_API_MPV_OPT
+{"rc_eq", "deprecated, use encoder private options instead", OFFSET(rc_eq), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, V|E},
+#endif
 {"maxrate", "Set maximum bitrate tolerance (in bits/s). Requires bufsize to be set.", OFFSET(rc_max_rate), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
 {"minrate", "Set minimum bitrate tolerance (in bits/s). Most useful in setting up a CBR encode. It is of little use otherwise.",
             OFFSET(rc_min_rate), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
index 92438b46f025070a4dc4d5c0963401ad230933d8..3aa3e27602a8183c4e0186457a031a74fd4c87d3 100644 (file)
@@ -126,11 +126,11 @@ av_cold int ff_rate_control_init(MpegEncContext *s)
     emms_c();
 
     res = av_expr_parse(&rcc->rc_eq_eval,
-                        s->avctx->rc_eq ? s->avctx->rc_eq : "tex^qComp",
+                        s->rc_eq ? s->rc_eq : "tex^qComp",
                         const_names, func1_names, func1,
                         NULL, NULL, 0, s->avctx);
     if (res < 0) {
-        av_log(s->avctx, AV_LOG_ERROR, "Error parsing rc_eq \"%s\"\n", s->avctx->rc_eq);
+        av_log(s->avctx, AV_LOG_ERROR, "Error parsing rc_eq \"%s\"\n", s->rc_eq);
         return res;
     }
 
@@ -382,7 +382,7 @@ static double get_qscale(MpegEncContext *s, RateControlEntry *rce,
 
     bits = av_expr_eval(rcc->rc_eq_eval, const_values, rce);
     if (isnan(bits)) {
-        av_log(s->avctx, AV_LOG_ERROR, "Error evaluating rc_eq \"%s\"\n", s->avctx->rc_eq);
+        av_log(s->avctx, AV_LOG_ERROR, "Error evaluating rc_eq \"%s\"\n", s->rc_eq);
         return -1;
     }