0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

player: refactor chapter seek code

mp_seek_chapter() had only 1 caller. Also the code was rather
roundabout; the entire function can be compressed to 5 lines of code.
(The new code is functionally the same - "mpctx->last_chapter_seek =
-2;" was effectively a dead assingment.)
This commit is contained in:
wm4 2015-07-10 12:11:14 +02:00
parent a46de35abb
commit 4e76782630
3 changed files with 7 additions and 24 deletions

View File

@ -762,7 +762,12 @@ static int mp_property_chapter(void *ctx, struct m_property *prop,
mpctx->stop_play = PT_NEXT_ENTRY;
}
} else {
mp_seek_chapter(mpctx, chapter);
double pts = chapter_start_time(mpctx, chapter);
if (pts != MP_NOPTS_VALUE) {
queue_seek(mpctx, MPSEEK_ABSOLUTE, pts, MPSEEK_DEFAULT, true);
mpctx->last_chapter_seek = chapter;
mpctx->last_chapter_pts = pts;
}
}
return M_PROPERTY_OK;
}

View File

@ -451,7 +451,6 @@ void unpause_player(struct MPContext *mpctx);
void add_step_frame(struct MPContext *mpctx, int dir);
void queue_seek(struct MPContext *mpctx, enum seek_type type, double amount,
enum seek_precision exact, bool immediate);
bool mp_seek_chapter(struct MPContext *mpctx, int chapter);
double get_time_length(struct MPContext *mpctx);
double get_current_time(struct MPContext *mpctx);
double get_playback_time(struct MPContext *mpctx);

View File

@ -486,7 +486,7 @@ char *chapter_name(struct MPContext *mpctx, int chapter)
return talloc_strdup(NULL, mpctx->chapters[chapter].name);
}
// returns the start of the chapter in seconds (-1 if unavailable)
// returns the start of the chapter in seconds (NOPTS if unavailable)
double chapter_start_time(struct MPContext *mpctx, int chapter)
{
if (chapter == -1)
@ -501,27 +501,6 @@ int get_chapter_count(struct MPContext *mpctx)
return mpctx->num_chapters;
}
// Seek to a given chapter. Queues the seek.
bool mp_seek_chapter(struct MPContext *mpctx, int chapter)
{
int num = get_chapter_count(mpctx);
if (num == 0)
return false;
if (chapter < -1 || chapter >= num)
return false;
mpctx->last_chapter_seek = -2;
double pts = chapter_start_time(mpctx, chapter);
if (pts == MP_NOPTS_VALUE)
return false;
queue_seek(mpctx, MPSEEK_ABSOLUTE, pts, MPSEEK_DEFAULT, true);
mpctx->last_chapter_seek = chapter;
mpctx->last_chapter_pts = pts;
return true;
}
static void handle_osd_redraw(struct MPContext *mpctx)
{
if (!mpctx->video_out || !mpctx->video_out->config_ok)