From f12c83b85b135c1cb9fb34e978eb0c8051450da8 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Wed, 1 Apr 2009 19:55:26 +0300 Subject: Change demuxer_seek_chapter() parameters Remove the "num_chapters" and "mode" parameters that aren't needed by any callers. Change "float *seek_pts" to "double *". Allocate the string returned via "chapter_name" with talloc. --- command.c | 10 ++++---- libmpdemux/demuxer.c | 71 +++++++++++----------------------------------------- libmpdemux/demuxer.h | 3 ++- mencoder.c | 4 +-- mplayer.c | 4 +-- 5 files changed, 26 insertions(+), 66 deletions(-) diff --git a/command.c b/command.c index 7c0352398f..97fc66ba7c 100644 --- a/command.c +++ b/command.c @@ -387,8 +387,6 @@ static int mp_property_chapter(m_option_t *prop, int action, void *arg, { struct MPOpts *opts = &mpctx->opts; int chapter = -1; - float next_pts = 0; - int chapter_num; int step_all; char *chapter_name = NULL; @@ -431,10 +429,12 @@ static int mp_property_chapter(m_option_t *prop, int action, void *arg, default: return M_PROPERTY_NOT_IMPLEMENTED; } + + double next_pts = 0; + chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, &next_pts, + &chapter_name); mpctx->rel_seek_secs = 0; mpctx->abs_seek_pos = 0; - chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1, - &next_pts, &chapter_num, &chapter_name); if (chapter >= 0) { if (next_pts > -1.0) { mpctx->abs_seek_pos = SEEK_ABSOLUTE; @@ -450,7 +450,7 @@ static int mp_property_chapter(m_option_t *prop, int action, void *arg, set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration, MSGTR_OSDChapter, 0, MSGTR_Unknown); if (chapter_name) - free(chapter_name); + talloc_free(chapter_name); return M_PROPERTY_OK; } diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c index 9d0e01450f..15cadb500f 100644 --- a/libmpdemux/demuxer.c +++ b/libmpdemux/demuxer.c @@ -1327,31 +1327,19 @@ int demuxer_add_chapter(demuxer_t *demuxer, const char *name, uint64_t start, * either using the demuxer->chapters structure set by the demuxer * or asking help to the stream layer (e.g. dvd) * \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 *num_chapters, +int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, double *seek_pts, char **chapter_name) { int ris; - int current, total; sh_video_t *sh_video = demuxer->video->sh; sh_audio_t *sh_audio = demuxer->audio->sh; if (!demuxer->num_chapters || !demuxer->chapters) { - if (!mode) { - ris = stream_control(demuxer->stream, - STREAM_CTRL_GET_CURRENT_CHAPTER, ¤t); - if (ris == STREAM_UNSUPPORTED) - return -1; - chapter += current; - } - demux_flush(demuxer); ris = stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_CHAPTER, @@ -1371,60 +1359,31 @@ int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, int mode, // (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_UNSUPPORTED) - *num_chapters = 0; - } - if (chapter_name) { *chapter_name = NULL; - if (num_chapters && *num_chapters) { - char *tmp = malloc(16); - if (tmp) { - sprintf(tmp, " of %3d", *num_chapters); - *chapter_name = tmp; - } + int num_chapters; + if (stream_control(demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS, + &num_chapters) == STREAM_UNSUPPORTED) + num_chapters = 0; + if (num_chapters) { + *chapter_name = talloc_size(NULL, 16); + sprintf(*chapter_name, " of %3d", num_chapters); } } return ris != STREAM_UNSUPPORTED ? chapter : -1; } else { // chapters structure is set in the demuxer - total = demuxer->num_chapters; - - if (mode == 1) //absolute seeking - current = chapter; - else { //relative seeking - uint64_t now; - now = (sh_video ? sh_video->pts : (sh_audio ? sh_audio->pts : 0.)) - * 1000 + .5; - - for (current = total - 1; current >= 0; --current) { - demux_chapter_t *chapter = demuxer->chapters + current; - if (chapter->start <= now) - break; - } - current += chapter; - } - - if (current >= total) + if (chapter >= demuxer->num_chapters) return -1; - if (current < 0) - current = 0; + if (chapter < 0) + chapter = 0; - *seek_pts = demuxer->chapters[current].start / 1000.0; + *seek_pts = demuxer->chapters[chapter].start / 1000.0; - if (num_chapters) - *num_chapters = demuxer->num_chapters; - - if (chapter_name) { - if (demuxer->chapters[current].name) - *chapter_name = strdup(demuxer->chapters[current].name); - else - *chapter_name = NULL; - } + if (chapter_name) + *chapter_name = talloc_strdup(NULL, demuxer->chapters[chapter].name); - return current; + return chapter; } } diff --git a/libmpdemux/demuxer.h b/libmpdemux/demuxer.h index 032552b751..6df2564e24 100644 --- a/libmpdemux/demuxer.h +++ b/libmpdemux/demuxer.h @@ -431,7 +431,8 @@ int demuxer_add_attachment(demuxer_t* demuxer, const char* name, const char* type, const void* data, size_t size); 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 *num_chapters, char **chapter_name); +int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, double *seek_pts, + char **chapter_name); /// Get current chapter index if available. int demuxer_get_current_chapter(demuxer_t *demuxer); diff --git a/mencoder.c b/mencoder.c index 6fb7f03600..6915a6efa3 100644 --- a/mencoder.c +++ b/mencoder.c @@ -575,8 +575,8 @@ if(stream->type==STREAMTYPE_DVDNAV){ } if(dvd_chapter>1) { - float pts; - if (demuxer_seek_chapter(demuxer, dvd_chapter-1, 1, &pts, NULL, NULL) >= 0 && pts > -1.0) + double pts; + if (demuxer_seek_chapter(demuxer, dvd_chapter-1, &pts, NULL) >= 0 && pts > -1.0) seek_to_sec = pts; } diff --git a/mplayer.c b/mplayer.c index 6e49876afe..42d24f03e6 100644 --- a/mplayer.c +++ b/mplayer.c @@ -3592,8 +3592,8 @@ if(!mpctx->demuxer) } if(dvd_chapter>1) { - float pts; - if (demuxer_seek_chapter(mpctx->demuxer, dvd_chapter-1, 1, &pts, NULL, NULL) >= 0 && pts > -1.0) + double pts; + if (demuxer_seek_chapter(mpctx->demuxer, dvd_chapter-1, &pts, NULL) >= 0 && pts > -1.0) seek(mpctx, pts, SEEK_ABSOLUTE); } -- cgit v1.2.3