ADTF File Library
Loading...
Searching...
No Matches
sorting_reader.h
Go to the documentation of this file.
1
16
17#pragma once
18
19#include <adtf_file/reader.h>
20
21namespace adtfdat_processing
22{
30{
31public:
41 void open(const std::vector<adtf_file::Stream>& streams,
42 bool sample_timestamps,
43 std::chrono::seconds sorting_window,
44 bool trigger_for_each_sample);
45
47
49
50 uint64_t getItemIndexForTimeStamp(std::chrono::nanoseconds time_stamp) override;
51 uint64_t getItemIndexForStreamItemIndex(uint16_t stream_id, uint64_t stream_item_index) override;
52 std::shared_ptr<const adtf_file::StreamType> getStreamTypeBefore(uint64_t item_index, uint16_t stream_id) override;
53 void seekTo(uint64_t item_index) override;
54
55protected:
64 virtual adtf_file::FileItem getNextUnsortedItem() = 0;
65
66 virtual uint64_t getUnsortedItemIndexForTimeStamp(std::chrono::nanoseconds time_stamp);
67 virtual std::shared_ptr<const adtf_file::StreamType> getUnsortedStreamTypeBefore(uint64_t item_index,
68 uint16_t stream_id);
69 virtual void unsortedSeekTo(uint64_t item_index);
70
71private:
72 void internalSeek(std::chrono::nanoseconds time_stamp);
73 void fillQueue(std::chrono::nanoseconds sorting_window_duration);
74
75 struct FileItemCompare
76 {
77 constexpr bool operator()(const adtf_file::FileItem& lhs, const adtf_file::FileItem& rhs) const
78 {
79 return lhs.time_stamp < rhs.time_stamp;
80 }
81 };
82 using Queue = std::multimap<adtf_file::FileItem, std::shared_ptr<const adtf_file::StreamType>, FileItemCompare>;
83 Queue _queue;
84 bool _end_of_file = false;
85 // Internal queue position caused by call to getStreamTypeBefore() or seekTo()
86 std::optional<std::chrono::nanoseconds> _internal_seek_queue_position;
87 // Queue position as set to explicit call to seekTo().
88 // If _internal_seek_queue_position and _seek_queue_position are inequal,
89 std::optional<std::chrono::nanoseconds> _seek_queue_position;
90 std::chrono::seconds _sorting_window = std::chrono::seconds(10);
91 std::unordered_map<uint16_t, std::chrono::nanoseconds> _highest_sample_item_timestamps;
92 bool _sample_timestamps = true;
93 bool _trigger_for_each_sample = false;
94 std::vector<uint16_t> _stream_ids;
95 std::unordered_map<uint16_t, std::shared_ptr<const adtf_file::StreamType>> _current_types;
96 std::unordered_map<uint16_t, std::shared_ptr<const adtf_file::StreamType>> _last_published_types;
97};
98
103{
104public:
109
110 std::string getReaderIdentifier() const override;
111 void open(const std::string& file_name,
112 std::shared_ptr<adtf_file::SampleFactory> sample_factory,
113 std::shared_ptr<adtf_file::StreamTypeFactory> stream_type_factory) override;
114
115 uint32_t getFileVersion() const override;
116 std::string getDescription() const override;
117 std::vector<adtf_file::Stream> getStreams() const override;
118 std::vector<adtf_file::Extension> getExtensions() const override;
120 std::optional<uint64_t> getItemCount() const override;
121 std::optional<double> getProgress() const override;
122
123 uint64_t getUnsortedItemIndexForTimeStamp(std::chrono::nanoseconds time_stamp) override;
124 std::shared_ptr<const adtf_file::StreamType> getUnsortedStreamTypeBefore(uint64_t item_index,
125 uint16_t stream_id) override;
126 void unsortedSeekTo(uint64_t item_index) override;
127
128private:
129 std::shared_ptr<Reader> _reader;
130 std::vector<adtf_file::Stream> _streams;
131};
132
137
138} // namespace adtfdat_processing
Definition reader.h:345
class to create or read a file item. This file item is either a sample, streamtype or trigger.
Definition reader.h:172
std::chrono::nanoseconds time_stamp
time stamp of the file item
Definition reader.h:177
Default Reader factory implementation for readers using a standard default CTOR.
Definition reader.h:367
virtual void open(const std::string &filename, std::shared_ptr< SampleFactory > sample_factory, std::shared_ptr< StreamTypeFactory > stream_type_factory)=0
opens a file by the given filename. The given factories must be used to create samples and streamtype...
Interface for seekable Reader, where the file position can be adapted.
Definition reader.h:288
uint32_t getFileVersion() const override
std::optional< double > getProgress() const override
Get the Progress, a relative file position between 0.0 and 1.0.
std::vector< adtf_file::Extension > getExtensions() const override
Get the Extensions if any.
std::string getDescription() const override
std::vector< adtf_file::Stream > getStreams() const override
Get the Streams.
void open(const std::string &file_name, std::shared_ptr< adtf_file::SampleFactory > sample_factory, std::shared_ptr< adtf_file::StreamTypeFactory > stream_type_factory) override
opens a file by the given filename. The given factories must be used to create samples and streamtype...
std::optional< uint64_t > getItemCount() const override
Get the Item Count. This gets the overall count of all items (samples, stream types and triggers) of ...
std::string getReaderIdentifier() const override
Get the Reader Identifier of the Reader.
adtf_file::FileItem getNextUnsortedItem() override
Proxy reader that reorders items within a sliding window to restore timestamp order....
Definition sorting_reader.h:30
std::shared_ptr< const adtf_file::StreamType > getStreamTypeBefore(uint64_t item_index, uint16_t stream_id) override
uint64_t getItemIndexForTimeStamp(std::chrono::nanoseconds time_stamp) override
void open(const std::vector< adtf_file::Stream > &streams, bool sample_timestamps, std::chrono::seconds sorting_window, bool trigger_for_each_sample)
prepare the sorting algorithm.
void seekTo(uint64_t item_index) override
uint64_t getItemIndexForStreamItemIndex(uint16_t stream_id, uint64_t stream_item_index) override
adtf_file::FileItem getNextItem() final override
virtual adtf_file::FileItem getNextUnsortedItem()=0
namespace for ADTF File library
Definition adtf2_adtf_core_media_sample_deserializer.h:25
namespace for ADTF DAT Processing library.
Definition ddl_helpers.h:38
adtf_file::ReaderFactoryImplementation< SortingProxyReader > SortingReaderFactory
Default reader factory implementation for the SortingProxyReader.
Definition sorting_reader.h:136