|
VLink
2.0.0
A high-performance communication middleware
|
Format-agnostic VLink bag player driven by an internal MessageLoop.
更多...
#include <bag_reader.h>
类 | |
| struct | Config |
Playback parameters consumed by play(). 更多... | |
| struct | Info |
| Aggregated metadata extracted from the bag header, summary and URL index. 更多... | |
Public 类型 | |
| enum | Status : uint8_t { kStopped = 0 , kPaused = 1 , kPlaying = 2 } |
Coarse playback state observable through get_status(). 更多... | |
| using | OutputCallback = FrameCallback |
Callback signature receiving one replayed Frame. 更多... | |
| using | StatusCallback = MoveFunction< void(Status status)> |
Callback fired on every transition of Status. 更多... | |
| using | ReadyCallback = MoveFunction< void()> |
| Callback fired once after the bag has been opened and indexed. 更多... | |
| using | FinishCallback = MoveFunction< void(bool is_interrupted)> |
| Callback fired when the current play session ends. 更多... | |
Public 类型 继承自 vlink::MessageLoop | |
| enum | Type : uint8_t { kNormalType = 0 , kLockfreeType = 1 , kPriorityType = 2 } |
| Internal queue implementation type. 更多... | |
| enum | Strategy : uint8_t { kOptimizationStrategy = 0 , kPopStrategy = 1 , kBlockStrategy = 2 } |
| Back-pressure strategy applied when the bounded queue is at capacity. 更多... | |
| enum | Priority : uint16_t { kNoPriority = 0 , kLowestPriority = 1 , kTimerPriority = 50 , kNormalPriority = 100 , kHighestPriority = std::numeric_limits<uint16_t>::max() } |
Built-in priority levels for kPriorityType loops; higher values dispatch first. 更多... | |
| using | Callback = MoveFunction< void()> |
| Callback type for tasks and event handlers. 更多... | |
Public 成员函数 | |
| BagReader (const std::string &path, bool read_only=true, bool try_to_fix=false) | |
| Constructs the base reader and stores construction-time options. 更多... | |
| virtual | ~BagReader () |
| Stops the loop, closes the file and releases backend resources. 更多... | |
| virtual void | bind_plugin_interface (const std::shared_ptr< BagPluginInterface > &plugin_interface) |
| Attaches a custom URL/type/message rewrite plugin to this reader. 更多... | |
| virtual void | clear_plugin_interface () |
| Detaches the currently bound plugin, if any. 更多... | |
| virtual void | register_status_callback (StatusCallback &&status_callback) |
| Installs a state-change observer. 更多... | |
| virtual void | register_ready_callback (ReadyCallback &&ready_callback) |
| Installs the "open complete" observer. 更多... | |
| virtual void | register_finish_callback (FinishCallback &&finish_callback) |
| Installs the "play session ended" observer. 更多... | |
| virtual void | register_output_callback (OutputCallback &&output_callback) |
| Installs the per-frame data sink. 更多... | |
| bool | open_cursor (const Config &config) |
| Opens (or rewinds) a synchronous sequential read cursor over the bag. 更多... | |
| bool | open_cursor () |
| Opens (or rewinds) a full, unfiltered sequential read cursor over the bag. 更多... | |
| bool | read_next (Frame &out) |
Reads the next frame in recorded order into out. 更多... | |
| BagReader & | operator>> (Frame &out) |
Stream-style alias for read_next(), enabling while (reader >> frame). 更多... | |
| bool | eof () const noexcept |
| Returns whether the cursor has reached the end of the bag. 更多... | |
| bool | fail () const noexcept |
| Returns whether the last cursor operation failed (open or backend read error). 更多... | |
| operator bool () const noexcept | |
| Reports whether the cursor is still in a readable state (not at end, not failed). 更多... | |
| virtual void | play (const Config &config)=0 |
| Starts (or restarts) a play session with the supplied configuration. 更多... | |
| virtual void | stop ()=0 |
| Aborts the active session and rewinds to the start of the bag. 更多... | |
| virtual void | pause ()=0 |
| Suspends frame dispatch while preserving the current position. 更多... | |
| virtual void | resume ()=0 |
| Resumes dispatch from the paused position. 更多... | |
| virtual void | pause_to_next ()=0 |
| Emits exactly one frame from the paused position, then pauses again. 更多... | |
| virtual void | jump (int64_t begin_time, double rate, int times, bool force_to_play=false)=0 |
Seeks playback to begin_time and applies updated rate and loop settings. 更多... | |
| virtual std::future< bool > | check ()=0 |
| Runs an asynchronous integrity verification pass. 更多... | |
| virtual std::future< bool > | reindex ()=0 |
| Rebuilds backend index tables in the background where supported. 更多... | |
| virtual std::future< bool > | fix (bool rebuild=false)=0 |
| Attempts to recover a corrupted bag in the background where supported. 更多... | |
| virtual void | tag (const std::string &tag_name)=0 |
| Overwrites the human-readable tag stored in the bag header. 更多... | |
| virtual int64_t | get_timestamp () const =0 |
| Returns the timestamp targeted by the playback cursor. 更多... | |
| virtual int64_t | get_real_timestamp () const =0 |
| Returns the timestamp of the most recently emitted frame. 更多... | |
| virtual Status | get_status () const =0 |
| Returns the current playback state. 更多... | |
| virtual const Info & | get_info () const =0 |
| Returns the cached header/summary metadata. 更多... | |
| virtual std::vector< SchemaData > | detect_schema ()=0 |
| Scans the bag and collects every embedded schema descriptor. 更多... | |
| virtual std::string | get_ser_type (const std::string &url) const |
Resolves the serialisation type associated with url. 更多... | |
| virtual SchemaType | get_schema_type (const std::string &url) const |
Resolves the schema family associated with url. 更多... | |
| virtual bool | is_split_mode () const =0 |
| Returns whether the opened bag spans multiple split files. 更多... | |
| virtual int | get_split_index () const =0 |
| Returns the zero-based index of the split file currently being consumed. 更多... | |
| virtual bool | is_jumping () const =0 |
Returns whether a jump() seek is still in progress. 更多... | |
Public 成员函数 继承自 vlink::MessageLoop | |
| MessageLoop () | |
Constructs a loop with the default kNormalType queue. 更多... | |
| MessageLoop (Type type) | |
| Constructs a loop with the given queue type. 更多... | |
| virtual | ~MessageLoop () |
| Destructor; requests quit and joins the dispatcher thread if needed. 更多... | |
| void | set_name (const std::string &name) |
| Sets a human-readable name visible to profiling tools. 更多... | |
| const std::string & | get_name () const |
Returns the loop name set via set_name. 更多... | |
| Type | get_type () const |
| Returns the queue type this loop was constructed with. 更多... | |
| Strategy | get_strategy () const |
| Returns the active back-pressure strategy. 更多... | |
| void | set_strategy (Strategy strategy) |
| Replaces the back-pressure strategy. 更多... | |
| void | register_begin_handler (Callback &&callback) |
| Registers a callback fired once at loop thread startup. 更多... | |
| void | register_end_handler (Callback &&callback) |
| Registers a callback fired once when the loop thread exits. 更多... | |
| void | register_idle_handler (Callback &&callback) |
| Registers a callback fired every time the queue becomes empty. 更多... | |
| bool | run () |
Runs the loop on the calling thread until quit is requested. 更多... | |
| bool | async_run () |
| Starts the loop on a new background thread. 更多... | |
| bool | spin () |
Alias of run blocking the calling thread. 更多... | |
| bool | spin_once (bool block=true) |
| Processes one batch of pending tasks and timers on the calling thread. 更多... | |
| bool | quit (bool force=false) |
| Requests the loop to exit. 更多... | |
| bool | wait_for_quit (int ms=Timer::kInfinite, bool check=true) |
| Waits until the loop has fully exited. 更多... | |
| bool | post_task (Callback &&callback) |
| Posts a task for execution on the loop thread. 更多... | |
| TaskHandle | post_task_handle (Callback &&callback, const PostTaskOptions &options={}) |
Tracked variant of post_task returning a TaskHandle. 更多... | |
| bool | post_task_with_priority (Callback &&callback, uint16_t priority) |
Posts a task with an explicit priority on a kPriorityType loop. 更多... | |
| TaskHandle | post_task_with_priority_handle (Callback &&callback, uint16_t priority, const PostTaskOptions &options={}) |
Tracked variant of post_task_with_priority returning a TaskHandle. 更多... | |
| template<typename CallbackT , typename = std::enable_if_t<!std::is_convertible_v<CallbackT, Schedule::RetCallback>>> | |
| Schedule::Status | exec_task (const Schedule::Config &config, CallbackT &&callback) |
Schedules a void-returning callable and returns a chainable Schedule::Status. 更多... | |
| template<typename CallbackT , typename = std::enable_if_t<std::is_convertible_v<CallbackT, Schedule::RetCallback>>> | |
| Schedule::RetStatus | exec_task (const Schedule::Config &config, CallbackT &&callback) |
Schedules a bool-returning callable and returns a chainable Schedule::RetStatus. 更多... | |
| bool | wakeup () |
| Wakes the loop thread if it is suspended in its idle wait. 更多... | |
| void | reset_lockfree_capacity () |
| Recreates the lock-free queue, clearing all queued tasks and counters. 更多... | |
| bool | is_running () const |
| Reports whether the loop is currently running. 更多... | |
| bool | is_ready_to_quit () const |
Reports whether quit has been requested and the loop is winding down. 更多... | |
| bool | is_busy () const |
| Reports whether the loop is currently executing a task. 更多... | |
| size_t | get_task_count () const |
| Returns the current pending task count. 更多... | |
| virtual bool | wait_for_idle (int ms=Timer::kInfinite, bool check=true) |
| Waits until the loop has drained its queue and is not executing a task. 更多... | |
| virtual size_t | get_max_task_count () const |
| Returns the maximum queue depth. 更多... | |
| virtual size_t | get_max_timer_count () const |
| Returns the maximum number of timers that can be attached. 更多... | |
| virtual uint32_t | get_max_elapsed_time () const |
| Returns the maximum allowed task execution time in milliseconds. 更多... | |
| virtual bool | is_in_same_thread () const |
| Reports whether the calling thread is owned by this loop. 更多... | |
| std::shared_ptr< AliveState > | get_alive_state () const |
| Returns the shared lifetime flag used by cross-thread bridges. 更多... | |
| template<class FunctionT , class... ArgsT, typename ResultT = std::invoke_result_t<FunctionT, ArgsT...>> | |
| std::future< ResultT > | invoke_task (FunctionT &&function, ArgsT &&... args) |
Dispatches a callable to the loop thread and returns a std::future for the result. 更多... | |
| template<class FunctionT , class... ArgsT, typename ResultT = std::invoke_result_t<FunctionT, ArgsT...>> | |
| std::future< ResultT > | invoke_task_with_priority (FunctionT &&function, uint16_t priority, ArgsT &&... args) |
Priority variant of invoke_task; requires a kPriorityType loop. 更多... | |
静态 Public 成员函数 | |
| static std::shared_ptr< BagReader > | create (const std::string &path, bool read_only=true, bool try_to_fix=false) |
Builds the concrete reader matching the extension of path. 更多... | |
静态 Public 属性 | |
| static constexpr int | kInfinite {-1} |
Sentinel for Config::times that requests endless loop playback. 更多... | |
Protected 成员函数 | |
| virtual bool | do_open_cursor (const Config &config) |
| virtual bool | do_read_next (Frame &out, bool &is_error) |
| void | process_output (Frame &frame) |
| void | fill_frame_meta (Frame &frame) const |
| void | flush_plugin () |
| void | process_url_metas (std::vector< Info::UrlMeta > &url_metas) |
| void | rebuild_url_meta_lookup (const std::vector< Info::UrlMeta > &url_metas) |
| std::unordered_map< std::string, std::string > & | url_ser_map () |
| std::unordered_map< std::string, SchemaType > & | url_schema_type_map () |
| bool | convert_playback_url (const std::string &input_url, std::string &output_url) const |
| bool | match_playback_url_filter (std::string_view input_url, const std::unordered_set< std::string > &filter_urls) const |
| void | detach_plugin () |
Protected 成员函数 继承自 vlink::MessageLoop | |
| virtual void | on_begin () |
| Hook invoked once on the loop thread before the first task runs. 更多... | |
| virtual void | on_end () |
| Hook invoked once on the loop thread after the last task runs. 更多... | |
| virtual void | on_idle () |
| Hook invoked on the loop thread each time the queue becomes empty. 更多... | |
| virtual void | on_task_changed (Callback &&callback, uint32_t start_time) |
| Dispatches a ready task on the loop thread. 更多... | |
| virtual void | on_task_timeout (Callback &&callback, uint32_t elapsed_time) |
Hook invoked when a task exceeds get_max_elapsed_time(). 更多... | |
静态 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) |
| static ActionType | convert_action (std::string_view str) |
Format-agnostic VLink bag player driven by an internal MessageLoop.
Inherits MessageLoop so playback runs on a dedicated worker thread. Construction opens the target file and parses its index, but no frames are emitted until async_run() starts the loop and play() supplies a Config. All virtual operations are implemented by VDBReader and VCAPReader; the base class only carries shared plumbing (callback storage, plugin binding, URL filtering helpers).
| using vlink::BagReader::FinishCallback = MoveFunction<void(bool is_interrupted)> |
Callback fired when the current play session ends.
| is_interrupted | True if termination was caused by stop(); false on natural end. |
Callback signature receiving one replayed Frame.
Invoked on the reader's MessageLoop thread. Frame::timestamp is relative to the recording start (microseconds), url is the playback URL, and data is a shallow view valid only for the duration of the call – copy it if it must outlive the callback. Frame::ser_type / schema_type are filled by the reader from the bag's URL metadata, so the frame is fully populated (no separate get_ser_type() / get_schema_type() lookup is required).
Config::begin_time and Config::end_time by 1000 before comparing them against Frame::timestamp. | using vlink::BagReader::ReadyCallback = MoveFunction<void()> |
Callback fired once after the bag has been opened and indexed.
| using vlink::BagReader::StatusCallback = MoveFunction<void(Status status)> |
Callback fired on every transition of Status.
| status | The new playback state. |
| enum vlink::BagReader::Status : uint8_t |
Coarse playback state observable through get_status().
| Value | Meaning |
|---|---|
| kStopped | No active session; position is reset to the start of the bag |
| kPaused | A play session is open but the dispatcher is suspended |
| kPlaying | The dispatcher is actively delivering frames |
| 枚举值 | |
|---|---|
| kStopped | Idle; no playback in progress. |
| kPaused | Playback temporarily suspended; position retained. |
| kPlaying | Actively forwarding frames to the output callback. |
|
explicit |
Constructs the base reader and stores construction-time options.
| path | Bag file path passed to the concrete subclass. |
| read_only | When true, prevents the backend from acquiring write access. |
| try_to_fix | When true, allows the subclass to run recovery while opening. |
|
virtual |
Stops the loop, closes the file and releases backend resources.
|
virtual |
Attaches a custom URL/type/message rewrite plugin to this reader.
The plugin's convert_url_meta() runs once per URL discovered in the bag and may rename topics, override serialisation types or filter URLs out. Its on_read() hook sees every replayed frame before it reaches the user OutputCallback.
| plugin_interface | Plugin instance, or nullptr to detach the current binding. |
nullptr. 被 vlink::VDBReader , 以及 vlink::VCAPReader 重载.
|
pure virtual |
Runs an asynchronous integrity verification pass.
true when the bag is structurally intact. 在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
virtual |
Detaches the currently bound plugin, if any.
Convenience wrapper equivalent to bind_plugin_interface(nullptr): flushes the bound plugin, clears its callback together with the plugin-derived URL remap / exclusion state, and drops the binding. Safe to call when no plugin is bound (in which case it is a no-op).
|
staticprotected |
|
protected |
|
static |
Builds the concrete reader matching the extension of path.
Suffix dispatch: .vdb / .vdbx select VDBReader, .vcap / .vcapx select VCAPReader; any other suffix returns nullptr.
| path | Bag file path on disk. |
| read_only | When true, opens the backend read-only and rejects mutating calls. |
| try_to_fix | When true, allows backends to attempt a recovery pass while opening. |
nullptr for an unknown suffix.
|
protected |
|
pure virtual |
Scans the bag and collects every embedded schema descriptor.
SchemaData entries. 在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
protectedvirtual |
被 vlink::VDBReader , 以及 vlink::VCAPReader 重载.
|
protectedvirtual |
被 vlink::VDBReader , 以及 vlink::VCAPReader 重载.
|
noexcept |
Returns whether the cursor has reached the end of the bag.
|
noexcept |
Returns whether the last cursor operation failed (open or backend read error).
|
protected |
|
pure virtual |
Attempts to recover a corrupted bag in the background where supported.
| rebuild | When true, also forces a full index rebuild. |
true when recovery succeeded. 在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
protected |
|
pure virtual |
Returns the cached header/summary metadata.
Info populated at open time. 在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
pure virtual |
Returns the timestamp of the most recently emitted frame.
在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
virtual |
Resolves the schema family associated with url.
| url | Fully-qualified URL to look up. |
SchemaType, or SchemaType::kUnknown when unavailable.
|
virtual |
Resolves the serialisation type associated with url.
| url | Fully-qualified URL to look up. |
url is unknown.
|
pure virtual |
Returns the zero-based index of the split file currently being consumed.
在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
pure virtual |
Returns the current playback state.
kStopped, kPaused or kPlaying. 在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
pure virtual |
Returns the timestamp targeted by the playback cursor.
在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
pure virtual |
Returns whether a jump() seek is still in progress.
在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
pure virtual |
Returns whether the opened bag spans multiple split files.
在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
pure virtual |
Seeks playback to begin_time and applies updated rate and loop settings.
| begin_time | Target recording timestamp in milliseconds. |
| rate | New playback speed multiplier. |
| times | Loop count to apply after the seek. |
| force_to_play | When true, transitions to kPlaying even if currently paused. |
在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
protected |
| bool vlink::BagReader::open_cursor | ( | ) |
Opens (or rewinds) a full, unfiltered sequential read cursor over the bag.
Convenience overload equivalent to open_cursor() with a default Config: every stored frame is visited in recorded order.
true when the cursor is positioned and ready, false on open failure (sets fail()). | bool vlink::BagReader::open_cursor | ( | const Config & | config | ) |
Opens (or rewinds) a synchronous sequential read cursor over the bag.
The cursor is an alternative to the timed play() / register_output_callback() path: it walks every stored frame in recorded order and hands them back one at a time through read_next() / operator>>, with no inter-frame delay, no loop thread and independent of any async_run() / play() session (a dedicated backend statement / iterator is used). Only Config::filter_urls and the Config::begin_time / Config::end_time window are honoured; rate, times and the auto_* / skip_blank flags are ignored. Any bound BagPluginInterface URL remap and URL exclusions still apply, but the plugin's on_read() interception (which is playback-only) does not run.
Calling it again rewinds the cursor and re-applies config, clearing the eof() / fail() state. read_next() and operator>> open a default (full, unfiltered) cursor automatically on first use, so an explicit call is only needed to apply a filter or seek window.
| config | Cursor filter and time window (rate / loop / auto flags are ignored). |
true when the cursor is positioned and ready, false on open failure (sets fail()).play() session on the same reader.
|
explicitnoexcept |
Reports whether the cursor is still in a readable state (not at end, not failed).
Returns true while a frame can still be read, so while (reader >> frame) stops at end of bag or on error.
Stream-style alias for read_next(), enabling while (reader >> frame).
| out | Receives the next frame. |
*this, whose bool conversion reflects the post-read stream state.
|
pure virtual |
Suspends frame dispatch while preserving the current position.
在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
pure virtual |
Emits exactly one frame from the paused position, then pauses again.
在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
pure virtual |
Starts (or restarts) a play session with the supplied configuration.
Transitions the reader into kPlaying. Requires that async_run() has already been called so that the loop thread can dispatch frames.
| config | Playback window, rate, loop count and URL filter. |
在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
protected |
|
protected |
| bool vlink::BagReader::read_next | ( | Frame & | out | ) |
Reads the next frame in recorded order into out.
Lazily calls open_cursor() with a default Config on first use. On success out is fully populated (the same URL remap and ser_type / schema_type fill applied to playback frames); out.data is a shallow view that stays valid only until the next read_next() / operator>> call – copy it if it must outlive that.
| out | Receives the next frame. |
|
protected |
|
staticprotected |
|
virtual |
Installs the "play session ended" observer.
| finish_callback | Function invoked at the end of a play session. |
被 vlink::VDBReader , 以及 vlink::VCAPReader 重载.
|
virtual |
Installs the per-frame data sink.
| output_callback | Function called for every replayed message. |
被 vlink::VDBReader , 以及 vlink::VCAPReader 重载.
|
virtual |
Installs the "open complete" observer.
| ready_callback | Function invoked once the bag is open and the index is parsed. |
被 vlink::VDBReader , 以及 vlink::VCAPReader 重载.
|
virtual |
Installs a state-change observer.
被 vlink::VDBReader , 以及 vlink::VCAPReader 重载.
|
pure virtual |
Rebuilds backend index tables in the background where supported.
true on success. 在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
pure virtual |
Resumes dispatch from the paused position.
在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
pure virtual |
Aborts the active session and rewinds to the start of the bag.
Drives the reader into kStopped and invokes the FinishCallback with is_interrupted set to true.
在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
pure virtual |
Overwrites the human-readable tag stored in the bag header.
| tag_name | New tag value. |
在 vlink::VDBReader , 以及 vlink::VCAPReader 内被实现.
|
protected |
|
protected |
|
staticconstexpr |
Sentinel for Config::times that requests endless loop playback.