From b36894246393f691b211432e8a475393e05029d7 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Sat, 17 Aug 2024 20:22:39 +0200 Subject: [PATCH] Fix wrong buffer size --- src/algorithms/signal_source/libs/ion_gsms.cc | 6 ++++-- src/algorithms/signal_source/libs/ion_gsms.h | 1 + src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc | 8 ++++++++ src/algorithms/signal_source/libs/ion_gsms_chunk_data.h | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gsms.cc b/src/algorithms/signal_source/libs/ion_gsms.cc index 1f6841224..d7036907a 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.cc +++ b/src/algorithms/signal_source/libs/ion_gsms.cc @@ -41,6 +41,7 @@ IONGSMSFileSource::IONGSMSFileSource( file_metadata_(file), block_metadata_(block), io_buffer_offset_(0), + maximum_item_rate_(0), chunk_cycle_length_(0) { std::filesystem::path data_filepath = metadata_filepath.parent_path() / file.Url().Value(); @@ -58,11 +59,10 @@ IONGSMSFileSource::IONGSMSFileSource( for (std::size_t i = 0; i < out_count; ++i) { output_stream_item_sizes_.push_back(chunk_data_.back()->output_stream_item_size(i)); + maximum_item_rate_ = std::max(chunk_data_.back()->output_stream_item_rate(i), maximum_item_rate_); } } output_stream_count_ = output_stream_offset; - - io_buffer_.resize((16*1024 - 1) * chunk_cycle_length_); } IONGSMSFileSource::~IONGSMSFileSource() @@ -75,6 +75,8 @@ int IONGSMSFileSource::work( gr_vector_const_void_star& input_items, gr_vector_void_star& output_items) { + const std::size_t max_sample_output = std::floor((noutput_items-1.0) / maximum_item_rate_); + io_buffer_.resize(max_sample_output * chunk_cycle_length_); io_buffer_offset_ = 0; std::fread(io_buffer_.data(), sizeof(decltype(io_buffer_)::value_type), io_buffer_.size(), fd_); diff --git a/src/algorithms/signal_source/libs/ion_gsms.h b/src/algorithms/signal_source/libs/ion_gsms.h index 629e00866..443ed3a81 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.h +++ b/src/algorithms/signal_source/libs/ion_gsms.h @@ -62,6 +62,7 @@ private: std::vector items_produced_; std::size_t output_stream_count_; std::vector output_stream_item_sizes_; + std::size_t maximum_item_rate_; std::vector> chunk_data_; std::size_t chunk_cycle_length_; }; diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc index dd2a09865..229d7a0d5 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc @@ -49,12 +49,15 @@ IONGSMSChunkData::IONGSMSChunkData(const GnssMetadata::Chunk& chunk, const std:: streams_.emplace_back(lump, stream, GnssMetadata::encoding_from_string(stream.Encoding()),output_streams + output_stream_offset); ++output_streams; std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); + std::size_t sample_rate = stream.RateFactor(); if (stream.Packedbits() >= 2 * stream.RateFactor() * stream.Quantization()) { // Samples have 'Complex' format sample_bitsize /= 2; + sample_rate *= 2; } output_stream_item_size_.push_back(bits_to_item_size(sample_bitsize)); + output_stream_item_rate_.push_back(sample_rate); } else { @@ -116,6 +119,11 @@ std::size_t IONGSMSChunkData::output_stream_item_size(std::size_t stream_index) return output_stream_item_size_[stream_index]; } +std::size_t IONGSMSChunkData::output_stream_item_rate(std::size_t stream_index) const +{ + return output_stream_item_rate_[stream_index]; +} + template void IONGSMSChunkData::unpack_words(gr_vector_void_star& outputs, std::vector& output_items) diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h index 4f517cf3f..97ce022c4 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h @@ -93,6 +93,7 @@ public: std::size_t output_stream_count() const; std::size_t output_stream_item_size(std::size_t stream_index) const; + std::size_t output_stream_item_rate(std::size_t stream_index) const; private: template @@ -126,6 +127,7 @@ private: uint8_t padding_bitsize_; std::size_t output_stream_count_; std::vector output_stream_item_size_; + std::vector output_stream_item_rate_; struct stream_metadata_t {