diff options
-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") |