+ if (segment_id >= segments_.size())
+ return;
+
+ const DecodeSegment *segment = &(segments_.at(segment_id));
+ const map<const decode::Row, decode::RowData> *rows = &(segment->annotation_rows);
+
+ const auto iter = rows->find(row);
+ if (iter != rows->end())
+ (*iter).second.get_annotation_subset(dest, start_sample, end_sample);
+}
+
+void DecodeSignal::get_annotation_subset(
+ vector<pv::data::decode::Annotation> &dest,
+ uint32_t segment_id, uint64_t start_sample, uint64_t end_sample) const
+{
+ // Note: We put all vectors and lists on the heap, not the stack
+
+ const vector<Row> rows = get_rows();
+
+ // Use forward_lists for faster merging
+ forward_list<Annotation> *all_ann_list = new forward_list<Annotation>();
+
+ for (const Row& row : rows) {
+ vector<Annotation> *ann_vector = new vector<Annotation>();
+ get_annotation_subset(*ann_vector, row, segment_id, start_sample, end_sample);
+
+ forward_list<Annotation> *ann_list =
+ new forward_list<Annotation>(ann_vector->begin(), ann_vector->end());
+ delete ann_vector;
+
+ all_ann_list->merge(*ann_list);
+ delete ann_list;
+ }
+
+ move(all_ann_list->begin(), all_ann_list->end(), back_inserter(dest));
+ delete all_ann_list;
+}
+
+uint32_t DecodeSignal::get_binary_data_chunk_count(uint32_t segment_id,
+ const Decoder* dec, uint32_t bin_class_id) const
+{
+ if (segments_.size() == 0)
+ return 0;
+
+ try {
+ const DecodeSegment *segment = &(segments_.at(segment_id));
+
+ for (const DecodeBinaryClass& bc : segment->binary_classes)
+ if ((bc.decoder == dec) && (bc.info->bin_class_id == bin_class_id))
+ return bc.chunks.size();
+ } catch (out_of_range&) {
+ // Do nothing
+ }
+
+ return 0;
+}
+
+void DecodeSignal::get_binary_data_chunk(uint32_t segment_id,
+ const Decoder* dec, uint32_t bin_class_id, uint32_t chunk_id,
+ const vector<uint8_t> **dest, uint64_t *size)
+{
+ try {
+ const DecodeSegment *segment = &(segments_.at(segment_id));
+
+ for (const DecodeBinaryClass& bc : segment->binary_classes)
+ if ((bc.decoder == dec) && (bc.info->bin_class_id == bin_class_id)) {
+ if (dest) *dest = &(bc.chunks.at(chunk_id).data);
+ if (size) *size = bc.chunks.at(chunk_id).data.size();
+ return;
+ }
+ } catch (out_of_range&) {
+ // Do nothing
+ }
+}
+
+void DecodeSignal::get_merged_binary_data_chunks_by_sample(uint32_t segment_id,
+ const Decoder* dec, uint32_t bin_class_id, uint64_t start_sample,
+ uint64_t end_sample, vector<uint8_t> *dest) const
+{
+ assert(dest != nullptr);
+
+ try {
+ const DecodeSegment *segment = &(segments_.at(segment_id));
+
+ const DecodeBinaryClass* bin_class = nullptr;
+ for (const DecodeBinaryClass& bc : segment->binary_classes)
+ if ((bc.decoder == dec) && (bc.info->bin_class_id == bin_class_id))
+ bin_class = &bc;
+
+ // Determine overall size before copying to resize dest vector only once
+ uint64_t size = 0;
+ uint64_t matches = 0;
+ for (const DecodeBinaryDataChunk& chunk : bin_class->chunks)
+ if ((chunk.sample >= start_sample) && (chunk.sample < end_sample)) {
+ size += chunk.data.size();
+ matches++;
+ }
+ dest->resize(size);
+
+ uint64_t offset = 0;
+ uint64_t matches2 = 0;
+ for (const DecodeBinaryDataChunk& chunk : bin_class->chunks)
+ if ((chunk.sample >= start_sample) && (chunk.sample < end_sample)) {
+ memcpy(dest->data() + offset, chunk.data.data(), chunk.data.size());
+ offset += chunk.data.size();
+ matches2++;
+
+ // Make sure we don't overwrite memory if the array grew in the meanwhile
+ if (matches2 == matches)
+ break;
+ }
+ } catch (out_of_range&) {
+ // Do nothing
+ }
+}
+
+void DecodeSignal::get_merged_binary_data_chunks_by_offset(uint32_t segment_id,
+ const data::decode::Decoder* dec, uint32_t bin_class_id, uint64_t start,
+ uint64_t end, vector<uint8_t> *dest) const
+{
+ assert(dest != nullptr);
+
+ try {
+ const DecodeSegment *segment = &(segments_.at(segment_id));
+
+ const DecodeBinaryClass* bin_class = nullptr;
+ for (const DecodeBinaryClass& bc : segment->binary_classes)
+ if ((bc.decoder == dec) && (bc.info->bin_class_id == bin_class_id))
+ bin_class = &bc;
+
+ // Determine overall size before copying to resize dest vector only once
+ uint64_t size = 0;
+ uint64_t offset = 0;
+ for (const DecodeBinaryDataChunk& chunk : bin_class->chunks) {
+ if (offset >= start)
+ size += chunk.data.size();
+ offset += chunk.data.size();
+ if (offset >= end)
+ break;
+ }
+ dest->resize(size);
+
+ offset = 0;
+ uint64_t dest_offset = 0;
+ for (const DecodeBinaryDataChunk& chunk : bin_class->chunks) {
+ if (offset >= start) {
+ memcpy(dest->data() + dest_offset, chunk.data.data(), chunk.data.size());
+ dest_offset += chunk.data.size();
+ }
+ offset += chunk.data.size();
+ if (offset >= end)
+ break;
+ }
+ } catch (out_of_range&) {
+ // Do nothing
+ }
+}
+
+const DecodeBinaryClass* DecodeSignal::get_binary_data_class(uint32_t segment_id,
+ const data::decode::Decoder* dec, uint32_t bin_class_id) const
+{