Skip to content

Commit

Permalink
Merge pull request IntelRealSense#1566 from AnnaRomanov/playback-repeat
Browse files Browse the repository at this point in the history
Playback repeat
  • Loading branch information
dorodnic authored Apr 23, 2018
2 parents 1751d03 + 57eae49 commit 2ac4722
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions CMake/realsense.def
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ EXPORTS
rs2_config_enable_all_stream
rs2_config_enable_device
rs2_config_enable_device_from_file
rs2_config_enable_device_from_file_repeat_option
rs2_config_enable_record_to_file
rs2_config_disable_stream
rs2_config_disable_indexed_stream
Expand Down
15 changes: 15 additions & 0 deletions include/librealsense2/h/rs_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,28 @@ extern "C" {
* The device available streams are as recorded to the file, and \c resolve() considers only this device and configuration
* as available.
* This request cannot be used if enable_record_to_file() is called for the current config, and vise versa
* By default, playback is repeated once the file ends. To control this, see 'rs2_config_enable_device_from_file_repeat_option'.
*
* \param[in] config A pointer to an instance of a config
* \param[in] file_name The playback file of the device
* \param[out] error if non-null, receives any error that occurs during this call, otherwise, errors are ignored
*/
void rs2_config_enable_device_from_file(rs2_config* config, const char* file, rs2_error ** error);

/**
* Select a recorded device from a file, to be used by the pipeline through playback.
* The device available streams are as recorded to the file, and \c resolve() considers only this device and configuration
* as available.
* This request cannot be used if enable_record_to_file() is called for the current config, and vise versa
*
* \param[in] config A pointer to an instance of a config
* \param[in] file_name The playback file of the device
* \param[in] repeat_playback if true, when file ends the playback starts again, in an infinite loop;
if false, when file ends playback does not start again, and should by stopped manually by the user.
* \param[out] error if non-null, receives any error that occurs during this call, otherwise, errors are ignored
*/
void rs2_config_enable_device_from_file_repeat_option(rs2_config* config, const char* file, int repeat_playback, rs2_error ** error);

/**
* Requires that the resolved device would be recorded to file
* This request cannot be used if enable_device_from_file() is called for the current config, and vise versa
Expand Down
4 changes: 2 additions & 2 deletions include/librealsense2/hpp/rs_pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ namespace rs2
*
* \param[in] file_name The playback file of the device
*/
void enable_device_from_file(const std::string& file_name)
void enable_device_from_file(const std::string& file_name, bool repeat_playback = true)
{
rs2_error* e = nullptr;
rs2_config_enable_device_from_file(_config.get(), file_name.c_str(), &e);
rs2_config_enable_device_from_file_repeat_option(_config.get(), file_name.c_str(), repeat_playback, &e);
error::handle(e);
}

Expand Down
9 changes: 7 additions & 2 deletions src/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace librealsense
_device_request.serial = serial;
}

void pipeline_config::enable_device_from_file(const std::string& file)
void pipeline_config::enable_device_from_file(const std::string& file, bool repeat_playback = true)
{
std::lock_guard<std::mutex> lock(_mtx);
if (!_device_request.record_output.empty())
Expand All @@ -118,6 +118,7 @@ namespace librealsense
}
_resolved_profile.reset();
_device_request.filename = file;
_playback_loop = repeat_playback;
}

void pipeline_config::enable_record_to_file(const std::string& file)
Expand Down Expand Up @@ -379,6 +380,10 @@ namespace librealsense
return default_profiles;
}

bool pipeline_config::get_repeat_playback() {
return _playback_loop;
}

/*
.______ __ .______ _______ __ __ .__ __. _______
| _ \ | | | _ \ | ____|| | | | | \ | | | ____|
Expand Down Expand Up @@ -510,7 +515,7 @@ namespace librealsense
{
//If the pipeline holds a playback device, and it reached the end of file (stopped)
//Then we restart it
if (_active_profile)
if (_active_profile && _prev_conf->get_repeat_playback())
{
_active_profile->_multistream.open();
_active_profile->_multistream.start(syncer_callback);
Expand Down
5 changes: 4 additions & 1 deletion src/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ namespace librealsense
void enable_stream(rs2_stream stream, int index, int width, int height, rs2_format format, int framerate);
void enable_all_stream();
void enable_device(const std::string& serial);
void enable_device_from_file(const std::string& file);
void enable_device_from_file(const std::string& file, bool repeat_playback);
void enable_record_to_file(const std::string& file);
void disable_stream(rs2_stream stream, int index = -1);
void disable_all_streams();
std::shared_ptr<pipeline_profile> resolve(std::shared_ptr<pipeline> pipe, const std::chrono::milliseconds& timeout = std::chrono::milliseconds(0));
bool can_resolve(std::shared_ptr<pipeline> pipe);
bool get_repeat_playback();

//Non top level API
std::shared_ptr<pipeline_profile> get_cached_resolved_profile();
Expand All @@ -103,6 +104,7 @@ namespace librealsense
_enable_all_streams = other._enable_all_streams;
_stream_requests = other._stream_requests;
_resolved_profile = nullptr;
_playback_loop = other._playback_loop;
}
private:
struct device_request
Expand All @@ -120,6 +122,7 @@ namespace librealsense
std::mutex _mtx;
bool _enable_all_streams = false;
std::shared_ptr<pipeline_profile> _resolved_profile;
bool _playback_loop;
};

}
11 changes: 10 additions & 1 deletion src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1471,12 +1471,21 @@ void rs2_config_enable_device(rs2_config* config, const char* serial, rs2_error
}
HANDLE_EXCEPTIONS_AND_RETURN(, config, serial)

void rs2_config_enable_device_from_file_repeat_option(rs2_config* config, const char* file, int repeat_playback, rs2_error ** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(config);
VALIDATE_NOT_NULL(file);

config->config->enable_device_from_file(file, repeat_playback);
}
HANDLE_EXCEPTIONS_AND_RETURN(, config, file)

void rs2_config_enable_device_from_file(rs2_config* config, const char* file, rs2_error ** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(config);
VALIDATE_NOT_NULL(file);

config->config->enable_device_from_file(file);
config->config->enable_device_from_file(file, true);
}
HANDLE_EXCEPTIONS_AND_RETURN(, config, file)

Expand Down
2 changes: 1 addition & 1 deletion wrappers/python/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ PYBIND11_MODULE(NAME, m) {
.def("enable_stream", (void (rs2::config::*)(rs2_stream, int, rs2_format, int)) &rs2::config::enable_stream, "stream_type"_a, "stream_index"_a, "format"_a, "framerate"_a = 0)
.def("enable_all_streams", &rs2::config::enable_all_streams)
.def("enable_device", &rs2::config::enable_device, "serial"_a)
.def("enable_device_from_file", &rs2::config::enable_device_from_file, "file_name"_a)
.def("enable_device_from_file", &rs2::config::enable_device_from_file, "file_name"_a, "repeat_playback"_a = true)
.def("enable_record_to_file", &rs2::config::enable_record_to_file, "file_name"_a)
.def("disable_stream", &rs2::config::disable_stream, "stream"_a, "index"_a = -1)
.def("disable_all_streams", &rs2::config::disable_all_streams)
Expand Down

0 comments on commit 2ac4722

Please sign in to comment.