diff options
Diffstat (limited to 'gnuradio-core')
-rw-r--r-- | gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 46 | ||||
-rw-r--r-- | gnuradio-core/src/lib/io/gr_file_meta_sink.h | 1 |
2 files changed, 43 insertions, 4 deletions
diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc index ff35a01fc..e2b892efd 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc @@ -213,13 +213,53 @@ gr_file_meta_sink::work(int noutput_items, } } else { - update_last_header(); - if(update_header(itr->key, itr->value)) { - write_and_update(); + int item_offset = (int)(itr->offset - abs_N); + + std::cerr << "New tag found with absolute index: " << itr->offset + << " and relative index: " << item_offset << std::endl; + std::cerr << "Current segment size: " << d_total_seg_size << std::endl; + std::cerr << "Tag key: " << pmt_symbol_to_string(itr->key) << std::endl; + std::cerr << "Tag Val: "; + pmt_print(itr->value); + std::cerr << std::endl; + + // Write date to file up to the next tag location + while(nwritten < item_offset) { + size_t towrite = std::min(d_max_seg_size - d_total_seg_size, + (size_t)(item_offset - nwritten)); + int count = fwrite(inbuf, d_itemsize, towrite, d_fp); + if(count == 0) // FIXME add error handling + break; + nwritten += count; + inbuf += count * d_itemsize; + + d_total_seg_size += count; + + // Only add a new header if we are not at the position of the + // next tag + if((d_total_seg_size == d_max_seg_size) && + (nwritten < item_offset)) { + update_last_header(); + write_and_update(); + d_total_seg_size = 0; + } + } + + if(d_total_seg_size > 0) { + update_last_header(); + if(update_header(itr->key, itr->value)) { + write_and_update(); + d_total_seg_size = 0; + } + } + else { + if(update_header(itr->key, itr->value)) + update_last_header(); } } } + // Finish up the rest of the data after tags while(nwritten < noutput_items) { size_t towrite = std::min(d_max_seg_size - d_total_seg_size, (size_t)(noutput_items - nwritten)); diff --git a/gnuradio-core/src/lib/io/gr_file_meta_sink.h b/gnuradio-core/src/lib/io/gr_file_meta_sink.h index f02c2c4ad..ed3a9f1db 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.h @@ -122,7 +122,6 @@ class GR_CORE_API gr_file_meta_sink : public gr_sync_block, public gr_file_sink_ bool update_header(pmt_t key, pmt_t value); void update_last_header(); void write_and_update(); - uint64_t get_last_header_loc(); public: ~gr_file_meta_sink(); |