diff options
author | Tom Rondeau | 2012-12-13 13:51:55 -0500 |
---|---|---|
committer | Tom Rondeau | 2012-12-13 13:51:55 -0500 |
commit | 68159be8e0114e347b942e33d0b116c9f77127ac (patch) | |
tree | 941af57738569c93a8cc80c3ee3e1f6dc1c65e88 /gnuradio-core | |
parent | 0ce94e0df4c20c2dfc3cbf98ef97aecc49ee1cd5 (diff) | |
download | gnuradio-68159be8e0114e347b942e33d0b116c9f77127ac.tar.gz gnuradio-68159be8e0114e347b942e33d0b116c9f77127ac.tar.bz2 gnuradio-68159be8e0114e347b942e33d0b116c9f77127ac.zip |
core: updated meta data file sink to extract header metadata as tags and add them to the tag stream.
Diffstat (limited to 'gnuradio-core')
-rw-r--r-- | gnuradio-core/src/lib/io/gr_file_meta_source.cc | 53 | ||||
-rw-r--r-- | gnuradio-core/src/lib/io/gr_file_meta_source.h | 6 |
2 files changed, 45 insertions, 14 deletions
diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.cc b/gnuradio-core/src/lib/io/gr_file_meta_source.cc index b0850593b..10f08e79d 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.cc @@ -90,15 +90,12 @@ gr_file_meta_source::gr_file_meta_source(const char *filename, pmt_t hdr = PMT_NIL, extras = PMT_NIL; if(read_header(hdr, extras)) - parse_header(hdr); + parse_header(hdr, 0, d_tags); else throw std::runtime_error("file_meta_source: could not read header.\n"); // Set output signature based on itemsize info in header set_output_signature(gr_make_io_signature(1, 1, d_itemsize)); - - // Convert from bytes to items - d_seg_size /= d_itemsize; } gr_file_meta_source::~gr_file_meta_source() @@ -183,19 +180,39 @@ gr_file_meta_source::read_header(pmt_t &hdr, pmt_t &extras) } void -gr_file_meta_source::parse_header(pmt_t hdr) +gr_file_meta_source::parse_header(pmt_t hdr, uint64_t offset, + std::vector<gr_tag_t> &tags) { + pmt_t r, key; + // GET SAMPLE RATE - if(pmt_dict_has_key(hdr, pmt_string_to_symbol("rx_rate"))) { - d_samp_rate = pmt_to_double(pmt_dict_ref(hdr, pmt_string_to_symbol("rx_rate"), PMT_NIL)); + key = pmt_string_to_symbol("rx_rate"); + if(pmt_dict_has_key(hdr, key)) { + r = pmt_dict_ref(hdr, key, PMT_NIL); + d_samp_rate = pmt_to_double(r); + + gr_tag_t t; + t.offset = offset; + t.key = key; + t.value = r; + t.srcid = alias_pmt(); + tags.push_back(t); } else { throw std::runtime_error("file_meta_source: Could not extract sample rate.\n"); } // GET TIME STAMP - if(pmt_dict_has_key(hdr, pmt_string_to_symbol("rx_time"))) { - d_time_stamp = pmt_dict_ref(hdr, pmt_string_to_symbol("rx_time"), PMT_NIL); + key = pmt_string_to_symbol("rx_time"); + if(pmt_dict_has_key(hdr, key)) { + d_time_stamp = pmt_dict_ref(hdr, key, PMT_NIL); + + gr_tag_t t; + t.offset = offset; + t.key = key; + t.value = d_time_stamp; + t.srcid = alias_pmt(); + tags.push_back(t); } else { throw std::runtime_error("file_meta_source: Could not extract time stamp.\n"); @@ -230,9 +247,12 @@ gr_file_meta_source::parse_header(pmt_t hdr) throw std::runtime_error("file_meta_source: Could not extract complex indicator.\n"); } - // GET FIRST SEGMENT SIZE + // GET SEGMENT SIZE if(pmt_dict_has_key(hdr, pmt_string_to_symbol("size"))) { d_seg_size = pmt_to_uint64(pmt_dict_ref(hdr, pmt_string_to_symbol("size"), PMT_NIL)); + + // Convert from bytes to items + d_seg_size /= d_itemsize; } else { throw std::runtime_error("file_meta_source: Could not extract segment size.\n"); @@ -329,12 +349,13 @@ gr_file_meta_source::work(int noutput_items, { // We've reached the end of a segment; parse the next header and get // the new tags to send and set the next segment size. - if((d_seg_size == 0) && (!feof(d_fp))) { + if(d_seg_size == 0) { pmt_t hdr=PMT_NIL, extras=PMT_NIL; if(read_header(hdr, extras)) - parse_header(hdr); - else + parse_header(hdr, nitems_written(0), d_tags); + else { return -1; + } } char *out = (char*)output_items[0]; @@ -346,6 +367,12 @@ gr_file_meta_source::work(int noutput_items, if(d_fp == NULL) throw std::runtime_error("work with file not open"); + // Push all tags onto the stream and remove them from the vector + while(!d_tags.empty()) { + add_item_tag(0, d_tags.back()); + d_tags.pop_back(); + } + gruel::scoped_lock lock(d_mutex); // hold for the rest of this function while(size) { i = fread(out, d_itemsize, size, d_fp); diff --git a/gnuradio-core/src/lib/io/gr_file_meta_source.h b/gnuradio-core/src/lib/io/gr_file_meta_source.h index 819f4ece2..de0bedf72 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.h @@ -25,6 +25,7 @@ #include <gr_core_api.h> #include <gr_sync_block.h> +#include <gr_tags.h> #include <gruel/pmt.h> #include <gruel/thread.h> #include <cstdio> @@ -92,6 +93,8 @@ class GR_CORE_API gr_file_meta_source : public gr_sync_block FILE *d_fp, *d_hdr_fp; meta_state_t d_state; + std::vector<gr_tag_t> d_tags; + protected: gr_file_meta_source(const char *filename, bool repeat=false, @@ -100,7 +103,8 @@ class GR_CORE_API gr_file_meta_source : public gr_sync_block bool _open(FILE **fp, const char *filename); bool read_header(pmt_t &hdr, pmt_t &extras); - void parse_header(pmt_t hdr); + void parse_header(pmt_t hdr, uint64_t offset, + std::vector<gr_tag_t> &tags); public: ~gr_file_meta_source(); |