blackshard83
Posts: 91
Joined: Fri Jan 10, 2014 8:31 am

egl_render, hangs at cleanup

Mon Jun 03, 2019 7:40 am

Hello,

I made some changes to stock omxplayer to use egl_render to render into an EGLImageKHR resource using the egl_render component instead of usual video_render. It worked, but during the cleanup it freezed because the component hangs when it is going to OMX_StateLoaded state.

I checked hello_videocube sample and found the cleanup step does never happen. I modified slightly the code to let it happen and it freezes at the same point; egl_render refuses to enter OMX_StateLoaded.

I attach the modified hello_videocube sample with the video shutdown phase enabled for further debugging (note: binary is already provided in the tgz)

Thanks
Attachments
hello_videocube_with_cleanup.tgz
hello_videocube with shutdown phase
(72.62 KiB) Downloaded 27 times

dickon
Posts: 386
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: egl_render, hangs at cleanup

Mon Jun 03, 2019 10:31 pm

I don't have an answer, but OOI, do you *need* to do a cleanup? Can you not just exit, and let the system sort itself out?

blackshard83
Posts: 91
Joined: Fri Jan 10, 2014 8:31 am

Re: egl_render, hangs at cleanup

Tue Jun 04, 2019 7:29 am

dickon wrote:
Mon Jun 03, 2019 10:31 pm
I don't have an answer, but OOI, do you *need* to do a cleanup? Can you not just exit, and let the system sort itself out?
Well, it's not my use case. It should fit into a long running process, so it's not a viable option because it leaks resources, in particular it leaks the ppBufferHdr buffer allocated by OMX_UseEGLImage.

Digging into the problem revealed an apparently working solution:
- Do the usual stuff to tear down the tunnel and other components
- Change the egl_render state to idle and regularly wait for the event
- Change the egl_render state to loaded but do not wait for the event
- Use OMX_FreeBuffer on the ppBufferHdr to free the buffer previously allocated by OMX_UseEGLImage (OMX specs says that doing OMX_FreeBuffer at this point is legit)
- Use OMX_FreeHandle to release the component

edit: I opened a pull request with all the fixes to make hello_videocube and hello_teapot work as they should: <https://github.com/raspberrypi/userland ... 974c6ab5aa>

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7149
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: egl_render, hangs at cleanup

Tue Jun 04, 2019 9:48 am

I generally try to avoid having to dig into IL because it is horrid in handling state changes and the linked completion events.

The transition between Loaded and Idle always requires the allocation / deallocation of all buffers for enabled ports. See Section 3.4.1.1 and Figure 3-5. Component Initialization, and section 3.4.3.1 / Figure 3-14 De-initialization of Non-tunneled Components of the 1.1.2 spec.
3.4.3.1 Non-tunneled De-initialization
...
When the transition to OMX_StateIdle is completed, the IL client can request the
component to change its state to OMX_StateLoaded. The IL client shall free all of the
component’s buffers by calling OMX_FreeBuffer for each buffer. The
OMX_FreeBuffer function requires that the component remove the specified buffer
from the specified port.
...
When all of the buffers have been freed, the component shall complete the state transition.
In your case you had allocated buffers with OMX_UseEGLImage (a variant on OMX_UseBuffer), but hadn't called OMX_FreeBuffer, therefore the component correctly didn't send the completion event as buffers were still allocated.

The other option would be to disable port 221 first (and as with enabling you need to make the SendCommand call, and then OMX_FreeBuffer), and then the state change to Loaded should complete without further odd handling.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7149
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: egl_render, hangs at cleanup

Tue Jun 04, 2019 9:58 am

Having just had a quick look at the PR

Code: Select all

      // need to flush the renderer to allow video_decode to disable its input port
      ilclient_flush_tunnels(tunnel, 0);
      ilclient_disable_port_buffers(video_decode, 130, NULL, NULL, NULL);
   }
   fclose(in);
   ilclient_disable_tunnel(tunnel);
   ilclient_disable_tunnel(tunnel+1);
   ilclient_disable_tunnel(tunnel+2);
   ilclient_teardown_tunnels(tunnel);

   ilclient_state_transition(list, OMX_StateIdle);
   ilclient_state_transition(list, OMX_StateLoaded);
So it has disabled all ports except egl_render's output port before the state changes. The more consistent solution would therefore be to disable egl_render 221 as well (with the special handling to manually free the buffers).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

blackshard83
Posts: 91
Joined: Fri Jan 10, 2014 8:31 am

Re: egl_render, hangs at cleanup

Tue Jun 04, 2019 12:39 pm

Thanks a lot for looking into.
I tried the other approach (disable the output port, then do OMX_FreeBuffers and finally do the transition to Idle) and it works and it looks tidier. I updated the pull request with the new solution.

Return to “OpenMAX”