Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support in configuring recorder compression mode #2687

Merged
merged 4 commits into from
Nov 22, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMake/realsense.def
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ EXPORTS
rs2_load_json
rs2_serialize_json

rs2_create_record_device
rs2_create_record_device
rs2_create_record_device_ex
rs2_record_device_pause
rs2_record_device_resume
rs2_record_device_filename
Expand Down
11 changes: 11 additions & 0 deletions include/librealsense2/h/rs_record_playback.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef enum rs2_playback_status
RS2_PLAYBACK_STATUS_STOPPED, /**< All sensors were stopped, or playback has ended (all data was read). This is the initial playback status*/
RS2_PLAYBACK_STATUS_COUNT
} rs2_playback_status;

const char* rs2_playback_status_to_string(rs2_playback_status status);

typedef void (*rs2_playback_status_changed_callback_ptr)(rs2_playback_status);
Expand All @@ -37,6 +38,16 @@ typedef void (*rs2_playback_status_changed_callback_ptr)(rs2_playback_status);
*/
rs2_device* rs2_create_record_device(const rs2_device* device, const char* file, rs2_error** error);

/**
* Creates a recording device to record the given device and save it to the given file
* \param[in] device The device to record
* \param[in] file The desired path to which the recorder should save the data
* \param[in] compression_enabled Indicates if compression is enabled, 0 means false, otherwise true
* \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored
* \return A pointer to a device that records its data to file, or null in case of failure
*/
rs2_device* rs2_create_record_device_ex(const rs2_device* device, const char* file, int compression_enabled, rs2_error** error);

/**
* Pause the recording device without stopping the actual device from streaming.
* Pausing will cause the device to stop writing new data to the file, in particular, frames and changes to extensions
Expand Down
16 changes: 16 additions & 0 deletions include/librealsense2/hpp/rs_record_playback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,22 @@ namespace rs2
rs2::error::handle(e);
}

/**
* Creates a recording device to record the given device and save it to the given file as rosbag format
* \param[in] file The desired path to which the recorder should save the data
* \param[in] device The device to record
* \param[in] compression_enabled Indicates if compression is enabled
*/
recorder(const std::string& file, rs2::device device, bool compression_enabled)
{
rs2_error* e = nullptr;
_dev = std::shared_ptr<rs2_device>(
rs2_create_record_device_ex(device.get().get(), file.c_str(), compression_enabled, &e),
rs2_delete_device);
rs2::error::handle(e);
}


/**
* Pause the recording device without stopping the actual device from streaming.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/core/streaming.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ namespace librealsense
virtual std::vector<tagged_profile> get_profiles_tags() const = 0;

virtual void tag_profiles(stream_profiles profiles) const = 0;

virtual bool compress_while_record() const = 0;
};

class depth_stereo_sensor;
Expand Down
2 changes: 2 additions & 0 deletions src/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ namespace librealsense

void tag_profiles(stream_profiles profiles) const override;

virtual bool compress_while_record() const override { return true; }

protected:
int add_sensor(std::shared_ptr<sensor_interface> sensor_base);
int assign_sensor(std::shared_ptr<sensor_interface> sensor_base, uint8_t idx);
Expand Down
2 changes: 2 additions & 0 deletions src/media/playback/playback_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace librealsense
for(auto profile : profiles)
profile->tag_profile(profile_tag::PROFILE_TAG_DEFAULT | profile_tag::PROFILE_TAG_SUPERSET);
}

bool compress_while_record() const override { return true; }

private:
void update_time_base(device_serializer::nanoseconds base_timestamp);
Expand Down
2 changes: 1 addition & 1 deletion src/media/record/record_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace librealsense

std::vector<tagged_profile> get_profiles_tags() const override { return m_device->get_profiles_tags(); };
void tag_profiles(stream_profiles profiles) const override { m_device->tag_profiles(profiles); }

bool compress_while_record() const override { return true; }
private:
template <typename T> void write_device_extension_changes(const T& ext);
template <rs2_extension E, typename P> bool extend_to_aux(std::shared_ptr<P> p, void** ext);
Expand Down
8 changes: 6 additions & 2 deletions src/media/ros/ros_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ namespace librealsense
class ros_writer: public writer
{
public:
explicit ros_writer(const std::string& file) : m_file_path(file)
explicit ros_writer(const std::string& file, bool compress_while_record) : m_file_path(file)
{
LOG_INFO("Compression while record is set to " << (compress_while_record ? "ON" : "OFF"));
m_bag.open(file, rosbag::BagMode::Write);
m_bag.setCompression(rosbag::CompressionType::LZ4);
if (compress_while_record)
{
m_bag.setCompression(rosbag::CompressionType::LZ4);
}
write_file_version();
}

Expand Down
2 changes: 1 addition & 1 deletion src/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ namespace librealsense
if (!dev)
throw librealsense::invalid_value_exception("Failed to create a pipeline_profile, device is null");

_dev = std::make_shared<record_device>(dev, std::make_shared<ros_writer>(to_file));
_dev = std::make_shared<record_device>(dev, std::make_shared<ros_writer>(to_file, dev->compress_while_record()));
}
_multistream = config.resolve(_dev.get());
}
Expand Down
14 changes: 12 additions & 2 deletions src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1295,15 +1295,25 @@ void rs2_playback_device_stop(const rs2_device* device, rs2_error** error) BEGIN
HANDLE_EXCEPTIONS_AND_RETURN(, device)

rs2_device* rs2_create_record_device(const rs2_device* device, const char* file, rs2_error** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(device);
VALIDATE_NOT_NULL(device->device);
VALIDATE_NOT_NULL(file);

return rs2_create_record_device_ex(device, file, device->device->compress_while_record(), error);
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device, device->device, file)

rs2_device* rs2_create_record_device_ex(const rs2_device* device, const char* file, int compression_enabled, rs2_error** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(device);
VALIDATE_NOT_NULL(file);

return new rs2_device({
device->ctx,
device->info,
std::make_shared<record_device>(device->device, std::make_shared<ros_writer>(file))
});
std::make_shared<record_device>(device->device, std::make_shared<ros_writer>(file, compression_enabled))
});
}
HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device, file)

Expand Down
1 change: 1 addition & 0 deletions src/tm2/tm-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace librealsense
{
return std::vector<tagged_profile>();
};
bool compress_while_record() const override { return false; }
private:
static const char* tm2_device_name()
{
Expand Down