Skip to content

Commit

Permalink
Merge pull request #6136 from dorodnic/ethernet
Browse files Browse the repository at this point in the history
RealSense Device over Network
  • Loading branch information
dorodnic committed Mar 26, 2020
2 parents 31cccea + 58d11a2 commit 4474e84
Show file tree
Hide file tree
Showing 72 changed files with 5,103 additions and 38 deletions.
5 changes: 5 additions & 0 deletions CMake/global_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ macro(global_set_flags)
include(libusb_config)
endif()

if(BUILD_NETWORK_DEVICE)
add_definitions(-DNET_DEVICE)
set(LRS_NET_TARGET realsense2-net)
endif()

add_definitions(-D${BACKEND} -DUNICODE)
endmacro()

Expand Down
1 change: 1 addition & 0 deletions CMake/lrs_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ option(BUILD_OPENNI2_BINDINGS "Build OpenNI bindings" OFF)
option(IMPORT_DEPTH_CAM_FW "Download the latest firmware for the depth cameras" ON)
option(BUILD_CV_KINFU_EXAMPLE "Build OpenCV KinectFusion example" OFF)
option(FORCE_RSUSB_BACKEND "Use RS USB backend, mandatory for Win7/MacOS/Android, optional for Linux" OFF)
option(BUILD_NETWORK_DEVICE "Build Network Device support" OFF)
option(FORCE_LIBUVC "Explicitly turn-on libuvc backend - deprecated, use FORCE_RSUSB_BACKEND instead" OFF)
option(FORCE_WINUSB_UVC "Explicitly turn-on winusb_uvc (for win7) backend - deprecated, use FORCE_RSUSB_BACKEND instead" OFF)
option(ANDROID_USB_HOST_UVC "Build UVC backend for Android - deprecated, use FORCE_RSUSB_BACKEND instead" OFF)
12 changes: 12 additions & 0 deletions CMake/realsense2-netConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@PACKAGE_INIT@

set(realsense2-net_VERSION_MAJOR "@REALSENSE_VERSION_MAJOR@")
set(realsense2-net_VERSION_MINOR "@REALSENSE_VERSION_MINOR@")
set(realsense2-net_VERSION_PATCH "@REALSENSE_VERSION_PATCH@")

set(realsense2-net_VERSION ${realsense2-net_VERSION_MAJOR}.${realsense2-net_VERSION_MINOR}.${realsense2-gl_VERSION_PATCH})

set_and_check(realsense2-net_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")

include("${CMAKE_CURRENT_LIST_DIR}/realsense2-netTargets.cmake")
set(realsense2-net_LIBRARY realsense2-net::realsense2-net)
1 change: 1 addition & 0 deletions CMake/unix_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ macro(os_set_flags)
if(${MACHINE} MATCHES "arm-linux-gnueabihf")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon -mfloat-abi=hard -ftree-vectorize -latomic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -mfloat-abi=hard -ftree-vectorize -latomic")
add_definitions(-DRASPBERRY_PI)
elseif(${MACHINE} MATCHES "aarch64-linux-gnu")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mstrict-align -ftree-vectorize")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mstrict-align -ftree-vectorize")
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ if(BUILD_UNIT_TESTS)
add_subdirectory(unit-tests)
endif()

if(BUILD_NETWORK_DEVICE)
add_subdirectory(src/ethernet)
add_subdirectory(src/compression)
endif()

if(BUILD_WITH_TM2)
add_tm2()
endif()
Expand Down
48 changes: 30 additions & 18 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5339,8 +5339,9 @@ namespace rs2
// draw device header
////////////////////////////////////////
const bool is_playback_device = dev.is<playback>();
bool is_ip_device = dev.supports(RS2_CAMERA_INFO_IP_ADDRESS);
auto header_h = panel_height;
if (is_playback_device) header_h += 15;
if (is_playback_device || is_ip_device) header_h += 15;

ImColor device_header_background_color = title_color;
const float left_space = 3.f;
Expand Down Expand Up @@ -5372,28 +5373,39 @@ namespace rs2
std::stringstream ss;
if(dev.supports(RS2_CAMERA_INFO_NAME))
ss << dev.get_info(RS2_CAMERA_INFO_NAME);
ImGui::Text(" %s", ss.str().c_str());
if (dev.supports(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR))
if(is_ip_device)
{
std::string desc = dev.get_info(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR);
ss.str("");
ss << " " << textual_icons::usb_type << " " << desc;
ImGui::SameLine();
if (!starts_with(desc, "3.")) ImGui::PushStyleColor(ImGuiCol_Text, yellow);
else ImGui::PushStyleColor(ImGuiCol_Text, light_grey);
ImGui::Text(" %s", ss.str().c_str());
ImGui::PopStyleColor();
ss.str("");
ss << "The camera was detected by the OS as connected to a USB " << desc << " port";
ImGui::Text(" %s", ss.str().substr(0, ss.str().find("\n IP Device")).c_str());

ImGui::PushFont(window.get_font());
ImGui::PushStyleColor(ImGuiCol_Text, light_grey);
if (ImGui::IsItemHovered())
ImGui::SetTooltip(" %s", ss.str().c_str());
ImGui::PopStyleColor();
ImGui::Text("\tNetwork Device at %s", dev.get_info(RS2_CAMERA_INFO_IP_ADDRESS));
ImGui::PopFont();
}
else
{
ImGui::Text(" %s", ss.str().c_str());


if (dev.supports(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR))
{
std::string desc = dev.get_info(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR);
ss.str("");
ss << " " << textual_icons::usb_type << " " << desc;
ImGui::SameLine();
if (!starts_with(desc, "3.")) ImGui::PushStyleColor(ImGuiCol_Text, yellow);
else ImGui::PushStyleColor(ImGuiCol_Text, light_grey);
ImGui::Text(" %s", ss.str().c_str());
ImGui::PopStyleColor();
ss.str("");
ss << "The camera was detected by the OS as connected to a USB " << desc << " port";
ImGui::PushFont(window.get_font());
ImGui::PushStyleColor(ImGuiCol_Text, light_grey);
if (ImGui::IsItemHovered())
ImGui::SetTooltip(" %s", ss.str().c_str());
ImGui::PopStyleColor();
ImGui::PopFont();
}
}

//ImGui::Text(" %s", dev.get_info(RS2_CAMERA_INFO_NAME));
ImGui::PopFont();

Expand Down
2 changes: 2 additions & 0 deletions common/model-views.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ namespace rs2
static const char* show_map_ruler { "viewer_model.show_map_ruler" };
static const char* show_stream_details { "viewer_model.show_stream_details" };
static const char* metric_system { "viewer_model.metric_system" };

static const char* last_ip { "viewer_model.last_ip" };
}
namespace window
{
Expand Down
17 changes: 17 additions & 0 deletions config/librealsense-net.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
includedir=${prefix}/include
#TODO: libdir=${exec_prefix}/lib@MULTI_ARCH_SUFFIX@
libdir= ${prefix}/lib/x86_64-linux-gnu

Name: realsense2-gl
Description: Intel(R) RealSense(tm) Network Device Extension Module
Version: @REALSENSE-NET_VERSION_STRING@
URL: https://github.com/IntelRealSense/librealsense
Requires.private: @LRS_LIB_NAME@
Libs: -L${libdir} -l@LRS_LIB_NAME@
Libs.private: @LRS_PKG_LIBS@
Cflags: -I${includedir}

#TODO check -Wl -Bdynamic
#Libs: -L${libdir} -Wl,-Bdynamic -lrealsense
29 changes: 29 additions & 0 deletions include/librealsense2-net/rs_net.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* License: Apache 2.0. See LICENSE file in root directory.
Copyright(c) 2020 Intel Corporation. All Rights Reserved. */

/** \file rs_net.h
* \
* Exposes RealSense network device functionality for C compilers
*/

#ifndef LIBREALSENSE_RS2_NET_H
#define LIBREALSENSE_RS2_NET_H

#ifdef __cplusplus
extern "C" {
#endif

#include "librealsense2/rs.h"

/**
* Net device is a rs2_device that can be stream and be contolled remotely over network
* \param[in] api_version Users are expected to pass their version of \c RS2_API_VERSION to make sure they are running the correct librealsense version.
* \param[in] address remote devce ip address. should be the address of the hosting device
* \param[out] error if non-null, receives any error that occurs during this call, otherwise, errors are ignored
*/
rs2_device* rs2_create_net_device(int api_version, const char* address, rs2_error** error);

#ifdef __cplusplus
}
#endif
#endif
47 changes: 47 additions & 0 deletions include/librealsense2-net/rs_net.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2020 Intel Corporation. All Rights Reserved.

#ifndef LIBREALSENSE_RS2_NET_HPP
#define LIBREALSENSE_RS2_NET_HPP

#include <librealsense2/rs.hpp>
#include "rs_net.h"

#include <memory>

namespace rs2
{
class net_device : public rs2::device
{
public:
net_device(const std::string& address) : rs2::device(init(address)) { }

/**
* Add network device to existing context.
* Any future queries on the context will return this device.
* This operation cannot be undone (except for destroying the context)
*
* \param[in] ctx context to add the device to
*/
void add_to(context& ctx)
{
rs2_error* e = nullptr;
rs2_context_add_software_device(((std::shared_ptr<rs2_context>)ctx).get(), _dev.get(), &e);
error::handle(e);
}


private:
std::shared_ptr<rs2_device> init(const std::string& address)
{
rs2_error* e = nullptr;
auto dev = std::shared_ptr<rs2_device>(
rs2_create_net_device(RS2_API_VERSION, address.c_str(), &e),
rs2_delete_device);
error::handle(e);

return dev;
}
};
}
#endif // LIBREALSENSE_RS2_NET_HPP
1 change: 1 addition & 0 deletions include/librealsense2/h/rs_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef enum rs2_camera_info {
RS2_CAMERA_INFO_PRODUCT_LINE , /**< Device product line D400/SR300/L500/T200 */
RS2_CAMERA_INFO_ASIC_SERIAL_NUMBER , /**< ASIC serial number */
RS2_CAMERA_INFO_FIRMWARE_UPDATE_ID , /**< Firmware update ID */
RS2_CAMERA_INFO_IP_ADDRESS , /**< IP address for remote camera. */
RS2_CAMERA_INFO_COUNT /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */
} rs2_camera_info;
const char* rs2_camera_info_to_string(rs2_camera_info info);
Expand Down
14 changes: 8 additions & 6 deletions include/librealsense2/hpp/rs_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,23 +259,25 @@ namespace rs2

class software_device : public device
{
std::shared_ptr<rs2_device> create_device_ptr()
std::shared_ptr<rs2_device> create_device_ptr(std::function<void(rs2_device*)> deleter)
{
rs2_error* e = nullptr;
std::shared_ptr<rs2_device> dev(
rs2_create_software_device(&e),
rs2_delete_device);
deleter);
error::handle(e);
return dev;
}

public:
software_device()
: device(create_device_ptr())
{}
software_device(std::function<void(rs2_device*)> deleter = &rs2_delete_device)
: device(create_device_ptr(deleter))
{
this->set_destruction_callback([]{});
}

software_device(std::string name)
: device(create_device_ptr())
: device(create_device_ptr(&rs2_delete_device))
{
update_info(RS2_CAMERA_INFO_NAME, name);
}
Expand Down
6 changes: 6 additions & 0 deletions scripts/setup_network_queues.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -e

echo 8388608 > /proc/sys/net/core/wmem_default
echo 8388608 > /proc/sys/net/core/rmem_default

echo "Setting-up network queues successfully changed"
65 changes: 65 additions & 0 deletions src/compression/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# License: Apache 2.0. See LICENSE file in root directory.
# Copyright(c) 2019 Intel Corporation. All Rights Reserved.
cmake_minimum_required(VERSION 3.1.0)

project(realsense2-compression VERSION 1.0.0 LANGUAGES CXX C)

# Save the command line compile commands in the build output
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

set(DEPENDENCIES ${DEPENDENCIES} realsense2)

file(GLOB COMPRESSION_SOURCES
"*.h"
"*.cpp"
"../ipDeviceCommon/*.h"
)

set(COMPRESSION_SOURCES ${COMPRESSION_SOURCES} ${LZ4_DIR}/lz4.h ${LZ4_DIR}/lz4.c)

add_library(${PROJECT_NAME} STATIC ${COMPRESSION_SOURCES})

include_directories(${PROJECT_NAME}
../../common
../ipDeviceCommon
../../third-party/easyloggingpp/src
)

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
#set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)

add_dependencies(${PROJECT_NAME}
libjpeg-turbo
)

include_directories(${PROJECT_NAME}
${CMAKE_BINARY_DIR}/libjpeg-turbo/include
${LZ4_DIR}
)

if(WIN32)
target_link_libraries(${PROJECT_NAME}
PRIVATE ${DEPENDENCIES}
PRIVATE ${CMAKE_BINARY_DIR}/libjpeg-turbo/lib/turbojpeg-static.lib
)
else()
target_link_libraries(${PROJECT_NAME}
PRIVATE ${DEPENDENCIES}
PRIVATE ${CMAKE_BINARY_DIR}/libjpeg-turbo/lib/libturbojpeg.a
)
endif()

set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "Library")

set(CMAKECONFIG_COMPRESS_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
install(TARGETS ${PROJECT_NAME}
EXPORT realsense2-compressTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(EXPORT realsense2-compressTargets
FILE realsense2-compressTargets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKECONFIG_COMPRESS_INSTALL_DIR}
)
Loading

0 comments on commit 4474e84

Please sign in to comment.