1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-18 12:55:16 +00:00

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
This commit is contained in:
nicodvb 2006-08-21 19:19:00 +00:00
parent 30c1486c65
commit b7b319395e
3 changed files with 32 additions and 5 deletions

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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.;