Bug 1491

Summary: GLMediaPlayer: Remove resource restrictions and locking with shared GLContext (*GraphicsDevice)
Product: [JogAmp] Jogl Reporter: Sven Gothel <sgothel>
Component: videoAssignee: Sven Gothel <sgothel>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P4    
Version: 2.6.0   
Hardware: All   
OS: all   
Type: FEATURE SCM Refs:
76487cd34ba706bee6c122a1cbbc75f5639eb4a4 18afa5200983bb158e631c81f2df1ca1a45cd882 78812de21182e32f86a823321b017f7f6cf52ae3
Workaround: ---
Bug Depends on:    
Bug Blocks: 805    

Description Sven Gothel 2024-01-25 09:41:23 CET
In a use case with hundreds of GLMediaPlayer instances, 
this causes the application to bail out due to running out of resources.

+++

GLMediaPlayer exposes resource restrictions and locking related
with the created off-thread shared GLContext 
due to its newly created NativeWindow *GraphicsDevice instance (on X11).

On the X11 platform, the *GraphicsDevice actually uses a native resource (X11 Display handle) and hence creating such device is costly and limited.

To operate an off-thread GLContext w/o actual X11 input handling, 
it is *NOT* required to use a new instance.

+++

Further more, the device is using locking.
To operate an off-thread GLContext, it is *NOT* required to use locking on it
as it does not perform actual X11 input handling etc.
All operations are performed on the shared GL context.

+++

Solution is to create a shared non-locking device clone 
compatible with the source.
A share counter shall determine that the last one actually gets destructed.
The usual ..
Comment 1 Sven Gothel 2024-01-25 09:42:17 CET
commit 76487cd34ba706bee6c122a1cbbc75f5639eb4a4

    NativeWindowFactory.createDevice(..) w/ unitID for cloning; DefaultGraphicsDevice: Move ownership (Object) code into base class ensuring same code
    
    NativeWindowFactory.createDevice(..) w/ unitID
    - Allows cloning a device instance with same parameter.
    
    DefaultGraphicsDevice: Move ownership (Object) code final into base class ensuring same code
    - Rename DefaultGraphicsDevice.swapDeviceHandleAndOwnership() -> swapHandleAndOwnership()
Comment 2 Sven Gothel 2024-01-25 09:44:02 CET
(In reply to Sven Gothel from comment #1)
commit 18afa5200983bb158e631c81f2df1ca1a45cd882

    Bug 1491: Add missing rename DefaultGraphicsDevice.swap{Device->}HandleAndOwnership()
Comment 3 Sven Gothel 2024-01-25 09:50:31 CET
commit 78812de21182e32f86a823321b017f7f6cf52ae3
Bug 1491: FFMPEGMediaPlayer: Lock moviePtr lifecycle phase in-between [initStreamImpl - destruction]

initStreamImpl() calls ffmpeg natives.setStream0(..), which in turn callsback to the GLMediaPlayerImpl 
and FFMPEGPlayer and hence requires a valid moviePtr. In total, it covers a longer time period.

This patch uses a moviePtrLock object avoiding destruction while within initStreamImpl.
Comment 4 Sven Gothel 2024-01-25 09:55:13 CET
commit 8fe39d3a524e5e580cf2667988965f1e27fed95b
Bug 1491: GLMediaPlayerImpl: Use a shared *GraphicsDevice for all compatible shared GLContext, removing resource restrictions

implemented as described.

+++

We may consider reusing this solution adding a GraphicsDevice shared resource handler class for other similar (if not same) cases.
Comment 5 Sven Gothel 2024-01-25 11:46:11 CET
See a demos w/ > 200 GLMediaPlayer instance running in a GraphUI Ranged Group,
having 36 instances being visible and displaying new decoded images.

https://jausoft.com/blog/wp-content/uploads/2024/01/UIMediaGrid01-norm-q1-s01-fsaa4-media-snap22b-1920x1080-1.jpg