Skip to content

Commit

Permalink
loadfile: move mp_format_track_metadata to misc.c
Browse files Browse the repository at this point in the history
Move the function added in 3ea8d75 to misc.c because command.c is too
big. The circle definitions are also moved to core.h
  • Loading branch information
guidocella authored and sfan5 committed Nov 16, 2024
1 parent da82c04 commit dd5f206
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 68 deletions.
63 changes: 2 additions & 61 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
#include "osdep/subprocess.h"
#include "osdep/terminal.h"

#include "core.h"

#ifdef _WIN32
#include <windows.h>
#endif
Expand Down Expand Up @@ -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 : "<unknown>");

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)
{
Expand Down
7 changes: 0 additions & 7 deletions player/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include <stdbool.h>

#include "core.h"
#include "libmpv/client.h"
#include "osdep/compiler.h"

Expand Down Expand Up @@ -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 */
6 changes: 6 additions & 0 deletions player/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
61 changes: 61 additions & 0 deletions player/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 : "<unknown>");

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);
}

0 comments on commit dd5f206

Please sign in to comment.