+
+ if (*buf_out)
+ {
+ hb_fifo_push( pv->delay_queue, *buf_out );
+ *buf_out = NULL;
+ }
+
+ /*
+ * Keep the last three frames in our queue, this ensures that we have the last
+ * two always in there should we need to rewrite the durations on them.
+ */
+ if( hb_fifo_size( pv->delay_queue ) >= 3 )
+ {
+ *buf_out = hb_fifo_get( pv->delay_queue );
+ }
+
+ if( *buf_out )
+ {
+ if( pv->frames_to_extend )
+ {
+ /*
+ * A frame's been dropped by VFR detelecine.
+ * Gotta make up the lost time. This will also
+ * slow down the video to 23.976fps.
+ * The dropped frame ran for 3003 ticks, so
+ * divvy it up amongst the 4 frames left behind.
+ * This is what the delay_queue is for;
+ * telecined sequences start 2 frames before
+ * the dropped frame, so to slow down the right
+ * ones you need a 2 frame delay between
+ * reading input and writing output.
+ */
+ ivtc_buffer = *buf_out;
+
+ /* The 4th cached frame will be the to use. */
+ ivtc_buffer->start = pv->last_start[3];
+ ivtc_buffer->stop = pv->last_stop[3];
+
+ if (pv->frames_to_extend % 4)
+ ivtc_buffer->stop += 751;
+ else
+ ivtc_buffer->stop += 750;
+
+ /* Set the 3rd cached frame to start when this one stops,
+ and to stop 3003 ticks later -- a normal 29.97fps
+ length frame. If it needs to be extended as well to
+ make up lost time, it'll be handled on the next
+ loop through the renderer. */
+ int temp_duration = pv->last_stop[2] - pv->last_start[2];
+ pv->last_start[2] = ivtc_buffer->stop;
+ pv->last_stop[2] = ivtc_buffer->stop + temp_duration;
+
+ pv->frames_to_extend--;
+ pv->extended_frames++;
+ }
+
+ }