1
mirror of https://github.com/mpv-player/mpv synced 2025-05-09 10:21:43 +02:00

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.
This commit is contained in:
Uoti Urpala 2009-04-01 19:55:26 +03:00
parent 997f636599
commit f12c83b85b
5 changed files with 26 additions and 66 deletions

@ -387,8 +387,6 @@ static int mp_property_chapter(m_option_t *prop, int action, void *arg,
{ {
struct MPOpts *opts = &mpctx->opts; struct MPOpts *opts = &mpctx->opts;
int chapter = -1; int chapter = -1;
float next_pts = 0;
int chapter_num;
int step_all; int step_all;
char *chapter_name = NULL; char *chapter_name = NULL;
@ -431,10 +429,12 @@ static int mp_property_chapter(m_option_t *prop, int action, void *arg,
default: default:
return M_PROPERTY_NOT_IMPLEMENTED; 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->rel_seek_secs = 0;
mpctx->abs_seek_pos = 0; mpctx->abs_seek_pos = 0;
chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1,
&next_pts, &chapter_num, &chapter_name);
if (chapter >= 0) { if (chapter >= 0) {
if (next_pts > -1.0) { if (next_pts > -1.0) {
mpctx->abs_seek_pos = SEEK_ABSOLUTE; 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, set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
MSGTR_OSDChapter, 0, MSGTR_Unknown); MSGTR_OSDChapter, 0, MSGTR_Unknown);
if (chapter_name) if (chapter_name)
free(chapter_name); talloc_free(chapter_name);
return M_PROPERTY_OK; return M_PROPERTY_OK;
} }

@ -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 * either using the demuxer->chapters structure set by the demuxer
* or asking help to the stream layer (e.g. dvd) * or asking help to the stream layer (e.g. dvd)
* \param chapter - chapter number wished - 0-based * \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 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) * \param chapter_name name of chapter found (set by this function is param is not null)
* \return -1 on error, current chapter if successful * \return -1 on error, current chapter if successful
*/ */
int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, int mode, int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, double *seek_pts,
float *seek_pts, int *num_chapters,
char **chapter_name) char **chapter_name)
{ {
int ris; int ris;
int current, total;
sh_video_t *sh_video = demuxer->video->sh; sh_video_t *sh_video = demuxer->video->sh;
sh_audio_t *sh_audio = demuxer->audio->sh; sh_audio_t *sh_audio = demuxer->audio->sh;
if (!demuxer->num_chapters || !demuxer->chapters) { if (!demuxer->num_chapters || !demuxer->chapters) {
if (!mode) {
ris = stream_control(demuxer->stream,
STREAM_CTRL_GET_CURRENT_CHAPTER, &current);
if (ris == STREAM_UNSUPPORTED)
return -1;
chapter += current;
}
demux_flush(demuxer); demux_flush(demuxer);
ris = stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_CHAPTER, 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) // (because e.g. dvds depend on sectors, not on pts)
*seek_pts = -1.0; *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) { if (chapter_name) {
*chapter_name = NULL; *chapter_name = NULL;
if (num_chapters && *num_chapters) { int num_chapters;
char *tmp = malloc(16); if (stream_control(demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS,
if (tmp) { &num_chapters) == STREAM_UNSUPPORTED)
sprintf(tmp, " of %3d", *num_chapters); num_chapters = 0;
*chapter_name = tmp; if (num_chapters) {
} *chapter_name = talloc_size(NULL, 16);
sprintf(*chapter_name, " of %3d", num_chapters);
} }
} }
return ris != STREAM_UNSUPPORTED ? chapter : -1; return ris != STREAM_UNSUPPORTED ? chapter : -1;
} else { // chapters structure is set in the demuxer } else { // chapters structure is set in the demuxer
total = demuxer->num_chapters; if (chapter >= 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)
return -1; return -1;
if (current < 0) if (chapter < 0)
current = 0; chapter = 0;
*seek_pts = demuxer->chapters[current].start / 1000.0; *seek_pts = demuxer->chapters[chapter].start / 1000.0;
if (num_chapters) if (chapter_name)
*num_chapters = demuxer->num_chapters; *chapter_name = talloc_strdup(NULL, demuxer->chapters[chapter].name);
if (chapter_name) { return chapter;
if (demuxer->chapters[current].name)
*chapter_name = strdup(demuxer->chapters[current].name);
else
*chapter_name = NULL;
}
return current;
} }
} }

@ -431,7 +431,8 @@ int demuxer_add_attachment(demuxer_t* demuxer, const char* name,
const char* type, const void* data, size_t size); 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_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. /// Get current chapter index if available.
int demuxer_get_current_chapter(demuxer_t *demuxer); int demuxer_get_current_chapter(demuxer_t *demuxer);

@ -575,8 +575,8 @@ if(stream->type==STREAMTYPE_DVDNAV){
} }
if(dvd_chapter>1) { if(dvd_chapter>1) {
float pts; double pts;
if (demuxer_seek_chapter(demuxer, dvd_chapter-1, 1, &pts, NULL, NULL) >= 0 && pts > -1.0) if (demuxer_seek_chapter(demuxer, dvd_chapter-1, &pts, NULL) >= 0 && pts > -1.0)
seek_to_sec = pts; seek_to_sec = pts;
} }

@ -3592,8 +3592,8 @@ if(!mpctx->demuxer)
} }
if(dvd_chapter>1) { if(dvd_chapter>1) {
float pts; double pts;
if (demuxer_seek_chapter(mpctx->demuxer, dvd_chapter-1, 1, &pts, NULL, NULL) >= 0 && pts > -1.0) if (demuxer_seek_chapter(mpctx->demuxer, dvd_chapter-1, &pts, NULL) >= 0 && pts > -1.0)
seek(mpctx, pts, SEEK_ABSOLUTE); seek(mpctx, pts, SEEK_ABSOLUTE);
} }