summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-05-04 01:20:39 +0200
committerwm4 <wm4@nowhere>2013-05-06 23:39:48 +0200
commitb01e8d6210adcf0b68313d1b31f904c121020401 (patch)
treeca966f78e23f8e2f6e2dc502ba05181b16baeebe /demux
parent5148f9f5cca6a5a28bb98a3b713f27614538815f (diff)
downloadmpv-b01e8d6210adcf0b68313d1b31f904c121020401.tar.bz2
mpv-b01e8d6210adcf0b68313d1b31f904c121020401.tar.xz
stream: report chapter times, use time seeks for DVD chapters
Allow the stream layer to report chapter times. Extend stream_dvd to do this. I'm not 100% sure whether the re-used code is bug-free (because it was used for slave-mode and/or debugging only). MAke the frontend do time-based seeks when switching DVD chapters. I'm not sure if there's a real reason STREAM_CTRL_SEEK_TO_CHAPTER exists (maybe/hopefully not), but we will see. Note that querying chapter times in demuxer_chapter_time() with the new STREAM_CTRL_GET_CHAPTER_TIME could be excessively slow, especially with the cache enabled. The frontend likes to query chapter times very often. Additionally, stream_dvd uses some sort of quadratic algorithm to list times for all chapters. For this reason, we try to query all chapters on start (after the demuxer is opened), and add the chapters to the demuxer chapter list. demuxer_chapter_time() will get the time from that list, instead of asking the stream layer over and over again. This assumes stream_dvd knows the list of chapters at the start, and also that the list of chapters never changes during playback. This seems to be true, and the only exception, switching DVD titles, is not supported at runtime (and doesn't need to be supported).
Diffstat (limited to 'demux')
-rw-r--r--demux/demux.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/demux/demux.c b/demux/demux.c
index 94f54fcbfd..f95a134903 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -101,6 +101,8 @@ const demuxer_desc_t *const demuxer_list[] = {
NULL
};
+static void add_stream_chapters(struct demuxer *demuxer);
+
static int packet_destroy(void *ptr)
{
struct demux_packet *dp = ptr;
@@ -932,6 +934,7 @@ static struct demuxer *open_given_type(struct MPOpts *opts,
// Doesn't work, because stream_pts is a "guess".
demuxer->accurate_seek = false;
}
+ add_stream_chapters(demuxer);
demuxer_sort_chapters(demuxer);
return demuxer;
} else {
@@ -1300,6 +1303,20 @@ int demuxer_add_chapter(demuxer_t *demuxer, struct bstr name,
return 0;
}
+static void add_stream_chapters(struct demuxer *demuxer)
+{
+ if (demuxer->num_chapters)
+ return;
+ int num_chapters = demuxer_chapter_count(demuxer);
+ for (int n = 0; n < num_chapters; n++) {
+ double p = n;
+ if (stream_control(demuxer->stream, STREAM_CTRL_GET_CHAPTER_TIME, &p)
+ != STREAM_OK)
+ return;
+ demuxer_add_chapter(demuxer, bstr0(""), p * 1e9, 0);
+ }
+}
+
/**
* \brief demuxer_seek_chapter() seeks to a chapter in two possible ways:
* either using the demuxer->chapters structure set by the demuxer