mirror of
https://github.com/mpv-player/mpv
synced 2025-03-24 20:31:37 +00:00
demux: move a seek helper to a separate function
It makes some slight sense and helps with one of the following commits. Also rename that other function to make it sound less similar to find_seek_target().
This commit is contained in:
parent
7893ab5a7e
commit
b55b9cb98c
@ -3461,8 +3461,9 @@ static struct demux_packet *find_seek_target(struct demux_queue *queue,
|
|||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return a cache range for the given pts/flags, or NULL if none available.
|
||||||
// must be called locked
|
// must be called locked
|
||||||
static struct demux_cached_range *find_cache_seek_target(struct demux_internal *in,
|
static struct demux_cached_range *find_cache_seek_range(struct demux_internal *in,
|
||||||
double pts, int flags)
|
double pts, int flags)
|
||||||
{
|
{
|
||||||
// Note about queued low level seeks: in->seeking can be true here, and it
|
// Note about queued low level seeks: in->seeking can be true here, and it
|
||||||
@ -3472,6 +3473,8 @@ static struct demux_cached_range *find_cache_seek_target(struct demux_internal *
|
|||||||
if ((flags & SEEK_FACTOR) || !in->seekable_cache)
|
if ((flags & SEEK_FACTOR) || !in->seekable_cache)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
struct demux_cached_range *res = NULL;
|
||||||
|
|
||||||
for (int n = 0; n < in->num_ranges; n++) {
|
for (int n = 0; n < in->num_ranges; n++) {
|
||||||
struct demux_cached_range *r = in->ranges[n];
|
struct demux_cached_range *r = in->ranges[n];
|
||||||
if (r->seek_start != MP_NOPTS_VALUE) {
|
if (r->seek_start != MP_NOPTS_VALUE) {
|
||||||
@ -3482,21 +3485,15 @@ static struct demux_cached_range *find_cache_seek_target(struct demux_internal *
|
|||||||
(pts <= r->seek_end || r->is_eof))
|
(pts <= r->seek_end || r->is_eof))
|
||||||
{
|
{
|
||||||
MP_VERBOSE(in, "...using this range for in-cache seek.\n");
|
MP_VERBOSE(in, "...using this range for in-cache seek.\n");
|
||||||
return r;
|
res = r;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// must be called locked
|
|
||||||
// range must be non-NULL and from find_cache_seek_target() using the same pts
|
|
||||||
// and flags, before any other changes to the cached state
|
|
||||||
static void execute_cache_seek(struct demux_internal *in,
|
|
||||||
struct demux_cached_range *range,
|
|
||||||
double pts, int flags)
|
|
||||||
{
|
|
||||||
// Adjust the seek target to the found video key frames. Otherwise the
|
// Adjust the seek target to the found video key frames. Otherwise the
|
||||||
// video will undershoot the seek target, while audio will be closer to it.
|
// video will undershoot the seek target, while audio will be closer to it.
|
||||||
// The player frontend will play the additional video without audio, so
|
// The player frontend will play the additional video without audio, so
|
||||||
@ -3504,22 +3501,28 @@ static void execute_cache_seek(struct demux_internal *in,
|
|||||||
// target will make the audio seek to the video target or before.
|
// target will make the audio seek to the video target or before.
|
||||||
// (If hr-seeks are used, it's better to skip this, as it would only mean
|
// (If hr-seeks are used, it's better to skip this, as it would only mean
|
||||||
// that more audio data than necessary would have to be decoded.)
|
// that more audio data than necessary would have to be decoded.)
|
||||||
if (!(flags & SEEK_HR)) {
|
static void adjust_cache_seek_target(struct demux_internal *in,
|
||||||
|
struct demux_cached_range *range,
|
||||||
|
double *pts, int *flags)
|
||||||
|
{
|
||||||
|
if (*flags & SEEK_HR)
|
||||||
|
return;
|
||||||
|
|
||||||
for (int n = 0; n < in->num_streams; n++) {
|
for (int n = 0; n < in->num_streams; n++) {
|
||||||
struct demux_stream *ds = in->streams[n]->ds;
|
struct demux_stream *ds = in->streams[n]->ds;
|
||||||
struct demux_queue *queue = range->streams[n];
|
struct demux_queue *queue = range->streams[n];
|
||||||
if (ds->selected && ds->type == STREAM_VIDEO) {
|
if (ds->selected && ds->type == STREAM_VIDEO) {
|
||||||
struct demux_packet *target = find_seek_target(queue, pts, flags);
|
struct demux_packet *target = find_seek_target(queue, *pts, *flags);
|
||||||
if (target) {
|
if (target) {
|
||||||
double target_pts;
|
double target_pts;
|
||||||
compute_keyframe_times(target, &target_pts, NULL);
|
compute_keyframe_times(target, &target_pts, NULL);
|
||||||
if (target_pts != MP_NOPTS_VALUE) {
|
if (target_pts != MP_NOPTS_VALUE) {
|
||||||
MP_VERBOSE(in, "adjust seek target %f -> %f\n",
|
MP_VERBOSE(in, "adjust seek target %f -> %f\n",
|
||||||
pts, target_pts);
|
*pts, target_pts);
|
||||||
// (We assume the find_seek_target() call will return
|
// (We assume the find_seek_target() call will return
|
||||||
// the same target for the video stream.)
|
// the same target for the video stream.)
|
||||||
pts = target_pts;
|
*pts = target_pts;
|
||||||
flags &= ~SEEK_FORWARD;
|
*flags &= ~SEEK_FORWARD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -3527,6 +3530,15 @@ static void execute_cache_seek(struct demux_internal *in,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// must be called locked
|
||||||
|
// range must be non-NULL and from find_cache_seek_range() using the same pts
|
||||||
|
// and flags, before any other changes to the cached state
|
||||||
|
static void execute_cache_seek(struct demux_internal *in,
|
||||||
|
struct demux_cached_range *range,
|
||||||
|
double pts, int flags)
|
||||||
|
{
|
||||||
|
adjust_cache_seek_target(in, range, &pts, &flags);
|
||||||
|
|
||||||
for (int n = 0; n < in->num_streams; n++) {
|
for (int n = 0; n < in->num_streams; n++) {
|
||||||
struct demux_stream *ds = in->streams[n]->ds;
|
struct demux_stream *ds = in->streams[n]->ds;
|
||||||
struct demux_queue *queue = range->streams[n];
|
struct demux_queue *queue = range->streams[n];
|
||||||
@ -3624,7 +3636,7 @@ static bool queue_seek(struct demux_internal *in, double seek_pts, int flags,
|
|||||||
flags &= ~(unsigned)SEEK_SATAN;
|
flags &= ~(unsigned)SEEK_SATAN;
|
||||||
|
|
||||||
struct demux_cached_range *cache_target =
|
struct demux_cached_range *cache_target =
|
||||||
find_cache_seek_target(in, seek_pts, flags);
|
find_cache_seek_range(in, seek_pts, flags);
|
||||||
|
|
||||||
if (!cache_target) {
|
if (!cache_target) {
|
||||||
if (require_cache) {
|
if (require_cache) {
|
||||||
|
Loading…
Reference in New Issue
Block a user