Nvv4l2h264enc and Nvv4l2h265enc remove EGLContext on JetPack 5.0.2

Hello there, hoping you can help me out with an issue we’re running into. We’re seeing that stopping a gstreamer pipeline with one of the hardware encoders in it destroys our EGLContext.

I have made a small sample program, which works on JetPack 4.4.1 (L4T 32.4.4), but fails on JetPack 5.0.2.

eglcontext-repro.cpp (2.0 KB)

You can compile it as follows:

g++ eglcontext-repo.cpp -o repro -I/usr/include/gstreamer-1.0/ -I/usr/lib/aarch64-linux-gnu/glib-2.0/include/ -I/usr/include/glib-2.0/ -I/usr/include -lEGL -lgstreamer-1.0

On JetPack 5.0.2:

Opening in BLOCKING MODE 
NvMMLiteOpen : Block : BlockType = 4 
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4 
H264: Profile = 66, Level = 0 
NVMEDIA: Need to set EMC bandwidth : 846000 
NVMEDIA: Need to set EMC bandwidth : 846000 
NVMEDIA_ENC: bBlitMode is set to TRUE 
tmp: tmp.cpp:66: int main(): Assertion `eglGetCurrentContext() != EGL_NO_CONTEXT && "CONTEXT IS NO LONGER CURRENT"' failed.
Aborted (core dumped)

On JetPack 4.4.1:

Opening in BLOCKING MODE 
NvMMLiteOpen : Block : BlockType = 4 
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4 
H264: Profile = 66, Level = 0 

When I replace the part from nvv4l2h264enc with fakesink, the assert passes.

Hoping you can help me out, thanks in advance!

Hi,
Thanks for sharing the test sample. We will check this and update.

1 Like

Hi,
It works fine by calling eglMakeCurrent() after terminating the gstreamer pipeline. Is this good to apply to your use-case?

Thank you for your response. I have tried using eglMakeCurrent and it does fix our problem.

In this simple example it is a lot easier to do than in our actual codebase, and it feels like some unintended behaviour from the encoder elements that we now have to work around. It would be much preferred to have an actual fix for the element(s) so the behaviour is consistent across JetPack versions.

Hi,
It looks fine to set to EGL_NO_CONTEXT after terminating a gstreamer pipeline. There are significant change between Jetpack 4 and 5, such as deprecating NvBuffer and using NvBufSurface. It is possible certain use-cases do not work same as Jetpack 4. Calling eglMakeCurrent() before using the context looks to be reasonable function calls.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.