From e8a996cedef347f9a4cee1172db39e7f0eea821f Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 27 Apr 2014 22:28:07 +0200 Subject: client API: add chapter change event Also works for mpv_observe_property() on the "chapter" property. --- player/client.c | 1 + player/command.c | 1 + player/core.h | 2 ++ player/loadfile.c | 1 + player/main.c | 1 + player/playloop.c | 11 +++++++++++ 6 files changed, 17 insertions(+) (limited to 'player') diff --git a/player/client.c b/player/client.c index 083785b0ee..7282d20603 100644 --- a/player/client.c +++ b/player/client.c @@ -1317,6 +1317,7 @@ static const char *event_table[] = { [MPV_EVENT_SEEK] = "seek", [MPV_EVENT_PLAYBACK_RESTART] = "playback-restart", [MPV_EVENT_PROPERTY_CHANGE] = "property-change", + [MPV_EVENT_CHAPTER_CHANGE] = "chapter-change", }; const char *mpv_event_name(mpv_event_id event) diff --git a/player/command.c b/player/command.c index fd08c667c8..d938e48162 100644 --- a/player/command.c +++ b/player/command.c @@ -2443,6 +2443,7 @@ const char **mp_event_property_change[] = { E(MPV_EVENT_AUDIO_RECONFIG, "audio-format", "audio-codec", "audio-bitrate", "samplerate", "channels", "audio"), E(MPV_EVENT_METADATA_UPDATE, "metadata"), + E(MPV_EVENT_CHAPTER_CHANGE, "chapter", "chapter-metadata"), }; #undef E diff --git a/player/core.h b/player/core.h index a360be4aa8..bd5f174075 100644 --- a/player/core.h +++ b/player/core.h @@ -276,6 +276,8 @@ typedef struct MPContext { // Video PTS, or audio PTS if video has ended. double playback_pts; + int last_chapter; + // History of video frames timestamps that were queued in the VO // This includes even skipped frames during hr-seek double vo_pts_history_pts[MAX_NUM_VO_PTS]; diff --git a/player/loadfile.c b/player/loadfile.c index d6ff75d668..f750d8917c 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1333,6 +1333,7 @@ goto_reopen_demuxer: ; mpctx->paused = false; mpctx->paused_for_cache = false; mpctx->eof_reached = false; + mpctx->last_chapter = -2; mpctx->seek = (struct seek_params){ 0 }; // If there's a timeline force an absolute seek to initialize state diff --git a/player/main.c b/player/main.c index 3522e12b0e..101f9fe196 100644 --- a/player/main.c +++ b/player/main.c @@ -310,6 +310,7 @@ struct MPContext *mp_create(void) struct MPContext *mpctx = talloc(NULL, MPContext); *mpctx = (struct MPContext){ .last_dvb_step = 1, + .last_chapter = -2, .term_osd_contents = talloc_strdup(mpctx, ""), .osd_progbar = { .type = -1 }, .playlist = talloc_struct(mpctx, struct playlist, {0}), diff --git a/player/playloop.c b/player/playloop.c index d182d090c4..a1cdb0028d 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -845,6 +845,15 @@ static void handle_keep_open(struct MPContext *mpctx) } } +static void handle_chapter_change(struct MPContext *mpctx) +{ + int chapter = get_current_chapter(mpctx); + if (chapter != mpctx->last_chapter) { + mpctx->last_chapter = chapter; + mp_notify(mpctx, MPV_EVENT_CHAPTER_CHANGE, NULL); + } +} + // Execute a forceful refresh of the VO window, if it hasn't had a valid frame // for a while. The problem is that a VO with no valid frame (vo->hasframe==0) // doesn't redraw video and doesn't OSD interaction. So screw it, hard. @@ -1295,6 +1304,8 @@ void run_playloop(struct MPContext *mpctx) handle_keep_open(mpctx); + handle_chapter_change(mpctx); + handle_force_window(mpctx, false); execute_queued_seek(mpctx); -- cgit v1.2.3