aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiří Pinkava <j-pi@seznam.cz>2014-07-31 00:17:25 +0000
committerDimitri Stolnikov <horiz0n@gmx.net>2014-08-14 23:35:23 +0200
commit225faa2e6a969207461201e1221d8bec2a683749 (patch)
tree82b7c755403d39c5a018a56bb51d8fc93b864f8a
parent3afecd6adf664efaac66432edf7b42d1afdadbb6 (diff)
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.
-rw-r--r--lib/rtl/rtl_source_c.cc40
1 files 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<std::string> rtl_source_c::get_devices()