demux_disc: pass seek flags to stream layer

Pass through the seek flags to the stream layer. The STREAM_CTRL
semantics become a bit awkward, but that's still the least awkward
part about optical disc media.

Make demux_disc.c request relative seeks. Now the player will use
relative seeks if the user sends relative seek commands, and the
demuxer announces it wants these by setting rel_seeks to true. This
change probably changes seek behavior for dvd, dvdnav, bluray, cdda,
and possibly makes seeking useless if the demuxer-cache is set to
a high value.

Will be used in the next commit. (Split to make reverting the next
commit easier.)
This commit is contained in:
wm4 2015-01-19 20:45:31 +01:00
parent e972ff4857
commit 966f0a41a4
4 changed files with 21 additions and 9 deletions

View File

@ -760,6 +760,7 @@ static void demux_copy(struct demuxer *dst, struct demuxer *src)
dst->seekable = src->seekable;
dst->filetype = src->filetype;
dst->ts_resets_possible = src->ts_resets_possible;
dst->rel_seeks = src->rel_seeks;
dst->start_time = src->start_time;
}
if (src->events & DEMUX_EVENT_STREAMS) {

View File

@ -71,11 +71,12 @@ struct demux_ctrl_stream_ctrl {
int res;
};
#define SEEK_ABSOLUTE (1 << 0)
#define SEEK_FACTOR (1 << 1)
#define SEEK_FORWARD (1 << 2)
#define SEEK_BACKWARD (1 << 3)
#define SEEK_SUBPREROLL (1 << 4)
#define SEEK_ABSOLUTE (1 << 0) // argument is a timestamp
#define SEEK_FACTOR (1 << 1) // argument is in range [0,1]
#define SEEK_FORWARD (1 << 2) // prefer later time if not exact
#define SEEK_BACKWARD (1 << 3) // prefer earlier time if not exact
#define SEEK_SUBPREROLL (1 << 4) // try to get more subtitle packets
#define SEEK_HR (1 << 5) // hr-seek (this is a weak hint only)
// Strictness of the demuxer open format check.
// demux.c will try by default: NORMAL, UNSAFE (in this order)
@ -188,6 +189,9 @@ typedef struct demuxer {
double start_time;
// File format allows PTS resets (even if the current file is without)
bool ts_resets_possible;
// Send relative seek requests, instead of SEEK_ABSOLUTE or SEEK_FACTOR.
// This is only done if the user explicitly uses a relative seek.
bool rel_seeks;
// Bitmask of DEMUX_EVENT_*
int events;

View File

@ -169,6 +169,7 @@ static void d_seek(demuxer_t *demuxer, double rel_seek_secs, int flags)
double pts = p->seek_pts;
if (flags & SEEK_ABSOLUTE)
pts = 0.0f;
double base_pts = pts; // to what pts is relative
if (flags & SEEK_FACTOR) {
double tmp = 0;
@ -180,7 +181,8 @@ static void d_seek(demuxer_t *demuxer, double rel_seek_secs, int flags)
MP_VERBOSE(demuxer, "seek to: %f\n", pts);
stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_TIME, &pts);
double seek_arg[] = {pts, base_pts, flags};
stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_TIME, seek_arg);
demux_control(p->slave, DEMUXER_CTRL_RESYNC, NULL);
p->seek_pts = pts;
@ -312,6 +314,8 @@ static int d_open(demuxer_t *demuxer, enum demux_check check)
// Can be seekable even if the stream isn't.
demuxer->seekable = true;
demuxer->rel_seeks = true;
// With cache enabled, the stream can be seekable. This causes demux_lavf.c
// (actually libavformat/mpegts.c) to seek sometimes when reading a packet.
// It does this to seek back a bit in case the current file position points

View File

@ -204,7 +204,7 @@ static int mp_seek(MPContext *mpctx, struct seek_params seek,
}
}
int direction = 0;
if (seek.type == MPSEEK_RELATIVE) {
if (seek.type == MPSEEK_RELATIVE && (!mpctx->demuxer->rel_seeks || hr_seek)) {
seek.type = MPSEEK_ABSOLUTE;
direction = seek.amount > 0 ? 1 : -1;
seek.amount += get_current_time(mpctx);
@ -233,10 +233,13 @@ static int mp_seek(MPContext *mpctx, struct seek_params seek,
demuxer_style |= SEEK_ABSOLUTE;
break;
}
if (hr_seek || direction < 0)
if (hr_seek || direction < 0) {
demuxer_style |= SEEK_BACKWARD;
else if (direction > 0)
} else if (direction > 0) {
demuxer_style |= SEEK_FORWARD;
}
if (hr_seek)
demuxer_style |= SEEK_HR;
if (hr_seek || opts->mkv_subtitle_preroll)
demuxer_style |= SEEK_SUBPREROLL;