summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-04-27 22:28:07 +0200
committerwm4 <wm4@nowhere>2014-04-27 22:28:07 +0200
commite8a996cedef347f9a4cee1172db39e7f0eea821f (patch)
tree6e764a5fe26b62e2af6ce6fc62a39d828ec9f713 /player
parentb20416abe3f7e15d27a9828c12171e65f6e62d9c (diff)
downloadmpv-e8a996cedef347f9a4cee1172db39e7f0eea821f.tar.bz2
mpv-e8a996cedef347f9a4cee1172db39e7f0eea821f.tar.xz
client API: add chapter change event
Also works for mpv_observe_property() on the "chapter" property.
Diffstat (limited to 'player')
-rw-r--r--player/client.c1
-rw-r--r--player/command.c1
-rw-r--r--player/core.h2
-rw-r--r--player/loadfile.c1
-rw-r--r--player/main.c1
-rw-r--r--player/playloop.c11
6 files changed, 17 insertions, 0 deletions
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);