summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/tags.c70
-rw-r--r--common/tags.h21
-rw-r--r--demux/demux.c42
-rw-r--r--demux/demux.h13
-rw-r--r--demux/demux_lavf.c16
-rw-r--r--old-makefile1
-rw-r--r--wscript_build.py1
7 files changed, 99 insertions, 65 deletions
diff --git a/common/tags.c b/common/tags.c
new file mode 100644
index 0000000000..f709cf0d5a
--- /dev/null
+++ b/common/tags.c
@@ -0,0 +1,70 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libavutil/dict.h>
+#include "tags.h"
+#include "bstr/bstr.h"
+
+void mp_tags_set_str(struct mp_tags *tags, const char *key, const char *value)
+{
+ mp_tags_set_bstr(tags, bstr0(key), bstr0(value));
+}
+
+void mp_tags_set_bstr(struct mp_tags *tags, bstr key, bstr value)
+{
+ for (int n = 0; n < tags->num_keys; n++) {
+ if (bstrcasecmp0(key, tags->keys[n]) == 0) {
+ talloc_free(tags->values[n]);
+ tags->values[n] = talloc_strndup(tags, value.start, value.len);
+ return;
+ }
+ }
+
+ MP_RESIZE_ARRAY(tags, tags->keys, tags->num_keys + 1);
+ MP_RESIZE_ARRAY(tags, tags->values, tags->num_keys + 1);
+ tags->keys[tags->num_keys] = talloc_strndup(tags, key.start, key.len);
+ tags->values[tags->num_keys] = talloc_strndup(tags, value.start, value.len);
+ tags->num_keys++;
+}
+
+char *mp_tags_get_str(struct mp_tags *tags, const char *key)
+{
+ return mp_tags_get_bstr(tags, bstr0(key));
+}
+
+char *mp_tags_get_bstr(struct mp_tags *tags, bstr key)
+{
+ for (int n = 0; n < tags->num_keys; n++) {
+ if (bstrcasecmp0(key, tags->keys[n]) == 0)
+ return tags->values[n];
+ }
+ return NULL;
+}
+
+void mp_tags_clear(struct mp_tags *tags)
+{
+ *tags = (struct mp_tags){0};
+ talloc_free_children(tags);
+}
+
+void mp_tags_copy_from_av_dictionary(struct mp_tags *tags,
+ struct AVDictionary *av_dict)
+{
+ AVDictionaryEntry *entry = NULL;
+ while ((entry = av_dict_get(av_dict, "", entry, AV_DICT_IGNORE_SUFFIX)))
+ mp_tags_set_str(tags, entry->key, entry->value);
+}
diff --git a/common/tags.h b/common/tags.h
new file mode 100644
index 0000000000..3bc0e6984b
--- /dev/null
+++ b/common/tags.h
@@ -0,0 +1,21 @@
+#ifndef MP_TAGS_H
+#define MP_TAGS_H
+
+#include "bstr/bstr.h"
+
+struct mp_tags {
+ char **keys;
+ char **values;
+ int num_keys;
+};
+
+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);
+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);
+struct AVDictionary;
+void mp_tags_copy_from_av_dictionary(struct mp_tags *tags,
+ struct AVDictionary *av_dict);
+
+#endif
diff --git a/demux/demux.c b/demux/demux.c
index f78a4628b8..c6d3b9d9d2 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -753,48 +753,6 @@ int demux_seek(demuxer_t *demuxer, float rel_seek_secs, int flags)
return 1;
}
-void mp_tags_set_str(struct mp_tags *tags, const char *key, const char *value)
-{
- mp_tags_set_bstr(tags, bstr0(key), bstr0(value));
-}
-
-void mp_tags_set_bstr(struct mp_tags *tags, bstr key, bstr value)
-{
- for (int n = 0; n < tags->num_keys; n++) {
- if (bstrcasecmp0(key, tags->keys[n]) == 0) {
- talloc_free(tags->values[n]);
- tags->values[n] = talloc_strndup(tags, value.start, value.len);
- return;
- }
- }
-
- MP_RESIZE_ARRAY(tags, tags->keys, tags->num_keys + 1);
- MP_RESIZE_ARRAY(tags, tags->values, tags->num_keys + 1);
- tags->keys[tags->num_keys] = talloc_strndup(tags, key.start, key.len);
- tags->values[tags->num_keys] = talloc_strndup(tags, value.start, value.len);
- tags->num_keys++;
-}
-
-char *mp_tags_get_str(struct mp_tags *tags, const char *key)
-{
- return mp_tags_get_bstr(tags, bstr0(key));
-}
-
-char *mp_tags_get_bstr(struct mp_tags *tags, bstr key)
-{
- for (int n = 0; n < tags->num_keys; n++) {
- if (bstrcasecmp0(key, tags->keys[n]) == 0)
- return tags->values[n];
- }
- return NULL;
-}
-
-void mp_tags_clear(struct mp_tags *tags)
-{
- *tags = (struct mp_tags){0};
- talloc_free_children(tags);
-}
-
static int demux_info_print(demuxer_t *demuxer)
{
struct mp_tags *info = demuxer->metadata;
diff --git a/demux/demux.h b/demux/demux.h
index 2d2bdfacc3..81568b96b9 100644
--- a/demux/demux.h
+++ b/demux/demux.h
@@ -27,6 +27,7 @@
#include "bstr/bstr.h"
#include "common/common.h"
+#include "common/tags.h"
#include "packet.h"
#include "stheader.h"
@@ -104,12 +105,6 @@ typedef struct demuxer_desc {
int (*control)(struct demuxer *demuxer, int cmd, void *arg);
} demuxer_desc_t;
-struct mp_tags {
- char **keys;
- char **values;
- int num_keys;
-};
-
typedef struct demux_chapter
{
int original_index;
@@ -292,12 +287,6 @@ double demux_packet_list_duration(struct demux_packet **pkts, int num_pkts);
struct demux_packet *demux_packet_list_fill(struct demux_packet **pkts,
int num_pkts, int *current);
-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);
-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);
-
bool demux_matroska_uid_cmp(struct matroska_segment_uid *a,
struct matroska_segment_uid *b);
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index ceff978afb..90fde22eba 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -41,6 +41,7 @@
#include "options/options.h"
#include "common/msg.h"
+#include "common/tags.h"
#include "common/av_opts.h"
#include "common/av_common.h"
#include "bstr/bstr.h"
@@ -560,13 +561,6 @@ static void add_new_streams(demuxer_t *demuxer)
handle_stream(demuxer, priv->num_streams);
}
-static void add_metadata(struct mp_tags *tags, AVDictionary *metadata)
-{
- AVDictionaryEntry *t = NULL;
- while ((t = av_dict_get(metadata, "", t, AV_DICT_IGNORE_SUFFIX)))
- mp_tags_set_str(tags, t->key, t->value);
-}
-
static void update_metadata(demuxer_t *demuxer, AVPacket *pkt)
{
#if HAVE_AVCODEC_METADATA_UPDATE_SIDE_DATA
@@ -578,7 +572,7 @@ static void update_metadata(demuxer_t *demuxer, AVPacket *pkt)
av_packet_unpack_dictionary(md, md_size, &dict);
if (dict) {
mp_tags_clear(demuxer->metadata);
- add_metadata(demuxer->metadata, dict);
+ mp_tags_copy_from_av_dictionary(demuxer->metadata, dict);
av_dict_free(&dict);
}
}
@@ -706,19 +700,19 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check)
t = av_dict_get(c->metadata, "title", NULL, 0);
int index = demuxer_add_chapter(demuxer, t ? bstr0(t->value) : bstr0(""),
start, end, i);
- add_metadata(demuxer->chapters[index].metadata, c->metadata);
+ mp_tags_copy_from_av_dictionary(demuxer->chapters[index].metadata, c->metadata);
}
add_new_streams(demuxer);
- add_metadata(demuxer->metadata, avfc->metadata);
+ mp_tags_copy_from_av_dictionary(demuxer->metadata, avfc->metadata);
// Often useful with OGG audio-only files, which have metadata in the audio
// track metadata instead of the main metadata.
if (demuxer->num_streams == 1) {
for (int n = 0; n < priv->num_streams; n++) {
if (priv->streams[n])
- add_metadata(demuxer->metadata, avfc->streams[n]->metadata);
+ mp_tags_copy_from_av_dictionary(demuxer->metadata, avfc->streams[n]->metadata);
}
}
diff --git a/old-makefile b/old-makefile
index 4df04d49da..411163fa9a 100644
--- a/old-makefile
+++ b/old-makefile
@@ -185,6 +185,7 @@ SOURCES = audio/audio.c \
common/common.c \
common/msg.c \
common/playlist.c \
+ common/tags.c \
common/version.c \
demux/codec_tags.c \
demux/demux.c \
diff --git a/wscript_build.py b/wscript_build.py
index 08b26db89b..8790c96d4a 100644
--- a/wscript_build.py
+++ b/wscript_build.py
@@ -161,6 +161,7 @@ def build(ctx):
( "common/cpudetect.c" ),
( "common/encode_lavc.c", "encoding" ),
( "common/common.c" ),
+ ( "common/tags.c" ),
( "common/msg.c" ),
( "common/playlist.c" ),
( "common/version.c" ),