X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=libhb%2Fsync.c;h=53b3193a3ebed8d3cbc52314ddc5a7108cc91519;hb=4b72a63eb61a01275493c4bfb51ba02152d1c5e1;hp=1501ea02ba2197192c7effc9d9171905cf23636f;hpb=b6a37c841f4fc3906526a790dfcc35cfd644c238;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/libhb/sync.c b/libhb/sync.c index 1501ea02..53b3193a 100644 --- a/libhb/sync.c +++ b/libhb/sync.c @@ -100,7 +100,7 @@ static hb_buffer_t * OutputAudioFrame( hb_audio_t *audio, hb_buffer_t *buf, *********************************************************************** * Initialize the work object **********************************************************************/ -int hb_sync_init( hb_job_t * job ) +hb_work_object_t * hb_sync_init( hb_job_t * job ) { hb_title_t * title = job->title; hb_chapter_t * chapter; @@ -109,18 +109,16 @@ int hb_sync_init( hb_job_t * job ) hb_work_private_t * pv; hb_sync_video_t * sync; hb_work_object_t * w; + hb_work_object_t * ret = NULL; pv = calloc( 1, sizeof( hb_work_private_t ) ); sync = &pv->type.video; pv->common = calloc( 1, sizeof( hb_sync_common_t ) ); pv->common->ref++; pv->common->mutex = hb_lock_init(); - pv->common->audio_pts_thresh = 0; + pv->common->audio_pts_thresh = -1; pv->common->next_frame = hb_cond_init(); - pv->common->pts_count = 1 + hb_list_count( title->list_audio ); - pv->common->first_pts = malloc( sizeof(int64_t) * pv->common->pts_count ); - for ( i = 0; i < pv->common->pts_count; i++ ) - pv->common->first_pts[i] = INT64_MAX; + pv->common->pts_count = 1; if ( job->frame_to_start || job->pts_to_start ) { pv->common->start_found = 0; @@ -130,7 +128,7 @@ int hb_sync_init( hb_job_t * job ) pv->common->start_found = 1; } - w = hb_get_work( WORK_SYNC_VIDEO ); + ret = w = hb_get_work( WORK_SYNC_VIDEO ); w->private_data = pv; w->fifo_in = job->fifo_raw; w->fifo_out = job->fifo_sync; @@ -170,20 +168,22 @@ int hb_sync_init( hb_job_t * job ) } sync->count_frames_max = duration * title->rate / title->rate_base / 90000; } - hb_list_add( job->list_work, w ); hb_log( "sync: expecting %d video frames", sync->count_frames_max ); /* Initialize libsamplerate for every audio track we have */ if ( ! job->indepth_scan ) { - for( i = 0; i < hb_list_count( title->list_audio ) && i < 8; i++ ) + for( i = 0; i < hb_list_count( title->list_audio ); i++ ) { InitAudio( job, pv->common, i ); } } + pv->common->first_pts = malloc( sizeof(int64_t) * pv->common->pts_count ); + for ( i = 0; i < pv->common->pts_count; i++ ) + pv->common->first_pts[i] = INT64_MAX; - return 0; + return ret; } /*********************************************************************** @@ -197,6 +197,11 @@ void syncVideoClose( hb_work_object_t * w ) hb_job_t * job = pv->job; hb_sync_video_t * sync = &pv->type.video; + // Wake up audio sync if it's still waiting on condition. + pv->common->pts_offset = 0; + pv->common->start_found = 1; + hb_cond_broadcast( pv->common->next_frame ); + if( sync->cur ) { hb_buffer_close( &sync->cur ); @@ -276,7 +281,10 @@ int syncVideoWork( hb_work_object_t * w, hb_buffer_t ** buf_in, subtitle = hb_list_item( job->list_subtitle, i ); if( subtitle->config.dest == PASSTHRUSUB ) { - hb_fifo_push( subtitle->fifo_out, hb_buffer_init( 0 ) ); + 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; @@ -360,7 +368,10 @@ int syncVideoWork( hb_work_object_t * w, hb_buffer_t ** buf_in, subtitle = hb_list_item( job->list_subtitle, i ); if( subtitle->config.dest == PASSTHRUSUB ) { - hb_fifo_push( subtitle->fifo_out, hb_buffer_init( 0 ) ); + 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; @@ -379,6 +390,9 @@ int syncVideoWork( hb_work_object_t * w, hb_buffer_t ** buf_in, cur->start = sync->next_start; cur->stop = cur->start + 90000. / ((double)job->vrate / (double)job->vrate_base); + /* Make sure last frame is reflected in frame count */ + pv->common->count_frames++; + /* Push the frame to the renderer */ hb_fifo_push( job->fifo_sync, cur ); sync->cur = NULL; @@ -418,6 +432,21 @@ int syncVideoWork( hb_work_object_t * w, hb_buffer_t ** buf_in, *buf_out = hb_buffer_init( 0 ); hb_log( "sync: reached %d frames, exiting early", pv->common->count_frames ); + + /* + * 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; } @@ -431,6 +460,21 @@ int syncVideoWork( hb_work_object_t * w, hb_buffer_t ** buf_in, hb_buffer_close( &sync->cur ); hb_buffer_close( &next ); *buf_out = hb_buffer_init( 0 ); + + /* + * 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; } @@ -520,7 +564,10 @@ int syncVideoWork( hb_work_object_t * w, hb_buffer_t ** buf_in, */ if( subtitle->source == CC608SUB || subtitle->source == CC708SUB || - subtitle->source == SRTSUB ) + subtitle->source == SRTSUB || + subtitle->source == UTF8SUB || + subtitle->source == TX3GSUB || + subtitle->source == SSASUB) { /* * Rewrite timestamps on subtitles that came from Closed Captions @@ -587,7 +634,7 @@ int syncVideoWork( hb_work_object_t * w, hb_buffer_t ** buf_in, sub->stop = sub2->start; } - // hb_log("0x%x: video seq: %lld subtitle sequence: %lld", + // hb_log("0x%x: video seq: %"PRId64" subtitle sequence: %"PRId64, // sub, cur->sequence, sub->sequence); if( sub->sequence > cur->sequence ) @@ -795,7 +842,7 @@ int syncVideoWork( hb_work_object_t * w, hb_buffer_t ** buf_in, /* Update UI */ UpdateState( w ); - + return HB_WORK_OK; } @@ -867,7 +914,6 @@ static int syncAudioWork( hb_work_object_t * w, hb_buffer_t ** buf_in, hb_job_t * job = pv->job; hb_sync_audio_t * sync = &pv->type.audio; hb_buffer_t * buf; - //hb_fifo_t * fifo; int64_t start; *buf_out = NULL; @@ -885,6 +931,13 @@ static int syncAudioWork( hb_work_object_t * w, hb_buffer_t ** buf_in, hb_lock( pv->common->mutex ); while ( !pv->common->start_found ) { + if ( pv->common->audio_pts_thresh < 0 ) + { + // I would initialize this in hb_sync_init, but + // job->pts_to_start can be modified by reader + // after hb_sync_init is called. + pv->common->audio_pts_thresh = job->pts_to_start; + } if ( buf->start < pv->common->audio_pts_thresh ) { hb_buffer_close( &buf ); @@ -1012,8 +1065,6 @@ static int syncAudioWork( hb_work_object_t * w, hb_buffer_t ** buf_in, (int)((start - sync->next_pts) / 90), w->audio->id, start, sync->next_pts ); InsertSilence( w, start - sync->next_pts ); - *buf_out = buf; - return HB_WORK_OK; } /* @@ -1047,6 +1098,7 @@ static void InitAudio( hb_job_t * job, hb_sync_common_t * common, int i ) pv->job = job; pv->common = common; pv->common->ref++; + pv->common->pts_count++; w = hb_get_work( WORK_SYNC_AUDIO ); w->private_data = pv;