From 9f4b01400ea515b295ad9f0b92d011e80ed0389f Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 19 Dec 2014 23:54:21 +0100 Subject: player: print only changed tags The code in the demuxer etc. was changed to update all metadata/tags at once, instead of changing each metadata field. As a consequence, printing of the tags to the terminal was also changed to print everything on each change. Some users didn't like this. Add a very primitive way to avoid printing fields with the same value again if metadata is marked as changed. This is not always correct (could print unchanged fields anyway), but usually works. (In general, a rather roundabout way to reflect a changed title with ICY streaming...) Fixes #813 (let's call it a "policy change"). --- player/core.h | 1 + player/loadfile.c | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'player') diff --git a/player/core.h b/player/core.h index 344e55df19..d6360c5135 100644 --- a/player/core.h +++ b/player/core.h @@ -196,6 +196,7 @@ typedef struct MPContext { double video_offset; struct demuxer *demuxer; + struct mp_tags *tags; struct track **tracks; int num_tracks; diff --git a/player/loadfile.c b/player/loadfile.c index d1b77743e6..624f6beebc 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -167,11 +167,27 @@ void update_demuxer_properties(struct MPContext *mpctx) } tracks->events &= ~DEMUX_EVENT_STREAMS; } - struct mp_tags *info = demuxer->metadata; - if ((events & DEMUX_EVENT_METADATA) && info->num_keys) { - MP_INFO(mpctx, "File tags:\n"); - for (int n = 0; n < info->num_keys; n++) + if (events & DEMUX_EVENT_METADATA) { + struct mp_tags *info = demuxer->metadata; + // prev is used to attempt to print changed tags only (to some degree) + struct mp_tags *prev = mpctx->tags; + int n_prev = 0; + bool had_output = false; + for (int n = 0; n < info->num_keys; n++) { + if (prev && n_prev < prev->num_keys) { + if (strcmp(prev->keys[n_prev], info->keys[n]) == 0) { + n_prev++; + if (strcmp(prev->values[n_prev - 1], info->values[n]) == 0) + continue; + } + } + if (!had_output) + MP_INFO(mpctx, "File tags:\n"); MP_INFO(mpctx, " %s: %s\n", info->keys[n], info->values[n]); + had_output = true; + } + talloc_free(mpctx->tags); + mpctx->tags = mp_tags_dup(mpctx, info); mp_notify(mpctx, MPV_EVENT_METADATA_UPDATE, NULL); } demuxer->events = 0; @@ -1189,6 +1205,9 @@ terminate_playback: m_config_restore_backups(mpctx->mconfig); + talloc_free(mpctx->tags); + mpctx->tags = NULL; + mpctx->playback_initialized = false; mp_notify(mpctx, MPV_EVENT_TRACKS_CHANGED, NULL); -- cgit v1.2.3