From 225faa2e6a969207461201e1221d8bec2a683749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pinkava?= Date: Thu, 31 Jul 2014 00:17:25 +0000 Subject: [PATCH] rtl: fix large output buffers handling When size of output buffer was larger than size of input buffer, uderflow occured because no check on number of avalilable data was done. This also improves buffer filling for large output buffers, fill output until anny input is available. --- lib/rtl/rtl_source_c.cc | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/lib/rtl/rtl_source_c.cc b/lib/rtl/rtl_source_c.cc index 3c29e42..ed307bf 100644 --- a/lib/rtl/rtl_source_c.cc +++ b/lib/rtl/rtl_source_c.cc @@ -347,37 +347,31 @@ int rtl_source_c::work( int noutput_items, if (!_running) return WORK_DONE; - unsigned short *buf = _buf[_buf_head] + _buf_offset; + while (noutput_items && _buf_used) { + const int nout = std::min(noutput_items, _samp_avail); + const unsigned short *buf = _buf[_buf_head] + _buf_offset; - if (noutput_items <= _samp_avail) { - for (int i = 0; i < noutput_items; ++i) + for (int i = 0; i < nout; ++i) *out++ = _lut[ *(buf + i) ]; - _buf_offset += noutput_items; - _samp_avail -= noutput_items; - } else { - for (int i = 0; i < _samp_avail; ++i) - *out++ = _lut[ *(buf + i) ]; + noutput_items -= nout; + _samp_avail -= nout; - { - boost::mutex::scoped_lock lock( _buf_mutex ); + if (!_samp_avail) { + { + boost::mutex::scoped_lock lock( _buf_mutex ); - _buf_head = (_buf_head + 1) % _buf_num; - _buf_used--; + _buf_head = (_buf_head + 1) % _buf_num; + _buf_used--; + } + _samp_avail = _buf_len / BYTES_PER_SAMPLE; + _buf_offset = 0; + } else { + _buf_offset += nout; } - - buf = _buf[_buf_head]; - - int remaining = noutput_items - _samp_avail; - - for (int i = 0; i < remaining; ++i) - *out++ = _lut[ *(buf + i) ]; - - _buf_offset = remaining; - _samp_avail = (_buf_len / BYTES_PER_SAMPLE) - remaining; } - return noutput_items; + return (out - ((gr_complex *)output_items[0])); } std::vector rtl_source_c::get_devices()