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