Class AsyncWriter

Nested Relationships

Nested Types

Class Documentation

class AsyncWriter

OSF AsyncWriter wraps osf::Writer so that saving occurs in a background thread.

Calls to save() return a std::future<void> instead of void to enable propagating exceptions from the save thread.

Public Functions

AsyncWriter(const std::string &filename, const std::vector<ouster::sdk::core::SensorInfo> &info, const std::vector<std::string> &fields_to_write = std::vector<std::string>(), uint32_t chunk_size = 0, std::shared_ptr<Encoder> encoder = nullptr)
Parameters:
  • filename[in] The filename to output to.

  • info[in] The sensor info vector to use for a multi stream OSF file.

  • fields_to_write[in] The fields from frames to actually save into the OSF. If not provided uses the fields from the first saved lidar frame for this sensor. This parameter is optional.

  • chunk_size[in] The chunksize to use for the OSF file, this parameter is optional.

  • encoder[in] An optional Encoder instance for configuring how the Writer should encode the OSF.

~AsyncWriter()

Closes the writer and finalizes any pending writes.

std::future<void> save(uint32_t stream_index, const ouster::sdk::core::LidarFrame &frame)

Save a single frame to the specified stream_index in an OSF file.

The concept of the stream_index is related to the sensor_info vector. Consider the following:

SensorInfo info1; // The first sensor in this OSF file
SensorInfo info2; // The second sensor in this OSF file
SensorInfo info3; // The third sensor in this OSF file

Writer output = Writer(filename, {info1, info2, info3});

LidarFrame frame = RANDOM_FRAME_HERE;

// To save the LidarFrame to the first sensor, you would do the
// following
output.save(0, frame);

// To save the LidarFrame to the second sensor, you would do the
// following
output.save(1, frame);

// To save the LidarFrame to the third sensor, you would do the
// following
output.save(2, frame);

Throws:
  • std::logic_error – Will throw exception on writer being closed.

  • std::logic_error – ///< Will throw exception on ///< out of bound stream_index.

Parameters:
  • stream_index[in] The index of the corrosponding SensorInfo to use.

  • frame[in] The frame to save.

Returns:

a future, which can propagate exceptions that may have occurred in the background from the save thread.

std::future<void> save(uint32_t stream_index, const ouster::sdk::core::LidarFrame &frame, ouster::sdk::osf::ts_t timestamp)

Save a single frame with the specified timestamp to the specified stream_index in an OSF file.

Throws:
  • std::logic_error – Will throw exception on writer being closed.

  • std::logic_error – ///< Will throw exception on ///< out of bound stream_index.

Parameters:
  • stream_index[in] The index of the corrosponding SensorInfo to use.

  • frame[in] The frame to save.

  • timestamp[in] Receive timestamp to index this frame with.

Returns:

a future, which can propagate exceptions that may have occurred in the background from the save thread.

std::future<void> save(const ouster::sdk::core::FrameSet &frames)

Save multiple frames to the OSF file.

The concept of the stream_index is related to the SensorInfo vector. Consider the following:

SensorInfo info1; // The first sensor in this OSF file
SensorInfo info2; // The second sensor in this OSF file
SensorInfo info3; // The third sensor in this OSF file

Writer output = Writer(filename, {info1, info2, info3});

std::shared_ptr<LidarFrame> sensor1_frame = RANDOM_FRAME_HERE;
std::shared_ptr<LidarFrame> sensor2_frame = RANDOM_FRAME_HERE;
std::shared_ptr<LidarFrame> sensor3_frame = RANDOM_FRAME_HERE;

FrameSet frame_set{sensor1_frame, sensor2_frame, sensor3_frame};

// To save the frames matched appropriately to their sensors, you would do
// the following
output.save(frame_set);

Throws:
  • std::logic_error – Will throw exception on writer being closed

  • OsfDropFrameError – Will throw exception on missing timestamps

Parameters:

frames[in] FrameSet to save.

Returns:

a future, which can propagate exceptions that may have occurred in the background from the save thread.

void save(const FrameSetSourceMetadataSet &frame_set_source_metadata_set)

Synchronously save a set of frame set source metadata to the OSF file.

Parameters:

frame_set_source_metadata_set[in] The set of metadata entries to save.

void close(bool fsync = false)

Finish file with a proper metadata object, and header.

This method blocks until all remaining tasks generated by save() have been finalized.

Parameters:

fsync[in] If true, force all writes on this file to disk.