[FFmpeg-cvslog] lavfi/perms: add seed option.

Clément Bœsch git at videolan.org
Tue Mar 26 02:49:48 CET 2013


ffmpeg | branch: master | Clément Bœsch <ubitux at gmail.com> | Tue Mar 26 02:39:55 2013 +0100| [9371467d9d434356ebd2d8b4209ed487147056d9] | committer: Clément Bœsch

lavfi/perms: add seed option.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9371467d9d434356ebd2d8b4209ed487147056d9
---

 doc/filters.texi      |    6 ++++++
 libavfilter/f_perms.c |   14 +++++++++++---
 libavfilter/version.h |    2 +-
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 02f0a29..4190cca 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -6249,6 +6249,12 @@ Make the frame read-only if writable, and writable if read-only.
 @item random
 Set each output frame read-only or writable randomly.
 @end table
+
+ at item seed
+Set the seed for the @var{random} mode, must be an integer included between
+ at code{0} and @code{UINT32_MAX}. If not specified, or if explicitly set to
+ at code{-1}, the filter will try to use a good random seed on a best effort
+basis.
 @end table
 
 Note: in case of auto-inserted filter between the permission filter and the
diff --git a/libavfilter/f_perms.c b/libavfilter/f_perms.c
index e3f974c..2c3d62c 100644
--- a/libavfilter/f_perms.c
+++ b/libavfilter/f_perms.c
@@ -34,6 +34,7 @@ enum mode {
 typedef struct {
     const AVClass *class;
     AVLFG lfg;
+    int64_t random_seed;
     enum mode mode;
 } PermsContext;
 
@@ -47,6 +48,7 @@ static const AVOption options[] = {
         { "rw",     "set all output frames writable",   0, AV_OPT_TYPE_CONST, {.i64 = MODE_RW},         INT_MIN, INT_MAX, FLAGS, "mode" },
         { "toggle", "switch permissions",               0, AV_OPT_TYPE_CONST, {.i64 = MODE_TOGGLE},     INT_MIN, INT_MAX, FLAGS, "mode" },
         { "random", "set permissions randomly",         0, AV_OPT_TYPE_CONST, {.i64 = MODE_RANDOM},     INT_MIN, INT_MAX, FLAGS, "mode" },
+    { "seed", "set the seed for the random mode", OFFSET(random_seed), AV_OPT_TYPE_INT64, {.i64 = -1}, -1, UINT32_MAX, FLAGS },
     { NULL }
 };
 
@@ -54,9 +56,15 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     PermsContext *perms = ctx->priv;
 
-    // TODO: add a seed option
-    if (perms->mode == MODE_RANDOM)
-        av_lfg_init(&perms->lfg, av_get_random_seed());
+    if (perms->mode == MODE_RANDOM) {
+        uint32_t seed;
+
+        if (perms->random_seed == -1)
+            perms->random_seed = av_get_random_seed();
+        seed = perms->random_seed;
+        av_log(ctx, AV_LOG_INFO, "random seed: 0x%08x\n", seed);
+        av_lfg_init(&perms->lfg, seed);
+    }
 
     return 0;
 }
diff --git a/libavfilter/version.h b/libavfilter/version.h
index ce6d874..e623896 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
 
 #define LIBAVFILTER_VERSION_MAJOR  3
 #define LIBAVFILTER_VERSION_MINOR  48
-#define LIBAVFILTER_VERSION_MICRO 104
+#define LIBAVFILTER_VERSION_MICRO 105
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
                                                LIBAVFILTER_VERSION_MINOR, \



More information about the ffmpeg-cvslog mailing list