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

Unable to Stop Realsense Pipeline! [C++] #2743

Closed
HippoEug opened this issue Nov 19, 2018 · 11 comments
Closed

Unable to Stop Realsense Pipeline! [C++] #2743

HippoEug opened this issue Nov 19, 2018 · 11 comments
Assignees

Comments

@HippoEug
Copy link

Required Info
Camera Model D400
Firmware Version 05.09.02.00
Operating System & Version Win 10
Kernel Version (Linux Only)
Platform PC
SDK Version 2.16.1
Language C++
Segment others

Introduction

Hi! I am trying to convert/split a .bag file into .csv and .png for further data analytics. However, I am unable to stop the pipeline when the conversion is complete. I borrowed most of the conversion code from rs-convert.exe.

Goal

For example, given a .bag file, in this case record.bag, I am able to produce realsense_Color_7.png, realsense_Depth_5.png, and most importantly realsense_Depth_5.csv.

image

Issue

After conversion, I have confirmed the realsense_Color_7.png, realsense_Depth_5.png, and realsense_Depth_5.csv opens just fine, but the pipeline refuses to close, resulting in a Not Responding Program since my conversion function is written as a blocking one.

Conversion Function Code:

if (convert_bag_button) {
	rs2::config convertConfig;
	std::vector<std::shared_ptr<rs2::tools::converter::converter_base>> convertToCSV;
	std::vector<std::shared_ptr<rs2::tools::converter::converter_base>> convertToPNG;

	convertToCSV.push_back(std::make_shared<rs2::tools::converter::converter_csv>("realsense"));
	convertToPNG.push_back(std::make_shared < rs2::tools::converter::converter_png>("realsense"));
	convertConfig.enable_device_from_file("record.bag");

	pipe->stop();
	pipe->start(convertConfig);
	auto device = pipe->get_active_profile().get_device();
	rs2::playback playback = device.as<rs2::playback>();
	playback.set_real_time(false);
	auto duration = playback.get_duration();
	int progress = 0;
	int frameNumber = 0ULL;

	while (true) {
		auto frameset_c = pipe->wait_for_frames();

		if (frameset_c[0].get_frame_number() == 5 || frameset_c[0].get_frame_number() == 6 || frameset_c[0].get_frame_number() == 7) { // If end of frame, bag loops again, hence get_frame_number resets to 1 and is smaller
			std::for_each(convertToCSV.begin(), convertToCSV.end(), [&frameset_c](std::shared_ptr<rs2::tools::converter::converter_base>& converter) {
				converter->convert(frameset_c);
			});
			std::cout << "\nCONVERTING CSV" << std::endl;
			std::for_each(convertToCSV.begin(), convertToCSV.end(), [](std::shared_ptr<rs2::tools::converter::converter_base>& converter) {
				converter->wait();
			});
			std::cout << "CONVERTING PICTURES" << std::endl;
			std::for_each(convertToPNG.begin(), convertToPNG.end(), [&frameset_c](std::shared_ptr<rs2::tools::converter::converter_base>& converter) {
				converter->convert(frameset_c);
			});
			std::for_each(convertToPNG.begin(), convertToPNG.end(), [](std::shared_ptr<rs2::tools::converter::converter_base>& converter) {
				converter->wait();
			});
			break;
		}

		frameNumber = frameset_c[0].get_frame_number();
	}

	std::cout << "\nDONE!" << std::endl << std::endl; // EXECUTES

	pipe->stop();
	std::cout << "HERE" << std::endl; // DOES NOT EXECUTE
	pipe->start(standardConfig);
			
	convert_bag_button = false;
}

image

Reason

I would like to stop the pipeline because the pipeline is with the configuration convertConfig.enable_device_from_file("record.bag");, and after this conversion I would like to restart the pipeline with a configuration for streaming Color and/or Depth (pipe->start(standardConfig);)

End

I have tested with just CSV conversion without PNG conversion, with the same results. The pipeline would not stop. Any ideas on how I would fix this is appreciated. Many thanks!

@HippoEug
Copy link
Author

Hello @RealSense-Customer-Engineering , any updates on what I could change to fix this? Many thanks!! 👍 😺

@Tuebel
Copy link

Tuebel commented Jan 4, 2019

I have experienced the same issue. The problem seems to be this line:
playback.set_real_time(false);
If i use playback.set_real_time(true); the pipeline stops as expected.

@HippoEug
Copy link
Author

HippoEug commented Jan 7, 2019

Hello @Tuebel , i will give this a shot. Thank you very much!!

@HippoEug
Copy link
Author

HippoEug commented Jan 7, 2019

This works @Tuebel, thank you very much!! Any idea why this solves it?

@Tuebel
Copy link

Tuebel commented Jan 9, 2019

@HippoEug Nope this was just a lucky shot.
I didn't have time to look into the source code of librealsense yet.
But as I would like to use the non-real-time functionality this issue is still relevant for ne.

@RealSense-Customer-Engineering
Copy link
Collaborator

[Realsense Customer Engineering Team Comment]
HI HippoEug,

Is the workaround suggested by Tuebel working for you?

Thanks!

@HippoEug
Copy link
Author

Hi @RealSense-Customer-Engineering , the workaround works. However, it would be nice to have an explanation of why simply changing this parameter fixes this issue. Is this a bug? Good to know in case there are any side effects (which I have not discovered so far)

@mcasl
Copy link

mcasl commented Jan 29, 2019

Similar behavior using Python in this related issue:
#3126

@RealSenseCustomerSupport
Copy link
Collaborator


HI HippoEug,

Wonder if there is any update?

Thanks!

@RealSenseCustomerSupport
Copy link
Collaborator


Hi HippoEug,

Wonder if you have any any update or still need help on this one?

Thanks!

@soarwing52
Copy link

@RealSense-Customer-Engineering @RealSenseCustomerSupport
I'm using the latest python wrapper but still get the freeze situation.
I can either set_real_time(True) which will skip frames

or enable_device_from_file(filename,False)
and
try:
except RuntimeError:

only this can stop the pipeline and keep the program running
which either is not so ideal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants