7 frame_archive::frame_archive(
const std::vector<subdevice_mode_selection>& selection, std::atomic<uint32_t>* in_max_frame_queue_size, std::chrono::high_resolution_clock::time_point capture_started)
8 : max_frame_queue_size(in_max_frame_queue_size), mutex(), capture_started(capture_started)
11 for (
auto &
mode : selection)
13 for (
auto & o :
mode.get_outputs())
40 std::lock_guard<std::recursive_mutex> lock(
mutex);
45 freelist.push_back(std::move(*frame));
62 *new_frame = std::move(
frame);
92 std::lock_guard<std::recursive_mutex> guard(
mutex);
99 if (it->data.size() ==
size)
111 if (additional_data.
timestamp > it->additional_data.timestamp + 1000) it =
freelist.erase(it);
132 std::unique_lock<std::recursive_mutex> lock(
mutex);
159 if (ref_count.fetch_sub(1) == 1)
162 owner->unpublish_frame(
this);
168 return owner->publish_frame(std::move(*
this));
173 return std::move(
buffer[stream]);
178 auto published_frame = new_frame.publish();
191 buffer[i].disable_continuation();
198 return frame_ptr ? frame_ptr->get_frame_metadata(frame_metadata) : 0;
203 return frame_ptr ? frame_ptr->supports_frame_metadata(frame_metadata) : 0;
208 return frame_ptr ? frame_ptr->get_frame_data() :
nullptr;
213 return frame_ptr ? frame_ptr->get_frame_timestamp(): 0;
218 return frame_ptr ? frame_ptr->get_frame_number() : 0;
223 return frame_ptr ? frame_ptr->get_frame_system_time() : 0;
233 return frame_ptr ? frame_ptr->get_width() : 0;
238 return frame_ptr ? frame_ptr->get_height() : 0;
243 return frame_ptr ? frame_ptr->get_framerate() : 0;
248 return frame_ptr ? frame_ptr->get_stride() : 0;
253 return frame_ptr ? frame_ptr->get_bpp() : 0;
268 return frame_ptr ? frame_ptr->get_frame_callback_start_time_point() : std::chrono::high_resolution_clock::now();
273 frame_ptr->update_frame_callback_start_ts(ts);
278 if (!supports_frame_metadata(frame_metadata))
279 throw std::logic_error(
"unsupported metadata type");
281 switch (frame_metadata)
284 return additional_data.exposure_value;
287 return additional_data.actual_fps;
290 throw std::logic_error(
"unsupported metadata type");
297 for (
auto & md : *additional_data.supported_metadata_vector)
if (md == frame_metadata)
return true;
303 const byte* frame_data =
data.data();;
305 if (on_release.get_data())
307 frame_data =
static_cast<const byte*
>(on_release.get_data());
308 if (additional_data.pad < 0)
310 frame_data += (
int)(additional_data.stride_x *additional_data.bpp*(-additional_data.pad) + (-additional_data.pad)*additional_data.bpp);
319 return additional_data.timestamp_domain;
324 return additional_data.timestamp;
329 return additional_data.frame_number;
334 return additional_data.system_time;
339 return additional_data.width;
344 return additional_data.stride_y ? std::min(additional_data.height, additional_data.stride_y) : additional_data.height;
349 return additional_data.fps;
354 return (additional_data.stride_x * additional_data.bpp) / 8;
359 return additional_data.bpp;
365 additional_data.frame_callback_started = ts;
371 return additional_data.format;
375 return additional_data.stream_type;
380 return additional_data.frame_callback_started;
385 auto callback_ended = std::chrono::high_resolution_clock::now();
386 auto ts = std::chrono::duration_cast<std::chrono::milliseconds>(callback_ended -
capture_started).
count();
390 if (callback_duration > callback_warning_duration)
392 LOG_INFO(
"Frame Callback took too long to complete. (Duration: " << callback_duration <<
"ms, FPS: " << frame->
additional_data.
fps <<
", Max Duration: " << callback_warning_duration <<
"ms)");
400 auto callback_start_time = std::chrono::high_resolution_clock::now();
401 auto ts = std::chrono::duration_cast<std::chrono::milliseconds>(callback_start_time - capture_start_time).
count();
subdevice_mode_selection modes[RS_STREAM_NATIVE_COUNT]
std::chrono::high_resolution_clock::time_point get_frame_callback_start_time_point() const
rs_timestamp_domain get_frame_timestamp_domain() const override
frame_ref * track_frame(rs_stream stream)
rs_stream get_stream_type() const override
std::atomic< uint32_t > * max_frame_queue_size
rs_format get_frame_format() const override
frame backbuffer[RS_STREAM_NATIVE_COUNT]
void attach_continuation(frame_continuation &&continuation)
bool supports_frame_metadata(rs_frame_metadata frame_metadata) const override
frame_metadata
Types of value provided from the device with each frame.
small_heap< frame, RS_USER_QUEUE_SIZE *RS_STREAM_COUNT > published_frames
double get_frame_metadata(rs_frame_metadata frame_metadata) const override
byte * alloc_frame(rs_stream stream, const frame_additional_data &additional_data, bool requires_memory)
frame_archive(const std::vector< subdevice_mode_selection > &selection, std::atomic< uint32_t > *max_frame_queue_size, std::chrono::high_resolution_clock::time_point capture_started=std::chrono::high_resolution_clock::now())
double get_frame_metadata(rs_frame_metadata frame_metadata) const override
int get_frame_width() const override
frame_ref * detach_frame_ref(frameset *frameset, rs_stream stream)
frame_ref * clone_frame(frame_ref *frameset)
void update_frame_callback_start_ts(std::chrono::high_resolution_clock::time_point ts)
frame * publish_frame(frame &&frame)
long long get_frame_system_time() const
unsigned long long get_frame_number() const override
int get_frame_bpp() const override
rs_timestamp_domain
Specifies the clock in relation to which the frame timestamp was measured.
const uint8_t RS_STREAM_NATIVE_COUNT
rs_format get_format() const
frame_ref detach_ref(rs_stream stream)
size_t get_image_size(rs_stream stream) const
unsigned long long get_frame_number() const override
void update_owner(frame_archive *new_owner)
GLuint GLuint GLsizei count
frame_additional_data additional_data
std::chrono::high_resolution_clock::time_point get_frame_callback_start_time_point() const
void place_frame(rs_stream stream, frame &&new_frame)
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
double get_frame_timestamp() const override
void update_frame_callback_start_ts(std::chrono::high_resolution_clock::time_point ts)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * data
long long get_frame_system_time() const override
rs_format
Formats: defines how each stream can be encoded.
small_heap< frame_ref, RS_USER_QUEUE_SIZE *RS_STREAM_COUNT > detached_refs
std::recursive_mutex mutex
int get_frame_height() const override
frameset * clone_frameset(frameset *frameset)
std::chrono::high_resolution_clock::time_point capture_started
const char * get_string(rs_stream value)
rs_timestamp_domain get_frame_timestamp_domain() const
void attach_continuation(rs_stream stream, frame_continuation &&continuation)
const byte * get_frame_data() const override
rs_stream
Streams are different types of data provided by RealSense devices.
void log_callback_start(std::chrono::high_resolution_clock::time_point capture_start_time)
void log_frame_callback_end(frame *frame)
int get_framerate() const
small_heap< frameset, RS_USER_QUEUE_SIZE *RS_STREAM_COUNT > published_sets
void unpublish_frame(frame *frame)
rs_frame_metadata
Types of value provided from the device with each frame.
std::vector< frame > freelist
rs_stream get_stream_type() const override
std::atomic< uint32_t > published_frames_per_stream[RS_STREAM_COUNT]
int get_frame_stride() const override
bool supports_frame_metadata(rs_frame_metadata frame_metadata) const override
int get_frame_framerate() const override
const byte * get_frame_data() const
double get_frame_timestamp() const