Skip to content

Commit 80026a8

Browse files
t-rapprichardpl
authored andcommitted
avfilter/f_metadata: rename "string" into "same_str"
Rename function option value "string" into "same_str". Remove obsolete "length" option. Signed-off-by: Tobias Rapp <[email protected]>
1 parent 730da5c commit 80026a8

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

doc/filters.texi

+2-7
Original file line numberDiff line numberDiff line change
@@ -8486,19 +8486,14 @@ Set key used with all modes. Must be set for all modes except @code{print}.
84868486
Set metadata value which will be used. This option is mandatory for
84878487
@code{modify} and @code{add} mode.
84888488

8489-
@item length
8490-
Set length of how many characters of two metadata values need to match to be
8491-
considered same. Default is all available characters.
8492-
84938489
@item function
84948490
Which function to use when comparing metadata value and @code{value}.
84958491

84968492
Can be one of following:
84978493

84988494
@table @samp
8499-
@item string
8500-
Values are interpreted as strings, returns true if @code{value} is same as metadata value up
8501-
to N chars as set in @code{length} option.
8495+
@item same_str
8496+
Values are interpreted as strings, returns true if metadata value is same as @code{value}.
85028497

85038498
@item starts_with
85048499
Values are interpreted as strings, returns true if metadata value starts with

libavfilter/f_metadata.c

+15-17
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ enum MetadataMode {
4848
};
4949

5050
enum MetadataFunction {
51-
METADATAF_STRING,
51+
METADATAF_SAME_STR,
5252
METADATAF_STARTS_WITH,
5353
METADATAF_LESS,
5454
METADATAF_EQUAL,
@@ -75,7 +75,6 @@ typedef struct MetadataContext {
7575
int mode;
7676
char *key;
7777
char *value;
78-
int length;
7978
int function;
8079

8180
char *expr_str;
@@ -86,7 +85,7 @@ typedef struct MetadataContext {
8685
char *file_str;
8786

8887
int (*compare)(struct MetadataContext *s,
89-
const char *value1, const char *value2, size_t length);
88+
const char *value1, const char *value2);
9089
void (*print)(AVFilterContext *ctx, const char *msg, ...) av_printf_format(2, 3);
9190
} MetadataContext;
9291

@@ -102,29 +101,28 @@ static const AVOption filt_name##_options[] = { \
102101
{ "key", "set metadata key", OFFSET(key), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, FLAGS }, \
103102
{ "value", "set metadata value", OFFSET(value), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, FLAGS }, \
104103
{ "function", "function for comparing values", OFFSET(function), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, METADATAF_NB-1, FLAGS, "function" }, \
105-
{ "string", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_STRING }, 0, 3, FLAGS, "function" }, \
104+
{ "same_str", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_SAME_STR }, 0, 3, FLAGS, "function" }, \
106105
{ "starts_with", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_STARTS_WITH }, 0, 0, FLAGS, "function" }, \
107106
{ "less", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_LESS }, 0, 3, FLAGS, "function" }, \
108107
{ "equal", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_EQUAL }, 0, 3, FLAGS, "function" }, \
109108
{ "greater", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_GREATER }, 0, 3, FLAGS, "function" }, \
110109
{ "expr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_EXPR }, 0, 3, FLAGS, "function" }, \
111110
{ "expr", "set expression for expr function", OFFSET(expr_str), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, FLAGS }, \
112-
{ "length", "compare up to N chars for string function", OFFSET(length), AV_OPT_TYPE_INT, {.i64 = INT_MAX }, 1, INT_MAX, FLAGS }, \
113111
{ "file", "set file where to print metadata information", OFFSET(file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, \
114112
{ NULL } \
115113
}
116114

117-
static int string(MetadataContext *s, const char *value1, const char *value2, size_t length)
115+
static int same_str(MetadataContext *s, const char *value1, const char *value2)
118116
{
119-
return !strncmp(value1, value2, length);
117+
return !strcmp(value1, value2);
120118
}
121119

122-
static int starts_with(MetadataContext *s, const char *value1, const char *value2, size_t length)
120+
static int starts_with(MetadataContext *s, const char *value1, const char *value2)
123121
{
124122
return !strncmp(value1, value2, strlen(value2));
125123
}
126124

127-
static int equal(MetadataContext *s, const char *value1, const char *value2, size_t length)
125+
static int equal(MetadataContext *s, const char *value1, const char *value2)
128126
{
129127
float f1, f2;
130128

@@ -134,7 +132,7 @@ static int equal(MetadataContext *s, const char *value1, const char *value2, siz
134132
return fabsf(f1 - f2) < FLT_EPSILON;
135133
}
136134

137-
static int less(MetadataContext *s, const char *value1, const char *value2, size_t length)
135+
static int less(MetadataContext *s, const char *value1, const char *value2)
138136
{
139137
float f1, f2;
140138

@@ -144,7 +142,7 @@ static int less(MetadataContext *s, const char *value1, const char *value2, size
144142
return (f1 - f2) < FLT_EPSILON;
145143
}
146144

147-
static int greater(MetadataContext *s, const char *value1, const char *value2, size_t length)
145+
static int greater(MetadataContext *s, const char *value1, const char *value2)
148146
{
149147
float f1, f2;
150148

@@ -154,7 +152,7 @@ static int greater(MetadataContext *s, const char *value1, const char *value2, s
154152
return (f2 - f1) < FLT_EPSILON;
155153
}
156154

157-
static int parse_expr(MetadataContext *s, const char *value1, const char *value2, size_t length)
155+
static int parse_expr(MetadataContext *s, const char *value1, const char *value2)
158156
{
159157
double f1, f2;
160158

@@ -205,8 +203,8 @@ static av_cold int init(AVFilterContext *ctx)
205203
}
206204

207205
switch (s->function) {
208-
case METADATAF_STRING:
209-
s->compare = string;
206+
case METADATAF_SAME_STR:
207+
s->compare = same_str;
210208
break;
211209
case METADATAF_STARTS_WITH:
212210
s->compare = starts_with;
@@ -289,7 +287,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
289287
if (!s->value && e && e->value) {
290288
return ff_filter_frame(outlink, frame);
291289
} else if (s->value && e && e->value &&
292-
s->compare(s, e->value, s->value, s->length)) {
290+
s->compare(s, e->value, s->value)) {
293291
return ff_filter_frame(outlink, frame);
294292
}
295293
break;
@@ -314,14 +312,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
314312
while ((e = av_dict_get(metadata, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL) {
315313
s->print(ctx, "%s=%s\n", e->key, e->value);
316314
}
317-
} else if (e && e->value && (!s->value || (e->value && s->compare(s, e->value, s->value, s->length)))) {
315+
} else if (e && e->value && (!s->value || (e->value && s->compare(s, e->value, s->value)))) {
318316
s->print(ctx, "frame %"PRId64" pts %"PRId64"\n", inlink->frame_count, frame->pts);
319317
s->print(ctx, "%s=%s\n", s->key, e->value);
320318
}
321319
return ff_filter_frame(outlink, frame);
322320
break;
323321
case METADATA_DELETE:
324-
if (e && e->value && s->value && s->compare(s, e->value, s->value, s->length)) {
322+
if (e && e->value && s->value && s->compare(s, e->value, s->value)) {
325323
av_dict_set(&metadata, s->key, NULL, 0);
326324
} else if (e && e->value) {
327325
av_dict_set(&metadata, s->key, NULL, 0);

0 commit comments

Comments
 (0)