diff options
author | Josh Morman <mormjb@gmail.com> | 2020-06-01 13:41:44 -0400 |
---|---|---|
committer | Josh Morman <mormjb@gmail.com> | 2020-06-04 10:05:48 -0400 |
commit | 4866d618d9f37dafe9f4ea54ee5c33588db9e72e (patch) | |
tree | 7ad6605af735783149181f478b5b2754e8c538ae | |
parent | 2af07cba8038587bc74abb0d9328a9284351f51c (diff) |
video-sdl: pybind11 bindings
8 files changed, 218 insertions, 3 deletions
diff --git a/gr-video-sdl/python/video_sdl/CMakeLists.txt b/gr-video-sdl/python/video_sdl/CMakeLists.txt index 9b6ee91b04..b1d9f6453f 100644 --- a/gr-video-sdl/python/video_sdl/CMakeLists.txt +++ b/gr-video-sdl/python/video_sdl/CMakeLists.txt @@ -36,3 +36,5 @@ if(ENABLE_TESTING) GR_ADD_TEST(${py_qa_test_name} ${QA_PYTHON_EXECUTABLE} -B ${py_qa_test_file}) endforeach(py_qa_test_file) endif(ENABLE_TESTING) + +add_subdirectory(bindings) diff --git a/gr-video-sdl/python/video_sdl/__init__.py b/gr-video-sdl/python/video_sdl/__init__.py index 96b7dfd180..cdc3bfa349 100644 --- a/gr-video-sdl/python/video_sdl/__init__.py +++ b/gr-video-sdl/python/video_sdl/__init__.py @@ -15,8 +15,8 @@ from __future__ import unicode_literals import os try: - from .video_sdl_swig import * + from .video_sdl_python import * except ImportError: dirname, filename = os.path.split(os.path.abspath(__file__)) - __path__.append(os.path.join(dirname, "..", "..", "swig")) - from .video_sdl_swig import * + __path__.append(os.path.join(dirname, "bindings")) + from .video_sdl_python import * diff --git a/gr-video-sdl/python/video_sdl/bindings/CMakeLists.txt b/gr-video-sdl/python/video_sdl/bindings/CMakeLists.txt new file mode 100644 index 0000000000..e381032930 --- /dev/null +++ b/gr-video-sdl/python/video_sdl/bindings/CMakeLists.txt @@ -0,0 +1,17 @@ +include(GrPybind) + +######################################################################## +# Python Bindings +######################################################################## + +list(APPEND video_sdl_python_files + sink_s_python.cc + sink_uc_python.cc + python_bindings.cc) + +GR_PYBIND_MAKE_CHECK_HASH(video_sdl + ../../.. + gr::video_sdl + "${video_sdl_python_files}") + +install(TARGETS video_sdl_python DESTINATION ${GR_PYTHON_DIR}/gnuradio/video_sdl COMPONENT pythonapi) diff --git a/gr-video-sdl/python/video_sdl/bindings/docstrings/sink_s_pydoc_template.h b/gr-video-sdl/python/video_sdl/bindings/docstrings/sink_s_pydoc_template.h new file mode 100644 index 0000000000..388d81fe7d --- /dev/null +++ b/gr-video-sdl/python/video_sdl/bindings/docstrings/sink_s_pydoc_template.h @@ -0,0 +1,24 @@ +/* + * Copyright 2020 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ +#include "pydoc_macros.h" +#define D(...) DOC(gr, video_sdl, __VA_ARGS__) +/* + This file contains placeholders for docstrings for the Python bindings. + Do not edit! These were automatically extracted during the binding process + and will be overwritten during the build process + */ + + +static const char* __doc_gr_video_sdl_sink_s = R"doc()doc"; + + +static const char* __doc_gr_video_sdl_sink_s_sink_s = R"doc()doc"; + + +static const char* __doc_gr_video_sdl_sink_s_make = R"doc()doc"; diff --git a/gr-video-sdl/python/video_sdl/bindings/docstrings/sink_uc_pydoc_template.h b/gr-video-sdl/python/video_sdl/bindings/docstrings/sink_uc_pydoc_template.h new file mode 100644 index 0000000000..977d75ed45 --- /dev/null +++ b/gr-video-sdl/python/video_sdl/bindings/docstrings/sink_uc_pydoc_template.h @@ -0,0 +1,24 @@ +/* + * Copyright 2020 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ +#include "pydoc_macros.h" +#define D(...) DOC(gr, video_sdl, __VA_ARGS__) +/* + This file contains placeholders for docstrings for the Python bindings. + Do not edit! These were automatically extracted during the binding process + and will be overwritten during the build process + */ + + +static const char* __doc_gr_video_sdl_sink_uc = R"doc()doc"; + + +static const char* __doc_gr_video_sdl_sink_uc_sink_uc = R"doc()doc"; + + +static const char* __doc_gr_video_sdl_sink_uc_make = R"doc()doc"; diff --git a/gr-video-sdl/python/video_sdl/bindings/python_bindings.cc b/gr-video-sdl/python/video_sdl/bindings/python_bindings.cc new file mode 100644 index 0000000000..3e74a6c56e --- /dev/null +++ b/gr-video-sdl/python/video_sdl/bindings/python_bindings.cc @@ -0,0 +1,42 @@ + +/* + * Copyright 2020 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include <pybind11/pybind11.h> + +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION +#include <numpy/arrayobject.h> + +namespace py = pybind11; + +void bind_sink_s(py::module&); +void bind_sink_uc(py::module&); + +// We need this hack because import_array() returns NULL +// for newer Python versions. +// This function is also necessary because it ensures access to the C API +// and removes a warning. +void* init_numpy() +{ + import_array(); + return NULL; +} + +PYBIND11_MODULE(video_sdl_python, m) +{ + // Initialize the numpy C API + // (otherwise we will see segmentation faults) + init_numpy(); + + // Allow access to base block methods + py::module::import("gnuradio.gr"); + + bind_sink_s(m); + bind_sink_uc(m); +} diff --git a/gr-video-sdl/python/video_sdl/bindings/sink_s_python.cc b/gr-video-sdl/python/video_sdl/bindings/sink_s_python.cc new file mode 100644 index 0000000000..172525e8dc --- /dev/null +++ b/gr-video-sdl/python/video_sdl/bindings/sink_s_python.cc @@ -0,0 +1,53 @@ +/* + * Copyright 2020 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +/***********************************************************************************/ +/* This file is automatically generated using bindtool and can be manually edited */ +/* The following lines can be configured to regenerate this file during cmake */ +/* If manual edits are made, the following tags should be modified accordingly. */ +/* BINDTOOL_GEN_AUTOMATIC(0) */ +/* BINDTOOL_USE_PYGCCXML(0) */ +/* BINDTOOL_HEADER_FILE(sink_s.h) */ +/* BINDTOOL_HEADER_FILE_HASH(15f36b3f61a071fa6a28398c6af1e4f4) */ +/***********************************************************************************/ + +#include <pybind11/complex.h> +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> + +namespace py = pybind11; + +#include <gnuradio/video_sdl/sink_s.h> +// pydoc.h is automatically generated in the build directory +#include <sink_s_pydoc.h> + +void bind_sink_s(py::module& m) +{ + + using sink_s = ::gr::video_sdl::sink_s; + + + py::class_<sink_s, + gr::sync_block, + gr::block, + gr::basic_block, + std::shared_ptr<sink_s>>(m, "sink_s", D(sink_s)) + + .def(py::init(&sink_s::make), + py::arg("framerate"), + py::arg("width"), + py::arg("height"), + py::arg("format"), + py::arg("dst_width"), + py::arg("dst_height"), + D(sink_s, make)) + + + ; +} diff --git a/gr-video-sdl/python/video_sdl/bindings/sink_uc_python.cc b/gr-video-sdl/python/video_sdl/bindings/sink_uc_python.cc new file mode 100644 index 0000000000..4f86aee0e1 --- /dev/null +++ b/gr-video-sdl/python/video_sdl/bindings/sink_uc_python.cc @@ -0,0 +1,53 @@ +/* + * Copyright 2020 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +/***********************************************************************************/ +/* This file is automatically generated using bindtool and can be manually edited */ +/* The following lines can be configured to regenerate this file during cmake */ +/* If manual edits are made, the following tags should be modified accordingly. */ +/* BINDTOOL_GEN_AUTOMATIC(0) */ +/* BINDTOOL_USE_PYGCCXML(0) */ +/* BINDTOOL_HEADER_FILE(sink_uc.h) */ +/* BINDTOOL_HEADER_FILE_HASH(d7fd4b5abcf667140169527a0b454a6f) */ +/***********************************************************************************/ + +#include <pybind11/complex.h> +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> + +namespace py = pybind11; + +#include <gnuradio/video_sdl/sink_uc.h> +// pydoc.h is automatically generated in the build directory +#include <sink_uc_pydoc.h> + +void bind_sink_uc(py::module& m) +{ + + using sink_uc = ::gr::video_sdl::sink_uc; + + + py::class_<sink_uc, + gr::sync_block, + gr::block, + gr::basic_block, + std::shared_ptr<sink_uc>>(m, "sink_uc", D(sink_uc)) + + .def(py::init(&sink_uc::make), + py::arg("framerate"), + py::arg("width"), + py::arg("height"), + py::arg("format"), + py::arg("dst_width"), + py::arg("dst_height"), + D(sink_uc, make)) + + + ; +} |