summaryrefslogtreecommitdiffstats
path: root/mplayer.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-08-04 02:00:28 +0200
committerwm4 <wm4@nowhere>2012-08-04 19:56:23 +0200
commita4f7a3df50c82a427bde283aeb6a71f0faaec859 (patch)
treef4c6f79413f2af33e171df70496dab8cb92f7d9e /mplayer.c
parentc0abc94a4bf21a69b9e5dfd8d1b02e85b82bc063 (diff)
downloadmpv-a4f7a3df50c82a427bde283aeb6a71f0faaec859.tar.bz2
mpv-a4f7a3df50c82a427bde283aeb6a71f0faaec859.tar.xz
mplayer: fix idle mode regressions
Commit 89a17bcda6c16 simplified the idle loop to run any commands mplayer receives, not just playlist related commands. Unfortunately, it turns out many slave commands always assume the presence of a demuxer. MPContext->demuxer is assumed not to be NULL. This made the player crash when receiving slave commands like pause/unpause, chapter control, subtitle selection. We want mplayer being able to handle this. Any slave command or property, as long as it's backed by a persistent setting, should be run successfully, even if no file is being played. If the slave command doesn't make sense in this state, it shouldn't crash the player. Insert some NULL checks when accessing demuxers. If sh_video or sh_audio are not NULL, assume demuxer can't be NULL. (There actually aren't that many properties which need to be changed. If it gets too complicated, we could employ alternative mechanisms instead, such as explicitly marking safe properties with a flag.)
Diffstat (limited to 'mplayer.c')
-rw-r--r--mplayer.c81
1 files changed, 52 insertions, 29 deletions
diff --git a/mplayer.c b/mplayer.c
index ad18f62730..0bb7f2a4b9 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -448,7 +448,8 @@ static void print_file_properties(struct MPContext *mpctx, const char *filename)
double video_start_pts = MP_NOPTS_VALUE;
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILENAME=%s\n",
filename);
- mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_DEMUXER=%s\n",
+ if (mpctx->demuxer)
+ mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_DEMUXER=%s\n",
mpctx->demuxer->desc->name);
if (mpctx->sh_video) {
/* Assume FOURCC if all bytes >= 0x20 (' ') */
@@ -516,9 +517,9 @@ static void print_file_properties(struct MPContext *mpctx, const char *filename)
talloc_free(name);
}
}
+ for (int n = 0; n < mpctx->demuxer->num_streams; n++)
+ print_stream(mpctx, mpctx->demuxer->streams[n]);
}
- for (int n = 0; n < mpctx->demuxer->num_streams; n++)
- print_stream(mpctx, mpctx->demuxer->streams[n]);
}
/// step size of mixer changes
@@ -2551,7 +2552,9 @@ void pause_player(struct MPContext *mpctx)
if (mpctx->ao && mpctx->sh_audio)
ao_pause(mpctx->ao); // pause audio, keep data if possible
- print_status(mpctx, MP_NOPTS_VALUE, false);
+ // Only print status if there's actually a file being played.
+ if (mpctx->demuxer)
+ print_status(mpctx, MP_NOPTS_VALUE, false);
if (!mpctx->opts.quiet)
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_PAUSED\n");
@@ -2683,6 +2686,9 @@ static int seek(MPContext *mpctx, struct seek_params seek,
{
struct MPOpts *opts = &mpctx->opts;
+ if (!mpctx->demuxer)
+ return -1;
+
if (mpctx->stop_play == AT_END_OF_FILE)
mpctx->stop_play = KEEP_PLAYING;
bool hr_seek = mpctx->demuxer->accurate_seek && opts->correct_pts;
@@ -2816,10 +2822,13 @@ void queue_seek(struct MPContext *mpctx, enum seek_type type, double amount,
double get_time_length(struct MPContext *mpctx)
{
+ struct demuxer *demuxer = mpctx->demuxer;
+ if (!demuxer)
+ return 0;
+
if (mpctx->timeline)
return mpctx->timeline[mpctx->num_timeline_parts].start;
- struct demuxer *demuxer = mpctx->demuxer;
double get_time_ans;
// <= 0 means DEMUXER_CTRL_NOTIMPL or DEMUXER_CTRL_DONTKNOW
if (demux_control(demuxer, DEMUXER_CTRL_GET_TIME_LENGTH,
@@ -2846,6 +2855,8 @@ double get_time_length(struct MPContext *mpctx)
double get_current_time(struct MPContext *mpctx)
{
struct demuxer *demuxer = mpctx->demuxer;
+ if (!demuxer)
+ return 0;
if (demuxer->stream_pts != MP_NOPTS_VALUE)
return demuxer->stream_pts;
if (mpctx->sh_video) {
@@ -2862,6 +2873,8 @@ double get_current_time(struct MPContext *mpctx)
int get_percent_pos(struct MPContext *mpctx)
{
struct demuxer *demuxer = mpctx->demuxer;
+ if (!demuxer)
+ return 0;
int ans = 0;
if (mpctx->timeline)
ans = get_current_time(mpctx) * 100 /
@@ -2888,15 +2901,17 @@ int get_percent_pos(struct MPContext *mpctx)
int get_current_chapter(struct MPContext *mpctx)
{
double current_pts = get_current_time(mpctx);
- if (!mpctx->chapters)
+ if (mpctx->chapters) {
+ int i;
+ for (i = 1; i < mpctx->num_chapters; i++)
+ if (current_pts < mpctx->chapters[i].start)
+ break;
+ return FFMAX(mpctx->last_chapter_seek, i - 1);
+ }
+ if (mpctx->demuxer)
return FFMAX(mpctx->last_chapter_seek,
demuxer_get_current_chapter(mpctx->demuxer, current_pts));
-
- int i;
- for (i = 1; i < mpctx->num_chapters; i++)
- if (current_pts < mpctx->chapters[i].start)
- break;
- return FFMAX(mpctx->last_chapter_seek, i - 1);
+ return -2;
}
char *chapter_display_name(struct MPContext *mpctx, int chapter)
@@ -2918,30 +2933,46 @@ char *chapter_display_name(struct MPContext *mpctx, int chapter)
// returns NULL if chapter name unavailable
char *chapter_name(struct MPContext *mpctx, int chapter)
{
- if (!mpctx->chapters)
+ if (mpctx->chapters)
+ return talloc_strdup(NULL, mpctx->chapters[chapter].name);
+ if (mpctx->demuxer)
return demuxer_chapter_name(mpctx->demuxer, chapter);
- return talloc_strdup(NULL, mpctx->chapters[chapter].name);
+ return NULL;
}
-// returns the start of the chapter in seconds
+// returns the start of the chapter in seconds (-1 if unavailable)
double chapter_start_time(struct MPContext *mpctx, int chapter)
{
- if (!mpctx->chapters)
+ if (mpctx->chapters)
+ return mpctx->chapters[chapter].start;
+ if (mpctx->demuxer)
return demuxer_chapter_time(mpctx->demuxer, chapter, NULL);
- return mpctx->chapters[chapter].start;
+ return -1;
}
int get_chapter_count(struct MPContext *mpctx)
{
- if (!mpctx->chapters)
+ if (mpctx->chapters)
+ return mpctx->num_chapters;
+ if (mpctx->demuxer)
return demuxer_chapter_count(mpctx->demuxer);
- return mpctx->num_chapters;
+ return 0;
}
int seek_chapter(struct MPContext *mpctx, int chapter, double *seek_pts)
{
mpctx->last_chapter_seek = -2;
- if (!mpctx->chapters) {
+ if (mpctx->chapters) {
+ if (chapter >= mpctx->num_chapters)
+ return -1;
+ if (chapter < 0)
+ chapter = 0;
+ *seek_pts = mpctx->chapters[chapter].start;
+ mpctx->last_chapter_seek = chapter;
+ mpctx->last_chapter_pts = *seek_pts;
+ return chapter;
+ }
+ if (mpctx->demuxer) {
int res = demuxer_seek_chapter(mpctx->demuxer, chapter, seek_pts);
if (res >= 0) {
if (*seek_pts == -1)
@@ -2953,15 +2984,7 @@ int seek_chapter(struct MPContext *mpctx, int chapter, double *seek_pts)
}
return res;
}
-
- if (chapter >= mpctx->num_chapters)
- return -1;
- if (chapter < 0)
- chapter = 0;
- *seek_pts = mpctx->chapters[chapter].start;
- mpctx->last_chapter_seek = chapter;
- mpctx->last_chapter_pts = *seek_pts;
- return chapter;
+ return -1;
}