|
VLink
2.1.0
A high-performance communication middleware
|
Time-sorted relay buffer keyed on the data-plane time, shared by read- and write-side plugins. More...
#include <bag_processor.h>
Classes | |
| struct | Config |
| Tunables controlling the reorder buffer behaviour. More... | |
Public Types | |
| using | OutputCallback = FrameCallback |
Sink receiving one Frame in data-plane-time order on the worker thread. More... | |
Public Member Functions | |
| BagProcessor (const Config &config=Config()) | |
| Builds the processor. More... | |
| ~BagProcessor () | |
| Drains remaining frames in data-plane-time order and joins the worker thread. More... | |
| void | register_output_callback (OutputCallback &&output_callback) |
| Sets the sink receiving reordered frames and starts the worker thread. More... | |
| void | push (int64_t data_timestamp, const Frame &frame) |
| Inserts a frame into the data-plane-time-sorted cache. More... | |
| void | flush () |
| Synchronously drains every currently-buffered frame to the sink, in data-plane-time order. More... | |
| void | reset () |
| Synchronously discards every buffered frame and starts a fresh timestamp timeline. More... | |
Time-sorted relay buffer keyed on the data-plane time, shared by read- and write-side plugins.
Thread-safe in the sense that push() may be called concurrently from the host's loop thread(s); delivery to the OutputCallback happens on a dedicated worker thread owned by the processor.
Sink receiving one Frame in data-plane-time order on the worker thread.
Invoked once Config::min_cache_time of data-plane time has accumulated ahead of the candidate frame, the size limit forces progress, or flush() drains the tail. The frame is moved out of the cache into the callback. The callback frame timestamp is remapped onto the sorted data-plane-time axis so it stays strictly increasing after the reorder.
Builds the processor.
| config | Cache time-window and memory-budget tunables. |
| vlink::BagProcessor::~BagProcessor | ( | ) |
Drains remaining frames in data-plane-time order and joins the worker thread.
| void vlink::BagProcessor::flush | ( | ) |
Synchronously drains every currently-buffered frame to the sink, in data-plane-time order.
Blocks until the cache is empty: the worker thread emits each queued frame through the registered output callback, then wakes the caller. A plugin forwards this from BagPluginInterface::flush() so buffered tail frames are emitted before teardown. Draining also resets the timestamp-resolution anchors, so the next push() starts a fresh timeline – flush() marks a file boundary, letting one processor instance serve consecutive bag files. Do not push() concurrently with flush(): frames racing the boundary belong to no defined timeline. A no-op before callback registration or shutdown.
| void vlink::BagProcessor::push | ( | int64_t | data_timestamp, |
| const Frame & | frame | ||
| ) |
Inserts a frame into the data-plane-time-sorted cache.
Safe to call from any thread after register_output_callback(). Frames are ordered by data_timestamp. Negative data_timestamp is filled from the previous data timestamp and the Frame::timestamp delta; without a previous anchor it stays -1, sorts before valid data timestamps, and is ordered against other missing-time frames by Frame::timestamp. Output frame timestamps are remapped on the data-time axis and kept strictly increasing within a flush segment (flush() resets the axis). The frame is copied into the owning cache.
| data_timestamp | Reorder key in microseconds (the data-plane time), or negative when missing. |
| frame | Frame to cache; Frame::timestamp is the canonical time before remapping. |
| void vlink::BagProcessor::register_output_callback | ( | OutputCallback && | output_callback | ) |
Sets the sink receiving reordered frames and starts the worker thread.
The first registration before push() takes effect; later registrations are ignored.
| output_callback | Sink invoked once per frame on the worker thread. |
| void vlink::BagProcessor::reset | ( | ) |
Synchronously discards every buffered frame and starts a fresh timestamp timeline.
Waits for any output callback already in progress, clears the cache without emitting it, and resets all data-time resolution and output timestamp anchors. Read-side plugins use this at the start of a new playback session so frames retained by an interrupted stop or jump cannot enter the next timeline. Do not call this from the processor's output callback or concurrently with push(). A no-op before callback registration or during shutdown.