+ next = *buf_in;
+ *buf_in = NULL;
+
+ /* Wait for start of point-to-point encoding */
+ if( !pv->common->start_found )
+ {
+ hb_sync_video_t * sync = &pv->type.video;
+
+ if( next->size == 0 )
+ {
+ *buf_out = next;
+ pv->common->start_found = 1;
+ hb_cond_broadcast( pv->common->next_frame );
+
+ /*
+ * Push through any subtitle EOFs in case they
+ * were not synced through.
+ */
+ for( i = 0; i < hb_list_count( job->list_subtitle ); i++)
+ {
+ subtitle = hb_list_item( job->list_subtitle, i );
+ if( subtitle->config.dest == PASSTHRUSUB )
+ {
+ if( subtitle->source == VOBSUB )
+ hb_fifo_push( subtitle->fifo_sync, hb_buffer_init( 0 ) );
+ else
+ hb_fifo_push( subtitle->fifo_out, hb_buffer_init( 0 ) );
+ }
+ }
+ return HB_WORK_DONE;
+ }
+ if ( pv->common->count_frames < job->frame_to_start ||
+ next->start < job->pts_to_start )
+ {
+ // Flush any subtitles that have pts prior to the
+ // current frame
+ for( i = 0; i < hb_list_count( job->list_subtitle ); i++)
+ {
+ subtitle = hb_list_item( job->list_subtitle, i );
+ while( ( sub = hb_fifo_see( subtitle->fifo_raw ) ) )
+ {
+ if ( sub->start > next->start )
+ break;
+ sub = hb_fifo_get( subtitle->fifo_raw );
+ hb_buffer_close( &sub );
+ }
+ }
+ hb_lock( pv->common->mutex );
+ // Tell the audio threads what must be dropped
+ pv->common->audio_pts_thresh = next->start;
+ hb_cond_broadcast( pv->common->next_frame );
+ hb_unlock( pv->common->mutex );
+
+ UpdateSearchState( w, next->start );
+ hb_buffer_close( &next );
+
+ return HB_WORK_OK;
+ }
+ hb_lock( pv->common->mutex );
+ pv->common->start_found = 1;
+ pv->common->count_frames = 0;
+ hb_cond_broadcast( pv->common->next_frame );
+ hb_unlock( pv->common->mutex );
+ sync->st_first = 0;
+ }
+
+ /* Wait till we can determine the initial pts of all streams */
+ if( pv->common->pts_offset == INT64_MIN )
+ {
+ pv->common->first_pts[0] = next->start;
+ hb_lock( pv->common->mutex );
+ while( pv->common->pts_offset == INT64_MIN )
+ {
+ // Full fifos will make us wait forever, so get the
+ // pts offset from the available streams if full
+ if ( hb_fifo_is_full( job->fifo_raw ) )
+ {
+ getPtsOffset( w );
+ hb_cond_broadcast( pv->common->next_frame );
+ }
+ else if ( checkPtsOffset( w ) )
+ hb_cond_broadcast( pv->common->next_frame );
+ else
+ hb_cond_timedwait( pv->common->next_frame, pv->common->mutex, 200 );
+ }
+ hb_unlock( pv->common->mutex );
+ }
+