deps/media-playback: Reset TS when seeking

If seeking occurs too close to the previous time value, it could cause
the playback to delay an abnormal amount of time, or if the time value
is under the previous value, then it would cause an assert.  So instead,
reset the next timestamp value to be instant in both cases if a seek
occurs to ensure timely playback.
This commit is contained in:
jp9000 2020-07-16 16:06:48 -07:00
parent 2ba2df6e59
commit 56e56cd265
2 changed files with 14 additions and 5 deletions

View file

@ -419,13 +419,19 @@ static void mp_media_calc_next_ns(mp_media_t *m)
{
int64_t min_next_ns = mp_media_get_next_min_pts(m);
int64_t delta = min_next_ns - m->next_pts_ns;
if (m->seek_next_ts) {
delta = 0;
m->seek_next_ts = false;
} else {
#ifdef _DEBUG
assert(delta >= 0);
assert(delta >= 0);
#endif
if (delta < 0)
delta = 0;
if (delta > 3000000000)
delta = 0;
if (delta < 0)
delta = 0;
if (delta > 3000000000)
delta = 0;
}
m->next_ns += delta;
m->next_pts_ns = min_next_ns;
@ -473,6 +479,7 @@ static bool mp_media_reset(mp_media_t *m)
m->eof = false;
m->base_ts += next_ts;
m->seek_next_ts = false;
pthread_mutex_lock(&m->mutex);
stopping = m->stopping;
@ -684,6 +691,7 @@ static inline bool mp_media_thread(mp_media_t *m)
}
if (seek) {
m->seek_next_ts = true;
seek_to(m, seek_pos);
continue;
}

View file

@ -98,6 +98,7 @@ struct mp_media {
bool pause;
bool reset_ts;
bool seek;
bool seek_next_ts;
int64_t seek_pos;
};