summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorKevin Mitchell <kevmitch@gmail.com>2014-04-13 05:01:55 -0700
committerwm4 <wm4@nowhere>2014-04-13 18:03:01 +0200
commitbc79ded75a63ae79a1119f5ca578d41fca04b283 (patch)
treec6d04bd0d0b090373f154b351fb7fabfd9ab529f /demux
parent47972a0077892636fb922a3600d66779636b7ee7 (diff)
downloadmpv-bc79ded75a63ae79a1119f5ca578d41fca04b283.tar.bz2
mpv-bc79ded75a63ae79a1119f5ca578d41fca04b283.tar.xz
mp_tags: move generic mp_tags stuff into its own .c/.h files in common/
rename add_metadata to the more genera/descriptive mp_tags_copy_items_from_av_dictionary Signed-off-by: wm4 <wm4@nowhere>
Diffstat (limited to 'demux')
-rw-r--r--demux/demux.c42
-rw-r--r--demux/demux.h13
-rw-r--r--demux/demux_lavf.c16
3 files changed, 6 insertions, 65 deletions
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);
}
}