Index: sync.c =================================================================== --- sync.c (revision 974) +++ sync.c (working copy) @@ -306,6 +306,7 @@ { while( ( sub = hb_fifo_get( pv->subtitle->fifo_raw ) ) ) { + hb_log("Trashing subtitle 0x%x", sub); hb_buffer_close( &sub ); } } @@ -336,9 +337,34 @@ if( sub2 && sub->stop > sub2->start ) sub->stop = sub2->start; - if( sub->stop > cur->start ) + if( sub->stop > cur->start ) { + /* + * The stop time is in the future + */ + hb_log("0x%x: Video is at %lld substart=%lld substop=%lld, applying subtitle", + sub, cur->start, sub->start, sub->stop); break; + } + else + { + /* + * The stop time is in the past. But is it due to it having been + * played already, or has the PTS been reset to 0? + */ + if( ( cur->start - sub->stop ) > PTS_DISCONTINUITY_TOLERANCE ) { + /* + * There is a lot of time between our current video and where + * this subtitle is ending, assume that we are about to reset + * the PTS and do not throw away this subtitle. + */ + break; + } + } + + hb_log("0x%x: *** Video is at %lld substart=%lld substop=%lld, trashing subtitle", + sub, cur->start, sub->start, sub->stop); + /* The subtitle is older than this picture, trash it */ sub = hb_fifo_get( pv->subtitle->fifo_raw ); hb_buffer_close( &sub ); @@ -349,6 +375,7 @@ keep it for later */ if( sub && sub->start > cur->start ) { + hb_log("0x%x: Subtitle too early, wait", sub); sub = NULL; } }