Logo
ApraPipes 1.0
Loading...
Searching...
No Matches
MotionVectorExtractor.h
1#pragma once
2#include "Module.h"
3#include "declarative/PropertyMacros.h"
4
5using namespace std;
7class DetailFfmpeg;
9
11{
12public:
18
19 // Constructor with defaults - supports declarative pipeline (can be called with no args)
20 MotionVectorExtractorProps(MVExtractMethod _MVExtractMethod = MVExtractMethod::FFMPEG, bool _sendDecodedFrame = false, int _motionVectorThreshold = 2) : MVExtract(_MVExtractMethod), sendDecodedFrame(_sendDecodedFrame), motionVectorThreshold(_motionVectorThreshold)
21 {
22 }
23
25 {
27 }
28 bool sendDecodedFrame = false;
31
32 // ============================================================
33 // Property Binding for Declarative Pipeline
34 // ============================================================
35 template<typename PropsT>
36 static void applyProperties(
37 PropsT& props,
38 const std::map<std::string, apra::ScalarPropertyValue>& values,
39 std::vector<std::string>& missingRequired
40 ) {
41 // Handle MVExtractMethod enum
42 auto it = values.find("MVExtractMethod");
43 if (it != values.end()) {
44 if (auto* strVal = std::get_if<std::string>(&it->second)) {
45 if (*strVal == "FFMPEG") props.MVExtract = MVExtractMethod::FFMPEG;
46 else if (*strVal == "OPENH264") props.MVExtract = MVExtractMethod::OPENH264;
47 }
48 }
49 apra::applyProp(props.sendDecodedFrame, "sendDecodedFrame", values, false, missingRequired);
50 apra::applyProp(props.motionVectorThreshold, "motionVectorThreshold", values, false, missingRequired);
51 }
52
53 apra::ScalarPropertyValue getProperty(const std::string& propName) const {
54 if (propName == "MVExtractMethod") return MVExtract == FFMPEG ? std::string("FFMPEG") : std::string("OPENH264");
55 if (propName == "sendDecodedFrame") return sendDecodedFrame;
56 if (propName == "motionVectorThreshold") return static_cast<int64_t>(motionVectorThreshold);
57 throw std::runtime_error("Unknown property: " + propName);
58 }
59
60 bool setProperty(const std::string& propName, const apra::ScalarPropertyValue& value) {
61 return false; // All properties are static
62 }
63
64 static std::vector<std::string> dynamicPropertyNames() {
65 return {};
66 }
67
68private:
70
71 template <class Archive>
72 void serialize(Archive& ar, const unsigned int version)
73 {
74 ar& boost::serialization::base_object<ModuleProps>(*this);
77 }
78};
79
81{
82public:
85 bool init();
86 bool term();
89protected:
90 bool process(frame_container& frame);
91 bool validateInputPins();
92 bool validateOutputPins();
93 bool shouldTriggerSOS();
94 bool processSOS(frame_sp& frame);
95 void setMetadata(frame_sp metadata);
96 bool handlePropsChange(frame_sp& frame);
97private:
98 boost::shared_ptr<MvExtractDetailAbs> mDetail;
99 framemetadata_sp rawOutputMetadata;
100 bool mShouldTriggerSOS = true;
102};
Definition MotionVectorExtractor.cpp:49
Definition MotionVectorExtractor.cpp:64
Definition Module.h:33
virtual size_t getSerializeSize()
Definition Module.h:101
Definition Module.h:151
Definition MotionVectorExtractor.h:11
bool sendDecodedFrame
Definition MotionVectorExtractor.h:28
MVExtractMethod MVExtract
Definition MotionVectorExtractor.h:30
int motionVectorThreshold
Definition MotionVectorExtractor.h:29
size_t getSerializeSize()
Definition MotionVectorExtractor.h:24
static void applyProperties(PropsT &props, const std::map< std::string, apra::ScalarPropertyValue > &values, std::vector< std::string > &missingRequired)
Definition MotionVectorExtractor.h:36
void serialize(Archive &ar, const unsigned int version)
Definition MotionVectorExtractor.h:72
MotionVectorExtractorProps(MVExtractMethod _MVExtractMethod=MVExtractMethod::FFMPEG, bool _sendDecodedFrame=false, int _motionVectorThreshold=2)
Definition MotionVectorExtractor.h:20
MVExtractMethod
Definition MotionVectorExtractor.h:14
@ OPENH264
Definition MotionVectorExtractor.h:16
@ FFMPEG
Definition MotionVectorExtractor.h:15
static std::vector< std::string > dynamicPropertyNames()
Definition MotionVectorExtractor.h:64
apra::ScalarPropertyValue getProperty(const std::string &propName) const
Definition MotionVectorExtractor.h:53
friend class boost::serialization::access
Definition MotionVectorExtractor.h:69
bool setProperty(const std::string &propName, const apra::ScalarPropertyValue &value)
Definition MotionVectorExtractor.h:60
Definition MotionVectorExtractor.h:81
boost::shared_ptr< MvExtractDetailAbs > mDetail
Definition MotionVectorExtractor.h:98
void setProps(MotionVectorExtractorProps &props)
Definition MotionVectorExtractor.cpp:418
bool validateInputPins()
Definition MotionVectorExtractor.cpp:339
MotionVectorExtractor(MotionVectorExtractorProps _props)
Definition MotionVectorExtractor.cpp:315
bool mShouldTriggerSOS
Definition MotionVectorExtractor.h:100
bool process(frame_container &frame)
Definition MotionVectorExtractor.cpp:380
bool init()
Definition MotionVectorExtractor.cpp:330
void setMetadata(frame_sp metadata)
Definition MotionVectorExtractor.cpp:388
MotionVectorExtractorProps mProps
Definition MotionVectorExtractor.h:101
bool handlePropsChange(frame_sp &frame)
Definition MotionVectorExtractor.cpp:410
bool processSOS(frame_sp &frame)
Definition MotionVectorExtractor.cpp:404
framemetadata_sp rawOutputMetadata
Definition MotionVectorExtractor.h:99
bool term()
Definition MotionVectorExtractor.cpp:335
bool validateOutputPins()
Definition MotionVectorExtractor.cpp:355
bool shouldTriggerSOS()
Definition MotionVectorExtractor.cpp:376
virtual ~MotionVectorExtractor()
Definition MotionVectorExtractor.h:84
MotionVectorExtractorProps getProps()
Definition MotionVectorExtractor.cpp:423
Definition MotionVectorExtractor.cpp:19
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