command: replace some show_ commands with properties

show_chapters, show_tracks, and show_playlist are killed and replaced
with the properties chapter-list, track-list, and playlist. The code
and the output of these stays the same, this is just moving a lot of
code around and reducing the number of properties.

The "old" commands will still be supported for a while (to avoid making
everyone angry), so handle them with the legacy layer. Add something to
suppress printing the legacy warnings for these commands.
This commit is contained in:
wm4 2013-05-15 02:17:47 +02:00
parent b15143b7e0
commit c185b0ba4a
5 changed files with 135 additions and 131 deletions

View File

@ -168,7 +168,12 @@ input.conf and slave commands
| | syntax slightly changed. |
+--------------------------------+----------------------------------------+
| osd_show_text | Now does the same as |
| | osd_show_property_text. |
| | osd_show_property_text. Use the raw |
| | prefix to disable property expansion. |
+--------------------------------+----------------------------------------+
| show_tracks | show_text ${track-list} |
+--------------------------------+----------------------------------------+
| show_chapters | show_text ${chapter-list} |
+--------------------------------+----------------------------------------+
Other

View File

@ -213,13 +213,6 @@ show_progress
Show the progress bar, the elapsed time and the total duration of the file
on the OSD.
show_chapters
Show a list of chapters on the OSD.
show_tracks
Show a list of video/audio/subtitle tracks on the OSD.
Input commands that are possibly subject to change
--------------------------------------------------
@ -271,7 +264,6 @@ vf set|add|toggle|del "filter1=params,filter2,..."
- ``b vf set ""`` remove all video filters on ``b``
- ``c vf toggle lavfi=gradfun`` toggle debanding on ``c``
Undocumented commands: tv_start_scan, tv_step_channel, tv_step_norm,
tv_step_chanlist, tv_set_channel, tv_last_channel, tv_set_freq, tv_step_freq,
tv_set_norm, dvb_set_channel, radio_step_channel, radio_set_channel,
@ -401,4 +393,7 @@ tv-brightness x
tv-contrast x
tv-saturation x
tv-hue x
track-list list of audio/video/sub tracks, cur. entr. marked
chapter-list list of chapters, current entry marked
playlist playlist, current entry marked
=========================== = ==================================================

View File

@ -393,6 +393,38 @@ static int mp_property_chapter(m_option_t *prop, int action, void *arg,
return M_PROPERTY_NOT_IMPLEMENTED;
}
static int mp_property_list_chapters(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
if (action == M_PROPERTY_GET) {
int count = get_chapter_count(mpctx);
int cur = mpctx->num_sources ? get_current_chapter(mpctx) : -1;
char *res = NULL;
int n;
if (count < 1) {
res = talloc_asprintf_append(res, "No chapters.");
}
for (n = 0; n < count; n++) {
char *name = chapter_display_name(mpctx, n);
double t = chapter_start_time(mpctx, n);
char* time = mp_format_time(t, false);
res = talloc_asprintf_append(res, "%s", time);
talloc_free(time);
char *m1 = "> ", *m2 = " <";
if (n != cur)
m1 = m2 = "";
res = talloc_asprintf_append(res, " %s%s%s\n", m1, name, m2);
talloc_free(name);
}
*(char **)arg = res;
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
static int mp_property_edition(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
@ -832,6 +864,60 @@ static int property_switch_track(m_option_t *prop, int action, void *arg,
return mp_property_generic_option(prop, action, arg, mpctx);
}
static const char *track_type_name(enum stream_type t)
{
switch (t) {
case STREAM_VIDEO: return "Video";
case STREAM_AUDIO: return "Audio";
case STREAM_SUB: return "Sub";
}
return NULL;
}
static int property_list_tracks(m_option_t *prop, int action, void *arg,
MPContext *mpctx, enum stream_type type)
{
if (action == M_PROPERTY_GET) {
char *res = NULL;
for (int type = 0; type < STREAM_TYPE_COUNT; type++) {
for (int n = 0; n < mpctx->num_tracks; n++) {
struct track *track = mpctx->tracks[n];
if (track->type != type)
continue;
bool selected = mpctx->current_track[track->type] == track;
res = talloc_asprintf_append(res, "%s: ",
track_type_name(track->type));
if (selected)
res = talloc_asprintf_append(res, "> ");
res = talloc_asprintf_append(res, "(%d) ", track->user_tid);
if (track->title)
res = talloc_asprintf_append(res, "'%s' ", track->title);
if (track->lang)
res = talloc_asprintf_append(res, "(%s) ", track->lang);
if (track->is_external)
res = talloc_asprintf_append(res, "(external) ");
if (selected)
res = talloc_asprintf_append(res, "<");
res = talloc_asprintf_append(res, "\n");
}
res = talloc_asprintf_append(res, "\n");
}
struct demuxer *demuxer = mpctx->master_demuxer;
if (demuxer && demuxer->num_editions > 1)
res = talloc_asprintf_append(res, "\nEdition: %d of %d\n",
demuxer->edition + 1,
demuxer->num_editions);
*(char **)arg = res;
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
/// Selected audio id (RW)
static int mp_property_audio(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
@ -1347,6 +1433,27 @@ static int mp_property_tv_color(m_option_t *prop, int action, void *arg,
#endif
static int mp_property_playlist(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
if (action == M_PROPERTY_GET) {
char *res = talloc_strdup(NULL, "");
for (struct playlist_entry *e = mpctx->playlist->first; e; e = e->next)
{
if (mpctx->playlist->current == e) {
res = talloc_asprintf_append(res, "> %s <\n", e->filename);
} else {
res = talloc_asprintf_append(res, "%s\n", e->filename);
}
}
*(char **)arg = res;
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
static int mp_property_alias(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
@ -1431,6 +1538,10 @@ static const m_option_t mp_properties[] = {
{ "clock", mp_property_clock, CONF_TYPE_STRING,
0, 0, 0, NULL },
{ "chapter-list", mp_property_list_chapters, CONF_TYPE_STRING },
{ "track-list", property_list_tracks, CONF_TYPE_STRING },
{ "playlist", mp_property_playlist, CONF_TYPE_STRING },
// Audio
{ "volume", mp_property_volume, CONF_TYPE_FLOAT,
M_OPT_RANGE, 0, 100, NULL },
@ -1699,101 +1810,6 @@ static const char *property_error_string(int error_value)
return "UNKNOWN";
}
static void show_chapters_on_osd(MPContext *mpctx)
{
int count = get_chapter_count(mpctx);
int cur = mpctx->num_sources ? get_current_chapter(mpctx) : -1;
char *res = NULL;
int n;
if (count < 1) {
res = talloc_asprintf_append(res, "No chapters.");
}
for (n = 0; n < count; n++) {
char *name = chapter_display_name(mpctx, n);
double t = chapter_start_time(mpctx, n);
char* time = mp_format_time(t, false);
res = talloc_asprintf_append(res, "%s", time);
talloc_free(time);
char *m1 = "> ", *m2 = " <";
if (n != cur)
m1 = m2 = "";
res = talloc_asprintf_append(res, " %s%s%s\n", m1, name, m2);
talloc_free(name);
}
set_osd_msg(mpctx, OSD_MSG_TEXT, 1, mpctx->opts.osd_duration, "%s", res);
talloc_free(res);
}
static const char *track_type_name(enum stream_type t)
{
switch (t) {
case STREAM_VIDEO: return "Video";
case STREAM_AUDIO: return "Audio";
case STREAM_SUB: return "Sub";
}
return NULL;
}
static void show_tracks_on_osd(MPContext *mpctx)
{
struct MPOpts *opts = &mpctx->opts;
char *res = NULL;
for (int type = 0; type < STREAM_TYPE_COUNT; type++) {
for (int n = 0; n < mpctx->num_tracks; n++) {
struct track *track = mpctx->tracks[n];
if (track->type != type)
continue;
bool selected = mpctx->current_track[track->type] == track;
res = talloc_asprintf_append(res, "%s: ", track_type_name(track->type));
if (selected)
res = talloc_asprintf_append(res, "> ");
res = talloc_asprintf_append(res, "(%d) ", track->user_tid);
if (track->title)
res = talloc_asprintf_append(res, "'%s' ", track->title);
if (track->lang)
res = talloc_asprintf_append(res, "(%s) ", track->lang);
if (track->is_external)
res = talloc_asprintf_append(res, "(external) ");
if (selected)
res = talloc_asprintf_append(res, "<");
res = talloc_asprintf_append(res, "\n");
}
res = talloc_asprintf_append(res, "\n");
}
struct demuxer *demuxer = mpctx->master_demuxer;
if (demuxer && demuxer->num_editions > 1)
res = talloc_asprintf_append(res, "\nEdition: %d of %d\n",
demuxer->edition + 1,
demuxer->num_editions);
set_osd_msg(mpctx, OSD_MSG_TEXT, 1, opts->osd_duration, "%s", res);
talloc_free(res);
}
static void show_playlist_on_osd(MPContext *mpctx)
{
struct MPOpts *opts = &mpctx->opts;
char *res = NULL;
for (struct playlist_entry *e = mpctx->playlist->first; e; e = e->next) {
if (mpctx->playlist->current == e) {
res = talloc_asprintf_append(res, "> %s <\n", e->filename);
} else {
res = talloc_asprintf_append(res, "%s\n", e->filename);
}
}
set_osd_msg(mpctx, OSD_MSG_TEXT, 1, opts->osd_duration, "%s", res);
talloc_free(res);
}
static void change_video_filters(MPContext *mpctx, const char *cmd,
const char *arg)
{
@ -2380,15 +2396,6 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
case MP_CMD_VF:
change_video_filters(mpctx, cmd->args[0].v.s, cmd->args[1].v.s);
break;
case MP_CMD_SHOW_CHAPTERS:
show_chapters_on_osd(mpctx);
break;
case MP_CMD_SHOW_TRACKS:
show_tracks_on_osd(mpctx);
break;
case MP_CMD_SHOW_PLAYLIST:
show_playlist_on_osd(mpctx);
break;
default:
mp_msg(MSGT_CPLAYER, MSGL_V,

View File

@ -204,10 +204,6 @@ static const mp_cmd_t mp_cmds[] = {
{ MP_CMD_VF, "vf", { ARG_STRING, ARG_STRING } },
{ MP_CMD_SHOW_CHAPTERS, "show_chapters", },
{ MP_CMD_SHOW_TRACKS, "show_tracks", },
{ MP_CMD_SHOW_PLAYLIST, "show_playlist", },
{ MP_CMD_VO_CMDLINE, "vo_cmdline", { ARG_STRING } },
{0}
@ -258,8 +254,12 @@ static const struct legacy_cmd legacy_cmds[] = {
{"osd_show_text", "show_text"},
{"osd_show_property_text", "show_text"},
{"osd_show_progression", "show_progress"},
{"show_chapters_osd", "show_chapters"},
{"show_tracks_osd", "show_tracks"},
{"show_chapters_osd", "show_text ${chapter-list}"},
{"!show_chapters", "show_text ${chapter-list}"},
{"show_tracks_osd", "show_text ${track-list}"},
{"!show_tracks", "show_text ${track-list}"},
{"!show_playlist", "show_text ${playlist}"},
// Approximate (can fail if user added additional whitespace)
{"pt_step 1", "playlist_next"},
{"pt_step -1", "playlist_prev"},
@ -826,14 +826,15 @@ mp_cmd_t *mp_input_parse_cmd(bstr str, const char *loc)
str = bstr_lstrip(str);
for (const struct legacy_cmd *entry = legacy_cmds; entry->old; entry++) {
size_t old_len = strlen(entry->old);
if (bstrcasecmp(bstr_splice(str, 0, old_len),
(bstr) {(char *)entry->old, old_len}) == 0)
{
mp_tmsg(MSGT_INPUT, MSGL_WARN, "Warning: command '%s' is "
"deprecated, replaced with '%s' at %s.\n",
entry->old, entry->new, loc);
bstr s = bstr_cut(str, old_len);
bstr old = bstr0(entry->old);
bool silent = bstr_eatstart0(&old, "!");
if (bstrcasecmp(bstr_splice(str, 0, old.len), old) == 0) {
if (!silent) {
mp_tmsg(MSGT_INPUT, MSGL_WARN, "Warning: command '%.*s' is "
"deprecated, replaced with '%s' at %s.\n",
BSTR_P(old), entry->new, loc);
}
bstr s = bstr_cut(str, old.len);
str = bstr0(talloc_asprintf(tmp, "%s%.*s", entry->new, BSTR_P(s)));
start = str;
break;

View File

@ -81,10 +81,6 @@ enum mp_command_type {
/// Video filter commands
MP_CMD_VF,
MP_CMD_SHOW_CHAPTERS,
MP_CMD_SHOW_TRACKS,
MP_CMD_SHOW_PLAYLIST,
/// Video output commands
MP_CMD_VO_CMDLINE,
};