diff options
author | Sven Göthel <[email protected]> | 2024-01-28 22:01:28 +0100 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-01-28 22:01:28 +0100 |
commit | 3e95c1994d363bc137ffcf548fd3751ac500ac7b (patch) | |
tree | 29aaef978ce7db146a0c80c25a3c36c771b7e49d /src/graphui/classes/com/jogamp/graph/ui | |
parent | c5bca1f0dba2540088e8e2a90d720fdbc4870b30 (diff) |
FFMPEGMediaPlayer/GraphUI MediaButton: AVSubtitles's start/end are relative to pts [ms] (fixed); Use ASSEventLine packets within proper pts only.
Diffstat (limited to 'src/graphui/classes/com/jogamp/graph/ui')
-rw-r--r-- | src/graphui/classes/com/jogamp/graph/ui/shapes/MediaButton.java | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/src/graphui/classes/com/jogamp/graph/ui/shapes/MediaButton.java b/src/graphui/classes/com/jogamp/graph/ui/shapes/MediaButton.java index 894ab5cb9..4c7e82dc1 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/shapes/MediaButton.java +++ b/src/graphui/classes/com/jogamp/graph/ui/shapes/MediaButton.java @@ -69,7 +69,7 @@ import com.jogamp.opengl.util.texture.TextureSequence.TextureFrame; * </p> */ public class MediaButton extends TexSeqButton { - private final boolean DEBUG = false; + private final boolean DEBUG_SUB = false; private boolean verbose = false; private final Label subLabel; @@ -136,7 +136,7 @@ public class MediaButton extends TexSeqButton { public void run(final ASSEventLine e) { synchronized( assEventLock ) { assEventQueue.add(e); - if( DEBUG ) { + if( DEBUG_SUB ) { System.err.println("MediaButton: GOT #"+assEventQueue.size()+": "+e); } } @@ -238,20 +238,46 @@ public class MediaButton extends TexSeqButton { assEventQueue.clear(); } } + private static final int SUB_MIN_DURATION = 5; // min duration 1s, broken ASS have <= 3ms private final void drawSubtitle(final GL2ES2 gl, final RegionRenderer renderer) { - // dequeue and earmark new subtitle + final GLMediaPlayer mPlayer = (GLMediaPlayer)texSeq; + final int pts = mPlayer.getPTS().get(Clock.currentMillis()); + + // Validate draw_lastASS timeout + ASSEventLine lastASS = draw_lastASS; + { + if( null != lastASS && lastASS.pts_end < pts && lastASS.getDuration() > SUB_MIN_DURATION ) { + if( DEBUG_SUB ) { + System.err.println("MediaButton: Drop.0: pts "+pts+", "+lastASS); + } + draw_lastASS = null; + lastASS = null; + } + } + // dequeue and earmark new subtitle in time final ASSEventLine ass; final boolean newASS; { final ASSEventLine gotASS; synchronized( assEventLock ) { if( assEventQueue.size() > 0 ) { - gotASS = assEventQueue.remove(0); + final ASSEventLine e = assEventQueue.get(0); + if( e.getDuration() <= SUB_MIN_DURATION || ( e.pts_start <= pts && pts <= e.pts_end ) ) { + gotASS = e; + assEventQueue.remove(0); + } else if( e.pts_end < pts ) { + gotASS = null; + assEventQueue.remove(0); + if( DEBUG_SUB ) { + System.err.println("MediaButton: Drop.1: pts "+pts+", "+e); + } + } else { + gotASS = null; + } } else { gotASS = null; } } - final ASSEventLine lastASS = draw_lastASS; if( null == gotASS || gotASS == lastASS ) { ass = lastASS; newASS = false; @@ -262,24 +288,10 @@ public class MediaButton extends TexSeqButton { } } // drop or draw (update label for new subtitle) - final GLMediaPlayer mPlayer = (GLMediaPlayer)texSeq; - final int pts; - { - // Well .. which one? So pick the lowest PTS to be more tolerant. - final int ptsS = mPlayer.getPTS().get(Clock.currentMillis()); - final int ptsV = mPlayer.getVideoPTS(); - pts = Math.min(ptsS, ptsV); - } final boolean drawASS; if( null == ass ) { draw_lastASS = null; drawASS = false; - } else if( ass.pts_end < pts && ass.getDuration() > 1000 ) { // min duration 1s, broken ASS have <= 3ms - if( DEBUG ) { - System.err.println("MediaButton: Drop: pts "+pts+", "+ass); - } - draw_lastASS = null; - drawASS = false; } else { drawASS = true; if( newASS ) { @@ -295,7 +307,7 @@ public class MediaButton extends TexSeqButton { final float dx = ( this.box.getWidth() - maxWidth ) * 0.5f; final float dy = subLineHeight * scale * 0.25f; this.subLabel.moveTo(dx, dy, subZOffset); - if( DEBUG ) { + if( DEBUG_SUB ) { System.err.println("MediaButton: NEXT pts "+pts+", "+ass); } } |