diff options
author | Tom Rondeau | 2012-12-13 14:23:11 -0500 |
---|---|---|
committer | Tom Rondeau | 2012-12-13 14:23:11 -0500 |
commit | 5e39e6c17b6af181f4cd9110e3a17a2d287318d1 (patch) | |
tree | 0228f76805f00dc86bce9777cc3b47b3e31c057e /gnuradio-core | |
parent | 68159be8e0114e347b942e33d0b116c9f77127ac (diff) | |
download | gnuradio-5e39e6c17b6af181f4cd9110e3a17a2d287318d1.tar.gz gnuradio-5e39e6c17b6af181f4cd9110e3a17a2d287318d1.tar.bz2 gnuradio-5e39e6c17b6af181f4cd9110e3a17a2d287318d1.zip |
core: metadata file source parses extras header and converts data to tags.
Diffstat (limited to 'gnuradio-core')
-rw-r--r-- | gnuradio-core/src/lib/io/gr_file_meta_source.cc | 29 | ||||
-rw-r--r-- | gnuradio-core/src/lib/io/gr_file_meta_source.h | 2 |
2 files changed, 29 insertions, 2 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 10f08e79d..02955e7b9 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.cc @@ -89,8 +89,10 @@ gr_file_meta_source::gr_file_meta_source(const char *filename, do_update(); pmt_t hdr = PMT_NIL, extras = PMT_NIL; - if(read_header(hdr, extras)) + if(read_header(hdr, extras)) { parse_header(hdr, 0, d_tags); + parse_extras(extras, 0, d_tags); + } else throw std::runtime_error("file_meta_source: could not read header.\n"); @@ -259,6 +261,27 @@ gr_file_meta_source::parse_header(pmt_t hdr, uint64_t offset, } } +void +gr_file_meta_source::parse_extras(pmt_t extras, uint64_t offset, + std::vector<gr_tag_t> &tags) +{ + pmt_t item, key, val; + + size_t nitems = pmt_length(extras); + for(size_t i = 0; i < nitems; i++) { + item = pmt_nth(i, extras); + key = pmt_car(item); + val = pmt_cdr(item); + + gr_tag_t t; + t.offset = offset; + t.key = key; + t.value = val; + t.srcid = alias_pmt(); + tags.push_back(t); + } +} + bool gr_file_meta_source::open(const char *filename) { @@ -351,8 +374,10 @@ gr_file_meta_source::work(int noutput_items, // the new tags to send and set the next segment size. if(d_seg_size == 0) { pmt_t hdr=PMT_NIL, extras=PMT_NIL; - if(read_header(hdr, extras)) + if(read_header(hdr, extras)) { parse_header(hdr, nitems_written(0), d_tags); + parse_extras(extras, nitems_written(0), d_tags); + } else { return -1; } 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 de0bedf72..46665e415 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_source.h +++ b/gnuradio-core/src/lib/io/gr_file_meta_source.h @@ -105,6 +105,8 @@ class GR_CORE_API gr_file_meta_source : public gr_sync_block bool read_header(pmt_t &hdr, pmt_t &extras); void parse_header(pmt_t hdr, uint64_t offset, std::vector<gr_tag_t> &tags); + void parse_extras(pmt_t extras, uint64_t offset, + std::vector<gr_tag_t> &tags); public: ~gr_file_meta_source(); |