aboutsummaryrefslogtreecommitdiffhomepage
path: root/libmpdemux
diff options
context:
space:
mode:
authorGravatar nicodvb <nicodvb@b3059339-0415-0410-9bf9-f77b7e298cf2>2006-08-18 16:48:22 +0000
committerGravatar nicodvb <nicodvb@b3059339-0415-0410-9bf9-f77b7e298cf2>2006-08-18 16:48:22 +0000
commit01602c31b39a22053ecadb185c6dcbad44f25f98 (patch)
treee1856f97fccc3db6b4243309bc35d93af20e9606 /libmpdemux
parent63fdcbc84009ef35d90308eeec14602c585e1056 (diff)
added first revision of demuxer_seek_chapter()
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@19441 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdemux')
-rw-r--r--libmpdemux/demuxer.c66
-rw-r--r--libmpdemux/demuxer.h1
2 files changed, 67 insertions, 0 deletions
diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c
index 818b87a225..82ae45d282 100644
--- a/libmpdemux/demuxer.c
+++ b/libmpdemux/demuxer.c
@@ -1046,3 +1046,69 @@ int demuxer_add_chapter(demuxer_t* demuxer, const char* name, uint64_t start, ui
return demuxer->num_chapters ++;
}
+/**
+ * \brief demuxer_seek_chapter() seeks to a chapter in two possible ways:
+ * 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
+ * \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)
+ * \return -1 on error, current chapter if successful
+ */
+
+int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, int mode, float *seek_pts) {
+ 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(demuxer->video->sh)
+ ds_free_packs(demuxer->video);
+
+ if(demuxer->audio->sh)
+ ds_free_packs(demuxer->audio);
+
+ if(demuxer->sub->id >= 0)
+ ds_free_packs(demuxer->sub);
+
+ ris = stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_CHAPTER, &chapter);
+ if(sh_video) {
+ ds_fill_buffer(demuxer->video);
+ resync_video_stream(sh_video);
+ }
+
+ if(sh_audio) {
+ ds_fill_buffer(demuxer->audio);
+ resync_audio_stream(sh_audio);
+ }
+
+ //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;
+ return (ris != STREAM_UNSUPORTED ? 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)
+ return -1;
+ if (current < 0) current = 0;
+
+ *seek_pts = demuxer->chapters[current].start / 1000.0;
+
+ return current;
+ }
+}
diff --git a/libmpdemux/demuxer.h b/libmpdemux/demuxer.h
index 5cbce24259..39820a537a 100644
--- a/libmpdemux/demuxer.h
+++ b/libmpdemux/demuxer.h
@@ -381,4 +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);