mirror of
https://github.com/WiVRn/WiVRn.git
synced 2026-11-20 09:01:39 -08:00
Fix pacer on reconnect
This commit is contained in:
1 parent
1266a46947
commit
a8c99ea4c1
4 files changed
+30
-9
No files matched your search
@@ -36,7 +36,7 @@ struct clock_offset
|
||||
int64_t b = 0;
|
||||
double a = 1;
|
||||
|
||||
operator bool()
|
||||
operator bool() const
|
||||
{
|
||||
return b != 0;
|
||||
}
|
||||
|
||||
@@ -463,6 +463,10 @@ static void * comp_wivrn_present_thread(void * void_param)
|
||||
encoder->Encode(*cn->cnx, psc_image.view_info, psc_image.frame_index);
|
||||
}
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
U_LOG_W("encode error: %s", e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Ignore errors
|
||||
@@ -643,6 +647,8 @@ static void comp_wivrn_info_gpu(struct comp_target * ct, int64_t frame_id, uint6
|
||||
|
||||
void wivrn_comp_target::on_feedback(const from_headset::feedback & feedback, const clock_offset & o)
|
||||
{
|
||||
if (not o)
|
||||
return;
|
||||
pacer.on_feedback(feedback, o);
|
||||
if (not feedback.sent_to_decoder)
|
||||
{
|
||||
@@ -654,6 +660,7 @@ void wivrn_comp_target::on_feedback(const from_headset::feedback & feedback, con
|
||||
|
||||
void wivrn_comp_target::reset_encoders()
|
||||
{
|
||||
pacer.reset();
|
||||
for (auto & encoder: encoders)
|
||||
{
|
||||
encoder->SyncNeeded();
|
||||
|
||||
@@ -44,14 +44,11 @@ void wivrn_pacer::predict(
|
||||
std::lock_guard lock(mutex);
|
||||
auto now = os_monotonic_get_ns();
|
||||
|
||||
if (next_frame_ns == 0)
|
||||
if (next_frame_ns < now)
|
||||
next_frame_ns = now;
|
||||
|
||||
next_frame_ns += frame_duration_ns;
|
||||
|
||||
if (next_frame_ns < now)
|
||||
next_frame_ns = now;
|
||||
|
||||
out_wake_up_time_ns = next_frame_ns;
|
||||
out_desired_present_time_ns = out_wake_up_time_ns + mean_wake_up_to_present_ns;
|
||||
out_present_slop_ns = 0;
|
||||
@@ -135,7 +132,9 @@ void wivrn_pacer::on_feedback(const xrt::drivers::wivrn::from_headset::feedback
|
||||
auto & when = in_flight_frames[feedback.frame_index % in_flight_frames.size()];
|
||||
if (when.frame_id == feedback.frame_index)
|
||||
{
|
||||
mean_present_to_display_ns = std::lerp(mean_present_to_display_ns, offset.from_headset(feedback.displayed) - when.present_ns, 0.1);
|
||||
auto displayed = offset.from_headset(feedback.displayed);
|
||||
if (displayed > when.present_ns)
|
||||
mean_present_to_display_ns = std::lerp(mean_present_to_display_ns, displayed - when.present_ns, 0.1);
|
||||
when.frame_id = 0;
|
||||
}
|
||||
}
|
||||
@@ -167,3 +166,14 @@ void wivrn_pacer::mark_timing_point(
|
||||
in_flight_frames[frame_id % in_flight_frames.size()] = {.frame_id = uint64_t(frame_id), .present_ns = when_ns};
|
||||
}
|
||||
}
|
||||
|
||||
void wivrn_pacer::reset()
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
for (auto & stream: streams)
|
||||
{
|
||||
stream.times.clear();
|
||||
stream.next_times_index = 0;
|
||||
}
|
||||
in_flight_frames = {};
|
||||
}
|
||||
@@ -35,8 +35,8 @@ class wivrn_pacer
|
||||
uint64_t next_frame_ns;
|
||||
uint64_t frame_duration_ns;
|
||||
|
||||
uint64_t mean_wake_up_to_present_ns = 0;
|
||||
uint64_t mean_present_to_display_ns = 0;
|
||||
uint64_t mean_wake_up_to_present_ns;
|
||||
uint64_t mean_present_to_display_ns;
|
||||
|
||||
uint64_t last_wake_up_ns = 0;
|
||||
|
||||
@@ -60,7 +60,9 @@ class wivrn_pacer
|
||||
public:
|
||||
wivrn_pacer(uint64_t frame_duration) :
|
||||
next_frame_ns(0),
|
||||
frame_duration_ns(frame_duration)
|
||||
frame_duration_ns(frame_duration),
|
||||
mean_wake_up_to_present_ns(1'000'000),
|
||||
mean_present_to_display_ns(frame_duration)
|
||||
{}
|
||||
|
||||
void set_stream_count(size_t count);
|
||||
@@ -77,4 +79,6 @@ public:
|
||||
comp_target_timing_point point,
|
||||
int64_t frame_id,
|
||||
uint64_t when_ns);
|
||||
|
||||
void reset();
|
||||
};
|
||||
Reference in new issue
Block a user