From 5cae4a807ca3d3c04932490f0b6f72ce1bf57a53 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 25 Mar 2014 02:10:24 +0100 Subject: player: remove weird separation between no chapters and 0 chapters For some reason, it mattered whether mpctx->chapters was NULL or not, even if mpctx->num_chapters was 0. Remove this separation; it serves no purpose. --- player/core.h | 2 -- player/playloop.c | 26 +++++++++++--------------- 2 files changed, 11 insertions(+), 17 deletions(-) (limited to 'player') diff --git a/player/core.h b/player/core.h index 5927091233..bda0309f9d 100644 --- a/player/core.h +++ b/player/core.h @@ -194,8 +194,6 @@ typedef struct MPContext { struct timeline_part *timeline; int num_timeline_parts; int timeline_part; - // NOTE: even if num_chapters==0, chapters being not NULL signifies presence - // of chapter metadata struct chapter *chapters; int num_chapters; double video_offset; diff --git a/player/playloop.c b/player/playloop.c index 790aeaa3ee..fa014d7397 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -501,15 +501,14 @@ int get_percent_pos(struct MPContext *mpctx) // -2 is no chapters, -1 is before first chapter int get_current_chapter(struct MPContext *mpctx) { + if (!mpctx->num_chapters) + return -2; double current_pts = get_current_time(mpctx); - if (mpctx->chapters) { - int i; - for (i = 1; i < mpctx->num_chapters; i++) - if (current_pts < mpctx->chapters[i].start) - break; - return MPMAX(mpctx->last_chapter_seek, i - 1); - } - return -2; + int i; + for (i = 1; i < mpctx->num_chapters; i++) + if (current_pts < mpctx->chapters[i].start) + break; + return MPMAX(mpctx->last_chapter_seek, i - 1); } char *chapter_display_name(struct MPContext *mpctx, int chapter) @@ -536,12 +535,9 @@ 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 (chapter < 0 || chapter >= mpctx->num_chapters) - return NULL; - return talloc_strdup(NULL, mpctx->chapters[chapter].name); - } - return NULL; + if (chapter < 0 || chapter >= mpctx->num_chapters) + return NULL; + return talloc_strdup(NULL, mpctx->chapters[chapter].name); } // returns the start of the chapter in seconds (-1 if unavailable) @@ -549,7 +545,7 @@ double chapter_start_time(struct MPContext *mpctx, int chapter) { if (chapter == -1) return get_start_time(mpctx); - if (mpctx->chapters && chapter < mpctx->num_chapters) + if (chapter >= 0 && chapter < mpctx->num_chapters) return mpctx->chapters[chapter].start; return -1.0; } -- cgit v1.2.3