1
0
mirror of https://github.com/mpv-player/mpv synced 2025-04-01 23:00:41 +00:00

player: simplify reload logic

Instead of only reloading the demuxer, reopen the stream as well.
This commit is contained in:
wm4 2015-07-02 14:38:03 +02:00
parent a9bbaa5eb2
commit a609877f00
4 changed files with 15 additions and 20 deletions

View File

@ -678,7 +678,7 @@ static int mp_property_disc_title(void *ctx, struct m_property *prop,
title = *(int*)arg; title = *(int*)arg;
if (demux_stream_control(d, STREAM_CTRL_SET_CURRENT_TITLE, &title) < 0) if (demux_stream_control(d, STREAM_CTRL_SET_CURRENT_TITLE, &title) < 0)
return M_PROPERTY_NOT_IMPLEMENTED; return M_PROPERTY_NOT_IMPLEMENTED;
mpctx->stop_play = PT_RELOAD_DEMUXER; mpctx->stop_play = PT_RELOAD_FILE;
return M_PROPERTY_OK; return M_PROPERTY_OK;
} }
return M_PROPERTY_NOT_IMPLEMENTED; return M_PROPERTY_NOT_IMPLEMENTED;
@ -837,7 +837,7 @@ static int mp_property_edition(void *ctx, struct m_property *prop,
edition = *(int *)arg; edition = *(int *)arg;
if (edition != demuxer->edition) { if (edition != demuxer->edition) {
opts->edition_id = edition; opts->edition_id = edition;
mpctx->stop_play = PT_RELOAD_DEMUXER; mpctx->stop_play = PT_RELOAD_FILE;
} }
return M_PROPERTY_OK; return M_PROPERTY_OK;
} }
@ -2847,7 +2847,7 @@ static int mp_property_dvb_channel(void *ctx, struct m_property *prop,
mpctx->last_dvb_step = 1; mpctx->last_dvb_step = 1;
r = prop_stream_ctrl(mpctx, STREAM_CTRL_DVB_SET_CHANNEL, arg); r = prop_stream_ctrl(mpctx, STREAM_CTRL_DVB_SET_CHANNEL, arg);
if (r == M_PROPERTY_OK) if (r == M_PROPERTY_OK)
mpctx->stop_play = PT_RELOAD_DEMUXER; mpctx->stop_play = PT_RELOAD_FILE;
return r; return r;
case M_PROPERTY_SWITCH: { case M_PROPERTY_SWITCH: {
struct m_property_switch_arg *sa = arg; struct m_property_switch_arg *sa = arg;
@ -2855,7 +2855,7 @@ static int mp_property_dvb_channel(void *ctx, struct m_property *prop,
mpctx->last_dvb_step = dir; mpctx->last_dvb_step = dir;
r = prop_stream_ctrl(mpctx, STREAM_CTRL_DVB_STEP_CHANNEL, &dir); r = prop_stream_ctrl(mpctx, STREAM_CTRL_DVB_STEP_CHANNEL, &dir);
if (r == M_PROPERTY_OK) if (r == M_PROPERTY_OK)
mpctx->stop_play = PT_RELOAD_DEMUXER; mpctx->stop_play = PT_RELOAD_FILE;
return r; return r;
} }
case M_PROPERTY_GET_TYPE: case M_PROPERTY_GET_TYPE:

View File

@ -37,7 +37,7 @@ enum stop_play_reason {
PT_NEXT_ENTRY, // prepare to play next entry in playlist PT_NEXT_ENTRY, // prepare to play next entry in playlist
PT_CURRENT_ENTRY, // prepare to play mpctx->playlist->current PT_CURRENT_ENTRY, // prepare to play mpctx->playlist->current
PT_STOP, // stop playback, clear playlist PT_STOP, // stop playback, clear playlist
PT_RELOAD_DEMUXER, // restart playback, but keep stream open PT_RELOAD_FILE, // restart playback
PT_QUIT, // stop playback, quit player PT_QUIT, // stop playback, quit player
PT_ERROR, // play next playlist entry (due to an error) PT_ERROR, // play next playlist entry (due to an error)
}; };

View File

@ -234,7 +234,7 @@ void mp_handle_nav(struct MPContext *mpctx)
break; break;
} }
case MP_NAV_EVENT_RESET_ALL: { case MP_NAV_EVENT_RESET_ALL: {
mpctx->stop_play = PT_RELOAD_DEMUXER; mpctx->stop_play = PT_RELOAD_FILE; // would wipe DVD state -> broken
MP_VERBOSE(nav, "reload\n"); MP_VERBOSE(nav, "reload\n");
// return immediately. // return immediately.
// other events should be handled after reloaded. // other events should be handled after reloaded.

View File

@ -1069,6 +1069,8 @@ static void play_current_file(struct MPContext *mpctx)
MP_INFO(mpctx, "Playing: %s\n", mpctx->filename); MP_INFO(mpctx, "Playing: %s\n", mpctx->filename);
reopen_file:
assert(mpctx->stream == NULL); assert(mpctx->stream == NULL);
assert(mpctx->demuxer == NULL); assert(mpctx->demuxer == NULL);
assert(mpctx->d_audio == NULL); assert(mpctx->d_audio == NULL);
@ -1105,8 +1107,6 @@ static void play_current_file(struct MPContext *mpctx)
stream_set_capture_file(mpctx->stream, opts->stream_capture); stream_set_capture_file(mpctx->stream, opts->stream_capture);
goto_reopen_demuxer: ;
mp_nav_reset(mpctx); mp_nav_reset(mpctx);
open_demux_reentrant(mpctx); open_demux_reentrant(mpctx);
@ -1242,16 +1242,6 @@ goto_reopen_demuxer: ;
terminate_playback: terminate_playback:
if (mpctx->stop_play == PT_RELOAD_DEMUXER) {
mpctx->stop_play = KEEP_PLAYING;
mpctx->playback_initialized = false;
uninit_audio_chain(mpctx);
uninit_video_chain(mpctx);
uninit_sub_all(mpctx);
uninit_demuxer(mpctx);
goto goto_reopen_demuxer;
}
process_unload_hooks(mpctx); process_unload_hooks(mpctx);
mp_nav_destroy(mpctx); mp_nav_destroy(mpctx);
@ -1279,13 +1269,18 @@ terminate_playback:
if (!opts->gapless_audio && !mpctx->encode_lavc_ctx) if (!opts->gapless_audio && !mpctx->encode_lavc_ctx)
uninit_audio_out(mpctx); uninit_audio_out(mpctx);
mpctx->playback_initialized = false;
if (mpctx->stop_play == PT_RELOAD_FILE) {
mpctx->stop_play = KEEP_PLAYING;
goto reopen_file;
}
m_config_restore_backups(mpctx->mconfig); m_config_restore_backups(mpctx->mconfig);
talloc_free(mpctx->filtered_tags); talloc_free(mpctx->filtered_tags);
mpctx->filtered_tags = NULL; mpctx->filtered_tags = NULL;
mpctx->playback_initialized = false;
mp_notify(mpctx, MPV_EVENT_TRACKS_CHANGED, NULL); mp_notify(mpctx, MPV_EVENT_TRACKS_CHANGED, NULL);
bool nothing_played = !mpctx->shown_aframes && !mpctx->shown_vframes && bool nothing_played = !mpctx->shown_aframes && !mpctx->shown_vframes &&