Rerun C++ SDK
Loading...
Searching...
No Matches
video_frame_reference.hpp
1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/store/re_types/definitions/rerun/archetypes/video_frame_reference.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/entity_path.hpp"
10#include "../components/video_timestamp.hpp"
11#include "../indicator_component.hpp"
12#include "../result.hpp"
13
14#include <cstdint>
15#include <optional>
16#include <utility>
17#include <vector>
18
19namespace rerun::archetypes {
20 /// **Archetype**: References a single video frame.
21 ///
22 /// Used to display individual video frames from a `archetypes::AssetVideo`.
23 /// To show an entire video, a video frame reference for each frame of the video should be logged.
24 ///
25 /// See <https://rerun.io/docs/reference/video> for details of what is and isn't supported.
26 ///
27 /// ## Examples
28 ///
29 /// ### Video with automatically determined frames
30 /// ![image](https://static.rerun.io/video_manual_frames/320a44e1e06b8b3a3161ecbbeae3e04d1ccb9589/full.png)
31 ///
32 /// ```cpp
33 /// #include <rerun.hpp>
34 ///
35 /// #include <iostream>
36 ///
37 /// using namespace std::chrono_literals;
38 ///
39 /// int main(int argc, char* argv[]) {
40 /// if (argc <2) {
41 /// // TODO(#7354): Only mp4 is supported for now.
42 /// std::cerr <<"Usage: " <<argv[0] <<" <path_to_video.[mp4]>" <<std::endl;
43 /// return 1;
44 /// }
45 ///
46 /// const auto path = argv[1];
47 ///
48 /// const auto rec = rerun::RecordingStream("rerun_example_asset_video_auto_frames");
49 /// rec.spawn().exit_on_failure();
50 ///
51 /// // Log video asset which is referred to by frame references.
52 /// auto video_asset = rerun::AssetVideo::from_file(path).value_or_throw();
53 /// rec.log_static("video", video_asset);
54 ///
55 /// // Send automatically determined video frame timestamps.
56 /// std::vector<std::chrono::nanoseconds> frame_timestamps_ns =
57 /// video_asset.read_frame_timestamps_ns().value_or_throw();
58 /// // Note timeline values don't have to be the same as the video timestamps.
59 /// auto time_column =
60 /// rerun::TimeColumn::from_times("video_time", rerun::borrow(frame_timestamps_ns));
61 ///
62 /// std::vector<rerun::components::VideoTimestamp> video_timestamps(frame_timestamps_ns.size());
63 /// for (size_t i = 0; i <frame_timestamps_ns.size(); i++) {
64 /// video_timestamps[i] = rerun::components::VideoTimestamp(frame_timestamps_ns[i]);
65 /// }
66 /// auto video_frame_reference_indicators =
67 /// rerun::ComponentColumn::from_indicators<rerun::VideoFrameReference>(
68 /// static_cast<uint32_t>(video_timestamps.size())
69 /// );
70 ///
71 /// rec.send_columns(
72 /// "video",
73 /// time_column,
74 /// rerun::VideoFrameReference().with_many_timestamp(rerun::borrow(video_timestamps)).columns()
75 /// );
76 /// }
77 /// ```
78 ///
79 /// ### Demonstrates manual use of video frame references
80 /// ![image](https://static.rerun.io/video_manual_frames/9f41c00f84a98cc3f26875fba7c1d2fa2bad7151/full.png)
81 ///
82 /// ```cpp
83 /// #include <rerun.hpp>
84 ///
85 /// #include <iostream>
86 ///
87 /// using namespace std::chrono_literals;
88 ///
89 /// int main(int argc, char* argv[]) {
90 /// if (argc <2) {
91 /// // TODO(#7354): Only mp4 is supported for now.
92 /// std::cerr <<"Usage: " <<argv[0] <<" <path_to_video.[mp4]>" <<std::endl;
93 /// return 1;
94 /// }
95 ///
96 /// const auto path = argv[1];
97 ///
98 /// const auto rec = rerun::RecordingStream("rerun_example_asset_video_manual_frames");
99 /// rec.spawn().exit_on_failure();
100 ///
101 /// // Log video asset which is referred to by frame references.
102 /// rec.log_static("video_asset", rerun::AssetVideo::from_file(path).value_or_throw());
103 ///
104 /// // Create two entities, showing the same video frozen at different times.
105 /// rec.log("frame_1s", rerun::VideoFrameReference(1.0s).with_video_reference("video_asset"));
106 /// rec.log("frame_2s", rerun::VideoFrameReference(2.0s).with_video_reference("video_asset"));
107 ///
108 /// // TODO(#5520): log blueprint once supported
109 /// }
110 /// ```
112 /// References the closest video frame to this timestamp.
113 ///
114 /// Note that this uses the closest video frame instead of the latest at this timestamp
115 /// in order to be more forgiving of rounding errors for inprecise timestamp types.
116 ///
117 /// Timestamps are relative to the start of the video, i.e. a timestamp of 0 always corresponds to the first frame.
118 /// This is oftentimes equivalent to presentation timestamps (known as PTS), but in the presence of B-frames
119 /// (bidirectionally predicted frames) there may be an offset on the first presentation timestamp in the video.
120 std::optional<ComponentBatch> timestamp;
121
122 /// Optional reference to an entity with a `archetypes::AssetVideo`.
123 ///
124 /// If none is specified, the video is assumed to be at the same entity.
125 /// Note that blueprint overrides on the referenced video will be ignored regardless,
126 /// as this is always interpreted as a reference to the data store.
127 ///
128 /// For a series of video frame references, it is recommended to specify this path only once
129 /// at the beginning of the series and then rely on latest-at query semantics to
130 /// keep the video reference active.
131 std::optional<ComponentBatch> video_reference;
132
133 public:
134 static constexpr const char IndicatorComponentName[] =
135 "rerun.components.VideoFrameReferenceIndicator";
136
137 /// Indicator component, used to identify the archetype when converting to a list of components.
139 /// The name of the archetype as used in `ComponentDescriptor`s.
140 static constexpr const char ArchetypeName[] = "rerun.archetypes.VideoFrameReference";
141
142 /// `ComponentDescriptor` for the `timestamp` field.
144 ArchetypeName, "timestamp",
146 );
147 /// `ComponentDescriptor` for the `video_reference` field.
149 ArchetypeName, "video_reference",
151 );
152
153 public:
154 VideoFrameReference() = default;
155 VideoFrameReference(VideoFrameReference&& other) = default;
156 VideoFrameReference(const VideoFrameReference& other) = default;
157 VideoFrameReference& operator=(const VideoFrameReference& other) = default;
158 VideoFrameReference& operator=(VideoFrameReference&& other) = default;
159
161 : timestamp(ComponentBatch::from_loggable(std::move(_timestamp), Descriptor_timestamp)
162 .value_or_throw()) {}
163
164 /// Update only some specific fields of a `VideoFrameReference`.
166 return VideoFrameReference();
167 }
168
169 /// Clear all the fields of a `VideoFrameReference`.
171
172 /// References the closest video frame to this timestamp.
173 ///
174 /// Note that this uses the closest video frame instead of the latest at this timestamp
175 /// in order to be more forgiving of rounding errors for inprecise timestamp types.
176 ///
177 /// Timestamps are relative to the start of the video, i.e. a timestamp of 0 always corresponds to the first frame.
178 /// This is oftentimes equivalent to presentation timestamps (known as PTS), but in the presence of B-frames
179 /// (bidirectionally predicted frames) there may be an offset on the first presentation timestamp in the video.
181 timestamp =
182 ComponentBatch::from_loggable(_timestamp, Descriptor_timestamp).value_or_throw();
183 return std::move(*this);
184 }
185
186 /// This method makes it possible to pack multiple `timestamp` in a single component batch.
187 ///
188 /// This only makes sense when used in conjunction with `columns`. `with_timestamp` should
189 /// be used when logging a single row's worth of data.
192 ) && {
193 timestamp =
194 ComponentBatch::from_loggable(_timestamp, Descriptor_timestamp).value_or_throw();
195 return std::move(*this);
196 }
197
198 /// Optional reference to an entity with a `archetypes::AssetVideo`.
199 ///
200 /// If none is specified, the video is assumed to be at the same entity.
201 /// Note that blueprint overrides on the referenced video will be ignored regardless,
202 /// as this is always interpreted as a reference to the data store.
203 ///
204 /// For a series of video frame references, it is recommended to specify this path only once
205 /// at the beginning of the series and then rely on latest-at query semantics to
206 /// keep the video reference active.
208 const rerun::components::EntityPath& _video_reference
209 ) && {
212 .value_or_throw();
213 return std::move(*this);
214 }
215
216 /// This method makes it possible to pack multiple `video_reference` in a single component batch.
217 ///
218 /// This only makes sense when used in conjunction with `columns`. `with_video_reference` should
219 /// be used when logging a single row's worth of data.
221 const Collection<rerun::components::EntityPath>& _video_reference
222 ) && {
225 .value_or_throw();
226 return std::move(*this);
227 }
228
229 /// Partitions the component data into multiple sub-batches.
230 ///
231 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
232 /// instead, via `ComponentBatch::partitioned`.
233 ///
234 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
235 ///
236 /// The specified `lengths` must sum to the total length of the component batch.
238
239 /// Partitions the component data into unit-length sub-batches.
240 ///
241 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
242 /// where `n` is automatically guessed.
244 };
245
246} // namespace rerun::archetypes
247
248namespace rerun {
249 /// \private
250 template <typename T>
251 struct AsComponents;
252
253 /// \private
254 template <>
255 struct AsComponents<archetypes::VideoFrameReference> {
256 /// Serialize all set component batches.
257 static Result<Collection<ComponentBatch>> as_batches(
258 const archetypes::VideoFrameReference& archetype
259 );
260 };
261} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
A class for representing either a usable value, or an error.
Definition result.hpp:14
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:76
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
Arrow-encoded data of a single batch of components together with a component descriptor.
Definition component_batch.hpp:28
static Result< ComponentBatch > from_loggable(const rerun::Collection< T > &components, const ComponentDescriptor &descriptor=rerun::Loggable< T >::Descriptor)
Creates a new component batch from a collection of component instances.
Definition component_batch.hpp:46
A ComponentDescriptor fully describes the semantics of a column of data.
Definition component_descriptor.hpp:14
The Loggable trait is used by all built-in implementation of rerun::AsComponents to serialize a colle...
Definition loggable.hpp:11
Archetype: References a single video frame.
Definition video_frame_reference.hpp:111
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
VideoFrameReference with_timestamp(const rerun::components::VideoTimestamp &_timestamp) &&
References the closest video frame to this timestamp.
Definition video_frame_reference.hpp:180
VideoFrameReference with_many_timestamp(const Collection< rerun::components::VideoTimestamp > &_timestamp) &&
This method makes it possible to pack multiple timestamp in a single component batch.
Definition video_frame_reference.hpp:190
std::optional< ComponentBatch > timestamp
References the closest video frame to this timestamp.
Definition video_frame_reference.hpp:120
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition video_frame_reference.hpp:140
static constexpr auto Descriptor_video_reference
ComponentDescriptor for the video_reference field.
Definition video_frame_reference.hpp:148
static constexpr auto Descriptor_timestamp
ComponentDescriptor for the timestamp field.
Definition video_frame_reference.hpp:143
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
VideoFrameReference with_video_reference(const rerun::components::EntityPath &_video_reference) &&
Optional reference to an entity with a archetypes::AssetVideo.
Definition video_frame_reference.hpp:207
std::optional< ComponentBatch > video_reference
Optional reference to an entity with a archetypes::AssetVideo.
Definition video_frame_reference.hpp:131
VideoFrameReference with_many_video_reference(const Collection< rerun::components::EntityPath > &_video_reference) &&
This method makes it possible to pack multiple video_reference in a single component batch.
Definition video_frame_reference.hpp:220
static VideoFrameReference update_fields()
Update only some specific fields of a VideoFrameReference.
Definition video_frame_reference.hpp:165
static VideoFrameReference clear_fields()
Clear all the fields of a VideoFrameReference.
Component: A path to an entity, usually to reference some data that is part of the target entity.
Definition entity_path.hpp:17
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:32
Component: Timestamp inside a archetypes::AssetVideo.
Definition video_timestamp.hpp:16