Skip to content

Commit

Permalink
player: simplify reload logic
Browse files Browse the repository at this point in the history
Instead of only reloading the demuxer, reopen the stream as well.
  • Loading branch information
wm4 committed Jul 2, 2015
1 parent a9bbaa5 commit a609877
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
8 changes: 4 additions & 4 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ static int mp_property_disc_title(void *ctx, struct m_property *prop,
title = *(int*)arg;
if (demux_stream_control(d, STREAM_CTRL_SET_CURRENT_TITLE, &title) < 0)
return M_PROPERTY_NOT_IMPLEMENTED;
mpctx->stop_play = PT_RELOAD_DEMUXER;
mpctx->stop_play = PT_RELOAD_FILE;
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
Expand Down Expand Up @@ -837,7 +837,7 @@ static int mp_property_edition(void *ctx, struct m_property *prop,
edition = *(int *)arg;
if (edition != demuxer->edition) {
opts->edition_id = edition;
mpctx->stop_play = PT_RELOAD_DEMUXER;
mpctx->stop_play = PT_RELOAD_FILE;
}
return M_PROPERTY_OK;
}
Expand Down Expand Up @@ -2847,15 +2847,15 @@ static int mp_property_dvb_channel(void *ctx, struct m_property *prop,
mpctx->last_dvb_step = 1;
r = prop_stream_ctrl(mpctx, STREAM_CTRL_DVB_SET_CHANNEL, arg);
if (r == M_PROPERTY_OK)
mpctx->stop_play = PT_RELOAD_DEMUXER;
mpctx->stop_play = PT_RELOAD_FILE;
return r;
case M_PROPERTY_SWITCH: {
struct m_property_switch_arg *sa = arg;
int dir = sa->inc >= 0 ? 1 : -1;
mpctx->last_dvb_step = dir;
r = prop_stream_ctrl(mpctx, STREAM_CTRL_DVB_STEP_CHANNEL, &dir);
if (r == M_PROPERTY_OK)
mpctx->stop_play = PT_RELOAD_DEMUXER;
mpctx->stop_play = PT_RELOAD_FILE;
return r;
}
case M_PROPERTY_GET_TYPE:
Expand Down
2 changes: 1 addition & 1 deletion player/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum stop_play_reason {
PT_NEXT_ENTRY, // prepare to play next entry in playlist
PT_CURRENT_ENTRY, // prepare to play mpctx->playlist->current
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_ERROR, // play next playlist entry (due to an error)
};
Expand Down
2 changes: 1 addition & 1 deletion player/discnav.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ void mp_handle_nav(struct MPContext *mpctx)
break;
}
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");
// return immediately.
// other events should be handled after reloaded.
Expand Down
23 changes: 9 additions & 14 deletions player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,8 @@ static void play_current_file(struct MPContext *mpctx)

MP_INFO(mpctx, "Playing: %s\n", mpctx->filename);

reopen_file:

assert(mpctx->stream == NULL);
assert(mpctx->demuxer == NULL);
assert(mpctx->d_audio == NULL);
Expand Down Expand Up @@ -1105,8 +1107,6 @@ static void play_current_file(struct MPContext *mpctx)

stream_set_capture_file(mpctx->stream, opts->stream_capture);

goto_reopen_demuxer: ;

mp_nav_reset(mpctx);

open_demux_reentrant(mpctx);
Expand Down Expand Up @@ -1242,16 +1242,6 @@ goto_reopen_demuxer: ;

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);

mp_nav_destroy(mpctx);
Expand Down Expand Up @@ -1279,13 +1269,18 @@ goto_reopen_demuxer: ;
if (!opts->gapless_audio && !mpctx->encode_lavc_ctx)
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);

talloc_free(mpctx->filtered_tags);
mpctx->filtered_tags = NULL;

mpctx->playback_initialized = false;

mp_notify(mpctx, MPV_EVENT_TRACKS_CHANGED, NULL);

bool nothing_played = !mpctx->shown_aframes && !mpctx->shown_vframes &&
Expand Down

0 comments on commit a609877

Please sign in to comment.