- /* There has been a PTS discontinuity, and this frame might
- be from before the discontinuity*/
-
- 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 );
- }
-
- /*
- * Is the audio from a valid period given the previous
- * Video PTS. I.e. has there just been a video PTS
- * discontinuity and this audio belongs to the vdeo from
- * before?
- */
- if( buf->start > pts_expected + PTS_DISCONTINUITY_TOLERANCE ||
- buf->start < pts_expected - PTS_DISCONTINUITY_TOLERANCE )
- {
- /*
- * It's outside of our tolerance for where the video
- * is now, and it's outside of the tolerance for
- * where we have been in the case of a VOB change.
- * Try and reconverge regardless. so continue on to
- * our convergence code below which will kick in as
- * it will be more than 100ms out.
- *
- * Note that trashing the Audio could make things
- * worse if the Audio is in front because we will end
- * up diverging even more. We need to hold on to the
- * audio until the video catches up.
- */
- if( !pv->way_out_of_sync )
- {
- hb_log("Sync: Audio is way out of sync, attempt to reconverge from current video PTS");
- pv->way_out_of_sync = 1;
- }
-
- /*
- * It wasn't from the old place, so we must be from
- * the new, but just too far out. So attempt to
- * reconverge by resetting the point we want to be to
- * where we are currently wanting to be.
- */
- pts_expected = pv->pts_offset + sync->count_frames * 90000 / rate;
- start = pts_expected - pv->pts_offset;
- } else {
- /* Use the older offset */
- start = pts_expected - pv->pts_offset_old;
- }