2014-04-13 12:01:55 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2014-04-13 12:01:55 +00:00
|
|
|
*
|
|
|
|
* 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
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2014-04-13 12:01:55 +00:00
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-13 12:01:55 +00:00
|
|
|
*/
|
|
|
|
|
2015-01-12 03:54:34 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <strings.h>
|
2017-12-24 02:14:16 +00:00
|
|
|
#include <assert.h>
|
2014-04-13 12:01:55 +00:00
|
|
|
#include <libavutil/dict.h>
|
|
|
|
#include "tags.h"
|
2014-08-29 10:09:04 +00:00
|
|
|
#include "misc/bstr.h"
|
2014-04-13 12:01:55 +00:00
|
|
|
|
|
|
|
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]);
|
2015-01-12 13:33:56 +00:00
|
|
|
tags->values[n] = bstrto0(tags, value);
|
2014-04-13 12:01:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MP_RESIZE_ARRAY(tags, tags->keys, tags->num_keys + 1);
|
|
|
|
MP_RESIZE_ARRAY(tags, tags->values, tags->num_keys + 1);
|
2015-01-12 13:33:56 +00:00
|
|
|
tags->keys[tags->num_keys] = bstrto0(tags, key);
|
|
|
|
tags->values[tags->num_keys] = bstrto0(tags, value);
|
2014-04-13 12:01:55 +00:00
|
|
|
tags->num_keys++;
|
|
|
|
}
|
|
|
|
|
2017-12-24 02:14:16 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-13 12:01:55 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
demux: support for some kinds of timed metadata
This makes ICY title changes show up at approximately the correct time,
even if the demuxer buffer is huge. (It'll still be wrong if the stream
byte cache contains a meaningful amount of data.)
It should have the same effect for mid-stream metadata changes in e.g.
OGG (untested).
This is still somewhat fishy, but in parts due to ICY being fishy, and
FFmpeg's metadata change API being somewhat fishy. For example, what
happens if you seek? With FFmpeg AVFMT_EVENT_FLAG_METADATA_UPDATED and
AVSTREAM_EVENT_FLAG_METADATA_UPDATED we hope that FFmpeg will correctly
restore the correct metadata when the first packet is returned.
If you seke with ICY, we're out of luck, and some audio will be
associated with the wrong tag until we get a new title through ICY
metadata update at an essentially random point (it's mostly inherent to
ICY). Then the tags will switch back and forth, and this behavior will
stick with the data stored in the demuxer cache. Fortunately, this can
happen only if the HTTP stream is actually seekable, which it usually is
not for ICY things. Seeking doesn't even make sense with ICY, since you
can't know the exact metadata location. Basically ICY metsdata sucks.
Some complexity is due to a microoptimization: I didn't want additional
atomic accesses for each packet if no timed metadata is used. (It
probably doesn't matter at all.)
2018-04-16 20:23:08 +00:00
|
|
|
|
|
|
|
|
2014-07-16 20:40:12 +00:00
|
|
|
struct mp_tags *mp_tags_dup(void *tparent, struct mp_tags *tags)
|
|
|
|
{
|
|
|
|
struct mp_tags *new = talloc_zero(tparent, struct mp_tags);
|
demux: support for some kinds of timed metadata
This makes ICY title changes show up at approximately the correct time,
even if the demuxer buffer is huge. (It'll still be wrong if the stream
byte cache contains a meaningful amount of data.)
It should have the same effect for mid-stream metadata changes in e.g.
OGG (untested).
This is still somewhat fishy, but in parts due to ICY being fishy, and
FFmpeg's metadata change API being somewhat fishy. For example, what
happens if you seek? With FFmpeg AVFMT_EVENT_FLAG_METADATA_UPDATED and
AVSTREAM_EVENT_FLAG_METADATA_UPDATED we hope that FFmpeg will correctly
restore the correct metadata when the first packet is returned.
If you seke with ICY, we're out of luck, and some audio will be
associated with the wrong tag until we get a new title through ICY
metadata update at an essentially random point (it's mostly inherent to
ICY). Then the tags will switch back and forth, and this behavior will
stick with the data stored in the demuxer cache. Fortunately, this can
happen only if the HTTP stream is actually seekable, which it usually is
not for ICY things. Seeking doesn't even make sense with ICY, since you
can't know the exact metadata location. Basically ICY metsdata sucks.
Some complexity is due to a microoptimization: I didn't want additional
atomic accesses for each packet if no timed metadata is used. (It
probably doesn't matter at all.)
2018-04-16 20:23:08 +00:00
|
|
|
mp_tags_replace(new, tags);
|
2014-07-16 20:40:12 +00:00
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
demux: support for some kinds of timed metadata
This makes ICY title changes show up at approximately the correct time,
even if the demuxer buffer is huge. (It'll still be wrong if the stream
byte cache contains a meaningful amount of data.)
It should have the same effect for mid-stream metadata changes in e.g.
OGG (untested).
This is still somewhat fishy, but in parts due to ICY being fishy, and
FFmpeg's metadata change API being somewhat fishy. For example, what
happens if you seek? With FFmpeg AVFMT_EVENT_FLAG_METADATA_UPDATED and
AVSTREAM_EVENT_FLAG_METADATA_UPDATED we hope that FFmpeg will correctly
restore the correct metadata when the first packet is returned.
If you seke with ICY, we're out of luck, and some audio will be
associated with the wrong tag until we get a new title through ICY
metadata update at an essentially random point (it's mostly inherent to
ICY). Then the tags will switch back and forth, and this behavior will
stick with the data stored in the demuxer cache. Fortunately, this can
happen only if the HTTP stream is actually seekable, which it usually is
not for ICY things. Seeking doesn't even make sense with ICY, since you
can't know the exact metadata location. Basically ICY metsdata sucks.
Some complexity is due to a microoptimization: I didn't want additional
atomic accesses for each packet if no timed metadata is used. (It
probably doesn't matter at all.)
2018-04-16 20:23:08 +00:00
|
|
|
void mp_tags_replace(struct mp_tags *dst, struct mp_tags *src)
|
|
|
|
{
|
|
|
|
mp_tags_clear(dst);
|
|
|
|
MP_RESIZE_ARRAY(dst, dst->keys, src->num_keys);
|
|
|
|
MP_RESIZE_ARRAY(dst, dst->values, src->num_keys);
|
|
|
|
dst->num_keys = src->num_keys;
|
|
|
|
for (int n = 0; n < src->num_keys; n++) {
|
|
|
|
dst->keys[n] = talloc_strdup(dst, src->keys[n]);
|
|
|
|
dst->values[n] = talloc_strdup(dst, src->values[n]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-29 21:51:18 +00:00
|
|
|
// Return a copy of the tags, but containing only keys in list. Also forces
|
|
|
|
// the order and casing of the keys (for cosmetic reasons).
|
2015-01-12 03:54:34 +00:00
|
|
|
// A trailing '*' matches the rest.
|
2014-12-29 21:51:18 +00:00
|
|
|
struct mp_tags *mp_tags_filtered(void *tparent, struct mp_tags *tags, char **list)
|
|
|
|
{
|
|
|
|
struct mp_tags *new = talloc_zero(tparent, struct mp_tags);
|
|
|
|
for (int n = 0; list && list[n]; n++) {
|
|
|
|
char *key = list[n];
|
2015-01-12 03:54:34 +00:00
|
|
|
size_t keylen = strlen(key);
|
|
|
|
if (keylen >= INT_MAX)
|
|
|
|
continue;
|
|
|
|
bool prefix = keylen && key[keylen - 1] == '*';
|
|
|
|
int matchlen = prefix ? keylen - 1 : keylen + 1;
|
|
|
|
for (int x = 0; x < tags->num_keys; x++) {
|
|
|
|
if (strncasecmp(tags->keys[x], key, matchlen) == 0) {
|
|
|
|
char skey[320];
|
|
|
|
snprintf(skey, sizeof(skey), "%.*s%s", matchlen, key,
|
|
|
|
prefix ? tags->keys[x] + keylen - 1 : "");
|
|
|
|
mp_tags_set_str(new, skey, tags->values[x]);
|
|
|
|
}
|
2014-12-29 21:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
2014-07-05 14:45:56 +00:00
|
|
|
void mp_tags_merge(struct mp_tags *tags, struct mp_tags *src)
|
|
|
|
{
|
|
|
|
for (int n = 0; n < src->num_keys; n++)
|
|
|
|
mp_tags_set_str(tags, src->keys[n], src->values[n]);
|
|
|
|
}
|
|
|
|
|
2014-04-13 12:01:55 +00:00
|
|
|
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);
|
|
|
|
}
|