From 19f1be2099130e9b150f316c1bd47dd2ad09d748 Mon Sep 17 00:00:00 2001 From: Naoto Kondo Date: Fri, 24 Apr 2020 21:45:34 +0900 Subject: [PATCH] Do not use wrapper class for Source --- src/PySource.cpp | 24 ------------------------ src/PySource.hpp | 19 ------------------- src/main.cpp | 32 +++++++++++++++++++++++++------- 3 files changed, 25 insertions(+), 50 deletions(-) delete mode 100644 src/PySource.cpp delete mode 100644 src/PySource.hpp diff --git a/src/PySource.cpp b/src/PySource.cpp deleted file mode 100644 index 039d3d9..0000000 --- a/src/PySource.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "PySource.hpp" - -PySource::PySource(const std::string &ndi_name_, - const std::string &url_address_) - : _ndi_name(ndi_name_), _url_address(url_address_) { - p_ndi_name = _ndi_name.c_str(); - p_url_address = _url_address.c_str(); -} - -PySource::~PySource() {} - -const std::string &PySource::getNdiName() const { return _ndi_name; } - -void PySource::setNdiName(const std::string &name) { - _ndi_name = name; - p_ndi_name = _ndi_name.c_str(); -} - -const std::string &PySource::getUrlAddress() const { return _url_address; } - -void PySource::setUrlAddress(const std::string &address) { - _url_address = address; - p_url_address = _url_address.c_str(); -} diff --git a/src/PySource.hpp b/src/PySource.hpp deleted file mode 100644 index 7a1cfbd..0000000 --- a/src/PySource.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#include - -#include - -class PySource : public NDIlib_source_t { -public: - PySource(const std::string &ndi_name_, const std::string &url_address_); - virtual ~PySource(); - - const std::string &getNdiName() const; - void setNdiName(const std::string &name); - - const std::string &getUrlAddress() const; - void setUrlAddress(const std::string &address); - -private: - std::string _ndi_name; - std::string _url_address; -}; diff --git a/src/main.cpp b/src/main.cpp index 7499277..691ec1b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,6 @@ #include "PyAudioFrame.hpp" #include "PyMetadataFrame.hpp" -#include "PySource.hpp" #include "PyVideoFrame.hpp" namespace py = pybind11; @@ -97,12 +96,31 @@ PYBIND11_MODULE(NDIlib, m) { m.attr("RECV_TIMESTAMP_UNDEFINED") = py::int_(INT64_MAX); - py::class_(m, "Source") - .def(py::init(), - py::arg("ndi_name") = nullptr, py::arg("url_address") = nullptr) - .def_property("ndi_name", &PySource::getNdiName, &PySource::setNdiName) - .def_property("url_address", &PySource::getUrlAddress, - &PySource::setUrlAddress); + py::class_(m, "Source") + .def(py::init(), + py::arg("p_ndi_name") = nullptr, py::arg("p_url_address") = nullptr) + .def_property( + "ndi_name", + [](const NDIlib_source_t &self) { + auto ustr = PyUnicode_DecodeLocale(self.p_ndi_name, nullptr); + return py::reinterpret_steal(ustr); + }, + [](NDIlib_source_t &self, const std::string &name) { + static std::unordered_map strs; + strs[&self] = py::str(name); + self.p_ndi_name = strs[&self].c_str(); + }) + .def_property( + "url_address", + [](const NDIlib_source_t &self) { + auto ustr = PyUnicode_DecodeLocale(self.p_url_address, nullptr); + return py::reinterpret_steal(ustr); + }, + [](NDIlib_source_t &self, const std::string &address) { + static std::unordered_map strs; + strs[&self] = py::str(address); + self.p_url_address = strs[&self].c_str(); + }); py::class_(m, "VideoFrameV2") .def(py::init