Orbbec SDK K4A Wrapper
Loading...
Searching...
No Matches
record.hpp
Go to the documentation of this file.
1
6#ifndef K4A_RECORD_HPP
7#define K4A_RECORD_HPP
8
9#include <k4a/k4a.hpp>
10#include <k4arecord/record.h>
11
12namespace k4a
13{
14
22class record
23{
24public:
30 record(k4a_record_t handle = nullptr) noexcept : m_handle(handle) {}
31
34 record(record &&other) noexcept : m_handle(other.m_handle)
35 {
36 other.m_handle = nullptr;
37 }
38
39 record(const record &) = delete;
40
41 ~record()
42 {
43 // NOTE: flush is called internally when closing record
44 close();
45 }
46
47 record &operator=(const record &) = delete;
48
51 record &operator=(record &&other) noexcept
52 {
53 if (this != &other)
54 {
55 close();
56 m_handle = other.m_handle;
57 other.m_handle = nullptr;
58 }
59
60 return *this;
61 }
62
65 explicit operator bool() const noexcept
66 {
67 return is_valid();
68 }
69
72 bool is_valid() const noexcept
73 {
74 return m_handle != nullptr;
75 }
76
81 void close() noexcept
82 {
83 if (is_valid())
84 {
85 k4a_record_close(m_handle);
86 m_handle = nullptr;
87 }
88 }
89
94 void flush()
95 {
96 if (m_handle)
97 {
98 k4a_result_t result = k4a_record_flush(m_handle);
99
100 if (K4A_FAILED(result))
101 {
102 throw error("Failed to flush!");
103 }
104 }
105 }
106
112 void add_tag(const char *name, const char *value)
113 {
114 k4a_result_t result = k4a_record_add_tag(m_handle, name, value);
115
116 if (K4A_FAILED(result))
117 {
118 throw error("Failed to add tag!");
119 }
120 }
121
128 {
129 k4a_result_t result = k4a_record_add_imu_track(m_handle);
130
131 if (K4A_FAILED(result))
132 {
133 throw error("Failed to add imu_track!");
134 }
135 }
136
142 void add_attachment(const char *attachment_name, const uint8_t *buffer, size_t buffer_size)
143 {
144 k4a_result_t result = k4a_record_add_attachment(m_handle, attachment_name, buffer, buffer_size);
145
146 if (K4A_FAILED(result))
147 {
148 throw error("Failed to add attachment!");
149 }
150 }
151
157 void add_custom_video_track(const char *track_name,
158 const char *codec_id,
159 const uint8_t *codec_context,
160 size_t codec_context_size,
161 const k4a_record_video_settings_t *track_settings)
162 {
163 k4a_result_t result = k4a_record_add_custom_video_track(m_handle,
164 track_name,
165 codec_id,
166 codec_context,
167 codec_context_size,
168 track_settings);
169
170 if (K4A_FAILED(result))
171 {
172 throw error("Failed to add custom video track!");
173 }
174 }
175
181 void add_custom_subtitle_track(const char *track_name,
182 const char *codec_id,
183 const uint8_t *codec_context,
184 size_t codec_context_size,
185 const k4a_record_subtitle_settings_t *track_settings)
186 {
187 k4a_result_t result = k4a_record_add_custom_subtitle_track(m_handle,
188 track_name,
189 codec_id,
190 codec_context,
191 codec_context_size,
192 track_settings);
193
194 if (K4A_FAILED(result))
195 {
196 throw error("Failed to add custom subtitle track!");
197 }
198 }
199
206 {
207 k4a_result_t result = k4a_record_write_header(m_handle);
208
209 if (K4A_FAILED(result))
210 {
211 throw error("Failed to write header!");
212 }
213 }
214
221 {
222 k4a_result_t result = k4a_record_write_capture(m_handle, capture.handle());
223
224 if (K4A_FAILED(result))
225 {
226 throw error("Failed to write capture!");
227 }
228 }
229
235 void write_imu_sample(const k4a_imu_sample_t &imu_sample)
236 {
237 k4a_result_t result = k4a_record_write_imu_sample(m_handle, imu_sample);
238
239 if (K4A_FAILED(result))
240 {
241 throw error("Failed to write imu sample!");
242 }
243 }
244
250 void write_custom_track_data(const char *track_name,
251 const std::chrono::microseconds device_timestamp_usec,
252 uint8_t *custom_data,
253 size_t custom_data_size)
254 {
255 k4a_result_t result = k4a_record_write_custom_track_data(m_handle,
256 track_name,
257 internal::clamp_cast<uint64_t>(
258 device_timestamp_usec.count()),
259 custom_data,
260 custom_data_size);
261
262 if (K4A_FAILED(result))
263 {
264 throw error("Failed to write custom track data!");
265 }
266 }
267
273 static record create(const char *path, const device &device, const k4a_device_configuration_t &device_configuration)
274 {
275 k4a_record_t handle = nullptr;
276 k4a_result_t result = k4a_record_create(path, device.handle(), device_configuration, &handle);
277
278 if (K4A_FAILED(result))
279 {
280 throw error("Failed to create recorder!");
281 }
282
283 return record(handle);
284 }
285
286private:
287 k4a_record_t m_handle;
288};
289
290} // namespace k4a
291
292#endif
k4a_capture_t handle() const noexcept
Definition: k4a.hpp:545
k4a_device_t handle() const noexcept
Definition: k4a.hpp:1162
void write_imu_sample(const k4a_imu_sample_t &imu_sample)
Definition: record.hpp:235
void add_custom_subtitle_track(const char *track_name, const char *codec_id, const uint8_t *codec_context, size_t codec_context_size, const k4a_record_subtitle_settings_t *track_settings)
Definition: record.hpp:181
void close() noexcept
Definition: record.hpp:81
bool is_valid() const noexcept
Definition: record.hpp:72
void write_custom_track_data(const char *track_name, const std::chrono::microseconds device_timestamp_usec, uint8_t *custom_data, size_t custom_data_size)
Definition: record.hpp:250
void add_imu_track()
Definition: record.hpp:127
void add_attachment(const char *attachment_name, const uint8_t *buffer, size_t buffer_size)
Definition: record.hpp:142
record(record &&other) noexcept
Definition: record.hpp:34
static record create(const char *path, const device &device, const k4a_device_configuration_t &device_configuration)
Definition: record.hpp:273
record & operator=(record &&other) noexcept
Definition: record.hpp:51
record(k4a_record_t handle=nullptr) noexcept
Definition: record.hpp:30
void write_header()
Definition: record.hpp:205
void add_custom_video_track(const char *track_name, const char *codec_id, const uint8_t *codec_context, size_t codec_context_size, const k4a_record_video_settings_t *track_settings)
Definition: record.hpp:157
void add_tag(const char *name, const char *value)
Definition: record.hpp:112
void write_capture(const capture &capture)
Definition: record.hpp:220
void flush()
Definition: record.hpp:94
k4a_result_t
Definition: k4atypes.h:218
#define K4A_FAILED(_result_)
Definition: k4atypes.h:756