From a6d1c9dd0fb912891abc1aa10d35f928188641d4 Mon Sep 17 00:00:00 2001 From: Claude Heiland-Allen Date: Wed, 11 Oct 2023 12:02:32 +0100 Subject: [PATCH] common/tags: add mp_tags_move_from_av_dictionary() Abstracts a common pattern, in which the av dictionary is cleared immediately after copying to mp tags, so that additional tags later in the stream get appended to empty tags, instead of being appended to existing tags that were already copied. --- common/tags.c | 7 +++++++ common/tags.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/common/tags.c b/common/tags.c index f7e85ace3d..43f557dd6c 100644 --- a/common/tags.c +++ b/common/tags.c @@ -142,3 +142,10 @@ void mp_tags_copy_from_av_dictionary(struct mp_tags *tags, while ((entry = av_dict_get(av_dict, "", entry, AV_DICT_IGNORE_SUFFIX))) mp_tags_set_str(tags, entry->key, entry->value); } + +void mp_tags_move_from_av_dictionary(struct mp_tags *tags, + struct AVDictionary **av_dict_ptr) +{ + mp_tags_copy_from_av_dictionary(tags, *av_dict_ptr); + av_dict_free(av_dict_ptr); +} diff --git a/common/tags.h b/common/tags.h index beb8388df1..e7eb4b32a2 100644 --- a/common/tags.h +++ b/common/tags.h @@ -25,5 +25,7 @@ void mp_tags_merge(struct mp_tags *tags, struct mp_tags *src); struct AVDictionary; void mp_tags_copy_from_av_dictionary(struct mp_tags *tags, struct AVDictionary *av_dict); +void mp_tags_move_from_av_dictionary(struct mp_tags *tags, + struct AVDictionary **av_dict_ptr); #endif