From 4e0e24c3c27362939d9f88d3e22267afef5f6d4f Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 11 Sep 2015 23:04:02 +0200 Subject: af_lavfi: implement af-metadata property Works like vf-metadata. Unfortunately requires some code duplication (even though it's not much). Fixes #2311. --- audio/filter/af.c | 12 ++++++++++++ audio/filter/af.h | 2 ++ audio/filter/af_lavfi.c | 23 +++++++++++++++++++++++ 3 files changed, 37 insertions(+) (limited to 'audio') diff --git a/audio/filter/af.c b/audio/filter/af.c index ba08c1ed9b..3f73ad9c58 100644 --- a/audio/filter/af.c +++ b/audio/filter/af.c @@ -695,6 +695,18 @@ void af_control_all(struct af_stream *s, int cmd, void *arg) af->control(af, cmd, arg); } +int af_control_by_label(struct af_stream *s, int cmd, void *arg, bstr label) +{ + char *label_str = bstrdup0(NULL, label); + struct af_instance *cur = af_find_by_label(s, label_str); + talloc_free(label_str); + if (cur) { + return cur->control ? cur->control(cur, cmd, arg) : CONTROL_NA; + } else { + return CONTROL_UNKNOWN; + } +} + // Used by filters to add a filtered frame to the output queue. // Ownership of frame is transferred from caller to the filter chain. void af_add_output_frame(struct af_instance *af, struct mp_audio *frame) diff --git a/audio/filter/af.h b/audio/filter/af.h index 944ac54427..199486509c 100644 --- a/audio/filter/af.h +++ b/audio/filter/af.h @@ -127,6 +127,7 @@ enum af_control { AF_CONTROL_GET_PAN_BALANCE, AF_CONTROL_SET_PLAYBACK_SPEED, AF_CONTROL_SET_PLAYBACK_SPEED_RESAMPLE, + AF_CONTROL_GET_METADATA, }; // Argument for AF_CONTROL_SET_PAN_LEVEL @@ -145,6 +146,7 @@ int af_remove_by_label(struct af_stream *s, char *label); struct af_instance *af_find_by_label(struct af_stream *s, char *label); struct af_instance *af_control_any_rev(struct af_stream *s, int cmd, void *arg); void af_control_all(struct af_stream *s, int cmd, void *arg); +int af_control_by_label(struct af_stream *s, int cmd, void *arg, bstr label); void af_seek_reset(struct af_stream *s); void af_add_output_frame(struct af_instance *af, struct mp_audio *frame); diff --git a/audio/filter/af_lavfi.c b/audio/filter/af_lavfi.c index 249a560fb6..a40904aa78 100644 --- a/audio/filter/af_lavfi.c +++ b/audio/filter/af_lavfi.c @@ -34,11 +34,14 @@ #include #include +#include "config.h" + #include "audio/format.h" #include "audio/fmt-conversion.h" #include "af.h" #include "common/av_common.h" +#include "common/tags.h" #include "options/m_option.h" @@ -63,6 +66,8 @@ struct priv { bool eof; + struct mp_tags *metadata; + // options char *cfg_graph; char **cfg_avopts; @@ -213,6 +218,12 @@ static int control(struct af_instance *af, int cmd, void *arg) return mp_audio_config_equals(in, &orig_in) ? AF_OK : AF_FALSE; } + case AF_CONTROL_GET_METADATA: + if (p->metadata) { + *(struct mp_tags *)arg = *p->metadata; + return CONTROL_OK; + } + return CONTROL_NA; case AF_CONTROL_RESET: reset(af); return AF_OK; @@ -220,6 +231,17 @@ static int control(struct af_instance *af, int cmd, void *arg) return AF_UNKNOWN; } +static void get_metadata_from_av_frame(struct af_instance *af, AVFrame *frame) +{ +#if HAVE_AVFRAME_METADATA + struct priv *p = af->priv; + if (!p->metadata) + p->metadata = talloc_zero(p, struct mp_tags); + + mp_tags_copy_from_av_dictionary(p->metadata, av_frame_get_metadata(frame)); +#endif +} + static int filter_frame(struct af_instance *af, struct mp_audio *data) { struct priv *p = af->priv; @@ -307,6 +329,7 @@ static int filter_out(struct af_instance *af) af->delay = in_time - out_time; } + get_metadata_from_av_frame(af, frame); af_add_output_frame(af, out); av_frame_free(&frame); return 0; -- cgit v1.2.3