diff options
author | 2006-08-21 19:19:00 +0000 | |
---|---|---|
committer | 2006-08-21 19:19:00 +0000 | |
commit | b7b319395e786fc6c2087ee6fd3e698e3b2f13e3 (patch) | |
tree | 2152545a45a47b9d64f74f79bb4d5aaa3fd157f0 | |
parent | 30c1486c650df5689728f72727917d46924f97d6 (diff) |
demuxer_seek_chapter() returns informations about chapters count and name
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@19484 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r-- | libmpdemux/demuxer.c | 25 | ||||
-rw-r--r-- | libmpdemux/demuxer.h | 2 | ||||
-rw-r--r-- | mplayer.c | 10 |
3 files changed, 32 insertions, 5 deletions
diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c index 0867aa4db1..75fc479393 100644 --- a/libmpdemux/demuxer.c +++ b/libmpdemux/demuxer.c @@ -1053,10 +1053,12 @@ int demuxer_add_chapter(demuxer_t* demuxer, const char* name, uint64_t start, ui * \param chapter - chapter number wished - 0-based * \param mode 0: relative to current main pts, 1: absolute * \param seek_pts set by the function to the pts to seek to (if demuxer->chapters is set) + * \param num_chapters number of chapters present (set by this function is param is not null) + * \param chapter_name name of chapter found (set by this function is param is not null) * \return -1 on error, current chapter if successful */ -int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, int mode, float *seek_pts) { +int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, int mode, float *seek_pts, int *num_chapters, char **chapter_name) { int ris; int current, total; sh_video_t *sh_video = demuxer->video->sh; @@ -1091,6 +1093,21 @@ int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, int mode, float *seek_ //exit status may be ok, but main() doesn't have to seek itself (because e.g. dvds depend on sectors, not on pts) *seek_pts = -1.0; + + if(num_chapters) { + if(stream_control(demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, num_chapters) == STREAM_UNSUPORTED) + *num_chapters = 0; + } + + if(chapter_name) { + char *tmp = malloc(16); + *chapter_name = NULL; + if(num_chapters && *num_chapters && tmp) { + sprintf(tmp, " of %3d", *num_chapters); + *chapter_name = tmp; + } + } + return (ris != STREAM_UNSUPORTED ? chapter : -1); } else { //chapters structure is set in the demuxer total = demuxer->num_chapters; @@ -1115,6 +1132,12 @@ int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, int mode, float *seek_ *seek_pts = demuxer->chapters[current].start / 1000.0; + if(num_chapters) + *num_chapters = demuxer->num_chapters; + + if(chapter_name) + *chapter_name = demuxer->chapters[current].name; + return current; } } diff --git a/libmpdemux/demuxer.h b/libmpdemux/demuxer.h index 39820a537a..051a2f3d8c 100644 --- a/libmpdemux/demuxer.h +++ b/libmpdemux/demuxer.h @@ -381,5 +381,5 @@ extern void demuxer_help(void); extern int get_demuxer_type_from_name(char *demuxer_name, int *force); int demuxer_add_chapter(demuxer_t* demuxer, const char* name, uint64_t start, uint64_t end); -int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, int mode, float *seek_pts); +int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, int mode, float *seek_pts, int *num_chapters, char **chapter_name); @@ -4822,18 +4822,22 @@ if(step_sec>0) { int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0; int chap; float next_pts = 0; + int num_chapters; + char *chapter_name; rel_seek_secs = 0; abs_seek_pos = 0; - chap = demuxer_seek_chapter(demuxer, seek, abs, &next_pts); + chap = demuxer_seek_chapter(demuxer, seek, abs, &next_pts, &num_chapters, &chapter_name); if(chap != -1) { if(next_pts > -1.0) { abs_seek_pos = 1; rel_seek_secs = next_pts; } - if(demuxer->num_chapters > chap) + if(chapter_name) { set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, MSGTR_OSDChapter, - chap, demuxer->chapters[chap].name); + chap, chapter_name); + free(chapter_name); + } } else { if (seek > 0) rel_seek_secs = 1000000000.; |