Skip to content

Commit b0203fd

Browse files
committed
Safer set_buffer_size_by_samplerate
1 parent 9391695 commit b0203fd

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Diff for: PlutoSDR_Streaming.cpp

+15-8
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bool SoapyPlutoSDR::IsValidRxStreamHandle(SoapySDR::Stream* handle) const
4949
}
5050

5151
//handle is an opaque pointer hiding either rx_stream or tx_streamer:
52-
//check that the handle matches one of them, onsistently with direction:
52+
//check that the handle matches one of them, consistently with direction:
5353
if (rx_stream) {
5454
//test if these handles really belong to us:
5555
if (reinterpret_cast<rx_streamer*>(handle) == rx_stream.get()) {
@@ -67,7 +67,7 @@ bool SoapyPlutoSDR::IsValidTxStreamHandle(SoapySDR::Stream* handle)
6767
}
6868

6969
//handle is an opaque pointer hiding either rx_stream or tx_streamer:
70-
//check that the handle matches one of them, onsistently with direction:
70+
//check that the handle matches one of them, consistently with direction:
7171
if (tx_stream) {
7272
//test if these handles really belong to us:
7373
if (reinterpret_cast<tx_streamer*>(handle) == tx_stream.get()) {
@@ -272,9 +272,9 @@ void rx_streamer::set_buffer_size_by_samplerate(const size_t samplerate) {
272272
SoapySDR_logf(SOAPY_SDR_INFO, "Auto setting Buffer Size: %lu", (unsigned long)buffer_size);
273273

274274
//Recompute MTU from buffer size change.
275-
//We set MTU size = Buffer Size.
276-
//in the future buffer size may be able to adjust of sample rate,
277-
//in this case MTU can be changed accordingly safely here.
275+
//We always set MTU size = Buffer Size.
276+
//On buffer size adjustment to sample rate,
277+
//MTU can be changed accordingly safely here.
278278
set_mtu_size(this->buffer_size);
279279
}
280280

@@ -520,11 +520,18 @@ int rx_streamer::stop(const int flags,
520520
void rx_streamer::set_buffer_size(const size_t _buffer_size){
521521

522522
if (!buf || this->buffer_size != _buffer_size) {
523-
if (buf) {
524-
iio_buffer_destroy(buf);
525-
}
523+
//cancel first
524+
if (buf) {
525+
iio_buffer_cancel(buf);
526+
}
527+
//then destroy
528+
if (buf) {
529+
iio_buffer_destroy(buf);
530+
}
526531

527532
items_in_buffer = 0;
533+
byte_offset = 0;
534+
528535
buf = iio_device_create_buffer(dev, _buffer_size, false);
529536
if (!buf) {
530537
SoapySDR_logf(SOAPY_SDR_ERROR, "Unable to create buffer!");

0 commit comments

Comments
 (0)