OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / libhb / sync.c
index 1501ea0..31c9583 100644 (file)
@@ -117,10 +117,7 @@ int hb_sync_init( hb_job_t * job )
     pv->common->mutex = hb_lock_init();
     pv->common->audio_pts_thresh = 0;
     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;
@@ -182,6 +179,9 @@ int hb_sync_init( hb_job_t * job )
             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;
 }
@@ -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 );
@@ -1047,6 +1052,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;