diff options
author | Paul Wicks <pwicks86@gmail.com> | 2018-05-29 14:12:59 -0700 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2018-07-15 15:59:57 +0200 |
commit | 5c63d71d44f299cda7ca5f8a3617a1d5b67c7544 (patch) | |
tree | eb86b294874e0ea2d1a8263c76d0f4178dbd632a /gr-blocks | |
parent | dea45c14abb5c4a76a507376198f954d01a74f9c (diff) |
Implement fix for gnuradio bug https://github.com/gnuradio/gnuradio/issues/959
Diffstat (limited to 'gr-blocks')
-rw-r--r-- | gr-blocks/lib/skiphead_impl.cc | 14 | ||||
-rw-r--r-- | gr-blocks/lib/skiphead_impl.h | 1 | ||||
-rwxr-xr-x | gr-blocks/python/blocks/qa_skiphead.py | 26 |
3 files changed, 40 insertions, 1 deletions
diff --git a/gr-blocks/lib/skiphead_impl.cc b/gr-blocks/lib/skiphead_impl.cc index da9cb11280..0a1685b732 100644 --- a/gr-blocks/lib/skiphead_impl.cc +++ b/gr-blocks/lib/skiphead_impl.cc @@ -44,6 +44,12 @@ namespace gr { io_signature::make(1, 1, itemsize)), d_nitems_to_skip(nitems_to_skip), d_nitems(0) { + // Reserve space for a few tags to avoid constant re-allocation + // in the call to get_tags_in_window + d_tags.reserve(8); + + // We'll handle propagating tags our selves to handle shifting offsets of tags + set_tag_propagation_policy(TPP_DONT); } skiphead_impl::~skiphead_impl() @@ -71,7 +77,13 @@ namespace gr { ii += n_to_skip; } - else { // nothing left to skip. copy away + else { // nothing left to skip. copy away + // Grab all tags in the window and shift their offsets appropriately + get_tags_in_window(d_tags, 0, ii, ninput_items); + for(std::vector<tag_t>::iterator it = d_tags.begin(); it != d_tags.end(); it++) { + (*it).offset -= d_nitems_to_skip; + add_item_tag(0, *it); + } int n_to_copy = ninput_items - ii; if(n_to_copy > 0) { size_t itemsize = output_signature()->sizeof_stream_item(0); diff --git a/gr-blocks/lib/skiphead_impl.h b/gr-blocks/lib/skiphead_impl.h index db4df50adb..738fa86a61 100644 --- a/gr-blocks/lib/skiphead_impl.h +++ b/gr-blocks/lib/skiphead_impl.h @@ -33,6 +33,7 @@ namespace gr { private: uint64_t d_nitems_to_skip; uint64_t d_nitems; // total items seen + std::vector<tag_t> d_tags; public: skiphead_impl(size_t itemsize, uint64_t nitems_to_skip); diff --git a/gr-blocks/python/blocks/qa_skiphead.py b/gr-blocks/python/blocks/qa_skiphead.py index a9b6df40cf..098e7b1e94 100755 --- a/gr-blocks/python/blocks/qa_skiphead.py +++ b/gr-blocks/python/blocks/qa_skiphead.py @@ -21,6 +21,19 @@ # from gnuradio import gr, gr_unittest, blocks +import pmt +import numpy + + +def make_tag(key, value, offset, srcid=None): + tag = gr.tag_t() + tag.key = pmt.string_to_symbol(key) + tag.value = pmt.to_pmt(value) + tag.offset = offset + if srcid is not None: + tag.srcid = pmt.to_pmt(srcid) + return tag + class test_skiphead(gr_unittest.TestCase): @@ -97,6 +110,19 @@ class test_skiphead(gr_unittest.TestCase): dst_data = dst1.data() self.assertEqual(expected_result, dst_data) + def test_skip_tags(self): + skip_cnt = 25 + expected_result = tuple(self.src_data[skip_cnt:]) + + src_tags = tuple([make_tag('foo', 'bar', 50, 'src')]) + src1 = blocks.vector_source_i(self.src_data, tags=src_tags) + op = blocks.skiphead(gr.sizeof_int, skip_cnt) + dst1 = blocks.vector_sink_i() + self.tb.connect(src1, op, dst1) + self.tb.run() + dst_data = dst1.data() + self.assertEqual(expected_result, dst_data) + self.assertEqual(dst1.tags()[0].offset, 25, "Tag offset is incorrect") if __name__ == '__main__': gr_unittest.run(test_skiphead, "test_skiphead.xml") |