diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2019-04-30 18:51:00 +0200 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2019-05-03 13:50:50 +0200 |
commit | ef192d303c131edf5844e57ea2aae1e40d8ecf9c (patch) | |
tree | c5546046225c07bbcb7dcb843ef995954d6ba69f | |
parent | ac927b2690034fbf711aa2739cf9acdde0b817b6 (diff) |
uhd: Avoid reallocation of buffers every read
Buffer size is based on num of chans and rxBuffer size is based on num
of chans and rx_spp, and both are available and set during open(), so no
need to waste time allocating and freeing them everytime we read from
the device.
Change-Id: I8c881c9c303c80f323825d85a924d74b76d2ce47
-rw-r--r-- | Transceiver52M/device/uhd/UHDDevice.cpp | 20 | ||||
-rw-r--r-- | Transceiver52M/device/uhd/UHDDevice.h | 5 |
2 files changed, 10 insertions, 15 deletions
diff --git a/Transceiver52M/device/uhd/UHDDevice.cpp b/Transceiver52M/device/uhd/UHDDevice.cpp index 34ffd57..6214666 100644 --- a/Transceiver52M/device/uhd/UHDDevice.cpp +++ b/Transceiver52M/device/uhd/UHDDevice.cpp @@ -516,6 +516,11 @@ int uhd_device::open(const std::string &args, int ref, bool swap_channels) for (size_t i = 0; i < rx_buffers.size(); i++) rx_buffers[i] = new smpl_buf(buf_len, rx_rate); + // Create vector buffer + pkt_bufs = std::vector<std::vector<short> >(chans, std::vector<short>(2 * rx_spp)); + for (size_t i = 0; i < pkt_bufs.size(); i++) + pkt_ptrs.push_back(&pkt_bufs[i].front()); + // Initialize and shadow gain values init_gains(); @@ -549,13 +554,6 @@ bool uhd_device::flush_recv(size_t num_pkts) size_t num_smpls; float timeout = UHD_RESTART_TIMEOUT; - std::vector<std::vector<short> > - pkt_bufs(chans, std::vector<short>(2 * rx_spp)); - - std::vector<short *> pkt_ptrs; - for (size_t i = 0; i < pkt_bufs.size(); i++) - pkt_ptrs.push_back(&pkt_bufs[i].front()); - ts_initial = 0; while (!ts_initial || (num_pkts-- > 0)) { num_smpls = rx_stream->recv(pkt_ptrs, rx_spp, md, @@ -720,14 +718,6 @@ int uhd_device::readSamples(std::vector<short *> &bufs, int len, bool *overrun, return 0; } - // Create vector buffer - std::vector<std::vector<short> > - pkt_bufs(chans, std::vector<short>(2 * rx_spp)); - - std::vector<short *> pkt_ptrs; - for (size_t i = 0; i < pkt_bufs.size(); i++) - pkt_ptrs.push_back(&pkt_bufs[i].front()); - // Receive samples from the usrp until we have enough while (rx_buffers[0]->avail_smpls(timestamp) < len) { thread_enable_cancel(false); diff --git a/Transceiver52M/device/uhd/UHDDevice.h b/Transceiver52M/device/uhd/UHDDevice.h index f5d0b33..05a5914 100644 --- a/Transceiver52M/device/uhd/UHDDevice.h +++ b/Transceiver52M/device/uhd/UHDDevice.h @@ -152,6 +152,11 @@ private: TIMESTAMP ts_initial, ts_offset; std::vector<smpl_buf *> rx_buffers; + /* Sample buffers used to receive samples from UHD: */ + std::vector<std::vector<short> > pkt_bufs; + /* Used to call UHD API: Buffer pointer of each elem in pkt_ptrs will + point to corresponding buffer of vector pkt_bufs. */ + std::vector<short *> pkt_ptrs; void init_gains(); void set_channels(bool swap); |