4 #ifndef LIBREALSENSE_UNITTESTS_COMMON_H 5 #define LIBREALSENSE_UNITTESTS_COMMON_H 15 #include <condition_variable> 26 #define NOEXCEPT_FALSE 28 #define NOEXCEPT_FALSE noexcept(false) 38 require_error(
std::string message,
bool message_validation=
true) : message(move(message)), validate_error_message(message_validation), err() {}
42 assert(!std::uncaught_exception());
44 if (validate_error_message)
62 assert(!std::uncaught_exception());
100 return a[0]*
b[0] +
a[1]*
b[1] +
a[2]*
b[2];
120 for(
int i=1; i<3; ++i)
REQUIRE( vector[i] == 0.0
f );
141 const float row1[] = {matrix[1], matrix[4], matrix[7]};
142 const float row2[] = {matrix[2], matrix[5], matrix[8]};
157 static const float identity_matrix_3x3[] = {1,0,0, 0,1,0, 0,0,1};
158 for(
int i=0; i<9; ++i)
REQUIRE(
matrix[i] == identity_matrix_3x3[i] );
164 std::chrono::high_resolution_clock::time_point
start_time , end_time;
170 inline void check_fps(
double actual_fps,
double configured_fps)
172 REQUIRE(actual_fps >= configured_fps * 0.9);
188 int lowest_fps_mode = std::numeric_limits<int>::max();
189 for(
auto &
mode : modes)
194 if (
mode.framerate < lowest_fps_mode) lowest_fps_mode =
mode.framerate;
197 std::vector<unsigned long long> last_frame_number;
198 std::vector<unsigned long long> number_of_frames;
202 for (
auto& elem : modes)
204 number_of_frames[elem.stream] = 0;
205 last_frame_number[elem.stream] = 0;
208 const auto actual_frames_to_receive = std::min(max_frames_to_receive, (uint32_t)(max_capture_time_sec* lowest_fps_mode));
209 const auto first_frame_to_capture = (actual_frames_to_receive*0.1);
210 const auto frames_to_capture = (actual_frames_to_receive - first_frame_to_capture);
212 for (
auto i = 0u; i< actual_frames_to_receive; ++i)
216 if (i < first_frame_to_capture)
continue;
218 for (
auto &
mode : modes)
227 if (!duration_per_stream[
mode.stream].is_end_time_initialized && last_frame_number[
mode.stream] != frame_number)
229 last_frame_number[
mode.stream] = frame_number;
230 ++number_of_frames[
mode.stream];
233 if (!duration_per_stream[
mode.stream].is_start_time_initialized && number_of_frames[
mode.stream] >= 1)
235 duration_per_stream[
mode.stream].start_time = std::chrono::high_resolution_clock::now();
236 duration_per_stream[
mode.stream].is_start_time_initialized =
true;
239 if (!duration_per_stream[
mode.stream].is_end_time_initialized && (number_of_frames[
mode.stream] > (0.9 * frames_to_capture)))
241 duration_per_stream[
mode.stream].end_time = std::chrono::high_resolution_clock::now();
242 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(duration_per_stream[
mode.stream].end_time - duration_per_stream[
mode.stream].start_time).
count();
243 auto fps = ((double)number_of_frames[
mode.stream] / duration) * 1000.;
245 duration_per_stream[
mode.stream].is_end_time_initialized =
true;
258 static std::condition_variable
cv;
269 std::lock_guard<std::mutex> lock(cb_mtx);
282 for (
auto& elem :
data->number_of_frames_per_stream)
284 if (elem.second <
data->duration_per_stream[stream_type].actual_frames_to_receive)
294 stop_streaming =
true;
297 std::lock_guard<std::mutex> lk(m);
304 if (
data->duration_per_stream[stream_type].is_end_time_initialized)
310 unsigned num_of_frames = 0;
311 num_of_frames = (++
data->number_of_frames_per_stream[stream_type]);
313 if (num_of_frames >=
data->duration_per_stream[stream_type].actual_frames_to_receive)
315 if (!
data->duration_per_stream[stream_type].is_end_time_initialized)
317 data->duration_per_stream[stream_type].end_time = std::chrono::high_resolution_clock::now();
318 data->duration_per_stream[stream_type].is_end_time_initialized =
true;
325 if ((num_of_frames ==
data->duration_per_stream[stream_type].first_frame_to_capture) && (!
data->duration_per_stream[stream_type].is_start_time_initialized))
327 data->duration_per_stream[stream_type].start_time = std::chrono::high_resolution_clock::now();
328 data->duration_per_stream[stream_type].is_start_time_initialized =
true;
337 inline void test_frame_callback(
rs_device * device, std::initializer_list<stream_mode>& modes, std::map<rs_stream, test_duration>& duration_per_stream)
340 stop_streaming =
false;
343 for(
auto &
mode : modes)
348 data.
duration_per_stream[
mode.stream].actual_frames_to_receive = std::min(max_frames_to_receive, (uint32_t)(max_capture_time_sec*
mode.framerate));
359 std::unique_lock<std::mutex> lk(m);
360 cv.wait(lk, [&]{
return done;});
367 for(
auto &
mode : modes)
386 std::map<rs_stream, test_duration> duration_per_stream;
387 for(
auto &
mode : modes)
389 duration_per_stream.insert(std::pair<rs_stream, test_duration>(
mode.stream,
test_duration()));
398 for(
auto &
mode : modes)
413 for(
auto value : good_values)
421 for(
auto value : bad_values)
void timestamp_callback(rs_device *, rs_timestamp_data, void *)
uint32_t first_frame_to_capture
require_error(std::string message, bool message_validation=true)
~require_no_error() NOEXCEPT_FALSE
uint32_t frames_to_capture
const int max_capture_time_sec
GLint GLint GLsizei GLsizei height
void motion_callback(rs_device *, rs_motion_data, void *)
double rs_get_frame_timestamp(const rs_device *device, rs_stream stream, rs_error **error)
Retrieves time at which the latest frame on a stream was captured.
const void * rs_get_frame_data(const rs_device *device, rs_stream stream, rs_error **error)
Retrieves the contents of the latest frame on a stream.
int rs_is_device_streaming(const rs_device *device, rs_error **error)
Determines if the device is currently streaming.
GLsizei const GLchar *const * string
bool is_end_time_initialized
void rs_delete_context(rs_context *context, rs_error **error)
Frees the relevant context object.
void rs_set_device_option(rs_device *device, rs_option option, double value, rs_error **error)
Sets the current value of a single option.
rs_option
Defines general configuration controls.
const char * rs_get_error_message(const rs_error *error)
Returns static pointer to error message.
void require_cross_product(const float(&r)[3], const float(&a)[3], const float(&b)[3])
std::map< rs_stream, unsigned > number_of_frames_per_stream
void require_zero_vector(const float(&vector)[3])
uint32_t actual_frames_to_receive
Exposes librealsense functionality for C compilers.
rs_stream rs_get_detached_frame_stream_type(const rs_frame_ref *frame, rs_error **error)
Retrieves frame stream type.
const uint32_t max_frames_to_receive
require_error & operator=(const require_error &)=delete
rs_context * rs_create_context(int api_version, rs_error **error)
Creates RealSense context that is required for the rest of the API.
double rs_get_device_option(rs_device *device, rs_option option, rs_error **error)
Retrieves the current value of a single option.
void rs_disable_stream(rs_device *device, rs_stream stream, rs_error **error)
Disables a specific stream.
void rs_set_frame_callback(rs_device *device, rs_stream stream, rs_frame_callback_ptr on_frame, void *user, rs_error **error)
Sets up a frame callback that is called immediately when an image is available, with no synchronizati...
void frame_callback(rs_device *dev, rs_frame_ref *frame, void *user)
void rs_release_frame(rs_device *device, rs_frame_ref *frame, rs_error **error)
Releases frame handle.
GLuint GLuint GLsizei count
Motion data from gyroscope and accelerometer from the microcontroller.
format
Formats: defines how each stream can be encoded. rs_format specifies how a frame is represented in me...
bool validate_error_message
void require_rotation_matrix(const float(&matrix)[9])
static std::condition_variable cv
void test_streaming(rs_device *device, std::initializer_list< stream_mode > modes)
void require_transposed(const float(&a)[9], const float(&b)[9])
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * data
void rs_enable_stream(rs_device *device, rs_stream stream, int width, int height, rs_format format, int framerate, rs_error **error)
Enables a specific stream and requests specific properties.
rs_format
Formats: defines how each stream can be encoded.
float vector_length(const float(&v)[3])
void test_wait_for_frames(rs_device *device, std::initializer_list< stream_mode > &modes, std::map< rs_stream, test_duration > &duration_per_stream)
double rs_get_detached_frame_timestamp(const rs_frame_ref *frame, rs_error **error)
Retrieves timestamp from frame reference.
void test_frame_callback(rs_device *device, std::initializer_list< stream_mode > &modes, std::map< rs_stream, test_duration > &duration_per_stream)
Timestamp data from the motion microcontroller.
unsigned long long rs_get_frame_number(const rs_device *device, rs_stream stream, rs_error **error)
Retrieves frame number.
GLboolean GLboolean GLboolean GLboolean a
GLsizei const GLfloat * value
bool is_start_time_initialized
float dot_product(const float(&a)[3], const float(&b)[3])
void require_identity_matrix(const float(&matrix)[9])
GLboolean GLboolean GLboolean b
~require_error() NOEXCEPT_FALSE
void test_option(rs_device *device, rs_option option, std::initializer_list< int > good_values, std::initializer_list< int > bad_values)
void check_fps(double actual_fps, double configured_fps)
rs_stream
Streams are different types of data provided by RealSense devices.
std::map< rs_stream, test_duration > duration_per_stream
static std::atomic< bool > stop_streaming
void rs_wait_for_frames(rs_device *device, rs_error **error)
Blocks until new frames are available.
void rs_start_device(rs_device *device, rs_error **error)
Begins streaming on all enabled streams for this device.
void rs_stop_device(rs_device *device, rs_error **error)
Ends data acquisition for the specified source providers.
bool operator==(const float3 &a, const float3 &b)
int rs_is_stream_enabled(const rs_device *device, rs_stream stream, rs_error **error)
Determines if a specific stream is enabled.
GLdouble GLdouble GLdouble r
const void * rs_get_detached_frame_data(const rs_frame_ref *frame, rs_error **error)
Retrieves data from frame reference.
std::chrono::high_resolution_clock::time_point start_time