thaytan/gst-rpicamsrc

Pausing rpicamsrc

Swap-File opened this issue · 1 comments

I'm using the Pi camera with a project that needs to regularly pause and restart the camera quickly.

If I set a pipeline using rpicamsrc back and forth between GST_STATE_PAUSED and GST_STATE_PLAYING enough times in my C program, eventually the camera starts to take longer and longer to come back from being paused, and eventually it stops working entirely. If I keep destroying the entire pipeline and recreating it in my C program, I don't get any increasing lag while restarting it, but eventually gstreamer stops responding. Simple pipelines not involving Pi hardware related elements behave fine. If I had to guess, in both cases it seems like something is leaking MMAL resources, but it is beyond my skill to pinpoint it.

In the past I have used raspivid piped into gstreamer via fdsrc without trouble. Then I could toggle raspivid between paused and playing via signals. This still works, but it is more CPU intensive than rpicamsrc.

As a quick and dirty hack, I added some code to rpicamsrc to listen for the signals SIGHUP (to stop) and SIGCONT (to start) the stream. This lets me load up a gstreamer pipeline with rpicamsrc, then find the pid of gstreamer, and then send gstreamer signals that the rpicamsrc plugin sees to stop and start the stream. Note: I couldn't use SIGUSR1 (and SIGUSR2) like I use to in raspivid since gstreamer already listens for them elsewhere.

https://gist.github.com/Swap-File/05d3e4dac21563b542c1576dfdaae4ec

This is good enough for me, but do you happen to have any suggestions on a better generic solution?

This problem was initially noticed under Raspbian Stretch Lite on my Pi3. I recently retested on a Pi4 with Raspbian Buster Lite and had no problems.

I had an exerciser program pause and play a pipeline with rpicamsrc in it every 3 seconds for 6 hours, and noticed no degradation or leakage.