summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorKevin Mitchell <kevmitch@gmail.com>2017-12-23 19:14:16 -0700
committerKevin Mitchell <kevmitch@gmail.com>2017-12-26 03:33:18 -0700
commite2f71f509fde010e4d0f175014fd4219b7dc7681 (patch)
treee424fe1f86c79f5288b50b72996c4603756419e0 /common
parente530783cdbdd95500aa86cfbcbfe005f6e0f5f41 (diff)
downloadmpv-e2f71f509fde010e4d0f175014fd4219b7dc7681.tar.bz2
mpv-e2f71f509fde010e4d0f175014fd4219b7dc7681.tar.xz
tags: add mp_tags_remove
This removes all tags matching the provided key. This will be used for removing metadata tags during encoding.
Diffstat (limited to 'common')
-rw-r--r--common/tags.c19
-rw-r--r--common/tags.h2
2 files changed, 21 insertions, 0 deletions
diff --git a/common/tags.c b/common/tags.c
index 29459d09e3..ffedab9b24 100644
--- a/common/tags.c
+++ b/common/tags.c
@@ -18,6 +18,7 @@
#include <stddef.h>
#include <limits.h>
#include <strings.h>
+#include <assert.h>
#include <libavutil/dict.h>
#include "tags.h"
#include "misc/bstr.h"
@@ -44,6 +45,24 @@ void mp_tags_set_bstr(struct mp_tags *tags, bstr key, bstr value)
tags->num_keys++;
}
+void mp_tags_remove_str(struct mp_tags *tags, const char *key)
+{
+ mp_tags_remove_bstr(tags, bstr0(key));
+}
+
+void mp_tags_remove_bstr(struct mp_tags *tags, bstr key)
+{
+ for (int n = 0; n < tags->num_keys; n++) {
+ if (bstrcasecmp0(key, tags->keys[n]) == 0) {
+ talloc_free(tags->keys[n]);
+ talloc_free(tags->values[n]);
+ int num_keys = tags->num_keys; // copy so it's only decremented once
+ MP_TARRAY_REMOVE_AT(tags->keys, num_keys, n);
+ MP_TARRAY_REMOVE_AT(tags->values, tags->num_keys, n);
+ }
+ }
+}
+
char *mp_tags_get_str(struct mp_tags *tags, const char *key)
{
return mp_tags_get_bstr(tags, bstr0(key));
diff --git a/common/tags.h b/common/tags.h
index dc8539d98f..3e538e7b76 100644
--- a/common/tags.h
+++ b/common/tags.h
@@ -11,6 +11,8 @@ struct mp_tags {
void mp_tags_set_str(struct mp_tags *tags, const char *key, const char *value);
void mp_tags_set_bstr(struct mp_tags *tags, bstr key, bstr value);
+void mp_tags_remove_str(struct mp_tags *tags, const char *key);
+void mp_tags_remove_bstr(struct mp_tags *tags, bstr key);
char *mp_tags_get_str(struct mp_tags *tags, const char *key);
char *mp_tags_get_bstr(struct mp_tags *tags, bstr key);
void mp_tags_clear(struct mp_tags *tags);