diff options
author | Tim O'Shea | 2012-09-27 14:41:55 -0400 |
---|---|---|
committer | Tom Rondeau | 2012-10-02 13:11:20 -0400 |
commit | 765d0686e6e0b46a7067cdf55ff195c425c709ed (patch) | |
tree | 69f91bae724c0bc35ef9b3e9c83d45379a99cefd /gnuradio-core/src/lib/runtime | |
parent | be0c7ca9854734b228067d3515b2d032362e966b (diff) | |
download | gnuradio-765d0686e6e0b46a7067cdf55ff195c425c709ed.tar.gz gnuradio-765d0686e6e0b46a7067cdf55ff195c425c709ed.tar.bz2 gnuradio-765d0686e6e0b46a7067cdf55ff195c425c709ed.zip |
providing additional control over GNU Radio buffer allocation size for latency effects etc
unlimited io_signatures of -1 should work correctly with this patch now
Diffstat (limited to 'gnuradio-core/src/lib/runtime')
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_basic_block.cc | 4 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_basic_block.h | 20 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_basic_block.i | 6 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc | 16 |
4 files changed, 44 insertions, 2 deletions
diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.cc b/gnuradio-core/src/lib/runtime/gr_basic_block.cc index d7263b92d..3d809aa8b 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.cc +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.cc @@ -45,7 +45,9 @@ gr_basic_block::gr_basic_block(const std::string &name, d_input_signature(input_signature), d_output_signature(output_signature), d_unique_id(s_next_id++), - d_color(WHITE) + d_color(WHITE), + d_max_output_buffer(std::max(output_signature->max_streams(),1), -1), + d_min_output_buffer(std::max(output_signature->max_streams(),1), -1) { s_ncurrently_allocated++; } diff --git a/gnuradio-core/src/lib/runtime/gr_basic_block.h b/gnuradio-core/src/lib/runtime/gr_basic_block.h index 4d03b878e..4d16014dd 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.h +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.h @@ -29,7 +29,9 @@ #include <boost/enable_shared_from_this.hpp> #include <boost/function.hpp> #include <gr_msg_accepter.h> +#include <gr_io_signature.h> #include <string> +#include <iostream> /*! * \brief The abstract base class for all signal processing blocks. @@ -73,6 +75,8 @@ protected: gr_io_signature_sptr d_output_signature; long d_unique_id; vcolor d_color; + std::vector<long> d_max_output_buffer; + std::vector<long> d_min_output_buffer; gr_basic_block(void){} //allows pure virtual interface sub-classes @@ -104,7 +108,21 @@ 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 - + long max_output_buffer(size_t i){ return d_max_output_buffer.size()>i?d_max_output_buffer[i]:d_max_output_buffer[0]; } + 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); + } + } + void set_max_output_buffer(long max_output_buffer, int port){ d_max_output_buffer[port] = max_output_buffer; } + long min_output_buffer(size_t i){ return d_min_output_buffer.size()>i?d_min_output_buffer[i]:d_min_output_buffer[0]; } + 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); + } + } + void set_min_output_buffer(long min_output_buffer, int port){ 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_basic_block.i b/gnuradio-core/src/lib/runtime/gr_basic_block.i index e43cc114c..848017dd8 100644 --- a/gnuradio-core/src/lib/runtime/gr_basic_block.i +++ b/gnuradio-core/src/lib/runtime/gr_basic_block.i @@ -42,6 +42,12 @@ public: long unique_id() const; gr_basic_block_sptr to_basic_block(); bool check_topology (int ninputs, int noutputs); + long max_output_buffer(int i); + void set_max_output_buffer(long max_output_buffer); + void set_max_output_buffer(long max_output_buffer, int port); + long min_output_buffer(int i); + void set_min_output_buffer(long min_output_buffer); + void set_min_output_buffer(long min_output_buffer, int port); }; %rename(block_ncurrently_allocated) gr_basic_block_ncurrently_allocated; diff --git a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc index 030e2d97d..fb375b0f3 100644 --- a/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc +++ b/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc @@ -114,6 +114,21 @@ 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){ +// 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){ + nitems = std::max((long)nitems, (long)block->min_output_buffer(port)); + nitems -= nitems%grblock->output_multiple(); + if( nitems < 1 ) + throw std::runtime_error("problems allocating a buffer with the given min output buffer constraint!"); + } + for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) { gr_block_sptr dgrblock = cast_to_block_sptr(*p); if (!dgrblock) @@ -125,6 +140,7 @@ gr_flat_flowgraph::allocate_buffer(gr_basic_block_sptr block, int port) nitems = std::max(nitems, static_cast<int>(2*(decimation*multiple+history))); } +// std::cout << "gr_make_buffer(" << nitems << ", " << item_size << ", " << grblock << "\n"; return gr_make_buffer(nitems, item_size, grblock); } |