From 6ddd2b8e0348e311eb883511c5cc4d5598bda086 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 30 Oct 2014 23:54:06 +0100 Subject: player: improve exit message in some scenarios If you played e.g. an audio-only file and something bad happened that interrupted playback, the exit message could say "No files played". This was awkward, so show a different message in this case. Also overhaul how the exit status is reported in order to make this easier. This includes things such as not reporting a playback error when loading playlists (playlists contain no video or audio, which was considered an error). Not sure if I'm happy with this, but for now it seems like a slight improvement. --- player/core.h | 18 ++++++-------- player/loadfile.c | 33 +++++++++++--------------- player/main.c | 70 +++++++++++++++++++++++++++++-------------------------- 3 files changed, 58 insertions(+), 63 deletions(-) (limited to 'player') diff --git a/player/core.h b/player/core.h index 32c6b45db6..631e5c75e0 100644 --- a/player/core.h +++ b/player/core.h @@ -41,15 +41,6 @@ enum stop_play_reason { PT_ERROR, // play next playlist entry (due to an error) }; -enum exit_reason { - EXIT_NONE, - EXIT_QUIT, - EXIT_PLAYED, - EXIT_ERROR, - EXIT_NOTPLAYED, - EXIT_SOMENOTPLAYED -}; - struct timeline_part { double start; double source_start; @@ -182,14 +173,19 @@ typedef struct MPContext { char *stream_open_filename; enum stop_play_reason stop_play; bool playback_initialized; // playloop can be run/is running + int error_playing; // Return code to use with PT_QUIT - enum exit_reason quit_player_rc; int quit_custom_rc; bool has_quit_custom_rc; - int error_playing; char **resume_defaults; + // Global file statistics + int files_played; // played without issues (even if stopped by user) + int files_errored; // played, but errors happened at one point + int files_broken; // couldn't be played at all + + // Current file statistics int64_t shown_vframes, shown_aframes; struct stream *stream; // stream that was initially opened diff --git a/player/loadfile.c b/player/loadfile.c index b68926f507..c4ddf51cc5 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -989,7 +989,7 @@ goto_reopen_demuxer: ; for (struct playlist_entry *e = pl->first; e; e = e->next) e->stream_flags |= entry_stream_flags; transfer_playlist(mpctx, pl); - mpctx->error_playing = 0; + mpctx->error_playing = 1; goto terminate_playback; } @@ -1179,16 +1179,16 @@ terminate_playback: mpctx->playback_initialized = false; mp_notify(mpctx, MPV_EVENT_TRACKS_CHANGED, NULL); + + bool nothing_played = !mpctx->shown_aframes && !mpctx->shown_vframes && + mpctx->error_playing <= 0; struct mpv_event_end_file end_event = {0}; switch (mpctx->stop_play) { case PT_ERROR: case AT_END_OF_FILE: { - if (mpctx->error_playing >= 0 && - mpctx->shown_aframes == 0 && mpctx->shown_vframes == 0) - { + if (mpctx->error_playing >= 0 && nothing_played) mpctx->error_playing = MPV_ERROR_NOTHING_TO_PLAY; - } end_event.error = mpctx->error_playing; if (end_event.error < 0) { end_event.reason = MPV_END_FILE_REASON_ERROR; @@ -1199,8 +1199,7 @@ terminate_playback: // Played/paused for longer than 1 second -> ok mpctx->playing->playback_short = playback_start < 0 || mp_time_sec() - playback_start < 1.0; - mpctx->playing->init_failed = - end_event.error == MPV_ERROR_NOTHING_TO_PLAY; + mpctx->playing->init_failed = nothing_played; } break; } @@ -1218,6 +1217,14 @@ terminate_playback: mpctx->filename = NULL; mpctx->stream_open_filename = NULL; + if (end_event.error < 0 && nothing_played) { + mpctx->files_broken++; + } else if (end_event.error < 0) { + mpctx->files_errored++; + } else { + mpctx->files_played++; + } + talloc_free(tmp); } @@ -1273,24 +1280,12 @@ struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction, // Return if all done. void mp_play_files(struct MPContext *mpctx) { - mpctx->quit_player_rc = EXIT_NONE; for (;;) { idle_loop(mpctx); if (mpctx->stop_play == PT_QUIT) break; play_current_file(mpctx); - if (mpctx->error_playing < 0) { - if (!mpctx->quit_player_rc) { - mpctx->quit_player_rc = EXIT_NOTPLAYED; - } else if (mpctx->quit_player_rc == EXIT_PLAYED) { - mpctx->quit_player_rc = EXIT_SOMENOTPLAYED; - } - } else if (mpctx->quit_player_rc == EXIT_NOTPLAYED) { - mpctx->quit_player_rc = EXIT_SOMENOTPLAYED; - } else { - mpctx->quit_player_rc = EXIT_PLAYED; - } if (mpctx->stop_play == PT_QUIT) break; diff --git a/player/main.c b/player/main.c index defceb43e5..ead6807b1e 100644 --- a/player/main.c +++ b/player/main.c @@ -83,6 +83,12 @@ static bool terminal_initialized; +enum exit_reason { + EXIT_NONE, + EXIT_NORMAL, + EXIT_ERROR, +}; + const char mp_help_text[] = "Usage: mpv [options] [url|path/]filename\n" "\n" @@ -161,45 +167,45 @@ void mp_destroy(struct MPContext *mpctx) static MP_NORETURN void exit_player(struct MPContext *mpctx, enum exit_reason how) { - int rc; - #if HAVE_COCOA_APPLICATION cocoa_set_input_context(NULL); #endif - if (how != EXIT_NONE) { - const char *reason; - switch (how) { - case EXIT_SOMENOTPLAYED: - case EXIT_PLAYED: - reason = "End of file"; - break; - case EXIT_NOTPLAYED: - reason = "No files played"; - break; - case EXIT_ERROR: - reason = "Fatal error"; - break; - default: + int rc = 0; + const char *reason = NULL; + + if (how == EXIT_ERROR) { + reason = "Fatal error"; + rc = 1; + } else if (how == EXIT_NORMAL) { + if (mpctx->stop_play == PT_QUIT) { reason = "Quit"; + rc = 0; + } else if (mpctx->files_played) { + if (mpctx->files_errored || mpctx->files_broken) { + reason = "Some errors happened"; + rc = 3; + } else { + reason = "End of file"; + rc = 0; + } + } else if (mpctx->files_broken && !mpctx->files_errored) { + reason = "Errors when loading file"; + rc = 2; + } else if (mpctx->files_errored) { + reason = "Interrupted by error"; + rc = 2; + } else { + reason = "No files played"; + rc = 0; } - MP_INFO(mpctx, "\nExiting... (%s)\n", reason); } - if (mpctx->has_quit_custom_rc) { + if (reason) + MP_INFO(mpctx, "\nExiting... (%s)\n", reason); + + if (mpctx->has_quit_custom_rc) rc = mpctx->quit_custom_rc; - } else { - switch (how) { - case EXIT_ERROR: - rc = 1; break; - case EXIT_NOTPLAYED: - rc = 2; break; - case EXIT_SOMENOTPLAYED: - rc = 3; break; - default: - rc = 0; - } - } mp_destroy(mpctx); @@ -527,8 +533,6 @@ int mpv_main(int argc, char *argv[]) exit_player(mpctx, EXIT_ERROR); mp_play_files(mpctx); - - exit_player(mpctx, mpctx->stop_play == PT_QUIT ? EXIT_QUIT : mpctx->quit_player_rc); - + exit_player(mpctx, EXIT_NORMAL); return 1; } -- cgit v1.2.3