aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Göthel <[email protected]>2024-01-28 22:01:28 +0100
committerSven Göthel <[email protected]>2024-01-28 22:01:28 +0100
commit3e95c1994d363bc137ffcf548fd3751ac500ac7b (patch)
tree29aaef978ce7db146a0c80c25a3c36c771b7e49d
parentc5bca1f0dba2540088e8e2a90d720fdbc4870b30 (diff)
FFMPEGMediaPlayer/GraphUI MediaButton: AVSubtitles's start/end are relative to pts [ms] (fixed); Use ASSEventLine packets within proper pts only.
-rw-r--r--src/graphui/classes/com/jogamp/graph/ui/shapes/MediaButton.java52
-rw-r--r--src/jogl/native/libav/ffmpeg_impl_template.c4
2 files changed, 34 insertions, 22 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);
}
}
diff --git a/src/jogl/native/libav/ffmpeg_impl_template.c b/src/jogl/native/libav/ffmpeg_impl_template.c
index d6a251c07..5261c8443 100644
--- a/src/jogl/native/libav/ffmpeg_impl_template.c
+++ b/src/jogl/native/libav/ffmpeg_impl_template.c
@@ -1804,8 +1804,8 @@ JNIEXPORT jint JNICALL FF_FUNC(readNextPacket0)
int32_t sPTS=-1, sStart=-1, sEnd=-1;
if( AV_NOPTS_VALUE != sub.pts ) {
sPTS = my_av_q2i32( sub.pts * 1000, AV_TIME_BASE_Q);
- sStart = my_av_q2i32( ( sub.pts + sub.start_display_time ) * 1000, AV_TIME_BASE_Q);
- sEnd = my_av_q2i32( ( sub.pts + sub.end_display_time ) * 1000, AV_TIME_BASE_Q);
+ sStart = sPTS + sub.start_display_time;
+ sEnd = sPTS + sub.end_display_time;
}
for(unsigned int i=0; i<sub.num_rects; ++i) {
AVSubtitleRect* r = sub.rects[i];