+
+ if( pv->discontinuity )
+ {
+ /*
+ * There is an outstanding discontinuity, so use the offset from
+ * that discontinuity.
+ */
+ pts_expected = pv->pts_offset_old + sync->count_frames *
+ 90000 / rate;
+ }
+ else
+ {
+ /*
+ * No outstanding discontinuity, so the audio must be leading the
+ * video (or the PTS values are really stuffed). So lets mark this
+ * as a discontinuity ourselves for the audio to use until
+ * the video also crosses the discontinuity.
+ *
+ * pts_offset is used when we are in the same time space as the video
+ * pts_offset_old when in a discontinuity.
+ *
+ * Therefore set the pts_offset_old given the new pts_offset for this
+ * current buffer.
+ */
+ pv->discontinuity = 1;
+ pv->pts_offset_old = buf->start - sync->count_frames *
+ 90000 / rate;
+ pts_expected = pv->pts_offset_old + sync->count_frames *
+ 90000 / rate;
+
+ hb_log("Sync: Audio discontinuity (sequence: vid %lld aud %lld) (pts %lld < %lld < %lld)",
+ pv->video_sequence, buf->sequence,
+ pts_expected - PTS_DISCONTINUITY_TOLERANCE, buf->start,
+ pts_expected + PTS_DISCONTINUITY_TOLERANCE );
+ }