+ /* The PTS of the frame we are expecting now */
+ pts_expected = pv->pts_offset +
+ pv->count_frames * pv->job->vrate_base / 300;
+
+ //hb_log("Video expecting PTS %lld, current frame: %lld, next frame: %lld, cf: %lld",
+ // pts_expected, cur->start, next->start, pv->count_frames * pv->job->vrate_base / 300 );
+
+ if( cur->start < pts_expected - pv->job->vrate_base / 300 / 2 &&
+ next->start < pts_expected + pv->job->vrate_base / 300 / 2 )
+ {
+ /* The current frame is too old but the next one matches,
+ let's trash */
+ /* Also, make sure we don't trash a chapter break */
+ chap_break = cur->new_chap;
+ hb_buffer_close( &cur );
+ pv->cur = cur = hb_fifo_get( job->fifo_raw );
+ cur->new_chap |= chap_break; // Make sure we don't stomp the existing one.
+
+ continue;
+ }
+
+ if( next->start > pts_expected + 3 * pv->job->vrate_base / 300 / 2 )
+ {
+ /* We'll need the current frame more than one time. Make a
+ copy of it and keep it */
+ buf_tmp = hb_buffer_init( cur->size );
+ memcpy( buf_tmp->data, cur->data, cur->size );
+ buf_tmp->sequence = cur->sequence;
+ }
+ else
+ {
+ /* The frame has the expected date and won't have to be
+ duplicated, just put it through */
+ buf_tmp = cur;
+ pv->cur = cur = hb_fifo_get( job->fifo_raw );
+ }
+
+ /* Replace those MPEG-2 dates with our dates */
+ buf_tmp->start = (uint64_t) pv->count_frames *
+ pv->job->vrate_base / 300;
+ buf_tmp->stop = (uint64_t) ( pv->count_frames + 1 ) *
+ pv->job->vrate_base / 300;