From bda5e6d9fd6827b3e5d4cf3f8cafef5e3e079370 Mon Sep 17 00:00:00 2001 From: Andre D Date: Fri, 2 Aug 2013 01:32:38 -0700 Subject: mplayer: add more verbose exit codes --- core/command.c | 3 ++- core/mp_core.h | 11 +++++++--- core/mplayer.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 61 insertions(+), 17 deletions(-) diff --git a/core/command.c b/core/command.c index 05f361be31..17b01686f2 100644 --- a/core/command.c +++ b/core/command.c @@ -2154,7 +2154,8 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) case MP_CMD_QUIT: mpctx->stop_play = PT_QUIT; - mpctx->quit_player_rc = cmd->args[0].v.i; + mpctx->quit_custom_rc = cmd->args[0].v.i; + mpctx->has_quit_custom_rc = true; break; case MP_CMD_QUIT_WATCH_LATER: diff --git a/core/mp_core.h b/core/mp_core.h index 39a05e0e3b..126c646a0b 100644 --- a/core/mp_core.h +++ b/core/mp_core.h @@ -52,8 +52,10 @@ enum stop_play_reason { enum exit_reason { EXIT_NONE, EXIT_QUIT, - EXIT_EOF, - EXIT_ERROR + EXIT_PLAYED, + EXIT_ERROR, + EXIT_NOTPLAYED, + EXIT_SOMENOTPLAYED }; struct timeline_part { @@ -135,7 +137,10 @@ typedef struct MPContext { unsigned int initialized_flags; // which subsystems have been initialized // Return code to use with PT_QUIT - int quit_player_rc; + enum exit_reason quit_player_rc; + int quit_custom_rc; + bool has_quit_custom_rc; + bool error_playing; struct demuxer **sources; int num_sources; diff --git a/core/mplayer.c b/core/mplayer.c index f8da58df63..2092a04f70 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -549,8 +549,9 @@ void uninit_player(struct MPContext *mpctx, unsigned int mask) } static MP_NORETURN void exit_player(struct MPContext *mpctx, - enum exit_reason how, int rc) + enum exit_reason how) { + int rc; uninit_player(mpctx, INITIALIZED_ALL); #ifdef CONFIG_ENCODING @@ -576,14 +577,37 @@ static MP_NORETURN void exit_player(struct MPContext *mpctx, if (how != EXIT_NONE) { const char *reason; switch (how) { - case EXIT_QUIT: reason = "Quit"; break; - case EXIT_EOF: reason = "End of file"; break; - case EXIT_ERROR: reason = "Fatal error"; break; - default: abort(); + 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: + reason = "Quit"; } mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "\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; + } + } + // must be last since e.g. mp_msg uses option values // that will be freed by this. @@ -3381,6 +3405,7 @@ static void run_playloop(struct MPContext *mpctx) mpctx->current_track[STREAM_VIDEO] = NULL; if (!mpctx->current_track[STREAM_AUDIO]) mpctx->stop_play = PT_NEXT_ENTRY; + mpctx->error_playing = true; break; } video_left = frame_time >= 0; @@ -4385,6 +4410,7 @@ goto_reopen_demuxer: ; if (mpctx->opts->pause) pause_player(mpctx); + mpctx->error_playing = false; while (!mpctx->stop_play) run_playloop(mpctx); @@ -4457,12 +4483,25 @@ struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction) // Return if all done. static void play_files(struct MPContext *mpctx) { + mpctx->quit_player_rc = EXIT_NONE; for (;;) { idle_loop(mpctx); if (mpctx->stop_play == PT_QUIT) break; + mpctx->error_playing = true; play_current_file(mpctx); + if (mpctx->error_playing) { + 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; @@ -4633,20 +4672,20 @@ static int mpv_main(int argc, char *argv[]) print_libav_versions(); if (!parse_cfgfiles(mpctx, mpctx->mconfig)) - exit_player(mpctx, EXIT_ERROR, 1); + exit_player(mpctx, EXIT_ERROR); int r = m_config_parse_mp_command_line(mpctx->mconfig, mpctx->playlist, argc, argv); if (r < 0) { if (r <= M_OPT_EXIT) { - exit_player(mpctx, EXIT_NONE, 0); + exit_player(mpctx, EXIT_NONE); } else { - exit_player(mpctx, EXIT_ERROR, 1); + exit_player(mpctx, EXIT_ERROR); } } if (handle_help_options(mpctx)) - exit_player(mpctx, EXIT_NONE, 0); + exit_player(mpctx, EXIT_NONE); mp_msg(MSGT_CPLAYER, MSGL_V, "Configuration: " CONFIGURATION "\n"); mp_tmsg(MSGT_CPLAYER, MSGL_V, "Command line:"); @@ -4657,7 +4696,7 @@ static int mpv_main(int argc, char *argv[]) if (!mpctx->playlist->first && !opts->player_idle_mode) { mp_print_version(true); mp_msg(MSGT_CPLAYER, MSGL_INFO, "%s", mp_gtext(mp_help_text)); - exit_player(mpctx, EXIT_NONE, 0); + exit_player(mpctx, EXIT_NONE); } #ifdef CONFIG_PRIORITY @@ -4671,7 +4710,7 @@ static int mpv_main(int argc, char *argv[]) mpctx->encode_lavc_ctx = encode_lavc_init(&opts->encode_output); if(!mpctx->encode_lavc_ctx) { mp_msg(MSGT_VO, MSGL_INFO, "Encoding initialization failed."); - exit_player(mpctx, EXIT_ERROR, 1); + exit_player(mpctx, EXIT_ERROR); } m_config_set_option0(mpctx->mconfig, "vo", "lavc"); m_config_set_option0(mpctx->mconfig, "ao", "lavc"); @@ -4691,8 +4730,7 @@ static int mpv_main(int argc, char *argv[]) play_files(mpctx); - exit_player(mpctx, mpctx->stop_play == PT_QUIT ? EXIT_QUIT : EXIT_EOF, - mpctx->quit_player_rc); + exit_player(mpctx, mpctx->stop_play == PT_QUIT ? EXIT_QUIT : mpctx->quit_player_rc); return 1; } -- cgit v1.2.3