1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-11-11 04:20:03 +00:00

Less callback shenanigans

This commit is contained in:
Victor Castillo 2024-08-17 20:20:27 +02:00
parent 01bbc39fa6
commit 33067d631d
No known key found for this signature in database
GPG Key ID: 8EF1FC8B7182F608
4 changed files with 32 additions and 26 deletions

View File

@ -77,35 +77,26 @@ int IONGSMSFileSource::work(
{ {
io_buffer_offset_ = 0; io_buffer_offset_ = 0;
std::fread(io_buffer_.data(), sizeof(decltype(io_buffer_)::value_type), io_buffer_.size(), fd_); std::fread(io_buffer_.data(), sizeof(decltype(io_buffer_)::value_type), io_buffer_.size(), fd_);
std::vector<int> items_produced{};
items_produced.resize(output_items.size()); items_produced_.resize(output_items.size());
for (int i = 0; i < items_produced.size(); ++i) for (int i = 0; i < items_produced_.size(); ++i)
{ {
items_produced[i] = 0; items_produced_[i] = 0;
} }
while (io_buffer_offset_ < io_buffer_.size()) while (io_buffer_offset_ < io_buffer_.size())
{ {
for (auto& c : chunk_data_) for (auto& c : chunk_data_)
{ {
io_buffer_offset_ += c->read_from_buffer(io_buffer_.data(), io_buffer_offset_); auto* chunk = c.get();
c->write_to_output(output_items, [&](int output, int nitems) { io_buffer_offset_ += chunk->read_from_buffer(io_buffer_.data(), io_buffer_offset_);
items_produced[output] += nitems; chunk->write_to_output(output_items, items_produced_);
// if (nitems_written(output) % 100 == 0)
// {
// add_item_tag(output, nitems_written(output), pmt::mp("tag_test"), pmt::from_uint64(nitems_written(output)));
// }
});
} }
} }
// std::cout << "produced: " << std::to_string(items_produced[0]) << " out of " << std::to_string(noutput_items) << std::endl; for (int i = 0; i < items_produced_.size(); ++i)
for (int i = 0; i < items_produced.size(); ++i)
{ {
produce(i, items_produced[i]); produce(i, items_produced_[i]);
} }
return WORK_CALLED_PRODUCE; return WORK_CALLED_PRODUCE;

View File

@ -59,6 +59,7 @@ private:
FILE* fd_; FILE* fd_;
std::vector<uint8_t> io_buffer_; std::vector<uint8_t> io_buffer_;
std::size_t io_buffer_offset_; std::size_t io_buffer_offset_;
std::vector<int> items_produced_;
std::size_t output_stream_count_; std::size_t output_stream_count_;
std::vector<std::size_t> output_stream_item_sizes_; std::vector<std::size_t> output_stream_item_sizes_;
std::vector<std::shared_ptr<IONGSMSChunkData>> chunk_data_; std::vector<std::shared_ptr<IONGSMSChunkData>> chunk_data_;

View File

@ -83,12 +83,26 @@ std::size_t IONGSMSChunkData::read_from_buffer(uint8_t* buffer, std::size_t offs
return sizeword_ * countwords_; return sizeword_ * countwords_;
} }
void IONGSMSChunkData::write_to_output(gr_vector_void_star& outputs, const std::function<void(int output, int nitems)>& produce) void IONGSMSChunkData::write_to_output(gr_vector_void_star& outputs, std::vector<int>& output_items)
{ {
with_word_type(sizeword_, [&]<typename WordType> switch (sizeword_)
{ {
unpack_words<WordType>(outputs, produce); case 1:
}); unpack_words<int8_t>(outputs, output_items);
break;
case 2:
unpack_words<int16_t>(outputs, output_items);
break;
case 4:
unpack_words<int32_t>(outputs, output_items);
break;
case 8:
unpack_words<int64_t>(outputs, output_items);
break;
default:
LOG(ERROR) << "Unknown word size (" << std::to_string(sizeword_) << "), unpacking nothing.";
break;
}
} }
@ -104,7 +118,7 @@ std::size_t IONGSMSChunkData::output_stream_item_size(std::size_t stream_index)
template <typename WT> template <typename WT>
void IONGSMSChunkData::unpack_words(gr_vector_void_star& outputs, const std::function<void(int output, int nitems)>& produce) void IONGSMSChunkData::unpack_words(gr_vector_void_star& outputs, std::vector<int>& output_items)
{ {
WT* data = static_cast<WT*>(buffer_); WT* data = static_cast<WT*>(buffer_);
// TODO - Swap endiannes if needed // TODO - Swap endiannes if needed
@ -131,7 +145,7 @@ void IONGSMSChunkData::unpack_words(gr_vector_void_star& outputs, const std::fun
} }
else else
{ {
produce(output_index, write_stream_samples(ctx, lump, stream, encoding, outputs[output_index])); output_items[output_index] += write_stream_samples(ctx, lump, stream, encoding, outputs[output_index]);
} }
} }
} }

View File

@ -89,14 +89,14 @@ public:
std::size_t read_from_buffer(uint8_t* buffer, std::size_t offset); std::size_t read_from_buffer(uint8_t* buffer, std::size_t offset);
void write_to_output(gr_vector_void_star& outputs, const std::function<void(int output, int nitems)>& produce); void write_to_output(gr_vector_void_star& outputs, std::vector<int>& output_items);
std::size_t output_stream_count() const; 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_size(std::size_t stream_index) const;
private: private:
template <typename WT> template <typename WT>
void unpack_words(gr_vector_void_star& outputs, const std::function<void(int output, int nitems)>& produce); void unpack_words(gr_vector_void_star& outputs, std::vector<int>& output_items);
template <typename WT> template <typename WT>
std::size_t write_stream_samples( std::size_t write_stream_samples(