mirror of https://github.com/mpv-player/mpv
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
This commit is contained in:
parent
da82c0428e
commit
dd5f2069b8
|
@ -76,6 +76,8 @@
|
||||||
#include "osdep/subprocess.h"
|
#include "osdep/subprocess.h"
|
||||||
#include "osdep/terminal.h"
|
#include "osdep/terminal.h"
|
||||||
|
|
||||||
|
#include "core.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -2099,67 +2101,6 @@ static char *append_track_info(char *res, struct track *track)
|
||||||
return res;
|
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,
|
static int property_list_tracks(void *ctx, struct m_property *prop,
|
||||||
int action, void *arg)
|
int action, void *arg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "core.h"
|
|
||||||
#include "libmpv/client.h"
|
#include "libmpv/client.h"
|
||||||
#include "osdep/compiler.h"
|
#include "osdep/compiler.h"
|
||||||
|
|
||||||
|
@ -122,10 +121,4 @@ void mark_seek(struct MPContext *mpctx);
|
||||||
|
|
||||||
void mp_abort_cache_dumping(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 */
|
#endif /* MPLAYER_COMMAND_H */
|
||||||
|
|
|
@ -481,6 +481,11 @@ struct mp_abort_entry {
|
||||||
// (only valid if client_work_type set)
|
// (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
|
// audio.c
|
||||||
void reset_audio_state(struct MPContext *mpctx);
|
void reset_audio_state(struct MPContext *mpctx);
|
||||||
void reinit_audio_chain(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);
|
int stream_dump(struct MPContext *mpctx, const char *source_filename);
|
||||||
double get_track_seek_offset(struct MPContext *mpctx, struct track *track);
|
double get_track_seek_offset(struct MPContext *mpctx, struct track *track);
|
||||||
bool str_in_list(bstr str, char **list);
|
bool str_in_list(bstr str, char **list);
|
||||||
|
char *mp_format_track_metadata(void *ctx, struct track *t, bool add_lang);
|
||||||
|
|
||||||
// osd.c
|
// osd.c
|
||||||
void set_osd_bar(struct MPContext *mpctx, int type,
|
void set_osd_bar(struct MPContext *mpctx, int type,
|
||||||
|
|
|
@ -353,3 +353,64 @@ bool str_in_list(bstr str, char **list)
|
||||||
}
|
}
|
||||||
return false;
|
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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue