diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst index a33bfd8be2..14d3bb0bd0 100644 --- a/DOCS/interface-changes.rst +++ b/DOCS/interface-changes.rst @@ -51,6 +51,11 @@ Interface changes filter chain initialization fails. Instead, the vf/af options are always set to the user's value, even if it does not reflect the "runtime" vf/af chain. + - the vid/aid/sid/secondary-sid properties (and their aliases: "audio", + "video", "sub") will now allow setting any track ID; before this change, + only IDs of actually existing tracks could be set (the restriction was + active the MPV_EVENT_FILE_LOADED/"file-loaded" event was sent). Setting + an ID for which no track exists is equivalent to disabling it. --- mpv 0.30.0 --- - add `--d3d11-output-format` to enable explicit selection of a D3D11 swap chain format. diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index ced5363ea1..70e3a4e8e9 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -2695,11 +2695,11 @@ You can access (almost) all options as properties, though there are some caveats with some properties (due to historical reasons): ``vid``, ``aid``, ``sid`` - While playback is active, you can set existing tracks only. (The option - allows setting any track ID, and which tracks to enable is chosen at - loading time.) + While playback is active, these result the actually active tracks. For + example, if you set ``aid=5``, and the currently played file contains no + audio track with ID 5, the ``aid`` property will return ``no``. - Option changes at runtime are affected by this as well. + Before mpv 0.31.0, you could set existing tracks at runtime only. ``display-fps`` This inconsistent behavior is deprecated. Post-deprecation, the reported diff --git a/player/command.c b/player/command.c index 74db80e7b9..43d1fbb1c4 100644 --- a/player/command.c +++ b/player/command.c @@ -1883,10 +1883,14 @@ static struct track* track_next(struct MPContext *mpctx, enum stream_type type, return direction > 0 ? next : prev; } -static int property_switch_track(struct m_property *prop, int action, void *arg, - MPContext *mpctx, int order, - enum stream_type type) +static int property_switch_track(void *ctx, struct m_property *prop, + int action, void *arg) { + MPContext *mpctx = ctx; + const int *def = prop->priv; + int order = def[0]; + enum stream_type type = def[1]; + struct track *track = mpctx->current_track[order][type]; switch (action) { @@ -1935,16 +1939,6 @@ static int property_switch_track(struct m_property *prop, int action, void *arg, } return M_PROPERTY_OK; } - case M_PROPERTY_SET: - if (mpctx->playback_initialized) { - track = mp_track_by_tid(mpctx, type, *(int *)arg); - mp_switch_track_n(mpctx, order, type, track, FLAG_MARK_SELECTION); - print_track_list(mpctx, "Track switched:"); - mp_wakeup_core(mpctx); - } else { - mpctx->opts->stream_id[order][type] = *(int *)arg; - } - return M_PROPERTY_OK; } return mp_property_generic_option(mpctx, prop, action, arg); } @@ -2080,20 +2074,6 @@ static int property_list_tracks(void *ctx, struct m_property *prop, get_track_entry, mpctx); } -/// Selected audio id (RW) -static int mp_property_audio(void *ctx, struct m_property *prop, - int action, void *arg) -{ - return property_switch_track(prop, action, arg, ctx, 0, STREAM_AUDIO); -} - -/// Selected video id (RW) -static int mp_property_video(void *ctx, struct m_property *prop, - int action, void *arg) -{ - return property_switch_track(prop, action, arg, ctx, 0, STREAM_VIDEO); -} - static int mp_property_hwdec_current(void *ctx, struct m_property *prop, int action, void *arg) { @@ -2741,19 +2721,6 @@ skip_warn: ; return M_PROPERTY_NOT_IMPLEMENTED; } -/// Selected subtitles (RW) -static int mp_property_sub(void *ctx, struct m_property *prop, - int action, void *arg) -{ - return property_switch_track(prop, action, arg, ctx, 0, STREAM_SUB); -} - -static int mp_property_sub2(void *ctx, struct m_property *prop, - int action, void *arg) -{ - return property_switch_track(prop, action, arg, ctx, 1, STREAM_SUB); -} - /// Subtitle delay (RW) static int mp_property_sub_delay(void *ctx, struct m_property *prop, int action, void *arg) @@ -3491,7 +3458,7 @@ static const struct m_property mp_properties_base[] = { {"audio-codec", mp_property_audio_codec}, {"audio-params", mp_property_audio_params}, {"audio-out-params", mp_property_audio_out_params}, - {"aid", mp_property_audio}, + {"aid", property_switch_track, .priv = (void *)(const int[]){0, STREAM_AUDIO}}, {"audio-device", mp_property_audio_device}, {"audio-device-list", mp_property_audio_devices}, {"current-ao", mp_property_ao}, @@ -3519,7 +3486,7 @@ static const struct m_property mp_properties_base[] = { {"container-fps", mp_property_fps}, {"estimated-vf-fps", mp_property_vf_fps}, {"video-aspect", mp_property_aspect}, - {"vid", mp_property_video}, + {"vid", property_switch_track, .priv = (void *)(const int[]){0, STREAM_VIDEO}}, {"hwdec-current", mp_property_hwdec_current}, {"hwdec-interop", mp_property_hwdec_interop}, @@ -3534,8 +3501,9 @@ static const struct m_property mp_properties_base[] = { {"osd-ass-cc", mp_property_osd_ass}, // Subs - {"sid", mp_property_sub}, - {"secondary-sid", mp_property_sub2}, + {"sid", property_switch_track, .priv = (void *)(const int[]){0, STREAM_SUB}}, + {"secondary-sid", property_switch_track, + .priv = (void *)(const int[]){1, STREAM_SUB}}, {"sub-delay", mp_property_sub_delay}, {"sub-speed", mp_property_sub_speed}, {"sub-pos", mp_property_sub_pos}, @@ -6315,6 +6283,20 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags) if (opt_ptr == &opts->af_settings) set_filters(mpctx, STREAM_AUDIO, opts->af_settings); + + for (int order = 0; order < NUM_PTRACKS; order++) { + for (int type = 0; type < STREAM_TYPE_COUNT; type++) { + if (opt_ptr == &opts->stream_id[order][type] && + mpctx->playback_initialized) + { + struct track *track = + mp_track_by_tid(mpctx, type, opts->stream_id[order][type]); + mp_switch_track_n(mpctx, order, type, track, FLAG_MARK_SELECTION); + print_track_list(mpctx, "Track switched:"); + mp_wakeup_core(mpctx); + } + } + } } void mp_notify_property(struct MPContext *mpctx, const char *property)