Logo
ApraPipes 1.0
Loading...
Searching...
No Matches
WebCamSource.h
1#pragma once
2
3#include "Module.h"
4#include "declarative/PropertyMacros.h"
5
7{
8public:
9 // Constructor with defaults - supports declarative pipeline (can be called with no args)
10 WebCamSourceProps(int _cameraId = -1, uint32_t _width = 640, uint32_t _height = 480, int _fps = 30) : ModuleProps(), width(_width), height(_height), cameraId(_cameraId), fps(_fps) {}
11
12 uint32_t width = 640;
13 uint32_t height = 480;
14 int cameraId = -1;
15 int fps = 30;
16
18 {
19 return ModuleProps::getSerializeSize() + sizeof(width) + sizeof(height) + sizeof(cameraId) + sizeof(fps);
20 }
21
22 // ============================================================
23 // Property Binding for Declarative Pipeline
24 // ============================================================
25 template<typename PropsT>
26 static void applyProperties(
27 PropsT& props,
28 const std::map<std::string, apra::ScalarPropertyValue>& values,
29 std::vector<std::string>& missingRequired
30 ) {
31 apra::applyProp(props.cameraId, "cameraId", values, false, missingRequired);
32 apra::applyProp(props.width, "width", values, false, missingRequired);
33 apra::applyProp(props.height, "height", values, false, missingRequired);
34 apra::applyProp(props.fps, "fps", values, false, missingRequired);
35 }
36
37 apra::ScalarPropertyValue getProperty(const std::string& propName) const {
38 if (propName == "cameraId") return static_cast<int64_t>(cameraId);
39 if (propName == "width") return static_cast<int64_t>(width);
40 if (propName == "height") return static_cast<int64_t>(height);
41 if (propName == "fps") return static_cast<int64_t>(fps);
42 throw std::runtime_error("Unknown property: " + propName);
43 }
44
45 bool setProperty(const std::string& propName, const apra::ScalarPropertyValue& value) {
46 // All properties are static (can't change after init)
47 return false;
48 }
49
50 static std::vector<std::string> dynamicPropertyNames() {
51 return {}; // No dynamically changeable properties
52 }
53
54private:
56
57 template <class Archive>
58 void serialize(Archive &ar, const unsigned int version)
59 {
60 ar &boost::serialization::base_object<ModuleProps>(*this);
61 ar &width &height &cameraId &fps;
62 }
63};
64
65class WebCamSource : public Module
66{
67public:
69 virtual ~WebCamSource();
70 bool init();
71 bool term();
72
73 void setProps(WebCamSourceProps &props);
75
76protected:
77 bool produce();
78 bool validateOutputPins();
79 bool handlePropsChange(frame_sp &frame);
80
81private:
82 class Detail;
83 std::shared_ptr<Detail> mDetail;
84};
Definition Module.h:33
virtual size_t getSerializeSize()
Definition Module.h:101
Definition Module.h:151
Definition WebCamSource.h:7
void serialize(Archive &ar, const unsigned int version)
Definition WebCamSource.h:58
bool setProperty(const std::string &propName, const apra::ScalarPropertyValue &value)
Definition WebCamSource.h:45
apra::ScalarPropertyValue getProperty(const std::string &propName) const
Definition WebCamSource.h:37
int fps
Definition WebCamSource.h:15
uint32_t width
Definition WebCamSource.h:12
WebCamSourceProps(int _cameraId=-1, uint32_t _width=640, uint32_t _height=480, int _fps=30)
Definition WebCamSource.h:10
static std::vector< std::string > dynamicPropertyNames()
Definition WebCamSource.h:50
size_t getSerializeSize()
Definition WebCamSource.h:17
friend class boost::serialization::access
Definition WebCamSource.h:55
static void applyProperties(PropsT &props, const std::map< std::string, apra::ScalarPropertyValue > &values, std::vector< std::string > &missingRequired)
Definition WebCamSource.h:26
int cameraId
Definition WebCamSource.h:14
uint32_t height
Definition WebCamSource.h:13
Definition WebCamSource.cpp:7
Definition WebCamSource.h:66
void setProps(WebCamSourceProps &props)
Definition WebCamSource.cpp:105
bool term()
Definition WebCamSource.cpp:81
bool validateOutputPins()
Definition WebCamSource.cpp:61
bool produce()
Definition WebCamSource.cpp:86
bool init()
Definition WebCamSource.cpp:71
virtual ~WebCamSource()
Definition WebCamSource.cpp:59
WebCamSourceProps getProps()
Definition WebCamSource.cpp:97
std::shared_ptr< Detail > mDetail
Definition WebCamSource.h:83
bool handlePropsChange(frame_sp &frame)
Definition WebCamSource.cpp:110
WebCamSource(WebCamSourceProps props)
Definition WebCamSource.cpp:51
void applyProp(T &member, const char *propName, const std::map< std::string, ScalarPropertyValue > &values, bool isRequired, std::vector< std::string > &missingRequired)
Definition PropertyMacros.h:36
std::variant< int64_t, double, bool, std::string > ScalarPropertyValue
Definition ModuleRegistry.h:30