mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2024-11-10 20:10:05 +00:00
Less callback shenanigans
This commit is contained in:
parent
01bbc39fa6
commit
33067d631d
@ -77,35 +77,26 @@ int IONGSMSFileSource::work(
|
||||
{
|
||||
io_buffer_offset_ = 0;
|
||||
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());
|
||||
for (int i = 0; i < items_produced.size(); ++i)
|
||||
items_produced_.resize(output_items.size());
|
||||
for (int i = 0; i < items_produced_.size(); ++i)
|
||||
{
|
||||
items_produced[i] = 0;
|
||||
items_produced_[i] = 0;
|
||||
}
|
||||
|
||||
|
||||
while (io_buffer_offset_ < io_buffer_.size())
|
||||
{
|
||||
for (auto& c : chunk_data_)
|
||||
{
|
||||
io_buffer_offset_ += c->read_from_buffer(io_buffer_.data(), io_buffer_offset_);
|
||||
c->write_to_output(output_items, [&](int output, int nitems) {
|
||||
items_produced[output] += nitems;
|
||||
|
||||
// if (nitems_written(output) % 100 == 0)
|
||||
// {
|
||||
// add_item_tag(output, nitems_written(output), pmt::mp("tag_test"), pmt::from_uint64(nitems_written(output)));
|
||||
// }
|
||||
});
|
||||
auto* chunk = c.get();
|
||||
io_buffer_offset_ += chunk->read_from_buffer(io_buffer_.data(), io_buffer_offset_);
|
||||
chunk->write_to_output(output_items, items_produced_);
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
@ -59,6 +59,7 @@ private:
|
||||
FILE* fd_;
|
||||
std::vector<uint8_t> io_buffer_;
|
||||
std::size_t io_buffer_offset_;
|
||||
std::vector<int> items_produced_;
|
||||
std::size_t output_stream_count_;
|
||||
std::vector<std::size_t> output_stream_item_sizes_;
|
||||
std::vector<std::shared_ptr<IONGSMSChunkData>> chunk_data_;
|
||||
|
@ -83,12 +83,26 @@ std::size_t IONGSMSChunkData::read_from_buffer(uint8_t* buffer, std::size_t offs
|
||||
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>
|
||||
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_);
|
||||
// TODO - Swap endiannes if needed
|
||||
@ -131,7 +145,7 @@ void IONGSMSChunkData::unpack_words(gr_vector_void_star& outputs, const std::fun
|
||||
}
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,14 +89,14 @@ public:
|
||||
|
||||
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_item_size(std::size_t stream_index) const;
|
||||
|
||||
private:
|
||||
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>
|
||||
std::size_t write_stream_samples(
|
||||
|
Loading…
Reference in New Issue
Block a user