Skip to content

Commit

Permalink
loadfile: move mp_format_track_metadata to loadfile.c
Browse files Browse the repository at this point in the history
Move the function added in 3ea8d75 to loadfile.c, because command.c
is too big and loadfile.c already exposes track-related functions, and
uses mp_format_track_metadata() in print_stream().
  • Loading branch information
guidocella committed Nov 14, 2024
1 parent c60d852 commit e2a0b6f
Show file tree
Hide file tree
Showing 4 changed files with 68 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 */
5 changes: 5 additions & 0 deletions player/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,11 @@ struct track *mp_track_by_tid(struct MPContext *mpctx, enum stream_type type,
int tid);
void add_demuxer_tracks(struct MPContext *mpctx, struct demuxer *demuxer);
bool mp_remove_track(struct MPContext *mpctx, struct track *track);
// 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);
struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction,
bool force);
void mp_set_playlist_entry(struct MPContext *mpctx, struct playlist_entry *e);
Expand Down
61 changes: 61 additions & 0 deletions player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,67 @@ static void uninit_demuxer(struct MPContext *mpctx)
talloc_free(demuxers);
}

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

#define APPEND(s, ...) mp_snprintf_cat(s, sizeof(s), __VA_ARGS__)
#define FILL(s, n) mp_snprintf_cat(s, sizeof(s), "%*s", n, "")

Expand Down

0 comments on commit e2a0b6f

Please sign in to comment.