summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c170
1 files changed, 93 insertions, 77 deletions
diff --git a/player/command.c b/player/command.c
index 3c7cfb282d..642330e34f 100644
--- a/player/command.c
+++ b/player/command.c
@@ -350,7 +350,7 @@ static int mp_property_stream_open_filename(void *ctx, struct m_property *prop,
return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_SET: {
- if (mpctx->stream)
+ if (mpctx->demuxer)
return M_PROPERTY_ERROR;
mpctx->stream_open_filename =
talloc_strdup(mpctx->stream_open_filename, *(char **)arg);
@@ -390,14 +390,14 @@ static int mp_property_media_title(void *ctx, struct m_property *prop,
name = mpctx->opts->media_title;
if (name && name[0])
return m_property_strdup_ro(action, arg, name);
- if (mpctx->master_demuxer) {
- name = mp_tags_get_str(mpctx->master_demuxer->metadata, "service_name");
+ if (mpctx->demuxer) {
+ name = mp_tags_get_str(mpctx->demuxer->metadata, "service_name");
if (name && name[0])
return m_property_strdup_ro(action, arg, name);
- name = mp_tags_get_str(mpctx->master_demuxer->metadata, "title");
+ name = mp_tags_get_str(mpctx->demuxer->metadata, "title");
if (name && name[0])
return m_property_strdup_ro(action, arg, name);
- name = mp_tags_get_str(mpctx->master_demuxer->metadata, "icy-title");
+ name = mp_tags_get_str(mpctx->demuxer->metadata, "icy-title");
if (name && name[0])
return m_property_strdup_ro(action, arg, name);
}
@@ -439,7 +439,7 @@ static int mp_property_demuxer(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- struct demuxer *demuxer = mpctx->master_demuxer;
+ struct demuxer *demuxer = mpctx->demuxer;
if (!demuxer)
return M_PROPERTY_UNAVAILABLE;
return m_property_strdup_ro(action, arg, demuxer->desc->name);
@@ -449,7 +449,7 @@ static int mp_property_file_format(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- struct demuxer *demuxer = mpctx->master_demuxer;
+ struct demuxer *demuxer = mpctx->demuxer;
if (!demuxer)
return M_PROPERTY_UNAVAILABLE;
const char *name = demuxer->filetype ? demuxer->filetype : demuxer->desc->name;
@@ -536,7 +536,7 @@ static int mp_property_avsync(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- if (!mpctx->d_audio || !mpctx->vo_chain)
+ if (!mpctx->ao_chain || !mpctx->vo_chain)
return M_PROPERTY_UNAVAILABLE;
if (action == M_PROPERTY_PRINT) {
*(char **)arg = talloc_asprintf(NULL, "%7.3f", mpctx->last_av_difference);
@@ -549,7 +549,7 @@ static int mp_property_total_avsync_change(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- if (!mpctx->d_audio || !mpctx->vo_chain)
+ if (!mpctx->ao_chain || !mpctx->vo_chain)
return M_PROPERTY_UNAVAILABLE;
if (mpctx->total_avsync_change == MP_NOPTS_VALUE)
return M_PROPERTY_UNAVAILABLE;
@@ -734,7 +734,7 @@ static int mp_property_disc_title(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- struct demuxer *d = mpctx->master_demuxer;
+ struct demuxer *d = mpctx->demuxer;
if (!d)
return M_PROPERTY_UNAVAILABLE;
unsigned int title = -1;
@@ -887,7 +887,7 @@ static int mp_property_edition(void *ctx, struct m_property *prop,
{
MPContext *mpctx = ctx;
struct MPOpts *opts = mpctx->opts;
- struct demuxer *demuxer = mpctx->master_demuxer;
+ struct demuxer *demuxer = mpctx->demuxer;
if (!demuxer)
return M_PROPERTY_UNAVAILABLE;
if (demuxer->num_editions <= 0)
@@ -926,7 +926,7 @@ static int get_edition_entry(int item, int action, void *arg, void *ctx)
{
struct MPContext *mpctx = ctx;
- struct demuxer *demuxer = mpctx->master_demuxer;
+ struct demuxer *demuxer = mpctx->demuxer;
struct demux_edition *ed = &demuxer->editions[item];
char *title = mp_tags_get_str(ed->metadata, "title");
@@ -946,7 +946,7 @@ static int property_list_editions(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- struct demuxer *demuxer = mpctx->master_demuxer;
+ struct demuxer *demuxer = mpctx->demuxer;
if (!demuxer)
return M_PROPERTY_UNAVAILABLE;
@@ -987,7 +987,7 @@ static int mp_property_disc_titles(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- struct demuxer *demuxer = mpctx->master_demuxer;
+ struct demuxer *demuxer = mpctx->demuxer;
unsigned int num_titles;
if (!demuxer || demux_stream_control(demuxer, STREAM_CTRL_GET_NUM_TITLES,
&num_titles) < 1)
@@ -998,7 +998,7 @@ static int mp_property_disc_titles(void *ctx, struct m_property *prop,
static int get_disc_title_entry(int item, int action, void *arg, void *ctx)
{
struct MPContext *mpctx = ctx;
- struct demuxer *demuxer = mpctx->master_demuxer;
+ struct demuxer *demuxer = mpctx->demuxer;
double len = item;
if (demux_stream_control(demuxer, STREAM_CTRL_GET_TITLE_LENGTH, &len) < 1)
@@ -1018,7 +1018,7 @@ static int mp_property_list_disc_titles(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- struct demuxer *demuxer = mpctx->master_demuxer;
+ struct demuxer *demuxer = mpctx->demuxer;
unsigned int num_titles;
if (!demuxer || demux_stream_control(demuxer, STREAM_CTRL_GET_NUM_TITLES,
&num_titles) < 1)
@@ -1042,7 +1042,7 @@ static int mp_property_editions(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- struct demuxer *demuxer = mpctx->master_demuxer;
+ struct demuxer *demuxer = mpctx->demuxer;
if (!demuxer)
return M_PROPERTY_UNAVAILABLE;
if (demuxer->num_editions <= 0)
@@ -1055,7 +1055,7 @@ static int mp_property_angle(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- struct demuxer *demuxer = mpctx->master_demuxer;
+ struct demuxer *demuxer = mpctx->demuxer;
if (!demuxer)
return M_PROPERTY_UNAVAILABLE;
@@ -1196,7 +1196,7 @@ static int mp_property_metadata(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- struct demuxer *demuxer = mpctx->master_demuxer;
+ struct demuxer *demuxer = mpctx->demuxer;
if (!demuxer)
return M_PROPERTY_UNAVAILABLE;
@@ -1242,9 +1242,9 @@ static int mp_property_filter_metadata(void *ctx, struct m_property *prop,
struct vf_chain *vf = mpctx->vo_chain->vf;
res = vf_control_by_label(vf, VFCTRL_GET_METADATA, &metadata, key);
} else if (strcmp(type, "af") == 0) {
- if (!(mpctx->d_audio && mpctx->d_audio->afilter))
+ if (!(mpctx->ao_chain && mpctx->ao_chain->af))
return M_PROPERTY_UNAVAILABLE;
- struct af_stream *af = mpctx->d_audio->afilter;
+ struct af_stream *af = mpctx->ao_chain->af;
res = af_control_by_label(af, AF_CONTROL_GET_METADATA, &metadata, key);
}
switch (res) {
@@ -1538,13 +1538,18 @@ static int mp_property_partially_seekable(void *ctx, struct m_property *prop,
return m_property_flag_ro(action, arg, mpctx->demuxer->partially_seekable);
}
+static int mp_property_mixer_active(void *ctx, struct m_property *prop,
+ int action, void *arg)
+{
+ MPContext *mpctx = ctx;
+ return m_property_flag_ro(action, arg, mixer_audio_initialized(mpctx->mixer));
+}
+
/// Volume (RW)
static int mp_property_volume(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- if (!mixer_audio_initialized(mpctx->mixer))
- return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_GET:
mixer_getbothvolume(mpctx->mixer, arg);
@@ -1578,13 +1583,18 @@ static int mp_property_volume(void *ctx, struct m_property *prop,
return M_PROPERTY_NOT_IMPLEMENTED;
}
+static int mp_property_volume_max(void *ctx, struct m_property *prop,
+ int action, void *arg)
+{
+ MPContext *mpctx = ctx;
+ return m_property_float_ro(action, arg, mixer_getmaxvolume(mpctx->mixer));
+}
+
/// Mute (RW)
static int mp_property_mute(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- if (!mixer_audio_initialized(mpctx->mixer))
- return M_PROPERTY_ERROR;
switch (action) {
case M_PROPERTY_SET:
mixer_setmute(mpctx->mixer, *(int *) arg);
@@ -1696,7 +1706,7 @@ static int mp_property_audio_delay(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- if (!(mpctx->d_audio && mpctx->vo_chain))
+ if (!(mpctx->ao_chain && mpctx->vo_chain))
return M_PROPERTY_UNAVAILABLE;
float delay = mpctx->opts->audio_delay;
switch (action) {
@@ -1716,7 +1726,8 @@ static int mp_property_audio_codec_name(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- const char *c = mpctx->d_audio ? mpctx->d_audio->header->codec->codec : NULL;
+ struct track *track = mpctx->current_track[0][STREAM_AUDIO];
+ const char *c = track && track->stream ? track->stream->codec->codec : NULL;
return m_property_strdup_ro(action, arg, c);
}
@@ -1725,7 +1736,8 @@ static int mp_property_audio_codec(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- const char *c = mpctx->d_audio ? mpctx->d_audio->decoder_desc : NULL;
+ struct track *track = mpctx->current_track[0][STREAM_AUDIO];
+ const char *c = track && track->d_audio ? track->d_audio->decoder_desc : NULL;
return m_property_strdup_ro(action, arg, c);
}
@@ -1751,8 +1763,8 @@ static int mp_property_audio_params(void *ctx, struct m_property *prop,
{
MPContext *mpctx = ctx;
struct mp_audio fmt = {0};
- if (mpctx->d_audio)
- fmt = mpctx->d_audio->decode_format;
+ if (mpctx->ao_chain)
+ fmt = mpctx->ao_chain->input_format;
return property_audiofmt(fmt, action, arg);
}
@@ -1808,27 +1820,18 @@ static int mp_property_balance(void *ctx, struct m_property *prop,
return M_PROPERTY_NOT_IMPLEMENTED;
}
-static struct track* track_next(struct MPContext *mpctx, int order,
- enum stream_type type, int direction,
- struct track *track)
+static struct track* track_next(struct MPContext *mpctx, enum stream_type type,
+ int direction, struct track *track)
{
assert(direction == -1 || direction == +1);
struct track *prev = NULL, *next = NULL;
bool seen = track == NULL;
for (int n = 0; n < mpctx->num_tracks; n++) {
struct track *cur = mpctx->tracks[n];
- // One track can be selected only one time - pretend already selected
- // tracks don't exist.
- for (int r = 0; r < NUM_PTRACKS; r++) {
- if (r != order && mpctx->current_track[r][type] == cur)
- cur = NULL;
- }
- if (!cur)
- continue;
if (cur->type == type) {
if (cur == track) {
seen = true;
- } else {
+ } else if (!cur->selected) {
if (seen && !next) {
next = cur;
}
@@ -1877,7 +1880,7 @@ static int property_switch_track(struct m_property *prop, int action, void *arg,
return M_PROPERTY_ERROR;
struct m_property_switch_arg *sarg = arg;
mp_switch_track_n(mpctx, order, type,
- track_next(mpctx, order, type, sarg->inc >= 0 ? +1 : -1, track),
+ track_next(mpctx, type, sarg->inc >= 0 ? +1 : -1, track),
FLAG_MARK_SELECTION);
print_track_list(mpctx, "Track switched:");
return M_PROPERTY_OK;
@@ -2013,7 +2016,7 @@ static int property_list_tracks(void *ctx, struct m_property *prop,
res = talloc_asprintf_append(res, "\n");
}
- struct demuxer *demuxer = mpctx->master_demuxer;
+ struct demuxer *demuxer = mpctx->demuxer;
if (demuxer && demuxer->num_editions > 1)
res = talloc_asprintf_append(res, "\nEdition: %d of %d\n",
demuxer->edition + 1,
@@ -2058,7 +2061,7 @@ static int mp_property_program(void *ctx, struct m_property *prop,
MPContext *mpctx = ctx;
demux_program_t prog;
- struct demuxer *demuxer = mpctx->master_demuxer;
+ struct demuxer *demuxer = mpctx->demuxer;
if (!demuxer)
return M_PROPERTY_UNAVAILABLE;
@@ -2119,9 +2122,8 @@ static int mp_property_hwdec(void *ctx, struct m_property *prop,
int current = -2;
video_vd_control(vd, VDCTRL_GET_HWDEC, &current);
if (current != opts->hwdec_api) {
+ video_vd_control(vd, VDCTRL_REINIT, NULL);
double last_pts = mpctx->last_vo_pts;
- uninit_video_chain(mpctx);
- reinit_video_chain(mpctx);
if (last_pts != MP_NOPTS_VALUE)
queue_seek(mpctx, MPSEEK_ABSOLUTE, last_pts, MPSEEK_EXACT, true);
}
@@ -2438,7 +2440,7 @@ static int mp_property_video_codec(void *ctx, struct m_property *prop,
{
MPContext *mpctx = ctx;
struct track *track = mpctx->current_track[0][STREAM_VIDEO];
- const char *c = track->d_video ? track->d_video->decoder_desc : NULL;
+ const char *c = track && track->d_video ? track->d_video->decoder_desc : NULL;
return m_property_strdup_ro(action, arg, c);
}
@@ -2507,9 +2509,9 @@ static int mp_property_vd_imgparams(void *ctx, struct m_property *prop,
{
MPContext *mpctx = ctx;
struct vo_chain *vo_c = mpctx->vo_chain;
- struct track *track = mpctx->current_track[0][STREAM_VIDEO];
- if (!vo_c || !track)
+ if (!vo_c)
return M_PROPERTY_UNAVAILABLE;
+ struct track *track = mpctx->current_track[0][STREAM_VIDEO];
struct mp_codec_params *c =
track && track->stream ? track->stream->codec : NULL;
if (vo_c->vf->input_params.imgfmt) {
@@ -2765,10 +2767,27 @@ static int mp_property_aspect(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
+
+ float aspect = mpctx->opts->movie_aspect;
+ if (mpctx->vo_chain && aspect <= 0) {
+ struct mp_image_params *params = &mpctx->vo_chain->vf->input_params;
+ if (params && params->p_w > 0 && params->p_h > 0) {
+ int d_w, d_h;
+ mp_image_params_get_dsize(params, &d_w, &d_h);
+ aspect = (float)d_w / d_h;
+ }
+ }
+ struct track *track = mpctx->current_track[0][STREAM_VIDEO];
+ if (track && track->d_video && aspect <= 0) {
+ struct dec_video *d_video = track->d_video;
+ struct mp_codec_params *c = d_video->header->codec;
+ if (c->disp_w && c->disp_h)
+ aspect = (float)c->disp_w / c->disp_h;
+ }
+
switch (action) {
case M_PROPERTY_SET: {
mpctx->opts->movie_aspect = *(float *)arg;
- struct track *track = mpctx->current_track[0][STREAM_VIDEO];
if (track && track->d_video) {
video_reset_aspect(track->d_video);
mp_force_video_refresh(mpctx);
@@ -2777,26 +2796,12 @@ static int mp_property_aspect(void *ctx, struct m_property *prop,
}
case M_PROPERTY_PRINT: {
if (mpctx->opts->movie_aspect <= 0) {
- *(char **)arg = talloc_strdup(NULL, "(original)");
+ *(char **)arg = talloc_asprintf(NULL, "%.3f (original)", aspect);
return M_PROPERTY_OK;
}
break;
}
case M_PROPERTY_GET: {
- float aspect = mpctx->opts->movie_aspect;
- struct track *track = mpctx->current_track[0][STREAM_VIDEO];
- if (track && track->d_video && mpctx->vo_chain && aspect <= 0) {
- struct dec_video *d_video = track->d_video;
- struct mp_codec_params *c = d_video->header->codec;
- struct mp_image_params *params = &mpctx->vo_chain->vf->input_params;
- if (params && params->p_w > 0 && params->p_h > 0) {
- int d_w, d_h;
- mp_image_params_get_dsize(params, &d_w, &d_h);
- aspect = (float)d_w / d_h;
- } else if (c->disp_w && c->disp_h) {
- aspect = (float)c->disp_w / c->disp_h;
- }
- }
*(float *)arg = aspect;
return M_PROPERTY_OK;
}
@@ -3551,7 +3556,9 @@ static const struct m_property mp_properties[] = {
M_PROPERTY_ALIAS("playlist-count", "playlist/count"),
// Audio
+ {"mixer-active", mp_property_mixer_active},
{"volume", mp_property_volume},
+ {"volume-max", mp_property_volume_max},
{"mute", mp_property_mute},
{"audio-delay", mp_property_audio_delay},
{"audio-codec-name", mp_property_audio_codec_name},
@@ -3732,7 +3739,7 @@ static const char *const *const mp_event_property_change[] = {
E(MPV_EVENT_AUDIO_RECONFIG, "audio-format", "audio-codec", "audio-bitrate",
"samplerate", "channels", "audio", "volume", "mute", "balance",
"volume-restore-data", "current-ao", "audio-codec-name", "audio-params",
- "audio-out-params"),
+ "audio-out-params", "volume-max", "mixer-active"),
E(MPV_EVENT_SEEK, "seeking", "core-idle", "eof-reached"),
E(MPV_EVENT_PLAYBACK_RESTART, "seeking", "core-idle", "eof-reached"),
E(MPV_EVENT_METADATA_UPDATE, "metadata", "filtered-metadata", "media-title"),
@@ -4037,9 +4044,6 @@ static int set_filters(struct MPContext *mpctx, enum stream_type mediatype,
reinit_filters(mpctx, mediatype);
}
- if (mediatype == STREAM_VIDEO)
- mp_force_video_refresh(mpctx);
-
return success ? 0 : -1;
}
@@ -4581,7 +4585,7 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
// frame which actually shows the sub first (because video
// frame PTS and sub PTS rarely match exactly). Add some
// rounding for the mess of it.
- a[0] += 0.01 * (a[1] > 0 ? 1 : -1);
+ a[0] += 0.01 * (a[1] >= 0 ? 1 : -1);
mark_seek(mpctx);
queue_seek(mpctx, MPSEEK_RELATIVE, a[0], MPSEEK_EXACT, false);
set_osd_function(mpctx, (a[0] > 0) ? OSD_FFW : OSD_REW);
@@ -4929,6 +4933,18 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
return edit_filters_osd(mpctx, STREAM_VIDEO, cmd->args[0].v.s,
cmd->args[1].v.s, msg_osd);
+ case MP_CMD_VF_COMMAND:
+ if (!mpctx->vo_chain)
+ return -1;
+ return vf_send_command(mpctx->vo_chain->vf, cmd->args[0].v.s,
+ cmd->args[1].v.s, cmd->args[2].v.s);
+
+ case MP_CMD_AF_COMMAND:
+ if (!mpctx->ao_chain)
+ return -1;
+ return af_send_command(mpctx->ao_chain->af, cmd->args[0].v.s,
+ cmd->args[1].v.s, cmd->args[2].v.s);
+
case MP_CMD_SCRIPT_BINDING: {
mpv_event_client_message event = {0};
char *name = cmd->args[0].v.s;
@@ -5027,7 +5043,7 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
const int x = cmd->args[0].v.i, y = cmd->args[1].v.i;
int button = cmd->args[2].v.i;
if (button == -1) {// no button
- mp_input_set_mouse_pos(mpctx->input, x, y);
+ mp_input_set_mouse_pos_artificial(mpctx->input, x, y);
break;
}
if (button < 0 || button >= 20) {// invalid button
@@ -5036,8 +5052,8 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
}
const bool dbc = cmd->args[3].v.i;
button += dbc ? MP_MOUSE_BASE_DBL : MP_MOUSE_BASE;
- mp_input_set_mouse_pos(mpctx->input, x, y);
- mp_input_put_key(mpctx->input, button);
+ mp_input_set_mouse_pos_artificial(mpctx->input, x, y);
+ mp_input_put_key_artificial(mpctx->input, button);
break;
}
@@ -5052,21 +5068,21 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
if (cmd->id == MP_CMD_KEYDOWN)
code |= MP_KEY_STATE_DOWN;
- mp_input_put_key(mpctx->input, code);
+ mp_input_put_key_artificial(mpctx->input, code);
break;
}
case MP_CMD_KEYUP: {
const char *key_name = cmd->args[0].v.s;
if (key_name[0] == '\0') {
- mp_input_put_key(mpctx->input, MP_INPUT_RELEASE_ALL);
+ mp_input_put_key_artificial(mpctx->input, MP_INPUT_RELEASE_ALL);
} else {
int code = mp_input_get_key_from_name(key_name);
if (code < 0) {
MP_ERR(mpctx, "%s is not a valid input name.\n", key_name);
return -1;
}
- mp_input_put_key(mpctx->input, code | MP_KEY_STATE_UP);
+ mp_input_put_key_artificial(mpctx->input, code | MP_KEY_STATE_UP);
}
break;
}