Rerun C++ SDK
Loading...
Searching...
No Matches
asset_audio.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/build/re_type_definitions/rerun/archetypes/asset_audio.def.rs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/blob.hpp"
10#include "../components/media_type.hpp"
11#include "../result.hpp"
12
13#include <cstdint>
14#include <filesystem>
15#include <optional>
16#include <utility>
17#include <vector>
18
19namespace rerun::archetypes {
20 /// **Archetype**: An audio file, stored as-is (`.aac`, `.flac`, `.m4a`, `.mp3`, `.ogg`, `.wav`).
21 ///
22 /// The audio is considered to start playing at the time it was logged,
23 /// so log it on a temporal timeline (duration or timestamp) at the point where playback should begin.
24 ///
25 /// ## Example
26 ///
27 /// ### Simple audio asset
28 /// ```cpp
29 /// #include <rerun.hpp>
30 ///
31 /// #include <iostream>
32 ///
33 /// int main(int argc, char* argv[]) {
34 /// if (argc <2) {
35 /// std::cerr <<"Usage: " <<argv[0]
36 /// <<" <path_to_audio.[aac|flac|m4a|mp3|ogg|wav]>" <<std::endl;
37 /// return 1;
38 /// }
39 ///
40 /// const auto path = argv[1];
41 ///
42 /// const auto rec = rerun::RecordingStream("rerun_example_asset_audio");
43 /// rec.spawn().exit_on_failure();
44 ///
45 /// rec.set_time_duration_secs("time", 0.0);
46 /// rec.log("audio", rerun::AssetAudio::from_file_path(path).value_or_throw());
47 /// }
48 /// ```
49 ///
50 /// ⚠ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
51 ///
52 struct AssetAudio {
53 /// The asset's bytes.
54 std::optional<ComponentBatch> blob;
55
56 /// The Media Type of the asset.
57 ///
58 /// For instance:
59 /// * `audio/aac` (raw ADTS stream)
60 /// * `audio/flac`
61 /// * `audio/mp4` (M4A)
62 /// * `audio/mpeg` (MP3)
63 /// * `audio/ogg`
64 /// * `audio/wav`
65 ///
66 /// Any audio media type can be stored.
67 /// Which ones the viewer can decode depends on the viewer version.
68 ///
69 /// If omitted, the viewer will try to guess from the data blob.
70 /// If it cannot guess, it won't be able to play the asset.
71 std::optional<ComponentBatch> media_type;
72
73 public:
74 /// The name of the archetype as used in `ComponentDescriptor`s.
75 static constexpr const char ArchetypeName[] = "rerun.archetypes.AssetAudio";
76
77 /// `ComponentDescriptor` for the `blob` field.
78 static constexpr auto Descriptor_blob = ComponentDescriptor(
80 );
81 /// `ComponentDescriptor` for the `media_type` field.
83 ArchetypeName, "AssetAudio:media_type",
85 );
86
87 public: // START of extensions from asset_audio_ext.cpp:
88 /// Creates a new `AssetAudio` from the file contents at `path`.
89 ///
90 /// The `MediaType` will be guessed from the file extension.
91 ///
92 /// If no `MediaType` can be guessed at the moment, the Rerun Viewer will try to guess one
93 /// from the data at playback-time. If it can't, playback will fail with an error.
94 static Result<AssetAudio> from_file_path(const std::filesystem::path& path);
95
96 /// Creates a new `AssetAudio` from the given `bytes`.
97 ///
98 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
99 /// at playback-time. If it can't, playback will fail with an error.
102 std::optional<rerun::components::MediaType> media_type = {}
103 ) {
104 AssetAudio asset = AssetAudio(std::move(bytes));
105 if (media_type.has_value()) {
106 return std::move(asset).with_media_type(media_type.value());
107 }
108 return asset;
109 }
110
111 // END of extensions from asset_audio_ext.cpp, start of generated code:
112
113 public:
114 AssetAudio() = default;
115 AssetAudio(AssetAudio&& other) = default;
116 AssetAudio(const AssetAudio& other) = default;
117 AssetAudio& operator=(const AssetAudio& other) = default;
118 AssetAudio& operator=(AssetAudio&& other) = default;
119
120 explicit AssetAudio(rerun::components::Blob _blob)
121 : blob(ComponentBatch::from_loggable(std::move(_blob), Descriptor_blob).value_or_throw()
122 ) {}
123
124 /// Update only some specific fields of a `AssetAudio`.
126 return AssetAudio();
127 }
128
129 /// Clear all the fields of a `AssetAudio`.
131
132 /// The asset's bytes.
134 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
135 return std::move(*this);
136 }
137
138 /// This method makes it possible to pack multiple `blob` in a single component batch.
139 ///
140 /// This only makes sense when used in conjunction with `columns`. `with_blob` should
141 /// be used when logging a single row's worth of data.
143 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
144 return std::move(*this);
145 }
146
147 /// The Media Type of the asset.
148 ///
149 /// For instance:
150 /// * `audio/aac` (raw ADTS stream)
151 /// * `audio/flac`
152 /// * `audio/mp4` (M4A)
153 /// * `audio/mpeg` (MP3)
154 /// * `audio/ogg`
155 /// * `audio/wav`
156 ///
157 /// Any audio media type can be stored.
158 /// Which ones the viewer can decode depends on the viewer version.
159 ///
160 /// If omitted, the viewer will try to guess from the data blob.
161 /// If it cannot guess, it won't be able to play the asset.
163 media_type =
164 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
165 return std::move(*this);
166 }
167
168 /// This method makes it possible to pack multiple `media_type` in a single component batch.
169 ///
170 /// This only makes sense when used in conjunction with `columns`. `with_media_type` should
171 /// be used when logging a single row's worth of data.
173 ) && {
174 media_type =
175 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
176 return std::move(*this);
177 }
178
179 /// Partitions the component data into multiple sub-batches.
180 ///
181 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
182 /// instead, via `ComponentBatch::partitioned`.
183 ///
184 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
185 ///
186 /// The specified `lengths` must sum to the total length of the component batch.
188
189 /// Partitions the component data into unit-length sub-batches.
190 ///
191 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
192 /// where `n` is automatically guessed.
194 };
195
196} // namespace rerun::archetypes
197
198namespace rerun {
199 /// \private
200 template <typename T>
201 struct AsComponents;
202
203 /// \private
204 template <>
205 struct AsComponents<archetypes::AssetAudio> {
206 /// Serialize all set component batches.
207 static Result<Collection<ComponentBatch>> as_batches(const archetypes::AssetAudio& archetype
208 );
209 };
210} // 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:90
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:26
static Result< ComponentBatch > from_loggable(const rerun::Collection< T > &components, const ComponentDescriptor &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:16
The Loggable trait is used by all built-in implementation of rerun::AsComponents to serialize a colle...
Definition loggable.hpp:11
Archetype: An audio file, stored as-is (.aac, .flac, .m4a, .mp3, .ogg, .wav).
Definition asset_audio.hpp:52
static Result< AssetAudio > from_file_path(const std::filesystem::path &path)
Creates a new AssetAudio from the file contents at path.
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
AssetAudio with_media_type(const rerun::components::MediaType &_media_type) &&
The Media Type of the asset.
Definition asset_audio.hpp:162
std::optional< ComponentBatch > blob
The asset's bytes.
Definition asset_audio.hpp:54
static AssetAudio update_fields()
Update only some specific fields of a AssetAudio.
Definition asset_audio.hpp:125
AssetAudio with_blob(const rerun::components::Blob &_blob) &&
The asset's bytes.
Definition asset_audio.hpp:133
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition asset_audio.hpp:75
AssetAudio with_many_blob(const Collection< rerun::components::Blob > &_blob) &&
This method makes it possible to pack multiple blob in a single component batch.
Definition asset_audio.hpp:142
static constexpr auto Descriptor_blob
ComponentDescriptor for the blob field.
Definition asset_audio.hpp:78
static constexpr auto Descriptor_media_type
ComponentDescriptor for the media_type field.
Definition asset_audio.hpp:82
std::optional< ComponentBatch > media_type
The Media Type of the asset.
Definition asset_audio.hpp:71
static AssetAudio from_file_contents(rerun::Collection< uint8_t > bytes, std::optional< rerun::components::MediaType > media_type={})
Creates a new AssetAudio from the given bytes.
Definition asset_audio.hpp:100
AssetAudio with_many_media_type(const Collection< rerun::components::MediaType > &_media_type) &&
This method makes it possible to pack multiple media_type in a single component batch.
Definition asset_audio.hpp:172
static AssetAudio clear_fields()
Clear all the fields of a AssetAudio.
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Component: A binary blob of data.
Definition blob.hpp:16
Component: A standardized media type (RFC2046, formerly known as MIME types), encoded as a string.
Definition media_type.hpp:20