17 #ifndef ADTF_FILE_FILE_WRITER_INCLUDED
18 #define ADTF_FILE_FILE_WRITER_INCLUDED
23 #include <unordered_map>
46 virtual void write(
const void* data,
size_t data_size) = 0;
57 static_assert(std::is_trivially_copyable<T>::value,
"Only trivially copyable types and std::string are allowed. Alternatively, provide a specialization for adtf_file::OutputStream& operator<<(T& value).");
58 write(&value,
sizeof(T));
114 void add(
const std::shared_ptr<StreamTypeSerializer>& serializer)
116 emplace(serializer->getMetaType(), serializer);
129 auto serializer = find(property_type.getMetaType());
130 if (serializer == end())
133 serializer = find(
"");
134 if (serializer == end())
136 throw std::runtime_error(
"No serializer for stream type " + property_type.getMetaType());
140 serializer->second->serialize(stream_type, stream);
152 auto serializer = find(property_type.getMetaType());
153 if (serializer != end())
155 auto adtf2_serializer = std::dynamic_pointer_cast<ADTF2StreamTypeSerializer>(serializer->second);
156 if (adtf2_serializer)
158 return adtf2_serializer->getTypeId();
177 virtual std::string
getId()
const = 0;
202 virtual std::string
getId()
const = 0;
207 virtual std::shared_ptr<SampleSerializer>
build()
const = 0;
214 template <
typename SERIALIZER>
220 return SERIALIZER::id;
223 std::shared_ptr<SampleSerializer>
build()
const override
225 return std::make_shared<SERIALIZER>();
240 void add(
const std::shared_ptr<SampleSerializerFactory>& serializer_factory)
242 emplace(serializer_factory->getId(), serializer_factory);
251 std::shared_ptr<SampleSerializer>
build(
const std::string&
id)
const
255 return at(
id)->build();
259 throw std::runtime_error(
"no sample serializer factory with id '" +
id +
"' available");
265 class CompatIndexedFileWriter;
274 class Buffer:
public std::vector<uint8_t>,
public OutputStream
278 void write(
const void* data,
size_t data_size)
override
280 this->insert(end(),
static_cast<const uint8_t*
>(data),
static_cast<const uint8_t*
>(data) + data_size);
284 class Chunk:
public Buffer
288 std::chrono::nanoseconds time_stamp;
292 void reset(
size_t stream_id_to_set,
293 std::chrono::nanoseconds time_stamp_to_set,
294 uint32_t flags_to_set)
296 this->stream_id = stream_id_to_set;
297 this->time_stamp = time_stamp_to_set;
298 this->flags = flags_to_set;
343 std::chrono::nanoseconds history_duration,
346 uint32_t writer_flags = 0);
364 const std::shared_ptr<SampleSerializer>& serializer);
371 void write(
size_t stream_id, std::chrono::nanoseconds time_stamp,
const StreamType& type);
378 void write(
size_t stream_id, std::chrono::nanoseconds time_stamp,
const WriteSample& sample);
384 void writeTrigger(
size_t stream_id, std::chrono::nanoseconds time_stamp);
402 uint32_t file_version_id);
409 void onChunkDropped(uint64_t index, uint16_t stream_id, uint16_t flags, timestamp_t time_stamp)
override;
411 const Chunk& serialize(
size_t stream_id, std::chrono::nanoseconds time_stamp,
const StreamType& type);
412 const Chunk& serialize(
size_t stream_id, std::chrono::nanoseconds time_stamp,
const WriteSample& sample);
413 const Chunk& serializeTrigger(
size_t stream_id, std::chrono::nanoseconds time_stamp);
415 void write(
const Chunk& chunk);
421 std::unique_ptr<CompatIndexedFileWriter> _file;
424 size_t _stream_id_counter = 0;
425 bool _history_active;
426 bool _lock_chunk_write;
432 std::string adtf2_initial_type_id;
433 std::shared_ptr<SampleSerializer> sample_serializer;
434 std::list<Buffer> type_queue;
436 bool has_samples =
false;
439 std::vector<Stream> _streams;
440 std::weak_ptr<OutputStream> _last_extension_stream;
ADTF2 stream type serializer interface class to write ADTF 2 stream types.
Definition: adtf_file_writer.h:94
virtual std::string getTypeId() const =0
Get the Type Id of the serializer.
Default ADTF DAT File Writer to write an ADTF DAT File (IFHD file with ADTF type and sample content).
Definition: adtf_file_writer.h:272
size_t createStream(const std::string &name, const StreamType &initial_type, const std::shared_ptr< SampleSerializer > &serializer)
Create a Stream and retrieve the stream id for it.
void write(size_t stream_id, std::chrono::nanoseconds time_stamp, const WriteSample &sample)
Writes a sample to the file or the history.
void setFileDescription(const std::string &description)
Set the File Description.
void quitHistory()
quits the history.
ADTFDatFileWriter(const std::string &file_name, std::chrono::nanoseconds history_duration, StreamTypeSerializers type_serializers, TargetADTFVersion target_adtf_version=adtf3ns, uint32_t writer_flags=0)
CTOR for a new ADTF file for writing.
void writeTrigger(size_t stream_id, std::chrono::nanoseconds time_stamp)
Writes a trigger to the file or the history.
TargetADTFVersion
Target Verion of the ADTF file to write.
Definition: adtf_file_writer.h:309
@ adtf3ns
target version is ADTF 3 file, ontaining samples, triggers and stream types with nanosecond resolutio...
Definition: adtf_file_writer.h:324
@ adtf3
target version is ADTF 3 file, containing samples, triggers and stream types.
Definition: adtf_file_writer.h:319
@ adtf2
target version is ADTF 2 file, containing samples only.
Definition: adtf_file_writer.h:314
void write(size_t stream_id, std::chrono::nanoseconds time_stamp, const StreamType &type)
Writes a type to the file or the history.
std::shared_ptr< OutputStream > getExtensionStream(const std::string &name, uint32_t user_id, uint32_t type_id, uint32_t file_version_id)
Creates and gets a extension stream to write information into an extension.
ADTFDatFileWriter(ADTFDatFileWriter &&)=default
move CTOR
base interface class for all available objects of the ADTF File Library that can be added to the obje...
Definition: object.h:33
Interface class for an output stream.
Definition: adtf_file_writer.h:39
virtual void write(const void *data, size_t data_size)=0
Writes the data to the output stream.
OutputStream & operator<<(const T &value)
template operator to write a standard layout type to the output stream
Definition: adtf_file_writer.h:55
The default interface class for stream types.
Definition: stream_type.h:32
Container class for SampleSerializerFactory.
Definition: adtf_file_writer.h:233
void add(const std::shared_ptr< SampleSerializerFactory > &serializer_factory)
Adds a SampleSerializerFactory instance to the container.
Definition: adtf_file_writer.h:240
std::shared_ptr< SampleSerializer > build(const std::string &id) const
Create an instance of a SampleSerializer for the given id.
Definition: adtf_file_writer.h:251
interface class for sample serializer
Definition: adtf_file_writer.h:196
virtual std::string getId() const =0
Get the id of the serializer.
virtual std::shared_ptr< SampleSerializer > build() const =0
Create an instance of a SampleSerializer.
Interface class for a sample serializer. Usually the implementaion has a serialization state dependin...
Definition: adtf_file_writer.h:171
virtual void serialize(const WriteSample &sample, OutputStream &stream)=0
Serializes the sample into the given stream. These samples usually are described by the previous set ...
virtual void setStreamType(const StreamType &stream_type)=0
Set the Stream Type and the serialization state of the serializer.
virtual std::string getId() const =0
Get the Id of the sample serializer.
interface class for stream type serializers.
Definition: adtf_file_writer.h:75
virtual std::string getMetaType() const =0
Get the Meta Type name for which the serializer serializes stream types.
virtual void serialize(const StreamType &stream_type, OutputStream &stream) const =0
serializes the given stream type into the output stream
Container class for StreamTypeSerializer.
Definition: adtf_file_writer.h:107
void add(const std::shared_ptr< StreamTypeSerializer > &serializer)
Adds a StreamTypeSerializer instance to the container.
Definition: adtf_file_writer.h:114
std::string getAdtf2TypeId(const StreamType &stream_type)
Get the ADTF 2 type id of the stream_type.
Definition: adtf_file_writer.h:149
void serialize(const StreamType &stream_type, OutputStream &stream) const
Serialzes the given stream type into the given stream. It will use the StreamTypeSerializer supportin...
Definition: adtf_file_writer.h:126
Stream Type base class.
Definition: stream_item.h:43
Interface class for samples that are written.
Definition: sample.h:114
default implementation template for SampleSerializerFactory to create an instance of the serialzer ty...
Definition: adtf_file_writer.h:216
std::string getId() const override
Get the id of the serializer.
Definition: adtf_file_writer.h:218
std::shared_ptr< SampleSerializer > build() const override
Create an instance of a SampleSerializer.
Definition: adtf_file_writer.h:223
namespace for ADTF File library
Definition: adtf2_adtf_core_media_sample_deserializer.h:25