Skip to content

Commit

Permalink
Added fields to encodedframe
Browse files Browse the repository at this point in the history
  • Loading branch information
asahtik committed Oct 10, 2023
1 parent bfa0026 commit 40e2c12
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 88 deletions.
202 changes: 115 additions & 87 deletions src/pipeline/datatype/EncodedFrameBindings.cpp
Original file line number Diff line number Diff line change
@@ -1,107 +1,135 @@
#include "DatatypeBindings.hpp"
#include "depthai-shared/datatype/RawEncodedFrame.hpp"
#include "pipeline/CommonBindings.hpp"
#include <unordered_map>
#include <memory>
#include <unordered_map>

// depthai
#include "depthai/pipeline/datatype/EncodedFrame.hpp"

//pybind
// pybind
#include <pybind11/chrono.h>
#include <pybind11/numpy.h>

void bind_encodedframe(pybind11::module& m, void* pCallstack){

using namespace dai;
void bind_encodedframe(pybind11::module &m, void *pCallstack) {

py::class_<RawEncodedFrame, RawBuffer, std::shared_ptr<RawEncodedFrame>> rawEncodedFrame(m, "RawEncodedFrame", DOC(dai, RawEncodedFrame));
py::enum_<RawEncodedFrame::Profile> rawEncodedFrameProfile(rawEncodedFrame, "Profile");
py::enum_<RawEncodedFrame::FrameType> rawEncodedFrameType(rawEncodedFrame, "FrameType", DOC(dai, RawEncodedFrame, FrameType));
py::class_<EncodedFrame, Buffer, std::shared_ptr<EncodedFrame>> encodedFrame(m, "EncodedFrame", DOC(dai, EncodedFrame));
using namespace dai;

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Call the rest of the type defines, then perform the actual bindings
Callstack* callstack = (Callstack*) pCallstack;
auto cb = callstack->top();
callstack->pop();
cb(m, pCallstack);
// Actual bindings
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
py::class_<RawEncodedFrame, RawBuffer, std::shared_ptr<RawEncodedFrame>>
rawEncodedFrame(m, "RawEncodedFrame", DOC(dai, RawEncodedFrame));
py::enum_<RawEncodedFrame::Profile> rawEncodedFrameProfile(rawEncodedFrame,
"Profile");
py::enum_<RawEncodedFrame::FrameType> rawEncodedFrameType(
rawEncodedFrame, "FrameType", DOC(dai, RawEncodedFrame, FrameType));
py::class_<EncodedFrame, Buffer, std::shared_ptr<EncodedFrame>> encodedFrame(
m, "EncodedFrame", DOC(dai, EncodedFrame));

// Metadata / raw
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Call the rest of the type defines, then perform the actual bindings
Callstack *callstack = (Callstack *)pCallstack;
auto cb = callstack->top();
callstack->pop();
cb(m, pCallstack);
// Actual bindings
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////

rawEncodedFrame
.def(py::init<>())
.def_readwrite("quality", &RawEncodedFrame::quality)
.def_readwrite("bitrate", &RawEncodedFrame::bitrate)
.def_readwrite("profile", &RawEncodedFrame::profile)
.def_readwrite("lossless", &RawEncodedFrame::lossless)
.def_readwrite("type", &RawEncodedFrame::type)
.def_readwrite("sequenceNum", &RawEncodedFrame::sequenceNum)
.def_property("ts",
[](const RawEncodedFrame& o){
double ts = o.ts.sec + o.ts.nsec / 1000000000.0;
return ts;
},
[](RawEncodedFrame& o, double ts){
o.ts.sec = ts;
o.ts.nsec = (ts - o.ts.sec) * 1000000000.0;
}
)
.def_property("tsDevice",
[](const RawEncodedFrame& o){
double ts = o.tsDevice.sec + o.tsDevice.nsec / 1000000000.0;
return ts;
},
[](RawEncodedFrame& o, double ts){
o.tsDevice.sec = ts;
o.tsDevice.nsec = (ts - o.tsDevice.sec) * 1000000000.0;
}
)
;
// Metadata / raw

rawEncodedFrame.def(py::init<>())
.def_readwrite("quality", &RawEncodedFrame::quality)
.def_readwrite("bitrate", &RawEncodedFrame::bitrate)
.def_readwrite("profile", &RawEncodedFrame::profile)
.def_readwrite("lossless", &RawEncodedFrame::lossless)
.def_readwrite("type", &RawEncodedFrame::type)
.def_readwrite("instanceNum", &RawEncodedFrame::instanceNum)
.def_readwrite("sequenceNum", &RawEncodedFrame::sequenceNum)
.def_property(
"ts",
[](const RawEncodedFrame &o) {
double ts = o.ts.sec + o.ts.nsec / 1000000000.0;
return ts;
},
[](RawEncodedFrame &o, double ts) {
o.ts.sec = ts;
o.ts.nsec = (ts - o.ts.sec) * 1000000000.0;
})
.def_property(
"tsDevice",
[](const RawEncodedFrame &o) {
double ts = o.tsDevice.sec + o.tsDevice.nsec / 1000000000.0;
return ts;
},
[](RawEncodedFrame &o, double ts) {
o.tsDevice.sec = ts;
o.tsDevice.nsec = (ts - o.tsDevice.sec) * 1000000000.0;
});

rawEncodedFrameProfile
.value("JPEG", EncodedFrame::Profile::JPEG)
.value("AVC", EncodedFrame::Profile::AVC)
.value("HEVC", EncodedFrame::Profile::HEVC)
;
rawEncodedFrameProfile.value("JPEG", EncodedFrame::Profile::JPEG)
.value("AVC", EncodedFrame::Profile::AVC)
.value("HEVC", EncodedFrame::Profile::HEVC);

rawEncodedFrameType
.value("I", EncodedFrame::FrameType::I)
.value("P", EncodedFrame::FrameType::P)
.value("B", EncodedFrame::FrameType::B)
.value("Unknown", EncodedFrame::FrameType::Unknown)
;
rawEncodedFrameType.value("I", EncodedFrame::FrameType::I)
.value("P", EncodedFrame::FrameType::P)
.value("B", EncodedFrame::FrameType::B)
.value("Unknown", EncodedFrame::FrameType::Unknown);

// Message
encodedFrame
.def(py::init<>())
// getters
.def("getTimestamp", py::overload_cast<>(&EncodedFrame::getTimestamp, py::const_), DOC(dai, EncodedFrame, getTimestamp))
.def("getTimestampDevice", py::overload_cast<>(&EncodedFrame::getTimestampDevice, py::const_), DOC(dai, EncodedFrame, getTimestampDevice))
.def("getSequenceNum", &EncodedFrame::getSequenceNum, DOC(dai, EncodedFrame, getSequenceNum))
.def("getQuality", &EncodedFrame::getQuality, DOC(dai, EncodedFrame, getQuality))
.def("getBitrate", &EncodedFrame::getBitrate, DOC(dai, EncodedFrame, getBitrate))
.def("getFrameType", &EncodedFrame::getFrameType, DOC(dai, EncodedFrame, getFrameType))
.def("getLossless", &EncodedFrame::getLossless, DOC(dai, EncodedFrame, getLossless))
.def("getProfile", &EncodedFrame::getProfile, DOC(dai, EncodedFrame, getProfile))
// Message
encodedFrame
.def(py::init<>())
// getters
.def("getTimestamp",
py::overload_cast<>(&EncodedFrame::getTimestamp, py::const_),
DOC(dai, EncodedFrame, getTimestamp))
.def("getTimestampDevice",
py::overload_cast<>(&EncodedFrame::getTimestampDevice, py::const_),
DOC(dai, EncodedFrame, getTimestampDevice))
.def("getInstanceNum", &EncodedFrame::getInstanceNum,
DOC(dai, EncodedFrame, getInstanceNum))
.def("getSequenceNum", &EncodedFrame::getSequenceNum,
DOC(dai, EncodedFrame, getSequenceNum))
.def("getExposureTime", &EncodedFrame::getExposureTime,
DOC(dai, EncodedFrame, getExposureTime))
.def("getSensitivity", &EncodedFrame::getSensitivity,
DOC(dai, EncodedFrame, getSensitivity))
.def("getColorTemperature", &EncodedFrame::getColorTemperature,
DOC(dai, EncodedFrame, getColorTemperature))
.def("getLensPosition", &EncodedFrame::getLensPosition,
DOC(dai, EncodedFrame, getLensPosition))
.def("getQuality", &EncodedFrame::getQuality,
DOC(dai, EncodedFrame, getQuality))
.def("getBitrate", &EncodedFrame::getBitrate,
DOC(dai, EncodedFrame, getBitrate))
.def("getFrameType", &EncodedFrame::getFrameType,
DOC(dai, EncodedFrame, getFrameType))
.def("getLossless", &EncodedFrame::getLossless,
DOC(dai, EncodedFrame, getLossless))
.def("getProfile", &EncodedFrame::getProfile,
DOC(dai, EncodedFrame, getProfile))

// setters
.def("setTimestamp", &EncodedFrame::setTimestamp, DOC(dai, EncodedFrame, setTimestamp))
.def("setTimestampDevice", &EncodedFrame::setTimestampDevice, DOC(dai, EncodedFrame, setTimestampDevice))
.def("setSequenceNum", &EncodedFrame::setSequenceNum, DOC(dai, EncodedFrame, getSequenceNum))
.def("setQuality", &EncodedFrame::setQuality, DOC(dai, EncodedFrame, getQuality))
.def("setBitrate", &EncodedFrame::setBitrate, DOC(dai, EncodedFrame, getBitrate))
.def("setFrameType", &EncodedFrame::setFrameType, DOC(dai, EncodedFrame, getFrameType))
.def("setLossless", &EncodedFrame::setLossless, DOC(dai, EncodedFrame, getLossless))
.def("setProfile", &EncodedFrame::setProfile, DOC(dai, EncodedFrame, getProfile))
;
// add aliases dai.ImgFrame.Type and dai.ImgFrame.Specs
m.attr("EncodedFrame").attr("FrameType") = m.attr("RawEncodedFrame").attr("FrameType");
m.attr("EncodedFrame").attr("Profile") = m.attr("RawEncodedFrame").attr("Profile");
// setters
.def("setTimestamp", &EncodedFrame::setTimestamp,
DOC(dai, EncodedFrame, setTimestamp))
.def("setTimestampDevice", &EncodedFrame::setTimestampDevice,
DOC(dai, EncodedFrame, setTimestampDevice))
.def("setSequenceNum", &EncodedFrame::setSequenceNum,
DOC(dai, EncodedFrame, getSequenceNum))
.def("setQuality", &EncodedFrame::setQuality,
DOC(dai, EncodedFrame, getQuality))
.def("setBitrate", &EncodedFrame::setBitrate,
DOC(dai, EncodedFrame, getBitrate))
.def("setFrameType", &EncodedFrame::setFrameType,
DOC(dai, EncodedFrame, getFrameType))
.def("setLossless", &EncodedFrame::setLossless,
DOC(dai, EncodedFrame, getLossless))
.def("setProfile", &EncodedFrame::setProfile,
DOC(dai, EncodedFrame, getProfile));
// add aliases dai.ImgFrame.Type and dai.ImgFrame.Specs
m.attr("EncodedFrame").attr("FrameType") =
m.attr("RawEncodedFrame").attr("FrameType");
m.attr("EncodedFrame").attr("Profile") =
m.attr("RawEncodedFrame").attr("Profile");
}

0 comments on commit 40e2c12

Please sign in to comment.