diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2020-03-29 15:36:16 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2020-03-29 15:36:43 +0200 |
commit | 3d20cc94beaa114a4ae8ab63e042ca907471d819 (patch) | |
tree | 222861f373c4f231719f883b17c81fafb1c5f847 /video-ps3eye/module.cpp | |
parent | fafe2e19d9f411f892fb9a162f03e6a6ce381f5a (diff) |
video/ps3eye: sleep the right amount
Diffstat (limited to 'video-ps3eye/module.cpp')
-rw-r--r-- | video-ps3eye/module.cpp | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/video-ps3eye/module.cpp b/video-ps3eye/module.cpp index db52f8ae..caed2fd7 100644 --- a/video-ps3eye/module.cpp +++ b/video-ps3eye/module.cpp @@ -158,6 +158,8 @@ bool ps3eye_camera::start(info& args) ptr.in.gain = (uint8_t)s.gain; ptr.in.exposure = (uint8_t)s.exposure; + sleep_ms = (int)std::ceil(1000./std::max(1, (int)ptr.in.framerate)); + wrapper.start(); constexpr int sleep_ms = 10, max_sleeps = 5000/sleep_ms; @@ -189,34 +191,40 @@ ok: std::tuple<const frame&, bool> ps3eye_camera::get_frame() { - volatile auto& ptr = *(ps3eye::shm*)shm.ptr(); - constexpr int sleep_ms = 2; - constexpr int max_sleeps = 2000/sleep_ms; + auto volatile* ptr = (ps3eye::shm*)shm.ptr(); - if (!open) - goto fail; + if (shm.success() && open) + { + int elapsed = std::min((int)std::ceil(t.elapsed_ms()), 100); + portable::sleep(sleep_ms - elapsed); - for (int i = 0; i < max_sleeps; i++) + if (unsigned tc = ptr->out.timecode; tc != timecode) + { + timecode = tc; + goto ok; + } + } + + for (int i = 0; i < 100; i++) { - unsigned new_timecode = ptr.out.timecode; - if (timecode != new_timecode) + if (unsigned tc = ptr->out.timecode; tc != timecode) { - timecode = new_timecode; + timecode = tc; goto ok; } - portable::sleep(sleep_ms); + portable::sleep(1); } -fail: stop(); return { fr, false }; - static_assert(offsetof(decltype(ptr.out), data_640x480) == offsetof(decltype(ptr.out), data_320x240)); + static_assert(offsetof(decltype(ptr->out), data_640x480) == offsetof(decltype(ptr->out), data_320x240)); ok: - memcpy(data, (unsigned char*)ptr.out.data_640x480,sizeof(ptr.out.data_640x480)); + t.start(); + memcpy(data, (unsigned char*)ptr->out.data_640x480,sizeof(ptr->out.data_640x480)); fr.data = data; - return { fr, true}; + return { fr, true }; } bool ps3eye_camera::show_dialog() |