ADTF File Library
Loading...
Searching...
No Matches
reader.h
Go to the documentation of this file.
1
16
17#pragma once
18
19#include <chrono>
20#include <memory>
21#include <vector>
22#include <unordered_map>
23#include <istream>
24#include <string>
25#include <optional>
26#include <ifhd/ifhd.h>
27#include "stream_item.h"
28#include "object.h"
29#include "default_sample.h"
30#include "stream_type.h"
31#include "configuration.h"
32
33namespace adtf_file
34{
38namespace exceptions
39{
44
48class SeekingNotSupported : public std::runtime_error
49{
50public:
54 SeekingNotSupported(): runtime_error("Seeking is not supported")
55 {
56 }
57
58 using std::runtime_error::runtime_error;
59};
60
61} // namespace exceptions
62
72{
73public:
75 std::string name;
77 uint16_t stream_id;
79 uint32_t user_id;
81 uint32_t type_id;
83 uint32_t version_id;
85 size_t data_size;
87 const void* data;
88};
89
94{
95public:
100 virtual std::shared_ptr<StreamType> build() const = 0;
101};
102
107template<typename STREAM_TYPE_CLASS>
109{
110public:
111 std::shared_ptr<StreamType> build() const override
112 {
113 return std::make_shared<STREAM_TYPE_CLASS>();
114 }
115};
116
121{
122public:
127 virtual std::shared_ptr<Sample> build() const = 0;
128};
129
134template<typename SAMPLE_CLASS>
136{
137public:
138 std::shared_ptr<Sample> build() const override
139 {
140 return std::make_shared<SAMPLE_CLASS>();
141 }
142};
143
150{
151public:
153 uint16_t stream_id;
155 std::string name;
157 uint64_t item_count;
159 std::chrono::nanoseconds timestamp_of_first_item;
161 std::chrono::nanoseconds timestamp_of_last_item;
163 std::shared_ptr<const StreamType> initial_type;
164};
165
172{
173public:
175 uint16_t stream_id;
177 std::chrono::nanoseconds time_stamp;
180 std::shared_ptr<const StreamItem> stream_item;
181};
182
188class Reader : public Configurable
189{
190public:
195 virtual std::string getReaderIdentifier() const = 0;
196
208 virtual void open(const std::string& filename,
209 std::shared_ptr<SampleFactory> sample_factory,
210 std::shared_ptr<StreamTypeFactory> stream_type_factory) = 0;
211
223 virtual FileItem getNextItem() = 0;
224
232 virtual uint32_t getFileVersion() const
233 {
234 return ifhd::v201_v301::version_id;
235 }
236
240 virtual std::string getDescription() const
241 {
242 return {};
243 }
244
249 virtual std::vector<Extension> getExtensions() const
250 {
251 return {};
252 }
253
258 virtual std::vector<Stream> getStreams() const
259 {
260 return {};
261 }
262
269 virtual std::optional<uint64_t> getItemCount() const
270 {
271 return {};
272 }
273
278 virtual std::optional<double> getProgress() const
279 {
280 return {};
281 }
282};
283
287class SeekableReader : public Reader
288{
289public:
299 virtual uint64_t getItemIndexForTimeStamp(std::chrono::nanoseconds time_stamp) = 0;
300
313 virtual uint64_t getItemIndexForStreamItemIndex(uint16_t stream_id, uint64_t stream_item_index) = 0;
314
326 virtual std::shared_ptr<const StreamType> getStreamTypeBefore(uint64_t item_index, uint16_t stream_id) = 0;
327
337 virtual void seekTo(uint64_t item_index) = 0;
338};
339
345{
346};
347
351class ReaderFactory : public Object
352{
353public:
358 virtual std::shared_ptr<Reader> makeReader() const = 0;
359};
360
365template<typename T>
367{
368public:
373 std::shared_ptr<adtf_file::Reader> makeReader() const override
374 {
375 return std::make_shared<T>();
376 }
377};
378
383{
384public:
389 void add(const std::shared_ptr<const adtf_file::ReaderFactory>& factory);
390
395 void remove(const std::string& reader_id);
396
404 std::shared_ptr<adtf_file::Reader> makeReader(const std::string& reader_id) const;
405
422 std::shared_ptr<adtf_file::Reader>
423 openReader(const std::string& filename,
424 const adtf_file::Configuration& configuration = {},
425 std::shared_ptr<adtf_file::SampleFactory> sample_factory = {},
426 std::shared_ptr<adtf_file::StreamTypeFactory> stream_type_factory = {},
427 std::optional<std::string> reader_id = {}) const;
428
442 void getCapableReaders(const std::string& filename,
443 const std::function<bool(const std::shared_ptr<Reader>&)>& capable_reader_callback,
444 const adtf_file::Configuration& configuration = {},
445 std::shared_ptr<adtf_file::SampleFactory> sample_factory = {},
446 std::shared_ptr<adtf_file::StreamTypeFactory> stream_type_factory = {}) const;
447
452 const std::unordered_map<std::string, std::shared_ptr<const ReaderFactory>>& getFactories() const;
453
454private:
455 std::unordered_map<std::string, std::shared_ptr<const ReaderFactory>> _factories;
456};
457
464Stream findStream(const Reader& reader, const std::string& stream_name);
465
471std::chrono::nanoseconds getFirstTimeOfStreams(const std::vector<Stream>& streams);
472
478std::chrono::nanoseconds getLastTimeOfStreams(const std::vector<Stream>& streams);
479
485} // namespace adtf_file
Definition configuration.h:448
Definition reader.h:345
Extension class for file extension. These extension are i.e.:
Definition reader.h:72
uint32_t user_id
the user id (if needed)
Definition reader.h:79
uint32_t type_id
the type id (if needed)
Definition reader.h:81
const void * data
reference pointer to the data of the extension
Definition reader.h:87
std::string name
the name of the extension
Definition reader.h:75
uint32_t version_id
the version id (if needed)
Definition reader.h:83
uint16_t stream_id
the stream id the extension belongs to
Definition reader.h:77
size_t data_size
the extension size in bytes
Definition reader.h:85
class to create or read a file item. This file item is either a sample, streamtype or trigger.
Definition reader.h:172
std::shared_ptr< const StreamItem > stream_item
Definition reader.h:180
std::chrono::nanoseconds time_stamp
time stamp of the file item
Definition reader.h:177
uint16_t stream_id
stream id the file items belongs to
Definition reader.h:175
base interface class for all available objects of the ADTF File Library that can be added to the obje...
Definition object.h:38
Definition reader.h:383
std::shared_ptr< adtf_file::Reader > openReader(const std::string &filename, const adtf_file::Configuration &configuration={}, std::shared_ptr< adtf_file::SampleFactory > sample_factory={}, std::shared_ptr< adtf_file::StreamTypeFactory > stream_type_factory={}, std::optional< std::string > reader_id={}) const
Creates an instance for the given reader_id, sets the given configuration and opens the reader with g...
const std::unordered_map< std::string, std::shared_ptr< const ReaderFactory > > & getFactories() const
Get the Factories.
void remove(const std::string &reader_id)
std::shared_ptr< adtf_file::Reader > makeReader(const std::string &reader_id) const
create an instance for the given reader_id
void add(const std::shared_ptr< const adtf_file::ReaderFactory > &factory)
void getCapableReaders(const std::string &filename, const std::function< bool(const std::shared_ptr< Reader > &)> &capable_reader_callback, const adtf_file::Configuration &configuration={}, std::shared_ptr< adtf_file::SampleFactory > sample_factory={}, std::shared_ptr< adtf_file::StreamTypeFactory > stream_type_factory={}) const
Get all capable readers can open the given file (filename). It will make and open all capable Reader ...
Default Reader factory implementation for readers using a standard default CTOR.
Definition reader.h:367
std::shared_ptr< adtf_file::Reader > makeReader() const override
make a reader T.
Definition reader.h:373
Reader Factory interface to create a reader.
Definition reader.h:352
virtual std::shared_ptr< Reader > makeReader() const =0
Creates a reader.
Definition reader.h:189
virtual std::string getDescription() const
Definition reader.h:240
virtual std::vector< Stream > getStreams() const
Get the Streams.
Definition reader.h:258
virtual uint32_t getFileVersion() const
Definition reader.h:232
virtual std::string getReaderIdentifier() const =0
Get the Reader Identifier of the Reader.
virtual std::vector< Extension > getExtensions() const
Get the Extensions if any.
Definition reader.h:249
virtual std::optional< double > getProgress() const
Get the Progress, a relative file position between 0.0 and 1.0.
Definition reader.h:278
virtual FileItem getNextItem()=0
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...
virtual std::optional< uint64_t > getItemCount() const
Get the Item Count. This gets the overall count of all items (samples, stream types and triggers) of ...
Definition reader.h:269
Base class for a sample factory to create sample used by the Reader.
Definition reader.h:121
virtual std::shared_ptr< Sample > build() const =0
Creates a sample.
Interface for seekable Reader, where the file position can be adapted.
Definition reader.h:288
virtual uint64_t getItemIndexForStreamItemIndex(uint16_t stream_id, uint64_t stream_item_index)=0
virtual void seekTo(uint64_t item_index)=0
virtual uint64_t getItemIndexForTimeStamp(std::chrono::nanoseconds time_stamp)=0
virtual std::shared_ptr< const StreamType > getStreamTypeBefore(uint64_t item_index, uint16_t stream_id)=0
Base class for a streamtype factory to create streamtypes used by the Reader.
Definition reader.h:94
virtual std::shared_ptr< StreamType > build() const =0
Creates a streamtype.
class to create and describe a stream within a adtf_file::Reader. Each stream has an identifier strea...
Definition reader.h:150
uint64_t item_count
the amount of stream items within the stream
Definition reader.h:157
std::string name
the stream name
Definition reader.h:155
std::chrono::nanoseconds timestamp_of_first_item
time stamp of the first stream item within the stream
Definition reader.h:159
uint16_t stream_id
the stream id
Definition reader.h:153
std::chrono::nanoseconds timestamp_of_last_item
time stamp of the last stream item within the stream
Definition reader.h:161
std::shared_ptr< const StreamType > initial_type
the initial stream type of the stream
Definition reader.h:163
SeekingNotSupported()
default CTOR
Definition reader.h:54
template class for a sample factory to create sample with implementation type SAMPLE_CLASS
Definition reader.h:136
std::shared_ptr< Sample > build() const override
Creates a sample.
Definition reader.h:138
template class for a streamtype factory to create streamtypes with implementation type STREAM_TYPE_CL...
Definition reader.h:109
std::shared_ptr< StreamType > build() const override
Creates a streamtype.
Definition reader.h:111
namespace for exceptions
Definition reader.h:39
namespace for ADTF File library
Definition adtf2_adtf_core_media_sample_deserializer.h:25
std::chrono::nanoseconds getLastTimeOfStreams(const std::vector< Stream > &streams)
Get the Last Time Of the given Streams.
Stream findStream(const Reader &reader, const std::string &stream_name)
std::chrono::nanoseconds getFirstTimeOfStreams(const std::vector< Stream > &streams)
Get the First Time Of the given Streams.
ReaderFactories getReaderFactories()
Get the Reader Factories from the Objects instance.
std::unordered_map< std::string, PropertyValue > Configuration
Configuration class as set of key - property value pairs This configuration is used to adjust the rea...
Definition configuration.h:132
utils5ext::exceptions::EndOfFile EndOfFile
Exception to indicate the end of file was reached.
Definition indexedfile_types.h:114