diff options
author | Josh Blum | 2012-09-21 20:42:24 -0700 |
---|---|---|
committer | Josh Blum | 2012-09-21 20:42:24 -0700 |
commit | 8583c68cf63c8fbaaa01b9ee43b2b96c95c6e34e (patch) | |
tree | e85721e7263cf0cbfd2ab4b969cff097ab92ff6d /lib | |
parent | 70d6105c6a5356e2b5dadeae45751239c080cace (diff) | |
download | sandhi-8583c68cf63c8fbaaa01b9ee43b2b96c95c6e34e.tar.gz sandhi-8583c68cf63c8fbaaa01b9ee43b2b96c95c6e34e.tar.bz2 sandhi-8583c68cf63c8fbaaa01b9ee43b2b96c95c6e34e.zip |
fix trim tags ordering vs production of samples
moved tags stuff into header thats called
within the existing work input for loops
Diffstat (limited to 'lib')
-rw-r--r-- | lib/block_task.cpp | 65 | ||||
-rw-r--r-- | lib/element_impl.hpp | 2 | ||||
-rw-r--r-- | lib/tag_handlers.hpp | 85 |
3 files changed, 92 insertions, 60 deletions
diff --git a/lib/block_task.cpp b/lib/block_task.cpp index 9cb7e22..96c6b7a 100644 --- a/lib/block_task.cpp +++ b/lib/block_task.cpp @@ -15,9 +15,8 @@ // along with io_sig program. If not, see <http://www.gnu.org/licenses/>. #include "element_impl.hpp" +#include "tag_handlers.hpp" #include <gras_impl/messages.hpp> -#include <boost/foreach.hpp> -#include <algorithm> #define REALLY_BIG size_t(1 << 30) @@ -95,17 +94,6 @@ void ElementImpl::handle_task(const tsbe::TaskInterface &task_iface) this->work_io_ptr_mask = 0; //reset //------------------------------------------------------------------ - //-- sort the input tags before working - //------------------------------------------------------------------ - for (size_t i = 0; i < num_inputs; i++) - { - if (not this->input_tags_changed[i]) continue; - std::vector<Tag> &tags_i = this->input_tags[i]; - std::sort(tags_i.begin(), tags_i.end(), Tag::offset_compare); - this->input_tags_changed[i] = false; - } - - //------------------------------------------------------------------ //-- initialize input buffers before work //------------------------------------------------------------------ size_t num_input_items = REALLY_BIG; //so big that it must std::min @@ -113,6 +101,8 @@ void ElementImpl::handle_task(const tsbe::TaskInterface &task_iface) size_t output_inline_index = 0; for (size_t i = 0; i < num_inputs; i++) { + this->sort_tags(i); + inputs_done = inputs_done or this->input_tokens[i].unique(); ASSERT(this->input_queues.ready(i)); @@ -237,6 +227,8 @@ void ElementImpl::handle_task(const tsbe::TaskInterface &task_iface) this->items_consumed[i] += items; const size_t bytes = items*this->input_items_sizes[i]; this->input_queues.consume(i, bytes); + + this->trim_tags(task_iface, i); } //------------------------------------------------------------------ @@ -262,53 +254,6 @@ void ElementImpl::handle_task(const tsbe::TaskInterface &task_iface) } //------------------------------------------------------------------ - //-- trim the input tags that are past the consumption zone - //-- and post trimmed tags to the downstream based on policy - //-- //FIXME this propagation is AFTER the output buffers flushed... fix this - //------------------------------------------------------------------ - for (size_t i = 0; i < num_inputs; i++) - { - std::vector<Tag> &tags_i = this->input_tags[i]; - const size_t items_consumed_i = this->items_consumed[i]; - size_t last = 0; - while (last < tags_i.size() and tags_i[last].offset < items_consumed_i) - { - last++; - } - - //follow the tag propagation policy before erasure - switch (this->tag_prop_policy) - { - case Block::TPP_DONT: break; //well that was ez - case Block::TPP_ALL_TO_ALL: - for (size_t out_i = 0; out_i < num_outputs; out_i++) - { - for (size_t tag_i = 0; tag_i < last; tag_i++) - { - Tag t = tags_i[tag_i]; - t.offset = myullround(t.offset * this->relative_rate); - task_iface.post_downstream(out_i, t); - } - } - break; - case Block::TPP_ONE_TO_ONE: - if (i < num_outputs) - { - for (size_t tag_i = 0; tag_i < last; tag_i++) - { - Tag t = tags_i[tag_i]; - t.offset = myullround(t.offset * this->relative_rate); - task_iface.post_downstream(i, t); - } - } - break; - }; - - //now its safe to perform the erasure - if (last != 0) tags_i.erase(tags_i.begin(), tags_i.begin()+last); - } - - //------------------------------------------------------------------ //-- Message self based on post-work conditions //------------------------------------------------------------------ this->conclusion(task_iface, inputs_done); diff --git a/lib/element_impl.hpp b/lib/element_impl.hpp index d791cb7..510bc72 100644 --- a/lib/element_impl.hpp +++ b/lib/element_impl.hpp @@ -134,6 +134,8 @@ struct ElementImpl void conclusion(const tsbe::TaskInterface &task_iface, const bool); void buffer_returner(const size_t index, SBuffer &buffer); void input_update(const tsbe::TaskInterface &task_iface); + void sort_tags(const size_t index); + void trim_tags(const tsbe::TaskInterface &, const size_t index); //work helpers int work_ret; diff --git a/lib/tag_handlers.hpp b/lib/tag_handlers.hpp new file mode 100644 index 0000000..b49be96 --- /dev/null +++ b/lib/tag_handlers.hpp @@ -0,0 +1,85 @@ +// +// Copyright 2012 Josh Blum +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with io_sig program. If not, see <http://www.gnu.org/licenses/>. + +#ifndef INCLUDED_LIBGRAS_TAG_HANDLERS_HPP +#define INCLUDED_LIBGRAS_TAG_HANDLERS_HPP + +#include "element_impl.hpp" +#include <algorithm> + +namespace gnuradio +{ + +GRAS_FORCE_INLINE void ElementImpl::sort_tags(const size_t i) +{ + if (not this->input_tags_changed[i]) return; + std::vector<Tag> &tags_i = this->input_tags[i]; + std::sort(tags_i.begin(), tags_i.end(), Tag::offset_compare); + this->input_tags_changed[i] = false; +} + +GRAS_FORCE_INLINE void ElementImpl::trim_tags(const tsbe::TaskInterface &task_iface, const size_t i) +{ + const size_t num_outputs = task_iface.get_num_outputs(); + + //------------------------------------------------------------------ + //-- trim the input tags that are past the consumption zone + //-- and post trimmed tags to the downstream based on policy + //------------------------------------------------------------------ + + std::vector<Tag> &tags_i = this->input_tags[i]; + const size_t items_consumed_i = this->items_consumed[i]; + size_t last = 0; + while (last < tags_i.size() and tags_i[last].offset < items_consumed_i) + { + last++; + } + + //follow the tag propagation policy before erasure + switch (this->tag_prop_policy) + { + case Block::TPP_DONT: break; //well that was ez + case Block::TPP_ALL_TO_ALL: + for (size_t out_i = 0; out_i < num_outputs; out_i++) + { + for (size_t tag_i = 0; tag_i < last; tag_i++) + { + Tag t = tags_i[tag_i]; + t.offset = myullround(t.offset * this->relative_rate); + task_iface.post_downstream(out_i, t); + } + } + break; + case Block::TPP_ONE_TO_ONE: + if (i < num_outputs) + { + for (size_t tag_i = 0; tag_i < last; tag_i++) + { + Tag t = tags_i[tag_i]; + t.offset = myullround(t.offset * this->relative_rate); + task_iface.post_downstream(i, t); + } + } + break; + }; + + //now its safe to perform the erasure + if (last != 0) tags_i.erase(tags_i.begin(), tags_i.begin()+last); +} + +} //namespace gnuradio + +#endif /*INCLUDED_LIBGRAS_TAG_HANDLERS_HPP*/ |