From 6f5e76aea9b2fbc0aacdff38ce0ae7ee130bccbe Mon Sep 17 00:00:00 2001 From: Naoto Kondo Date: Fri, 24 Apr 2020 21:36:56 +0900 Subject: [PATCH] Do not use wrapper class for SendCreate --- src/PySendCreate.cpp | 27 --------------------------- src/PySendCreate.hpp | 20 -------------------- src/main.cpp | 37 +++++++++++++++++++++++++++---------- 3 files changed, 27 insertions(+), 57 deletions(-) delete mode 100644 src/PySendCreate.cpp delete mode 100644 src/PySendCreate.hpp diff --git a/src/PySendCreate.cpp b/src/PySendCreate.cpp deleted file mode 100644 index c122150..0000000 --- a/src/PySendCreate.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "PySendCreate.hpp" - -PySendCreate::PySendCreate(const std::string &ndi_name_, - const std::string &groupds_, bool clock_video_, - bool clock_audio_) - : _ndi_name(ndi_name_), _groups(groupds_) { - p_ndi_name = _ndi_name.c_str(); - p_groups = _groups.c_str(); - clock_video = clock_video_; - clock_audio = clock_audio_; -} - -PySendCreate::~PySendCreate() {} - -const std::string &PySendCreate::getNdiName() const { return _ndi_name; } - -void PySendCreate::setNdiName(const std::string &name) { - _ndi_name = name; - p_ndi_name = _ndi_name.c_str(); -} - -const std::string &PySendCreate::getGroups() const { return _groups; } - -void PySendCreate::setGroups(const std::string &groups) { - _groups = groups; - p_groups = _groups.c_str(); -} diff --git a/src/PySendCreate.hpp b/src/PySendCreate.hpp deleted file mode 100644 index 873b4ae..0000000 --- a/src/PySendCreate.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#include - -#include - -class PySendCreate : public NDIlib_send_create_t { -public: - PySendCreate(const std::string &ndi_name_, const std::string &groups_, - bool clock_video_, bool clock_audio_); - virtual ~PySendCreate(); - - const std::string &getNdiName() const; - void setNdiName(const std::string &name); - - const std::string &getGroups() const; - void setGroups(const std::string &groups); - -private: - std::string _ndi_name; - std::string _groups; -}; diff --git a/src/main.cpp b/src/main.cpp index 1152735..7499277 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,6 @@ #include "PyAudioFrame.hpp" #include "PyMetadataFrame.hpp" -#include "PySendCreate.hpp" #include "PySource.hpp" #include "PyVideoFrame.hpp" @@ -437,16 +436,34 @@ PYBIND11_MODULE(NDIlib, m) { py::arg("instance"), py::arg("times")); // Processing.NDI.Send - py::class_(m, "SendCreate") - .def(py::init(), - py::arg("ndi_name") = nullptr, py::arg("groups") = nullptr, + py::class_(m, "SendCreate") + .def(py::init(), + py::arg("p_ndi_name") = nullptr, py::arg("p_groups") = nullptr, py::arg("clock_video") = true, py::arg("clock_audio") = true) - .def_property("ndi_name", &PySendCreate::getNdiName, - &PySendCreate::setNdiName) - .def_property("groups", &PySendCreate::getGroups, - &PySendCreate::setGroups) - .def_readwrite("clock_video", &PySendCreate::clock_video) - .def_readwrite("clock_audio", &PySendCreate::clock_audio); + .def_property( + "ndi_name", + [](const NDIlib_send_create_t &self) { + auto ustr = PyUnicode_DecodeLocale(self.p_ndi_name, nullptr); + return py::reinterpret_steal(ustr); + }, + [](NDIlib_send_create_t &self, const char *name) { + static std::unordered_map strs; + strs[&self] = py::str(name); + self.p_ndi_name = strs[&self].c_str(); + }) + .def_property( + "groups", + [](const NDIlib_send_create_t &self) { + auto ustr = PyUnicode_DecodeLocale(self.p_groups, nullptr); + return py::reinterpret_steal(ustr); + }, + [](NDIlib_send_create_t &self, const std::string &groups) { + static std::unordered_map strs; + strs[&self] = py::str(groups); + self.p_groups = strs[&self].c_str(); + }) + .def_readwrite("clock_video", &NDIlib_send_create_t::clock_video) + .def_readwrite("clock_audio", &NDIlib_send_create_t::clock_audio); m.def("send_create", &NDIlib_send_create, py::arg("create_settings") = nullptr);