From 5e39e6c17b6af181f4cd9110e3a17a2d287318d1 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 13 Dec 2012 14:23:11 -0500 Subject: core: metadata file source parses extras header and converts data to tags. --- gnuradio-core/src/lib/io/gr_file_meta_source.cc | 29 +++++++++++++++++++++++-- gnuradio-core/src/lib/io/gr_file_meta_source.h | 2 ++ 2 files changed, 29 insertions(+), 2 deletions(-) (limited to 'gnuradio-core') 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 &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 &tags); + void parse_extras(pmt_t extras, uint64_t offset, + std::vector &tags); public: ~gr_file_meta_source(); -- cgit