diff options
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r-- | gr-blocks/lib/file_source_impl.cc | 25 | ||||
-rw-r--r-- | gr-blocks/lib/file_source_impl.h | 7 |
2 files changed, 31 insertions, 1 deletions
diff --git a/gr-blocks/lib/file_source_impl.cc b/gr-blocks/lib/file_source_impl.cc index 1602b02416..9dfd30c016 100644 --- a/gr-blocks/lib/file_source_impl.cc +++ b/gr-blocks/lib/file_source_impl.cc @@ -64,10 +64,15 @@ namespace gr { io_signature::make(0, 0, 0), io_signature::make(1, 1, itemsize)), d_itemsize(itemsize), d_fp(0), d_new_fp(0), d_repeat(repeat), - d_updated(false) + d_updated(false), d_file_begin(true), d_repeat_cnt(0), + d_add_begin_tag(pmt::PMT_NIL) { open(filename, repeat); do_update(); + + std::stringstream str; + str << name() << unique_id(); + _id = pmt::string_to_symbol(str.str()); } file_source_impl::~file_source_impl() @@ -139,9 +144,16 @@ namespace gr { d_fp = d_new_fp; // install new file pointer d_new_fp = 0; d_updated = false; + d_file_begin = true; } } + void + file_source_impl::set_begin_tag(pmt::pmt_t val) + { + d_add_begin_tag = val; + } + int file_source_impl::work(int noutput_items, gr_vector_const_void_star &input_items, @@ -156,7 +168,14 @@ namespace gr { throw std::runtime_error("work with file not open"); gr::thread::scoped_lock lock(fp_mutex); // hold for the rest of this function + while(size) { + // Add stream tag whenever the file starts again + if (d_file_begin && d_add_begin_tag != pmt::PMT_NIL) { + add_item_tag(0, nitems_written(0) + noutput_items - size, d_add_begin_tag, pmt::from_long(d_repeat_cnt), _id); + d_file_begin = false; + } + i = fread(o, d_itemsize, size, (FILE*)d_fp); size -= i; @@ -178,6 +197,10 @@ namespace gr { fprintf(stderr, "[%s] fseek failed\n", __FILE__); exit(-1); } + if (d_add_begin_tag != pmt::PMT_NIL) { + d_file_begin = true; + d_repeat_cnt++; + } } if(size > 0) { // EOF or error diff --git a/gr-blocks/lib/file_source_impl.h b/gr-blocks/lib/file_source_impl.h index 80232a1dbe..19f393fc1d 100644 --- a/gr-blocks/lib/file_source_impl.h +++ b/gr-blocks/lib/file_source_impl.h @@ -37,7 +37,12 @@ namespace gr { FILE *d_new_fp; bool d_repeat; bool d_updated; + bool d_file_begin; + long d_repeat_cnt; + pmt::pmt_t d_add_begin_tag; + boost::mutex fp_mutex; + pmt::pmt_t _id; void do_update(); @@ -52,6 +57,8 @@ namespace gr { int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + + void set_begin_tag(pmt::pmt_t val); }; } /* namespace blocks */ |