Extend syntax, allow to easily add more options later.
Stefano Sabatini authored on 2011/10/26 07:18:16... | ... |
@@ -30,7 +30,7 @@ |
30 | 30 |
|
31 | 31 |
#define LIBAVFILTER_VERSION_MAJOR 2 |
32 | 32 |
#define LIBAVFILTER_VERSION_MINOR 45 |
33 |
-#define LIBAVFILTER_VERSION_MICRO 1 |
|
33 |
+#define LIBAVFILTER_VERSION_MICRO 2 |
|
34 | 34 |
|
35 | 35 |
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ |
36 | 36 |
LIBAVFILTER_VERSION_MINOR, \ |
... | ... |
@@ -28,6 +28,7 @@ |
28 | 28 |
#include "avfilter.h" |
29 | 29 |
#include "libavutil/eval.h" |
30 | 30 |
#include "libavutil/avstring.h" |
31 |
+#include "libavutil/opt.h" |
|
31 | 32 |
#include "libavutil/pixdesc.h" |
32 | 33 |
#include "libavutil/imgutils.h" |
33 | 34 |
#include "libavutil/mathematics.h" |
... | ... |
@@ -53,6 +54,7 @@ enum var_name { |
53 | 53 |
#define OVERLAY 1 |
54 | 54 |
|
55 | 55 |
typedef struct { |
56 |
+ const AVClass *class; |
|
56 | 57 |
int x, y; ///< position of overlayed picture |
57 | 58 |
|
58 | 59 |
AVFilterBufferRef *overpicref; |
... | ... |
@@ -60,26 +62,66 @@ typedef struct { |
60 | 60 |
int max_plane_step[4]; ///< steps per pixel for each plane |
61 | 61 |
int hsub, vsub; ///< chroma subsampling values |
62 | 62 |
|
63 |
- char x_expr[256], y_expr[256]; |
|
63 |
+ char *x_expr, *y_expr; |
|
64 | 64 |
} OverlayContext; |
65 | 65 |
|
66 |
+#define OFFSET(x) offsetof(OverlayContext, x) |
|
67 |
+ |
|
68 |
+static const AVOption overlay_options[] = { |
|
69 |
+ { "x", "set the x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX }, |
|
70 |
+ { "y", "set the y expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX }, |
|
71 |
+ {NULL}, |
|
72 |
+}; |
|
73 |
+ |
|
74 |
+static const char *overlay_get_name(void *ctx) |
|
75 |
+{ |
|
76 |
+ return "overlay"; |
|
77 |
+} |
|
78 |
+ |
|
79 |
+static const AVClass overlay_class = { |
|
80 |
+ "OverlayContext", |
|
81 |
+ overlay_get_name, |
|
82 |
+ overlay_options |
|
83 |
+}; |
|
84 |
+ |
|
66 | 85 |
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) |
67 | 86 |
{ |
68 | 87 |
OverlayContext *over = ctx->priv; |
88 |
+ char *args1 = av_strdup(args); |
|
89 |
+ char *expr, *bufptr = NULL; |
|
90 |
+ int ret = 0; |
|
69 | 91 |
|
70 |
- av_strlcpy(over->x_expr, "0", sizeof(over->x_expr)); |
|
71 |
- av_strlcpy(over->y_expr, "0", sizeof(over->y_expr)); |
|
92 |
+ over->class = &overlay_class; |
|
93 |
+ av_opt_set_defaults(over); |
|
72 | 94 |
|
73 |
- if (args) |
|
74 |
- sscanf(args, "%255[^:]:%255[^:]", over->x_expr, over->y_expr); |
|
95 |
+ if (expr = av_strtok(args1, ":", &bufptr)) { |
|
96 |
+ if (!(over->x_expr = av_strdup(expr))) { |
|
97 |
+ ret = AVERROR(ENOMEM); |
|
98 |
+ goto end; |
|
99 |
+ } |
|
100 |
+ } |
|
101 |
+ if (expr = av_strtok(NULL, ":", &bufptr)) { |
|
102 |
+ if (!(over->y_expr = av_strdup(expr))) { |
|
103 |
+ ret = AVERROR(ENOMEM); |
|
104 |
+ goto end; |
|
105 |
+ } |
|
106 |
+ } |
|
75 | 107 |
|
76 |
- return 0; |
|
108 |
+ if (bufptr && (ret = av_set_options_string(over, bufptr, "=", ":")) < 0) |
|
109 |
+ goto end; |
|
110 |
+ |
|
111 |
+end: |
|
112 |
+ av_free(args1); |
|
113 |
+ return ret; |
|
77 | 114 |
} |
78 | 115 |
|
79 | 116 |
static av_cold void uninit(AVFilterContext *ctx) |
80 | 117 |
{ |
81 | 118 |
OverlayContext *over = ctx->priv; |
82 | 119 |
|
120 |
+ av_freep(&over->x_expr); |
|
121 |
+ av_freep(&over->y_expr); |
|
122 |
+ |
|
83 | 123 |
if (over->overpicref) |
84 | 124 |
avfilter_unref_buffer(over->overpicref); |
85 | 125 |
} |