Skip to content

Commit

Permalink
Merge pull request #34 from IntelRealSense/development
Browse files Browse the repository at this point in the history
Merge IntelRealSense/librealsense/Development to abernste/librealsense/development
  • Loading branch information
abernste authored Sep 20, 2018
2 parents 519e045 + ba160b4 commit a5f210f
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 109 deletions.
59 changes: 28 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CUDA_STANDARD 11)
elseif(COMPILER_SUPPORTS_CXX0X)
Expand Down Expand Up @@ -198,25 +198,20 @@ set(REALSENSE_CPP
src/media/playback/playback_device.cpp
src/media/playback/playback_sensor.cpp
)

## Check for Windows Version ##
if( (${CMAKE_SYSTEM_VERSION} EQUAL 6.1) OR (FORCE_WINUSB_UVC) ) # Windows 7
if (NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
set(DRIVERS IntelRealSense_D400_series_win7.inf
WdfCoinstaller01011.dll
winusbcoinstaller2.dll
)

message("Preparing Windows 7 drivers" )
make_directory(${CMAKE_CURRENT_BINARY_DIR}/drivers/)
file(GLOB DRIVERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/src/win7/drivers/" "${CMAKE_CURRENT_SOURCE_DIR}/src/win7/drivers/*")
foreach(item IN LISTS DRIVERS)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${item}"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/src/win7/drivers/${item}" "${CMAKE_CURRENT_BINARY_DIR}/drivers/${item}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/win7/drivers/${item}"
)
message("Copying ${CMAKE_CURRENT_SOURCE_DIR}/src/win7/drivers/${item} to ${CMAKE_CURRENT_BINARY_DIR}/drivers/" )
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/win7/drivers/${item}" "${CMAKE_CURRENT_BINARY_DIR}/drivers/${item}" COPYONLY)
endforeach()
endif()
add_custom_target(realsense-driver ALL DEPENDS ${DRIVERS})

list(APPEND REALSENSE_CPP
src/win7/win7-helpers.cpp
src/win7/win7-uvc.cpp
Expand Down Expand Up @@ -360,23 +355,25 @@ set(REALSENSE_HPP
src/media/ros/ros_file_format.h
)

## Check for Windows Version ##
if( ${CMAKE_SYSTEM_VERSION} EQUAL 6.1 ) # Windows 7
list(APPEND REALSENSE_HPP
src/win7/win7-helpers.h
src/win7/win7-uvc.h
src/win7/win7-usb.h
src/win7/win7-hid.h
src/win7/win7-backend.h
)
else() # Some other windows version
list(APPEND REALSENSE_HPP
src/win/win-helpers.h
src/win/win-uvc.h
src/win/win-usb.h
src/win/win-hid.h
src/win/win-backend.h
)
if(WIN32)
## Check for Windows Version ##
if( ${CMAKE_SYSTEM_VERSION} EQUAL 6.1 ) # Windows 7
list(APPEND REALSENSE_HPP
src/win7/win7-helpers.h
src/win7/win7-uvc.h
src/win7/win7-usb.h
src/win7/win7-hid.h
src/win7/win7-backend.h
)
else() # Some other windows version
list(APPEND REALSENSE_HPP
src/win/win-helpers.h
src/win/win-uvc.h
src/win/win-usb.h
src/win/win-hid.h
src/win/win-backend.h
)
endif()
endif()

if(BUILD_EASYLOGGINGPP)
Expand Down Expand Up @@ -855,7 +852,7 @@ if(BUILD_SHARED_LIBS)
add_library(realsense2 SHARED
${REALSENSE_CPP} ${REALSENSE_HPP} ${REALSENSE_DEF} ${REALSENSE_CU} ${REALSENSE_CUH}
src/res/resource.h
src/res/librealsense.rc)
src/res/librealsense.rc)
source_group("Resources" FILES
src/res/resource.h
src/res/librealsense.rc
Expand Down
2 changes: 2 additions & 0 deletions src/libuvc/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ void *_uvc_handle_events(void *arg) {
uvc_context_t *ctx = (uvc_context_t *) arg;

while (!ctx->kill_handler_thread)
{
libusb_handle_events_completed(ctx->usb_ctx, &ctx->kill_handler_thread);
}
return NULL;
}

Expand Down
10 changes: 5 additions & 5 deletions src/libuvc/libuvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,6 @@ namespace librealsense
void stop_callbacks() override
{
_is_started = false;
_stream_ctrls.clear();
_profiles.clear();
_callbacks.clear();
}

void close(stream_profile) override
Expand All @@ -372,6 +369,10 @@ namespace librealsense
_is_started = false;
}
uvc_stop_streaming(_device_handle);
_stream_ctrls.clear();
_profiles.clear();
_callbacks.clear();

}

void power_D0() {
Expand Down Expand Up @@ -416,7 +417,7 @@ namespace librealsense
void power_D3() {
uvc_unref_device(_device);
//uvc_stop_streaming(_device_handle);
_profiles.clear();
//_profiles.clear();
uvc_close(_device_handle);
_device = NULL;
_device_handle = NULL;
Expand All @@ -439,7 +440,6 @@ namespace librealsense
else {
// we have been asked to close the device. queue the request for several seconds
// just in case a quick turn on come right over.

_state_change_time = std::clock();
}

Expand Down
4 changes: 2 additions & 2 deletions src/libuvc/libuvc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ struct uvc_stream_handle {
struct uvc_streaming_interface *stream_if;

/** if true, stream is running (streaming video to host) */
uint8_t running;
std::atomic<uint8_t> running;
/** Current control block */
struct uvc_stream_ctrl cur_ctrl;

Expand All @@ -261,13 +261,13 @@ struct uvc_stream_handle {
uint8_t *outbuf, *holdbuf;
std::mutex cb_mutex;
std::condition_variable cb_cond;
std::condition_variable cb_cancel;
std::thread cb_thread;
uint32_t last_polled_seq;
uvc_frame_callback_t *user_cb;
void *user_ptr;
struct libusb_transfer *transfers[LIBUVC_NUM_TRANSFER_BUFS];
uint8_t *transfer_bufs[LIBUVC_NUM_TRANSFER_BUFS];
std::condition_variable transfer_cancel[LIBUVC_NUM_TRANSFER_BUFS];
struct uvc_frame frame;
enum uvc_frame_format frame_format;
};
Expand Down
157 changes: 93 additions & 64 deletions src/libuvc/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,68 +831,67 @@ void _uvc_process_payload(uvc_stream_handle_t *strmh, uint8_t *payload, size_t p
*/
void LIBUSB_CALL _uvc_stream_callback(struct libusb_transfer *transfer) {
uvc_stream_handle_t *strmh = (uvc_stream_handle_t *)transfer->user_data;



int resubmit = 1;

std::unique_lock<std::mutex> lock(strmh->cb_mutex);
switch (transfer->status) {
case LIBUSB_TRANSFER_COMPLETED:
if (transfer->num_iso_packets == 0) {
std::unique_lock<std::mutex> lock(strmh->cb_mutex);
/* This is a bulk mode transfer, so it just has one payload transfer */
_uvc_process_payload(strmh, transfer->buffer, transfer->actual_length);


}
else
{
/* This is an isochronous mode transfer, so each packet has a payload transfer */
int packet_id;

for (packet_id = 0; packet_id < transfer->num_iso_packets; ++packet_id) {
uint8_t *pktbuf;
struct libusb_iso_packet_descriptor *pkt;

pkt = transfer->iso_packet_desc + packet_id;

if (pkt->status != 0) {
UVC_DEBUG("bad packet (isochronous transfer); status: %d", pkt->status);
continue;
}

pktbuf = libusb_get_iso_packet_buffer_simple(transfer, packet_id);

_uvc_process_payload(strmh, pktbuf, pkt->actual_length);

case LIBUSB_TRANSFER_COMPLETED:
{
if (strmh && !strmh->running)
break;
if (transfer->num_iso_packets == 0) {
/* This is a bulk mode transfer, so it just has one payload transfer */
_uvc_process_payload(strmh, transfer->buffer, transfer->actual_length);
}
else
{
/* This is an isochronous mode transfer, so each packet has a payload transfer */
int packet_id;

for (packet_id = 0; packet_id < transfer->num_iso_packets; ++packet_id) {
uint8_t *pktbuf;
struct libusb_iso_packet_descriptor *pkt;

pkt = transfer->iso_packet_desc + packet_id;

if (pkt->status != 0) {

UVC_DEBUG("bad packet (isochronous transfer); status: %d", pkt->status);
continue;
}

pktbuf = libusb_get_iso_packet_buffer_simple(transfer, packet_id);

_uvc_process_payload(strmh, pktbuf, pkt->actual_length);

}
}
break;
}
}
break;

case LIBUSB_TRANSFER_CANCELLED:
case LIBUSB_TRANSFER_NO_DEVICE: {
int i;
UVC_DEBUG("not retrying transfer, status = %d", transfer->status);

UVC_DEBUG("not retrying transfer, status = %d", transfer->status);
{
std::unique_lock<std::mutex> lock(strmh->cb_mutex);

/* Mark transfer as deleted. */
for (i = 0; i < LIBUVC_NUM_TRANSFER_BUFS; i++) {
if (strmh->transfers[i] == transfer) {
UVC_DEBUG("Freeing transfer %d (%p)", i, transfer);
free(transfer->buffer);
libusb_free_transfer(transfer);
strmh->transfers[i] = NULL;
strmh->transfer_cancel[i].notify_all();
break;
}
}
if (i == LIBUVC_NUM_TRANSFER_BUFS) {
UVC_DEBUG("transfer %p not found; not freeing!", transfer);
}

resubmit = 0;
strmh->cb_cancel.notify_all();
}


break;
}
case LIBUSB_TRANSFER_TIMED_OUT:
Expand All @@ -902,11 +901,32 @@ void LIBUSB_CALL _uvc_stream_callback(struct libusb_transfer *transfer) {
UVC_DEBUG("retrying transfer, status = %d", transfer->status);
break;
}

if (strmh && strmh->running && resubmit )
{
auto res = libusb_submit_transfer(transfer);
}

if ( resubmit )
{
if ( strmh->running )
{
libusb_submit_transfer(transfer);
}
else
{
int i;
/* Mark transfer as deleted. */
for(i=0; i < LIBUVC_NUM_TRANSFER_BUFS; i++) {
if(strmh->transfers[i] == transfer) {
UVC_DEBUG("Freeing orphan transfer %d (%p)", i, transfer);
free(transfer->buffer);
libusb_free_transfer(transfer);
strmh->transfers[i] = NULL;
strmh->transfer_cancel[i].notify_all();

}
}
if(i == LIBUVC_NUM_TRANSFER_BUFS ) {
UVC_DEBUG("orphan transfer %p not found; not freeing!", transfer);
}
}
}
}

/** Begin streaming video from the camera into the callback function.
Expand Down Expand Up @@ -1383,34 +1403,43 @@ uvc_error_t uvc_stream_stop(uvc_stream_handle_t *strmh) {

if (!strmh->running)
return UVC_ERROR_INVALID_PARAM;

{
std::unique_lock<std::mutex> lock(strmh->cb_mutex);
strmh->running = 0;
for (i = 0; i < LIBUVC_NUM_TRANSFER_BUFS; i++) {
if (strmh->transfers[i] != NULL) {
int res = libusb_cancel_transfer(strmh->transfers[i]);
if (res < 0) {
free(strmh->transfers[i]->buffer);
libusb_free_transfer(strmh->transfers[i]);
strmh->transfers[i] = NULL;
}
else
strmh->cb_cancel.wait(lock);
}
}
std::unique_lock<std::mutex> lock(strmh->cb_mutex);
strmh->running = 0;
for (i = 0; i < LIBUVC_NUM_TRANSFER_BUFS; i++)
{
if (strmh->transfers[i] != NULL)
{
int res = libusb_cancel_transfer(strmh->transfers[i]);
if (res < 0)
{
free(strmh->transfers[i]->buffer);
libusb_free_transfer(strmh->transfers[i]);
strmh->transfers[i] = NULL;
}
}
}

for (i = 0; i < LIBUVC_NUM_TRANSFER_BUFS; i++)
{
if (strmh->transfers[i] != NULL)
strmh->transfer_cancel[i].wait(lock);
}


// Kick the user thread awake
strmh->cb_cond.notify_all();
}
// Kick the user thread awake
strmh->cb_cond.notify_all();

/** @todo stop the actual stream, camera side? */

if (strmh->user_cb) {
/* wait for the thread to stop (triggered by
* LIBUSB_TRANSFER_CANCELLED transfer) */
strmh->cb_thread.join();
}
auto res = libusb_clear_halt(strmh->devh->usb_devh,strmh->stream_if->bEndpointAddress);
}

auto res = libusb_clear_halt(strmh->devh->usb_devh,strmh->stream_if->bEndpointAddress);

return UVC_SUCCESS;
}
Expand Down
18 changes: 11 additions & 7 deletions unit-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ install(
${CMAKE_INSTALL_PREFIX}/bin
)

#Windows OS will host the files under %TEMP% location
#Unix-like machines will host the tests files under /temp/ directory
if (WIN32)
set(Deployment_Location "$ENV{TEMP}\\")
else() # Data shall be preserved between reboots. For Linux distributions/ ANDROID_NDK_TOOLCHAIN_INCLUDED/APPLE
#set(Deployment_Location /var/tmp/) The standard confoiguration currently fails on CI
set(Deployment_Location /tmp/)
if(TESTDATA_LOCATION)
set(Deployment_Location ${TESTDATA_LOCATION})
else()
#Windows OS will host the files under %TEMP% location
#Unix-like machines will host the tests files under /tmp/ directory
if (WIN32)
set(Deployment_Location "$ENV{TEMP}\\")
else() # Data shall be preserved between reboots. For Linux distributions/ ANDROID_NDK_TOOLCHAIN_INCLUDED/APPLE
#set(Deployment_Location /var/tmp/) The standard configuration currently fails on CI
set(Deployment_Location /tmp/)
endif()
endif()

add_custom_command(TARGET live-test POST_BUILD
Expand Down

0 comments on commit a5f210f

Please sign in to comment.