aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/stream_python.hpp
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2019-02-04 16:00:16 +0100
committerMartin Braun <martin.braun@ettus.com>2019-02-22 16:56:52 -0800
commit692ddc71b17196487dcad982836e074cab9a0f25 (patch)
treecf76abf577dde6128e03561c52d9c31dca302026 /host/lib/stream_python.hpp
parent51bbf548c9b442d0b53b6c8de5f89403de274424 (diff)
downloaduhd-692ddc71b17196487dcad982836e074cab9a0f25.tar.gz
uhd-692ddc71b17196487dcad982836e074cab9a0f25.tar.bz2
uhd-692ddc71b17196487dcad982836e074cab9a0f25.zip
python: Replace Boost.Python with PyBind11
This does not change the Python API itself, but it is still a significant change. Most importantly, it removes the dependency on Boost.Python.
Diffstat (limited to 'host/lib/stream_python.hpp')
-rw-r--r--host/lib/stream_python.hpp73
1 files changed, 26 insertions, 47 deletions
diff --git a/host/lib/stream_python.hpp b/host/lib/stream_python.hpp
index 0760edf1b..1cb922b52 100644
--- a/host/lib/stream_python.hpp
+++ b/host/lib/stream_python.hpp
@@ -1,5 +1,6 @@
//
// Copyright 2017-2018 Ettus Research, a National Instruments Company
+// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
@@ -7,24 +8,15 @@
#ifndef INCLUDED_UHD_STREAM_PYTHON_HPP
#define INCLUDED_UHD_STREAM_PYTHON_HPP
-#include "utils/gil_release_python.hpp"
#include <uhd/stream.hpp>
#include <uhd/types/metadata.hpp>
-
#include <boost/format.hpp>
static size_t wrap_recv(uhd::rx_streamer *rx_stream,
- bp::object &np_array,
- bp::object &metadata,
+ py::object &np_array,
+ uhd::rx_metadata_t &metadata,
const double timeout = 0.1)
{
- // Extract the metadata
- bp::extract<uhd::rx_metadata_t&> get_metadata(metadata);
- if (not get_metadata.check())
- {
- return 0;
- }
-
// Get a numpy array object from given python object
// No sanity checking possible!
PyObject* array_obj = PyArray_FROM_OF(np_array.ptr(), NPY_ARRAY_CARRAY);
@@ -70,12 +62,12 @@ static size_t wrap_recv(uhd::rx_streamer *rx_stream,
// Release the GIL only for the recv() call
const size_t result = [&]() {
- scoped_gil_release gil_release;
+ py::gil_scoped_release release;
// Call the real recv()
return rx_stream->recv(
channel_storage,
nsamps_per_buff,
- get_metadata(),
+ metadata,
timeout
);
}();
@@ -84,21 +76,12 @@ static size_t wrap_recv(uhd::rx_streamer *rx_stream,
Py_DECREF(array_obj);
return result;
}
-BOOST_PYTHON_FUNCTION_OVERLOADS(overload_wrap_recv, wrap_recv, 3, 4);
static size_t wrap_send(uhd::tx_streamer *tx_stream,
- bp::object &np_array,
- bp::object &metadata,
+ py::object &np_array,
+ uhd::tx_metadata_t& metadata,
const double timeout = 0.1)
{
- // Extract the metadata
- bp::extract<uhd::tx_metadata_t&> get_metadata(metadata);
- // TODO: throw an error here?
- if (not get_metadata.check())
- {
- return 0;
- }
-
// Get a numpy array object from given python object
// No sanity checking possible!
// Note: this increases the ref count, which we'll need to manually decrease at the end
@@ -140,12 +123,12 @@ static size_t wrap_send(uhd::tx_streamer *tx_stream,
// Release the GIL only for the send() call
const size_t result = [&]() {
- scoped_gil_release gil_release;
+ py::gil_scoped_release release;
// Call the real send()
return tx_stream->send(
channel_storage,
nsamps_per_buff,
- get_metadata(),
+ metadata,
timeout
);
}();
@@ -154,28 +137,25 @@ static size_t wrap_send(uhd::tx_streamer *tx_stream,
Py_DECREF(array_obj);
return result;
}
-BOOST_PYTHON_FUNCTION_OVERLOADS(overload_wrap_send, wrap_send, 3, 4);
static bool wrap_recv_async_msg(uhd::tx_streamer *tx_stream,
uhd::async_metadata_t &async_metadata,
double timeout = 0.1)
{
// Release the GIL
- scoped_gil_release gil_release;
-
+ py::gil_scoped_release release;
return tx_stream->recv_async_msg(async_metadata, timeout);
}
-BOOST_PYTHON_FUNCTION_OVERLOADS(overload_wrap_recv_async_msg, wrap_recv_async_msg, 2, 3);
-void export_stream()
+void export_stream(py::module& m)
{
using stream_args_t = uhd::stream_args_t;
using rx_streamer = uhd::rx_streamer;
using tx_streamer = uhd::tx_streamer;
- bp::class_<stream_args_t>
- ("stream_args", bp::init<const std::string&, const std::string&>())
-
+ py::class_<stream_args_t>
+ (m, "stream_args")
+ .def(py::init<const std::string&, const std::string&>())
// Properties
.def_readwrite("cpu_format", &stream_args_t::cpu_format)
.def_readwrite("otw_format", &stream_args_t::otw_format)
@@ -183,29 +163,28 @@ void export_stream()
.def_readwrite("channels" , &stream_args_t::channels )
;
- bp::class_<
- rx_streamer,
- boost::shared_ptr<rx_streamer>,
- uhd::noncopyable>("rx_streamer", "See: uhd::rx_streamer", bp::no_init)
-
+ py::class_<rx_streamer, rx_streamer::sptr>(m, "rx_streamer", "See: uhd::rx_streamer")
// Methods
- .def("recv" , &wrap_recv, overload_wrap_recv() )
+ .def("recv" , &wrap_recv,
+ py::arg("np_array"),
+ py::arg("metadata"),
+ py::arg("timeout") = 0.1)
.def("get_num_channels" , &uhd::rx_streamer::get_num_channels )
.def("get_max_num_samps", &uhd::rx_streamer::get_max_num_samps)
.def("issue_stream_cmd" , &uhd::rx_streamer::issue_stream_cmd )
;
- bp::class_<
- tx_streamer,
- boost::shared_ptr<tx_streamer>,
- uhd::noncopyable>("tx_streamer", "See: uhd::tx_streamer", bp::no_init)
-
+ py::class_<tx_streamer, tx_streamer::sptr>(m, "tx_streamer", "See: uhd::tx_streamer")
// Methods
- .def("send" , &wrap_send, overload_wrap_send())
+ .def("send" , &wrap_send,
+ py::arg("np_array"),
+ py::arg("metadata"),
+ py::arg("timeout") = 0.1)
.def("get_num_channels" , &tx_streamer::get_num_channels )
.def("get_max_num_samps", &tx_streamer::get_max_num_samps )
.def("recv_async_msg" , &wrap_recv_async_msg,
- overload_wrap_recv_async_msg() )
+ py::arg("async_metadata"),
+ py::arg("timeout") = 0.1)
;
}