Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/IntelRealSense/libre…
Browse files Browse the repository at this point in the history
…alsense into development
  • Loading branch information
ogoshen committed Jul 16, 2018
2 parents dcb82f8 + 3e0a8da commit 00fb0f0
Show file tree
Hide file tree
Showing 49 changed files with 1,128 additions and 626 deletions.
3 changes: 3 additions & 0 deletions CMake/realsense.def
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ EXPORTS
rs2_delete_context
rs2_create_recording_context
rs2_create_mock_context
rs2_create_mock_context_versioned
rs2_get_time
rs2_context_add_device
rs2_context_remove_device
Expand Down Expand Up @@ -92,6 +93,7 @@ EXPORTS
rs2_delete_frame_queue
rs2_wait_for_frame
rs2_poll_for_frame
rs2_try_wait_for_frame
rs2_enqueue_frame
rs2_flush_queue

Expand Down Expand Up @@ -223,6 +225,7 @@ EXPORTS
rs2_pipeline_stop
rs2_pipeline_wait_for_frames
rs2_pipeline_poll_for_frames
rs2_pipeline_try_wait_for_frames
rs2_delete_pipeline
rs2_pipeline_start
rs2_pipeline_start_with_config
Expand Down
14 changes: 10 additions & 4 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3169,7 +3169,7 @@ namespace rs2
if(viewer.synchronization_enable)
{
auto index = 0;
while (syncer_queue.poll_for_frame(&frm) && ++index <= syncer_queue.capacity())
while (syncer_queue.try_wait_for_frame(&frm, 30) && ++index <= syncer_queue.capacity())
{
processing_block.invoke(frm);
}
Expand All @@ -3184,7 +3184,7 @@ namespace rs2
for (auto&& q : frames_queue_local)
{
frame frm;
if (q.second.poll_for_frame(&frm))
if (q.second.try_wait_for_frame(&frm, 30))
{
processing_block.invoke(frm);
}
Expand Down Expand Up @@ -5446,6 +5446,14 @@ namespace rs2
}


bool rs2::device_model::is_streaming() const
{
return std::any_of(subdevices.begin(), subdevices.end(), [](const std::shared_ptr<subdevice_model>& sm)
{
return sm->streaming;
});
}

void device_model::draw_controls(float panel_width, float panel_height,
ux_window& window,
std::string& error_message,
Expand Down Expand Up @@ -5773,8 +5781,6 @@ namespace rs2
return sm->streaming;
}))
{
// Stopping post processing filter rendering thread
viewer.ppf.stop();
stop_recording = true;
}
}
Expand Down
7 changes: 6 additions & 1 deletion common/model-views.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ namespace rs2
void handle_harware_events(const std::string& serialized_data);

std::vector<std::shared_ptr<subdevice_model>> subdevices;

bool is_streaming() const;
bool metadata_supported = false;
bool get_curr_advanced_controls = true;
device dev;
Expand Down Expand Up @@ -658,6 +658,11 @@ namespace rs2
}
}

bool is_rendering() const
{
return render_thread_active.load();
}

rs2::frameset get_points()
{
frame f;
Expand Down
12 changes: 12 additions & 0 deletions include/librealsense2/h/rs_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ rs2_context* rs2_create_recording_context(int api_version, const char* filename,
*/
rs2_context* rs2_create_mock_context(int api_version, const char* filename, const char* section, rs2_error** error);

/**
* Create librealsense context that given a file will respond to calls exactly as the recording did
* if the user calls a method that was either not called during recording or violates causality of the recording error will be thrown
* \param[in] api_version realsense API version as provided by RS2_API_VERSION macro
* \param[in] filename string representing the name of the file to play back from
* \param[in] section string representing the name of the section within existing recording
* \param[in] min_api_version reject any file that was recorded before this version
* \param[out] error if non-null, receives any error that occurs during this call, otherwise, errors are ignored
* \return context object, should be released by rs2_delete_context
*/
rs2_context* rs2_create_mock_context_versioned(int api_version, const char* filename, const char* section, const char* min_api_version, rs2_error** error);

/**
* Create software device to enable use librealsense logic without getting data from backend
* but inject the data from outside
Expand Down
16 changes: 16 additions & 0 deletions include/librealsense2/h/rs_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ extern "C" {
*/
int rs2_pipeline_poll_for_frames(rs2_pipeline* pipe, rs2_frame** output_frame, rs2_error ** error);

/**
* Wait until a new set of frames becomes available.
* The frames set includes time-synchronized frames of each enabled stream in the pipeline.
* The method blocks the calling thread, and fetches the latest unread frames set.
* Device frames, which were produced while the function wasn't called, are dropped. To avoid frame drops, this method should be called
* as fast as the device frame rate.
* The application can maintain the frames handles to defer processing. However, if the application maintains too long history, the device
* may lack memory resources to produce new frames, and the following call to this method shall fail to retrieve new frames, until resources
* are retained.
* \param[in] pipe the pipeline
* \param[in] timeout_ms max time in milliseconds to wait until a frame becomes available
* \param[out] output_frame frame handle to be released using rs2_release_frame
* \param[out] error if non-null, receives any error that occurs during this call, otherwise, errors are ignored
* \return true if new frame was stored to output_frame
*/
int rs2_pipeline_try_wait_for_frames(rs2_pipeline* pipe, rs2_frame** output_frame, unsigned int timeout_ms, rs2_error ** error);

/**
* Delete a pipeline instance.
Expand Down
11 changes: 11 additions & 0 deletions include/librealsense2/h/rs_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ void rs2_delete_frame_queue(rs2_frame_queue* queue);
/**
* wait until new frame becomes available in the queue and dequeue it
* \param[in] queue the frame queue data structure
* \param[in] timeout_ms max time in milliseconds to wait until an exception will be thrown
* \param[out] error if non-null, receives any error that occurs during this call, otherwise, errors are ignored
* \return frame handle to be released using rs2_release_frame
*/
Expand All @@ -131,6 +132,16 @@ rs2_frame* rs2_wait_for_frame(rs2_frame_queue* queue, unsigned int timeout_ms, r
*/
int rs2_poll_for_frame(rs2_frame_queue* queue, rs2_frame** output_frame, rs2_error** error);

/**
* wait until new frame becomes available in the queue and dequeue it
* \param[in] queue the frame queue data structure
* \param[in] timeout_ms max time in milliseconds to wait until a frame becomes available
* \param[out] output_frame frame handle to be released using rs2_release_frame
* \param[out] error if non-null, receives any error that occurs during this call, otherwise, errors are ignored
* \return true if new frame was stored to output_frame
*/
int rs2_try_wait_for_frame(rs2_frame_queue* queue, unsigned int timeout_ms, rs2_frame** output_frame, rs2_error** error);

/**
* enqueue new frame into a queue
* \param[in] frame frame handle to enqueue (this operation passed ownership to the queue)
Expand Down
5 changes: 3 additions & 2 deletions include/librealsense2/hpp/rs_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ namespace rs2
* \param[in] filename string of the name of the file
*/
mock_context(const std::string& filename,
const std::string& section = "")
const std::string& section = "",
const std::string& min_api_version = "0.0.0")
{
rs2_error* e = nullptr;
_context = std::shared_ptr<rs2_context>(
rs2_create_mock_context(RS2_API_VERSION, filename.c_str(), section.c_str(), &e),
rs2_create_mock_context_versioned(RS2_API_VERSION, filename.c_str(), section.c_str(), min_api_version.c_str(), &e),
rs2_delete_context);
error::handle(e);
}
Expand Down
14 changes: 14 additions & 0 deletions include/librealsense2/hpp/rs_pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,20 @@ namespace rs2
return res > 0;
}

bool try_wait_for_frames(frameset* f, unsigned int timeout_ms = 5000) const
{
if (!f)
{
throw std::invalid_argument("null frameset");
}
rs2_error* e = nullptr;
rs2_frame* frame_ref = nullptr;
auto res = rs2_pipeline_try_wait_for_frames(_pipeline.get(), &frame_ref, timeout_ms, &e);
error::handle(e);
if (res) *f = frameset(frame(frame_ref));
return res > 0;
}

/**
* Return the active device and streams profiles, used by the pipeline.
* The pipeline streams profiles are selected during \c start(). The method returns a valid result only when the pipeline is active -
Expand Down
29 changes: 29 additions & 0 deletions include/librealsense2/hpp/rs_processing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,18 @@ namespace rs2
if (res) *output = f;
return res > 0;
}

template<typename T>
typename std::enable_if<std::is_base_of<rs2::frame, T>::value, bool>::type try_wait_for_frame(T* output, unsigned int timeout_ms = 5000) const
{
rs2_error* e = nullptr;
rs2_frame* frame_ref = nullptr;
auto res = rs2_try_wait_for_frame(_queue.get(), timeout_ms, &frame_ref, &e);
error::handle(e);
frame f{ frame_ref };
if (res) *output = f;
return res > 0;
}
/**
* Does the same thing as enqueue function.
*/
Expand Down Expand Up @@ -392,6 +404,23 @@ namespace rs2
return false;
}

/**
* Wait until coherent set of frames becomes available
* \param[in] timeout_ms Max time in milliseconds to wait until an available frame
* \param[out] fs New coherent frame-set
* \return true if new frame-set was stored to result
*/
bool try_wait_for_frames(frameset* fs, unsigned int timeout_ms = 5000) const
{
frame result;
if (_results.try_wait_for_frame(&result, timeout_ms))
{
*fs = frameset(result);
return true;
}
return false;
}

void operator()(frame f) const
{
_sync(std::move(f));
Expand Down
Loading

0 comments on commit 00fb0f0

Please sign in to comment.