summaryrefslogtreecommitdiffhomepage
path: root/video/camera.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2019-03-18 15:20:09 +0100
committerStanislaw Halik <sthalik@misaki.pl>2019-03-18 15:20:09 +0100
commit5023b54ba76325bb0b5598d59714bdad2d55d81e (patch)
tree15cc639eff7dbfa12eeccaa52d7fd251f18969e6 /video/camera.hpp
parent3aababf6fd53a7b0312c2c1492bab6b43584b613 (diff)
video: add support for camera modules
Issue: #910
Diffstat (limited to 'video/camera.hpp')
-rw-r--r--video/camera.hpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/video/camera.hpp b/video/camera.hpp
new file mode 100644
index 00000000..c9577933
--- /dev/null
+++ b/video/camera.hpp
@@ -0,0 +1,95 @@
+/* Copyright (c) 2019 Stanislaw Halik <sthalik@misaki.pl>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+
+#pragma once
+
+#include "export.hpp"
+
+#include <memory>
+#include <vector>
+
+#include <QString>
+
+namespace video
+{
+
+struct frame final
+{
+ unsigned char* data = nullptr;
+ int width = 0, height = 0, stride = 0, channels = 0;
+};
+
+} // ns video
+
+namespace video::impl {
+
+using namespace video;
+
+struct camera;
+
+struct OTR_VIDEO_EXPORT camera_
+{
+ camera_();
+ virtual ~camera_();
+
+ virtual std::vector<QString> camera_names() const = 0;
+ virtual std::unique_ptr<camera> make_camera(const QString& name) = 0;
+ [[nodiscard]] virtual bool show_dialog(const QString& camera_name) = 0;
+ virtual bool can_show_dialog(const QString& camera_name) = 0;
+};
+
+struct OTR_VIDEO_EXPORT camera
+{
+ struct info final
+ {
+ int width = 0, height = 0, fps = 0;
+ };
+
+ camera();
+ virtual ~camera();
+
+ [[nodiscard]] virtual bool start(const info& args) = 0;
+ virtual void stop() = 0;
+ virtual bool is_open() = 0;
+
+ virtual std::tuple<const frame&, bool> get_frame() = 0;
+ [[nodiscard]] virtual bool show_dialog() = 0;
+};
+
+OTR_VIDEO_EXPORT
+void register_camera(std::unique_ptr<impl::camera_> metadata);
+
+} // ns video::impl
+
+#define OTR_REGISTER_CAMERA2(type, ctr) \
+ namespace { \
+ struct init_##ctr \
+ { \
+ static char fuzz; \
+ }; \
+ char init_##ctr :: fuzz = \
+ (::video::impl::register_camera(std::make_unique<type>()), 0); \
+ } // anon ns
+
+#define OTR_REGISTER_CAMERA(type) \
+ OTR_REGISTER_CAMERA2(type, __COUNTER__)
+
+namespace video
+{
+using camera_impl = typename impl::camera;
+
+OTR_VIDEO_EXPORT
+std::unique_ptr<camera_impl> make_camera(const QString& name);
+
+OTR_VIDEO_EXPORT
+std::vector<QString> camera_names();
+
+[[nodiscard]]
+OTR_VIDEO_EXPORT
+bool show_dialog(const QString& camera_name);
+
+} // ns video