diff options
author | Tom Rondeau | 2012-12-04 18:36:35 -0500 |
---|---|---|
committer | Tom Rondeau | 2012-12-04 18:36:35 -0500 |
commit | 611959d2f9af4595200186acf85a64f5bf318fac (patch) | |
tree | 06d9bbd954d245195cd75c346643ceded4040591 /gnuradio-core | |
parent | 13139bb7dff0d543dfdb2cdaaa684a9fc5800cae (diff) | |
download | gnuradio-611959d2f9af4595200186acf85a64f5bf318fac.tar.gz gnuradio-611959d2f9af4595200186acf85a64f5bf318fac.tar.bz2 gnuradio-611959d2f9af4595200186acf85a64f5bf318fac.zip |
core: updated metadata structure to use relative header info.
Now the start tag info in the header is relative to the begining of the header (so, basically, the size of the header + extras).
Diffstat (limited to 'gnuradio-core')
-rw-r--r-- | gnuradio-core/src/lib/io/gr_file_meta_sink.cc | 32 | ||||
-rw-r--r-- | gnuradio-core/src/python/gnuradio/parse_file_metadata.py | 12 |
2 files changed, 12 insertions, 32 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 ebfeb4e4a..ff35a01fc 100644 --- a/gnuradio-core/src/lib/io/gr_file_meta_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_meta_sink.cc @@ -151,15 +151,13 @@ gr_file_meta_sink::update_last_header() { // Update the last header info with the number of samples this // block represents. + size_t hdrlen = METADATA_HEADER_SIZE+d_extra_size; size_t seg_size = d_itemsize*d_total_seg_size; - uint64_t loc = get_last_header_loc(); pmt_t s = pmt_from_uint64(seg_size); - //std::cerr << "Found Tag at: " << itr->offset*d_itemsize << std::endl; - //std::cerr << " last header starts at: " << loc << std::endl; - //std::cerr << " segment size is: " << seg_size << std::endl; if(update_header(mp("size"), s)) { - fseek(d_fp, loc, SEEK_SET); + fseek(d_fp, -seg_size-hdrlen, SEEK_CUR); write_header(d_header, d_extra); + fseek(d_fp, seg_size, SEEK_CUR); } } @@ -168,38 +166,19 @@ gr_file_meta_sink::write_and_update() { // New header, so set current size of chunk to 0 and start of chunk // based on current index + header size. - uint64_t loc = get_last_header_loc(); + //uint64_t loc = get_last_header_loc(); pmt_t s = pmt_from_uint64(0); - size_t seg_size = d_itemsize*d_total_seg_size; if(update_header(mp("size"), s)) { // If we have multiple tags on the same offset, this makes // sure we just overwrite the same header each time instead // of creating a new header per tag. - uint64_t seg_start = loc; - if(seg_size != 0) - seg_start += METADATA_HEADER_SIZE + d_extra_size + seg_size + 1; - s = pmt_from_uint64(seg_start + METADATA_HEADER_SIZE + d_extra_size); + s = pmt_from_uint64(METADATA_HEADER_SIZE + d_extra_size); if(update_header(mp("strt"), s)) { - //std::cerr << "Adding new header" << std::endl; - //std::cerr << " new header start at: " << seg_start-METADATA_HEADER_SIZE << std::endl; - //std::cerr << " new seg start at: " << seg_start << std::endl; - fseek(d_fp, seg_start, SEEK_SET); write_header(d_header, d_extra); - d_total_seg_size = 0; } } } -uint64_t -gr_file_meta_sink::get_last_header_loc() -{ - uint64_t loc = 0; - pmt_t v = pmt_dict_ref(d_header, mp("strt"), PMT_NIL); - if(!pmt_eq(v, PMT_NIL)) - loc = pmt_to_uint64(v) - (METADATA_HEADER_SIZE+d_extra_size); - return loc; -} - gr_file_meta_sink::~gr_file_meta_sink() { update_last_header(); @@ -254,6 +233,7 @@ gr_file_meta_sink::work(int noutput_items, if(d_total_seg_size == d_max_seg_size) { update_last_header(); write_and_update(); + d_total_seg_size = 0; } } diff --git a/gnuradio-core/src/python/gnuradio/parse_file_metadata.py b/gnuradio-core/src/python/gnuradio/parse_file_metadata.py index 31ba5f7f0..053f096c1 100644 --- a/gnuradio-core/src/python/gnuradio/parse_file_metadata.py +++ b/gnuradio-core/src/python/gnuradio/parse_file_metadata.py @@ -50,7 +50,7 @@ ftype_to_size = {gr.GR_FILE_BYTE: gr.sizeof_char, gr.GR_FILE_FLOAT: gr.sizeof_float, gr.GR_FILE_DOUBLE: gr.sizeof_double} -def parse_header(p, hdr_start, VERBOSE=False): +def parse_header(p, VERBOSE=False): dump = gr.PMT_NIL info = dict() @@ -122,13 +122,13 @@ def parse_header(p, hdr_start, VERBOSE=False): if(gr.pmt_dict_has_key(p, gr.pmt_string_to_symbol("strt"))): r = gr.pmt_dict_ref(p, gr.pmt_string_to_symbol("strt"), dump) seg_start = gr.pmt_to_uint64(r) - info["strt"] = seg_start - info["extra_len"] = seg_start - hdr_start - HEADER_LENGTH + info["hdr_len"] = seg_start + info["extra_len"] = seg_start - HEADER_LENGTH info["has_extra"] = info["extra_len"] > 0 if(VERBOSE): - print "Segment Start: {0} bytes".format(seg_start) - print "Extra Length: {0}".format((info["extra_len"])) - print "Extra Header? {0}".format(info["has_extra"]) + print "Header Length: {0} bytes".format(info["hdr_len"]) + print "Extra Length: {0}".format((info["extra_len"])) + print "Extra Header? {0}".format(info["has_extra"]) else: sys.stderr.write("Could not find key 'strt': invalid or corrupt data file.\n") sys.exit(1) |