From b0e2f8f97b00a8a25105c038389e22864c990f41 Mon Sep 17 00:00:00 2001 From: Naoto Kondo Date: Fri, 24 Apr 2020 10:55:17 +0900 Subject: [PATCH] Add Source class --- src/PySource.cpp | 24 ++++++++++++++++++++++++ src/PySource.hpp | 18 ++++++++++++++++++ src/main.cpp | 11 ++++++----- 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 src/PySource.cpp create mode 100644 src/PySource.hpp diff --git a/src/PySource.cpp b/src/PySource.cpp new file mode 100644 index 0000000..039d3d9 --- /dev/null +++ b/src/PySource.cpp @@ -0,0 +1,24 @@ +#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 new file mode 100644 index 0000000..7caf522 --- /dev/null +++ b/src/PySource.hpp @@ -0,0 +1,18 @@ +#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 f2e5b08..684d9a3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ #include -#include +#include "PySource.hpp" namespace py = pybind11; @@ -93,11 +93,12 @@ PYBIND11_MODULE(NDIlib, m) { m.attr("RECV_TIMESTAMP_UNDEFINED") = py::int_(INT64_MAX); - py::class_(m, "Source") - .def(py::init(), + py::class_(m, "Source") + .def(py::init(), py::arg("ndi_name") = nullptr, py::arg("url_address") = nullptr) - .def_readwrite("ndi_name", &NDIlib_source_t::p_ndi_name) - .def_readwrite("url_address", &NDIlib_source_t::p_url_address); + .def_property("ndi_name", &PySource::getNdiName, &PySource::setNdiName) + .def_property("url_address", &PySource::getUrlAddress, + &PySource::setUrlAddress); py::class_(m, "VideoFrameV2") .def(py::init