]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/f_metadata.c
avfilter: Constify all AVFilters
[ffmpeg] / libavfilter / f_metadata.c
index 2ed1393cbaa9ac1217cf686c5428dd743213d35d..5fec7c3c56606fe89e48b72ce4b6bd60f909f1fb 100644 (file)
@@ -88,6 +88,8 @@ typedef struct MetadataContext {
     int (*compare)(struct MetadataContext *s,
                    const char *value1, const char *value2);
     void (*print)(AVFilterContext *ctx, const char *msg, ...) av_printf_format(2, 3);
+
+    int direct;    // reduces buffering when printing to user-supplied URL
 } MetadataContext;
 
 #define OFFSET(x) offsetof(MetadataContext, x)
@@ -111,6 +113,7 @@ static const AVOption filt_name##_options[] = { \
     {   "ends_with",   NULL, 0, AV_OPT_TYPE_CONST, {.i64 = METADATAF_ENDS_WITH },   0, 0, FLAGS, "function" }, \
     { "expr", "set expression for expr function", OFFSET(expr_str), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, FLAGS }, \
     { "file", "set file where to print metadata information", OFFSET(file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, \
+    { "direct", "reduce buffering when printing to user-set file or pipe", OFFSET(direct), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, \
     { NULL } \
 }
 
@@ -274,6 +277,9 @@ static av_cold int init(AVFilterContext *ctx)
                    s->file_str, buf);
             return ret;
         }
+
+        if (s->direct)
+            s->avio_context->direct = AVIO_FLAG_DIRECT;
     }
 
     return 0;
@@ -298,7 +304,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
     AVDictionary **metadata = &frame->metadata;
     AVDictionaryEntry *e;
 
-    if (!*metadata)
+    if (!*metadata && s->mode != METADATA_ADD)
         return ff_filter_frame(outlink, frame);
 
     e = av_dict_get(*metadata, !s->key ? "" : s->key, NULL,
@@ -320,13 +326,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
             av_dict_set(metadata, s->key, s->value, 0);
         }
         return ff_filter_frame(outlink, frame);
-        break;
     case METADATA_MODIFY:
         if (e && e->value) {
             av_dict_set(metadata, s->key, s->value, 0);
         }
         return ff_filter_frame(outlink, frame);
-        break;
     case METADATA_PRINT:
         if (!s->key && e) {
             s->print(ctx, "frame:%-4"PRId64" pts:%-7s pts_time:%s\n",
@@ -341,7 +345,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
             s->print(ctx, "%s=%s\n", s->key, e->value);
         }
         return ff_filter_frame(outlink, frame);
-        break;
     case METADATA_DELETE:
         if (!s->key) {
             av_dict_free(metadata);
@@ -349,7 +352,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
             av_dict_set(metadata, s->key, NULL, 0);
         }
         return ff_filter_frame(outlink, frame);
-        break;
     default:
         av_assert0(0);
     };
@@ -381,7 +383,7 @@ static const AVFilterPad aoutputs[] = {
     { NULL }
 };
 
-AVFilter ff_af_ametadata = {
+const AVFilter ff_af_ametadata = {
     .name          = "ametadata",
     .description   = NULL_IF_CONFIG_SMALL("Manipulate audio frame metadata."),
     .priv_size     = sizeof(MetadataContext),
@@ -416,7 +418,7 @@ static const AVFilterPad outputs[] = {
     { NULL }
 };
 
-AVFilter ff_vf_metadata = {
+const AVFilter ff_vf_metadata = {
     .name        = "metadata",
     .description = NULL_IF_CONFIG_SMALL("Manipulate video frame metadata."),
     .priv_size   = sizeof(MetadataContext),