1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-30 11:42:04 +00:00

demux: handle tag updates differently

Instead of printing lines like:

    Demuxer info GENRE changed to Alternative Rock

Just output all tags once they change. The assumption is that individual
tags rarely change, while all tags change in the common case.

This changes tag updates to use polling. This could be fixed later,
although the ICY stuff makes it a bit painful, so maybe it will remain
this way.

Also remove DEMUXER_CTRL_UPDATE_INFO. This was intended to check for tag
updates, but now we use a different approach.
This commit is contained in:
wm4 2014-02-06 13:41:20 +01:00
parent 5693b5ae16
commit eb1ec14b67
3 changed files with 21 additions and 15 deletions

View File

@ -720,19 +720,11 @@ int demux_info_add(demuxer_t *demuxer, const char *opt, const char *param)
int demux_info_add_bstr(demuxer_t *demuxer, struct bstr opt, struct bstr param)
{
char *oldval = mp_tags_get_bstr(demuxer->metadata, opt);
if (oldval) {
if (bstrcmp0(param, oldval) == 0)
return 0;
MP_INFO(demuxer, "Demuxer info %.*s changed to %.*s\n",
BSTR_P(opt), BSTR_P(param));
}
mp_tags_set_bstr(demuxer->metadata, opt, param);
return 1;
}
int demux_info_print(demuxer_t *demuxer)
static int demux_info_print(demuxer_t *demuxer)
{
struct mp_tags *info = demuxer->metadata;
int n;
@ -760,14 +752,29 @@ char *demux_info_get(demuxer_t *demuxer, const char *opt)
void demux_info_update(struct demuxer *demuxer)
{
demux_control(demuxer, DEMUXER_CTRL_UPDATE_INFO, NULL);
struct mp_tags *tags = demuxer->metadata;
// Take care of stream metadata as well
char **meta;
if (stream_control(demuxer->stream, STREAM_CTRL_GET_METADATA, &meta) > 0) {
for (int n = 0; meta[n + 0]; n += 2)
demux_info_add(demuxer, meta[n + 0], meta[n + 1]);
mp_tags_set_str(tags, meta[n + 0], meta[n + 1]);
talloc_free(meta);
}
// Check for metadata changes the hard way.
char *data = talloc_strdup(demuxer, "");
for (int n = 0; n < tags->num_keys; n++) {
data = talloc_asprintf_append_buffer(data, "%s=%s\n", tags->keys[n],
tags->values[n]);
}
if (!demuxer->previous_metadata ||
strcmp(demuxer->previous_metadata, data) != 0)
{
talloc_free(demuxer->previous_metadata);
demuxer->previous_metadata = data;
demux_info_print(demuxer);
} else {
talloc_free(data);
}
}
int demux_control(demuxer_t *demuxer, int cmd, void *arg)

View File

@ -50,8 +50,7 @@ enum demuxer_type {
#define DEMUXER_CTRL_GUESS 2
enum demux_ctrl {
DEMUXER_CTRL_UPDATE_INFO = 1,
DEMUXER_CTRL_SWITCHED_TRACKS,
DEMUXER_CTRL_SWITCHED_TRACKS = 1,
DEMUXER_CTRL_GET_TIME_LENGTH,
DEMUXER_CTRL_GET_START_TIME,
DEMUXER_CTRL_RESYNC,
@ -199,6 +198,7 @@ typedef struct demuxer {
struct playlist *playlist;
struct mp_tags *metadata;
char *previous_metadata;
void *priv; // demuxer-specific internal data
struct MPOpts *opts;
@ -247,7 +247,6 @@ int demux_info_add(struct demuxer *demuxer, const char *opt, const char *param);
int demux_info_add_bstr(struct demuxer *demuxer, struct bstr opt,
struct bstr param);
char *demux_info_get(struct demuxer *demuxer, const char *opt);
int demux_info_print(struct demuxer *demuxer);
void demux_info_update(struct demuxer *demuxer);
int demux_control(struct demuxer *demuxer, int cmd, void *arg);

View File

@ -1256,7 +1256,7 @@ goto_reopen_demuxer: ;
}
reselect_demux_streams(mpctx);
demux_info_print(mpctx->master_demuxer);
demux_info_update(mpctx->master_demuxer);
print_file_properties(mpctx);
#if HAVE_ENCODING