From e22efe2d221ec668cb362c6ce4e4ebb974bf1ce7 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Sun, 1 Oct 2023 11:55:24 -0500 Subject: [PATCH] stream_lavf: use metadata-codepage option for codepage conversion a343666ab5121e7a3388be9aa2d8731d6d1f2f64 made demux options public, so we can take advantage of that here as well. This lets users guess the codepage if the stream doesn't use UTF-8 characters. Fixes #8844. --- stream/stream_lavf.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/stream/stream_lavf.c b/stream/stream_lavf.c index 0164ede388..08b61ab445 100644 --- a/stream/stream_lavf.c +++ b/stream/stream_lavf.c @@ -26,6 +26,8 @@ #include "common/msg.h" #include "common/tags.h" #include "common/av_common.h" +#include "demux/demux.h" +#include "misc/charset_conv.h" #include "misc/thread_tools.h" #include "stream.h" #include "options/m_config.h" @@ -403,7 +405,21 @@ static struct mp_tags *read_icy(stream_t *s) packet = bstr_cut(packet, i + head.len); int end = bstr_find(packet, bstr0("\';")); packet = bstr_splice(packet, 0, end); + + bool allocated = false; + struct demux_opts *opts = mp_get_config_group(NULL, s->global, &demux_conf); + const char *charset = mp_charset_guess(s, s->log, packet, opts->meta_cp, 0); + if (charset && !mp_charset_is_utf8(charset)) { + bstr conv = mp_iconv_to_utf8(s->log, packet, charset, 0); + if (conv.start && conv.start != packet.start) { + allocated = true; + packet = conv; + } + } mp_tags_set_bstr(res, bstr0("icy-title"), packet); + talloc_free(opts); + if (allocated) + talloc_free(packet.start); } av_opt_set(avio, "icy_metadata_packet", "-", AV_OPT_SEARCH_CHILDREN);