From dd5f2069b8b3e452e7cdca017942da07b02a69ad Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Thu, 14 Nov 2024 10:46:05 +0100 Subject: [PATCH] loadfile: move mp_format_track_metadata to misc.c Move the function added in 3ea8d751f5 to misc.c because command.c is too big. The circle definitions are also moved to core.h --- player/command.c | 63 ++---------------------------------------------- player/command.h | 7 ------ player/core.h | 6 +++++ player/misc.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 68 deletions(-) diff --git a/player/command.c b/player/command.c index b62d4cccb62c4..ec92bc6c3d696 100644 --- a/player/command.c +++ b/player/command.c @@ -76,6 +76,8 @@ #include "osdep/subprocess.h" #include "osdep/terminal.h" +#include "core.h" + #ifdef _WIN32 #include #endif @@ -2099,67 +2101,6 @@ static char *append_track_info(char *res, struct track *track) return res; } -#define bstr_xappend0(ctx, dst, s) bstr_xappend(ctx, dst, bstr0(s)) -#define ADD_FLAG(ctx, dst, flag, first) do { \ - bstr_xappend_asprintf(ctx, &dst, " %s%s", first ? "[" : "", flag); \ - first = false; \ -} while(0) - -char *mp_format_track_metadata(void *ctx, struct track *t, bool add_lang) -{ - struct sh_stream *s = t->stream; - bstr dst = {0}; - - if (t->title) - bstr_xappend_asprintf(ctx, &dst, "'%s' ", t->title); - - const char *codec = s ? s->codec->codec : NULL; - - bstr_xappend0(ctx, &dst, "("); - - if (add_lang && t->lang) - bstr_xappend_asprintf(ctx, &dst, "%s ", t->lang); - - bstr_xappend0(ctx, &dst, codec ? codec : ""); - - if (s && s->codec->codec_profile) - bstr_xappend_asprintf(ctx, &dst, " [%s]", s->codec->codec_profile); - if (s && s->codec->disp_w) - bstr_xappend_asprintf(ctx, &dst, " %dx%d", s->codec->disp_w, s->codec->disp_h); - if (s && s->codec->fps && !t->image) { - char *fps = mp_format_double(ctx, s->codec->fps, 4, false, false, true); - bstr_xappend_asprintf(ctx, &dst, " %s fps", fps); - } - if (s && s->codec->channels.num) - bstr_xappend_asprintf(ctx, &dst, " %dch", s->codec->channels.num); - if (s && s->codec->samplerate) - bstr_xappend_asprintf(ctx, &dst, " %d Hz", s->codec->samplerate); - if (s && s->codec->bitrate) { - bstr_xappend_asprintf(ctx, &dst, " %d kbps", (s->codec->bitrate + 500) / 1000); - } else if (s && s->hls_bitrate) { - bstr_xappend_asprintf(ctx, &dst, " %d kbps", (s->hls_bitrate + 500) / 1000); - } - bstr_xappend0(ctx, &dst, ")"); - - bool first = true; - if (t->default_track) - ADD_FLAG(ctx, dst, "default", first); - if (t->forced_track) - ADD_FLAG(ctx, dst, "forced", first); - if (t->dependent_track) - ADD_FLAG(ctx, dst, "dependent", first); - if (t->visual_impaired_track) - ADD_FLAG(ctx, dst, "visual-impaired", first); - if (t->hearing_impaired_track) - ADD_FLAG(ctx, dst, "hearing-impaired", first); - if (t->is_external) - ADD_FLAG(ctx, dst, "external", first); - if (!first) - bstr_xappend0(ctx, &dst, "]"); - - return bstrto0(ctx, dst); -} - static int property_list_tracks(void *ctx, struct m_property *prop, int action, void *arg) { diff --git a/player/command.h b/player/command.h index 17c62cae96622..31e3b32a78bf4 100644 --- a/player/command.h +++ b/player/command.h @@ -20,7 +20,6 @@ #include -#include "core.h" #include "libmpv/client.h" #include "osdep/compiler.h" @@ -122,10 +121,4 @@ void mark_seek(struct MPContext *mpctx); void mp_abort_cache_dumping(struct MPContext *mpctx); -// U+25CB WHITE CIRCLE -// U+25CF BLACK CIRCLE -#define WHITE_CIRCLE "\xe2\x97\x8b" -#define BLACK_CIRCLE "\xe2\x97\x8f" -char *mp_format_track_metadata(void *ctx, struct track *t, bool add_lang); - #endif /* MPLAYER_COMMAND_H */ diff --git a/player/core.h b/player/core.h index dce3ce47342cc..1342243201a27 100644 --- a/player/core.h +++ b/player/core.h @@ -481,6 +481,11 @@ struct mp_abort_entry { // (only valid if client_work_type set) }; +// U+25CB WHITE CIRCLE +// U+25CF BLACK CIRCLE +#define WHITE_CIRCLE "\xe2\x97\x8b" +#define BLACK_CIRCLE "\xe2\x97\x8f" + // audio.c void reset_audio_state(struct MPContext *mpctx); void reinit_audio_chain(struct MPContext *mpctx); @@ -566,6 +571,7 @@ void error_on_track(struct MPContext *mpctx, struct track *track); int stream_dump(struct MPContext *mpctx, const char *source_filename); double get_track_seek_offset(struct MPContext *mpctx, struct track *track); bool str_in_list(bstr str, char **list); +char *mp_format_track_metadata(void *ctx, struct track *t, bool add_lang); // osd.c void set_osd_bar(struct MPContext *mpctx, int type, diff --git a/player/misc.c b/player/misc.c index a19dd17f88666..61839e2cc280a 100644 --- a/player/misc.c +++ b/player/misc.c @@ -353,3 +353,64 @@ bool str_in_list(bstr str, char **list) } return false; } + +#define ADD_FLAG(ctx, dst, flag, first) do { \ + bstr_xappend_asprintf(ctx, &dst, " %s%s", first ? "[" : "", flag); \ + first = false; \ +} while(0) +#define bstr_xappend0(ctx, dst, s) bstr_xappend(ctx, dst, bstr0(s)) + +char *mp_format_track_metadata(void *ctx, struct track *t, bool add_lang) +{ + struct sh_stream *s = t->stream; + bstr dst = {0}; + + if (t->title) + bstr_xappend_asprintf(ctx, &dst, "'%s' ", t->title); + + const char *codec = s ? s->codec->codec : NULL; + + bstr_xappend0(ctx, &dst, "("); + + if (add_lang && t->lang) + bstr_xappend_asprintf(ctx, &dst, "%s ", t->lang); + + bstr_xappend0(ctx, &dst, codec ? codec : ""); + + if (s && s->codec->codec_profile) + bstr_xappend_asprintf(ctx, &dst, " [%s]", s->codec->codec_profile); + if (s && s->codec->disp_w) + bstr_xappend_asprintf(ctx, &dst, " %dx%d", s->codec->disp_w, s->codec->disp_h); + if (s && s->codec->fps && !t->image) { + char *fps = mp_format_double(ctx, s->codec->fps, 4, false, false, true); + bstr_xappend_asprintf(ctx, &dst, " %s fps", fps); + } + if (s && s->codec->channels.num) + bstr_xappend_asprintf(ctx, &dst, " %dch", s->codec->channels.num); + if (s && s->codec->samplerate) + bstr_xappend_asprintf(ctx, &dst, " %d Hz", s->codec->samplerate); + if (s && s->codec->bitrate) { + bstr_xappend_asprintf(ctx, &dst, " %d kbps", (s->codec->bitrate + 500) / 1000); + } else if (s && s->hls_bitrate) { + bstr_xappend_asprintf(ctx, &dst, " %d kbps", (s->hls_bitrate + 500) / 1000); + } + bstr_xappend0(ctx, &dst, ")"); + + bool first = true; + if (t->default_track) + ADD_FLAG(ctx, dst, "default", first); + if (t->forced_track) + ADD_FLAG(ctx, dst, "forced", first); + if (t->dependent_track) + ADD_FLAG(ctx, dst, "dependent", first); + if (t->visual_impaired_track) + ADD_FLAG(ctx, dst, "visual-impaired", first); + if (t->hearing_impaired_track) + ADD_FLAG(ctx, dst, "hearing-impaired", first); + if (t->is_external) + ADD_FLAG(ctx, dst, "external", first); + if (!first) + bstr_xappend0(ctx, &dst, "]"); + + return bstrto0(ctx, dst); +}