mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-trx.git
synced 2025-11-18 04:32:58 +00:00
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
This commit is contained in:
@@ -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++)
|
for (size_t i = 0; i < rx_buffers.size(); i++)
|
||||||
rx_buffers[i] = new smpl_buf(buf_len, rx_rate);
|
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
|
// Initialize and shadow gain values
|
||||||
init_gains();
|
init_gains();
|
||||||
|
|
||||||
@@ -549,13 +554,6 @@ bool uhd_device::flush_recv(size_t num_pkts)
|
|||||||
size_t num_smpls;
|
size_t num_smpls;
|
||||||
float timeout = UHD_RESTART_TIMEOUT;
|
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;
|
ts_initial = 0;
|
||||||
while (!ts_initial || (num_pkts-- > 0)) {
|
while (!ts_initial || (num_pkts-- > 0)) {
|
||||||
num_smpls = rx_stream->recv(pkt_ptrs, rx_spp, md,
|
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;
|
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
|
// Receive samples from the usrp until we have enough
|
||||||
while (rx_buffers[0]->avail_smpls(timestamp) < len) {
|
while (rx_buffers[0]->avail_smpls(timestamp) < len) {
|
||||||
thread_enable_cancel(false);
|
thread_enable_cancel(false);
|
||||||
|
|||||||
@@ -152,6 +152,11 @@ private:
|
|||||||
|
|
||||||
TIMESTAMP ts_initial, ts_offset;
|
TIMESTAMP ts_initial, ts_offset;
|
||||||
std::vector<smpl_buf *> rx_buffers;
|
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 init_gains();
|
||||||
void set_channels(bool swap);
|
void set_channels(bool swap);
|
||||||
|
|||||||
Reference in New Issue
Block a user