diff options
author | Tom Rondeau | 2012-10-02 14:56:10 -0400 |
---|---|---|
committer | Tom Rondeau | 2012-10-03 12:26:18 -0400 |
commit | 2fdfad0411da70118269a3fb85d5c2c6ad80ead3 (patch) | |
tree | 3a8e2b81073af346b81914aa89de807b1c48a677 /gnuradio-core/src | |
parent | 1e528816fd70f3a61d7f00a370cb056f03ceb6a7 (diff) | |
download | gnuradio-2fdfad0411da70118269a3fb85d5c2c6ad80ead3.tar.gz gnuradio-2fdfad0411da70118269a3fb85d5c2c6ad80ead3.tar.bz2 gnuradio-2fdfad0411da70118269a3fb85d5c2c6ad80ead3.zip |
core: fixed set min/max buffer sizes to better handle blocks with infinite streams.
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_basic_block.h | 74 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 7 |
2 files changed, 65 insertions, 16 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 37a09cd41..b8e8148b2 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -63,6 +63,20 @@ private: msg_handler_t d_msg_handler; + /* + * Used to expand the vectors that hold the min/max buffer sizes. + * + * Specifically, when -1 is used, the vectors are just initialized + * with 1 value; this is used by the flat_flowgraph to expand when + * required to add a new value for new ports on these blocks. + */ + void expand_minmax_buffer(int port) { + if((size_t)port >= d_max_output_buffer.size()) + set_max_output_buffer(port, -1); + if((size_t)port >= d_min_output_buffer.size()) + set_min_output_buffer(port, -1); + } + protected: friend class gr_flowgraph; friend class gr_flat_flowgraph; // TODO: will be redundant @@ -108,29 +122,63 @@ public: gr_io_signature_sptr input_signature() const { return d_input_signature; } gr_io_signature_sptr output_signature() const { return d_output_signature; } gr_basic_block_sptr to_basic_block(); // Needed for Python type coercion + + /*! + * \brief Returns max buffer size on output port \p i. + */ long max_output_buffer(size_t i) { - if(d_max_output_buffer.size() <= i) + if(i >= d_max_output_buffer.size()) throw std::invalid_argument("gr_basic_block::max_output_buffer: port out of range."); return d_max_output_buffer[i]; } - void set_max_output_buffer(long max_output_buffer){ - for(int i=0; i<output_signature()->max_streams(); i++){ - set_max_output_buffer(max_output_buffer, i); - } + + /*! + * \brief Sets max buffer size on all output ports. + */ + void set_max_output_buffer(long max_output_buffer) { + for(int i=0; i<output_signature()->max_streams(); i++) { + set_max_output_buffer(i, max_output_buffer); + } } - void set_max_output_buffer(int port, long max_output_buffer){ d_max_output_buffer[port] = max_output_buffer; } + + /*! + * \brief Sets max buffer size on output port \p port. + */ + void set_max_output_buffer(int port, long max_output_buffer) { + if((size_t)port >= d_max_output_buffer.size()) + d_max_output_buffer.push_back(max_output_buffer); + else + d_max_output_buffer[port] = max_output_buffer; + } + + /*! + * \brief Returns min buffer size on output port \p i. + */ long min_output_buffer(size_t i) { - if(d_min_output_buffer.size() <= i) + if(i >= d_min_output_buffer.size()) throw std::invalid_argument("gr_basic_block::min_output_buffer: port out of range."); return d_min_output_buffer[i]; } - void set_min_output_buffer(long min_output_buffer){ - for(int i=0; i<output_signature()->max_streams(); i++){ - set_min_output_buffer(min_output_buffer, i); - } + + /*! + * \brief Sets min buffer size on all output ports. + */ + void set_min_output_buffer(long min_output_buffer) { + for(int i=0; i<output_signature()->max_streams(); i++) { + set_min_output_buffer(i, min_output_buffer); + } } - void set_min_output_buffer(int port, long min_output_buffer){ d_min_output_buffer[port] = min_output_buffer; } - + + /*! + * \brief Sets min buffer size on output port \p port. + */ + void set_min_output_buffer(int port, long min_output_buffer) { + if((size_t)port >= d_min_output_buffer.size()) + d_min_output_buffer.push_back(min_output_buffer); + else + d_min_output_buffer[port] = min_output_buffer; + } + /*! * \brief Confirm that ninputs and noutputs is an acceptable combination. * diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index 15f07e26b..f51e52ce3 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -84,6 +84,7 @@ gr_flat_flowgraph::allocate_block_detail(gr_basic_block_sptr block) std::cout << "Creating block detail for " << block << std::endl; for (int i = 0; i < noutputs; i++) { + block->expand_minmax_buffer(i); gr_buffer_sptr buffer = allocate_buffer(block, i); if (GR_FLAT_FLOWGRAPH_DEBUG) std::cout << "Allocated buffer for output " << block << ":" << i << std::endl; @@ -117,15 +118,15 @@ gr_flat_flowgraph::allocate_buffer(gr_basic_block_sptr block, int port) // ensure we have a buffer at least twice their decimation factor*output_multiple gr_basic_block_vector_t blocks = calc_downstream_blocks(block, port); - // limit buffer size if indicated - if(block->max_output_buffer(port) > 0){ + if(block->max_output_buffer(port) > 0) { // std::cout << "constraining output items to " << block->max_output_buffer(port) << "\n"; nitems = std::min((long)nitems, (long)block->max_output_buffer(port)); nitems -= nitems%grblock->output_multiple(); if( nitems < 1 ) throw std::runtime_error("problems allocating a buffer with the given max output buffer constraint!"); - } else if(block->min_output_buffer(port) > 0){ + } + else if(block->min_output_buffer(port) > 0) { nitems = std::max((long)nitems, (long)block->min_output_buffer(port)); nitems -= nitems%grblock->output_multiple(); if( nitems < 1 ) |