diff options
-rw-r--r-- | video-ps3eye/module.cpp | 2 | ||||
-rw-r--r-- | video-ps3eye/module.hpp | 1 | ||||
-rw-r--r-- | video-ps3eye/shm-layout.hpp | 11 | ||||
-rw-r--r-- | video-ps3eye/wrapper.cxx | 46 |
4 files changed, 32 insertions, 28 deletions
diff --git a/video-ps3eye/module.cpp b/video-ps3eye/module.cpp index fe6b51b8..2c9ce100 100644 --- a/video-ps3eye/module.cpp +++ b/video-ps3eye/module.cpp @@ -179,7 +179,7 @@ ok: std::tuple<const frame&, bool> ps3eye_camera::get_frame() { volatile auto& ptr = *(ps3eye::shm*)shm.ptr(); - constexpr int sleep_ms = 10; + constexpr int sleep_ms = 2; constexpr int max_sleeps = 2000/sleep_ms; if (!open) diff --git a/video-ps3eye/module.hpp b/video-ps3eye/module.hpp index 73cdf04c..6e0addfc 100644 --- a/video-ps3eye/module.hpp +++ b/video-ps3eye/module.hpp @@ -28,6 +28,7 @@ struct ps3eye_camera final : video::impl::camera shm_wrapper shm { "ps3eye-driver-shm", nullptr, sizeof(ps3eye::shm) }; settings s; frame fr; + int framerate = 30; bool open = false; unsigned timecode = 0; diff --git a/video-ps3eye/shm-layout.hpp b/video-ps3eye/shm-layout.hpp index 2335eab8..577021b9 100644 --- a/video-ps3eye/shm-layout.hpp +++ b/video-ps3eye/shm-layout.hpp @@ -5,20 +5,22 @@ namespace ps3eye { struct shm_in { enum class mode : uint8_t { qvga, vga, }; - enum class status : uint8_t { starting, running, fail, terminate, }; uint32_t settings_updated; uint8_t framerate; mode resolution; - status status_; //uint8_t sharpness, contrast, brightness hue, saturation; uint8_t gain, exposure, auto_gain, test_pattern; uint8_t do_exit; }; -struct shm_out { +struct shm_out +{ + enum class status : uint8_t { starting, running, fail, terminate, }; + uint32_t timecode; uint32_t settings_updated_ack; + status status_; char error_string[256]; union { uint8_t data_320x240[320][240][3]; @@ -31,9 +33,6 @@ struct shm { static constexpr unsigned _padding_len = (_cacheline_len - (sizeof(shm_in) & (_cacheline_len - 1))) & (_cacheline_len - 1); - using resolution = shm_in::mode; - using status = shm_in::status; - shm_out out; const char* _padding[_padding_len]; shm_in in; diff --git a/video-ps3eye/wrapper.cxx b/video-ps3eye/wrapper.cxx index 0f063097..37f67a70 100644 --- a/video-ps3eye/wrapper.cxx +++ b/video-ps3eye/wrapper.cxx @@ -4,7 +4,6 @@ #include "ps3eye-driver/ps3eye.hpp" #include <thread> -#include <chrono> #include <cstdlib> #ifdef __clang__ @@ -42,6 +41,18 @@ static void update_settings(ps3eye::camera& camera, const volatile ps3eye::shm_i camera.set_test_pattern_status(in.test_pattern); } +static ps3eye::resolution get_mode(ps3eye::shm_in::mode res) +{ + switch (res) + { + default: + case ps3eye::shm_in::mode::qvga: + return ps3eye::res_QVGA; + case ps3eye::shm_in::mode::vga: + return ps3eye::res_VGA; + } +} + int main(int argc, char** argv) { (void)argc; (void)argv; @@ -52,34 +63,22 @@ int main(int argc, char** argv) auto cameras = ps3eye::list_devices(); + out.status_ = ps3eye::shm_out::status::starting; + if (cameras.empty()) error(out, "no camera found"); auto& camera = cameras[0]; camera->set_debug(false); - uint8_t* frame; + auto frame = (uint8_t*)out.data_640x480; decltype(out.timecode) timecode = 0; { - ps3eye::resolution mode; - switch (in.resolution) - { - case ps3eye::shm_in::mode::qvga: - mode = ps3eye::res_QVGA; - frame = (uint8_t*)out.data_320x240; - break; - case ps3eye::shm_in::mode::vga: - mode = ps3eye::res_VGA; - frame = (uint8_t*)out.data_640x480; - break; - default: error(out, "wrong resolution %u", (unsigned)mode); - } - int framerate = in.framerate; - if (!framerate) + if (framerate <= 0) framerate = 60; - if (!camera->init(mode, framerate)) + if (!camera->init(get_mode(in.resolution), framerate)) error(out, "camera init failed: %s", camera->error_string()); update_settings(*camera, in); @@ -98,16 +97,21 @@ int main(int argc, char** argv) auto cookie = in.settings_updated; if (cookie != out.settings_updated_ack) { + camera->stop(); update_settings(*camera, in); + int framerate = in.framerate; + if (framerate <= 0) + framerate = 60; + if (!camera->init(get_mode(in.resolution), framerate)) + error(out, "camera init failed: %s", camera->error_string()); + if (!camera->start()) + error(out, "can't start camera: %s", camera->error_string()); out.settings_updated_ack = cookie; } } if (!camera->get_frame(frame)) - { - std::this_thread::sleep_for(std::chrono::milliseconds{4}); continue; - } out.timecode = ++timecode; |