OrbbecSDK 2.10.6
OrbbecSDK: Software-Development-Kit for Orbbec 3D Cameras
Loading...
Searching...
No Matches
RecordPlayback.hpp
Go to the documentation of this file.
1// Copyright (c) Orbbec Inc. All Rights Reserved.
2// Licensed under the MIT License.
3
9
10#pragma once
11
12#include "Types.hpp"
13#include "Error.hpp"
16
17namespace ob {
18
19typedef std::function<void(OBPlaybackStatus status)> PlaybackStatusChangeCallback;
20
22private:
23 ob_record_device_t *impl_ = nullptr;
24
25public:
26 explicit RecordDevice(std::shared_ptr<Device> device, const std::string &file, bool compressionEnabled = true) {
27 ob_error *error = nullptr;
28 impl_ = ob_create_record_device(device->getImpl(), file.c_str(), compressionEnabled, &error);
29 Error::handle(&error);
30 }
31
32 virtual ~RecordDevice() noexcept {
33 ob_error *error = nullptr;
34 ob_delete_record_device(impl_, &error);
35 Error::handle(&error, false);
36 }
37
38 RecordDevice(RecordDevice &&other) noexcept {
39 if(this != &other) {
40 impl_ = other.impl_;
41 other.impl_ = nullptr;
42 }
43 }
44
45 RecordDevice &operator=(RecordDevice &&other) noexcept {
46 if(this != &other) {
47 impl_ = other.impl_;
48 other.impl_ = nullptr;
49 }
50
51 return *this;
52 }
53
54 RecordDevice(const RecordDevice &) = delete;
56
57public:
58 void pause() {
59 ob_error *error = nullptr;
60 ob_record_device_pause(impl_, &error);
61 Error::handle(&error);
62 }
63
64 void resume() {
65 ob_error *error = nullptr;
66 ob_record_device_resume(impl_, &error);
67 Error::handle(&error);
68 }
69};
70
71class PlaybackDevice : public Device {
72public:
78 explicit PlaybackDevice(const std::string &file, const std::string &presetPath = "") : Device(nullptr) {
79 ob_error *error = nullptr;
80 impl_ = ob_create_playback_device(file.c_str(), &error);
81 Error::handle(&error);
82
83 if(!presetPath.empty()) {
84 loadPresetFromJsonFile(presetPath.c_str());
85 }
86 }
87
88 virtual ~PlaybackDevice() noexcept override = default;
89
90 PlaybackDevice(PlaybackDevice &&other) noexcept : Device(std::move(other)) {}
91
93 Device::operator=(std::move(other));
94 return *this;
95 }
96
97 PlaybackDevice(const PlaybackDevice &) = delete;
99
100public:
104 void pause() {
105 ob_error *error = nullptr;
107 Error::handle(&error);
108 }
109
113 void resume() {
114 ob_error *error = nullptr;
116 Error::handle(&error);
117 }
118
123 void seek(const int64_t timestamp) {
124 ob_error *error = nullptr;
125 ob_playback_device_seek(impl_, timestamp, &error);
126 Error::handle(&error);
127 }
128
133 void setPlaybackRate(const float rate) {
134 ob_error *error = nullptr;
136 Error::handle(&error);
137 }
138
144 callback_ = callback;
145 ob_error *error = nullptr;
146 ob_playback_device_set_playback_status_changed_callback(impl_, &PlaybackDevice::playbackStatusCallback, this, &error);
147 Error::handle(&error);
148 }
149
155 ob_error *error = nullptr;
157 Error::handle(&error);
158
159 return status;
160 }
161
166 uint64_t getPosition() const {
167 ob_error *error = nullptr;
168 uint64_t position = ob_playback_device_get_position(impl_, &error);
169 Error::handle(&error);
170
171 return position;
172 }
173
178 uint64_t getDuration() const {
179 ob_error *error = nullptr;
180 uint64_t duration = ob_playback_device_get_duration(impl_, &error);
181 Error::handle(&error);
182
183 return duration;
184 }
185
186private:
187 static void playbackStatusCallback(OBPlaybackStatus status, void *userData) {
188 auto *playbackDevice = static_cast<PlaybackDevice *>(userData);
189 if(playbackDevice && playbackDevice->callback_) {
190 playbackDevice->callback_(status);
191 }
192 }
193
194private:
196};
197} // namespace ob
Device related types, including operations such as getting and creating a device, setting and obtaini...
This file defines the Error class, which describes abnormal errors within the SDK....
enum ob_playback_status OBPlaybackStatus
OB_EXPORT void ob_playback_device_seek(ob_device *player, const uint64_t timestamp, ob_error **error)
Set the playback to a specified time point of the played data.
OB_EXPORT uint64_t ob_playback_device_get_position(ob_device *player, ob_error **error)
Get the current playback position of the played data.
OB_EXPORT ob_playback_status ob_playback_device_get_current_playback_status(ob_device *player, ob_error **error)
Get the current playback status of the played data.
OB_EXPORT ob_device * ob_create_playback_device(const char *file_path, ob_error **error)
Create a playback device for the specified file path.
OB_EXPORT ob_record_device * ob_create_record_device(ob_device *device, const char *file_path, bool compression_enabled, ob_error **error)
Create a recording device for the specified device with a specified file path and compression enabled...
OB_EXPORT uint64_t ob_playback_device_get_duration(ob_device *player, ob_error **error)
Get the duration of the played data.
OB_EXPORT void ob_playback_device_set_playback_rate(ob_device *player, const float rate, ob_error **error)
Set the playback to a specified time point of the played data.
OB_EXPORT void ob_playback_device_pause(ob_device *player, ob_error **error)
Pause playback on the specified playback device.
OB_EXPORT void ob_playback_device_resume(ob_device *player, ob_error **error)
Resume playback on the specified playback device.
OB_EXPORT void ob_playback_device_set_playback_status_changed_callback(ob_device *player, ob_playback_status_changed_callback callback, void *user_data, ob_error **error)
Set a callback function to receive playback status updates.
OB_EXPORT void ob_record_device_pause(ob_record_device *recorder, ob_error **error)
Pause recording on the specified recording device.
OB_EXPORT void ob_delete_record_device(ob_record_device *recorder, ob_error **error)
Delete a recording device.
OB_EXPORT void ob_record_device_resume(ob_record_device *recorder, ob_error **error)
Resume recording on the specified recording device.
ob_device * impl_
Definition Device.hpp:56
Device(ob_device_t *impl)
Describe the entity of the RGBD camera, representing a specific model of RGBD camera.
Definition Device.hpp:64
Device & operator=(Device &&other) noexcept
Definition Device.hpp:70
void loadPresetFromJsonFile(const char *filePath) const
Load custom preset from file.
Definition Device.hpp:932
static void handle(ob_error **error, bool throw_exception=true)
A static function to handle the ob_error and throw an exception if needed.
Definition Error.hpp:38
virtual ~PlaybackDevice() noexcept override=default
void seek(const int64_t timestamp)
Seek to a specific timestamp when playing back a recording.
PlaybackDevice & operator=(const PlaybackDevice &)=delete
OBPlaybackStatus getPlaybackStatus() const
Get the current playback status of the playback device.
void resume()
Resume the streaming data from the playback device.
uint64_t getDuration() const
Get the duration of the playback device.
void setPlaybackStatusChangeCallback(PlaybackStatusChangeCallback callback)
Set a callback function to be called when the playback status changes.
PlaybackDevice(const PlaybackDevice &)=delete
uint64_t getPosition() const
Get the current position of the playback device.
PlaybackDevice(const std::string &file, const std::string &presetPath="")
Constructs a PlaybackDevice for playing back recorded device data.
PlaybackDevice & operator=(PlaybackDevice &&other) noexcept
void setPlaybackRate(const float rate)
Set the playback rate of the playback device.
void pause()
Pause the streaming data from the playback device.
RecordDevice(std::shared_ptr< Device > device, const std::string &file, bool compressionEnabled=true)
RecordDevice(const RecordDevice &)=delete
virtual ~RecordDevice() noexcept
RecordDevice & operator=(RecordDevice &&other) noexcept
RecordDevice & operator=(const RecordDevice &)=delete
RecordDevice(RecordDevice &&other) noexcept
std::function< void(OBPlaybackStatus status)> PlaybackStatusChangeCallback
The error class exposed by the SDK, users can get detailed error information according to the error.
Definition ObTypes.h:162