VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::BagReader类 参考abstract

Abstract VLink bag file player with time control, seeking, and integrity tools. 更多...

#include <bag_reader.h>

类 vlink::BagReader 继承关系图:
vlink::BagReader 的协作图:

struct  Info
 Metadata extracted from the bag file header and index. 更多...
struct  Config
 Playback configuration passed to play(). 更多...

Public 类型

enum  Status : uint8_t { kStoped = 0 , kPaused = 1 , kPlaying = 2 }
 Playback state of the reader. 更多...
using OutputCallback
 Callback type fired for each replayed message.
using StatusCallback = std::function<void(Status status)>
 Callback fired whenever the playback Status changes.
using ReadyCallback = std::function<void()>
 Callback fired when the reader has opened the file and is ready to start playing.
using FinishCallback = std::function<void(bool is_interrupted)>
 Callback fired when playback has finished (or was interrupted).
 Queue implementation type. 更多...
 Idle strategy controlling CPU and latency trade-offs. 更多...
 Pre-defined task priority levels for kPriorityType loops. 更多...

Public 成员函数

 BagReader (const std::string &path, bool read_only=true, bool try_to_fix=false)
 Constructs the reader for path.
virtual ~BagReader ()
 Destructor – stops playback and releases file resources.
virtual void bind_plugin_interface (const std::shared_ptr< BagReaderPluginInterface > &plugin_interface)
 Attaches a BagReaderPluginInterface for custom URL/type conversion.
virtual void register_status_callback (StatusCallback &&status_callback)
 Registers a callback fired whenever the playback status changes.
virtual void register_ready_callback (ReadyCallback &&ready_callback)
 Registers a callback fired when the reader is ready to start playing.
virtual void register_finish_callback (FinishCallback &&finish_callback)
 Registers a callback fired when playback ends or is interrupted.
virtual void register_output_callback (OutputCallback &&output_callback)
 Registers the callback that receives replayed messages.
virtual void play (const Config &config)=0
 Starts playback with the given config.
virtual void stop ()=0
 Stops playback and resets the reader to the beginning.
virtual void pause ()=0
 Pauses playback at the current position.
virtual void resume ()=0
 Resumes a paused playback from the current position.
virtual void pause_to_next ()=0
 Advances one message while paused, then pauses again.
virtual void jump (int64_t begin_time, double rate, int times, bool force_to_play=false)=0
 Seeks to begin_time and resumes playback at rate with times loops.
virtual std::future< bool > check ()=0
 Verifies the integrity of the bag file asynchronously.
virtual std::future< bool > reindex ()=0
 Rebuilds the index tables asynchronously.
virtual std::future< bool > fix (bool rebuild=false)=0
 Repairs a corrupt bag file asynchronously.
virtual void tag (const std::string &tag_name)=0
 Updates the tag name stored in the bag's metadata.
virtual int64_t get_timestamp () const =0
 Returns the current playback position as a recording timestamp.
virtual int64_t get_real_timestamp () const =0
 Returns the current playback position in real elapsed time.
virtual Status get_status () const =0
 Returns the current playback status.
virtual const Infoget_info () const =0
 Returns the bag file metadata and per-URL statistics.
virtual std::vector< SchemaDatadetect_schema ()=0
 Scans the bag and returns all embedded schemas.
virtual std::string get_ser_type (const std::string &url) const =0
 Returns the serialisation type string for a given url.
virtual SchemaType get_schema_type (const std::string &url) const =0
 Returns the coarse schema family for a given url.
virtual bool is_split_mode () const =0
 Returns true if the bag spans multiple split files.
virtual int get_split_index () const =0
 Returns the zero-based index of the current split file being read.
virtual bool is_jumping () const =0
 Returns true if a jump-to-timestamp seek is currently in progress.

静态 Public 成员函数

static std::shared_ptr< BagReadercreate (const std::string &path, bool read_only=true, bool try_to_fix=false)
 Creates a concrete BagReader for path, selecting the implementation by extension.

静态 Public 属性

static constexpr int kInfinite {-1}
 Sentinel value for the Config::times field to indicate endless loop playback.

Protected 成员函数

void process_output (int64_t timestamp, const std::string &url, ActionType action_type, const Bytes &data)
void process_url_metas (std::vector< Info::UrlMeta > &url_metas)

静态 Protected 成员函数

static void rebuild_url_meta_maps (const std::vector< Info::UrlMeta > &url_metas, std::unordered_map< std::string, std::string > &ser_map, std::unordered_map< std::string, SchemaType > &schema_type_map)
 Rebuilds URL metadata lookup maps after plugin remapping.
static ActionType convert_action (std::string_view str)

详细描述

Abstract VLink bag file player with time control, seeking, and integrity tools.

Inherits MessageLoop to drive playback on a dedicated thread. Concrete subclasses (DatabaseReader, McapReader) implement format-specific I/O.

成员类型定义说明

◆ FinishCallback

using vlink::BagReader::FinishCallback = std::function<void(bool is_interrupted)>

Callback fired when playback has finished (or was interrupted).

参数
is_interruptedtrue if stop() was called before natural end.

◆ OutputCallback

初始值:
std::function<void(int64_t microseconds_timestamp, const std::string& url,
ActionType action_type, const Bytes& data)>

Callback type fired for each replayed message.

Called on the BagReader's loop thread. The data reference is valid only for the duration of the callback.

参数
microseconds_timestampMessage timestamp in microseconds.
urlTopic URL string.
action_typeAction type (kPublish, kRequest, etc.).
dataSerialized message payload.

◆ ReadyCallback

using vlink::BagReader::ReadyCallback = std::function<void()>

Callback fired when the reader has opened the file and is ready to start playing.

◆ StatusCallback

using vlink::BagReader::StatusCallback = std::function<void(Status status)>

Callback fired whenever the playback Status changes.

参数
statusNew playback status.

成员枚举类型说明

◆ Status

enum vlink::BagReader::Status : uint8_t

Playback state of the reader.

State Description
kStopped Not playing; reset to beginning
kPaused Playback suspended; can be resumed
kPlaying Actively delivering messages to the callback
枚举值
kStoped 

Stopped (not playing).

kPaused 

Paused mid-playback.

kPlaying 

Actively playing.

构造及析构函数说明

◆ BagReader()

vlink::BagReader::BagReader ( const std::string & path,
bool read_only = true,
bool try_to_fix = false )
explicit

Constructs the reader for path.

参数
pathPath to the bag file.
read_onlyOpen in read-only mode.
try_to_fixAttempt repair if the file is corrupt.
这是这个函数的调用关系图:

◆ ~BagReader()

virtual vlink::BagReader::~BagReader ( )
virtual

Destructor – stops playback and releases file resources.

成员函数说明

◆ bind_plugin_interface()

virtual void vlink::BagReader::bind_plugin_interface ( const std::shared_ptr< BagReaderPluginInterface > & plugin_interface)
virtual

Attaches a BagReaderPluginInterface for custom URL/type conversion.

The plugin's convert_url_meta() is called for each URL in the bag to allow remapping before messages are dispatched to OutputCallback.

参数
plugin_interfacePlugin to bind. May be nullptr to detach.

vlink::DatabaseReader , 以及 vlink::McapReader 重载.

◆ check()

virtual std::future< bool > vlink::BagReader::check ( )
pure virtual

Verifies the integrity of the bag file asynchronously.

返回
std::future<bool> that resolves to true if the file is intact.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ convert_action()

ActionType vlink::BagReader::convert_action ( std::string_view str)
staticprotected
函数调用图:

◆ create()

std::shared_ptr< BagReader > vlink::BagReader::create ( const std::string & path,
bool read_only = true,
bool try_to_fix = false )
staticnodiscard

Creates a concrete BagReader for path, selecting the implementation by extension.

参数
pathPath to the bag file.
read_onlyIf true, open in read-only mode (no write operations).
try_to_fixIf true, attempt to repair a corrupt bag on open.
返回
Shared pointer to the new reader.

◆ detect_schema()

virtual std::vector< SchemaData > vlink::BagReader::detect_schema ( )
nodiscardpure virtual

Scans the bag and returns all embedded schemas.

返回
Vector of SchemaData descriptors found in the bag.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ fix()

virtual std::future< bool > vlink::BagReader::fix ( bool rebuild = false)
pure virtual

Repairs a corrupt bag file asynchronously.

参数
rebuildIf true, rebuilds the entire index from scratch.
返回
std::future<bool> that resolves to true if repair succeeded.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ get_info()

virtual const Info & vlink::BagReader::get_info ( ) const
nodiscardpure virtual

Returns the bag file metadata and per-URL statistics.

返回
Const reference to the Info struct populated at open time.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ get_real_timestamp()

virtual int64_t vlink::BagReader::get_real_timestamp ( ) const
nodiscardpure virtual

Returns the current playback position in real elapsed time.

返回
Elapsed time since playback started (milliseconds).

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ get_schema_type()

virtual SchemaType vlink::BagReader::get_schema_type ( const std::string & url) const
nodiscardpure virtual

Returns the coarse schema family for a given url.

参数
urlTopic URL to look up.
返回
Schema family, or SchemaType::kUnknown if unavailable.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ get_ser_type()

virtual std::string vlink::BagReader::get_ser_type ( const std::string & url) const
nodiscardpure virtual

Returns the serialisation type string for a given url.

参数
urlTopic URL to look up.
返回
Serialisation type (e.g., "demo.proto.PointCloud"), or an empty string if unknown.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ get_split_index()

virtual int vlink::BagReader::get_split_index ( ) const
nodiscardpure virtual

Returns the zero-based index of the current split file being read.

返回
Current split file index, or 0 for single-file bags.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ get_status()

virtual Status vlink::BagReader::get_status ( ) const
nodiscardpure virtual

Returns the current playback status.

返回
One of kStopped, kPaused, or kPlaying.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ get_timestamp()

virtual int64_t vlink::BagReader::get_timestamp ( ) const
nodiscardpure virtual

Returns the current playback position as a recording timestamp.

返回
Current message timestamp in milliseconds (recording time, relative to start).

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ is_jumping()

virtual bool vlink::BagReader::is_jumping ( ) const
nodiscardpure virtual

Returns true if a jump-to-timestamp seek is currently in progress.

返回
true while seeking.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ is_split_mode()

virtual bool vlink::BagReader::is_split_mode ( ) const
nodiscardpure virtual

Returns true if the bag spans multiple split files.

返回
true when reading a split bag.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ jump()

virtual void vlink::BagReader::jump ( int64_t begin_time,
double rate,
int times,
bool force_to_play = false )
pure virtual

Seeks to begin_time and resumes playback at rate with times loops.

参数
begin_timeSeek target timestamp in milliseconds (relative to recording start).
rateNew playback rate multiplier.
timesNumber of loops after the jump.
force_to_playIf true, forces play state even if currently paused.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ pause()

virtual void vlink::BagReader::pause ( )
pure virtual

Pauses playback at the current position.

Transitions from kPlaying to kPaused.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ pause_to_next()

virtual void vlink::BagReader::pause_to_next ( )
pure virtual

Advances one message while paused, then pauses again.

Useful for single-stepping through a bag in debug sessions.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ play()

virtual void vlink::BagReader::play ( const Config & config)
pure virtual

Starts playback with the given config.

Must be called after async_run(). The reader transitions to kPlaying.

参数
configPlayback configuration.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ process_output()

void vlink::BagReader::process_output ( int64_t timestamp,
const std::string & url,
ActionType action_type,
const Bytes & data )
protected

◆ process_url_metas()

void vlink::BagReader::process_url_metas ( std::vector< Info::UrlMeta > & url_metas)
protected

◆ rebuild_url_meta_maps()

void vlink::BagReader::rebuild_url_meta_maps ( const std::vector< Info::UrlMeta > & url_metas,
std::unordered_map< std::string, std::string > & ser_map,
std::unordered_map< std::string, SchemaType > & schema_type_map )
staticprotected

Rebuilds URL metadata lookup maps after plugin remapping.

Reader implementations call this after process_url_metas() mutates the per-URL metadata list, ensuring get_ser_type() and get_schema_type() both observe the remapped metadata instead of stale pre-plugin entries.

参数
url_metasRemapped URL metadata list.
ser_mapOutput lookup map: URL -> serialisation type.
schema_type_mapOutput lookup map: URL -> coarse schema family.

◆ register_finish_callback()

virtual void vlink::BagReader::register_finish_callback ( FinishCallback && finish_callback)
virtual

Registers a callback fired when playback ends or is interrupted.

参数
finish_callbackCallback receiving is_interrupted flag.

vlink::DatabaseReader , 以及 vlink::McapReader 重载.

◆ register_output_callback()

virtual void vlink::BagReader::register_output_callback ( OutputCallback && output_callback)
virtual

Registers the callback that receives replayed messages.

参数
output_callbackCalled for each message during playback.

vlink::DatabaseReader , 以及 vlink::McapReader 重载.

◆ register_ready_callback()

virtual void vlink::BagReader::register_ready_callback ( ReadyCallback && ready_callback)
virtual

Registers a callback fired when the reader is ready to start playing.

参数
ready_callbackCallback invoked once the file is open and parsed.

vlink::DatabaseReader , 以及 vlink::McapReader 重载.

◆ register_status_callback()

virtual void vlink::BagReader::register_status_callback ( StatusCallback && status_callback)
virtual

Registers a callback fired whenever the playback status changes.

参数
status_callbackCallback receiving the new Status value.

vlink::DatabaseReader , 以及 vlink::McapReader 重载.

◆ reindex()

virtual std::future< bool > vlink::BagReader::reindex ( )
pure virtual

Rebuilds the index tables asynchronously.

返回
std::future<bool> that resolves to true on success.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ resume()

virtual void vlink::BagReader::resume ( )
pure virtual

Resumes a paused playback from the current position.

Transitions from kPaused to kPlaying.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ stop()

virtual void vlink::BagReader::stop ( )
pure virtual

Stops playback and resets the reader to the beginning.

Transitions the reader to kStopped. The FinishCallback is fired with is_interrupted = true.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

◆ tag()

virtual void vlink::BagReader::tag ( const std::string & tag_name)
pure virtual

Updates the tag name stored in the bag's metadata.

参数
tag_nameNew tag name string.

vlink::DatabaseReader , 以及 vlink::McapReader 内被实现.

类成员变量说明

◆ kInfinite

int vlink::BagReader::kInfinite {-1}
staticconstexpr

Sentinel value for the Config::times field to indicate endless loop playback.


该类的文档由以下文件生成: