-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
gstream omxh264enc causes a stall and locks the raspberry pi 4 UI #1426
Comments
When you create an issue you should be presented with a template, which includes a request for a load of information on firmware and kernel versions being used, and ideally any logs that you can retrieve.
Seeing as it was a bug in the FFmpeg code, why would it change anything in GStreamer? Which version of GStreamer are you using? Rasbian has a couple of bug fixes in gstreamer-1.0-onx-rpi, including the equivalent to the fix applied to FFmpeg. If you've built GStreamer from scratch then you would want to also pick up that patch. |
Hey 6by9, thanks for your reply. I'm not sure why but I don't remember the "write" section for New issue having a description in it when I made this ticket yesterday. I attempted to make another ticket now and it was indeed populated. Below are some of the details regarding the various versions that it says to provide as well as the gstreamer version you requested.
My initial hope was that this might have been the same issue that was fixed for ffmpeg that had not yet been fixed for gstreamer but this does not appear to be the case. The version I am using is the one installed via regular apt-get install gstreamer1.0-tools (I am not building from source). I have noticed that if I reboot and am careful not to do anything that might result in dropped packets/data I am able to have a stream work for over 1-2 hours. I am going to try and hookup a seperate mouse and monitor to another raspberry pi to test over wifi to see the frequency of the issue. If gstreamer were just crashing or pegging the CPU I would take the issue there, but what happens is a total lockup of the system with a low cpu load of 0% to 1% for gst-launch-1.0 If there are any other details I missed or that might be of assistance please let me know. I included the gstreamer debug output in my original post. I'm unsure what precise output from dmesg would be of interest but I'm happy to try and get some logs from that too. |
So afew more data points.
Just afew notes about things I tried to see if I could reduce the number of steps that caused the issue to occur or reduce it's frequency significantly enough that it did not occur for at least 5 minutes.
If there are any other data points you want me to obtain by trying to eliminate specific steps from the repro steps above let me know. This seems to be a bit of a tricky issue to reproduce as it appears like it may need the system to be experiencing a specific type of load to end up in the state which causes things to lock up. I had read something about omxh264enc perhaps using zerocopy that could result in systems locking up, but I'm unsure of what specifically that means and if it might be related. Also I realize this is an unrelated bug, but I'm throwing the details in here just incase it's indicative of a larger issue that may be causing both problems. I am unable to use gstreamer "omxh264dec" as it appears something may have been built incorrectly relating to it. (this does work fine when plugging the same sdcard into my raspberry pi 3b+ so the issue is specific to raspberry pi 4 and it's firmware)
|
One last point, I swapped out the webcam as the video source for a raspberry pi camera. I continued to bring the data in via "v4l2src device=/dev/videoNNN do-timestamp=1" (where N is the dev for the native raspberry pi camera now). I was unable to cause the issue. Even when I tried unplugging keyboard, mouse and monitor and opening many chrome tabs, it continued to function for over 10 minutes. I'm not sure how using the usb webcam could be related but it appears it may be in some way. This also fits with the case I mentioned earlier where I was unable to reproduce the issue using videotestsrc instead of the usb camera. |
omxh264dec is broken on Pi4 as they try to merge video_decode with the firmware GLES egl_render component, the latter of which is incompatible with the updated 3D block on the Pi4. The recommendation is to switch from the OMX codec components to the V4L2 ones as they are also more efficient in terms of copying behaviour. It's the same underlying encoder/decoder, but the frameworks allow more efficient buffer passing. You may even be able to skip the (software) videoconvert with v4l2h264enc as it supports a greater number of input formats. It depends on exactly what format your webcam is producing. Your command lines don't appear to force any particular format, so your webcam, Pi camera, and videotestsrc could all be producing different formats.
|
Thanks so much for your suggestions. The last suggestions reduced gstreamer cpu utilization by between 5% and 10% down to around 20% from 27%. Unfortunately the issue still persists when I use a USB webcamera. I have two identical web cameras and was able to confirm that the issue occurs identically for both cameras so I don't think it is a hardware fault in the camera (and even if it was it wouldn't expect it to cause the UI to lock with low CPU figures). For reference the latest command I'm using is the one you suggested.
I've uploaded the full GST_DEBUG=5 log output to the following zip file https://www.udrop.com/SMc/gst_007.zip it's 24 MB uncompressed. Basically the highlights are the following.
I'm starting to wonder why this lock-up only happens when using the usb webcam and not the pi camera through the custom connector. Perhaps it is a USB firmware issue and not graphics? |
If it crashes only on a Pi4, and only with a USB webcam, then I'm suspecting a USB issue not one in the codec. Can you confirm the USB chipset firmware in use? See https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=273027 |
Thanks for the fast reply.
|
Hey 6by9 did you want me to attempt to upgrade or downgrade my firmware? Also please let me know if I should close this issue as it appears to be a USB firmware issue and not an issue related to the hardware accelerated encoding. I can close it if you feel it is appropriate. I will probably make use of the pi camera module anyways instead of a webcam due to these issues preventing further development for now. Also unrelated to this issue but related to your earlier suggestion about using v4l2h264dec. It appears there is some issue with v4l2h264dec where it dies when run over wlan0 due to missing packets I presume (It works fine when run over eth0). This is documented well by another user who hit it over half a year ago https://stackoverflow.com/questions/57946999/problem-when-playing-rtsp-stream-with-gstreamer. I appear to be having the exact same issue. Since omxh264dec doesn't work on pi4 I'm going to need to try and find some way to work around it. Are there any instructions your aware of that talk about how to build v4l2h264dec (and/or the gst-plugins-good repo that it's included in). I wasn't sure if it was good enough to follow any normal build instructions or if some raspberrypi specific patches needed to be applied to the base repo before attempting to build. Perhaps there is a script that already exists that is used to build the deb modules in the raspberrypi distribution. I expect in order to file a bug ticket related to v4l2h264dec and help test any potential fix I am going to need to be able to build gstream from source. (Sorry for the unrelated question) |
So just to update you I did try updating the VL805 firmware to 000138a1 as per your link. Before (and after) attempting the update I also tried setting the usb chipset power saving mode to 0x40, 0x41 and the default 0x43 as per. I found that setting the power mode whilst on 000137ad didn't appear to make any difference for some reason. By this I mean that when using 000137ad (with any mode) or 000138a1 (with 0x43) the UI would freeze up (or all usb input would be dropped, hard to tell which) for about 5-10 seconds at a time then return for afew milliseconds. When using 000138a1 with 0x40 or 0x41 the UI would freeze up for 3 seconds, come back for about 500ms then freeze up for 1-2 second come back for 500 ms then go away for 1-2 seconds, this made it much easier to recover from the hung (dropped USB) state. One last thing if I run my webcam at 320x240 yuyv instead of 640x480 yuyv or 800x448 yuyv it doesn't cause the USB to fail, so I'm pretty sure it's a throughput issue, perhaps related to how fast the cpu is able to pull data out of some usb chpset queue, due the cpu is being busy doing other things I've asked of it. Maybe the pi 3b+ has some different interrupt scheme or queue or something... In short it seems the raspberry pi 4 USB support for USB2 hi speed is most likely the cause of the hanging, it's a shame that despite all your teams efforts over the last year the performance for USB2 is still not as good as the pi 3b+. Do you have any idea if it will ever be as good or is there some fundamental change in how the data is handled (beyond the totally different USB chipset). I was able to build gstreamer from source and the issue with it hanging in 1.42 is resolved in 1.62 and was able to get a system working with the raspberry pi camera module that will do what I need for now. I'm going to close this issue as it seems you and your team are away of the USB issues already and actively working on resolving them still. I wish you the best of luck. |
I've tested the following steps on a raspberry pi 3b+ and 4. On the 3b+ everything works fine however on the 4 it crashes after 1-2 minutes. I can trigger the crash faster by unplugging my keyboard, mouse and monitor and re-plugging them back in, but it isn't necessary to cause the issue.
I am hoping that this may be related to the issue fixed for ffmpeg over a year ago #1087
The patch for the change that was required to ffmpeg is linked below, but I can't be certain it's the same issue.
https://trac.ffmpeg.org/ticket/7687
https://trac.ffmpeg.org/attachment/ticket/7687/0001-avcodec-omx-Fix-handling-of-fragmented-buffers.patch
The setup is to install the latest version of raspberry pi os on a new SD card, insert it in a raspberry pi 4 with a logitech c525 webcam attached, and then run the following commands.
The result is that stream goes out fine for a minute or two (one can confirm this by connecting via VLC), but then after 1-2 minutes the raspberry pi UI locks up. It becomes almost impossible to close the program as you can only interact with the UI every few seconds for afew milliseconds. The CPU is not pegged as confirmed by having top running in a parallel window which shows gst-launch-1.0 CPU usage at 0% to 1%. If you do manage to kill gst-launch-1.0 the system will return to normal, but the error will occur much more quickly the second time you attempt to start gst-launch-1.0.
The log file for gst-launch-1.0 when obtained after running "export GST_DEBUG=5" shows the following at the point where the UI was locked.
The last call before the UI locks up appears to be "omx gstomx.c:460:gst_omx_component_wait_message: video_encode waiting for signal".
I am unable to reproduce the issue on the raspberry pi 3b+ even if I unplug my mouse, keyboard and monitor and reconnect them. It appears to keep playing fine.
I am happy to try and roll back to different versions of the raspberry pi firmware to debug the issue as that appears to have allowed for isolation of the issue when debugging #1087 .
But I am unsure which firmware versions to attempt and which would be compatible with the kernel running on my system.
Please let me know how I can provide more information to help you trouble shoot the issue.
I will see if I can generate the same issue when streaming from a file (I suspect it should be possible). It appears that the issue randomly occurs more based on other interactions with the system that may be happening, more so than the nature of the media being encoded.
The text was updated successfully, but these errors were encountered: