Logo
ApraPipes 1.0
Loading...
Searching...
No Matches
H264EncoderV4L2.h
1#pragma once
2
3#include "Module.h"
4#include "declarative/PropertyMacros.h"
5
7
9{
10public:
11 // Default constructor for declarative pipeline
15
16 H264EncoderV4L2Props(bool _enableMotionVectors, int _motionVectorThreshold = 5): targetKbps(1024)
17 {
18 enableMotionVectors = _enableMotionVectors;
19 motionVectorThreshold = _motionVectorThreshold;
20 }
21
22 uint32_t targetKbps;
23 bool enableMotionVectors = false;
25
26 // ============================================================
27 // Property Binding for Declarative Pipeline
28 // ============================================================
29 template<typename PropsT>
30 static void applyProperties(
31 PropsT& props,
32 const std::map<std::string, apra::ScalarPropertyValue>& values,
33 std::vector<std::string>& missingRequired
34 ) {
35 // Handle uint32_t via int64_t
36 auto it = values.find("targetKbps");
37 if (it != values.end()) {
38 if (auto* val = std::get_if<int64_t>(&it->second)) {
39 props.targetKbps = static_cast<uint32_t>(*val);
40 }
41 }
42 apra::applyProp(props.enableMotionVectors, "enableMotionVectors", values, false, missingRequired);
43 apra::applyProp(props.motionVectorThreshold, "motionVectorThreshold", values, false, missingRequired);
44 }
45
46 apra::ScalarPropertyValue getProperty(const std::string& propName) const {
47 if (propName == "targetKbps") return static_cast<int64_t>(targetKbps);
48 if (propName == "enableMotionVectors") return enableMotionVectors;
49 if (propName == "motionVectorThreshold") return static_cast<int64_t>(motionVectorThreshold);
50 throw std::runtime_error("Unknown property: " + propName);
51 }
52
53 bool setProperty(const std::string& propName, const apra::ScalarPropertyValue& value) {
54 return false; // All properties are static
55 }
56
57 static std::vector<std::string> dynamicPropertyNames() {
58 return {};
59 }
60};
61
62class H264EncoderV4L2 : public Module
63{
64
65public:
67 virtual ~H264EncoderV4L2();
68 bool init();
69 bool term();
70
71protected:
72 bool process(frame_container& frames);
73 bool processSOS(frame_sp& frame);
74 bool validateInputPins();
75 bool validateOutputPins();
76 bool shouldTriggerSOS();
77 bool processEOS(string& pinId);
78
79private:
80 std::shared_ptr<H264EncoderV4L2Helper> mHelper;
81
85};
Definition H264EncoderV4L2Helper.h:10
Definition H264EncoderV4L2.h:9
H264EncoderV4L2Props()
Definition H264EncoderV4L2.h:12
static std::vector< std::string > dynamicPropertyNames()
Definition H264EncoderV4L2.h:57
static void applyProperties(PropsT &props, const std::map< std::string, apra::ScalarPropertyValue > &values, std::vector< std::string > &missingRequired)
Definition H264EncoderV4L2.h:30
H264EncoderV4L2Props(bool _enableMotionVectors, int _motionVectorThreshold=5)
Definition H264EncoderV4L2.h:16
apra::ScalarPropertyValue getProperty(const std::string &propName) const
Definition H264EncoderV4L2.h:46
bool setProperty(const std::string &propName, const apra::ScalarPropertyValue &value)
Definition H264EncoderV4L2.h:53
int motionVectorThreshold
Definition H264EncoderV4L2.h:24
bool enableMotionVectors
Definition H264EncoderV4L2.h:23
uint32_t targetKbps
Definition H264EncoderV4L2.h:22
Definition H264EncoderV4L2.h:63
std::shared_ptr< H264EncoderV4L2Helper > mHelper
Definition H264EncoderV4L2.h:80
bool term()
Definition H264EncoderV4L2.cpp:83
H264EncoderV4L2(H264EncoderV4L2Props props)
Definition H264EncoderV4L2.cpp:11
H264EncoderV4L2Props mProps
Definition H264EncoderV4L2.h:82
bool processSOS(frame_sp &frame)
Definition H264EncoderV4L2.cpp:96
std::string motionVectorFramePinId
Definition H264EncoderV4L2.h:83
bool validateOutputPins()
Definition H264EncoderV4L2.cpp:59
std::string h264FrameOutputPinId
Definition H264EncoderV4L2.h:84
virtual ~H264EncoderV4L2()
Definition H264EncoderV4L2.cpp:19
bool validateInputPins()
Definition H264EncoderV4L2.cpp:28
bool init()
Definition H264EncoderV4L2.cpp:73
bool processEOS(string &pinId)
Definition H264EncoderV4L2.cpp:163
bool shouldTriggerSOS()
Definition H264EncoderV4L2.cpp:158
bool process(frame_container &frames)
Definition H264EncoderV4L2.cpp:88
Definition Module.h:33
Definition Module.h:151
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