Mercurial > mplayer.hg
changeset 19478:bab82c53e433
demuxer_seek_chapter() returns informations about chapters count and name
author | nicodvb |
---|---|
date | Mon, 21 Aug 2006 19:19:00 +0000 |
parents | 2a6520a36e96 |
children | 8dd04ec733f5 |
files | libmpdemux/demuxer.c libmpdemux/demuxer.h mplayer.c |
diffstat | 3 files changed, 32 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/libmpdemux/demuxer.c Mon Aug 21 19:16:39 2006 +0000 +++ b/libmpdemux/demuxer.c Mon Aug 21 19:19:00 2006 +0000 @@ -1053,10 +1053,12 @@ * \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 @@ //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 @@ *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; } }
--- a/libmpdemux/demuxer.h Mon Aug 21 19:16:39 2006 +0000 +++ b/libmpdemux/demuxer.h Mon Aug 21 19:19:00 2006 +0000 @@ -381,5 +381,5 @@ 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);
--- a/mplayer.c Mon Aug 21 19:16:39 2006 +0000 +++ b/mplayer.c Mon Aug 21 19:19:00 2006 +0000 @@ -4822,18 +4822,22 @@ 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.;