OrbbecSDK 2.5.5
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:
73 explicit PlaybackDevice(const std::string &file) : Device(nullptr) {
74 ob_error *error = nullptr;
75 impl_ = ob_create_playback_device(file.c_str(), &error);
76 Error::handle(&error);
77 }
78
79 virtual ~PlaybackDevice() noexcept override = default;
80
81 PlaybackDevice(PlaybackDevice &&other) noexcept : Device(std::move(other)) {}
82
84 Device::operator=(std::move(other));
85 return *this;
86 }
87
88 PlaybackDevice(const PlaybackDevice &) = delete;
90
91public:
95 void pause() {
96 ob_error *error = nullptr;
98 Error::handle(&error);
99 }
100
104 void resume() {
105 ob_error *error = nullptr;
107 Error::handle(&error);
108 }
109
114 void seek(const int64_t timestamp) {
115 ob_error *error = nullptr;
116 ob_playback_device_seek(impl_, timestamp, &error);
117 Error::handle(&error);
118 }
119
124 void setPlaybackRate(const float rate) {
125 ob_error *error = nullptr;
127 Error::handle(&error);
128 }
129
135 callback_ = callback;
136 ob_error *error = nullptr;
137 ob_playback_device_set_playback_status_changed_callback(impl_, &PlaybackDevice::playbackStatusCallback, this, &error);
138 Error::handle(&error);
139 }
140
146 ob_error *error = nullptr;
148 Error::handle(&error);
149
150 return status;
151 }
152
157 uint64_t getPosition() const {
158 ob_error *error = nullptr;
159 uint64_t position = ob_playback_device_get_position(impl_, &error);
160 Error::handle(&error);
161
162 return position;
163 }
164
169 uint64_t getDuration() const {
170 ob_error *error = nullptr;
171 uint64_t duration = ob_playback_device_get_duration(impl_, &error);
172 Error::handle(&error);
173
174 return duration;
175 }
176
177private:
178 static void playbackStatusCallback(OBPlaybackStatus status, void *userData) {
179 auto *playbackDevice = static_cast<PlaybackDevice *>(userData);
180 if(playbackDevice && playbackDevice->callback_) {
181 playbackDevice->callback_(status);
182 }
183 }
184
185private:
187};
188} // 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:55
Device(ob_device_t *impl)
Describe the entity of the RGBD camera, representing a specific model of RGBD camera.
Definition Device.hpp:63
Device & operator=(Device &&other) noexcept
Definition Device.hpp:69
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
PlaybackDevice(const std::string &file)
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 & 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
Definition Context.hpp:19
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:117