mirror of
https://github.com/mpv-player/mpv
synced 2025-02-16 12:17:12 +00:00
vo: use nanoseconds for frame duration and pts
This commit is contained in:
parent
8fccd6bf91
commit
c82c55b4b9
@ -1198,7 +1198,7 @@ void write_video(struct MPContext *mpctx)
|
||||
}
|
||||
|
||||
double time_frame = MPMAX(mpctx->time_frame, -1);
|
||||
int64_t pts = mp_time_us() + (int64_t)(time_frame * 1e6);
|
||||
int64_t pts = mp_time_ns() + (int64_t)(time_frame * 1e9);
|
||||
|
||||
// wait until VO wakes us up to get more frames
|
||||
// (NB: in theory, the 1st frame after display sync mode change uses the
|
||||
@ -1240,7 +1240,7 @@ void write_video(struct MPContext *mpctx)
|
||||
diff /= mpctx->video_speed;
|
||||
if (mpctx->time_frame < 0)
|
||||
diff += mpctx->time_frame;
|
||||
frame->duration = MPCLAMP(diff, 0, 10) * 1e6;
|
||||
frame->duration = MPCLAMP(diff, 0, 10) * 1e9;
|
||||
}
|
||||
|
||||
mpctx->video_pts = mpctx->next_frames[0]->pts;
|
||||
|
@ -232,7 +232,7 @@ static void read_opts(struct vo *vo)
|
||||
struct vo_internal *in = vo->in;
|
||||
|
||||
pthread_mutex_lock(&in->lock);
|
||||
in->timing_offset = (uint64_t)(vo->opts->timing_offset * 1e6);
|
||||
in->timing_offset = (uint64_t)(vo->opts->timing_offset * 1e9);
|
||||
pthread_mutex_unlock(&in->lock);
|
||||
}
|
||||
|
||||
@ -782,7 +782,7 @@ bool vo_is_ready_for_frame(struct vo *vo, int64_t next_pts)
|
||||
// time.
|
||||
next_pts -= in->timing_offset;
|
||||
next_pts -= in->flip_queue_offset;
|
||||
int64_t now = mp_time_us();
|
||||
int64_t now = mp_time_ns();
|
||||
if (next_pts > now)
|
||||
r = false;
|
||||
if (!in->wakeup_pts || next_pts < in->wakeup_pts) {
|
||||
@ -830,9 +830,9 @@ void vo_wait_frame(struct vo *vo)
|
||||
static void wait_until(struct vo *vo, int64_t target)
|
||||
{
|
||||
struct vo_internal *in = vo->in;
|
||||
struct timespec ts = mp_time_us_to_realtime(target);
|
||||
struct timespec ts = mp_time_ns_to_realtime(target);
|
||||
pthread_mutex_lock(&in->lock);
|
||||
while (target > mp_time_us()) {
|
||||
while (target > mp_time_ns()) {
|
||||
if (in->queued_events & VO_EVENT_LIVE_RESIZING)
|
||||
break;
|
||||
if (pthread_cond_timedwait(&in->wakeup, &in->lock, &ts))
|
||||
@ -873,7 +873,7 @@ static bool render_frame(struct vo *vo)
|
||||
if (in->paused)
|
||||
frame->vsync_offset = 0;
|
||||
|
||||
int64_t now = mp_time_us();
|
||||
int64_t now = mp_time_ns();
|
||||
int64_t pts = frame->pts;
|
||||
int64_t duration = frame->duration;
|
||||
int64_t end_time = pts + duration;
|
||||
@ -889,7 +889,7 @@ static bool render_frame(struct vo *vo)
|
||||
in->dropped_frame &= frame->can_drop;
|
||||
// Even if we're hopelessly behind, rather degrade to 10 FPS playback,
|
||||
// instead of just freezing the display forever.
|
||||
in->dropped_frame &= now - (in->prev_vsync / 1000.0) < 100 * 1000;
|
||||
in->dropped_frame &= now - in->prev_vsync < 100 * 1e6;
|
||||
in->dropped_frame &= in->hasframe_rendered;
|
||||
|
||||
// Setup parameters for the next time this frame is drawn. ("frame" is the
|
||||
@ -907,7 +907,7 @@ static bool render_frame(struct vo *vo)
|
||||
|
||||
bool use_vsync = in->current_frame->display_synced && !in->paused;
|
||||
if (use_vsync && !in->expecting_vsync) // first DS frame in a row
|
||||
in->prev_vsync = now * 1000;
|
||||
in->prev_vsync = now;
|
||||
in->expecting_vsync = use_vsync;
|
||||
|
||||
// Store the initial value before we unlock.
|
||||
@ -1230,15 +1230,15 @@ void vo_get_src_dst_rects(struct vo *vo, struct mp_rect *out_src,
|
||||
out_src, out_dst, out_osd);
|
||||
}
|
||||
|
||||
// flip_page[_timed] will be called offset_us microseconds too early.
|
||||
// flip_page[_timed] will be called offset_us nanoseconds too early.
|
||||
// (For vo_vdpau, which does its own timing.)
|
||||
// num_req_frames set the requested number of requested vo_frame.frames.
|
||||
// (For vo_gpu interpolation.)
|
||||
void vo_set_queue_params(struct vo *vo, int64_t offset_us, int num_req_frames)
|
||||
void vo_set_queue_params(struct vo *vo, int64_t offset_ns, int num_req_frames)
|
||||
{
|
||||
struct vo_internal *in = vo->in;
|
||||
pthread_mutex_lock(&in->lock);
|
||||
in->flip_queue_offset = offset_us;
|
||||
in->flip_queue_offset = offset_ns;
|
||||
in->req_frames = MPCLAMP(num_req_frames, 1, VO_MAX_REQ_FRAMES);
|
||||
pthread_mutex_unlock(&in->lock);
|
||||
}
|
||||
|
@ -207,10 +207,10 @@ struct vo_extra {
|
||||
};
|
||||
|
||||
struct vo_frame {
|
||||
// If > 0, realtime when frame should be shown, in mp_time_us() units.
|
||||
// If > 0, realtime when frame should be shown, in mp_time_ns() units.
|
||||
// If 0, present immediately.
|
||||
int64_t pts;
|
||||
// Approximate frame duration, in us.
|
||||
// Approximate frame duration, in ns.
|
||||
int duration;
|
||||
// Realtime of estimated distance between 2 vsync events.
|
||||
double vsync_interval;
|
||||
@ -508,7 +508,7 @@ void vo_query_formats(struct vo *vo, uint8_t *list);
|
||||
void vo_event(struct vo *vo, int event);
|
||||
int vo_query_and_reset_events(struct vo *vo, int events);
|
||||
struct mp_image *vo_get_current_frame(struct vo *vo);
|
||||
void vo_set_queue_params(struct vo *vo, int64_t offset_us, int num_req_frames);
|
||||
void vo_set_queue_params(struct vo *vo, int64_t offset_ns, int num_req_frames);
|
||||
int vo_get_num_req_frames(struct vo *vo);
|
||||
double vo_get_vsync_interval(struct vo *vo);
|
||||
double vo_get_estimated_vsync_interval(struct vo *vo);
|
||||
|
@ -279,7 +279,7 @@ static void resize(struct vo *vo)
|
||||
vc->flip_offset_us = vo->opts->fullscreen ?
|
||||
1000LL * vc->flip_offset_fs :
|
||||
1000LL * vc->flip_offset_window;
|
||||
vo_set_queue_params(vo, vc->flip_offset_us, 1);
|
||||
vo_set_queue_params(vo, vc->flip_offset_us * 1000, 1);
|
||||
|
||||
if (vc->output_surface_w < vo->dwidth || vc->output_surface_h < vo->dheight ||
|
||||
vc->rotation != vo->params->rotate)
|
||||
|
Loading…
Reference in New Issue
Block a user