diff --git a/CMakeLists.txt b/CMakeLists.txt index 61706ab..e394b4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,3 +13,8 @@ else() endif() add_subdirectory(samples) + +option(BUILD_TESTS "set run_tests to NO if build tests should be run, set to OFF to skip tests" OFF) +if(BUILD_TESTS) + add_subdirectory(tests) +endif(BUILD_TESTS) diff --git a/samples/playback_sample/playback_sample.cpp b/samples/playback_sample/playback_sample.cpp index d6ba136..28f96c5 100644 --- a/samples/playback_sample/playback_sample.cpp +++ b/samples/playback_sample/playback_sample.cpp @@ -29,7 +29,7 @@ int main(int argc, char* argv[]) string playback_file_name(argv[1]); //create a playback enabled context with a given output file - rs::playback::context context(playback_file_name); + rs::playback::context context(playback_file_name.c_str()); //create a playback enabled device rs::device* device = context.get_device(0); diff --git a/samples/projection_sample/projection_sample.cpp b/samples/projection_sample/projection_sample.cpp index 633aa51..2f5e139 100644 --- a/samples/projection_sample/projection_sample.cpp +++ b/samples/projection_sample/projection_sample.cpp @@ -12,8 +12,8 @@ using namespace std; using namespace rs::core; //helper functions -void get_depth_coordinates_from_rectangle_on_depth_image(custom_image &depthImage, vector &depthCoordinates); -void get_color_coordinates_from_rectangle_on_color_image(custom_image &colorImage, vector &colorCoordinates); +void get_depth_coordinates_from_rectangle_on_depth_image(std::shared_ptr depthImage, vector &depthCoordinates); +void get_color_coordinates_from_rectangle_on_color_image(std::shared_ptr colorImage, vector &colorCoordinates); int main () { @@ -53,13 +53,13 @@ int main () ColorInfo.format = rs::utils::convert_pixel_format(colorFormat); ColorInfo.pitch = color_pixel_size * colorWidth; - custom_image colorImage (&ColorInfo, + std::shared_ptr colorImage(image_interface::create_instance_from_raw_data(&ColorInfo, device->get_frame_data(rs::stream::color), stream_type::color, image_interface::flag::any, device->get_frame_timestamp(rs::stream::color), device->get_frame_number(rs::stream::color), - nullptr, nullptr); + nullptr, nullptr)); image_info DepthInfo; DepthInfo.width = depthWidth; @@ -67,13 +67,13 @@ int main () DepthInfo.format = rs::utils::convert_pixel_format(depthFormat); DepthInfo.pitch = depth_pixel_size * depthWidth; - custom_image depthImage (&DepthInfo, + std::shared_ptr depthImage (image_interface::create_instance_from_raw_data(&DepthInfo, device->get_frame_data(rs::stream::depth), stream_type::depth, image_interface::flag::any, device->get_frame_timestamp(rs::stream::depth), device->get_frame_number(rs::stream::depth), - nullptr, nullptr); + nullptr, nullptr)); /** * MapDepthToColor example. @@ -99,7 +99,7 @@ int main () get_color_coordinates_from_rectangle_on_color_image(colorImage, colorCoordinates); vector mappedDepthCoordinates(colorCoordinates.size()); - if(projection_->map_color_to_depth(&depthImage, colorCoordinates.size(), colorCoordinates.data(), mappedDepthCoordinates.data()) < status_no_error) + if(projection_->map_color_to_depth(depthImage.get(), colorCoordinates.size(), colorCoordinates.data(), mappedDepthCoordinates.data()) < status_no_error) { cerr<<"failed to map the color coordinates to depth" << endl; return -1; @@ -168,9 +168,9 @@ int main () * QueryUVMap Example. * Retrieve the UV map for the specific depth image. The UVMap is a pointF32 array of depth size width*height. */ - auto depthImageInfo = depthImage.query_info(); + auto depthImageInfo = depthImage->query_info(); vector uvmap(depthImageInfo.width * depthImageInfo.height); - if(projection_->query_uvmap(&depthImage, uvmap.data()) < status_no_error) + if(projection_->query_uvmap(depthImage.get(), uvmap.data()) < status_no_error) { cerr<<"failed to query UV map" << endl; return -1; @@ -181,9 +181,9 @@ int main () * Retrieve the inverse UV map for the specific depth image. The inverse UV map maps color coordinates * back to the depth coordinates. The inverse UVMap is a pointF32 array of color size width*height. */ - auto colorImageInfo = colorImage.query_info(); + auto colorImageInfo = colorImage->query_info(); vector invUVmap(colorImageInfo.width * colorImageInfo.height); - if(projection_->query_invuvmap(&depthImage, invUVmap.data()) < status_no_error) + if(projection_->query_invuvmap(depthImage.get(), invUVmap.data()) < status_no_error) { cerr<<"failed to query invariant UV map" << endl; return -1; @@ -195,7 +195,7 @@ int main () * size width*height. The world coordiantes units are in mm. */ vector vertices(depthImageInfo.width * depthImageInfo.height); - if(projection_->query_vertices(&depthImage, vertices.data()) < status_no_error) + if(projection_->query_vertices(depthImage.get(), vertices.data()) < status_no_error) { cerr<<"failed to query vertices" << endl; return -1; @@ -206,7 +206,7 @@ int main () * Get the color pixel for every depth pixel using the UV map, and output a color image, aligned in space * and resolution to the depth image. */ - std::unique_ptr colorImageMappedToDepth = std::unique_ptr(projection_->create_color_image_mapped_to_depth(&depthImage, &colorImage)); + std::unique_ptr colorImageMappedToDepth = std::unique_ptr(projection_->create_color_image_mapped_to_depth(depthImage.get(), colorImage.get())); //use the mapped image... //The application must release the instance after use. (e.g. use smart ptr) @@ -216,7 +216,7 @@ int main () * Map every depth pixel to the color image resolution, and output a depth image, aligned in space * and resolution to the color image. The color image size may be different from original. */ - std::unique_ptr depthImageMappedToColor = std::unique_ptr(projection_->create_depth_image_mapped_to_color(&depthImage, &colorImage)); + std::unique_ptr depthImageMappedToColor = std::unique_ptr(projection_->create_depth_image_mapped_to_color(depthImage.get(), colorImage.get())); //use the mapped image... //The application must release the instance after use. (e.g. use smart ptr) @@ -226,12 +226,18 @@ int main () return 0; } -void get_depth_coordinates_from_rectangle_on_depth_image(custom_image &depthImage, vector &depthCoordinates) +void get_depth_coordinates_from_rectangle_on_depth_image(std::shared_ptr depthImage, vector &depthCoordinates) { - auto depthImageInfo = depthImage.query_info(); + if(!depthImage) + { + cerr<<"cant use null image" << endl; + return; + } + + auto depthImageInfo = depthImage->query_info(); // get read access to the detph image data - const void * depthImageData = depthImage.query_data(); + const void * depthImageData = depthImage->query_data(); if(!depthImageData) { cerr<<"failed to get depth image data" << endl; @@ -254,9 +260,15 @@ void get_depth_coordinates_from_rectangle_on_depth_image(custom_image &depthImag } -void get_color_coordinates_from_rectangle_on_color_image(custom_image &colorImage, vector &colorCoordinates) +void get_color_coordinates_from_rectangle_on_color_image(std::shared_ptr colorImage, vector &colorCoordinates) { - auto colorImageInfo = colorImage.query_info(); + if(!colorImage) + { + cerr<<"cant use null image" << endl; + return; + } + + auto colorImageInfo = colorImage->query_info(); // create a pointF32 array for the color coordinates you would like to project, for example the central rectangle const int startX = colorImageInfo.width / 4; const int endX = (colorImageInfo.width * 3) / 4; diff --git a/samples/record_sample/record_sample.cpp b/samples/record_sample/record_sample.cpp index 4790865..420558b 100644 --- a/samples/record_sample/record_sample.cpp +++ b/samples/record_sample/record_sample.cpp @@ -22,7 +22,7 @@ int main(int argc, char* argv[]) const string output_file(argv[1]); //create a record enabled context with a given output file - rs::record::context context(output_file); + rs::record::context context(output_file.c_str()); if(context.get_device_count() == 0) { diff --git a/samples/sync_utility_sample/sync_utility_sample.cpp b/samples/sync_utility_sample/sync_utility_sample.cpp index a1a4d05..4ad337a 100644 --- a/samples/sync_utility_sample/sync_utility_sample.cpp +++ b/samples/sync_utility_sample/sync_utility_sample.cpp @@ -76,7 +76,7 @@ void frame_handler(rs::frame new_frame) std::cout << "Received "< ctx; + std::unique_ptr ctx; if (argc > 1) { @@ -46,8 +46,7 @@ int main (int argc, char* argv[]) rs::device * device = ctx->get_device(0); //device memory managed by the context // initialize the module - bool is_complete_sample_set_required = false; - std::unique_ptr module(new video_module_mock(is_complete_sample_set_required)); + std::unique_ptr module(new video_module_mock()); // get the first supported module configuration video_module_interface::supported_module_config supported_config = {}; @@ -57,10 +56,9 @@ int main (int argc, char* argv[]) return -1; } - if(supported_config.complete_sample_set_required) + if(supported_config.config_flags & video_module_interface::supported_module_config::flags::time_synced_input) { - cerr<<"error : (complete_sample_set_required == true) is not inmplemented" << endl; - return -1; + cout<<"the sample is not implementing complete sample set syncroniztion"<< endl; } auto device_name = device->get_name(); @@ -139,8 +137,8 @@ int main (int argc, char* argv[]) stream_callback_per_stream[stream] = [stream, &module](rs::frame frame) { correlated_sample_set sample_set; - smart_ptr metadata(new rs::core::metadata()); - smart_ptr image(new lrs_image(frame, image_interface::flag::any, metadata)); + smart_ptr metadata(metadata_interface::create_instance()); + smart_ptr image(image_interface::create_instance_from_librealsense_frame(frame, image_interface::flag::any, metadata)); sample_set[stream] = image; //send asynced sample set to the module @@ -170,9 +168,12 @@ int main (int argc, char* argv[]) if (!supported_motion_config.is_enabled) continue; - actual_config[motion].flags = sample_flags::none; - actual_config[motion].frame_rate = 0; // not implemented by librealsense - actual_config[motion].is_enabled = true; + video_module_interface::actual_motion_sensor_config &actual_motion_config = actual_config[motion]; + actual_motion_config.flags = sample_flags::none; + actual_motion_config.frame_rate = 0; // not implemented by librealsense + actual_motion_config.intrinsics = convert_motion_intrinsics(device->get_motion_intrinsics()); + actual_motion_config.extrinsics = convert_extrinsics(device->get_motion_extrinsics_from(rs::stream::depth)); + actual_motion_config.is_enabled = true; actual_motions.push_back(motion); } @@ -219,7 +220,7 @@ int main (int argc, char* argv[]) rs_intrinsics depth_intrin = device->get_stream_intrinsics(rs::stream::depth); rs_extrinsics extrinsics = device->get_extrinsics(rs::stream::depth, rs::stream::color); projection.reset(rs::core::projection_interface::create_instance(&color_intrin, &depth_intrin, &extrinsics)); - module->set_projection(projection.get()); + actual_config.projection = projection.get(); } // setting the enabled module configuration diff --git a/samples/video_module_sample/video_module_mock.cpp b/samples/video_module_sample/video_module_mock.cpp index d4c17a8..60d0643 100644 --- a/samples/video_module_sample/video_module_mock.cpp +++ b/samples/video_module_sample/video_module_mock.cpp @@ -14,10 +14,8 @@ namespace rs namespace mock { - video_module_mock::video_module_mock(bool is_complete_sample_set_required): - m_processing_handler(nullptr), - m_projection(nullptr), - m_is_complete_sample_set_required(is_complete_sample_set_required) {} + video_module_mock::video_module_mock(): + m_processing_handler(nullptr) {} int32_t video_module_mock::query_module_uid() { @@ -34,7 +32,9 @@ namespace rs std::memcpy(supported_config.device_name, device_name, std::strlen(device_name)); supported_config.concurrent_samples_count = 1; - supported_config.complete_sample_set_required = m_is_complete_sample_set_required; + supported_config.config_flags = static_cast( + supported_module_config::flags::sync_processing_supported | + supported_module_config::flags::async_processing_supported); video_module_interface::supported_image_stream_config & color_desc = supported_config[stream_type::color]; color_desc.min_size.width = 640; @@ -183,11 +183,6 @@ namespace rs return status_no_error; } - void video_module_mock::set_projection(rs::core::projection_interface * projection) - { - m_projection = projection; - } - video_module_control_interface * video_module_mock::query_video_module_control() { return nullptr; diff --git a/samples/video_module_sample/video_module_mock.h b/samples/video_module_sample/video_module_mock.h index c18a018..c3f675e 100644 --- a/samples/video_module_sample/video_module_mock.h +++ b/samples/video_module_sample/video_module_mock.h @@ -17,10 +17,8 @@ namespace rs private: rs::core::video_module_interface::actual_module_config m_current_module_config; rs::core::video_module_interface::processing_event_handler * m_processing_handler; - rs::core::projection_interface * m_projection; - bool m_is_complete_sample_set_required; public: - video_module_mock(bool is_complete_sample_set_required); + video_module_mock(); int32_t query_module_uid(); rs::core::status query_supported_module_config(int32_t idx, rs::core::video_module_interface::supported_module_config &supported_config); @@ -30,7 +28,6 @@ namespace rs rs::core::status process_sample_set_async(rs::core::correlated_sample_set *sample_set); rs::core::status register_event_hander(rs::core::video_module_interface::processing_event_handler *handler); rs::core::status unregister_event_hander(rs::core::video_module_interface::processing_event_handler *handler); - void set_projection(rs::core::projection_interface * projection); rs::core::video_module_control_interface *query_video_module_control(); }; } diff --git a/samples/video_module_sample/video_module_sync_sample.cpp b/samples/video_module_sample/video_module_sync_sample.cpp index e40eb4c..962cde7 100644 --- a/samples/video_module_sample/video_module_sync_sample.cpp +++ b/samples/video_module_sample/video_module_sync_sample.cpp @@ -18,7 +18,7 @@ using namespace rs::mock; int main (int argc, char* argv[]) { // initialize the device from live device or playback file, based on command line parameters. - std::unique_ptr ctx; + std::unique_ptr ctx; int frames_count = 0; if (argc > 1) @@ -54,8 +54,7 @@ int main (int argc, char* argv[]) rs::device * device = ctx->get_device(0); //device memory managed by the context // initialize the module - bool is_complete_sample_set_required = true; - std::unique_ptr module(new video_module_mock(is_complete_sample_set_required)); + std::unique_ptr module(new video_module_mock()); // get the first supported module configuration video_module_interface::supported_module_config supported_config = {}; @@ -142,7 +141,7 @@ int main (int argc, char* argv[]) rs_intrinsics depth_intrin = device->get_stream_intrinsics(rs::stream::depth); rs_extrinsics extrinsics = device->get_extrinsics(rs::stream::depth, rs::stream::color); projection.reset(rs::core::projection_interface::create_instance(&color_intrin, &depth_intrin, &extrinsics)); - module->set_projection(projection.get()); + actual_config.projection = projection.get(); } // setting the enabled module configuration @@ -168,8 +167,8 @@ int main (int argc, char* argv[]) rs::utils::convert_pixel_format(device->get_stream_format(librealsense_stream)), device->get_stream_width(librealsense_stream) }; - smart_ptr metadata(new rs::core::metadata()); - smart_ptr image(new custom_image(&info, + smart_ptr metadata(metadata_interface::create_instance()); + smart_ptr image(image_interface::create_instance_from_raw_data(&info, device->get_frame_data(librealsense_stream), stream, image_interface::flag::any, diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index efd4b6f..2cb4ee9 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 2.8.9) project(realsense_sdk) -include(ExternalProject) if(CMAKE_USE_INTEL_COMPILER EQUAL 1) MESSAGE("--------- Using Intel compiler------------") @@ -41,8 +40,7 @@ add_definitions(-Wno-unused-variable) add_definitions(-Wno-reorder) add_definitions(-Werror) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) @@ -95,4 +93,3 @@ add_subdirectory(src/utilities) add_subdirectory(src/core) add_subdirectory(src/tools) add_subdirectory(src/cameras) - diff --git a/sdk/CMakeVersion b/sdk/CMakeVersion index 15d14a0..c76dec7 100644 --- a/sdk/CMakeVersion +++ b/sdk/CMakeVersion @@ -1,4 +1,4 @@ set(SDK_VERSION_MAJOR 0 ) set(SDK_VERSION_MINOR 2 ) -set(SDK_VERSION_COMMIT_NUMBER 2 ) +set(SDK_VERSION_COMMIT_NUMBER 3 ) set(SDK_VERSION_COMMIT_ID 0 ) diff --git a/sdk/include/rs/core/context.h b/sdk/include/rs/core/context.h index 59edc13..e1b3324 100644 --- a/sdk/include/rs/core/context.h +++ b/sdk/include/rs/core/context.h @@ -3,6 +3,7 @@ #pragma once #include +#include "context_interface.h" namespace rs { @@ -11,40 +12,26 @@ namespace rs /** For Context documentation see rs.hpp(librealsense). */ - class context + class context : public context_interface { - protected: - rs_context * handle; - context(const context &) = delete; - context & operator = (const context &) = delete; public: - context() - { - rs_error * e = nullptr; - handle = rs_create_context(RS_API_VERSION, &e); - rs::error::handle(e); - } - - virtual ~context() - { - rs_delete_context(handle, nullptr); - } + context() {} + virtual ~context() {} virtual int get_device_count() const { - rs_error * e = nullptr; - auto r = rs_get_device_count(handle, &e); - rs::error::handle(e); - return r; + return m_context.get_device_count(); } virtual rs::device * get_device(int index) { - rs_error * e = nullptr; - auto r = rs_get_device(handle, index, &e); - rs::error::handle(e); - return (rs::device *)r; + return m_context.get_device(index); } - }; + + protected: + rs::context m_context; + context(const context &) = delete; + context & operator = (const context &) = delete; + }; } } diff --git a/sdk/include/rs/core/context_interface.h b/sdk/include/rs/core/context_interface.h new file mode 100644 index 0000000..1b94ecf --- /dev/null +++ b/sdk/include/rs/core/context_interface.h @@ -0,0 +1,29 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2016 Intel Corporation. All Rights Reserved. + +#pragma once +#include + +namespace rs +{ + namespace core + { + class context_interface + { + public: + virtual ~context_interface() {} + /** + @brief determine number of connected devices + @return the count of devices + */ + virtual int get_device_count() const = 0; + + /** + @brief retrieve connected device by index + @param[in] index the zero based index of device to retrieve + @return the requested device + */ + virtual rs::device * get_device(int index) = 0; + }; + } +} diff --git a/sdk/include/rs/core/image_interface.h b/sdk/include/rs/core/image_interface.h index 139cc5e..01090e3 100644 --- a/sdk/include/rs/core/image_interface.h +++ b/sdk/include/rs/core/image_interface.h @@ -7,7 +7,11 @@ #include "types.h" namespace rs -{ +{ /** + * forward declaraion of librealsense frame. + */ + class frame; + namespace core { /** @@ -90,6 +94,54 @@ namespace rs virtual status convert_to(rotation rotation, rs::utils::smart_ptr & converted_image) = 0; virtual ~image_interface() {} + + /** + * @brief create_instance_from_librealsense_frame. + * sdk image implementation for a frame defined by librealsense. + * takes ownership on the frame. + * @param frame - frame object defined by librealsense (rs::frame) + * @param flags - optional flags, place holder for future options + * @param metadata - image extended metadata + * @return image_interface object + */ + static image_interface * create_instance_from_librealsense_frame(rs::frame& frame, + flag flags, + rs::utils::smart_ptr metadata); + + /** + * @brief The data_releaser_interface class + * optional custom deallocation method to be called by the image destructor. + */ + class data_releaser_interface + { + public: + virtual void release() = 0; + virtual ~data_releaser_interface() {} + }; + + /** + * @brief create_instance_from_raw_data + * sdk image implementation from raw data, where the user provides an allocated image data and + * an optional image deallocation method with the data_releaser_interface, if no deallocation method is provided, + * it assumes that the user is handling memory deallocation outside of the custom image class. + * @param info - info required to successfully traverse the image data/ + * @param data - the image raw data. + * @param stream - the stream type. + * @param flags - optional flags, place holder for future options. + * @param time_stamp - the timestamp of the image, in milliseconds since the device was started. + * @param frame_number - the number of the image, since the device was started. + * @param metadata - image extended metadata. + * @param data_releaser - optional data releaser, if null, no deallocation is done. + * @return image_interface object + */ + static image_interface * create_instance_from_raw_data(image_info * info, + const void * data, + stream_type stream, + image_interface::flag flags, + double time_stamp, + uint64_t frame_number, + rs::utils::smart_ptr metadata, + rs::utils::smart_ptr data_releaser); }; } } diff --git a/sdk/include/rs/core/metadata_interface.h b/sdk/include/rs/core/metadata_interface.h index b09893a..d37e0ac 100644 --- a/sdk/include/rs/core/metadata_interface.h +++ b/sdk/include/rs/core/metadata_interface.h @@ -53,6 +53,8 @@ namespace rs virtual status query_buffer(int32_t id, uint8_t * buffer, int32_t size) = 0; virtual ~metadata_interface() {} + + static metadata_interface * create_instance(); }; } } diff --git a/sdk/include/rs/core/projection_interface.h b/sdk/include/rs/core/projection_interface.h index 6907afa..e3244f6 100644 --- a/sdk/include/rs/core/projection_interface.h +++ b/sdk/include/rs/core/projection_interface.h @@ -8,7 +8,6 @@ #pragma once #include "rs/core/status.h" #include "rs/core/types.h" -#include "custom_image.h" #include "rs/core/image_interface.h" extern "C" { diff --git a/sdk/include/rs/core/types.h b/sdk/include/rs/core/types.h index 860d53c..5201af6 100644 --- a/sdk/include/rs/core/types.h +++ b/sdk/include/rs/core/types.h @@ -94,7 +94,20 @@ namespace rs { none = 0, // Rectilinear images, no distortion compensation required modified_brown_conrady = 1, // Equivalent to Brown-Conrady distortion, except that tangential distortion is applied to radially distorted points - inverse_brown_conrady = 2 // Equivalent to Brown-Conrady distortion, except undistorts image instead of distorting it + inverse_brown_conrady = 2, // Equivalent to Brown-Conrady distortion, except undistorts image instead of distorting it + distortion_ftheta = 3 + }; + + struct motion_device_intrinsics + { + float bias[3]; + float scale[3]; + }; + + struct motion_intrinsics + { + motion_device_intrinsics gyro; + motion_device_intrinsics acc; }; struct intrinsics diff --git a/sdk/include/rs/core/video_module_interface.h b/sdk/include/rs/core/video_module_interface.h index c30f9f2..30614b9 100644 --- a/sdk/include/rs/core/video_module_interface.h +++ b/sdk/include/rs/core/video_module_interface.h @@ -45,7 +45,7 @@ namespace rs float minimal_frame_rate; /* minimal operetional frame rate */ float ideal_frame_rate; /* frame rate for ideal operation */ sample_flags flags; /* optional supported flags */ - bool is_enabled; /* is the indexed motion sensor is enabled, defaults to 0 = false */ + bool is_enabled; /* is the indexed motion sensor is enabled, defaults to 0 = false */ // range }; @@ -55,11 +55,20 @@ namespace rs */ struct supported_module_config { - supported_image_stream_config image_streams_configs[static_cast(stream_type::max)]; /* requested stream characters, index is stream_type*/ - supported_motion_sensor_config motion_sensors_configs[static_cast(motion_type::max)]; /* requested motion sample, index is motion_type*/ - char device_name[256]; /* requested device name */ - uint32_t concurrent_samples_count; /* requested number of concurrent samples the module can process */ - bool complete_sample_set_required; /* requested streams will be delivered only when all the streams are ready */ + enum flags + { + time_synced_input = 0x1, /* this configuration requires time synced samples set + with all the requested streams and motion samples to operate. */ + accept_unmatch_samples = 0x2, /* complete sample sets are required, but its not mandatory. */ + async_processing_supported = 0x4, /* this configuration supports async sample set processing */ + sync_processing_supported = 0x8 /* this configuration supports sync sample set processing */ + }; + + supported_image_stream_config image_streams_configs[static_cast(stream_type::max)]; /* requested stream characters, index is stream_type*/ + supported_motion_sensor_config motion_sensors_configs[static_cast(motion_type::max)]; /* requested motion sample, index is motion_type*/ + char device_name[256]; /* requested device name */ + uint32_t concurrent_samples_count; /* requested number of concurrent samples the module can process */ + flags config_flags; /* mode of operation flags */ __inline supported_image_stream_config &operator[](stream_type stream) { return image_streams_configs[static_cast(stream)];} __inline supported_motion_sensor_config &operator[](motion_type motion) { return motion_sensors_configs[static_cast(motion)];} @@ -87,11 +96,11 @@ namespace rs */ struct actual_motion_sensor_config { - float frame_rate; /* actual configured frame rate */ - sample_flags flags; /* actual motion sensor flags */ - bool is_enabled; /* is the indexed motion sensor is enabled, defaults to 0 = false */ - // range - // intrinsics + float frame_rate; /* actual configured frame rate */ + sample_flags flags; /* actual motion sensor flags */ + bool is_enabled; /* is the indexed motion sensor is enabled, defaults to 0 = false */ + rs::core::motion_intrinsics intrinsics; /* motion intrinsic data */ + rs::core::extrinsics extrinsics; /* motion extrinsics data (see actual_image_steam_config)*/ }; /** @@ -100,9 +109,12 @@ namespace rs */ struct actual_module_config { - actual_image_stream_config image_streams_configs[static_cast(stream_type::max)]; /* requested stream characters, index is stream_type*/ - actual_motion_sensor_config motion_sensors_configs[static_cast(motion_type::max)]; /* requested motion sersors, index is motion_type*/ - rs::core::device_info device_info; /* requested device info */ + actual_image_stream_config image_streams_configs[static_cast(stream_type::max)]; /* requested stream characters, index is stream_type*/ + actual_motion_sensor_config motion_sensors_configs[static_cast(motion_type::max)]; /* requested motion sersors, index is motion_type*/ + rs::core::device_info device_info; /* requested device info */ + projection_interface * projection; /* projection object for mappings between color and + depth coordinate systems. the objects memory is + handled outside of the video module.*/ __inline actual_image_stream_config &operator[](stream_type stream) { return image_streams_configs[static_cast(stream)]; } __inline actual_motion_sensor_config &operator[](motion_type motion) { return motion_sensors_configs[static_cast(motion)]; } @@ -179,13 +191,6 @@ namespace rs */ virtual status unregister_event_hander(processing_event_handler * handler) = 0; - - /** - * @brief Pass projection object for mappings between color and depth coordinate systems - * @param[in] projection The projection object. - */ - virtual void set_projection(projection_interface* /*projection*/) { } - /** * @brief Returns an optional module controller * @return video_module_control_interface The control object diff --git a/sdk/include/rs/playback/playback_context.h b/sdk/include/rs/playback/playback_context.h index 4c9672a..70612f5 100644 --- a/sdk/include/rs/playback/playback_context.h +++ b/sdk/include/rs/playback/playback_context.h @@ -2,10 +2,8 @@ // Copyright(c) 2016 Intel Corporation. All Rights Reserved. #pragma once -#include #include #include "rs/core/context.h" -#include "rs/core/status.h" namespace rs { @@ -15,14 +13,14 @@ namespace rs /** This class provides access to recorded stream data wrraped as a rs::device with playback abilities extentions. */ - class context : public rs::core::context + class context : public rs::core::context_interface { public: - context(const std::string& file_path); + context(const char * file_path); ~context(); /** - @brief Returns number of available devices. + @brief Returns number of available devices. currently supporting a single device. */ int get_device_count() const; @@ -40,8 +38,8 @@ namespace rs device * get_playback_device(); private: - std::unique_ptr m_device; - bool m_init_status; + rs_device ** m_devices; + bool m_init_status; }; } } diff --git a/sdk/include/rs/playback/playback_device.h b/sdk/include/rs/playback/playback_device.h index 8881071..c8d6d5d 100644 --- a/sdk/include/rs/playback/playback_device.h +++ b/sdk/include/rs/playback/playback_device.h @@ -39,7 +39,9 @@ namespace rs */ bool set_frame_by_timestamp(uint64_t timestamp); /** - @brief Sets the state of the real time flag. + @brief Sets the state of the real time flag. Enabled by default. + Non realtime mode delivers all samples without any sample drop, according to the application sample processing latency. + This mode is designed for a single consumer, as the next sample delivery is blocked by current sample processing, faster or slower than original camera FPS. @param[in] realtime The requsted state. */ void set_real_time(bool realtime); diff --git a/sdk/include/rs/record/record_context.h b/sdk/include/rs/record/record_context.h index f9f6550..46a19c7 100644 --- a/sdk/include/rs/record/record_context.h +++ b/sdk/include/rs/record/record_context.h @@ -2,8 +2,6 @@ // Copyright(c) 2016 Intel Corporation. All Rights Reserved. #pragma once -#include -#include #include #include "rs/core/context.h" @@ -18,7 +16,7 @@ namespace rs class context : public rs::core::context { public: - context(const std::string& file_path); + context(const char * file_path); virtual ~context(); /** @@ -36,7 +34,7 @@ namespace rs device * get_record_device(int index); private: - std::vector> m_devices; + rs_device ** m_devices; }; } } diff --git a/sdk/include/rs/utils/cyclic_array.h b/sdk/include/rs/utils/cyclic_array.h index 267fcf3..2dfd5c3 100644 --- a/sdk/include/rs/utils/cyclic_array.h +++ b/sdk/include/rs/utils/cyclic_array.h @@ -1,24 +1,24 @@ #pragma once #include +#include namespace rs { namespace utils { template - class cyclic_array - { - public: + class cyclic_array { + public: explicit cyclic_array(unsigned int capacity = 0) : m_head(0), m_tail(0), m_contents_size(0), m_array_size(capacity), m_array(capacity) { - } - ~cyclic_array() - { m_array.clear(); } - void push_back(const T& new_element) { + + if (m_array_size == 0) + throw std::out_of_range("Can not push to the array of size 0!"); + // move head to next element if the array is full and we // are going to add another element, so now the head // will point to the next element, and we can @@ -52,21 +52,15 @@ namespace rs T& front() { if (m_contents_size == 0) - throw "Can not reference an empty array!"; + { + throw std::out_of_range("Can not reference an empty array!"); + } return m_array[m_head]; } unsigned int size() { return m_contents_size; } - void reset(unsigned int capacity) - { - m_head = m_tail = m_contents_size = 0; - m_array.clear(); - m_array.resize(capacity); - m_array_size = capacity; - } - private: std::vector m_array; diff --git a/sdk/include/rs/utils/librealsense_conversion_utils.h b/sdk/include/rs/utils/librealsense_conversion_utils.h index 66e3dc7..f28dbe4 100644 --- a/sdk/include/rs/utils/librealsense_conversion_utils.h +++ b/sdk/include/rs/utils/librealsense_conversion_utils.h @@ -103,10 +103,30 @@ namespace rs case rs::distortion::none : return rs::core::distortion_type::none; case rs::distortion::modified_brown_conrady : return rs::core::distortion_type::modified_brown_conrady ; case rs::distortion::inverse_brown_conrady : return rs::core::distortion_type::inverse_brown_conrady; + case rs::distortion::distortion_ftheta : return rs::core::distortion_type::distortion_ftheta; } return static_cast(-1); } + static rs::core::motion_device_intrinsics convert_motion_device_intrinsics(rs_motion_device_intrinsics lrs_motion_device_intrinsics) + { + rs::core::motion_device_intrinsics framework_motion_device_intrinsics = {}; + std::memcpy(framework_motion_device_intrinsics.bias, lrs_motion_device_intrinsics.bias, sizeof(framework_motion_device_intrinsics.bias)); + std::memcpy(framework_motion_device_intrinsics.scale, lrs_motion_device_intrinsics.scale, sizeof(framework_motion_device_intrinsics.scale)); + return framework_motion_device_intrinsics; + } + + static rs::core::motion_intrinsics convert_motion_intrinsics(rs::motion_intrinsics lrs_motion_intrinsics) + { + rs::core::motion_intrinsics framework_motion_intrinsics = + { + convert_motion_device_intrinsics(lrs_motion_intrinsics.gyro), + convert_motion_device_intrinsics(lrs_motion_intrinsics.acc) + }; + + return framework_motion_intrinsics ; + } + static rs::core::intrinsics convert_intrinsics(rs::intrinsics lrs_intrinsics) { rs::core::intrinsics framework_intrinsics = diff --git a/sdk/include/rs/utils/smart_ptr.h b/sdk/include/rs/utils/smart_ptr.h index 3af2310..26c756f 100644 --- a/sdk/include/rs/utils/smart_ptr.h +++ b/sdk/include/rs/utils/smart_ptr.h @@ -42,6 +42,20 @@ namespace rs other.m_reference_count = nullptr; } + /** + * templated K smart_ptr friend class and alias constructor allows assignments of + * smart ptr with derived type into a smart ptr of base type. + */ + template friend class smart_ptr; + template + smart_ptr(const smart_ptr& other) : m_object(other.m_object), + m_reference_count(other.m_reference_count) + { + if(m_reference_count) + { + add_ref(); + } + } smart_ptr& operator=(const smart_ptr & other) noexcept { diff --git a/sdk/include/rs/utils/sync_utility.h b/sdk/include/rs/utils/sync_utility.h index c9accca..e40f716 100644 --- a/sdk/include/rs/utils/sync_utility.h +++ b/sdk/include/rs/utils/sync_utility.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "rs_sdk.h" #include "rs/utils/cyclic_array.h" diff --git a/sdk/include/rs_core.h b/sdk/include/rs_core.h index a0cce6c..11d6099 100644 --- a/sdk/include/rs_core.h +++ b/sdk/include/rs_core.h @@ -3,6 +3,7 @@ #pragma once +#include "rs/core/context_interface.h" #include "rs/core/context.h" #include "rs/core/correlated_sample_set.h" #include "rs/core/image_interface.h" @@ -12,7 +13,4 @@ #include "rs/core/types.h" #include "rs/core/video_module_control_interface.h" #include "rs/core/video_module_interface.h" -#include "rs/core/custom_image.h" -#include "rs/core/lrs_image.h" #include "rs/core/projection_interface.h" -#include "rs/core/metadata.h" diff --git a/sdk/include/rs_sdk_version.h b/sdk/include/rs_sdk_version.h index 2fd4087..b56a928 100644 --- a/sdk/include/rs_sdk_version.h +++ b/sdk/include/rs_sdk_version.h @@ -1,5 +1,5 @@ #define SDK_VER_MAJOR 0 #define SDK_VER_MINOR 2 -#define SDK_VER_COMMIT_NUMBER 2 +#define SDK_VER_COMMIT_NUMBER 3 #define SDK_VER_COMMIT_ID 0 -#define SDK_VERSION_STRING static char version_id[] = "VERSION: 0.2.2.0"; +#define SDK_VERSION_STRING static char version_id[] = "VERSION: 0.2.3.0"; diff --git a/sdk/src/cameras/include/file_types.h b/sdk/src/cameras/include/file_types.h index 7a8c8ee..481f566 100644 --- a/sdk/src/cameras/include/file_types.h +++ b/sdk/src/cameras/include/file_types.h @@ -3,8 +3,6 @@ #pragma once #include -#include "rs/core/image_interface.h" -#include "image/librealsense_image_utils.h" /** This macro constructs a UID given four byte values. The arguments will be evaluated exactly once, cast to unsigned int and shifted into one of the @@ -41,18 +39,19 @@ namespace rs enum chunk_id { - chunk_device_info = 1, - chunk_stream_info = 2, - chunk_properties = 3, - chunk_profile = 4, - chunk_serializeable = 5, - chunk_frame_info = 6,//frame stream type, frame width, frame height, frame format etc. - chunk_sample_data = 7,//rs_timestamp_data / rs_motion_data / image buffer - chunk_image_metadata = 8, - chunk_frame_indexing = 9, - chunk_sw_info = 10, - chunk_sample_info = 11,//sample type, capture time, offset - chunk_capabilities = 12 + chunk_device_info = 1, + chunk_stream_info = 2, + chunk_properties = 3, + chunk_profile = 4, + chunk_serializeable = 5, + chunk_frame_info = 6,//frame stream type, frame width, frame height, frame format etc. + chunk_sample_data = 7,//rs_timestamp_data / rs_motion_data / image buffer + chunk_image_metadata = 8, + chunk_frame_indexing = 9, + chunk_sw_info = 10, + chunk_sample_info = 11,//sample type, capture time, offset + chunk_capabilities = 12, + chunk_motion_intrinsics = 13 }; struct device_cap @@ -77,10 +76,12 @@ namespace rs struct device_info { - char name[224]; // device name - char serial[32]; // serial number - char firmware[32]; // firmware version - char usb_port_id[256]; // firmware version + char name[224]; + char serial[32]; + char camera_firmware[32]; + char usb_port_id[256]; + char adapter_board_firmware[32]; + char motion_module_firmware[32]; }; struct sw_info @@ -130,15 +131,15 @@ namespace rs int width; int height; rs_format format; - int stride_x; - int stride_y; - float bpp; + int stride; + int bpp; rs_stream stream; - int number; + unsigned long long number; double time_stamp; long long system_time; int framerate; uint32_t index_in_stream; + rs_timestamp_domain time_stamp_domain; }; struct frame_sample : public sample @@ -154,8 +155,7 @@ namespace rs memset(&finfo, 0, sizeof(frame_info)); finfo.width = ref->get_frame_width(); finfo.height = ref->get_frame_height(); - finfo.stride_x = ref->get_frame_stride_x(); - finfo.stride_y = ref->get_frame_stride_y(); + finfo.stride = ref->get_frame_stride(); finfo.bpp = ref->get_frame_bpp(); finfo.format = ref->get_frame_format(); finfo.stream = stream; @@ -172,9 +172,8 @@ namespace rs memset(&finfo, 0, sizeof(frame_info)); finfo.width = si.get_intrinsics().width; finfo.height = si.get_intrinsics().height; - finfo.stride_x = si.get_intrinsics().width;//rs_stream_interface is missing stride and bpp data - finfo.stride_y = si.get_intrinsics().height;//rs_stream_interface is missing stride and bpp data - finfo.bpp = image_utils::get_pixel_size(si.get_format()); + finfo.stride = si.get_frame_stride(); + finfo.bpp = si.get_frame_bpp(); finfo.format = si.get_format(); finfo.stream = stream; finfo.number = si.get_frame_number(); @@ -186,7 +185,7 @@ namespace rs frame_sample * copy() { auto rv = new frame_sample(this); - size_t size = finfo.stride_x * finfo.bpp * finfo.stride_y; + size_t size = finfo.stride * finfo.height * (finfo.bpp / 8); auto data_clone = new uint8_t[size]; memcpy(data_clone, data, size); rv->data = data_clone; @@ -204,6 +203,7 @@ namespace rs rs_intrinsics rect_intrinsics; rs_extrinsics extrinsics; float depth_scale; + rs_extrinsics motion_extrinsics; }; struct stream_info @@ -274,6 +274,12 @@ namespace rs file_types::file_header data; int32_t reserved[25]; }; + + struct motion_intrinsics + { + rs_motion_intrinsics data; + int32_t reserved[32]; + }; }; } } diff --git a/sdk/src/cameras/playback/CMakeLists.txt b/sdk/src/cameras/playback/CMakeLists.txt index 4c877f6..c8d411c 100644 --- a/sdk/src/cameras/playback/CMakeLists.txt +++ b/sdk/src/cameras/playback/CMakeLists.txt @@ -17,6 +17,8 @@ set(SOURCE_FILES_BASE playback_context.cpp playback_device_impl.cpp rs_stream_impl.cpp + disk_read.cpp + include/disk_read.h include/rs_stream_impl.h include/disk_read_factory.h include/disk_read_base.h @@ -29,16 +31,18 @@ set(SOURCE_FILES_BASE ) set(SOURCE_FILES_LINUX - include/linux/disk_read_linux.h - linux/disk_read_linux.cpp + include/linux/v1/file_types.h + include/linux/v1/disk_read.h + include/linux/v1/conversions.h + linux/v1/disk_read.cpp ) set(SOURCE_FILES_WINDOWS - include/windows/conversions.h - include/windows/file_types_windows.h - include/windows/disk_read_windows.h - windows/conversions.cpp - windows/disk_read_windows.cpp + include/windows/v10/conversions.h + include/windows/v10/file_types.h + include/windows/v10/disk_read.h + windows/v10/conversions.cpp + windows/v10/disk_read.cpp ) set(SOURCE_FILES_FILE diff --git a/sdk/src/cameras/playback/disk_read.cpp b/sdk/src/cameras/playback/disk_read.cpp new file mode 100644 index 0000000..34fe299 --- /dev/null +++ b/sdk/src/cameras/playback/disk_read.cpp @@ -0,0 +1,193 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2016 Intel Corporation. All Rights Reserved + +#include "disk_read.h" +#include "file/file.h" +#include "rs/utils/log_utils.h" + +namespace rs +{ + namespace playback + { + disk_read::~disk_read(void) + { + LOG_FUNC_SCOPE(); + pause(); + } + + core::status disk_read::read_headers() + { + /* Get the file header */ + m_file_data_read->set_position(0, core::move_method::begin); + uint32_t nbytesRead = 0; + unsigned long nbytesToRead = 0; + core::file_types::disk_format::file_header fh; + m_file_data_read->read_bytes(&fh, sizeof(fh), nbytesRead); + m_file_header = fh.data; + if (nbytesRead < sizeof(m_file_header)) return core::status_item_unavailable; + if (m_file_header.id != UID('R', 'S', 'L', '2')) return core::status_param_unsupported; + + /* Get all chunks */ + for (;;) + { + core::file_types::chunk_info chunk = {}; + m_file_data_read->read_bytes(&chunk, sizeof(chunk), nbytesRead); + if (nbytesRead < sizeof(chunk)) break; + if (chunk.id == core::file_types::chunk_id::chunk_sample_info) break; + nbytesToRead = chunk.size; + switch (chunk.id) + { + case core::file_types::chunk_id::chunk_device_info: + { + core::file_types::disk_format::device_info dinfo; + m_file_data_read->read_bytes(&dinfo, std::min(nbytesToRead, (unsigned long)sizeof(dinfo)), nbytesRead); + m_device_info = dinfo.data; + nbytesToRead -= nbytesRead; + LOG_INFO("read device info chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + } + break; + case core::file_types::chunk_id::chunk_properties: + do + { + core::file_types::device_cap devcap = {}; + m_file_data_read->read_bytes(&devcap, std::min(nbytesToRead, (unsigned long)sizeof(devcap)), nbytesRead); + m_properties[devcap.label] = devcap.value; + nbytesToRead -= nbytesRead; + } + while (nbytesToRead > 0 && nbytesRead > 0); + LOG_INFO("read properties chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + break; + case core::file_types::chunk_id::chunk_serializeable: + { + rs_option label = (rs_option)0; + m_file_data_read->read_bytes(&label, std::min(nbytesToRead, (unsigned long)sizeof(label)), nbytesRead); + nbytesToRead -= nbytesRead; + std::vector data(nbytesToRead); + m_file_data_read->read_bytes(data.data(), nbytesToRead, nbytesRead); + nbytesToRead -= nbytesRead; + LOG_INFO("read serializeable chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + } + break; + case core::file_types::chunk_id::chunk_stream_info: + for (int i = 0; i < m_file_header.nstreams; i++) + { + core::file_types::disk_format::stream_info stream_info1 = {}; + m_file_data_read->read_bytes(&stream_info1, std::min(nbytesToRead, (unsigned long)sizeof(stream_info1)), nbytesRead); + m_streams_infos[stream_info1.data.stream] = stream_info1.data; + nbytesToRead -= nbytesRead; + } + LOG_INFO("read stream info chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + break; + case core::file_types::chunk_id::chunk_motion_intrinsics: + { + core::file_types::disk_format::motion_intrinsics mi; + m_file_data_read->read_bytes(&mi, std::min(nbytesToRead, (unsigned long)sizeof(mi)), nbytesRead); + m_motion_intrinsics = mi.data; + nbytesToRead -= nbytesRead; + LOG_INFO("read motion intrinsics chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + } + break; + case core::file_types::chunk_id::chunk_sw_info: + { + core::file_types::disk_format::sw_info swinfo; + m_file_data_read->read_bytes(&swinfo, std::min(nbytesToRead, (unsigned long)sizeof(swinfo)), nbytesRead); + m_sw_info = swinfo.data; + nbytesToRead -= nbytesRead; + LOG_INFO("read sw info chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + } + break; + case core::file_types::chunk_id::chunk_capabilities: + { + std::vector caps(chunk.size / sizeof(rs_capabilities)); + m_file_data_read->read_bytes(caps.data(), chunk.size, nbytesRead); + m_capabilities = caps; + nbytesToRead -= nbytesRead; + LOG_INFO("read capabilities chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + } + break; + default: + std::vector data(nbytesToRead); + m_file_data_read->read_bytes(&data[0], nbytesToRead, nbytesRead); + m_unknowns[chunk.id] = data; + nbytesToRead -= nbytesRead; + LOG_INFO("read unknown chunk " << (nbytesToRead == 0 ? "succeeded" : "failed") << "chunk id - " << chunk.id) + } + if (nbytesToRead > 0) return core::status_item_unavailable; + } + return core::status_no_error; + } + + void disk_read::index_next_samples(uint32_t number_of_samples) + { + if (m_is_index_complete) return; + + std::lock_guard guard(m_mutex); + + for (uint32_t index = 0; index < number_of_samples;) + { + core::file_types::chunk_info chunk = {}; + uint32_t nbytesRead = 0; + m_file_indexing->read_bytes(&chunk, sizeof(chunk), nbytesRead); + if (nbytesRead < sizeof(chunk) || chunk.size <= 0 || chunk.size > 100000000 /*invalid chunk*/) + { + m_is_index_complete = true; + LOG_INFO("samples indexing is done") + break; + } + if(chunk.id == core::file_types::chunk_id::chunk_sample_info) + { + core::file_types::disk_format::sample_info si; + m_file_indexing->read_bytes(&si, std::min((long unsigned)chunk.size, (unsigned long)sizeof(si)), nbytesRead); + auto sample_info = si.data; + core::file_types::chunk_info chunk2 = {}; + m_file_indexing->read_bytes(&chunk2, sizeof(chunk2), nbytesRead); + switch(sample_info.type) + { + case core::file_types::sample_type::st_image: + { + core::file_types::disk_format::frame_info fi = {}; + m_file_indexing->read_bytes(&fi, std::min((long unsigned)chunk2.size, (unsigned long)sizeof(fi)), nbytesRead); + core::file_types::frame_info frame_info = fi.data; + frame_info.index_in_stream = m_image_indices[frame_info.stream].size(); + m_image_indices[frame_info.stream].push_back(m_samples_desc.size()); + m_samples_desc.push_back(std::make_shared(frame_info, sample_info)); + ++index; + LOG_VERBOSE("frame sample indexed, sample time - " << sample_info.capture_time) + break; + } + case core::file_types::sample_type::st_motion: + { + core::file_types::disk_format::motion_data md = {}; + m_file_indexing->read_bytes(&md, std::min((long unsigned)chunk2.size, (unsigned long)sizeof(md)), nbytesRead); + rs_motion_data motion_data = md.data; + m_samples_desc.push_back(std::make_shared(motion_data, sample_info)); + ++index; + LOG_VERBOSE("motion sample indexed, sample time - " << sample_info.capture_time) + break; + } + case core::file_types::sample_type::st_time: + { + core::file_types::disk_format::time_stamp_data tsd = {}; + m_file_indexing->read_bytes(&tsd, std::min((long unsigned)chunk2.size, (unsigned long)sizeof(tsd)), nbytesRead); + rs_timestamp_data time_stamp_data = tsd.data; + m_samples_desc.push_back(std::make_shared(time_stamp_data, sample_info)); + ++index; + LOG_VERBOSE("time stamp sample indexed, sample time - " << sample_info.capture_time) + break; + } + } + } + else + { + m_file_indexing->set_position(chunk.size, core::move_method::current); + continue; + } + } + } + + int32_t disk_read::size_of_pitches(void) + { + return 0; + } + } +} diff --git a/sdk/src/cameras/playback/disk_read_base.cpp b/sdk/src/cameras/playback/disk_read_base.cpp index ac3f1f5..8f583b0 100644 --- a/sdk/src/cameras/playback/disk_read_base.cpp +++ b/sdk/src/cameras/playback/disk_read_base.cpp @@ -425,6 +425,10 @@ status disk_read_base::read_image_buffer(std::shared_ptrset_position(nbytesToRead, move_method::current); } nbytesToRead = 0; diff --git a/sdk/src/cameras/playback/include/linux/disk_read_linux.h b/sdk/src/cameras/playback/include/disk_read.h similarity index 72% rename from sdk/src/cameras/playback/include/linux/disk_read_linux.h rename to sdk/src/cameras/playback/include/disk_read.h index 3d45a7b..39756fc 100644 --- a/sdk/src/cameras/playback/include/linux/disk_read_linux.h +++ b/sdk/src/cameras/playback/include/disk_read.h @@ -8,11 +8,11 @@ namespace rs { namespace playback { - class disk_read_linux : public disk_read_base + class disk_read : public disk_read_base { public: - disk_read_linux(const char *file_name) : disk_read_base(file_name) {} - virtual ~disk_read_linux(void); + disk_read(const char *file_name) : disk_read_base(file_name) {} + virtual ~disk_read(void); protected: virtual rs::core::status read_headers() override; virtual void index_next_samples(uint32_t number_of_samples) override; diff --git a/sdk/src/cameras/playback/include/disk_read_base.h b/sdk/src/cameras/playback/include/disk_read_base.h index 0bbdd71..b84c643 100644 --- a/sdk/src/cameras/playback/include/disk_read_base.h +++ b/sdk/src/cameras/playback/include/disk_read_base.h @@ -47,6 +47,7 @@ namespace rs virtual int32_t query_coordinate_system() override { return m_file_header.coordinate_system; } virtual const core::file_types::device_info& get_device_info() override { return m_device_info; } virtual std::map get_streams_infos() override {return m_streams_infos; } + virtual rs_motion_intrinsics get_motion_intrinsics() { return m_motion_intrinsics; } virtual std::map get_properties() override { return m_properties; } virtual std::vector get_capabilities() { return m_capabilities; } virtual void set_callback(std::function)> handler) { m_sample_callback = handler;} @@ -96,7 +97,7 @@ namespace rs std::vector m_capabilities; std::map> m_unknowns; std::map m_streams_infos; - + rs_motion_intrinsics m_motion_intrinsics; std::map m_active_streams_info; bool m_is_motion_tracking_enabled; diff --git a/sdk/src/cameras/playback/include/disk_read_factory.h b/sdk/src/cameras/playback/include/disk_read_factory.h index 02d62c5..a322614 100644 --- a/sdk/src/cameras/playback/include/disk_read_factory.h +++ b/sdk/src/cameras/playback/include/disk_read_factory.h @@ -4,8 +4,9 @@ #pragma once #include #include "file/file.h" -#include "linux/disk_read_linux.h" -#include "windows/disk_read_windows.h" +#include "disk_read.h" +#include "linux/v1/disk_read.h" +#include "windows/v10/disk_read.h" #include "rs/utils/log_utils.h" namespace rs @@ -32,17 +33,24 @@ namespace rs status = file_->read_bytes(&file_type_id, sizeof(file_type_id), nbytesRead); if (status != rs::core::status_no_error) return status; + if (file_type_id == UID('R', 'S', 'L', '2')) + { + LOG_INFO("create disk read for Linux file format version 2") + disk_read = std::unique_ptr(new playback::disk_read(file_name)); + return disk_read->init(); + } + if (file_type_id == UID('R', 'S', 'L', '1')) { LOG_INFO("create disk read for Linux file format version 1") - disk_read = std::unique_ptr(new disk_read_linux(file_name)); + disk_read = std::unique_ptr(new linux::v1::disk_read(file_name)); return disk_read->init(); - } + } if (file_type_id == UID('R', 'S', 'C', 'F')) { LOG_INFO("create disk read for Windows file format") - disk_read = std::unique_ptr(new disk_read_windows(file_name)); + disk_read = std::unique_ptr(new windows::v10::disk_read(file_name)); return disk_read->init(); } LOG_ERROR("failed to create disk read") diff --git a/sdk/src/cameras/playback/include/disk_read_interface.h b/sdk/src/cameras/playback/include/disk_read_interface.h index 56cc1ef..7fd7eaf 100644 --- a/sdk/src/cameras/playback/include/disk_read_interface.h +++ b/sdk/src/cameras/playback/include/disk_read_interface.h @@ -26,6 +26,7 @@ namespace rs virtual bool is_motion_tracking_enabled() = 0; virtual const core::file_types::device_info& get_device_info() = 0; virtual std::map get_streams_infos() = 0; + virtual rs_motion_intrinsics get_motion_intrinsics() = 0; virtual std::vector get_capabilities() = 0; virtual std::map get_properties() = 0; virtual void set_realtime(bool realtime) = 0; diff --git a/sdk/src/cameras/playback/include/linux/v1/conversions.h b/sdk/src/cameras/playback/include/linux/v1/conversions.h new file mode 100644 index 0000000..e2c3c9d --- /dev/null +++ b/sdk/src/cameras/playback/include/linux/v1/conversions.h @@ -0,0 +1,113 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2016 Intel Corporation. All Rights Reserved. + +#pragma once +#include +#include "include/linux/v1/file_types.h" +#include "status.h" +#include "rs/utils/log_utils.h" + +namespace rs +{ + namespace playback + { + namespace linux + { + namespace v1 + { + namespace conversions + { + + core::status convert(const file_types::file_header &source, core::file_types::file_header &target) + { + memset(&target, 0, sizeof(target)); + target.id = source.id; + target.version = source.version; + target.coordinate_system = source.coordinate_system; + target.first_frame_offset = source.first_frame_offset; + target.nstreams = source.nstreams; + return core::status_no_error; + } + + core::status convert(const file_types::device_info &source, core::file_types::device_info &target) + { + memset(&target, 0, sizeof(target)); + auto nameSize = sizeof(target.name) / sizeof(target.name[0]); + for(size_t i = 0; i < nameSize; i++) + target.name[i] = source.name[i]; + auto serial_size = sizeof(target.serial) / sizeof(target.serial[0]); + for(size_t i = 0; i < serial_size; i++) + target.serial[i] = source.serial[i]; + auto fw_size = sizeof(target.serial) / sizeof(target.serial[0]); + for(size_t i = 0; i < fw_size; i++) + target.camera_firmware[i] = source.firmware[i]; + return core::status_no_error; + } + + core::status convert(const file_types::sw_info &source, core::file_types::sw_info &target) + { + memset(&target, 0, sizeof(target)); + target.librealsense = source.librealsense; + target.sdk = source.sdk; + return core::status_no_error; + } + + core::status convert(const file_types::sample_info &source, core::file_types::sample_info &target) + { + memset(&target, 0, sizeof(target)); + target.capture_time = source.capture_time; + target.offset = source.offset; + target.type = source.type; + return core::status_no_error; + } + + core::status convert(const file_types::frame_info &source, core::file_types::frame_info &target) + { + memset(&target, 0, sizeof(target)); + target.width = source.width; + target.height = source.height; + target.stride = source.stride_x; + target.bpp = source.bpp * 8; + target.format = source.format; + target.framerate = source.framerate; + target.index_in_stream = source.index_in_stream; + target.number = source.number; + target.stream = source.stream; + target.system_time = source.system_time; + target.time_stamp = source.time_stamp; + target.time_stamp_domain = RS_TIMESTAMP_DOMAIN_CAMERA; + return core::status_no_error; + } + + core::status convert(const file_types::stream_profile &source, core::file_types::stream_profile &target) + { + memset(&target, 0, sizeof(target)); + core::file_types::frame_info frame_info; + if(convert(source.info, frame_info) != core::status_no_error) + return core::status_item_unavailable; + target.frame_rate = source.frame_rate; + target.info = frame_info; + target.depth_scale = source.depth_scale; + target.extrinsics = source.extrinsics; + target.intrinsics = source.intrinsics; + target.rect_intrinsics = source.rect_intrinsics; + return core::status_no_error; + } + + core::status convert(const file_types::stream_info &source, core::file_types::stream_info &target) + { + memset(&target, 0, sizeof(target)); + core::file_types::stream_profile profile; + if(convert(source.profile, profile) != core::status_no_error) + return core::status_item_unavailable; + target.profile = profile; + target.stream = source.stream; + target.nframes = source.nframes; + target.ctype = source.ctype; + return core::status_no_error; + } + } + } + } + } +} diff --git a/sdk/src/cameras/playback/include/linux/v1/disk_read.h b/sdk/src/cameras/playback/include/linux/v1/disk_read.h new file mode 100644 index 0000000..bb079f5 --- /dev/null +++ b/sdk/src/cameras/playback/include/linux/v1/disk_read.h @@ -0,0 +1,28 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2016 Intel Corporation. All Rights Reserved. + +#pragma once +#include "disk_read_base.h" + +namespace rs +{ + namespace playback + { + namespace linux + { + namespace v1 + { + class disk_read : public disk_read_base + { + public: + disk_read(const char *file_name) : disk_read_base(file_name) {} + virtual ~disk_read(void); + protected: + virtual rs::core::status read_headers() override; + virtual void index_next_samples(uint32_t number_of_samples) override; + virtual int32_t size_of_pitches(void) override; + }; + } + } + } +} diff --git a/sdk/src/cameras/playback/include/linux/v1/file_types.h b/sdk/src/cameras/playback/include/linux/v1/file_types.h new file mode 100644 index 0000000..7c3556e --- /dev/null +++ b/sdk/src/cameras/playback/include/linux/v1/file_types.h @@ -0,0 +1,145 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2016 Intel Corporation. All Rights Reserved. + +#pragma once +#include +#include "include/file_types.h" + +namespace rs +{ + namespace playback + { + namespace linux + { + namespace v1 + { + namespace file_types + { + struct chunk_info + { + core::file_types::chunk_id id; + int32_t size; + }; + + struct device_info + { + char name[224]; // device name + char serial[32]; // serial number + char firmware[32]; // firmware version + char usb_port_id[256]; // firmware version + }; + + struct sw_info + { + core::file_types::version sdk; + core::file_types::version librealsense; + }; + + struct sample_info + { + core::file_types::sample_type type; + uint64_t capture_time; + uint64_t offset; + }; + + struct frame_info + { + int width; + int height; + rs_format format; + int stride_x; + int stride_y; + float bpp; + rs_stream stream; + int number; + double time_stamp; + long long system_time; + int framerate; + uint32_t index_in_stream; + }; + + struct stream_profile + { + frame_info info; + int32_t frame_rate; + rs_intrinsics intrinsics; + rs_intrinsics rect_intrinsics; + rs_extrinsics extrinsics; + float depth_scale; + }; + + struct stream_info + { + rs_stream stream; + core::file_types::compression_type ctype; + int32_t nframes; + stream_profile profile; + }; + + struct file_header + { + int32_t id; // File identifier + int32_t version; // file version for windows files + int32_t first_frame_offset; // The byte offset to the meta data of the first frame. + int32_t nstreams; // Number of streams + core::file_types::coordinate_system coordinate_system; + }; + + class disk_format + { + public: + struct device_info + { + file_types::device_info data; + int32_t reserved[25]; + }; + + struct sw_info + { + file_types::sw_info data; + int32_t reserved[10]; + }; + + struct stream_info + { + file_types::stream_info data; + int32_t reserved[10]; + + }; + + struct sample_info + { + file_types::sample_info data; + int32_t reserved[10]; + }; + + struct frame_info + { + file_types::frame_info data; + int32_t reserved[10]; + }; + + struct time_stamp_data + { + rs_timestamp_data data; + int32_t reserved[10]; + }; + + struct motion_data + { + rs_motion_data data; + int32_t reserved[10]; + }; + + struct file_header + { + file_types::file_header data; + int32_t reserved[25]; + }; + }; + } + } + } + } +} + diff --git a/sdk/src/cameras/playback/include/playback_device_impl.h b/sdk/src/cameras/playback/include/playback_device_impl.h index ed82ccc..2f3c8fd 100644 --- a/sdk/src/cameras/playback/include/playback_device_impl.h +++ b/sdk/src/cameras/playback/include/playback_device_impl.h @@ -21,16 +21,16 @@ namespace rs std::shared_ptr get_frame() { return m_frame; } virtual const uint8_t *get_frame_data() const override { return m_frame->data; } virtual double get_frame_timestamp() const override { return m_frame->finfo.time_stamp; } - virtual int get_frame_number() const override { return m_frame->finfo.number; } + virtual unsigned long long get_frame_number() const override { return m_frame->finfo.number; } virtual long long get_frame_system_time() const override { return m_frame->finfo.system_time; } virtual int get_frame_width() const override { return m_frame->finfo.width; } virtual int get_frame_height() const override { return m_frame->finfo.height; } virtual int get_frame_framerate() const override { return m_frame->finfo.framerate; } - virtual int get_frame_stride_x() const override { return m_frame->finfo.stride_x; } - virtual int get_frame_stride_y() const override { return m_frame->finfo.stride_y; } - virtual float get_frame_bpp() const override { return m_frame->finfo.bpp; } + virtual int get_frame_stride() const override { return m_frame->finfo.stride; } + virtual int get_frame_bpp() const override { return m_frame->finfo.bpp; } virtual rs_format get_frame_format() const override { return m_frame->finfo.format; } virtual rs_stream get_stream_type() const override { return m_frame->finfo.stream; } + virtual rs_timestamp_domain get_frame_timestamp_domain() const { return m_frame->finfo.time_stamp_domain; } void add_ref() { m_ref_count++; } void release() { if(--m_ref_count == 0) delete this; } @@ -85,6 +85,10 @@ namespace rs virtual rs_frame_ref * clone_frame(rs_frame_ref * frame) override; virtual const char * get_usb_port_id() const; + virtual const char * get_camera_info(rs_camera_info info_type) const; + virtual rs_motion_intrinsics get_motion_intrinsics() const; + virtual rs_extrinsics get_motion_extrinsics_from(rs_stream from) const; + virtual bool init() override; virtual bool is_real_time() override; virtual void pause() override; diff --git a/sdk/src/cameras/playback/include/rs_stream_impl.h b/sdk/src/cameras/playback/include/rs_stream_impl.h index cb7dd5f..9cd8679 100644 --- a/sdk/src/cameras/playback/include/rs_stream_impl.h +++ b/sdk/src/cameras/playback/include/rs_stream_impl.h @@ -25,7 +25,7 @@ namespace rs virtual rs_intrinsics get_rectified_intrinsics() const override { return m_stream_info.profile.rect_intrinsics; } virtual rs_format get_format() const override { return m_stream_info.profile.info.format; } virtual int get_framerate() const override { return m_stream_info.profile.frame_rate; } - virtual int get_frame_number() const override { return m_frame ? m_frame->finfo.number : 0; } + virtual unsigned long long get_frame_number() const override { return m_frame ? m_frame->finfo.number : 0; } virtual long long get_frame_system_time() const override { return m_frame ? m_frame->finfo.system_time : 0; } virtual const uint8_t *get_frame_data() const override { return m_frame ? m_frame->data : nullptr; } virtual int get_mode_count() const override { return get_format() == rs_format::RS_FORMAT_ANY ? 0 : 1; } @@ -34,6 +34,8 @@ namespace rs virtual bool is_enabled() const override { return m_is_enabled; } virtual bool has_data() const { return m_frame ? true : false; } rs_stream get_stream_type() { return m_stream_info.stream; } + virtual int get_frame_stride() const { return m_frame ? m_frame->finfo.stride : 0; } + virtual int get_frame_bpp() const { return m_frame ? m_frame->finfo.bpp : 0; } private: bool m_is_enabled; diff --git a/sdk/src/cameras/playback/include/windows/conversions.h b/sdk/src/cameras/playback/include/windows/conversions.h deleted file mode 100644 index 166ce0c..0000000 --- a/sdk/src/cameras/playback/include/windows/conversions.h +++ /dev/null @@ -1,37 +0,0 @@ -// License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2016 Intel Corporation. All Rights Reserved. - -#pragma once -#include -#include -#include "windows/file_types_windows.h" -#include "include/file_types.h" -#include "projection_types.h" -#include "status.h" -#include "image/librealsense_image_utils.h" -#include "rs/utils/log_utils.h" - -namespace rs -{ - namespace win_file - { - namespace conversions - { - uint64_t rssdk2lrs_timestamp(uint64_t time); - core::status convert(stream_type source, rs_stream &target); - core::status convert(compression_type source, core::file_types::compression_type &target); - core::status convert(rotation source, rs::core::rotation &target); - core::status convert(pixel_format source, rs_format &target); - core::status convert(const coordinate_system &source, core::file_types::coordinate_system &target); - core::status convert(const disk_format::header &source, core::file_types::file_header &target); - core::status convert(const disk_format::stream_info &source, core::file_types::stream_info &target); - core::status convert(const disk_format::device_info_disk &source, core::file_types::device_info &target); - core::status convert(const image_info &source, core::file_types::frame_info &target); - core::status convert(const disk_format::stream_profile_disk &source, core::file_types::stream_profile &target); - core::status convert(const disk_format::stream_profile_set_disk &source, std::map &target); - core::status convert(const disk_format::frame_metadata &source, core::file_types::frame_info &target); - rs_intrinsics get_intrinsics(stream_type stream, ds_projection::ProjectionData* projection); - rs_extrinsics get_extrinsics(stream_type stream, ds_projection::ProjectionData *projection); - } - } -} diff --git a/sdk/src/cameras/playback/include/windows/disk_read_windows.h b/sdk/src/cameras/playback/include/windows/disk_read_windows.h deleted file mode 100644 index af8e0e6..0000000 --- a/sdk/src/cameras/playback/include/windows/disk_read_windows.h +++ /dev/null @@ -1,29 +0,0 @@ -// License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2016 Intel Corporation. All Rights Reserved. - -#pragma once -#include "disk_read_base.h" - -namespace rs -{ - namespace playback - { - class disk_read_windows : public disk_read_base - { - - public: - disk_read_windows(const char *file_name) : disk_read_base(file_name), m_time_stamp_base(0) {} - virtual ~disk_read_windows(void); - - protected: - virtual rs::core::status read_headers() override; - virtual void index_next_samples(uint32_t number_of_samples) override; - virtual int32_t size_of_pitches(void) override; - void handle_ds_projection(std::vector &projection_data); - rs::core::status get_image_offset(rs_stream stream, int64_t & offset); - - private: - uint64_t m_time_stamp_base; - }; - } -} diff --git a/sdk/src/cameras/playback/include/windows/file_types_windows.h b/sdk/src/cameras/playback/include/windows/file_types_windows.h deleted file mode 100644 index 3a9efb8..0000000 --- a/sdk/src/cameras/playback/include/windows/file_types_windows.h +++ /dev/null @@ -1,385 +0,0 @@ -// License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2016 Intel Corporation. All Rights Reserved. - -#pragma once -#include "include/file_types.h" - -#define PXC_DEFINE_CONST(Y,X) enum {Y=X} -#define NUM_OF_PLANES 4 - -namespace rs -{ - namespace win_file - { - static const int streams_limit = 8; - class File; - - /** - @enum Property - Describes the device properties. - Use the inline functions to access specific device properties. - */ - enum property - { - // Misc. Properties - property_projection_serializable = 3003, /* pxcU32 R The meta data identifier of the Projection instance serialization data. */ - }; - - /** - @structure DeviceCap - Describes a pair value of device property and its value. - Use the inline functions to access specific device properties. - */ - struct device_cap - { - property label; /* Property type */ - float value; /* Property value */ - }; - - /** - @enum StreamOption - Describes the steam options. - */ - enum stream_option - { - so_any = 0, - - // Optional options - so_optional_mask = 0x0000FFFF, /* The option can be added to any profile, but not necessarily supported for any profile */ - so_depth_precalculate_uvmap = 0x00000001, /* A flag to ask the device to precalculate UVMap */ - so_strong_stream_sync = 0x00000002, /* A flag to ask the device to perform strong (HW-based) synchronization on the streams with this flag. */ - - // Mandatory options - so_mandatory_mask = 0xFFFF0000, /* If the option is supported - the device sets this flag in the profile */ - so_unrectified = 0x00010000, /* A mandatory flag to ask the device to stream unrectified images on the stream with this flag */ - so_depth_confidence = 0x00020000 /* A mandatory flag to ask the device to attach confidence data to depth images (see PIXEL_FORMAT_DEPTH_CONFIDENCE) */ - }; - - /** - @enum PixelFormat - Describes the image sample pixel format - */ - enum pixel_format - { - pf_any = 0, /* Unknown/undefined */ - - // STREAM_TYPE_COLOR - pf_yuy2 = 0x00010000, /* YUY2 image */ - pf_nv12, /* NV12 image */ - pf_rgb32, /* BGRA layout on a little-endian machine */ - pf_rgb24, /* BGR layout on a little-endian machine */ - pf_y8, /* 8-Bit Gray Image, or IR 8-bit */ - - // STREAM_TYPE_DEPTH - pf_depth = 0x00020000, /* 16-bit unsigned integer with precision mm. */ - pf_raw, /* 16-bit unsigned integer with device specific precision (call device->QueryDepthUnit()) */ - pf_depth_f32, /* 32-bit float-point with precision mm. */ - pf_depth_confidence = 0x40000004, /* Additional plane with 8-bits depth confidence (MSB) */ - - // STREAM_TYPE_IR - pf_y16 = 0x00040000, /* 16-Bit Gray Image */ - pf_y8_ur_relative = 0x00080000 /* Relative IR Image */ - }; - - /** - @enum DeviceModel - Describes the device model - */ - enum device_model - { - dm_generic = 0x00000000, /* a generic device or unknown device */ - dm_f200 = 0x0020000E, /* the Intel(R) RealSense(TM) 3D Camera, model F200 */ - dm_ivcam = 0x0020000E, /* deprecated: the Intel(R) RealSense(TM) 3D Camera, model F200 */ - dm_r200 = 0x0020000F, /* the Intel(R) RealSense(TM) 3D Camera, model R200 */ - dm_ds4 = 0x0020000F, /* deprecated: the Intel(R) RealSense(TM) 3D Camera, model R200 */ - dm_sr300 = 0x00200010, /* The Intel(R) RealSense(TM) 3D Camera, model SR300 */ - dm_r200_enhanced = 0x0020001F, /* The Intel(R) RealSense(TM) 3D Camera, model R200 and Platform Camera */ - }; - - /** - @enum DeviceOrientation - Describes the device orientation - */ - enum device_orientation - { - do_any = 0x0, /* Unknown orientation */ - do_user_facing = 0x1, /* A user facing camera */ - do_front_facing = 0x1, /* A front facing camera */ - do_world_facing = 0x2, /* A world facing camera */ - do_rear_facing = 0x2, /* A rear facing camera */ - }; - - - /** - @enum Rotation - Image rotation options. - */ - enum rotation - { - rotation_0_degree = 0x0, /* 0 Degree rotation */ - rotation_90_degree = 90, /* 90 degree clockwise rotation */ - rotation_180_degree = 180, /* 180 degree clockwise rotation */ - rotation_270_degree = 270, /* 270 degree clockwise rotation */ - }; - - /** - @struct ImageInfo - Describes the image sample detailed information. - */ - struct image_info - { - int32_t width; /* width of the image in pixels */ - int32_t height; /* height of the image in pixels */ - pixel_format format; /* image pixel format */ - int32_t reserved; - }; - - /** - @enum Option - Describes the image options. - */ - enum image_option - { - OPTION_ANY = 0, - }; - - enum compression_type - { - compression_none = 0, - compression_h264, - compression_lzo - }; - - /** - @enum StreamType - Bit-OR'ed values of stream types, physical or virtual streams. - */ - enum stream_type - { - stream_type_any = 0, /* Unknown/undefined type */ - stream_type_color = 0x0001, /* the color stream type */ - stream_type_depth = 0x0002, /* the depth stream type */ - stream_type_ir = 0x0004, /* the infrared stream type */ - stream_type_left = 0x0008, /* the stereoscopic left intensity image */ - stream_type_right = 0x0010, /* the stereoscopic right intensity image */ - }; - - /** - @enum ConnectionType - Describes the Connection type of the device - */ - enum connection_type - { - connection_type_unknown = 0, /* Any connection type */ - connection_type_usb_integrated, /* USB Integrated Camera */ - connection_type_usb_peripheral /* USB Peripheral Camera */ - }; - - struct version - { - uint32_t major; - uint32_t minor; - uint32_t build; - uint32_t revision; - }; - - /** - @enum CoordinateSystem - SDK supports several 3D coordinate systems for front and rear facing cameras. - */ - enum coordinate_system - { - coordinate_system_rear_default = 0x100, /* Right-hand system: X right, Y up, Z to the user */ - coordinate_system_rear_opencv = 0x200, /* Right-hand system: X right, Y down, Z to the world */ - coordinate_system_front_default = 0x001, /* Left-hand system: X left, Y up, Z to the user */ - }; - - /** - @enum ImplGroup - The SDK group I/O and algorithm modules into groups and subgroups. - This is the enumerator for algorithm groups. - */ - enum impl_group - { - impl_group_any = 0, /* Undefine group */ - impl_group_object_recognition = 0x00000001, /* Object recognition algorithms */ - impl_group_speech_recognition = 0x00000002, /* Speech recognition algorithms */ - impl_group_sensor = 0x00000004, /* I/O modules */ - impl_group_photography = 0x00000008, /* Photography/Videography algorithms */ - impl_group_utilities = 0x00000010, /* Utility modules */ - impl_group_core = 0x80000000, /* Core SDK modules */ - impl_group_user = 0x40000000, /* User defined algorithms */ - }; - - /** - @enum ImplSubgroup - The SDK group I/O and algorithm modules into groups and subgroups. - This is the enumerator for algorithm subgroups. - */ - enum impl_subgroup - { - impl_subgroup_any = 0, /* Undefined subgroup */ - - /* object recognition building blocks */ - impl_subgroup_face_analysis = 0x00000001, /* face analysis subgroup */ - impl_subgroup_gesture_recognition = 0x00000010, /* gesture recognition subgroup */ - impl_subgroup_segmentation = 0x00000020, /* segmentation subgroup */ - impl_subgroup_pulse_estimation = 0x00000040, /* pulse estimation subgroup */ - impl_subgroup_emotion_recognition = 0x00000080, /* emotion recognition subgroup */ - impl_subgroup_object_tracking = 0x00000100, /* object detection subgroup */ - impl_subgroup_3dseg = 0x00000200, /* user segmentation subgroup */ - impl_subgroup_3dscan = 0x00000400, /* mesh capture subgroup */ - impl_subgroup_scene_perception = 0x00000800, /* scene perception subgroup */ - - /* Photography building blocks */ - impl_subgroup_enhanced_photography = 0x00001000, /* enhanced photography subgroup */ - impl_subgroup_enhanced_videography = 0x00002000, /* enhanced videography subgroup */ - - /* sensor building blocks */ - impl_subgroup_audio_capture = 0x00000001, /* audio capture subgroup */ - impl_subgroup_video_capture = 0x00000002, /* video capture subgroup */ - - /* speech recognition building blocks */ - impl_subgroup_speech_recognition = 0x00000001, /* speech recognition subgroup */ - impl_subgroup_speech_synthesis = 0x00000002, /* speech synthesis subgroup */ - }; - enum - { - image_metadata_power_state = 0x35467859, - image_metadata_sample_id = 0x9F228B51, - }; - - /** - @brief Get the stream index number - @param[in] StreamType The stream type - @return The stream index number. - **/ - __inline static int32_t stream_type_to_index(stream_type type) - { - int32_t s = 0; - while (type > 1) type = (stream_type)(type >> 1), s++; - return s; - } - - class disk_format - { - public: - - enum chunk_id - { - chunk_deviceinfo = 1, - chunk_streaminfo = 2, - chunk_properties = 3, - chunk_profiles = 4, - chunk_serializeable = 5, - chunk_frame_meta_data = 6, - chunk_frame_data = 7, - chunk_image_meta_data = 8, - chunk_frame_indexing = 9, - chunk_sw_info = 10 - }; - - struct header - { - PXC_DEFINE_CONST(FILE_IDENTIFIER, UID('R', 'S', 'L', 'X')); - int32_t id; // File identifier - int32_t version; // file version - int32_t first_frame_offset; // The byte offset to the meta data of the first frame. - int32_t nstreams; // Number of streams - int64_t frame_indexing_offset; // The byte offset to the frame indexing structure. - win_file::coordinate_system coordinate_system; - int32_t reserved[25]; - }; - - struct chunk - { - disk_format::chunk_id chunk_id; - int32_t chunk_size; - }; - - struct frame_indexing - { - int32_t nframes[streams_limit]; - struct frame_info_st - { - rs_stream type; // stream type - int64_t offset; // file offset in bytes - int64_t time_stamp; // the time stamp in 100ns. - int32_t frame_number; // absolution frame number in the file - } *frame_list; // all frames in file - }; - - struct stream_info - { - stream_type stype; - compression_type ctype; - int32_t nframes; - }; - - struct frame_metadata - { - int32_t frame_number; - win_file::stream_type stream_type; - int64_t time_stamp; - image_option options; - int32_t reserved[3]; - }; - - struct device_info_disk - { - uint16_t name[224]; - uint16_t serial[32]; - uint16_t did[256]; - int32_t firmware[4]; - float location[2]; - device_model model; - device_orientation orientation; - stream_type streams; - int32_t didx; - int32_t duid; - win_file::rotation rotation; - connection_type connectionType; - int32_t reserved[11]; - }; - - struct stream_profile_disk - { - win_file::image_info image_info; /* resolution and color format */ - float frame_rate[2]; /* frame rate range. Set max when configuring FPS */ - stream_option options; /* bit-mask of stream options */ - int32_t reserved[5]; - }; - /** - @structure StreamProfileSet - The set of StreamProfile that describes the configuration parameters of all streams. - */ - struct stream_profile_set_disk - { - stream_profile_disk color; - stream_profile_disk depth; - stream_profile_disk ir; - stream_profile_disk left; - stream_profile_disk right; - stream_profile_disk reserved[streams_limit-5]; - - /** - @brief Access the configuration parameters by the stream type. - @param[in] type The stream type. - @return The StreamProfile instance. - */ - __inline stream_profile_disk &operator[](stream_type type) - { - if (type==stream_type::stream_type_color) return color; - if (type==stream_type::stream_type_depth) return depth; - if (type==stream_type::stream_type_ir) return ir; - if (type==stream_type::stream_type_left) return left; - if (type==stream_type::stream_type_right) return right; - for (int i=sizeof(reserved)/sizeof(reserved[0])-1,j=(1<<(streams_limit-1)); i>=0; i--,j>>=1) - if (type&j) return reserved[i]; - return reserved[sizeof(reserved)/sizeof(reserved[0])-1]; - } - }; - }; - } -} - diff --git a/sdk/src/cameras/playback/include/windows/v10/conversions.h b/sdk/src/cameras/playback/include/windows/v10/conversions.h new file mode 100644 index 0000000..90198fd --- /dev/null +++ b/sdk/src/cameras/playback/include/windows/v10/conversions.h @@ -0,0 +1,43 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2016 Intel Corporation. All Rights Reserved. + +#pragma once +#include +#include +#include "windows/v10/file_types.h" +#include "include/file_types.h" +#include "include/windows/projection_types.h" +#include "status.h" +#include "image/librealsense_image_utils.h" +#include "rs/utils/log_utils.h" + +namespace rs +{ + namespace playback + { + namespace windows + { + namespace v10 + { + namespace conversions + { + uint64_t rssdk2lrs_timestamp(uint64_t time); + core::status convert(file_types::stream_type source, rs_stream &target); + core::status convert(file_types::compression_type source, core::file_types::compression_type &target); + core::status convert(file_types::rotation source, rs::core::rotation &target); + core::status convert(file_types::pixel_format source, rs_format &target); + core::status convert(const file_types::coordinate_system &source, core::file_types::coordinate_system &target); + core::status convert(const file_types::disk_format::header &source, core::file_types::file_header &target); + core::status convert(const file_types::disk_format::stream_info &source, core::file_types::stream_info &target); + core::status convert(const file_types::disk_format::device_info_disk &source, core::file_types::device_info &target); + core::status convert(const file_types::image_info &source, core::file_types::frame_info &target); + core::status convert(const file_types::disk_format::stream_profile_disk &source, core::file_types::stream_profile &target); + core::status convert(const file_types::disk_format::stream_profile_set_disk &source, std::map &target); + core::status convert(const file_types::disk_format::frame_metadata &source, core::file_types::frame_info &target); + rs_intrinsics get_intrinsics(file_types::stream_type stream, ds_projection::ProjectionData* projection); + rs_extrinsics get_extrinsics(file_types::stream_type stream, ds_projection::ProjectionData *projection); + } + } + } + } +} diff --git a/sdk/src/cameras/playback/include/windows/v10/disk_read.h b/sdk/src/cameras/playback/include/windows/v10/disk_read.h new file mode 100644 index 0000000..4060ec0 --- /dev/null +++ b/sdk/src/cameras/playback/include/windows/v10/disk_read.h @@ -0,0 +1,35 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2016 Intel Corporation. All Rights Reserved. + +#pragma once +#include "disk_read_base.h" + +namespace rs +{ + namespace playback + { + namespace windows + { + namespace v10 + { + class disk_read : public disk_read_base + { + + public: + disk_read(const char *file_name) : disk_read_base(file_name), m_time_stamp_base(0) {} + virtual ~disk_read(void); + + protected: + virtual rs::core::status read_headers() override; + virtual void index_next_samples(uint32_t number_of_samples) override; + virtual int32_t size_of_pitches(void) override; + void handle_ds_projection(std::vector &projection_data); + rs::core::status get_image_offset(rs_stream stream, int64_t & offset); + + private: + uint64_t m_time_stamp_base; + }; + } + } + } +} diff --git a/sdk/src/cameras/playback/include/windows/v10/file_types.h b/sdk/src/cameras/playback/include/windows/v10/file_types.h new file mode 100644 index 0000000..13dc0d3 --- /dev/null +++ b/sdk/src/cameras/playback/include/windows/v10/file_types.h @@ -0,0 +1,394 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2016 Intel Corporation. All Rights Reserved. + +#pragma once +#include "include/file_types.h" + +#define PXC_DEFINE_CONST(Y,X) enum {Y=X} +#define NUM_OF_PLANES 4 + +namespace rs +{ + namespace playback + { + namespace windows + { + namespace v10 + { + namespace file_types + { + static const int streams_limit = 8; + class File; + + /** + @enum Property + Describes the device properties. + Use the inline functions to access specific device properties. + */ + enum property + { + // Misc. Properties + property_projection_serializable = 3003, /* pxcU32 R The meta data identifier of the Projection instance serialization data. */ + }; + + /** + @structure DeviceCap + Describes a pair value of device property and its value. + Use the inline functions to access specific device properties. + */ + struct device_cap + { + property label; /* Property type */ + float value; /* Property value */ + }; + + /** + @enum StreamOption + Describes the steam options. + */ + enum stream_option + { + so_any = 0, + + // Optional options + so_optional_mask = 0x0000FFFF, /* The option can be added to any profile, but not necessarily supported for any profile */ + so_depth_precalculate_uvmap = 0x00000001, /* A flag to ask the device to precalculate UVMap */ + so_strong_stream_sync = 0x00000002, /* A flag to ask the device to perform strong (HW-based) synchronization on the streams with this flag. */ + + // Mandatory options + so_mandatory_mask = 0xFFFF0000, /* If the option is supported - the device sets this flag in the profile */ + so_unrectified = 0x00010000, /* A mandatory flag to ask the device to stream unrectified images on the stream with this flag */ + so_depth_confidence = 0x00020000 /* A mandatory flag to ask the device to attach confidence data to depth images (see PIXEL_FORMAT_DEPTH_CONFIDENCE) */ + }; + + /** + @enum PixelFormat + Describes the image sample pixel format + */ + enum pixel_format + { + pf_any = 0, /* Unknown/undefined */ + + // STREAM_TYPE_COLOR + pf_yuy2 = 0x00010000, /* YUY2 image */ + pf_nv12, /* NV12 image */ + pf_rgb32, /* BGRA layout on a little-endian machine */ + pf_rgb24, /* BGR layout on a little-endian machine */ + pf_y8, /* 8-Bit Gray Image, or IR 8-bit */ + + // STREAM_TYPE_DEPTH + pf_depth = 0x00020000, /* 16-bit unsigned integer with precision mm. */ + pf_raw, /* 16-bit unsigned integer with device specific precision (call device->QueryDepthUnit()) */ + pf_depth_f32, /* 32-bit float-point with precision mm. */ + pf_depth_confidence = 0x40000004, /* Additional plane with 8-bits depth confidence (MSB) */ + + // STREAM_TYPE_IR + pf_y16 = 0x00040000, /* 16-Bit Gray Image */ + pf_y8_ur_relative = 0x00080000 /* Relative IR Image */ + }; + + /** + @enum DeviceModel + Describes the device model + */ + enum device_model + { + dm_generic = 0x00000000, /* a generic device or unknown device */ + dm_f200 = 0x0020000E, /* the Intel(R) RealSense(TM) 3D Camera, model F200 */ + dm_ivcam = 0x0020000E, /* deprecated: the Intel(R) RealSense(TM) 3D Camera, model F200 */ + dm_r200 = 0x0020000F, /* the Intel(R) RealSense(TM) 3D Camera, model R200 */ + dm_ds4 = 0x0020000F, /* deprecated: the Intel(R) RealSense(TM) 3D Camera, model R200 */ + dm_sr300 = 0x00200010, /* The Intel(R) RealSense(TM) 3D Camera, model SR300 */ + dm_r200_enhanced = 0x0020001F, /* The Intel(R) RealSense(TM) 3D Camera, model R200 and Platform Camera */ + }; + + /** + @enum DeviceOrientation + Describes the device orientation + */ + enum device_orientation + { + do_any = 0x0, /* Unknown orientation */ + do_user_facing = 0x1, /* A user facing camera */ + do_front_facing = 0x1, /* A front facing camera */ + do_world_facing = 0x2, /* A world facing camera */ + do_rear_facing = 0x2, /* A rear facing camera */ + }; + + + /** + @enum Rotation + Image rotation options. + */ + enum rotation + { + rotation_0_degree = 0x0, /* 0 Degree rotation */ + rotation_90_degree = 90, /* 90 degree clockwise rotation */ + rotation_180_degree = 180, /* 180 degree clockwise rotation */ + rotation_270_degree = 270, /* 270 degree clockwise rotation */ + }; + + /** + @struct ImageInfo + Describes the image sample detailed information. + */ + struct image_info + { + int32_t width; /* width of the image in pixels */ + int32_t height; /* height of the image in pixels */ + pixel_format format; /* image pixel format */ + int32_t reserved; + }; + + /** + @enum Option + Describes the image options. + */ + enum image_option + { + OPTION_ANY = 0, + }; + + enum compression_type + { + compression_none = 0, + compression_h264, + compression_lzo + }; + + /** + @enum StreamType + Bit-OR'ed values of stream types, physical or virtual streams. + */ + enum stream_type + { + stream_type_any = 0, /* Unknown/undefined type */ + stream_type_color = 0x0001, /* the color stream type */ + stream_type_depth = 0x0002, /* the depth stream type */ + stream_type_ir = 0x0004, /* the infrared stream type */ + stream_type_left = 0x0008, /* the stereoscopic left intensity image */ + stream_type_right = 0x0010, /* the stereoscopic right intensity image */ + }; + + /** + @enum ConnectionType + Describes the Connection type of the device + */ + enum connection_type + { + connection_type_unknown = 0, /* Any connection type */ + connection_type_usb_integrated, /* USB Integrated Camera */ + connection_type_usb_peripheral /* USB Peripheral Camera */ + }; + + struct version + { + uint32_t major; + uint32_t minor; + uint32_t build; + uint32_t revision; + }; + + /** + @enum CoordinateSystem + SDK supports several 3D coordinate systems for front and rear facing cameras. + */ + enum coordinate_system + { + coordinate_system_rear_default = 0x100, /* Right-hand system: X right, Y up, Z to the user */ + coordinate_system_rear_opencv = 0x200, /* Right-hand system: X right, Y down, Z to the world */ + coordinate_system_front_default = 0x001, /* Left-hand system: X left, Y up, Z to the user */ + }; + + /** + @enum ImplGroup + The SDK group I/O and algorithm modules into groups and subgroups. + This is the enumerator for algorithm groups. + */ + enum impl_group + { + impl_group_any = 0, /* Undefine group */ + impl_group_object_recognition = 0x00000001, /* Object recognition algorithms */ + impl_group_speech_recognition = 0x00000002, /* Speech recognition algorithms */ + impl_group_sensor = 0x00000004, /* I/O modules */ + impl_group_photography = 0x00000008, /* Photography/Videography algorithms */ + impl_group_utilities = 0x00000010, /* Utility modules */ + impl_group_core = 0x80000000, /* Core SDK modules */ + impl_group_user = 0x40000000, /* User defined algorithms */ + }; + + /** + @enum ImplSubgroup + The SDK group I/O and algorithm modules into groups and subgroups. + This is the enumerator for algorithm subgroups. + */ + enum impl_subgroup + { + impl_subgroup_any = 0, /* Undefined subgroup */ + + /* object recognition building blocks */ + impl_subgroup_face_analysis = 0x00000001, /* face analysis subgroup */ + impl_subgroup_gesture_recognition = 0x00000010, /* gesture recognition subgroup */ + impl_subgroup_segmentation = 0x00000020, /* segmentation subgroup */ + impl_subgroup_pulse_estimation = 0x00000040, /* pulse estimation subgroup */ + impl_subgroup_emotion_recognition = 0x00000080, /* emotion recognition subgroup */ + impl_subgroup_object_tracking = 0x00000100, /* object detection subgroup */ + impl_subgroup_3dseg = 0x00000200, /* user segmentation subgroup */ + impl_subgroup_3dscan = 0x00000400, /* mesh capture subgroup */ + impl_subgroup_scene_perception = 0x00000800, /* scene perception subgroup */ + + /* Photography building blocks */ + impl_subgroup_enhanced_photography = 0x00001000, /* enhanced photography subgroup */ + impl_subgroup_enhanced_videography = 0x00002000, /* enhanced videography subgroup */ + + /* sensor building blocks */ + impl_subgroup_audio_capture = 0x00000001, /* audio capture subgroup */ + impl_subgroup_video_capture = 0x00000002, /* video capture subgroup */ + + /* speech recognition building blocks */ + impl_subgroup_speech_recognition = 0x00000001, /* speech recognition subgroup */ + impl_subgroup_speech_synthesis = 0x00000002, /* speech synthesis subgroup */ + }; + enum + { + image_metadata_power_state = 0x35467859, + image_metadata_sample_id = 0x9F228B51, + }; + + /** + @brief Get the stream index number + @param[in] StreamType The stream type + @return The stream index number. + **/ + __inline static int32_t stream_type_to_index(stream_type type) + { + int32_t s = 0; + while (type > 1) type = (stream_type)(type >> 1), s++; + return s; + } + + class disk_format + { + public: + + enum chunk_id + { + chunk_deviceinfo = 1, + chunk_streaminfo = 2, + chunk_properties = 3, + chunk_profiles = 4, + chunk_serializeable = 5, + chunk_frame_meta_data = 6, + chunk_frame_data = 7, + chunk_image_meta_data = 8, + chunk_frame_indexing = 9, + chunk_sw_info = 10 + }; + + struct header + { + PXC_DEFINE_CONST(FILE_IDENTIFIER, UID('R', 'S', 'L', 'X')); + int32_t id; // File identifier + int32_t version; // file version + int32_t first_frame_offset; // The byte offset to the meta data of the first frame. + int32_t nstreams; // Number of streams + int64_t frame_indexing_offset; // The byte offset to the frame indexing structure. + file_types::coordinate_system coordinate_system; + int32_t reserved[25]; + }; + + struct chunk + { + disk_format::chunk_id chunk_id; + int32_t chunk_size; + }; + + struct frame_indexing + { + int32_t nframes[streams_limit]; + struct frame_info_st + { + rs_stream type; // stream type + int64_t offset; // file offset in bytes + int64_t time_stamp; // the time stamp in 100ns. + int32_t frame_number; // absolution frame number in the file + } *frame_list; // all frames in file + }; + + struct stream_info + { + stream_type stype; + compression_type ctype; + int32_t nframes; + }; + + struct frame_metadata + { + int32_t frame_number; + file_types::stream_type stream_type; + int64_t time_stamp; + image_option options; + int32_t reserved[3]; + }; + + struct device_info_disk + { + uint16_t name[224]; + uint16_t serial[32]; + uint16_t did[256]; + int32_t firmware[4]; + float location[2]; + device_model model; + device_orientation orientation; + stream_type streams; + int32_t didx; + int32_t duid; + file_types::rotation rotation; + connection_type connectionType; + int32_t reserved[11]; + }; + + struct stream_profile_disk + { + file_types::image_info image_info; /* resolution and color format */ + float frame_rate[2]; /* frame rate range. Set max when configuring FPS */ + stream_option options; /* bit-mask of stream options */ + int32_t reserved[5]; + }; + /** + @structure StreamProfileSet + The set of StreamProfile that describes the configuration parameters of all streams. + */ + struct stream_profile_set_disk + { + stream_profile_disk color; + stream_profile_disk depth; + stream_profile_disk ir; + stream_profile_disk left; + stream_profile_disk right; + stream_profile_disk reserved[streams_limit-5]; + + /** + @brief Access the configuration parameters by the stream type. + @param[in] type The stream type. + @return The StreamProfile instance. + */ + __inline stream_profile_disk &operator[](stream_type type) + { + if (type==stream_type::stream_type_color) return color; + if (type==stream_type::stream_type_depth) return depth; + if (type==stream_type::stream_type_ir) return ir; + if (type==stream_type::stream_type_left) return left; + if (type==stream_type::stream_type_right) return right; + for (int i=sizeof(reserved)/sizeof(reserved[0])-1,j=(1<<(streams_limit-1)); i>=0; i--,j>>=1) + if (type&j) return reserved[i]; + return reserved[sizeof(reserved)/sizeof(reserved[0])-1]; + } + }; + }; + } + } + } + } +} + diff --git a/sdk/src/cameras/playback/include/windows/windows_file_types.h b/sdk/src/cameras/playback/include/windows/windows_file_types.h deleted file mode 100644 index cb62973..0000000 --- a/sdk/src/cameras/playback/include/windows/windows_file_types.h +++ /dev/null @@ -1,463 +0,0 @@ -/******************************************************************************* - -INTEL CORPORATION PROPRIETARY INFORMATION -This software is supplied under the terms of a license agreement or nondisclosure -agreement with Intel Corporation and may not be copied or disclosed except in -accordance with the terms of that agreement -Copyright(c) 2013-2014 Intel Corporation. All Rights Reserved. - -*******************************************************************************/ -#pragma once - -//#include "RealSense/Image.h" -//#include "compression/compression.h" -//#include "pxcdefs.h" -//#include "RealSense/Sample.h" - - -namespace Intel -{ - namespace PXC - { - -#define STREAMS_LIMIT 8 -#define PXC_DEFINE_CONST(Y,X) enum {Y=X} - - class File; - - /** - @enum Property - Describes the device properties. - Use the inline functions to access specific device properties. - */ - enum Property - { - /* Color Stream Properties */ - PROPERTY_COLOR_EXPOSURE = 1, /* int32_t RW The color stream exposure, in log base 2 seconds. */ - PROPERTY_COLOR_BRIGHTNESS = 2, /* int32_t RW The color stream brightness from -10,000 (pure black) to 10,000 (pure white). */ - PROPERTY_COLOR_CONTRAST = 3, /* int32_t RW The color stream contrast, from 0 to 10,000. */ - PROPERTY_COLOR_SATURATION = 4, /* int32_t RW The color stream saturation, from 0 to 10,000. */ - PROPERTY_COLOR_HUE = 5, /* int32_t RW The color stream hue, from -180,000 to 180,000 (representing -180 to 180 degrees.) */ - PROPERTY_COLOR_GAMMA = 6, /* int32_t RW The color stream gamma, from 1 to 500. */ - PROPERTY_COLOR_WHITE_BALANCE = 7, /* int32_t RW The color stream balance, as a color temperature in degrees Kelvin. */ - PROPERTY_COLOR_SHARPNESS = 8, /* int32_t RW The color stream sharpness, from 0 to 100. */ - PROPERTY_COLOR_BACK_LIGHT_COMPENSATION = 9, /* bool32_t RW The color stream back light compensation. */ - PROPERTY_COLOR_GAIN = 10, /* int32_t RW The color stream gain adjustment, with negative values darker, positive values brighter, and zero as normal. */ - PROPERTY_COLOR_POWER_LINE_FREQUENCY = 11, /* int32_t RW The power line frequency in Hz. */ - PROPERTY_COLOR_FOCAL_LENGTH_MM = 12, /* float R The color-sensor focal length in mm. */ - PROPERTY_COLOR_FIELD_OF_VIEW = 1000, /* PXCPointF32 R The color-sensor horizontal and vertical field of view parameters, in degrees. */ - PROPERTY_COLOR_FOCAL_LENGTH = 1006, /* PXCPointF32 R The color-sensor focal length in pixels. The parameters vary with the resolution setting. */ - PROPERTY_COLOR_PRINCIPAL_POINT = 1008, /* PXCPointF32 R The color-sensor principal point in pixels. The parameters vary with the resolution setting. */ - - // Depth Stream Properties - PROPERTY_DEPTH_LOW_CONFIDENCE_VALUE = 201, /* pxcU16 R The special depth map value to indicate that the corresponding depth map pixel is of low-confidence. */ - PROPERTY_DEPTH_CONFIDENCE_THRESHOLD = 202, /* pxcI16 RW The confidence threshold that is used to floor the depth map values. The range is from 0 to 15. */ - PROPERTY_DEPTH_UNIT = 204, /* int32_t R The unit of depth values in micrometer if PIXEL_FORMAT_DEPTH_RAW */ - PROPERTY_DEPTH_FOCAL_LENGTH_MM = 205, /* float R The depth-sensor focal length in mm. */ - PROPERTY_DEPTH_FIELD_OF_VIEW = 2000, /* PXCPointF32 R The depth-sensor horizontal and vertical field of view parameters, in degrees. */ - PROPERTY_DEPTH_SENSOR_RANGE = 2002, /* PXCRangeF32 R The depth-sensor, sensing distance parameters, in millimeters. */ - PROPERTY_DEPTH_FOCAL_LENGTH = 2006, /* PXCPointF32 R The depth-sensor focal length in pixels. The parameters vary with the resolution setting. */ - PROPERTY_DEPTH_PRINCIPAL_POINT = 2008, /* PXCPointF32 R The depth-sensor principal point in pixels. The parameters vary with the resolution setting. */ - - // Device Properties - PROPERTY_DEVICE_ALLOW_PROFILE_CHANGE = 302, /* bool32_t RW If true, allow resolution change and throw PXC_STATUS_STREAM_CONFIG_CHANGED */ - PROPERTY_DEVICE_MIRROR = 304, /* MirrorMode RW The mirroring options. */ - - // Misc. Properties - PROPERTY_PROJECTION_SERIALIZABLE = 3003, /* pxcU32 R The meta data identifier of the Projection instance serialization data. */ - - // Device Specific Properties - IVCam - PROPERTY_IVCAM_LASER_POWER = 0x10000, /* int32_t RW The laser power value from 0 (minimum) to 16 (maximum). */ - PROPERTY_IVCAM_ACCURACY = 0x10001, /* IVCAMAccuracy RW The IVCAM accuracy value. */ - PROPERTY_IVCAM_FILTER_OPTION = 0x10003, /* int32_t RW The filter option (smoothing aggressiveness) ranged from 0 (close range) to 7 (far range). */ - PROPERTY_IVCAM_MOTION_RANGE_TRADE_OFF = 0x10004, /* int32_t RW This option specifies the motion and range trade off. The value ranged from 0 (short exposure, range, and better motion) to 100 (long exposure, range). */ - - // Device Specific Properties - DS - PROPERTY_DS_CROP = 0x20000, /* bool32_t RW Indicates whether to crop left and right images to match size of z image*/ - PROPERTY_DS_EMITTER = 0x20001, /* bool32_t RW Enable or disable DS emitter*/ - PROPERTY_DS_DISPARITY_OUTPUT = 0x20003, /* bool32_t RW Switches the range output mode between distance (Z) and disparity (inverse distance)*/ - PROPERTY_DS_DISPARITY_MULTIPLIER = 0x20004, /* int32_t RW Sets the disparity scale factor used when in disparity output mode. Default value is 32.*/ - PROPERTY_DS_DISPARITY_SHIFT = 0x20005, /* int32_t RW Reduces both the minimum and maximum depth that can be computed. - Allows range to be computed for points in the near field which would otherwise be beyond the disparity search range.*/ - PROPERTY_DS_MIN_MAX_Z = 0x20006, /* PXCRangeF32 RW The minimum z and maximum z in Z units that will be output */ - PROPERTY_DS_COLOR_RECTIFICATION = 0x20008, /* bool32_t R if true rectification is enabled to DS color*/ - PROPERTY_DS_DEPTH_RECTIFICATION = 0x20009, /* bool32_t R if true rectification is enabled to DS depth*/ - PROPERTY_DS_LEFTRIGHT_EXPOSURE = 0x2000A, /* float RW The depth stream exposure, in log base 2 seconds. */ - PROPERTY_DS_LEFTRIGHT_GAIN = 0x2000B, /* int32_t RW The depth stream gain adjustment, with negative values darker, positive values brighter, and zero as normal. */ - PROPERTY_DS_Z_TO_DISPARITY_CONSTANT = 0x2000C, /* float R used to convert between Z distance (in mm) and disparity (in pixels)*/ - PROPERTY_DS_ROBINS_MUNROE_MINUS_INCREMENT = 0x2000D, /* float RW Sets the value to subtract when estimating the median of the correlation surface.*/ - PROPERTY_DS_ROBINS_MUNROE_PLUS_INCREMENT = 0x2000E, /* float RW Sets the value to add when estimating the median of the correlation surface. */ - PROPERTY_DS_MEDIAN_THRESHOLD = 0x2000F, /* float RW Sets the threshold for how much the winning score must beat the median to be judged a reliable depth measurement. */ - PROPERTY_DS_SCORE_MIN_THRESHOLD = 0x20010, /* float RW Sets the minimum correlation score that is considered acceptable. */ - PROPERTY_DS_SCORE_MAX_THRESHOLD = 0x20011, /* float RW Sets the maximum correlation score that is considered acceptable. */ - PROPERTY_DS_TEXTURE_COUNT_THRESHOLD = 0x20012, /* float RW Set parameter for determining how much texture in the region is sufficient to be judged a reliable depth measurement. */ - PROPERTY_DS_TEXTURE_DIFFERENCE_THRESHOLD = 0x20013, /* float RW Set parameter for determining whether the texture in the region is sufficient to justify a reliable depth measurement. */ - PROPERTY_DS_SECOND_PEAK_THRESHOLD = 0x20014, /* float RW Sets the threshold for how much the minimum correlation score must differ from the next best score to be judged a reliable depth measurement. */ - PROPERTY_DS_NEIGHBOR_THRESHOLD = 0x20015, /* float RW Sets the threshold for how much at least one adjacent disparity score must differ from the minimum score to be judged a reliable depth measurement. */ - PROPERTY_DS_LR_THRESHOLD = 0x20016, /* float RW Determines the current threshold for determining whether the left-right match agrees with the right-left match. */ - - PROPERTY_SR300_COLOR_EXPOSURE_PRIORITY = 0x30000, /* float RW Sets the Color Exposure Priority. */ - PROPERTY_SR300_HDR_MODE = 0x30001, /* float RW Sets the HDR mode (0 = DISABLED). */ - - // Customized properties - PROPERTY_CUSTOMIZED = 0x04000000, /* CUSTOMIZED properties */ - }; - - /** - @structure DeviceCap - Describes a pair value of device property and its value. - Use the inline functions to access specific device properties. - */ - struct DeviceCap - { - Property label; /* Property type */ - float value; /* Property value */ - }; - - /** - @enum StreamOption - Describes the steam options. - */ - enum StreamOption - { - STREAM_OPTION_ANY = 0, - - // Optional options - STREAM_OPTION_OPTIONAL_MASK = 0x0000FFFF, /* The option can be added to any profile, but not necessarily supported for any profile */ - STREAM_OPTION_DEPTH_PRECALCULATE_UVMAP = 0x00000001, /* A flag to ask the device to precalculate UVMap */ - STREAM_OPTION_STRONG_STREAM_SYNC = 0x00000002, /* A flag to ask the device to perform strong (HW-based) synchronization on the streams with this flag. */ - - // Mandatory options - STREAM_OPTION_MANDATORY_MASK = 0xFFFF0000, /* If the option is supported - the device sets this flag in the profile */ - STREAM_OPTION_UNRECTIFIED = 0x00010000, /* A mandatory flag to ask the device to stream unrectified images on the stream with this flag */ - STREAM_OPTION_DEPTH_CONFIDENCE = 0x00020000 /* A mandatory flag to ask the device to attach confidence data to depth images (see PIXEL_FORMAT_DEPTH_CONFIDENCE) */ - }; - - /** - @enum PixelFormat - Describes the image sample pixel format - */ - enum PixelFormat - { - PIXEL_FORMAT_ANY = 0, /* Unknown/undefined */ - - // STREAM_TYPE_COLOR - PIXEL_FORMAT_YUY2 = 0x00010000, /* YUY2 image */ - PIXEL_FORMAT_NV12, /* NV12 image */ - PIXEL_FORMAT_RGB32, /* BGRA layout on a little-endian machine */ - PIXEL_FORMAT_RGB24, /* BGR layout on a little-endian machine */ - PIXEL_FORMAT_Y8, /* 8-Bit Gray Image, or IR 8-bit */ - - // STREAM_TYPE_DEPTH - PIXEL_FORMAT_DEPTH = 0x00020000, /* 16-bit unsigned integer with precision mm. */ - PIXEL_FORMAT_DEPTH_RAW, /* 16-bit unsigned integer with device specific precision (call device->QueryDepthUnit()) */ - PIXEL_FORMAT_DEPTH_F32, /* 32-bit float-point with precision mm. */ - PIXEL_FORMAT_DEPTH_CONFIDENCE = 0x40000004, /* Additional plane with 8-bits depth confidence (MSB) */ - - // STREAM_TYPE_IR - PIXEL_FORMAT_Y16 = 0x00040000, /* 16-Bit Gray Image */ - PIXEL_FORMAT_Y8_IR_RELATIVE = 0x00080000 /* Relative IR Image */ - }; - - /** - @enum DeviceModel - Describes the device model - */ - enum DeviceModel - { - DEVICE_MODEL_GENERIC = 0x00000000, /* a generic device or unknown device */ - DEVICE_MODEL_F200 = 0x0020000E, /* the Intel(R) RealSense(TM) 3D Camera, model F200 */ - DEVICE_MODEL_IVCAM = 0x0020000E, /* deprecated: the Intel(R) RealSense(TM) 3D Camera, model F200 */ - DEVICE_MODEL_R200 = 0x0020000F, /* the Intel(R) RealSense(TM) 3D Camera, model R200 */ - DEVICE_MODEL_DS4 = 0x0020000F, /* deprecated: the Intel(R) RealSense(TM) 3D Camera, model R200 */ - DEVICE_MODEL_SR300 = 0x00200010, /* The Intel(R) RealSense(TM) 3D Camera, model SR300 */ - DEVICE_MODEL_R200_ENHANCED = 0x0020001F, /* The Intel(R) RealSense(TM) 3D Camera, model R200 and Platform Camera */ - }; - - /** - @enum DeviceOrientation - Describes the device orientation - */ - enum DeviceOrientation - { - DEVICE_ORIENTATION_ANY = 0x0, /* Unknown orientation */ - DEVICE_ORIENTATION_USER_FACING = 0x1, /* A user facing camera */ - DEVICE_ORIENTATION_FRONT_FACING = 0x1, /* A front facing camera */ - DEVICE_ORIENTATION_WORLD_FACING = 0x2, /* A world facing camera */ - DEVICE_ORIENTATION_REAR_FACING = 0x2, /* A rear facing camera */ - }; - - - /** - @enum Rotation - Image rotation options. - */ - enum Rotation - { - ROTATION_0_DEGREE = 0x0, /* 0 Degree rotation */ - ROTATION_90_DEGREE = 90, /* 90 degree clockwise rotation */ - ROTATION_180_DEGREE = 180, /* 180 degree clockwise rotation */ - ROTATION_270_DEGREE = 270, /* 270 degree clockwise rotation */ - }; - - /** - @struct ImageInfo - Describes the image sample detailed information. - */ - struct ImageInfo - { - int32_t width; /* width of the image in pixels */ - int32_t height; /* height of the image in pixels */ - PixelFormat format; /* image pixel format */ - int32_t reserved; - }; - - /** - @enum Option - Describes the image options. - */ - enum ImageOption - { - OPTION_ANY = 0, - }; - - enum compression_type - { - COMPRESSION_NONE = 0, - COMPRESSION_H264, - COMPRESSION_LZO - }; - - /** - @enum StreamType - Bit-OR'ed values of stream types, physical or virtual streams. - */ - enum StreamType - { - STREAM_TYPE_ANY = 0, /* Unknown/undefined type */ - STREAM_TYPE_COLOR = 0x0001, /* the color stream type */ - STREAM_TYPE_DEPTH = 0x0002, /* the depth stream type */ - STREAM_TYPE_IR = 0x0004, /* the infrared stream type */ - STREAM_TYPE_LEFT = 0x0008, /* the stereoscopic left intensity image */ - STREAM_TYPE_RIGHT = 0x0010, /* the stereoscopic right intensity image */ - }; - - /** - @enum ConnectionType - Describes the Connection type of the device - */ - enum ConnectionType - { - CONNECTION_TYPE_UNKNOWN = 0, /* Any connection type */ - CONNECTION_TYPE_USB_INTEGRATED, /* USB Integrated Camera */ - CONNECTION_TYPE_USB_PERIPHERAL /* USB Peripheral Camera */ - }; - - struct Version - { - u_int32_t major; - u_int32_t minor; - u_int32_t build; - u_int32_t revision; - }; - - /** - @enum CoordinateSystem - SDK supports several 3D coordinate systems for front and rear facing cameras. - */ - enum CoordinateSystem - { - COORDINATE_SYSTEM_REAR_DEFAULT = 0x100, /* Right-hand system: X right, Y up, Z to the user */ - COORDINATE_SYSTEM_REAR_OPENCV = 0x200, /* Right-hand system: X right, Y down, Z to the world */ - COORDINATE_SYSTEM_FRONT_DEFAULT = 0x001, /* Left-hand system: X left, Y up, Z to the user */ - }; - - /** - @enum ImplGroup - The SDK group I/O and algorithm modules into groups and subgroups. - This is the enumerator for algorithm groups. - */ - enum ImplGroup - { - IMPL_GROUP_ANY = 0, /* Undefine group */ - IMPL_GROUP_OBJECT_RECOGNITION = 0x00000001, /* Object recognition algorithms */ - IMPL_GROUP_SPEECH_RECOGNITION = 0x00000002, /* Speech recognition algorithms */ - IMPL_GROUP_SENSOR = 0x00000004, /* I/O modules */ - IMPL_GROUP_PHOTOGRAPHY = 0x00000008, /* Photography/Videography algorithms */ - IMPL_GROUP_UTILITIES = 0x00000010, /* Utility modules */ - IMPL_GROUP_CORE = 0x80000000, /* Core SDK modules */ - IMPL_GROUP_USER = 0x40000000, /* User defined algorithms */ - }; - - /** - @enum ImplSubgroup - The SDK group I/O and algorithm modules into groups and subgroups. - This is the enumerator for algorithm subgroups. - */ - enum ImplSubgroup - { - IMPL_SUBGROUP_ANY = 0, /* Undefined subgroup */ - - /* object recognition building blocks */ - IMPL_SUBGROUP_FACE_ANALYSIS = 0x00000001, /* face analysis subgroup */ - IMPL_SUBGROUP_GESTURE_RECOGNITION = 0x00000010, /* gesture recognition subgroup */ - IMPL_SUBGROUP_SEGMENTATION = 0x00000020, /* segmentation subgroup */ - IMPL_SUBGROUP_PULSE_ESTIMATION = 0x00000040, /* pulse estimation subgroup */ - IMPL_SUBGROUP_EMOTION_RECOGNITION = 0x00000080, /* emotion recognition subgroup */ - IMPL_SUBGROUP_OBJECT_TRACKING = 0x00000100, /* object detection subgroup */ - IMPL_SUBGROUP_3DSEG = 0x00000200, /* user segmentation subgroup */ - IMPL_SUBGROUP_3DSCAN = 0x00000400, /* mesh capture subgroup */ - IMPL_SUBGROUP_SCENE_PERCEPTION = 0x00000800, /* scene perception subgroup */ - - /* Photography building blocks */ - IMPL_SUBGROUP_ENHANCED_PHOTOGRAPHY = 0x00001000, /* enhanced photography subgroup */ - IMPL_SUBGROUP_ENHANCED_VIDEOGRAPHY = 0x00002000, /* enhanced videography subgroup */ - - /* sensor building blocks */ - IMPL_SUBGROUP_AUDIO_CAPTURE = 0x00000001, /* audio capture subgroup */ - IMPL_SUBGROUP_VIDEO_CAPTURE = 0x00000002, /* video capture subgroup */ - - /* speech recognition building blocks */ - IMPL_SUBGROUP_SPEECH_RECOGNITION = 0x00000001, /* speech recognition subgroup */ - IMPL_SUBGROUP_SPEECH_SYNTHESIS = 0x00000002, /* speech synthesis subgroup */ - }; - enum - { - IMAGE_METADATA_POWER_STATE = 0x35467859, - IMAGE_METADATA_SAMPLE_ID = 0x9F228B51, - }; - - /** - @brief Get the stream index number - @param[in] StreamType The stream type - @return The stream index number. - **/ - __inline static int32_t StreamTypeToIndex(StreamType type) - { - int32_t s = 0; - while (type > 1) type = (StreamType)(type >> 1), s++; - return s; - } - - class CMDiskFormat - { - public: - - enum ChunkId - { - CHUNK_DEVICEINFO = 1, - CHUNK_STREAMINFO = 2, - CHUNK_PROPERTIES = 3, - CHUNK_PROFILES = 4, - CHUNK_SERIALIZEABLE = 5, - CHUNK_FRAME_META_DATA = 6, - CHUNK_FRAME_DATA = 7, - CHUNK_IMAGE_META_DATA = 8, - CHUNK_FRAME_INDEXING = 9, - CHUNK_SW_INFO = 10 - }; - - struct Header - { - PXC_DEFINE_CONST(FILE_IDENTIFIER, PXC_UID('R', 'S', 'L', 'X')); - int32_t id; // File identifier - int32_t version; // file version - int32_t firstFrameOffset; // The byte offset to the meta data of the first frame. - int32_t nstreams; // Number of streams - int64_t frameIndexingOffset; // The byte offset to the frame indexing structure. - int32_t coordinateSystem; - int32_t reserved[25]; - }; - - struct Chunk - { - ChunkId chunkId; - int32_t chunkSize; - }; - - struct FrameIndexing - { - int32_t nframes[STREAMS_LIMIT]; - struct frameInfo_st - { - rs::stream type; // stream type - int64_t offset; // file offset in bytes - int64_t timeStamp; // the time stamp in 100ns. - int32_t frameNumber; // absolution frame number in the file - } *frameList; // all frames in file - }; - - struct StreamInfo - { - StreamType stype; - compression_type ctype; - int32_t nframes; - }; - - struct FrameMetaData - { - int32_t syncId; - StreamType streamType; - int64_t timeStamp; - ImageOption options; - int32_t reserved; - }; - - struct DeviceInfoDisk - { - u_int16_t name[224]; - u_int16_t serial[32]; - u_int16_t did[256]; - int32_t firmware[4]; - float location[2]; - DeviceModel model; - DeviceOrientation orientation; - StreamType streams; - int32_t didx; - int32_t duid; - Rotation rotation; - ConnectionType connectionType; - int32_t reserved[11]; - }; - - struct StreamProfileDisk - { - ImageInfo imageInfo; /* resolution and color format */ - float frameRate[2]; /* frame rate range. Set max when configuring FPS */ - StreamOption options; /* bit-mask of stream options */ - int32_t reserved[5]; - }; - /** - @structure StreamProfileSet - The set of StreamProfile that describes the configuration parameters of all streams. - */ - struct StreamProfileSetDisk - { - StreamProfileDisk color; - StreamProfileDisk depth; - StreamProfileDisk ir; - StreamProfileDisk left; - StreamProfileDisk right; - StreamProfileDisk reserved[STREAMS_LIMIT-5]; - - /** - @brief Access the configuration parameters by the stream type. - @param[in] type The stream type. - @return The StreamProfile instance. - */ - __inline StreamProfileDisk &operator[](StreamType type) - { - if (type==StreamType::STREAM_TYPE_COLOR) return color; - if (type==StreamType::STREAM_TYPE_DEPTH) return depth; - if (type==StreamType::STREAM_TYPE_IR) return ir; - if (type==StreamType::STREAM_TYPE_LEFT) return left; - if (type==StreamType::STREAM_TYPE_RIGHT) return right; - for (int i=sizeof(reserved)/sizeof(reserved[0])-1,j=(1<<(STREAMS_LIMIT-1)); i>=0; i--,j>>=1) - if (type&j) return reserved[i]; - return reserved[sizeof(reserved)/sizeof(reserved[0])-1]; - } - }; - }; - } -} - diff --git a/sdk/src/cameras/playback/linux/disk_read_linux.cpp b/sdk/src/cameras/playback/linux/disk_read_linux.cpp deleted file mode 100644 index ad60497..0000000 --- a/sdk/src/cameras/playback/linux/disk_read_linux.cpp +++ /dev/null @@ -1,181 +0,0 @@ -// License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2016 Intel Corporation. All Rights Reserved - -#include "linux/disk_read_linux.h" -#include "file/file.h" -#include "rs/utils/log_utils.h" - -using namespace rs::core; -using namespace rs::playback; - -disk_read_linux::~disk_read_linux(void) -{ - LOG_FUNC_SCOPE(); - pause(); -} - -status disk_read_linux::read_headers() -{ - /* Get the file header */ - m_file_data_read->set_position(0, move_method::begin); - uint32_t nbytesRead = 0; - unsigned long nbytesToRead = 0; - file_types::disk_format::file_header fh; - m_file_data_read->read_bytes(&fh, sizeof(fh), nbytesRead); - m_file_header = fh.data; - if (nbytesRead < sizeof(m_file_header)) return status_item_unavailable; - if (m_file_header.id != UID('R', 'S', 'L', '1')) return status_param_unsupported; - - /* Get all chunks */ - for (;;) - { - file_types::chunk_info chunk = {}; - m_file_data_read->read_bytes(&chunk, sizeof(chunk), nbytesRead); - if (nbytesRead < sizeof(chunk)) break; - if (chunk.id == file_types::chunk_id::chunk_sample_info) break; - nbytesToRead = chunk.size; - switch (chunk.id) - { - case file_types::chunk_id::chunk_device_info: - { - file_types::disk_format::device_info dinfo; - m_file_data_read->read_bytes(&dinfo, std::min(nbytesToRead, (unsigned long)sizeof(dinfo)), nbytesRead); - m_device_info = dinfo.data; - nbytesToRead -= nbytesRead; - LOG_INFO("read device info chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) - } - break; - case file_types::chunk_id::chunk_properties: - do - { - file_types::device_cap devcap = {}; - m_file_data_read->read_bytes(&devcap, std::min(nbytesToRead, (unsigned long)sizeof(devcap)), nbytesRead); - m_properties[devcap.label] = devcap.value; - nbytesToRead -= nbytesRead; - } - while (nbytesToRead > 0 && nbytesRead > 0); - LOG_INFO("read properties chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) - break; - case file_types::chunk_id::chunk_serializeable: - { - rs_option label = (rs_option)0; - m_file_data_read->read_bytes(&label, std::min(nbytesToRead, (unsigned long)sizeof(label)), nbytesRead); - nbytesToRead -= nbytesRead; - std::vector data(nbytesToRead); - m_file_data_read->read_bytes(data.data(), nbytesToRead, nbytesRead); - nbytesToRead -= nbytesRead; - LOG_INFO("read serializeable chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) - } - break; - case file_types::chunk_id::chunk_stream_info: - for (int i = 0; i < m_file_header.nstreams; i++) - { - file_types::disk_format::stream_info stream_info1 = {}; - m_file_data_read->read_bytes(&stream_info1, std::min(nbytesToRead, (unsigned long)sizeof(stream_info1)), nbytesRead); - m_streams_infos[stream_info1.data.stream] = stream_info1.data; - nbytesToRead -= nbytesRead; - } - LOG_INFO("read stream info chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) - break; - case file_types::chunk_id::chunk_sw_info: - { - file_types::disk_format::sw_info swinfo; - m_file_data_read->read_bytes(&swinfo, std::min(nbytesToRead, (unsigned long)sizeof(swinfo)), nbytesRead); - m_sw_info = swinfo.data; - nbytesToRead -= nbytesRead; - LOG_INFO("read sw info chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) - } - break; - case file_types::chunk_id::chunk_capabilities: - { - std::vector caps(chunk.size / sizeof(rs_capabilities)); - m_file_data_read->read_bytes(caps.data(), chunk.size, nbytesRead); - m_capabilities = caps; - nbytesToRead -= nbytesRead; - LOG_INFO("read capabilities chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) - } - break; - default: - std::vector data(nbytesToRead); - m_file_data_read->read_bytes(&data[0], nbytesToRead, nbytesRead); - m_unknowns[chunk.id] = data; - nbytesToRead -= nbytesRead; - LOG_INFO("read unknown chunk " << (nbytesToRead == 0 ? "succeeded" : "failed") << "chunk id - " << chunk.id) - } - if (nbytesToRead > 0) return status_item_unavailable; - } - return status_no_error; -} - -void disk_read_linux::index_next_samples(uint32_t number_of_samples) -{ - if (m_is_index_complete) return; - - std::lock_guard guard(m_mutex); - - for (uint32_t index = 0; index < number_of_samples;) - { - file_types::chunk_info chunk = {}; - uint32_t nbytesRead = 0; - m_file_indexing->read_bytes(&chunk, sizeof(chunk), nbytesRead); - if (nbytesRead < sizeof(chunk) || chunk.size <= 0 || chunk.size > 100000000 /*invalid chunk*/) - { - m_is_index_complete = true; - LOG_INFO("samples indexing is done") - break; - } - if(chunk.id == file_types::chunk_id::chunk_sample_info) - { - file_types::disk_format::sample_info si; - m_file_indexing->read_bytes(&si, std::min((long unsigned)chunk.size, (unsigned long)sizeof(si)), nbytesRead); - auto sample_info = si.data; - file_types::chunk_info chunk2 = {}; - m_file_indexing->read_bytes(&chunk2, sizeof(chunk2), nbytesRead); - switch(sample_info.type) - { - case file_types::sample_type::st_image: - { - file_types::disk_format::frame_info fi = {}; - m_file_indexing->read_bytes(&fi, std::min((long unsigned)chunk2.size, (unsigned long)sizeof(fi)), nbytesRead); - file_types::frame_info frame_info = fi.data; - frame_info.index_in_stream = m_image_indices[frame_info.stream].size(); - m_image_indices[frame_info.stream].push_back(m_samples_desc.size()); - m_samples_desc.push_back(std::make_shared(frame_info, sample_info)); - ++index; - LOG_VERBOSE("frame sample indexed, sample time - " << sample_info.capture_time) - break; - } - case file_types::sample_type::st_motion: - { - file_types::disk_format::motion_data md = {}; - m_file_indexing->read_bytes(&md, std::min((long unsigned)chunk2.size, (unsigned long)sizeof(md)), nbytesRead); - rs_motion_data motion_data = md.data; - m_samples_desc.push_back(std::make_shared(motion_data, sample_info)); - ++index; - LOG_VERBOSE("motion sample indexed, sample time - " << sample_info.capture_time) - break; - } - case file_types::sample_type::st_time: - { - file_types::disk_format::time_stamp_data tsd = {}; - m_file_indexing->read_bytes(&tsd, std::min((long unsigned)chunk2.size, (unsigned long)sizeof(tsd)), nbytesRead); - rs_timestamp_data time_stamp_data = tsd.data; - m_samples_desc.push_back(std::make_shared(time_stamp_data, sample_info)); - ++index; - LOG_VERBOSE("time stamp sample indexed, sample time - " << sample_info.capture_time) - break; - } - } - } - else - { - m_file_indexing->set_position(chunk.size, move_method::current); - continue; - } - } -} - -int32_t disk_read_linux::size_of_pitches(void) -{ - return 0; -} diff --git a/sdk/src/cameras/playback/linux/v1/disk_read.cpp b/sdk/src/cameras/playback/linux/v1/disk_read.cpp new file mode 100644 index 0000000..f82c28e --- /dev/null +++ b/sdk/src/cameras/playback/linux/v1/disk_read.cpp @@ -0,0 +1,200 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2016 Intel Corporation. All Rights Reserved + +#include "disk_read.h" +#include "linux/v1/disk_read.h" +#include "linux/v1/conversions.h" +#include "file/file.h" +#include "rs/utils/log_utils.h" + +namespace rs +{ + namespace playback + { + namespace linux + { + namespace v1 + { + disk_read::~disk_read(void) + { + LOG_FUNC_SCOPE(); + pause(); + } + + core::status disk_read::read_headers() + { + /* Get the file header */ + m_file_data_read->set_position(0, core::move_method::begin); + uint32_t nbytesRead = 0; + unsigned long nbytesToRead = 0; + file_types::disk_format::file_header fh; + m_file_data_read->read_bytes(&fh, sizeof(fh), nbytesRead); + if(conversions::convert(fh.data, m_file_header) != core::status::status_no_error) + return core::status::status_item_unavailable; + if (nbytesRead < sizeof(m_file_header)) return core::status::status_item_unavailable; + if (m_file_header.id != UID('R', 'S', 'L', '1')) return core::status::status_param_unsupported; + + /* Get all chunks */ + for (;;) + { + core::file_types::chunk_info chunk = {}; + m_file_data_read->read_bytes(&chunk, sizeof(chunk), nbytesRead); + if (nbytesRead < sizeof(chunk)) break; + if (chunk.id == core::file_types::chunk_id::chunk_sample_info) break; + nbytesToRead = chunk.size; + switch (chunk.id) + { + case core::file_types::chunk_id::chunk_device_info: + { + file_types::disk_format::device_info dinfo; + m_file_data_read->read_bytes(&dinfo, std::min(nbytesToRead, (unsigned long)sizeof(dinfo)), nbytesRead); + if(conversions::convert(dinfo.data, m_device_info) != core::status::status_no_error) + return core::status::status_item_unavailable; + nbytesToRead -= nbytesRead; + LOG_INFO("read device info chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + } + break; + case core::file_types::chunk_id::chunk_properties: + do + { + core::file_types::device_cap devcap = {}; + m_file_data_read->read_bytes(&devcap, std::min(nbytesToRead, (unsigned long)sizeof(devcap)), nbytesRead); + m_properties[devcap.label] = devcap.value; + nbytesToRead -= nbytesRead; + } + while (nbytesToRead > 0 && nbytesRead > 0); + LOG_INFO("read properties chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + break; + case core::file_types::chunk_id::chunk_serializeable: + { + rs_option label = (rs_option)0; + m_file_data_read->read_bytes(&label, std::min(nbytesToRead, (unsigned long)sizeof(label)), nbytesRead); + nbytesToRead -= nbytesRead; + std::vector data(nbytesToRead); + m_file_data_read->read_bytes(data.data(), nbytesToRead, nbytesRead); + nbytesToRead -= nbytesRead; + LOG_INFO("read serializeable chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + } + break; + case core::file_types::chunk_id::chunk_stream_info: + for (int i = 0; i < m_file_header.nstreams; i++) + { + file_types::disk_format::stream_info stream_info1 = {}; + m_file_data_read->read_bytes(&stream_info1, std::min(nbytesToRead, (unsigned long)sizeof(stream_info1)), nbytesRead); + if(conversions::convert(stream_info1.data, m_streams_infos[stream_info1.data.stream]) != core::status::status_no_error) + return core::status::status_item_unavailable; + // m_streams_infos[stream_info1.data.stream] = stream_info1.data; + nbytesToRead -= nbytesRead; + } + LOG_INFO("read stream info chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + break; + case core::file_types::chunk_id::chunk_sw_info: + { + file_types::disk_format::sw_info swinfo; + m_file_data_read->read_bytes(&swinfo, std::min(nbytesToRead, (unsigned long)sizeof(swinfo)), nbytesRead); + if(conversions::convert(swinfo.data, m_sw_info) != core::status::status_no_error) + return core::status::status_item_unavailable; + nbytesToRead -= nbytesRead; + LOG_INFO("read sw info chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + } + break; + case core::file_types::chunk_id::chunk_capabilities: + { + std::vector caps(chunk.size / sizeof(rs_capabilities)); + m_file_data_read->read_bytes(caps.data(), chunk.size, nbytesRead); + m_capabilities = caps; + nbytesToRead -= nbytesRead; + LOG_INFO("read capabilities chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + } + break; + default: + std::vector data(nbytesToRead); + m_file_data_read->read_bytes(&data[0], nbytesToRead, nbytesRead); + m_unknowns[chunk.id] = data; + nbytesToRead -= nbytesRead; + LOG_INFO("read unknown chunk " << (nbytesToRead == 0 ? "succeeded" : "failed") << "chunk id - " << chunk.id) + } + if (nbytesToRead > 0) return core::status::status_item_unavailable; + } + return core::status::status_no_error; + } + + void disk_read::index_next_samples(uint32_t number_of_samples) + { + if (m_is_index_complete) return; + + std::lock_guard guard(m_mutex); + + for (uint32_t index = 0; index < number_of_samples;) + { + core::file_types::chunk_info chunk = {}; + uint32_t nbytesRead = 0; + m_file_indexing->read_bytes(&chunk, sizeof(chunk), nbytesRead); + if (nbytesRead < sizeof(chunk) || chunk.size <= 0 || chunk.size > 100000000 /*invalid chunk*/) + { + m_is_index_complete = true; + LOG_INFO("samples indexing is done") + break; + } + if(chunk.id == core::file_types::chunk_id::chunk_sample_info) + { + file_types::disk_format::sample_info si; + m_file_indexing->read_bytes(&si, std::min((long unsigned)chunk.size, (unsigned long)sizeof(si)), nbytesRead); + core::file_types::sample_info sample_info; + if(conversions::convert(si.data, sample_info) != core::status::status_no_error) continue; + core::file_types::chunk_info chunk2 = {}; + m_file_indexing->read_bytes(&chunk2, sizeof(chunk2), nbytesRead); + switch(sample_info.type) + { + case core::file_types::sample_type::st_image: + { + file_types::disk_format::frame_info fi = {}; + m_file_indexing->read_bytes(&fi, std::min((long unsigned)chunk2.size, (unsigned long)sizeof(fi)), nbytesRead); + core::file_types::frame_info frame_info; + assert(conversions::convert(fi.data, frame_info) == core::status::status_no_error); + frame_info.index_in_stream = m_image_indices[frame_info.stream].size(); + m_image_indices[frame_info.stream].push_back(m_samples_desc.size()); + m_samples_desc.push_back(std::make_shared(frame_info, sample_info)); + ++index; + LOG_VERBOSE("frame sample indexed, sample time - " << sample_info.capture_time) + break; + } + case core::file_types::sample_type::st_motion: + { + file_types::disk_format::motion_data md = {}; + m_file_indexing->read_bytes(&md, std::min((long unsigned)chunk2.size, (unsigned long)sizeof(md)), nbytesRead); + rs_motion_data motion_data = md.data; + m_samples_desc.push_back(std::make_shared(motion_data, sample_info)); + ++index; + LOG_VERBOSE("motion sample indexed, sample time - " << sample_info.capture_time) + break; + } + case core::file_types::sample_type::st_time: + { + file_types::disk_format::time_stamp_data tsd = {}; + m_file_indexing->read_bytes(&tsd, std::min((long unsigned)chunk2.size, (unsigned long)sizeof(tsd)), nbytesRead); + rs_timestamp_data time_stamp_data = tsd.data; + m_samples_desc.push_back(std::make_shared(time_stamp_data, sample_info)); + ++index; + LOG_VERBOSE("time stamp sample indexed, sample time - " << sample_info.capture_time) + break; + } + } + } + else + { + m_file_indexing->set_position(chunk.size, core::move_method::current); + continue; + } + } + } + + int32_t disk_read::size_of_pitches(void) + { + return 0; + } + } + } + } +} + diff --git a/sdk/src/cameras/playback/playback_context.cpp b/sdk/src/cameras/playback/playback_context.cpp index 4952d73..ffde98c 100644 --- a/sdk/src/cameras/playback/playback_context.cpp +++ b/sdk/src/cameras/playback/playback_context.cpp @@ -9,15 +9,21 @@ namespace rs { namespace playback { - context::context(const std::string& file_path) : m_init_status(false) + context::context(const char *file_path) : m_init_status(false) { - m_device = std::unique_ptr(new rs_device_ex(file_path)); - m_init_status = ((rs_device_ex*)m_device.get())->init(); + m_devices = new rs_device*[1]; + m_devices[0] = new rs_device_ex(file_path); + m_init_status = ((rs_device_ex*)m_devices[0])->init(); } context::~context() { - + for(auto i = 0; i < 1; i++) + { + if(m_devices[i]) + delete m_devices[i]; + } + delete[] m_devices; } int context::get_device_count() const @@ -32,7 +38,7 @@ namespace rs device * context::get_playback_device() { - return m_init_status ? (device*)m_device.get() : nullptr; + return m_init_status ? (device*)m_devices[0] : nullptr; } } } diff --git a/sdk/src/cameras/playback/playback_device_impl.cpp b/sdk/src/cameras/playback/playback_device_impl.cpp index 28f6a4a..01d5e9b 100644 --- a/sdk/src/cameras/playback/playback_device_impl.cpp +++ b/sdk/src/cameras/playback/playback_device_impl.cpp @@ -126,7 +126,7 @@ namespace rs const char * rs_device_ex::get_firmware_version() const { - return m_disk_read->get_device_info().firmware; + return m_disk_read->get_device_info().camera_firmware; } float rs_device_ex::get_depth_scale() const @@ -358,6 +358,32 @@ namespace rs return m_disk_read->get_device_info().usb_port_id; } + const char * rs_device_ex::get_camera_info(rs_camera_info info_type) const + { + const file_types::device_info &info = m_disk_read->get_device_info(); + switch(info_type) + { + case RS_CAMERA_INFO_DEVICE_NAME: return info.name; + case RS_CAMERA_INFO_DEVICE_SERIAL_NUMBER: return info.serial; + case RS_CAMERA_INFO_CAMERA_FIRMWARE_VERSION: return info.camera_firmware; + case RS_CAMERA_INFO_ADAPTER_BOARD_FIRMWARE_VERSION: return info.adapter_board_firmware; + case RS_CAMERA_INFO_MOTION_MODULE_FIRMWARE_VERSION: return info.motion_module_firmware; + default: return nullptr; + } + } + + rs_motion_intrinsics rs_device_ex::get_motion_intrinsics() const + { + return m_disk_read->get_motion_intrinsics(); + } + + rs_extrinsics rs_device_ex::get_motion_extrinsics_from(rs_stream from) const + { + rs_extrinsics rv = {}; + auto infos = m_disk_read->get_streams_infos(); + return infos.find(from) != infos.end() ? infos[from].profile.motion_extrinsics : rv; + } + bool rs_device_ex::is_real_time() { return m_disk_read->query_realtime(); diff --git a/sdk/src/cameras/playback/windows/conversions.cpp b/sdk/src/cameras/playback/windows/conversions.cpp deleted file mode 100644 index bf17eec..0000000 --- a/sdk/src/cameras/playback/windows/conversions.cpp +++ /dev/null @@ -1,300 +0,0 @@ -// License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2016 Intel Corporation. All Rights Reserved. - -#include "windows/conversions.h" -#include "linear_algebra/linear_algebra.h" - -namespace rs -{ - namespace win_file - { - namespace conversions - { - - uint64_t rssdk2lrs_timestamp(uint64_t time) - { - return time * 0.0001; - } - - core::status convert(stream_type source, rs_stream &target) - { - target = (rs_stream)-1; - switch(source) - { - case stream_type::stream_type_color: target = rs_stream::RS_STREAM_COLOR; break; - case stream_type::stream_type_depth: target = rs_stream::RS_STREAM_DEPTH; break; - case stream_type::stream_type_ir: target = rs_stream::RS_STREAM_INFRARED; break; - case stream_type::stream_type_left: target = rs_stream::RS_STREAM_INFRARED; break; - case stream_type::stream_type_right: target = rs_stream::RS_STREAM_INFRARED2; break; - default: return core::status_item_unavailable; break; - } - return core::status_no_error; - } - - core::status convert(compression_type source, core::file_types::compression_type &target) - { - target = (core::file_types::compression_type)-1; - switch(source) - { - case compression_none: target = core::file_types::compression_type::none; break; - case compression_h264: target = core::file_types::compression_type::h264; break; - case compression_lzo: target = core::file_types::compression_type::lzo; break; - default: return core::status_item_unavailable; break; - } - return core::status_no_error; - } - - core::status convert(rotation source, rs::core::rotation &target) - { - target = (rs::core::rotation)-1; - switch(source) - { - case rotation:: rotation_0_degree: target = rs::core::rotation::rotation_0_degree; break; - case rotation:: rotation_90_degree: target = rs::core::rotation::rotation_90_degree; break; - case rotation:: rotation_180_degree: target = rs::core::rotation::rotation_180_degree; break; - case rotation:: rotation_270_degree: target = rs::core::rotation::rotation_270_degree; break; - default: return core::status_item_unavailable; break; - } - return core::status_no_error; - } - - core::status convert(pixel_format source, rs_format &target) - { - target = (rs_format)-1; - switch(source) - { - case pixel_format::pf_any: target = rs_format::RS_FORMAT_ANY; break; - case pixel_format::pf_depth: target = rs_format::RS_FORMAT_Z16; break; - case pixel_format::pf_depth_f32: target = rs_format::RS_FORMAT_XYZ32F; break; - case pixel_format::pf_yuy2: target = rs_format::RS_FORMAT_YUYV; break; - case pixel_format::pf_rgb24: target = rs_format::RS_FORMAT_RGB8; break; - case pixel_format::pf_rgb32: target = rs_format::RS_FORMAT_BGRA8; break; - case pixel_format::pf_y8: target = rs_format::RS_FORMAT_Y8; break; - case pixel_format::pf_y16: target = rs_format::RS_FORMAT_Y16; break; - case pixel_format::pf_raw: target = rs_format::RS_FORMAT_RAW10; break; - default: return core::status_item_unavailable; break; - } - return core::status_no_error; - } - - core::status convert(const coordinate_system &source, core::file_types::coordinate_system &target) - { - target = (core::file_types::coordinate_system)-1; - switch(source) - { - case coordinate_system::coordinate_system_rear_default: target = core::file_types::coordinate_system::rear_default; break; - case coordinate_system::coordinate_system_rear_opencv: target = core::file_types::coordinate_system::rear_opencv; break; - case coordinate_system::coordinate_system_front_default: target = core::file_types::coordinate_system::front_default; break; - default: target = (core::file_types::coordinate_system)source; break; - } - return core::status_no_error; - } - - core::status convert(const disk_format::header &source, core::file_types::file_header &target) - { - memset(&target, 0, sizeof(target)); - core::file_types::coordinate_system cs; - if(convert(source.coordinate_system, cs) != core::status_no_error) - return core::status_item_unavailable; - target.id = source.id; - target.version = source.version; - target.coordinate_system = cs; - target.first_frame_offset = source.first_frame_offset; - target.nstreams = source.nstreams; - return core::status_no_error; - } - - core::status convert(const disk_format::stream_info &source, core::file_types::stream_info &target) - { - memset(&target, 0, sizeof(target)); - rs_stream stream; - core::file_types::compression_type ctype; - if(convert(source.stype, stream) != core::status_no_error || convert(source.ctype, ctype) != core::status_no_error) - return core::status_item_unavailable; - target.stream = stream; - target.nframes = source.nframes; - target.ctype = ctype; - return core::status_no_error; - } - - core::status convert(const disk_format::device_info_disk &source, core::file_types::device_info &target) - { - memset(&target, 0, sizeof(target)); - rs::core::rotation rotaion; - if(convert(source.rotation, rotaion) != core::status_no_error) - return core::status_item_unavailable; - auto nameSize = sizeof(target.name) / sizeof(target.name[0]); - for(size_t i = 0; i < nameSize; i++) - target.name[i] = source.name[i]; - auto serialSize = sizeof(target.serial) / sizeof(target.serial[0]); - for(size_t i = 0; i < serialSize; i++) - target.serial[i] = source.serial[i]; - std::stringstream ss; - ss << source.firmware[0] << "." << source.firmware[1] << "." << - source.firmware[2] << "." << source.firmware[3]; - memcpy(&target.firmware, ss.str().c_str(), ss.str().size()); - return core::status_no_error; - } - - core::status convert(const image_info &source, core::file_types::frame_info &target) - { - memset(&target, 0, sizeof(target)); - rs_format format; - if(convert(source.format, format) != core::status_no_error) - return core::status_item_unavailable; - target.width = source.width; - target.height = source.height; - target.stride_x = source.width == 628 ? 640 : source.width; - target.stride_y = source.height == 468 ? 480 : source.height; - target.bpp = rs::core::image_utils::get_pixel_size(format); - target.format = format; - return core::status_no_error; - } - - core::status convert(const disk_format::stream_profile_disk &source, core::file_types::stream_profile &target) - { - memset(&target, 0, sizeof(target)); - core::file_types::frame_info frame_info; - if(convert(source.image_info, frame_info) != core::status_no_error) - return core::status_item_unavailable; - if(source.frame_rate[0] != source.frame_rate[1]) - { - LOG_ERROR("min != max fps is not supported, setting to min"); - } - target.frame_rate = source.frame_rate[0]; - target.info = frame_info; - - return core::status_no_error; - //rv.options = profile.options; - } - - core::status convert(const disk_format::stream_profile_set_disk &source, std::map &target) - { - core::file_types::stream_profile sp; - if(source.color.image_info.format) - { - if(convert(source.color, sp) != core::status_no_error) return core::status_item_unavailable; - target[rs_stream::RS_STREAM_COLOR].profile = sp; - } - if(source.depth.image_info.format) - { - if(convert(source.depth, sp) != core::status_no_error) return core::status_item_unavailable; - target[rs_stream::RS_STREAM_DEPTH].profile = sp; - } - if(source.ir.image_info.format) - { - if(convert(source.ir, sp) != core::status_no_error) return core::status_item_unavailable; - target[rs_stream::RS_STREAM_INFRARED].profile = sp; - } - if(source.left.image_info.format) - { - if(convert(source.left, sp) != core::status_no_error) return core::status_item_unavailable; - target[rs_stream::RS_STREAM_INFRARED].profile = sp; - } - if(source.right.image_info.format) - { - if(convert(source.right, sp) != core::status_no_error) return core::status_item_unavailable; - target[rs_stream::RS_STREAM_INFRARED2].profile = sp; - } - return core::status_no_error; - } - - core::status convert(const disk_format::frame_metadata &source, core::file_types::frame_info &target) - { - memset(&target, 0, sizeof(target)); - rs_stream stream; - if(convert(source.stream_type, stream) != core::status_no_error) - return core::status_item_unavailable; - target.stream = stream; - target.time_stamp = rssdk2lrs_timestamp(source.time_stamp); - target.number = source.frame_number; - return core::status_no_error; - } - - rs_intrinsics get_intrinsics(stream_type stream, ds_projection::ProjectionData* projection) - { - rs::intrinsics rv; - switch(stream) - { - case stream_type::stream_type_color: - { - rv.fx = projection->thirdCameraParams.isRectified ? - projection->thirdCameraParams.calibIntrinsicsRectified.rfx : projection->thirdCameraParams.calibIntrinsicsNonRectified.fx; - rv.fy = projection->thirdCameraParams.isRectified ? - projection->thirdCameraParams.calibIntrinsicsRectified.rfy : projection->thirdCameraParams.calibIntrinsicsNonRectified.fy; - rv.ppx = projection->thirdCameraParams.isRectified ? - projection->thirdCameraParams.calibIntrinsicsRectified.rpx : projection->thirdCameraParams.calibIntrinsicsNonRectified.px; - rv.ppy = projection->thirdCameraParams.isRectified ? - projection->thirdCameraParams.calibIntrinsicsRectified.rpy : projection->thirdCameraParams.calibIntrinsicsNonRectified.py; - rv.width = projection->thirdCameraParams.width; - rv.height = projection->thirdCameraParams.height; - break; - } - case stream_type::stream_type_depth: - { - rv.fx = projection->zRectified ? projection->zIntrinRect.rfx : projection->zIntrinNonRect.fx; - rv.fy = projection->zRectified ? projection->zIntrinRect.rfy : projection->zIntrinNonRect.fy; - rv.ppx = projection->zRectified ? projection->zIntrinRect.rpx : projection->zIntrinNonRect.px; - rv.ppy = projection->zRectified ? projection->zIntrinRect.rpy : projection->zIntrinNonRect.py; - rv.width = projection->dWidth; - rv.height = projection->dHeight; - break; - } - case stream_type::stream_type_left: - { - rv.fx = projection->zRectified ? projection->lrIntrinRect.rfx : projection->lIntrinNonRect.fx; - rv.fy = projection->zRectified ? projection->lrIntrinRect.rfy : projection->lIntrinNonRect.fy; - rv.ppx = projection->zRectified ? projection->lrIntrinRect.rpx : projection->lIntrinNonRect.px; - rv.ppy = projection->zRectified ? projection->lrIntrinRect.rpy : projection->lIntrinNonRect.py; - rv.width = projection->dWidth; - rv.height = projection->dHeight; - break; - } - case stream_type::stream_type_right: - { - rv.fx = projection->zRectified ? projection->lrIntrinRect.rfx : projection->rIntrinNonRect.fx; - rv.fy = projection->zRectified ? projection->lrIntrinRect.rfy : projection->rIntrinNonRect.fy; - rv.ppx = projection->zRectified ? projection->lrIntrinRect.rpx : projection->rIntrinNonRect.px; - rv.ppy = projection->zRectified ? projection->lrIntrinRect.rpy : projection->rIntrinNonRect.py; - rv.width = projection->dWidth; - rv.height = projection->dHeight; - break; - } - default: break; - } - return rv; - } - - rs_extrinsics get_extrinsics(stream_type stream, ds_projection::ProjectionData *projection) - { - rs_extrinsics rv = {}; - switch(stream) - { - case stream_type::stream_type_color: - { - rs::utils::float3 trans = {}; - for(int i = 0; i < 3; ++i) - { - trans[i] = projection->thirdCameraParams.isRectified ? - projection->thirdCameraParams.zToRectColorTranslation[i] * 0.001 : - projection->thirdCameraParams.zToNonRectColorTranslation[i] * 0.001; - } - rs::utils::float3x3 rot = {}; - memcpy(&rot, projection->calibParams.Rthird[0], sizeof(float) * 9); - const rs::utils::pose mat = {rot, trans}; - auto inv = inverse(mat); - rv = {inv.orientation.x.x, inv.orientation.x.y, inv.orientation.x.z, - inv.orientation.y.x, inv.orientation.y.y, inv.orientation.y.z, - inv.orientation.z.x, inv.orientation.z.y, inv.orientation.z.z, - inv.position.x, inv.position.y, inv.position.z - }; - return rv; - break; - } - default: break;//TODO - add support in other streams - } - return rv; - } - } - } -} diff --git a/sdk/src/cameras/playback/windows/disk_read_windows.cpp b/sdk/src/cameras/playback/windows/disk_read_windows.cpp deleted file mode 100644 index a0f854f..0000000 --- a/sdk/src/cameras/playback/windows/disk_read_windows.cpp +++ /dev/null @@ -1,221 +0,0 @@ -// License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2016 Intel Corporation. All Rights Reserved - -#include "windows/disk_read_windows.h" -#include "windows/file_types_windows.h" -#include "windows/conversions.h" -#include "file/file.h" -#include "rs/utils/log_utils.h" - -using namespace rs::core; -using namespace rs::win_file; -using namespace rs::playback; - -namespace -{ - static rs_capabilities get_capability(rs_stream stream) - { - switch(stream) - { - case rs_stream::RS_STREAM_COLOR: return rs_capabilities::RS_CAPABILITIES_COLOR; - case rs_stream::RS_STREAM_DEPTH: return rs_capabilities::RS_CAPABILITIES_DEPTH; - case rs_stream::RS_STREAM_INFRARED: return rs_capabilities::RS_CAPABILITIES_INFRARED; - case rs_stream::RS_STREAM_INFRARED2: return rs_capabilities::RS_CAPABILITIES_INFRARED2; - case rs_stream::RS_STREAM_FISHEYE: return rs_capabilities::RS_CAPABILITIES_FISH_EYE; - default: return rs_capabilities::RS_CAPABILITIES_MAX_ENUM; - } - } -} - -struct FrameInfo -{ - int64_t offset; // file offset in bytes - int64_t timeStamp; // the time stamp in 100ns. - int32_t syncId; // syncId in the file -}; - -disk_read_windows::~disk_read_windows(void) -{ - LOG_FUNC_SCOPE(); - pause(); -} - -void disk_read_windows::handle_ds_projection(std::vector &projection_data) -{ - LOG_INFO("handle ds projection") - auto data = &(projection_data.data()[640]); // 640 is the size of PXCSerializableService::ProfileInfo - ds_projection::ProjectionDataVersions projectionDataVersion = (ds_projection::ProjectionDataVersions)((unsigned int)(*data)); - ds_projection::ProjectionData* projection = NULL; - ds_projection::ProjectionData v0TmpProjection; - switch (projectionDataVersion) - { - case ds_projection::ProjectionDataVersions::VERSION_0: - { - ds_projection::Version0_ProjectionData* version0ProjectionData = reinterpret_cast(data); - v0TmpProjection = *version0ProjectionData; - projection = &v0TmpProjection; - } - break; - case ds_projection::ProjectionDataVersions::VERSION_1: - projection = reinterpret_cast(data); - break; - } - m_streams_infos[rs_stream::RS_STREAM_COLOR].profile.intrinsics = win_file::conversions::get_intrinsics(win_file::stream_type::stream_type_color, projection); - m_streams_infos[rs_stream::RS_STREAM_DEPTH].profile.intrinsics = win_file::conversions::get_intrinsics(win_file::stream_type::stream_type_depth, projection); - m_streams_infos[rs_stream::RS_STREAM_COLOR].profile.extrinsics = win_file::conversions::get_extrinsics(win_file::stream_type::stream_type_color, projection); -} - -status disk_read_windows::read_headers() -{ - /* Get the file header */ - m_file_data_read->set_position(0, move_method::begin); - uint32_t nbytesRead = 0; - unsigned long nbytesToRead = 0; - disk_format::header header; - m_file_data_read->read_bytes(&header, sizeof(header), nbytesRead); - if(conversions::convert(header, m_file_header) != status_no_error) return status_item_unavailable; - if (nbytesRead < sizeof(m_file_header)) return status_item_unavailable; - if (m_file_header.id != UID('R', 'S', 'C', 'F')) return status_param_unsupported; - if (header.version >= 8) - conversions::convert(header.coordinate_system, m_file_header.coordinate_system); - /* Get all chunks */ - for (;;) - { - disk_format::chunk chunk = {}; - m_file_data_read->read_bytes(&chunk, sizeof(chunk), nbytesRead); - if (nbytesRead < sizeof(chunk)) break; - if (chunk.chunk_id == disk_format::chunk_frame_meta_data) break; - nbytesToRead = chunk.chunk_size; - switch (chunk.chunk_id) - { - case disk_format::chunk_deviceinfo: - { - disk_format::device_info_disk did; - m_file_data_read->read_bytes(&did, std::min(nbytesToRead, (unsigned long)sizeof(did)), nbytesRead); - if(conversions::convert(did, m_device_info) != status_no_error) return status_item_unavailable; - nbytesToRead -= nbytesRead; - LOG_INFO("read device info chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) - } - break; - case disk_format::chunk_profiles: - disk_format::stream_profile_set_disk spsd; - m_file_data_read->read_bytes(&spsd, std::min(nbytesToRead, (unsigned long)sizeof(spsd)), nbytesRead); - if(conversions::convert(spsd, m_streams_infos) != status_no_error) return status_item_unavailable; - nbytesToRead -= nbytesRead; - LOG_INFO("read profiles chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) - break; - case disk_format::chunk_properties://TODO - create conversion table - do - { - device_cap devcap = {}; - m_file_data_read->read_bytes(&devcap, std::min(nbytesToRead, (unsigned long)sizeof(devcap)), nbytesRead); - //if(Conversions::convert(devcap, option) != status_no_error) return status_item_unavailable; - nbytesToRead -= nbytesRead; - } - while (nbytesToRead > 0 && nbytesRead > 0); - LOG_INFO("read properties chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) - break; - case disk_format::chunk_serializeable: - { - property label = (property)0; - m_file_data_read->read_bytes(&label, std::min(nbytesToRead, (unsigned long)sizeof(label)), nbytesRead); - nbytesToRead -= nbytesRead; - std::vector data(nbytesToRead); - m_file_data_read->read_bytes(data.data(), nbytesToRead, nbytesRead); - nbytesToRead -= nbytesRead; - LOG_INFO("read serializeable chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) - - if (label == property::property_projection_serializable) - { - auto str = std::string(m_device_info.name); - std::size_t found = str.find("R200"); - if (found!=std::string::npos) - { - handle_ds_projection(data); - } - } - } - break; - case disk_format::chunk_streaminfo: - for (int i = 0; i < m_file_header.nstreams; i++) - { - disk_format::stream_info stream_info1 = {}; - m_file_data_read->read_bytes(&stream_info1, std::min(nbytesToRead, (unsigned long)sizeof(stream_info1)), nbytesRead); - file_types::stream_info si; - if(conversions::convert(stream_info1, si) != status_no_error) return status_item_unavailable; - m_streams_infos[si.stream] = si; - auto cap = get_capability(si.stream); - if(cap != rs_capabilities::RS_CAPABILITIES_MAX_ENUM) - m_capabilities.push_back(cap); - nbytesToRead -= nbytesRead; - } - LOG_INFO("read stream info chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) - break; - default: - std::vector data(nbytesToRead); - m_file_data_read->read_bytes(&data[0], nbytesToRead, nbytesRead); - m_unknowns[(file_types::chunk_id)chunk.chunk_id] = data; - nbytesToRead -= nbytesRead; - LOG_INFO("read unknown chunk " << (nbytesToRead == 0 ? "succeeded" : "failed") << "chunk id - " << chunk.chunk_id) - } - if (nbytesToRead > 0) return status_item_unavailable; - } - return status_no_error; -} - -int32_t disk_read_windows::size_of_pitches(void) -{ - return sizeof(int32_t) * NUM_OF_PLANES; -} - -void disk_read_windows::index_next_samples(uint32_t number_of_samples) -{ - if (m_is_index_complete) return; - - std::lock_guard guard(m_mutex); - - for (uint32_t index = 0; index < number_of_samples;) - { - disk_format::chunk chunk = {}; - uint32_t nbytesRead = 0; - m_file_indexing->read_bytes(&chunk, sizeof(chunk), nbytesRead); - if (nbytesRead < sizeof(chunk) || chunk.chunk_size <= 0 || chunk.chunk_size > 100000000 /*invalid chunk*/) - { - m_is_index_complete = true; - LOG_INFO("samples indexing is done") - break; - } - unsigned long nbytesToRead = chunk.chunk_size; - if (chunk.chunk_id == disk_format::chunk_frame_meta_data) - { - disk_format::frame_metadata mdata = {}; - auto so = m_file_header.version < 10 ? 24 : (unsigned long)sizeof(mdata); - m_file_indexing->read_bytes(&mdata, so, nbytesRead); - file_types::sample_info sample_info; - file_types::frame_info frame_info; - if(conversions::convert(mdata, frame_info) != status_no_error) continue; - auto ts = frame_info.time_stamp; - auto st = frame_info.stream; - auto fn = frame_info.number; - frame_info = m_streams_infos[frame_info.stream].profile.info; - frame_info.time_stamp = ts; - frame_info.stream = st; - frame_info.number = fn; - if(m_time_stamp_base == 0) m_time_stamp_base = frame_info.time_stamp; - frame_info.time_stamp -= m_time_stamp_base; - sample_info.type = file_types::sample_type::st_image; - sample_info.capture_time = frame_info.time_stamp; - m_file_indexing->get_position(&sample_info.offset); - frame_info.index_in_stream = m_image_indices[frame_info.stream].size(); - m_image_indices[frame_info.stream].push_back(m_samples_desc.size()); - m_samples_desc.push_back(std::make_shared(frame_info, sample_info)); - ++index; - LOG_VERBOSE("frame sample indexed, sample time - " << sample_info.capture_time) - } - else - { - // skip any other sections - m_file_indexing->set_position(chunk.chunk_size, move_method::current); - } - } -} diff --git a/sdk/src/cameras/playback/windows/v10/conversions.cpp b/sdk/src/cameras/playback/windows/v10/conversions.cpp new file mode 100644 index 0000000..11c7a6d --- /dev/null +++ b/sdk/src/cameras/playback/windows/v10/conversions.cpp @@ -0,0 +1,305 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2016 Intel Corporation. All Rights Reserved. + +#include "windows/v10/conversions.h" +#include "linear_algebra/linear_algebra.h" + +namespace rs +{ + namespace playback + { + namespace windows + { + namespace v10 + { + namespace conversions + { + + uint64_t rssdk2lrs_timestamp(uint64_t time) + { + return time * 0.0001; + } + + core::status convert(file_types::stream_type source, rs_stream &target) + { + target = (rs_stream)-1; + switch(source) + { + case file_types::stream_type::stream_type_color: target = rs_stream::RS_STREAM_COLOR; break; + case file_types::stream_type::stream_type_depth: target = rs_stream::RS_STREAM_DEPTH; break; + case file_types::stream_type::stream_type_ir: target = rs_stream::RS_STREAM_INFRARED; break; + case file_types::stream_type::stream_type_left: target = rs_stream::RS_STREAM_INFRARED; break; + case file_types::stream_type::stream_type_right: target = rs_stream::RS_STREAM_INFRARED2; break; + default: return core::status_item_unavailable; break; + } + return core::status_no_error; + } + + core::status convert(file_types::compression_type source, core::file_types::compression_type &target) + { + target = (core::file_types::compression_type)-1; + switch(source) + { + case file_types::compression_none: target = core::file_types::compression_type::none; break; + case file_types::compression_h264: target = core::file_types::compression_type::h264; break; + case file_types::compression_lzo: target = core::file_types::compression_type::lzo; break; + default: return core::status_item_unavailable; break; + } + return core::status_no_error; + } + + core::status convert(file_types::rotation source, rs::core::rotation &target) + { + target = (rs::core::rotation)-1; + switch(source) + { + case file_types::rotation:: rotation_0_degree: target = rs::core::rotation::rotation_0_degree; break; + case file_types::rotation:: rotation_90_degree: target = rs::core::rotation::rotation_90_degree; break; + case file_types::rotation:: rotation_180_degree: target = rs::core::rotation::rotation_180_degree; break; + case file_types::rotation:: rotation_270_degree: target = rs::core::rotation::rotation_270_degree; break; + default: return core::status_item_unavailable; break; + } + return core::status_no_error; + } + + core::status convert(file_types::pixel_format source, rs_format &target) + { + target = (rs_format)-1; + switch(source) + { + case file_types::pixel_format::pf_any: target = rs_format::RS_FORMAT_ANY; break; + case file_types::pixel_format::pf_depth: target = rs_format::RS_FORMAT_Z16; break; + case file_types::pixel_format::pf_depth_f32: target = rs_format::RS_FORMAT_XYZ32F; break; + case file_types::pixel_format::pf_yuy2: target = rs_format::RS_FORMAT_YUYV; break; + case file_types::pixel_format::pf_rgb24: target = rs_format::RS_FORMAT_RGB8; break; + case file_types::pixel_format::pf_rgb32: target = rs_format::RS_FORMAT_BGRA8; break; + case file_types::pixel_format::pf_y8: target = rs_format::RS_FORMAT_Y8; break; + case file_types::pixel_format::pf_y16: target = rs_format::RS_FORMAT_Y16; break; + case file_types::pixel_format::pf_raw: target = rs_format::RS_FORMAT_RAW10; break; + default: return core::status_item_unavailable; break; + } + return core::status_no_error; + } + + core::status convert(const file_types::coordinate_system &source, core::file_types::coordinate_system &target) + { + target = (core::file_types::coordinate_system)-1; + switch(source) + { + case file_types::coordinate_system::coordinate_system_rear_default: target = core::file_types::coordinate_system::rear_default; break; + case file_types::coordinate_system::coordinate_system_rear_opencv: target = core::file_types::coordinate_system::rear_opencv; break; + case file_types::coordinate_system::coordinate_system_front_default: target = core::file_types::coordinate_system::front_default; break; + default: target = (core::file_types::coordinate_system)source; break; + } + return core::status_no_error; + } + + core::status convert(const file_types::disk_format::header &source, core::file_types::file_header &target) + { + memset(&target, 0, sizeof(target)); + core::file_types::coordinate_system cs; + if(convert(source.coordinate_system, cs) != core::status_no_error) + return core::status_item_unavailable; + target.id = source.id; + target.version = source.version; + target.coordinate_system = cs; + target.first_frame_offset = source.first_frame_offset; + target.nstreams = source.nstreams; + return core::status_no_error; + } + + core::status convert(const file_types::disk_format::stream_info &source, core::file_types::stream_info &target) + { + memset(&target, 0, sizeof(target)); + rs_stream stream; + core::file_types::compression_type ctype; + if(convert(source.stype, stream) != core::status_no_error || convert(source.ctype, ctype) != core::status_no_error) + return core::status_item_unavailable; + target.stream = stream; + target.nframes = source.nframes; + target.ctype = ctype; + return core::status_no_error; + } + + core::status convert(const file_types::disk_format::device_info_disk &source, core::file_types::device_info &target) + { + memset(&target, 0, sizeof(target)); + rs::core::rotation rotaion; + if(convert(source.rotation, rotaion) != core::status_no_error) + return core::status_item_unavailable; + auto nameSize = sizeof(target.name) / sizeof(target.name[0]); + for(size_t i = 0; i < nameSize; i++) + target.name[i] = source.name[i]; + auto serialSize = sizeof(target.serial) / sizeof(target.serial[0]); + for(size_t i = 0; i < serialSize; i++) + target.serial[i] = source.serial[i]; + std::stringstream ss; + ss << source.firmware[0] << "." << source.firmware[1] << "." << + source.firmware[2] << "." << source.firmware[3]; + memcpy(&target.camera_firmware, ss.str().c_str(), ss.str().size()); + return core::status_no_error; + } + + core::status convert(const file_types::image_info &source, core::file_types::frame_info &target) + { + memset(&target, 0, sizeof(target)); + rs_format format; + if(convert(source.format, format) != core::status_no_error) + return core::status_item_unavailable; + target.width = source.width; + target.height = source.height; + target.stride = source.width == 628 ? 640 : source.width; + target.bpp = rs::core::image_utils::get_pixel_size(format); + target.format = format; + return core::status_no_error; + } + + core::status convert(const file_types::disk_format::stream_profile_disk &source, core::file_types::stream_profile &target) + { + memset(&target, 0, sizeof(target)); + core::file_types::frame_info frame_info; + if(convert(source.image_info, frame_info) != core::status_no_error) + return core::status_item_unavailable; + if(source.frame_rate[0] != source.frame_rate[1]) + { + LOG_ERROR("min != max fps is not supported, setting to min"); + } + target.frame_rate = source.frame_rate[0]; + target.info = frame_info; + + return core::status_no_error; + //rv.options = profile.options; + } + + core::status convert(const file_types::disk_format::stream_profile_set_disk &source, std::map &target) + { + core::file_types::stream_profile sp; + if(source.color.image_info.format) + { + if(convert(source.color, sp) != core::status_no_error) return core::status_item_unavailable; + target[rs_stream::RS_STREAM_COLOR].profile = sp; + } + if(source.depth.image_info.format) + { + if(convert(source.depth, sp) != core::status_no_error) return core::status_item_unavailable; + target[rs_stream::RS_STREAM_DEPTH].profile = sp; + } + if(source.ir.image_info.format) + { + if(convert(source.ir, sp) != core::status_no_error) return core::status_item_unavailable; + target[rs_stream::RS_STREAM_INFRARED].profile = sp; + } + if(source.left.image_info.format) + { + if(convert(source.left, sp) != core::status_no_error) return core::status_item_unavailable; + target[rs_stream::RS_STREAM_INFRARED].profile = sp; + } + if(source.right.image_info.format) + { + if(convert(source.right, sp) != core::status_no_error) return core::status_item_unavailable; + target[rs_stream::RS_STREAM_INFRARED2].profile = sp; + } + return core::status_no_error; + } + + core::status convert(const file_types::disk_format::frame_metadata &source, core::file_types::frame_info &target) + { + memset(&target, 0, sizeof(target)); + rs_stream stream; + if(convert(source.stream_type, stream) != core::status_no_error) + return core::status_item_unavailable; + target.stream = stream; + target.time_stamp = rssdk2lrs_timestamp(source.time_stamp); + target.number = source.frame_number; + return core::status_no_error; + } + + rs_intrinsics get_intrinsics(file_types::stream_type stream, ds_projection::ProjectionData* projection) + { + rs::intrinsics rv; + switch(stream) + { + case file_types::stream_type::stream_type_color: + { + rv.fx = projection->thirdCameraParams.isRectified ? + projection->thirdCameraParams.calibIntrinsicsRectified.rfx : projection->thirdCameraParams.calibIntrinsicsNonRectified.fx; + rv.fy = projection->thirdCameraParams.isRectified ? + projection->thirdCameraParams.calibIntrinsicsRectified.rfy : projection->thirdCameraParams.calibIntrinsicsNonRectified.fy; + rv.ppx = projection->thirdCameraParams.isRectified ? + projection->thirdCameraParams.calibIntrinsicsRectified.rpx : projection->thirdCameraParams.calibIntrinsicsNonRectified.px; + rv.ppy = projection->thirdCameraParams.isRectified ? + projection->thirdCameraParams.calibIntrinsicsRectified.rpy : projection->thirdCameraParams.calibIntrinsicsNonRectified.py; + rv.width = projection->thirdCameraParams.width; + rv.height = projection->thirdCameraParams.height; + break; + } + case file_types::stream_type::stream_type_depth: + { + rv.fx = projection->zRectified ? projection->zIntrinRect.rfx : projection->zIntrinNonRect.fx; + rv.fy = projection->zRectified ? projection->zIntrinRect.rfy : projection->zIntrinNonRect.fy; + rv.ppx = projection->zRectified ? projection->zIntrinRect.rpx : projection->zIntrinNonRect.px; + rv.ppy = projection->zRectified ? projection->zIntrinRect.rpy : projection->zIntrinNonRect.py; + rv.width = projection->dWidth; + rv.height = projection->dHeight; + break; + } + case file_types::stream_type::stream_type_left: + { + rv.fx = projection->zRectified ? projection->lrIntrinRect.rfx : projection->lIntrinNonRect.fx; + rv.fy = projection->zRectified ? projection->lrIntrinRect.rfy : projection->lIntrinNonRect.fy; + rv.ppx = projection->zRectified ? projection->lrIntrinRect.rpx : projection->lIntrinNonRect.px; + rv.ppy = projection->zRectified ? projection->lrIntrinRect.rpy : projection->lIntrinNonRect.py; + rv.width = projection->dWidth; + rv.height = projection->dHeight; + break; + } + case file_types::stream_type::stream_type_right: + { + rv.fx = projection->zRectified ? projection->lrIntrinRect.rfx : projection->rIntrinNonRect.fx; + rv.fy = projection->zRectified ? projection->lrIntrinRect.rfy : projection->rIntrinNonRect.fy; + rv.ppx = projection->zRectified ? projection->lrIntrinRect.rpx : projection->rIntrinNonRect.px; + rv.ppy = projection->zRectified ? projection->lrIntrinRect.rpy : projection->rIntrinNonRect.py; + rv.width = projection->dWidth; + rv.height = projection->dHeight; + break; + } + default: break; + } + return rv; + } + + rs_extrinsics get_extrinsics(file_types::stream_type stream, ds_projection::ProjectionData *projection) + { + rs_extrinsics rv = {}; + switch(stream) + { + case file_types::stream_type::stream_type_color: + { + rs::utils::float3 trans = {}; + for(int i = 0; i < 3; ++i) + { + trans[i] = projection->thirdCameraParams.isRectified ? + projection->thirdCameraParams.zToRectColorTranslation[i] * 0.001 : + projection->thirdCameraParams.zToNonRectColorTranslation[i] * 0.001; + } + rs::utils::float3x3 rot = {}; + memcpy(&rot, projection->calibParams.Rthird[0], sizeof(float) * 9); + const rs::utils::pose mat = {rot, trans}; + auto inv = inverse(mat); + rv = {inv.orientation.x.x, inv.orientation.x.y, inv.orientation.x.z, + inv.orientation.y.x, inv.orientation.y.y, inv.orientation.y.z, + inv.orientation.z.x, inv.orientation.z.y, inv.orientation.z.z, + inv.position.x, inv.position.y, inv.position.z + }; + return rv; + break; + } + default: break;//TODO - add support in other streams + } + return rv; + } + } + } + } + } +} diff --git a/sdk/src/cameras/playback/windows/v10/disk_read.cpp b/sdk/src/cameras/playback/windows/v10/disk_read.cpp new file mode 100644 index 0000000..7441cd7 --- /dev/null +++ b/sdk/src/cameras/playback/windows/v10/disk_read.cpp @@ -0,0 +1,234 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2016 Intel Corporation. All Rights Reserved + +#include "windows/v10/disk_read.h" +#include "windows/v10/file_types.h" +#include "windows/v10/conversions.h" +#include "file/file.h" +#include "rs/utils/log_utils.h" + +//using namespace rs::core; +//using namespace rs::windows; +//using namespace rs::playback; + +namespace +{ + static rs_capabilities get_capability(rs_stream stream) + { + switch(stream) + { + case rs_stream::RS_STREAM_COLOR: return rs_capabilities::RS_CAPABILITIES_COLOR; + case rs_stream::RS_STREAM_DEPTH: return rs_capabilities::RS_CAPABILITIES_DEPTH; + case rs_stream::RS_STREAM_INFRARED: return rs_capabilities::RS_CAPABILITIES_INFRARED; + case rs_stream::RS_STREAM_INFRARED2: return rs_capabilities::RS_CAPABILITIES_INFRARED2; + case rs_stream::RS_STREAM_FISHEYE: return rs_capabilities::RS_CAPABILITIES_FISH_EYE; + default: return rs_capabilities::RS_CAPABILITIES_MAX_ENUM; + } + } +} + +namespace rs +{ + namespace playback + { + namespace windows + { + namespace v10 + { + struct FrameInfo + { + int64_t offset; // file offset in bytes + int64_t timeStamp; // the time stamp in 100ns. + int32_t syncId; // syncId in the file + }; + + disk_read::~disk_read(void) + { + LOG_FUNC_SCOPE(); + pause(); + } + + void disk_read::handle_ds_projection(std::vector &projection_data) + { + LOG_INFO("handle ds projection") + auto data = &(projection_data.data()[640]); // 640 is the size of PXCSerializableService::ProfileInfo + ds_projection::ProjectionDataVersions projectionDataVersion = (ds_projection::ProjectionDataVersions)((unsigned int)(*data)); + ds_projection::ProjectionData* projection = NULL; + ds_projection::ProjectionData v0TmpProjection; + switch (projectionDataVersion) + { + case ds_projection::ProjectionDataVersions::VERSION_0: + { + ds_projection::Version0_ProjectionData* version0ProjectionData = reinterpret_cast(data); + v0TmpProjection = *version0ProjectionData; + projection = &v0TmpProjection; + } + break; + case ds_projection::ProjectionDataVersions::VERSION_1: + projection = reinterpret_cast(data); + break; + } + m_streams_infos[rs_stream::RS_STREAM_COLOR].profile.intrinsics = conversions::get_intrinsics(file_types::stream_type::stream_type_color, projection); + m_streams_infos[rs_stream::RS_STREAM_DEPTH].profile.intrinsics = conversions::get_intrinsics(file_types::stream_type::stream_type_depth, projection); + m_streams_infos[rs_stream::RS_STREAM_COLOR].profile.extrinsics = conversions::get_extrinsics(file_types::stream_type::stream_type_color, projection); + } + + core::status disk_read::read_headers() + { + /* Get the file header */ + m_file_data_read->set_position(0, core::move_method::begin); + uint32_t nbytesRead = 0; + unsigned long nbytesToRead = 0; + file_types::disk_format::header header; + m_file_data_read->read_bytes(&header, sizeof(header), nbytesRead); + if(conversions::convert(header, m_file_header) != core::status_no_error) return core::status_item_unavailable; + if (nbytesRead < sizeof(m_file_header)) return core::status_item_unavailable; + if (m_file_header.id != UID('R', 'S', 'C', 'F')) return core::status_param_unsupported; + if (header.version >= 8) + conversions::convert(header.coordinate_system, m_file_header.coordinate_system); + /* Get all chunks */ + for (;;) + { + file_types::disk_format::chunk chunk = {}; + m_file_data_read->read_bytes(&chunk, sizeof(chunk), nbytesRead); + if (nbytesRead < sizeof(chunk)) break; + if (chunk.chunk_id == file_types::disk_format::chunk_frame_meta_data) break; + nbytesToRead = chunk.chunk_size; + switch (chunk.chunk_id) + { + case file_types::disk_format::chunk_deviceinfo: + { + file_types::disk_format::device_info_disk did; + m_file_data_read->read_bytes(&did, std::min(nbytesToRead, (unsigned long)sizeof(did)), nbytesRead); + if(conversions::convert(did, m_device_info) != core::status_no_error) return core::status_item_unavailable; + nbytesToRead -= nbytesRead; + LOG_INFO("read device info chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + } + break; + case file_types::disk_format::chunk_profiles: + file_types::disk_format::stream_profile_set_disk spsd; + m_file_data_read->read_bytes(&spsd, std::min(nbytesToRead, (unsigned long)sizeof(spsd)), nbytesRead); + if(conversions::convert(spsd, m_streams_infos) != core::status_no_error) return core::status_item_unavailable; + nbytesToRead -= nbytesRead; + LOG_INFO("read profiles chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + break; + case file_types::disk_format::chunk_properties://TODO - create conversion table + do + { + file_types::device_cap devcap = {}; + m_file_data_read->read_bytes(&devcap, std::min(nbytesToRead, (unsigned long)sizeof(devcap)), nbytesRead); + //if(Conversions::convert(devcap, option) !=core::status_no_error) returncore::status_item_unavailable; + nbytesToRead -= nbytesRead; + } + while (nbytesToRead > 0 && nbytesRead > 0); + LOG_INFO("read properties chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + break; + case file_types::disk_format::chunk_serializeable: + { + file_types::property label = (file_types::property)0; + m_file_data_read->read_bytes(&label, std::min(nbytesToRead, (unsigned long)sizeof(label)), nbytesRead); + nbytesToRead -= nbytesRead; + std::vector data(nbytesToRead); + m_file_data_read->read_bytes(data.data(), nbytesToRead, nbytesRead); + nbytesToRead -= nbytesRead; + LOG_INFO("read serializeable chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + + if (label == file_types::property::property_projection_serializable) + { + auto str = std::string(m_device_info.name); + std::size_t found = str.find("R200"); + if (found!=std::string::npos) + { + handle_ds_projection(data); + } + } + } + break; + case file_types::disk_format::chunk_streaminfo: + for (int i = 0; i < m_file_header.nstreams; i++) + { + file_types::disk_format::stream_info stream_info1 = {}; + m_file_data_read->read_bytes(&stream_info1, std::min(nbytesToRead, (unsigned long)sizeof(stream_info1)), nbytesRead); + core::file_types::stream_info si; + if(conversions::convert(stream_info1, si) != core::status_no_error) return core::status_item_unavailable; + m_streams_infos[si.stream] = si; + auto cap = get_capability(si.stream); + if(cap != rs_capabilities::RS_CAPABILITIES_MAX_ENUM) + m_capabilities.push_back(cap); + nbytesToRead -= nbytesRead; + } + LOG_INFO("read stream info chunk " << (nbytesToRead == 0 ? "succeeded" : "failed")) + break; + default: + std::vector data(nbytesToRead); + m_file_data_read->read_bytes(&data[0], nbytesToRead, nbytesRead); + m_unknowns[(core::file_types::chunk_id)chunk.chunk_id] = data; + nbytesToRead -= nbytesRead; + LOG_INFO("read unknown chunk " << (nbytesToRead == 0 ? "succeeded" : "failed") << "chunk id - " << chunk.chunk_id) + } + if (nbytesToRead > 0) return core::status_item_unavailable; + } + return core::status_no_error; + } + + int32_t disk_read::size_of_pitches(void) + { + return sizeof(int32_t) * NUM_OF_PLANES; + } + + void disk_read::index_next_samples(uint32_t number_of_samples) + { + if (m_is_index_complete) return; + + std::lock_guard guard(m_mutex); + + for (uint32_t index = 0; index < number_of_samples;) + { + file_types::disk_format::chunk chunk = {}; + uint32_t nbytesRead = 0; + m_file_indexing->read_bytes(&chunk, sizeof(chunk), nbytesRead); + if (nbytesRead < sizeof(chunk) || chunk.chunk_size <= 0 || chunk.chunk_size > 100000000 /*invalid chunk*/) + { + m_is_index_complete = true; + LOG_INFO("samples indexing is done") + break; + } + unsigned long nbytesToRead = chunk.chunk_size; + if (chunk.chunk_id == file_types::disk_format::chunk_frame_meta_data) + { + file_types::disk_format::frame_metadata mdata = {}; + auto so = m_file_header.version < 10 ? 24 : (unsigned long)sizeof(mdata); + m_file_indexing->read_bytes(&mdata, so, nbytesRead); + core::file_types::sample_info sample_info; + core::file_types::frame_info frame_info; + if(conversions::convert(mdata, frame_info) != core::status_no_error) continue; + auto ts = frame_info.time_stamp; + auto st = frame_info.stream; + auto fn = frame_info.number; + frame_info = m_streams_infos[frame_info.stream].profile.info; + frame_info.time_stamp = ts; + frame_info.stream = st; + frame_info.number = fn; + if(m_time_stamp_base == 0) m_time_stamp_base = frame_info.time_stamp; + frame_info.time_stamp -= m_time_stamp_base; + sample_info.type = core::file_types::sample_type::st_image; + sample_info.capture_time = frame_info.time_stamp; + m_file_indexing->get_position(&sample_info.offset); + frame_info.index_in_stream = m_image_indices[frame_info.stream].size(); + m_image_indices[frame_info.stream].push_back(m_samples_desc.size()); + m_samples_desc.push_back(std::make_shared(frame_info, sample_info)); + ++index; + LOG_VERBOSE("frame sample indexed, sample time - " << sample_info.capture_time) + } + else + { + // skip any other sections + m_file_indexing->set_position(chunk.chunk_size, core::move_method::current); + } + } + } + } + } + } +} + diff --git a/sdk/src/cameras/record/disk_write.cpp b/sdk/src/cameras/record/disk_write.cpp index ffad646..d641228 100644 --- a/sdk/src/cameras/record/disk_write.cpp +++ b/sdk/src/cameras/record/disk_write.cpp @@ -109,6 +109,7 @@ namespace rs write_device_info(config.m_device_info); write_sw_info(); write_capabilities(config.m_capabilities); + write_motion_intrinsics(config.m_motion_intrinsics); write_stream_info(config.m_stream_profiles); write_properties(config.m_options); write_first_frame_offset(); @@ -150,8 +151,8 @@ namespace rs void disk_write::write_header(uint8_t stream_count, file_types::coordinate_system cs) { file_types::disk_format::file_header header = {}; - header.data.id = UID('R', 'S', 'L', '1'); - header.data.version = header.data.id;//required for windows versioning method + header.data.version = 2; + header.data.id = UID('R', 'S', 'L', '0' + header.data.version); header.data.coordinate_system = cs; /* calculate the number of streams */ @@ -236,6 +237,20 @@ namespace rs } } + void disk_write::write_motion_intrinsics(const rs_motion_intrinsics &motion_intrinsics) + { + file_types::chunk_info chunk = {}; + chunk.id = file_types::chunk_id::chunk_motion_intrinsics; + file_types::disk_format::motion_intrinsics mi; + chunk.size = sizeof(mi); + mi.data = motion_intrinsics; + + uint32_t bytes_written = 0; + m_file->write_bytes(&chunk, sizeof(chunk), bytes_written); + m_file->write_bytes(&mi, chunk.size, bytes_written); + LOG_INFO("write motion intrinsics chunk, chunk size - " << chunk.size) + } + void disk_write::write_properties(const std::vector& properties) { file_types::chunk_info chunk = {}; @@ -364,7 +379,7 @@ namespace rs if (frame) { /* Get raw stream size */ - int32_t nbytes = (frame->finfo.stride_x * frame->finfo.bpp * frame->finfo.stride_y); + int32_t nbytes = (frame->finfo.stride * frame->finfo.height * (frame->finfo.bpp / 8)); std::vector buffer; file_types::compression_type ctype = m_compression.compression_policy(frame->finfo.stream); diff --git a/sdk/src/cameras/record/include/disk_write.h b/sdk/src/cameras/record/include/disk_write.h index 5edc250..38f3998 100644 --- a/sdk/src/cameras/record/include/disk_write.h +++ b/sdk/src/cameras/record/include/disk_write.h @@ -28,6 +28,7 @@ namespace rs std::map m_stream_profiles; core::file_types::coordinate_system m_coordinate_system; std::vector m_capabilities; + rs_motion_intrinsics m_motion_intrinsics; }; class disk_write @@ -51,6 +52,7 @@ namespace rs //required since rs_stream doesn't include motion stream info void write_capabilities(std::vector capabilities); void write_stream_info(std::map profiles); + void write_motion_intrinsics(const rs_motion_intrinsics &motion_intrinsics); void write_properties(const std::vector &properties); void write_first_frame_offset(); void write_stream_num_of_frames(); diff --git a/sdk/src/cameras/record/include/record_device_impl.h b/sdk/src/cameras/record/include/record_device_impl.h index e4ed61a..91b7dde 100644 --- a/sdk/src/cameras/record/include/record_device_impl.h +++ b/sdk/src/cameras/record/include/record_device_impl.h @@ -49,6 +49,10 @@ namespace rs virtual rs_frame_ref * clone_frame(rs_frame_ref * frame) override; virtual const char * get_usb_port_id() const; + virtual const char * get_camera_info(rs_camera_info) const; + virtual rs_motion_intrinsics get_motion_intrinsics() const; + virtual rs_extrinsics get_motion_extrinsics_from(rs_stream from) const; + virtual void pause_record() override; virtual void resume_record() override; diff --git a/sdk/src/cameras/record/record_context.cpp b/sdk/src/cameras/record/record_context.cpp index 6d8c319..6a76830 100644 --- a/sdk/src/cameras/record/record_context.cpp +++ b/sdk/src/cameras/record/record_context.cpp @@ -8,20 +8,23 @@ namespace rs { namespace record { - context::context(const std::string& file_path) + context::context(const char *file_path) { + m_devices = new rs_device*[get_device_count()]; for(auto i = 0; i < get_device_count(); i++) { - rs_error * e = nullptr; - auto r = rs_get_device(handle, i, &e); - rs::error::handle(e); - m_devices.push_back(std::unique_ptr(new rs_device_ex(file_path, r))); + m_devices[i] = new rs_device_ex(file_path, (rs_device*)(m_context.get_device(i)));//revert casting to cpp wrapper done by librealsense } } context::~context() { - + for(auto i = 0; i < get_device_count(); i++) + { + if(m_devices[i]) + delete m_devices[i]; + } + delete[] m_devices; } rs::device * context::get_device(int index) @@ -31,7 +34,7 @@ namespace rs device * context::get_record_device(int index) { - return (device*)m_devices[index].get(); + return (device*)m_devices[index]; } } } diff --git a/sdk/src/cameras/record/record_device_impl.cpp b/sdk/src/cameras/record/record_device_impl.cpp index f0b13c6..ed9e521 100644 --- a/sdk/src/cameras/record/record_device_impl.cpp +++ b/sdk/src/cameras/record/record_device_impl.cpp @@ -368,6 +368,24 @@ namespace rs return m_device->get_usb_port_id(); } + const char * rs_device_ex::get_camera_info(rs_camera_info type) const + { + LOG_FUNC_SCOPE(); + return m_device->get_camera_info(type); + } + + rs_motion_intrinsics rs_device_ex::get_motion_intrinsics() const + { + LOG_FUNC_SCOPE(); + return m_device->get_motion_intrinsics(); + } + + rs_extrinsics rs_device_ex::get_motion_extrinsics_from(rs_stream from) const + { + LOG_FUNC_SCOPE(); + return m_device->get_motion_extrinsics_from(from); + } + void rs_device_ex::pause_record() { LOG_INFO("pause record") @@ -385,9 +403,11 @@ namespace rs LOG_FUNC_SCOPE(); core::file_types::device_info info; memset(&info, 0, sizeof(device_info)); - strcpy(info.name, get_name()); - strcpy(info.serial, get_serial()); - strcpy(info.firmware, get_firmware_version()); + strcpy(info.name, get_camera_info(rs_camera_info::RS_CAMERA_INFO_DEVICE_NAME)); + strcpy(info.serial, get_camera_info(rs_camera_info::RS_CAMERA_INFO_DEVICE_SERIAL_NUMBER)); + strcpy(info.camera_firmware, get_camera_info(rs_camera_info::RS_CAMERA_INFO_CAMERA_FIRMWARE_VERSION)); + strcpy(info.motion_module_firmware, get_camera_info(rs_camera_info::RS_CAMERA_INFO_MOTION_MODULE_FIRMWARE_VERSION)); + strcpy(info.adapter_board_firmware, get_camera_info(rs_camera_info::RS_CAMERA_INFO_ADAPTER_BOARD_FIRMWARE_VERSION)); strcpy(info.usb_port_id, get_usb_port_id()); return info; } @@ -441,6 +461,9 @@ namespace rs auto capture_time = get_capture_time(); for(auto it = m_active_streams.begin(); it != m_active_streams.end(); ++it) { +#ifndef lrs_empty_first_frames_workaround + if(m_device->get_stream_interface(*it).get_frame_number() == 0) continue; +#endif file_types::frame_sample frame(*it, m_device->get_stream_interface(*it), capture_time); std::shared_ptr sample = std::shared_ptr(frame.copy(), [](file_types::sample* f) { delete[] (static_cast(f))->data; delete f;}); @@ -457,6 +480,7 @@ namespace rs config.m_file_path = m_file_path; config.m_options = read_all_options(); config.m_stream_profiles = get_profiles(); + config.m_motion_intrinsics = get_motion_intrinsics(); return m_disk_write.configure(config); } @@ -488,6 +512,17 @@ namespace rs rs_extrinsics extrinsics = si.get_extrinsics_to(m_device->get_stream_interface(rs_stream::RS_STREAM_DEPTH)); auto depth_scale = *it == rs_stream::RS_STREAM_DEPTH ? m_device->get_depth_scale() : 0; profiles[*it] = {fi, si.get_framerate(), intrinsics, rect_intrinsics, extrinsics, depth_scale}; +#ifndef infrared_bug + switch(*it) + { + case rs_stream::RS_STREAM_DEPTH: + case rs_stream::RS_STREAM_COLOR: + case rs_stream::RS_STREAM_FISHEYE: profiles[*it].motion_extrinsics = m_device->get_motion_extrinsics_from(*it);break; + default: break; + } +#else + profiles[*it].motion_extrinsics = m_device->get_motion_extrinsics_from(*it); +#endif } return profiles; } diff --git a/sdk/src/core/image/CMakeLists.txt b/sdk/src/core/image/CMakeLists.txt index ffe8d85..82a6a2e 100755 --- a/sdk/src/core/image/CMakeLists.txt +++ b/sdk/src/core/image/CMakeLists.txt @@ -7,7 +7,6 @@ include_directories( . .. ${ROOT_DIR}/include - ${ROOT_DIR}/include/rs/core ${ROOT_DIR}/src/utilities ${ROOT_DIR}/src/utilities/image ) @@ -16,15 +15,15 @@ include_directories( #Source Files set(SOURCE_FILES image_base.cpp - ${ROOT_DIR}/include/rs/core/image_base.h + image_base.h custom_image.cpp - ${ROOT_DIR}/include/rs/core/custom_image.h + custom_image.h lrs_image.cpp - ${ROOT_DIR}/include/rs/core/lrs_image.h + lrs_image.h image_conversion_util.cpp image_conversion_util.h metadata.cpp - ${ROOT_DIR}/include/rs/core/metadata.h + metadata.h ${ROOT_DIR}/include/rs/core/image_interface.h ${ROOT_DIR}/include/rs/core/metadata_interface.h ) diff --git a/sdk/src/core/image/custom_image.cpp b/sdk/src/core/image/custom_image.cpp index ed99f82..bbc6ecc 100644 --- a/sdk/src/core/image/custom_image.cpp +++ b/sdk/src/core/image/custom_image.cpp @@ -60,6 +60,18 @@ namespace rs m_data_releaser->release(); } } + + image_interface * image_interface::create_instance_from_raw_data(image_info * info, + const void * data, + stream_type stream, + image_interface::flag flags, + double time_stamp, + uint64_t frame_number, + rs::utils::smart_ptr metadata, + rs::utils::smart_ptr data_releaser) + { + return new custom_image(info, data, stream, flags, time_stamp, frame_number, metadata, data_releaser); + } } } diff --git a/sdk/include/rs/core/custom_image.h b/sdk/src/core/image/custom_image.h similarity index 84% rename from sdk/include/rs/core/custom_image.h rename to sdk/src/core/image/custom_image.h index 36c03a7..8cb123f 100644 --- a/sdk/include/rs/core/custom_image.h +++ b/sdk/src/core/image/custom_image.h @@ -18,17 +18,6 @@ namespace rs class custom_image : public image_base { public: - /** - * @brief The data_releaser_interface class - * optional custom deallocation method to be called by the image destructor. - */ - class data_releaser_interface - { - public: - virtual void release() = 0; - virtual ~data_releaser_interface() {} - }; - custom_image(const custom_image &) = delete; custom_image & operator = (const custom_image &) = delete; diff --git a/sdk/src/core/image/image_base.cpp b/sdk/src/core/image/image_base.cpp index 421d983..b3d6d7e 100644 --- a/sdk/src/core/image/image_base.cpp +++ b/sdk/src/core/image/image_base.cpp @@ -13,7 +13,7 @@ namespace rs namespace core { - class data_releaser_impl : public custom_image::data_releaser_interface + class data_releaser_impl : public image_interface::data_releaser_interface { public: data_releaser_impl(uint8_t* data) :data(data) {} @@ -48,7 +48,7 @@ namespace rs auto dst_data = new uint8_t[dst_info.height * dst_info.pitch]; //create a releaser for the above allocation - smart_ptr data_releaser(new data_releaser_impl(dst_data)); + smart_ptr data_releaser(new data_releaser_impl(dst_data)); // update the dst image data if(image_conversion_util::convert(query_info(), static_cast(query_data()), dst_info, dst_data) < status_no_error) @@ -58,7 +58,7 @@ namespace rs } //cache the image - const image_interface * dst_image = new custom_image(&dst_info, + const image_interface * dst_image = create_instance_from_raw_data(&dst_info, dst_data, query_stream_type(), query_flags(), diff --git a/sdk/include/rs/core/image_base.h b/sdk/src/core/image/image_base.h similarity index 100% rename from sdk/include/rs/core/image_base.h rename to sdk/src/core/image/image_base.h diff --git a/sdk/src/core/image/image_conversion_util.cpp b/sdk/src/core/image/image_conversion_util.cpp index d9ab635..94d2a64 100644 --- a/sdk/src/core/image/image_conversion_util.cpp +++ b/sdk/src/core/image/image_conversion_util.cpp @@ -1,9 +1,8 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2016 Intel Corporation. All Rights Reserved. -#include "custom_image.h" #include "image_conversion_util.h" -#include "status.h" +#include "rs/core/status.h" #include "opencv/cv.h" #include "opencv/cxcore.h" diff --git a/sdk/src/core/image/lrs_image.cpp b/sdk/src/core/image/lrs_image.cpp index dd4800c..ff30200 100644 --- a/sdk/src/core/image/lrs_image.cpp +++ b/sdk/src/core/image/lrs_image.cpp @@ -1,7 +1,7 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2016 Intel Corporation. All Rights Reserved. -#include "rs/core/lrs_image.h" +#include "lrs_image.h" #include "rs/utils/librealsense_conversion_utils.h" using namespace rs::utils; @@ -24,7 +24,7 @@ namespace rs info.format = utils::convert_pixel_format(m_frame.get_format()); info.height = m_frame.get_height(); info.width = m_frame.get_width(); - info.pitch = m_frame.get_stride_x(); + info.pitch = m_frame.get_stride(); return info; } @@ -53,6 +53,13 @@ namespace rs { return m_frame.get_frame_number(); } + + image_interface * image_interface::create_instance_from_librealsense_frame(rs::frame& frame, + flag flags, + rs::utils::smart_ptr metadata) + { + return new lrs_image(frame, flags, metadata); + } } } diff --git a/sdk/include/rs/core/lrs_image.h b/sdk/src/core/image/lrs_image.h similarity index 100% rename from sdk/include/rs/core/lrs_image.h rename to sdk/src/core/image/lrs_image.h diff --git a/sdk/src/core/image/metadata.cpp b/sdk/src/core/image/metadata.cpp index d1933e5..a726466 100644 --- a/sdk/src/core/image/metadata.cpp +++ b/sdk/src/core/image/metadata.cpp @@ -31,6 +31,11 @@ namespace rs { return status_feature_unsupported; } + + metadata_interface * metadata_interface::create_instance() + { + return new metadata(); + } } } diff --git a/sdk/include/rs/core/metadata.h b/sdk/src/core/image/metadata.h similarity index 100% rename from sdk/include/rs/core/metadata.h rename to sdk/src/core/image/metadata.h diff --git a/sdk/src/core/projection/projection_r200.cpp b/sdk/src/core/projection/projection_r200.cpp index 3f10a23..9f166ba 100644 --- a/sdk/src/core/projection/projection_r200.cpp +++ b/sdk/src/core/projection/projection_r200.cpp @@ -8,7 +8,6 @@ #include "projection_r200.h" #pragma warning (disable : 4068) -#include "rs/core/custom_image.h" #include "src/utilities/image/librealsense_image_utils.h" #include "librealsense/rs.h" #include "projection/projection_utils.h" @@ -21,7 +20,7 @@ namespace rs namespace core { - class data_releaser_impl : public custom_image::data_releaser_interface + class data_releaser_impl : public image_interface::data_releaser_interface { public: data_releaser_impl(uint8_t* data) :data(data) {} @@ -521,16 +520,16 @@ namespace rs ptr_color2depth_data += color2depth_step; } - smart_ptr data_releaser(new data_releaser_impl(color2depth_data)); + smart_ptr data_releaser(new data_releaser_impl(color2depth_data)); - return new custom_image(&color2depth_info, - color2depth_data, - stream_type::color, - image_interface::flag::any, - 0, - 0, - nullptr, - data_releaser); + return image_interface::create_instance_from_raw_data(&color2depth_info, + color2depth_data, + stream_type::color, + image_interface::flag::any, + 0, + 0, + nullptr, + data_releaser); } @@ -579,16 +578,16 @@ namespace rs (float*)m_buffer, color_info.width * sizeof(pointF32), (uint16_t*)depth2color_data, color_size, depth2color_info.pitch, 0, default_depth_value); - smart_ptr data_releaser(new data_releaser_impl(depth2color_data)); + smart_ptr data_releaser(new data_releaser_impl(depth2color_data)); - return new custom_image(&depth2color_info, - depth2color_data, - stream_type::depth, - image_interface::flag::any, - 0, - 0, - nullptr, - data_releaser); + return image_interface::create_instance_from_raw_data(&depth2color_info, + depth2color_data, + stream_type::depth, + image_interface::flag::any, + 0, + 0, + nullptr, + data_releaser); } diff --git a/sdk/src/tools/capture_tool/capture_tool.cpp b/sdk/src/tools/capture_tool/capture_tool.cpp index 1aa561f..cb43ead 100644 --- a/sdk/src/tools/capture_tool/capture_tool.cpp +++ b/sdk/src/tools/capture_tool/capture_tool.cpp @@ -8,6 +8,7 @@ #include #include #include "rs_core.h" +#include "rs/core/context_interface.h" #include "rs/playback/playback_context.h" #include "rs/record/record_context.h" #include "command_line/basic_cmd_util.h" @@ -32,13 +33,13 @@ auto g_frame_callback = [](rs::frame frame) g_renderer->show_frame(std::move(frame)); }; -std::shared_ptr create_context(basic_cmd_util cl_util) +std::shared_ptr create_context(basic_cmd_util cl_util) { switch(cl_util.get_streaming_mode()) { - case streaming_mode::live: return std::shared_ptr(new context()); - case streaming_mode::record: return std::shared_ptr(new rs::record::context(cl_util.get_file_path(streaming_mode::record))); - case streaming_mode::playback: return std::shared_ptr(new rs::playback::context(cl_util.get_file_path(streaming_mode::playback))); + case streaming_mode::live: return std::shared_ptr(new context()); + case streaming_mode::record: return std::shared_ptr(new rs::record::context(cl_util.get_file_path(streaming_mode::record).c_str())); + case streaming_mode::playback: return std::shared_ptr(new rs::playback::context(cl_util.get_file_path(streaming_mode::playback).c_str())); } return nullptr; } @@ -89,7 +90,7 @@ int main(int argc, char* argv[]) std::cout << g_cmd.get_selection(); - std::shared_ptr context = create_context(g_cmd); + std::shared_ptr context = create_context(g_cmd); if(context->get_device_count() == 0) { diff --git a/sdk/src/tools/projection_tool/projection_tool.cpp b/sdk/src/tools/projection_tool/projection_tool.cpp index 46217cb..cd3069f 100644 --- a/sdk/src/tools/projection_tool/projection_tool.cpp +++ b/sdk/src/tools/projection_tool/projection_tool.cpp @@ -37,7 +37,7 @@ using namespace rs::utils; * @return World image raw data * @return nullptr Failed to query vertices from projection image */ -uint8_t* create_world_data(projection_interface* realsense_projection, const void* depth_data, custom_image* depth, int depth_width, int depth_height); +uint8_t* create_world_data(projection_interface* realsense_projection, const void* depth_data, image_interface* depth, int depth_width, int depth_height); /* helper functions */ /* @@ -78,7 +78,7 @@ static const char* keys = int main(int argc, char* argv[]) { - std::unique_ptr realsense_context; + std::unique_ptr realsense_context; rs::device* realsense_device; std::unique_ptr realsense_projection; rs::stream color_stream = rs::stream::color; @@ -106,7 +106,7 @@ int main(int argc, char* argv[]) std::cerr << "\nError: Playback file is not accessible" << std::endl; return -1; } - realsense_context = std::unique_ptr(new rs::playback::context(file_path)); + realsense_context = std::unique_ptr(new rs::playback::context(file_path.c_str())); realsense_device = realsense_context->get_device(0); // device is managed by context, no need to deallocate manually if (!realsense_device) { @@ -266,26 +266,26 @@ int main(int argc, char* argv[]) // image objects (image info and data pointers) image_info depth_info = {depth_width, depth_height, convert_pixel_format(rs::format::z16), depth_pitch}; - custom_image depth (&depth_info, - depth_data, - stream_type::depth, - image_interface::flag::any, - realsense_device->get_frame_timestamp(rs::stream::depth), - realsense_device->get_frame_number(rs::stream::depth), - nullptr, - nullptr); + std::unique_ptr depth(image_interface::create_instance_from_raw_data(&depth_info, + depth_data, + stream_type::depth, + image_interface::flag::any, + realsense_device->get_frame_timestamp(rs::stream::depth), + realsense_device->get_frame_number(rs::stream::depth), + nullptr, + nullptr)); image_info color_info = {color_width, color_height, convert_pixel_format(rs::format::bgra8), color_pitch}; - custom_image color (&color_info, - color_data, - stream_type::color, - image_interface::flag::any, - realsense_device->get_frame_timestamp(rs::stream::color), - realsense_device->get_frame_number(rs::stream::color), - nullptr, - nullptr); + std::unique_ptr color(image_interface::create_instance_from_raw_data(&color_info, + color_data, + stream_type::color, + image_interface::flag::any, + realsense_device->get_frame_timestamp(rs::stream::color), + realsense_device->get_frame_number(rs::stream::color), + nullptr, + nullptr)); const std::unique_ptr world_data = - std::unique_ptr(create_world_data(realsense_projection.get(), depth_data, &depth, depth_width, depth_height)); // deallocation is handled by smart ptr + std::unique_ptr(create_world_data(realsense_projection.get(), depth_data, depth.get(), depth_width, depth_height)); // deallocation is handled by smart ptr if (!(world_data.get())) { std::cerr << "Unable to get world data" << std::endl; @@ -304,7 +304,7 @@ int main(int argc, char* argv[]) { /* Documentation reference: query_uvmap function */ std::vector uvmap(depth_width*depth_height); - status = realsense_projection->query_uvmap(&depth, uvmap.data()); + status = realsense_projection->query_uvmap(depth.get(), uvmap.data()); if (status != status_no_error) { std::cerr << "Error: query_uvmap bad status returned: " << status << std::endl; @@ -329,7 +329,7 @@ int main(int argc, char* argv[]) { /* Documentation reference: query_invuvmap function */ std::vector invuvmap(color_width*color_height); - status = realsense_projection->query_invuvmap(&depth, invuvmap.data()); + status = realsense_projection->query_invuvmap(depth.get(), invuvmap.data()); if (status != status_no_error) { std::cerr << "\nError: query_invuvmap bad status returned: " << status << std::endl; @@ -357,7 +357,7 @@ int main(int argc, char* argv[]) if (gui_handler.is_color_to_depth_queried()) // color image mapped to depth { /* Documentation reference: create_color_image_mapped_to_depth function */ - smart_ptr color2depth_image(realsense_projection->create_color_image_mapped_to_depth(&depth, &color)); + smart_ptr color2depth_image(realsense_projection->create_color_image_mapped_to_depth(depth.get(), color.get())); const void* color2depth_data = color2depth_image->query_data(); if (!color2depth_data) { @@ -369,7 +369,7 @@ int main(int argc, char* argv[]) if (gui_handler.is_depth_to_color_queried()) // depth image mapped to color { /* Documentation reference: create_depth_image_mapped_to_color function */ - smart_ptr depth2color_image(realsense_projection->create_depth_image_mapped_to_color(&depth, &color)); + smart_ptr depth2color_image(realsense_projection->create_depth_image_mapped_to_color(depth.get(), color.get())); const void* depth2color_data = depth2color_image->query_data(); if (!depth2color_data) { @@ -459,7 +459,7 @@ int main(int argc, char* argv[]) /* Documentation reference: map_color_to_depth function */ // mapping color image to depth image std::vector depth_points(drawn_points_size); - status = realsense_projection->map_color_to_depth(&depth, drawn_points_size, color_points.data(), depth_points.data()); + status = realsense_projection->map_color_to_depth(depth.get(), drawn_points_size, color_points.data(), depth_points.data()); if (status != status_no_error) { if (status != status_value_out_of_range) @@ -472,7 +472,7 @@ int main(int argc, char* argv[]) /* Documentation reference: project_color_to_camera function */ // projecting color image to image from camera std::vector world_points(drawn_points_size); - status = realsense_projection->map_color_to_depth(&depth, drawn_points_size, color_points.data(), world_points.data()); + status = realsense_projection->map_color_to_depth(depth.get(), drawn_points_size, color_points.data(), world_points.data()); if (status != status_no_error) { if (status != status_value_out_of_range) @@ -567,7 +567,7 @@ int main(int argc, char* argv[]) return 0; } -uint8_t* create_world_data(projection_interface* realsense_projection, const void* depth_data, custom_image* depth, int depth_width, int depth_height) +uint8_t* create_world_data(projection_interface* realsense_projection, const void* depth_data, image_interface* depth, int depth_width, int depth_height) { std::vector matrix(depth_width*depth_height); const int pitch = depth_width; diff --git a/sdk/src/utilities/sync_utility/sync_utility.cpp b/sdk/src/utilities/sync_utility/sync_utility.cpp index 92d1d7f..7d91172 100644 --- a/sdk/src/utilities/sync_utility/sync_utility.cpp +++ b/sdk/src/utilities/sync_utility/sync_utility.cpp @@ -11,13 +11,13 @@ rs::utils::sync_utility::sync_utility(vector>& s if (max_input_latency == 0) { LOG_ERROR("Zero latency is not acceptable"); - throw "Zero latency is not acceptable"; + throw std::invalid_argument("Zero latency is not acceptable"); } if (streams.size() + motions.size() < 2 ) { LOG_ERROR("Less than two streams were registered to sync utility instance!"); - throw "Less than two streams were registered to sync utility instance!"; + throw std::invalid_argument("Less than two streams were registered to sync utility instance!"); } // Save fps's for each stream and motion requested @@ -35,7 +35,7 @@ rs::utils::sync_utility::sync_utility(vector>& s if (ret.second == false) { LOG_ERROR("Same stream type specified twice !"); - throw "Same stream type specified twice !"; + throw std::invalid_argument("Same stream type specified twice !"); } m_stream_fps[item.first] = item.second; @@ -44,7 +44,7 @@ rs::utils::sync_utility::sync_utility(vector>& s for (auto item : motions) { // We do not support motions meanwhile - throw "Not implemented."; + throw std::logic_error("Not implemented."); m_motion_fps[item.first] = item.second; @@ -57,7 +57,7 @@ rs::utils::sync_utility::sync_utility(vector>& s if (ret.second == false) { LOG_ERROR("Same stream type specified twice !"); - throw "Same motion type specified twice !"; + throw std::invalid_argument("Same motion type specified twice !"); } } @@ -137,11 +137,11 @@ bool rs::utils::sync_utility::insert(rs::utils::smart_ptr new_i rs::core::correlated_sample_set& correlated_sample) { if (!new_image) - throw "Null pointer received!"; + throw std::invalid_argument("Null pointer received!"); // this stream type was not registered with this instance of the sync_utility if (!is_stream_registered( new_image->query_stream_type() )) - throw "Stream was not registered to this sync utility instance!"; + throw std::invalid_argument("Stream was not registered to this sync utility instance!"); std::lock_guard lock_guard(m_image_mutex); @@ -154,7 +154,7 @@ bool rs::utils::sync_utility::insert(rs::utils::smart_ptr new_i bool rs::utils::sync_utility::insert(rs::core::motion_sample new_motion, rs::core::correlated_sample_set& correlated_sample) { - throw "Not implemented."; + throw std::logic_error("Not implemented."); return false; } diff --git a/sdk/src/utilities/viewer/viewer.cpp b/sdk/src/utilities/viewer/viewer.cpp index 46a31a1..cfff4e1 100644 --- a/sdk/src/utilities/viewer/viewer.cpp +++ b/sdk/src/utilities/viewer/viewer.cpp @@ -2,7 +2,6 @@ // Copyright(c) 2016 Intel Corporation. All Rights Reserved. #include "viewer.h" -#include "rs/core/lrs_image.h" namespace { @@ -23,16 +22,22 @@ namespace rs { namespace utils { - viewer::viewer(rs::device* device, uint32_t window_size) : + viewer::viewer(rs::device* device, uint32_t window_size, std::string window_title) : m_window_size(window_size), m_window(nullptr), - m_device(device) + m_device(device), + m_window_title(window_title) { for(int i = 0; i <= (int)rs::core::stream_type::fisheye; i++) { if(device->is_stream_enabled((rs::stream)i)) m_streams.push_back((rs::core::stream_type)i); } + + if(m_window == nullptr) + { + setup_windows(); + } } viewer::~viewer() @@ -46,12 +51,20 @@ namespace rs void viewer::show_frame(rs::frame frame) { - auto image = std::shared_ptr(new rs::core::lrs_image(frame, rs::core::image_interface::flag::any, nullptr)); + auto image = std::shared_ptr(core::image_interface::create_instance_from_librealsense_frame(frame, rs::core::image_interface::flag::any, nullptr)); render_image(std::move(image)); } + void viewer::show_image(rs::utils::smart_ptr image) + { + if(!image) return; + auto smart_img = std::shared_ptr(const_cast(image.get()), [](rs::core::image_interface*){}); + render_image(smart_img); + } + void viewer::show_image(std::shared_ptr image) { + if(!image) return; render_image(image); } @@ -61,17 +74,52 @@ namespace rs std::lock_guard guard(m_render_mutex); - if(m_window == nullptr) - { - setup_windows(); - } - auto position = m_windows_positions.at(stream); + int gl_format, gl_pixel_size; utils::smart_ptr converted_image; - if(image->convert_to(core::pixel_format::rgba8, converted_image) != core::status_no_error) return; + const core::image_interface * image_to_show = image.get(); + switch(image->query_info().format) + { + case rs::core::pixel_format::rgb8: + gl_format = GL_RGB; + gl_pixel_size = GL_UNSIGNED_BYTE; + break; + case rs::core::pixel_format::bgr8: + gl_format = GL_BGR; + gl_pixel_size = GL_UNSIGNED_BYTE; + break; + case rs::core::pixel_format::yuyv: + gl_format = GL_LUMINANCE_ALPHA; + gl_pixel_size = GL_UNSIGNED_BYTE; + break; + case rs::core::pixel_format::rgba8: + gl_format = GL_RGBA; + gl_pixel_size = GL_UNSIGNED_BYTE; + break; + case rs::core::pixel_format::bgra8: + gl_format = GL_BGRA; + gl_pixel_size = GL_UNSIGNED_BYTE; + break; + case rs::core::pixel_format::y8: + gl_format = GL_LUMINANCE; + gl_pixel_size = GL_UNSIGNED_BYTE; + break; + case rs::core::pixel_format::y16: + gl_format = GL_LUMINANCE; + gl_pixel_size = GL_SHORT; + break; + case rs::core::pixel_format::z16: + if(image->convert_to(core::pixel_format::rgba8, converted_image) != core::status_no_error) return; + image_to_show = converted_image.get(); + gl_format = GL_RGBA; + gl_pixel_size = GL_UNSIGNED_BYTE; + break; + default: + throw "format is not supported"; + } - auto info = converted_image->query_info(); + auto info = image_to_show->query_info(); double scale = (double)m_window_size / (double)info.width; auto width = m_window_size; @@ -87,7 +135,7 @@ namespace rs glPushMatrix(); glOrtho(0, m_window_size, m_window_size, 0, -1, +1); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, info.width, info.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, converted_image->query_data()); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, info.width, info.height, 0, gl_format, gl_pixel_size, image_to_show->query_data()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); @@ -117,10 +165,12 @@ namespace rs glfwTerminate(); } glfwInit(); - m_window = glfwCreateWindow(m_window_size * m_windows_positions.size(), m_window_size, "RS SDK Viewer", NULL, NULL); + auto title = m_window_title == "" ? "RS SDK Viewer" : m_window_title; + m_window = glfwCreateWindow(m_window_size * m_windows_positions.size(), m_window_size, title.c_str(), NULL, NULL); glfwMakeContextCurrent(m_window); glViewport (0, 0, m_window_size * m_windows_positions.size(), m_window_size); glClear(GL_COLOR_BUFFER_BIT); + glfwSwapBuffers(m_window); } } } diff --git a/sdk/src/utilities/viewer/viewer.h b/sdk/src/utilities/viewer/viewer.h index 0efe29d..94882bc 100644 --- a/sdk/src/utilities/viewer/viewer.h +++ b/sdk/src/utilities/viewer/viewer.h @@ -25,9 +25,10 @@ namespace rs class viewer { public: - viewer(device *device, uint32_t window_size); + viewer(device *device, uint32_t window_size, std::string window_title = ""); ~viewer(); void show_frame(rs::frame frame); + void show_image(rs::utils::smart_ptr image); void show_image(std::shared_ptr image); private: @@ -38,6 +39,7 @@ namespace rs std::mutex m_render_mutex; int m_window_size; + std::string m_window_title; GLFWwindow * m_window; rs::device * m_device; std::vector m_streams; diff --git a/sdk/test/CMakeLists.txt b/sdk/test/CMakeLists.txt deleted file mode 100644 index 25eb320..0000000 --- a/sdk/test/CMakeLists.txt +++ /dev/null @@ -1,52 +0,0 @@ -cmake_minimum_required(VERSION 2.8) -project(rs_tests) - - -include_directories( - ${ROOT_DIR} - ${ROOT_DIR}/include/rs/core - ${ROOT_DIR}/src/cameras/include - ${ROOT_DIR}/src/cameras/playback/include - ${ROOT_DIR}/src/cameras/record/include - ${ROOT_DIR}/src/core/image - ${ROOT_DIR}/src/utilities - ${ROOT_DIR}/src/utilities/logger/include -) - -add_executable(${PROJECT_NAME} - main.cpp - projection_fixture.h - utilities/utilities.h - simple_streaming_tests.cpp - playback_device_tests.cpp - record_device_tests.cpp - image_tests.cpp - projection_tests.cpp - librealsense_conversion_tests.cpp - smart_ptr_tests.cpp -) - -target_link_libraries(${PROJECT_NAME} - gtest - gtest_main - pthread - realsense - rs_image - rs_playback - rs_record - glfw - rs_log_utils - GL - rs_viewer -) - -add_dependencies(${PROJECT_NAME} - rs_viewer - rs_playback - rs_record - rs_log_utils - rs_image - rs_projection -) - -install(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/sdk/test/simple_streaming_tests.cpp b/sdk/test/simple_streaming_tests.cpp deleted file mode 100644 index c859ae9..0000000 --- a/sdk/test/simple_streaming_tests.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2016 Intel Corporation. All Rights Reserved. - -#include -#include "gtest/gtest.h" -#include "utilities/utilities.h" - -//librealsense api -#include "librealsense/rs.hpp" -#include - -//opengl api -#define GLFW_INCLUDE_GLU -#include - -using namespace std; - -GTEST_TEST(StreamingTests, basicColorStreaming) -{ - rs::context contex; - ASSERT_NE(contex.get_device_count(), 0) << "No camera is connected"; - - rs::device * device = contex.get_device(0); - - int colorWidth = 640, colorHeight = 480, colorFps = 30; - const rs::format colorFormat = rs::format::rgb8; - int depthWidth = 628, depthHeight = 468, depthFps = 30; - const rs::format depthFormat = rs::format::z16; - - auto frame_count = 0; - auto maxFramesCount = 100; - - device->enable_stream(rs::stream::color, colorWidth, colorHeight, colorFormat, colorFps); - device->enable_stream(rs::stream::depth, depthWidth, depthHeight, depthFormat, depthFps); - std::map windows; - for(int32_t s = (int32_t)rs::stream::depth; s <= (int32_t)rs::stream::infrared2; ++s) - { - auto stream = (rs::stream)s; - if(device->is_stream_enabled(stream)) - { - glfwInit(); - auto width = device->get_stream_width(stream); - auto height = device->get_stream_height(stream); - windows[stream] = (glfwCreateWindow(width, height, "basic playback test", nullptr, nullptr)); - } - } - - device->start(); - - while(frame_count++ < maxFramesCount) - { - device->wait_for_frames(); - for(int32_t s = (int32_t)rs::stream::depth; s <= (int32_t)rs::stream::infrared2; ++s) - { - auto stream = (rs::stream)s; - if(device->is_stream_enabled(stream)) - { - glfwMakeContextCurrent(windows.at(stream)); - glutils::gl_render(windows.at(stream), device, (rs::stream)s); - } - } - } - - for(int32_t s = (int32_t)rs::stream::depth; s <= (int32_t)rs::stream::infrared2; ++s) - { - auto stream = (rs::stream)s; - if(device->is_stream_enabled(stream)) - { - glutils::gl_close(windows.at(stream)); - } - } -} diff --git a/sdk/test/utilities/utilities.h b/sdk/test/utilities/utilities.h deleted file mode 100644 index dfb5ed7..0000000 --- a/sdk/test/utilities/utilities.h +++ /dev/null @@ -1,209 +0,0 @@ -// License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2016 Intel Corporation. All Rights Reserved. - -#pragma once -#include "rs/core/image_interface.h" -#include "rs/utils/librealsense_conversion_utils.h" -#include "image/image_utils.h" -#include "librealsense/rs.hpp" -//opengl api -#define GLFW_INCLUDE_GLU -#include -#include -#include -#include - -namespace glutils -{ - static void gl_close(GLFWwindow * window) - { - glfwDestroyWindow(window); - glfwTerminate(); - } - - static inline void make_depth_histogram(std::vector& rgb_image, const uint16_t depth_image[]) - { - static uint32_t histogram[0x10000]; - memset(histogram, 0, sizeof(histogram)); - auto size = rgb_image.size() / 3; - for(size_t i = 0; i < size; ++i) ++histogram[depth_image[i]]; - for(size_t i = 2; i < 0x10000; ++i) histogram[i] += histogram[i-1]; // Build a cumulative histogram for the indices in [1,0xFFFF] - for(size_t i = 0; i < size; ++i) - { - if(uint16_t d = depth_image[i]) - { - int f = histogram[d] * 255 / histogram[0xFFFF]; // 0-255 based on histogram location - rgb_image[i*3 + 0] = 255 - f; - rgb_image[i*3 + 1] = 0; - rgb_image[i*3 + 2] = f; - } - else - { - rgb_image[i*3 + 0] = 20; - rgb_image[i*3 + 1] = 5; - rgb_image[i*3 + 2] = 0; - } - } - } - - static void gl_render(GLFWwindow * window, rs::frame& frame) - { - std::vector rgb; - GLuint texture = 0; - auto width = frame.get_width(); - auto height = frame.get_height(); - const void * imageDataToDisplay = frame.get_data(); - if(!imageDataToDisplay)return; - rgb.resize(width * height * 3); - auto format = frame.get_format(); - int gl_color_format = GL_NONE; - switch(format) - { - case rs::format::rgb8: - case rs::format::bgr8: gl_color_format = GL_RGB; break; - case rs::format::rgba8: - case rs::format::bgra8: gl_color_format = GL_RGBA; break; - default: break; - } - - glPushMatrix(); - glOrtho(0, width, height, 0, -1, +1); - - if(frame.get_stream_type() != rs::stream::color) - { - make_depth_histogram(rgb,reinterpret_cast(imageDataToDisplay)); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, rgb.data()); - } - else - glTexImage2D(GL_TEXTURE_2D, 0, gl_color_format,width ,height , 0, gl_color_format, GL_UNSIGNED_BYTE, imageDataToDisplay); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glBindTexture(GL_TEXTURE_2D, texture); - glEnable(GL_TEXTURE_2D); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); glVertex2f(0, 0); - glTexCoord2f(0, 1); glVertex2f(0, height); - glTexCoord2f(1, 1); glVertex2f(width, height); - glTexCoord2f(1, 0); glVertex2f(width, 0); - glEnd(); - glDisable(GL_TEXTURE_2D); - glPopMatrix(); - glfwSwapBuffers(window); - glfwPollEvents(); - //std::this_thread::sleep_for (std::chrono::milliseconds(15)); - } - - static void gl_render(GLFWwindow * window, rs::device* device, rs::stream stream) - { - std::vector rgb; - GLuint texture = 0; - auto width = device->get_stream_width(stream); - auto height = device->get_stream_height(stream); - const void * imageDataToDisplay = device->get_frame_data(stream); - if(!imageDataToDisplay)return; - rgb.resize(width * height * 3); - auto format = device->get_stream_format(stream); - int gl_color_format = GL_NONE; - switch(format) - { - case rs::format::rgb8: - case rs::format::bgr8: gl_color_format = GL_RGB; break; - case rs::format::rgba8: - case rs::format::bgra8: gl_color_format = GL_RGBA; break; - default: break; - } - - glPushMatrix(); - glOrtho(0, width, height, 0, -1, +1); - if(stream == rs::stream::depth) - { - make_depth_histogram(rgb,reinterpret_cast(imageDataToDisplay)); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, rgb.data()); - } - else - glTexImage2D(GL_TEXTURE_2D, 0, gl_color_format,width ,height , 0, gl_color_format, GL_UNSIGNED_BYTE, imageDataToDisplay); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glBindTexture(GL_TEXTURE_2D, texture); - glEnable(GL_TEXTURE_2D); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); glVertex2f(0, 0); - glTexCoord2f(0, 1); glVertex2f(0, height); - glTexCoord2f(1, 1); glVertex2f(width, height); - glTexCoord2f(1, 0); glVertex2f(width, 0); - glEnd(); - glDisable(GL_TEXTURE_2D); - glPopMatrix(); - glfwSwapBuffers(window); - glfwPollEvents(); - //std::this_thread::sleep_for (std::chrono::milliseconds(15)); - } - - static void display_image(const rs::core::image_interface * image, std::string title) - { - auto info = image->query_info(); - - int gl_internal_format = GL_RGB, gl_format, gl_pixel_size; - switch(rs::utils::convert_pixel_format(info.format)) - { - case rs::format::rgb8: - gl_format = GL_RGB; - gl_pixel_size = GL_UNSIGNED_BYTE; - break; - case rs::format::bgr8: - gl_format = GL_BGR; - gl_pixel_size = GL_UNSIGNED_BYTE; - break; - case rs::format::yuyv: - gl_format = GL_LUMINANCE_ALPHA; - gl_pixel_size = GL_UNSIGNED_BYTE; - break; - case rs::format::rgba8: - gl_format = GL_RGBA; - gl_pixel_size = GL_UNSIGNED_BYTE; - break; - case rs::format::bgra8: - gl_format = GL_BGRA; - gl_pixel_size = GL_UNSIGNED_BYTE; - break; - case rs::format::y8: - gl_format = GL_LUMINANCE; - gl_pixel_size = GL_UNSIGNED_BYTE; - break; - default: - throw "no support format"; - } - - int windowWidth = info.width, windowHeight = info.height; - const void * imageDataToDisplay = image->query_data(); - glfwInit(); - GLFWwindow * window = glfwCreateWindow(windowWidth, windowHeight, title.c_str(), nullptr, nullptr); - glfwMakeContextCurrent(window); - GLuint texture = 0; - for(int i = 0; !(glfwWindowShouldClose(window) || i > 100); i++) - { - glPushMatrix(); - glOrtho(0, windowWidth, windowHeight, 0, -1, +1); - glTexImage2D(GL_TEXTURE_2D, 0, gl_internal_format, windowWidth, windowHeight, 0, gl_format , gl_pixel_size, imageDataToDisplay); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glBindTexture(GL_TEXTURE_2D, texture); - glEnable(GL_TEXTURE_2D); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); glVertex2f(0, 0); - glTexCoord2f(0, 1); glVertex2f(0, windowHeight); - glTexCoord2f(1, 1); glVertex2f(windowWidth, windowHeight); - glTexCoord2f(1, 0); glVertex2f(windowWidth, 0); - glEnd(); - glDisable(GL_TEXTURE_2D); - glPopMatrix(); - - glfwSwapBuffers(window); - glfwPollEvents(); - } - glfwDestroyWindow(window); - glfwTerminate(); - } -} - - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..01032a2 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,105 @@ +cmake_minimum_required(VERSION 2.8) +include(ExternalProject) +project(rs_tests) + +set(SDK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../sdk") +set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + +#Common settings +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + +add_definitions(-Wall) +add_definitions(-Wno-write-strings) +add_definitions(-Wno-comment) +add_definitions(-Wno-unknown-pragmas) +add_definitions(-Wno-unused-function) +add_definitions(-Wno-unused-variable) +add_definitions(-Wno-reorder) +add_definitions(-Werror) + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin/debug) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 ") +else() + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin/release) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 ") +endif() +file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) + +#--------------Add security options -------------------- +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORTIFY_SOURCE=2 ") #TODO: Check what it is +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat -Wformat-security") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fPIC") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z relro -z now") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") + + +#Add Gtest project +ExternalProject_Add( + gtest_lib + URL http://googletest.googlecode.com/files/gtest-1.7.0.zip + URL_HASH SHA1=f85f6d2481e2c6c4a18539e391aa4ea8ab0394af + CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} + -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} + -DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS} + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gtest + # Disable install step + INSTALL_COMMAND "" +) +# Set gtest properties +ExternalProject_Get_Property(gtest_lib source_dir binary_dir) +include_directories("${source_dir}/include") +link_directories("${binary_dir}") + +#build unit tests +include_directories( + ${SDK_DIR} + ${SDK_DIR}/include/rs/core + ${SDK_DIR}/src/cameras/include + ${SDK_DIR}/src/cameras/playback/include + ${SDK_DIR}/src/cameras/record/include + ${SDK_DIR}/src/core/image + ${SDK_DIR}/src/utilities + ${SDK_DIR}/src/utilities/logger/include +) + +add_executable(${PROJECT_NAME} + main.cpp + projection_fixture.h + utilities/utilities.h + simple_streaming_tests.cpp + playback_device_tests.cpp + record_device_tests.cpp + image_tests.cpp + projection_tests.cpp + librealsense_conversion_tests.cpp + ${SDK_DIR}/include/rs/utils/smart_ptr.h + smart_ptr_tests.cpp +) + +target_link_libraries(${PROJECT_NAME} + gtest + gtest_main + pthread + realsense + rs_image + rs_playback + rs_record + rs_log_utils + rs_viewer +) + +add_dependencies(${PROJECT_NAME} + rs_viewer + rs_playback + rs_record + rs_log_utils + rs_image + rs_projection + gtest_lib +) + +install(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/sdk/test/image_tests.cpp b/tests/image_tests.cpp similarity index 51% rename from sdk/test/image_tests.cpp rename to tests/image_tests.cpp index f15b83c..c2b8580 100644 --- a/sdk/test/image_tests.cpp +++ b/tests/image_tests.cpp @@ -7,10 +7,10 @@ #include "gtest/gtest.h" #include "utilities/utilities.h" #include "librealsense/rs.hpp" -#include "rs/core/custom_image.h" #include "image/librealsense_image_utils.h" #include "rs/utils/smart_ptr.h" #include "rs/utils/librealsense_conversion_utils.h" +#include "viewer/viewer.h" using namespace std; using namespace rs::core; @@ -31,7 +31,7 @@ class image_basic_tests : public testing::Test sleep(1); m_device->wait_for_frames(); - m_image.reset(new rs::core::custom_image(&info, + m_image.reset(image_interface::create_instance_from_raw_data(&info, m_device->get_frame_data(stream), convert_stream_type(stream), flags, @@ -125,14 +125,14 @@ TEST_P(image_conversions_tests, check_supported_conversions) m_device->enable_stream(test_data.stream, test_data.src_info.width, test_data.src_info.height, convert_pixel_format(test_data.src_info.format), 30); if(test_data.stream == rs::stream::infrared)//this will turn on the projector - m_device->enable_stream(rs::stream::depth, test_data.src_info.width, test_data.src_info.height, rs::format::z16, 30); + m_device->set_option(rs::option::r200_emitter_enabled,1); m_device->start(); m_device->wait_for_frames(); sleep(1); m_device->wait_for_frames(); - smart_ptr metadata = nullptr; - m_image.reset(new rs::core::custom_image(&test_data.src_info, + smart_ptr metadata(metadata_interface::create_instance()); + m_image.reset(image_interface::create_instance_from_raw_data(&test_data.src_info, m_device->get_frame_data(test_data.stream), convert_stream_type(test_data.stream), image_interface::flag::any, @@ -149,7 +149,11 @@ TEST_P(image_conversions_tests, check_supported_conversions) ASSERT_EQ(test_data.dst_info.format, info.format) << "converted image not in the right format"; std::ostringstream display_title; display_title << "converted : " << m_image->query_info()<< " to : " << converted_image->query_info(); - glutils::display_image(converted_image.get(), display_title.str()); + + auto viewer = std::make_shared(m_device, 640, display_title.str()); + + viewer->show_image(converted_image); + std::this_thread::sleep_for (std::chrono::milliseconds(500)); //check caching with another convert request smart_ptr second_converted_image; @@ -165,41 +169,41 @@ INSTANTIATE_TEST_CASE_P(basic_conversions, image_conversions_tests, ::testing::V // conversion_test_data(rs::stream::infrared, image_conversions_tests::get_info(640, 480, rs::format::y8 ), image_conversions_tests::get_info(640, 480, rs::format::rgba8)), // conversion_test_data(rs::stream::infrared, image_conversions_tests::get_info(640, 480, rs::format::y8 ), image_conversions_tests::get_info(640, 480, rs::format::bgra8)), - conversion_test_data(rs::stream::infrared, image_conversions_tests::get_info(640, 480, rs::format::y16 ), image_conversions_tests::get_info(640, 480, rs::format::bgr8)), - conversion_test_data(rs::stream::infrared, image_conversions_tests::get_info(628, 468, rs::format::y16 ), image_conversions_tests::get_info(640, 480, rs::format::rgb8)), - conversion_test_data(rs::stream::infrared, image_conversions_tests::get_info(480, 360, rs::format::y16 ), image_conversions_tests::get_info(640, 480, rs::format::rgba8)), - conversion_test_data(rs::stream::infrared, image_conversions_tests::get_info(320, 240, rs::format::y16 ), image_conversions_tests::get_info(640, 480, rs::format::bgra8)), - - conversion_test_data(rs::stream::depth, image_conversions_tests::get_info(320, 240, rs::format::z16 ), image_conversions_tests::get_info(640, 480, rs::format::bgr8)), - conversion_test_data(rs::stream::depth, image_conversions_tests::get_info(628, 468, rs::format::z16 ), image_conversions_tests::get_info(640, 480, rs::format::rgb8)), - conversion_test_data(rs::stream::depth, image_conversions_tests::get_info(640, 480, rs::format::z16 ), image_conversions_tests::get_info(640, 480, rs::format::rgba8)), - conversion_test_data(rs::stream::depth, image_conversions_tests::get_info(480, 360, rs::format::z16 ), image_conversions_tests::get_info(640, 480, rs::format::bgra8)), - - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::bgr8 ), image_conversions_tests::get_info(640, 480, rs::format::y8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::bgr8 ), image_conversions_tests::get_info(640, 480, rs::format::rgb8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::bgr8 ), image_conversions_tests::get_info(640, 480, rs::format::rgba8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::bgr8 ), image_conversions_tests::get_info(640, 480, rs::format::bgra8)), - - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::rgb8 ), image_conversions_tests::get_info(640, 480, rs::format::y8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::rgb8 ), image_conversions_tests::get_info(640, 480, rs::format::bgr8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::rgb8 ), image_conversions_tests::get_info(640, 480, rs::format::rgba8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::rgb8 ), image_conversions_tests::get_info(640, 480, rs::format::bgra8)), - - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::rgba8 ), image_conversions_tests::get_info(640, 480, rs::format::y8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::rgba8 ), image_conversions_tests::get_info(640, 480, rs::format::bgr8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::rgba8 ), image_conversions_tests::get_info(640, 480, rs::format::rgb8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::rgba8 ), image_conversions_tests::get_info(640, 480, rs::format::bgra8)), - - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::bgra8 ), image_conversions_tests::get_info(640, 480, rs::format::y8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::bgra8 ), image_conversions_tests::get_info(640, 480, rs::format::bgr8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::bgra8 ), image_conversions_tests::get_info(640, 480, rs::format::rgb8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::bgra8 ), image_conversions_tests::get_info(640, 480, rs::format::rgba8)), - - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::yuyv ), image_conversions_tests::get_info(640, 480, rs::format::y8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::yuyv ), image_conversions_tests::get_info(640, 480, rs::format::bgr8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::yuyv ), image_conversions_tests::get_info(640, 480, rs::format::rgb8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::yuyv ), image_conversions_tests::get_info(640, 480, rs::format::rgba8)), - conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::yuyv ), image_conversions_tests::get_info(640, 480, rs::format::bgra8)) - )); + conversion_test_data(rs::stream::infrared, image_conversions_tests::get_info(640, 480, rs::format::y16 ), image_conversions_tests::get_info(640, 480, rs::format::bgr8)), + conversion_test_data(rs::stream::infrared, image_conversions_tests::get_info(628, 468, rs::format::y16 ), image_conversions_tests::get_info(640, 480, rs::format::rgb8)), + conversion_test_data(rs::stream::infrared, image_conversions_tests::get_info(480, 360, rs::format::y16 ), image_conversions_tests::get_info(640, 480, rs::format::rgba8)), + conversion_test_data(rs::stream::infrared, image_conversions_tests::get_info(320, 240, rs::format::y16 ), image_conversions_tests::get_info(640, 480, rs::format::bgra8)), + + conversion_test_data(rs::stream::depth, image_conversions_tests::get_info(320, 240, rs::format::z16 ), image_conversions_tests::get_info(640, 480, rs::format::bgr8)), + conversion_test_data(rs::stream::depth, image_conversions_tests::get_info(628, 468, rs::format::z16 ), image_conversions_tests::get_info(640, 480, rs::format::rgb8)), + conversion_test_data(rs::stream::depth, image_conversions_tests::get_info(640, 480, rs::format::z16 ), image_conversions_tests::get_info(640, 480, rs::format::rgba8)), + conversion_test_data(rs::stream::depth, image_conversions_tests::get_info(480, 360, rs::format::z16 ), image_conversions_tests::get_info(640, 480, rs::format::bgra8)), + + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::bgr8 ), image_conversions_tests::get_info(640, 480, rs::format::y8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::bgr8 ), image_conversions_tests::get_info(640, 480, rs::format::rgb8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::bgr8 ), image_conversions_tests::get_info(640, 480, rs::format::rgba8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::bgr8 ), image_conversions_tests::get_info(640, 480, rs::format::bgra8)), + + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::rgb8 ), image_conversions_tests::get_info(640, 480, rs::format::y8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::rgb8 ), image_conversions_tests::get_info(640, 480, rs::format::bgr8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::rgb8 ), image_conversions_tests::get_info(640, 480, rs::format::rgba8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::rgb8 ), image_conversions_tests::get_info(640, 480, rs::format::bgra8)), + + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::rgba8 ), image_conversions_tests::get_info(640, 480, rs::format::y8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::rgba8 ), image_conversions_tests::get_info(640, 480, rs::format::bgr8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::rgba8 ), image_conversions_tests::get_info(640, 480, rs::format::rgb8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::rgba8 ), image_conversions_tests::get_info(640, 480, rs::format::bgra8)), + + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::bgra8 ), image_conversions_tests::get_info(640, 480, rs::format::y8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::bgra8 ), image_conversions_tests::get_info(640, 480, rs::format::bgr8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::bgra8 ), image_conversions_tests::get_info(640, 480, rs::format::rgb8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::bgra8 ), image_conversions_tests::get_info(640, 480, rs::format::rgba8)), + + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::yuyv ), image_conversions_tests::get_info(640, 480, rs::format::y8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::yuyv ), image_conversions_tests::get_info(640, 480, rs::format::bgr8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::yuyv ), image_conversions_tests::get_info(640, 480, rs::format::rgb8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(640, 480, rs::format::yuyv ), image_conversions_tests::get_info(640, 480, rs::format::rgba8)), + conversion_test_data(rs::stream::color, image_conversions_tests::get_info(1920, 1080, rs::format::yuyv ), image_conversions_tests::get_info(640, 480, rs::format::bgra8)) + )); diff --git a/sdk/test/librealsense_conversion_tests.cpp b/tests/librealsense_conversion_tests.cpp similarity index 81% rename from sdk/test/librealsense_conversion_tests.cpp rename to tests/librealsense_conversion_tests.cpp index 5ecce25..34c8180 100644 --- a/sdk/test/librealsense_conversion_tests.cpp +++ b/tests/librealsense_conversion_tests.cpp @@ -54,3 +54,24 @@ GTEST_TEST(librealsense_types_conversion, stream_conversions) ASSERT_EQ(convert_stream_type(rs::stream::depth_aligned_to_rectified_color), stream_type::depth_aligned_to_rectified_color); ASSERT_EQ(convert_stream_type(rs::stream::depth_aligned_to_infrared2), stream_type::depth_aligned_to_infrared2); } + + +GTEST_TEST(librealsense_types_conversion, convert_motion_intrinsics) +{ + //assert that librealsense motion intrinsics\extrinsics struct is in the same size as the sdk librealsense motion intrinsics\extrinsics structs + ASSERT_EQ(sizeof(rs::motion_intrinsics), sizeof(rs::core::motion_intrinsics)); + ASSERT_EQ(sizeof(rs::extrinsics), sizeof(rs::core::extrinsics)); + + rs::motion_intrinsics lrs_motion_intrinsics; + lrs_motion_intrinsics.acc.bias[1] = 0.1f; + lrs_motion_intrinsics.acc.scale[0] = 0.2f; + lrs_motion_intrinsics.gyro.bias[1] = 0.3f; + lrs_motion_intrinsics.gyro.scale[0] = 0.4f; + + rs::core::motion_intrinsics sdk_motion_intrinsics = convert_motion_intrinsics(lrs_motion_intrinsics); + + ASSERT_EQ(0.1f, sdk_motion_intrinsics.acc.bias[1]); + ASSERT_EQ(0.2f, sdk_motion_intrinsics.acc.scale[0]); + ASSERT_EQ(0.3f, sdk_motion_intrinsics.gyro.bias[1]); + ASSERT_EQ(0.4f, sdk_motion_intrinsics.gyro.scale[0]); +} diff --git a/sdk/test/main.cpp b/tests/main.cpp similarity index 100% rename from sdk/test/main.cpp rename to tests/main.cpp diff --git a/sdk/test/playback_device_tests.cpp b/tests/playback_device_tests.cpp similarity index 81% rename from sdk/test/playback_device_tests.cpp rename to tests/playback_device_tests.cpp index 7b6f746..a3e6a47 100644 --- a/sdk/test/playback_device_tests.cpp +++ b/tests/playback_device_tests.cpp @@ -3,8 +3,10 @@ #include #include +#include +#include + #include "gtest/gtest.h" -#include "utilities/utilities.h" #include "rs/playback/playback_device.h" #include "rs/playback/playback_context.h" #include "rs/record/record_context.h" @@ -12,6 +14,8 @@ #include "file_types.h" #include "rs/utils/librealsense_conversion_utils.h" #include "image/image_utils.h" +#include "viewer/viewer.h" +#include "utilities/utilities.h" using namespace std; using namespace rs::core; @@ -31,6 +35,8 @@ namespace setup static const std::string file_callbacks = "/tmp/rstest_callbacks.rssdk"; static std::vector supported_options; + static std::map motion_extrinsics; + static rs::motion_intrinsics motion_intrinsics; static std::map profiles; static rs::core::device_info dinfo; } @@ -55,18 +61,6 @@ namespace playback_tests_util } return stream_count; } - static void enable_streams(rs::device* device, const std::map& profiles) - { - for(auto it = profiles.begin(); it != profiles.end(); ++it) - { - auto stream = it->first; - int width, height, fps; - rs::format format; - device->get_stream_mode(stream, 0, width, height, format, fps); - device->enable_stream(stream, width, height, format, fps); - EXPECT_TRUE(device->is_stream_enabled(stream)); - } - } static void record_callback_no_motion(rs::device* device) { @@ -105,8 +99,11 @@ namespace playback_tests_util { rs::stream stream = it->first; device->set_frame_callback(stream, [stream,&frame_count](rs::frame entry) {frame_count[stream]++;}); + setup::motion_extrinsics[stream] = device->get_motion_extrinsics_from(stream); } + setup::motion_intrinsics = device->get_motion_intrinsics(); + device->start(rs::source::all_sources); ASSERT_TRUE(device->is_motion_tracking_active()); @@ -148,6 +145,14 @@ namespace playback_tests_util device->enable_motion_tracking(motion_callback, timestamp_callback); int frames = setup::frames; + for(auto it = setup::profiles.begin(); it != setup::profiles.end(); ++it) + { + rs::stream stream = it->first; + setup::motion_extrinsics[stream] = device->get_motion_extrinsics_from(stream); + } + + setup::motion_intrinsics = device->get_motion_intrinsics(); + device->start(rs::source::all_sources); ASSERT_TRUE(device->is_motion_tracking_active()); @@ -163,7 +168,7 @@ namespace playback_tests_util static void record_wait_for_frames_no_motion(std::string file_path) { //create a record enabled context with a given output file - rs::record::context context(file_path); + rs::record::context context(file_path.c_str()); ASSERT_NE(0, context.get_device_count()) << "no device detected"; //each device created from the record enabled context will write the streaming data to the given file @@ -189,6 +194,7 @@ namespace playback_tests_util stream_profile sp = it->second; device->enable_stream(stream, sp.info.width, sp.info.height, (rs::format)sp.info.format, sp.frame_rate); } + if(file_path == setup::file_wait_for_frames) { if(device->supports(rs::capabilities::motion_events)) @@ -227,7 +233,7 @@ class playback_streaming_fixture : public testing::TestWithParam virtual void SetUp() { //create a playback context with a given input file - context = std::unique_ptr(new rs::playback::context(GetParam())); + context = std::unique_ptr(new rs::playback::context(GetParam().c_str())); //create a playback device device = context->get_playback_device(); @@ -252,8 +258,7 @@ TEST_P(playback_streaming_fixture, get_firmware_version) TEST_P(playback_streaming_fixture, get_extrinsics) { - device->enable_stream(rs::stream::color, rs::preset::best_quality); - device->enable_stream(rs::stream::depth, rs::preset::best_quality); + auto stream_count = playback_tests_util::enable_available_streams(device); auto ext1 = device->get_extrinsics(rs::stream::color, rs::stream::depth); auto ext2 = device->get_extrinsics(rs::stream::depth, rs::stream::color); EXPECT_GT(ext1.translation[0], 0); @@ -261,6 +266,37 @@ TEST_P(playback_streaming_fixture, get_extrinsics) EXPECT_NEAR(ext1.translation[0], -ext2.translation[0], 0.001); } +TEST_P(playback_streaming_fixture, get_motion_extrinsics_from) +{ + auto stream_count = playback_tests_util::enable_available_streams(device); + for(auto it = setup::motion_extrinsics.begin(); it != setup::motion_extrinsics.end(); ++it) + { + rs::stream stream = it->first; + rs::extrinsics ext = device->get_motion_extrinsics_from(stream); + for(int i = 0; i < 9; i++) + { + EXPECT_EQ(setup::motion_extrinsics[stream].rotation[i], ext.rotation[i]); + } + for(int i = 0; i < 3; i++) + { + EXPECT_EQ(setup::motion_extrinsics[stream].translation[i], ext.translation[i]); + } + } +} + +TEST_P(playback_streaming_fixture, get_motion_intrinsics) +{ + auto stream_count = playback_tests_util::enable_available_streams(device); + rs::motion_intrinsics motion_intrinsics = device->get_motion_intrinsics(); + for(int i = 0; i < 3; i++) + { + EXPECT_NEAR(setup::motion_intrinsics.acc.bias[i], motion_intrinsics.acc.bias[i], 0.0001); + EXPECT_NEAR(setup::motion_intrinsics.gyro.bias[i], motion_intrinsics.gyro.bias[i], 0.0001); + EXPECT_NEAR(setup::motion_intrinsics.acc.scale[i], motion_intrinsics.acc.scale[i], 0.0001); + EXPECT_NEAR(setup::motion_intrinsics.gyro.scale[i], motion_intrinsics.gyro.scale[i], 0.0001); + } +} + TEST_P(playback_streaming_fixture, get_depth_scale) { EXPECT_NEAR(0.001, device->get_depth_scale(), 1e-6); @@ -300,12 +336,12 @@ TEST_P(playback_streaming_fixture, get_stream_mode) TEST_P(playback_streaming_fixture, enable_stream) { - playback_tests_util::enable_streams(device, setup::profiles); + auto stream_count = playback_tests_util::enable_available_streams(device); } TEST_P(playback_streaming_fixture, disable_stream) { - playback_tests_util::enable_streams(device, setup::profiles); + auto stream_count = playback_tests_util::enable_available_streams(device); for(auto it = setup::profiles.begin(); it != setup::profiles.end(); ++it) { auto stream = it->first; @@ -316,7 +352,7 @@ TEST_P(playback_streaming_fixture, disable_stream) TEST_P(playback_streaming_fixture, get_stream_width) { - playback_tests_util::enable_streams(device, setup::profiles); + auto stream_count = playback_tests_util::enable_available_streams(device); for(auto it = setup::profiles.begin(); it != setup::profiles.end(); ++it) { auto stream = it->first; @@ -327,7 +363,7 @@ TEST_P(playback_streaming_fixture, get_stream_width) TEST_P(playback_streaming_fixture, get_stream_height) { - playback_tests_util::enable_streams(device, setup::profiles); + auto stream_count = playback_tests_util::enable_available_streams(device); for(auto it = setup::profiles.begin(); it != setup::profiles.end(); ++it) { auto stream = it->first; @@ -338,7 +374,7 @@ TEST_P(playback_streaming_fixture, get_stream_height) TEST_P(playback_streaming_fixture, get_stream_format) { - playback_tests_util::enable_streams(device, setup::profiles); + auto stream_count = playback_tests_util::enable_available_streams(device); for(auto it = setup::profiles.begin(); it != setup::profiles.end(); ++it) { auto stream = it->first; @@ -349,7 +385,7 @@ TEST_P(playback_streaming_fixture, get_stream_format) TEST_P(playback_streaming_fixture, start_stop_stress) { - playback_tests_util::enable_streams(device, setup::profiles); + auto stream_count = playback_tests_util::enable_available_streams(device); for(int i = 0; i < 100; i++) { device->start(); @@ -371,13 +407,13 @@ TEST_P(playback_streaming_fixture, start_stop_stress) TEST_P(playback_streaming_fixture, stop) { - playback_tests_util::enable_streams(device, setup::profiles); + auto stream_count = playback_tests_util::enable_available_streams(device); auto it = setup::profiles.begin(); ASSERT_NE(it, setup::profiles.end()); rs::stream stream = it->first; device->start(); EXPECT_TRUE(device->is_streaming()); - std::this_thread::sleep_for (std::chrono::milliseconds(800)); + std::this_thread::sleep_for (std::chrono::milliseconds(1000)); device->wait_for_frames(); auto first = device->get_frame_index(stream); device->stop(); @@ -393,7 +429,7 @@ TEST_P(playback_streaming_fixture, stop) TEST_P(playback_streaming_fixture, is_streaming) { - playback_tests_util::enable_streams(device, setup::profiles); + auto stream_count = playback_tests_util::enable_available_streams(device); device->start(); EXPECT_TRUE(device->is_streaming()); device->stop(); @@ -409,7 +445,7 @@ TEST_P(playback_streaming_fixture, is_streaming) TEST_P(playback_streaming_fixture, poll_for_frames) { - playback_tests_util::enable_streams(device, setup::profiles); + auto stream_count = playback_tests_util::enable_available_streams(device); auto it = setup::profiles.begin(); ASSERT_NE(it, setup::profiles.end()); rs::stream stream = it->first; @@ -428,7 +464,7 @@ TEST_P(playback_streaming_fixture, poll_for_frames) TEST_P(playback_streaming_fixture, get_frame_timestamp) { - playback_tests_util::enable_streams(device, setup::profiles); + auto stream_count = playback_tests_util::enable_available_streams(device); auto expected_fps = 0; rs::stream stream = rs::stream::color; for(auto it = setup::profiles.begin(); it != setup::profiles.end(); ++it) @@ -455,7 +491,7 @@ TEST_P(playback_streaming_fixture, get_frame_timestamp) TEST_P(playback_streaming_fixture, get_frame_data) { - playback_tests_util::enable_streams(device, setup::profiles); + auto stream_count = playback_tests_util::enable_available_streams(device); for(auto it = setup::profiles.begin(); it != setup::profiles.end(); ++it) { auto stream = it->first; @@ -474,12 +510,12 @@ TEST_P(playback_streaming_fixture, is_real_time) TEST_P(playback_streaming_fixture, non_real_time_playback) { - playback_tests_util::enable_streams(device, setup::profiles); + auto stream_count = playback_tests_util::enable_available_streams(device); device->set_real_time(false); EXPECT_FALSE(device->is_real_time()); auto it = setup::profiles.begin(); - int prev = 0; + unsigned long long prev = 0; device->start(); for(int i = 0; i < 10; i++) { @@ -497,9 +533,9 @@ TEST_P(playback_streaming_fixture, non_real_time_playback) TEST_P(playback_streaming_fixture, pause) { - auto it = setup::profiles.begin(); - ASSERT_NE(it, setup::profiles.end()); - rs::stream stream = it->first; + auto stream_count = playback_tests_util::enable_available_streams(device); + ASSERT_NE(0, stream_count); + rs::stream stream = rs::stream::color; device->enable_stream(stream, rs::preset::best_quality); device->start(); std::this_thread::sleep_for (std::chrono::milliseconds(300)); @@ -515,10 +551,9 @@ TEST_P(playback_streaming_fixture, pause) TEST_P(playback_streaming_fixture, resume) { - playback_tests_util::enable_streams(device, setup::profiles); - auto it = setup::profiles.begin(); - ASSERT_NE(it, setup::profiles.end()); - rs::stream stream = it->first; + auto stream_count = playback_tests_util::enable_available_streams(device); + ASSERT_NE(0, stream_count); + rs::stream stream = rs::stream::color; device->start(); std::this_thread::sleep_for (std::chrono::milliseconds(200)); device->wait_for_frames(); @@ -533,10 +568,9 @@ TEST_P(playback_streaming_fixture, resume) TEST_P(playback_streaming_fixture, set_frame_by_index) { - playback_tests_util::enable_streams(device, setup::profiles); - auto it = setup::profiles.begin(); - ASSERT_NE(it, setup::profiles.end()); - rs::stream stream = it->first; + auto stream_count = playback_tests_util::enable_available_streams(device); + ASSERT_NE(0, stream_count); + rs::stream stream = rs::stream::color; auto index = device->get_frame_count() - 1; device->set_frame_by_index(index, stream); EXPECT_EQ(index, device->get_frame_index(stream)); @@ -544,10 +578,9 @@ TEST_P(playback_streaming_fixture, set_frame_by_index) TEST_P(playback_streaming_fixture, DISABLED_set_frame_by_timestamp) { - playback_tests_util::enable_streams(device, setup::profiles); - auto it = setup::profiles.begin(); - ASSERT_NE(it, setup::profiles.end()); - rs::stream stream = it->first; + auto stream_count = playback_tests_util::enable_available_streams(device); + ASSERT_NE(0, stream_count); + rs::stream stream = rs::stream::color; auto first_index = 100; device->set_frame_by_index(first_index, stream); auto ts1 = device->get_frame_timestamp(stream); @@ -558,7 +591,7 @@ TEST_P(playback_streaming_fixture, DISABLED_set_frame_by_timestamp) TEST_P(playback_streaming_fixture, set_real_time) { - playback_tests_util::enable_streams(device, setup::profiles); + auto stream_count = playback_tests_util::enable_available_streams(device); auto t1 = std::chrono::system_clock::now(); device->set_real_time(true); device->start(); @@ -583,10 +616,9 @@ TEST_P(playback_streaming_fixture, set_real_time) TEST_P(playback_streaming_fixture, get_frame_index) { - playback_tests_util::enable_streams(device, setup::profiles); - auto it = setup::profiles.begin(); - ASSERT_NE(it, setup::profiles.end()); - rs::stream stream = it->first; + auto stream_count = playback_tests_util::enable_available_streams(device); + ASSERT_NE(0, stream_count); + rs::stream stream = rs::stream::color; auto index = device->get_frame_count() - 1; device->set_frame_by_index(index, stream); EXPECT_EQ(index, device->get_frame_index(stream)); @@ -627,58 +659,32 @@ TEST_P(playback_streaming_fixture, playback_set_frames) { auto stream_count = playback_tests_util::enable_available_streams(device); - std::map windows; - for(int32_t s = (int32_t)rs::stream::depth; s <= (int32_t)rs::stream::infrared2; ++s) - { - auto stream = (rs::stream)s; - if(device->is_stream_enabled(stream)) - { - glfwInit(); - windows[stream] = (glfwCreateWindow(device->get_stream_width(stream), device->get_stream_height(stream), "basic playback test", nullptr, nullptr)); - } - } + std::shared_ptr viewer = std::make_shared(device, 320); auto frame_count = device->get_frame_count(); int counter = 0; while(counter< frame_count) { - device->set_frame_by_index(counter++, rs::stream::color); + device->set_frame_by_index(counter++, rs::stream::depth); for(int32_t s = (int32_t)rs::stream::depth; s <= (int32_t)rs::stream::infrared2; ++s) { auto stream = (rs::stream)s; if(device->is_stream_enabled(stream)) { - glfwMakeContextCurrent(windows.at(stream)); - glutils::gl_render(windows.at(stream), device, (rs::stream)s); + if(device->get_frame_data(stream) == nullptr)continue; + auto image = test_utils::create_image(device, stream); + viewer->show_image(image); } } //std::this_thread::sleep_for (std::chrono::milliseconds(33)); } - - for(int32_t s = (int32_t)rs::stream::depth; s <= (int32_t)rs::stream::infrared2; ++s) - { - auto stream = (rs::stream)s; - if(device->is_stream_enabled(stream)) - { - glutils::gl_close(windows.at(stream)); - } - } } TEST_P(playback_streaming_fixture, basic_playback) { auto stream_count = playback_tests_util::enable_available_streams(device); - std::map windows; - for(int32_t s = (int32_t)rs::stream::depth; s <= (int32_t)rs::stream::infrared2; ++s) - { - auto stream = (rs::stream)s; - if(device->is_stream_enabled(stream)) - { - glfwInit(); - windows[stream] = (glfwCreateWindow(device->get_stream_width(stream), device->get_stream_height(stream), "basic playback test", nullptr, nullptr)); - } - } + std::shared_ptr viewer = std::make_shared(device, 320, "basic_playback"); device->start(); auto counter = 0; @@ -690,21 +696,12 @@ TEST_P(playback_streaming_fixture, basic_playback) auto stream = (rs::stream)s; if(device->is_stream_enabled(stream)) { - glfwMakeContextCurrent(windows.at(stream)); - glutils::gl_render(windows.at(stream), device, (rs::stream)s); + auto image = test_utils::create_image(device, stream); + viewer->show_image(image); } } counter++; } - - for(int32_t s = (int32_t)rs::stream::depth; s <= (int32_t)rs::stream::infrared2; ++s) - { - auto stream = (rs::stream)s; - if(device->is_stream_enabled(stream)) - { - glutils::gl_close(windows.at(stream)); - } - } } TEST_P(playback_streaming_fixture, motions_callback) @@ -773,23 +770,14 @@ TEST_P(playback_streaming_fixture, frames_callback) TEST_P(playback_streaming_fixture, playback_and_render_callbak) { auto stream_count = playback_tests_util::enable_available_streams(device); - std::map windows; - for(auto it = setup::profiles.begin(); it != setup::profiles.end(); ++it) - { - auto stream = it->first; - if(device->is_stream_enabled(stream)) - { - glfwInit(); - windows[stream] = (glfwCreateWindow(device->get_stream_width(stream), device->get_stream_height(stream), "basic record test", nullptr, nullptr)); - } - } + + std::shared_ptr viewer = std::make_shared(device, 320, "playback_and_render_callbak"); std::map frame_counter; - auto callback = [&frame_counter, windows](rs::frame f) + auto callback = [&frame_counter, viewer](rs::frame f) { auto stream = f.get_stream_type(); - glfwMakeContextCurrent(windows.at(stream)); - glutils::gl_render(windows.at(stream), f); + viewer->show_frame(std::move(f)); frame_counter[stream]++; }; @@ -803,15 +791,6 @@ TEST_P(playback_streaming_fixture, playback_and_render_callbak) while(device->is_streaming()) std::this_thread::sleep_for(std::chrono::seconds(1)); device->stop(); - - for(auto it = setup::profiles.begin(); it != setup::profiles.end(); ++it) - { - auto stream = it->first; - if(device->is_stream_enabled(stream)) - { - glutils::gl_close(windows.at(stream)); - } - } } INSTANTIATE_TEST_CASE_P(playback_tests, playback_streaming_fixture, ::testing::Values( diff --git a/sdk/test/projection_fixture.h b/tests/projection_fixture.h similarity index 97% rename from sdk/test/projection_fixture.h rename to tests/projection_fixture.h index 87f4415..1994faa 100644 --- a/sdk/test/projection_fixture.h +++ b/tests/projection_fixture.h @@ -7,6 +7,7 @@ #include #include #include +#include /* gtest */ #include "gtest/gtest.h" @@ -49,7 +50,7 @@ class projection_fixture : public testing::Test static void SetUpTestCase() { //create a record enabled context with a given output file - rs::record::context m_context(projection_tests_util::file_name); + rs::record::context m_context(projection_tests_util::file_name.c_str()); ASSERT_NE(0, m_context.get_device_count()) << "no device detected"; @@ -70,7 +71,7 @@ class projection_fixture : public testing::Test virtual void SetUp() { //create a playback context with a given input file - m_context = std::unique_ptr(new rs::playback::context(projection_tests_util::file_name)); + m_context = std::unique_ptr(new rs::playback::context(projection_tests_util::file_name.c_str())); //create a playback device m_device = m_context->get_playback_device(); diff --git a/sdk/test/projection_tests.cpp b/tests/projection_tests.cpp similarity index 94% rename from sdk/test/projection_tests.cpp rename to tests/projection_tests.cpp index 0c35bb3..107e0ed 100644 --- a/sdk/test/projection_tests.cpp +++ b/tests/projection_tests.cpp @@ -7,7 +7,6 @@ #include #include #include "rs/utils/librealsense_conversion_utils.h" -#include "rs/core/custom_image.h" #include "image/librealsense_image_utils.h" using namespace rs::core; @@ -377,24 +376,24 @@ TEST_F(projection_fixture, map_depth_to_color_to_depth) int depthPitch = depthWidth * image_utils::get_pixel_size(m_device->get_stream_format(rs::stream::depth)); image_info DepthInfo = {depthWidth, depthHeight, convert_pixel_format(projection_tests_util::depth_format), depthPitch}; - custom_image depth (&DepthInfo, + std::unique_ptr depth (image_interface::create_instance_from_raw_data(&DepthInfo, m_device->get_frame_data(rs::stream::depth), stream_type::depth, image_interface::flag::any, m_device->get_frame_timestamp(rs::stream::depth), m_device->get_frame_number(rs::stream::depth), nullptr, - nullptr); + nullptr)); /* Retrieve the depth pixels */ - const uint8_t * ddata = (uint8_t*)depth.query_data(); + const uint8_t * ddata = (uint8_t*)depth->query_data(); ASSERT_FALSE(!ddata); std::vector pos_ijSrc; int32_t npoints = 0; for (int32_t y = 0; y < m_color_intrin.height; y++) { - uint16_t *d = (uint16_t*)(ddata + y * depth.query_info().pitch); + uint16_t *d = (uint16_t*)(ddata + y * depth->query_info().pitch); for (int32_t x = 0; x < m_color_intrin.width; x++) { if (d[x] == invalid_value || d[x] > MAX_DISTANCE) continue; // no mapping based on unreliable depth values @@ -419,7 +418,7 @@ TEST_F(projection_fixture, map_depth_to_color_to_depth) m_log_util.m_logger->logw(logging_service::LEVEL_ERROR, L"Unable to MapDepthToColor", __FILE__, __LINE__, "map_depth_to_color_to_depth"); ASSERT_EQ(m_sts, status_no_error); } - m_sts = m_projection->map_color_to_depth(&depth, npoints, &pos_ijDst1[0], &pos_ijDst2[0]); + m_sts = m_projection->map_color_to_depth(depth.get(), npoints, &pos_ijDst1[0], &pos_ijDst2[0]); if( m_sts == status_param_unsupported ) { skipped = true; @@ -501,23 +500,23 @@ TEST_F(projection_fixture, map_depth_camera_color) int depthPitch = m_depth_intrin.width * image_utils::get_pixel_size(projection_tests_util::depth_format); image_info DepthInfo = {m_depth_intrin.width, m_depth_intrin.height, convert_pixel_format(projection_tests_util::depth_format), depthPitch}; - custom_image depth (&DepthInfo, + std::unique_ptr depth (image_interface::create_instance_from_raw_data(&DepthInfo, m_device->get_frame_data(rs::stream::depth), stream_type::depth, image_interface::flag::any, m_device->get_frame_timestamp(rs::stream::depth), m_device->get_frame_number(rs::stream::depth), nullptr, - nullptr); + nullptr)); /* Retrieve the depth pixels */ - const uint8_t * ddata = (uint8_t*)depth.query_data(); + const uint8_t * ddata = (uint8_t*)depth->query_data(); ASSERT_FALSE(!ddata); std::vector pos_ijSrc; for (int32_t y = 0; y < m_color_intrin.height; y++) { - uint16_t *d = (uint16_t*)(ddata + y * depth.query_info().pitch); + uint16_t *d = (uint16_t*)(ddata + y * depth->query_info().pitch); for (int32_t x = 0; x < m_color_intrin.width; x++) { if (d[x] == invalid_value || d[x] > MAX_DISTANCE) continue; // no mapping based on unreliable depth values @@ -631,17 +630,17 @@ TEST_F(projection_fixture, map_color_camera_depth) int depthPitch = m_depth_intrin.width * image_utils::get_pixel_size(projection_tests_util::depth_format); image_info DepthInfo = {m_depth_intrin.width, m_depth_intrin.height, convert_pixel_format(projection_tests_util::depth_format), depthPitch}; - custom_image depth (&DepthInfo, + std::unique_ptr depth (image_interface::create_instance_from_raw_data(&DepthInfo, m_device->get_frame_data(rs::stream::depth), stream_type::depth, image_interface::flag::any, m_device->get_frame_timestamp(rs::stream::depth), m_device->get_frame_number(rs::stream::depth), nullptr, - nullptr); + nullptr)); /* Retrieve the depth pixels */ - const uint8_t * ddata = (uint8_t*)depth.query_data(); + const uint8_t * ddata = (uint8_t*)depth->query_data(); ASSERT_FALSE(!ddata); @@ -649,7 +648,7 @@ TEST_F(projection_fixture, map_color_camera_depth) std::vector pos_ijSrc; for (int32_t y = 0; y < m_color_intrin.height; y++) { - uint16_t *d = (uint16_t*)(ddata + y * depth.query_info().pitch); + uint16_t *d = (uint16_t*)(ddata + y * depth->query_info().pitch); for (int32_t x = 0; x < m_color_intrin.width; x++) { if (d[x] == invalid_value || d[x] > MAX_DISTANCE) continue; // no mapping based on unreliable depth values @@ -691,7 +690,7 @@ TEST_F(projection_fixture, map_color_camera_depth) // Maps and projects back Color points to Depth std::vector pos_ijDst1(npoints); - m_sts = m_projection->map_color_to_depth(&depth, npoints, &pos_ijSrc2[0], &pos_ijDst1[0]); + m_sts = m_projection->map_color_to_depth(depth.get(), npoints, &pos_ijSrc2[0], &pos_ijDst1[0]); if( m_sts == status_param_unsupported ) { skipped = true; @@ -796,18 +795,18 @@ TEST_F(projection_fixture, query_uvmap_map_depth_to_color) int depthPitch = m_depth_intrin.width * image_utils::get_pixel_size(projection_tests_util::depth_format); image_info DepthInfo = {m_depth_intrin.width, m_depth_intrin.height, convert_pixel_format(projection_tests_util::depth_format), depthPitch}; - custom_image depth (&DepthInfo, + std::unique_ptr depth (image_interface::create_instance_from_raw_data(&DepthInfo, m_device->get_frame_data(rs::stream::depth), stream_type::depth, image_interface::flag::any, m_device->get_frame_timestamp(rs::stream::depth), m_device->get_frame_number(rs::stream::depth), nullptr, - nullptr); - const uint8_t * ddata = (uint8_t*)depth.query_data(); + nullptr)); + const uint8_t * ddata = (uint8_t*)depth->query_data(); /* Get uvMap */ - m_sts = m_projection->query_uvmap(&depth, uvMap.data()); + m_sts = m_projection->query_uvmap(depth.get(), uvMap.data()); if(m_sts == status_feature_unsupported) { skipped = true; @@ -824,7 +823,7 @@ TEST_F(projection_fixture, query_uvmap_map_depth_to_color) int32_t npoints = 0; for (int32_t y = 0; y < m_depth_intrin.height; y++) { - uint16_t *d = (uint16_t*)(ddata + y*depth.query_info().pitch); + uint16_t *d = (uint16_t*)(ddata + y*depth->query_info().pitch); for (int32_t x = 0; x < m_depth_intrin.width; x++) { if (d[x] == invalid_value || d[x] > MAX_DISTANCE) continue; // no mapping based on unreliable depth values @@ -921,17 +920,17 @@ TEST_F(projection_fixture, query_invuvmap_map_color_to_depth) int depthPitch = m_depth_intrin.width * image_utils::get_pixel_size(m_device->get_stream_format(rs::stream::depth)); image_info DepthInfo = {m_depth_intrin.width, m_depth_intrin.height, convert_pixel_format(projection_tests_util::depth_format), depthPitch}; - custom_image depth (&DepthInfo, + std::unique_ptr depth (image_interface::create_instance_from_raw_data(&DepthInfo, m_device->get_frame_data(rs::stream::depth), stream_type::depth, image_interface::flag::any, m_device->get_frame_timestamp(rs::stream::depth), m_device->get_frame_number(rs::stream::depth), nullptr, - nullptr); + nullptr)); /* Get Inversed UV Map */ - m_sts = m_projection->query_invuvmap(&depth, &invUvMap[0]); + m_sts = m_projection->query_invuvmap(depth.get(), &invUvMap[0]); if( m_sts == status_feature_unsupported ) { skipped = true; @@ -960,7 +959,7 @@ TEST_F(projection_fixture, query_invuvmap_map_color_to_depth) // Find a Color map of the choosen points std::vector pos_ijDst(npoints); - m_sts = m_projection->map_color_to_depth(&depth, npoints, pos_ijSrc.data(), pos_ijDst.data()); + m_sts = m_projection->map_color_to_depth(depth.get(), npoints, pos_ijSrc.data(), pos_ijDst.data()); if( m_sts == status_param_unsupported ) { skipped = true; @@ -1047,18 +1046,18 @@ TEST_F(projection_fixture, query_vertices_project_depth_to_camera) int depthPitch = m_depth_intrin.width * image_utils::get_pixel_size(projection_tests_util::depth_format); image_info DepthInfo = {m_depth_intrin.width, m_depth_intrin.height, convert_pixel_format(projection_tests_util::depth_format), depthPitch}; - custom_image depth (&DepthInfo, + std::unique_ptr depth (image_interface::create_instance_from_raw_data(&DepthInfo, m_device->get_frame_data(rs::stream::depth), stream_type::depth, image_interface::flag::any, m_device->get_frame_timestamp(rs::stream::depth), m_device->get_frame_number(rs::stream::depth), nullptr, - nullptr); - const uint8_t* ddata = (uint8_t*)depth.query_data(); + nullptr)); + const uint8_t* ddata = (uint8_t*)depth->query_data(); // Get QueryVertices - m_sts = m_projection->query_vertices(&depth, pos_ijDst1.data()); + m_sts = m_projection->query_vertices(depth.get(), pos_ijDst1.data()); if( m_sts == status_feature_unsupported ) { skipped = true; @@ -1073,7 +1072,7 @@ TEST_F(projection_fixture, query_vertices_project_depth_to_camera) std::vector pos_ijSrc; for (int32_t y = 0; y < m_depth_intrin.height; y++) { - uint16_t *d = (uint16_t*)(ddata + y*depth.query_info().pitch); + uint16_t *d = (uint16_t*)(ddata + y*depth->query_info().pitch); for (int32_t x = 0; x < m_depth_intrin.width; x++) { if (d[x] == invalid_value || d[x] > MAX_DISTANCE) continue; // no mapping based on unreliable depth values @@ -1164,17 +1163,17 @@ TEST_F(projection_fixture, query_uvmap_query_invuvmap) int depthPitch = m_depth_intrin.width * image_utils::get_pixel_size(projection_tests_util::depth_format); image_info DepthInfo = { m_depth_intrin.width, m_depth_intrin.height, convert_pixel_format(projection_tests_util::depth_format), depthPitch }; - custom_image depth (&DepthInfo, + std::unique_ptr depth (image_interface::create_instance_from_raw_data(&DepthInfo, m_device->get_frame_data(rs::stream::depth), stream_type::depth, image_interface::flag::any, m_device->get_frame_timestamp(rs::stream::depth), m_device->get_frame_number(rs::stream::depth), nullptr, - nullptr); + nullptr)); /* Get UV Map */ std::vector uvMap(m_depth_intrin.width * m_depth_intrin.height); - m_sts = m_projection->query_uvmap(&depth, uvMap.data()); + m_sts = m_projection->query_uvmap(depth.get(), uvMap.data()); if(m_sts == status_feature_unsupported) { skipped = true; @@ -1187,7 +1186,7 @@ TEST_F(projection_fixture, query_uvmap_query_invuvmap) /* Get Inverse UV Map */ std::vector invUvMap(m_color_intrin.width * m_color_intrin.height); - m_sts = m_projection->query_invuvmap(&depth, invUvMap.data()); + m_sts = m_projection->query_invuvmap(depth.get(), invUvMap.data()); if(m_sts == status_feature_unsupported) { skipped = true; @@ -1279,24 +1278,24 @@ TEST_F(projection_fixture, create_depth_image_mapped_to_color_query_invuvmap) const void* depthData = (void*)m_device->get_frame_data(rs::stream::depth); const void* colorData = (void*)m_device->get_frame_data(rs::stream::color); - custom_image depth(&depthInfo, + std::unique_ptr depth (image_interface::create_instance_from_raw_data(&depthInfo, depthData, stream_type::depth, image_interface::flag::any, m_device->get_frame_timestamp(rs::stream::depth), m_device->get_frame_number(rs::stream::depth), - nullptr, nullptr); - custom_image color(&colorInfo, + nullptr, nullptr)); + std::unique_ptr color(image_interface::create_instance_from_raw_data(&colorInfo, colorData, stream_type::color, image_interface::flag::any, m_device->get_frame_timestamp(rs::stream::color), m_device->get_frame_number(rs::stream::color), - nullptr, nullptr); + nullptr, nullptr)); /* Get Inverse UV Map */ std::vector invUvMap(colorInfo.width * colorInfo.height); - m_sts = m_projection->query_invuvmap(&depth, invUvMap.data()); + m_sts = m_projection->query_invuvmap(depth.get(), invUvMap.data()); if(m_sts == status_feature_unsupported) { skipped = true; @@ -1306,12 +1305,12 @@ TEST_F(projection_fixture, create_depth_image_mapped_to_color_query_invuvmap) ASSERT_EQ(m_sts, status_no_error); } - std::unique_ptr depth2color = std::unique_ptr(m_projection->create_depth_image_mapped_to_color(&depth, &color)); + std::unique_ptr depth2color = std::unique_ptr(m_projection->create_depth_image_mapped_to_color(depth.get(), color.get())); ASSERT_NE(depth2color.get(), nullptr); ASSERT_NE(depth2color->query_data(), nullptr); const uint8_t* depth2color_data = (const uint8_t*)depth2color->query_data(); image_info depth2colorInfo = depth2color->query_info(); - const uint8_t* depth_data = (const uint8_t*)depth.query_data(); + const uint8_t* depth_data = (const uint8_t*)depth->query_data(); for (int32_t y = 0; y < m_depth_intrin.height; y++) { @@ -1393,23 +1392,23 @@ TEST_F(projection_fixture, create_color_image_mapped_to_depth_query_uvmap) const void* depthData = m_device->get_frame_data(rs::stream::depth); const void* colorData = m_device->get_frame_data(rs::stream::color); - custom_image depth(&depthInfo, + std::unique_ptr depth(image_interface::create_instance_from_raw_data(&depthInfo, depthData, stream_type::depth, image_interface::flag::any, m_device->get_frame_timestamp(rs::stream::depth), m_device->get_frame_number(rs::stream::depth), - nullptr, nullptr); - custom_image color(&colorInfo, + nullptr, nullptr)); + std::unique_ptr color(image_interface::create_instance_from_raw_data(&colorInfo, colorData, stream_type::color, image_interface::flag::any, m_device->get_frame_timestamp(rs::stream::color), m_device->get_frame_number(rs::stream::color), - nullptr, nullptr); + nullptr, nullptr)); /* Get uvmap */ std::vector uvMap(depthInfo.width * depthInfo.height); - m_sts = m_projection->query_uvmap(&depth, uvMap.data()); + m_sts = m_projection->query_uvmap(depth.get(), uvMap.data()); if(m_sts == status_feature_unsupported) { skipped = true; @@ -1419,11 +1418,11 @@ TEST_F(projection_fixture, create_color_image_mapped_to_depth_query_uvmap) ASSERT_EQ(m_sts, status_no_error); } - std::unique_ptr color2depth = std::unique_ptr(m_projection->create_color_image_mapped_to_depth(&depth, &color)); + std::unique_ptr color2depth = std::unique_ptr(m_projection->create_color_image_mapped_to_depth(depth.get(), color.get())); ASSERT_NE(color2depth.get(), nullptr); ASSERT_NE(color2depth->query_data(), nullptr); const uint8_t* color2depth_data = (const uint8_t*)color2depth->query_data(); - const uint8_t* color_data = (const uint8_t*)color.query_data(); + const uint8_t* color_data = (const uint8_t*)color->query_data(); image_info color2depth_info = color2depth->query_info(); colorComponents = image_utils::get_pixel_size(color2depth_info.format); diff --git a/sdk/test/record_device_tests.cpp b/tests/record_device_tests.cpp similarity index 97% rename from sdk/test/record_device_tests.cpp rename to tests/record_device_tests.cpp index 55c3186..5d5b0e6 100644 --- a/sdk/test/record_device_tests.cpp +++ b/tests/record_device_tests.cpp @@ -47,7 +47,7 @@ class record_fixture : public testing::Test virtual void SetUp() { //create a record enabled context with a given output file - m_context = std::unique_ptr(new rs::record::context(setup::file_path)); + m_context = std::unique_ptr(new rs::record::context(setup::file_path.c_str())); ASSERT_NE(0, m_context->get_device_count()) << "no device detected"; @@ -237,14 +237,13 @@ TEST_F(record_fixture, record_and_render) m_device->enable_stream(stream, sp.info.width, sp.info.height, (rs::format)sp.info.format, sp.frame_rate); } - m_viewer = std::make_shared(m_device, 320); + m_viewer = std::make_shared(m_device, 320, "record_and_render"); std::map frame_counter; int run_time = 3; // Set callbacks prior to calling start() - auto callback = [&frame_counter, this](rs::frame f) + auto callback = [&frame_counter, this](rs::frame frame) { - auto frame = f.clone_ref(); + frame_counter[frame.get_stream_type()]++; m_viewer->show_frame(std::move(frame)); - frame_counter[f.get_stream_type()]++; }; m_device->set_frame_callback(rs::stream::depth, callback); diff --git a/tests/simple_streaming_tests.cpp b/tests/simple_streaming_tests.cpp new file mode 100644 index 0000000..4b88c1a --- /dev/null +++ b/tests/simple_streaming_tests.cpp @@ -0,0 +1,84 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2016 Intel Corporation. All Rights Reserved. + +#include +#include +#include "gtest/gtest.h" +#include "utilities/utilities.h" + +//librealsense api +#include "librealsense/rs.hpp" +#include "viewer/viewer.h" + +using namespace std; + +GTEST_TEST(StreamingTests, basic_streaming_sync) +{ + rs::core::context context; + ASSERT_NE(context.get_device_count(), 0) << "No camera is connected"; + + rs::device * device = context.get_device(0); + + int colorWidth = 640, colorHeight = 480, colorFps = 30; + const rs::format colorFormat = rs::format::rgb8; + int depthWidth = 628, depthHeight = 468, depthFps = 30; + const rs::format depthFormat = rs::format::z16; + + auto frame_count = 0; + auto maxFramesCount = 100; + + device->enable_stream(rs::stream::color, colorWidth, colorHeight, colorFormat, colorFps); + device->enable_stream(rs::stream::depth, depthWidth, depthHeight, depthFormat, depthFps); + + std::shared_ptr viewer = std::make_shared(device, 320, "basic_streaming_sync"); + + device->start(); + + while(frame_count++ < maxFramesCount) + { + device->wait_for_frames(); + for(int32_t s = (int32_t)rs::stream::depth; s <= (int32_t)rs::stream::infrared2; ++s) + { + auto stream = (rs::stream)s; + if(device->is_stream_enabled(stream)) + { + auto image = test_utils::create_image(device, stream); + viewer->show_image(image); + } + } + } +} + +GTEST_TEST(StreamingTests, basic_streaming_callbacks) +{ + rs::core::context context; + ASSERT_NE(context.get_device_count(), 0) << "No camera is connected"; + + rs::device * device = context.get_device(0); + + int color_width = 640, color_height = 480, color_fps = 30; + const rs::format color_format = rs::format::rgb8; + int depth_width = 628, depth_height = 468, depth_fps = 30; + const rs::format depth_format = rs::format::z16; + + auto run_time = 2; + + device->enable_stream(rs::stream::color, color_width, color_height, color_format, color_fps); + device->enable_stream(rs::stream::depth, depth_width, depth_height, depth_format, depth_fps); + + + auto viewer = std::make_shared(device, 320, "basic_streaming_callbacks"); + + auto callback = [viewer](rs::frame f) + { + auto stream = f.get_stream_type(); + viewer->show_frame(std::move(f)); + }; + + device->set_frame_callback(rs::stream::color, callback); + device->set_frame_callback(rs::stream::depth, callback); + + device->start(); + std::this_thread::sleep_for(std::chrono::seconds(run_time)); + device->stop(); +} diff --git a/sdk/test/smart_ptr_tests.cpp b/tests/smart_ptr_tests.cpp similarity index 80% rename from sdk/test/smart_ptr_tests.cpp rename to tests/smart_ptr_tests.cpp index 4489d1f..42adee1 100644 --- a/sdk/test/smart_ptr_tests.cpp +++ b/tests/smart_ptr_tests.cpp @@ -19,7 +19,9 @@ namespace mock test_data & operator=(const test_data&) = delete; test_data() = default; test_data(int x) : m_x(x) {} - int get_x() const noexcept { return m_x; } + virtual int get_x() const noexcept { return m_x; } + void add_to_x(int addition) noexcept { m_x += addition; } + virtual ~test_data() {} private: int m_x; }; @@ -153,3 +155,35 @@ GTEST_TEST(smart_ptr_tests, swap) ASSERT_EQ(nullptr, initially_empty_data.get()); } +GTEST_TEST(smart_ptr_tests, alias_ctor) +{ + class derived_test_data : public mock::test_data + { + public: + derived_test_data(int y) : mock::test_data(), m_y(y) {} + int get_y() {return m_y;} + virtual int get_x() const noexcept { return -1; } + private: + int m_y; + }; + + smart_ptr derived_data(new derived_test_data(1)); + smart_ptr base_type_data(derived_data); + + ASSERT_EQ(2, derived_data.use_count()); + ASSERT_EQ(-1, derived_data->get_x()); + ASSERT_EQ(2, base_type_data.use_count()); + ASSERT_EQ(-1, base_type_data->get_x()); + ASSERT_EQ(1, derived_data->get_y()); + derived_data.reset(); + ASSERT_EQ(0, derived_data.use_count()); + ASSERT_EQ(1, base_type_data.use_count()); + + smart_ptr const_data = base_type_data; + + ASSERT_EQ(2, const_data.use_count()); + ASSERT_EQ(-1, const_data->get_x()); + //const_data->add_to_x(3); not a const function. + +} + diff --git a/tests/utilities/utilities.h b/tests/utilities/utilities.h new file mode 100644 index 0000000..5cd6389 --- /dev/null +++ b/tests/utilities/utilities.h @@ -0,0 +1,39 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2016 Intel Corporation. All Rights Reserved. + +#pragma once +#include +#include "rs/core/image_interface.h" +#include "rs/utils/librealsense_conversion_utils.h" +#include "image/image_utils.h" +#include "librealsense/rs.hpp" + + +namespace test_utils +{ + static std::shared_ptr create_image(rs::device * device, rs::stream stream) + { + if(device->get_frame_data(stream) == nullptr) + return nullptr; + auto sdk_stream = rs::utils::convert_stream_type(stream); + auto sdk_format = rs::utils::convert_pixel_format(device->get_stream_format(stream)); + const int pitch = device->get_stream_width(stream) * rs::core::image_utils::get_pixel_size(sdk_format); + rs::core::image_info info = {device->get_stream_width(stream), + device->get_stream_height(stream), + sdk_format, + pitch + }; + return std::shared_ptr(rs::core::image_interface::create_instance_from_raw_data(&info, + device->get_frame_data(stream), + sdk_stream, + rs::core::image_interface::flag::any, + device->get_frame_timestamp(stream), + device->get_frame_number(stream), + nullptr, + nullptr + )); + } + +} + +