OSDN Git Service

Fix a hang in sync
[handbrake-jp/handbrake-jp-git.git] / libhb / decmpeg2.c
index 63f2ebb..1d2d059 100644 (file)
@@ -291,10 +291,9 @@ static hb_buffer_t *hb_copy_frame( hb_job_t *job, int width, int height,
             memcpy( in.data[1], u, src_wh >> 2 );
             memcpy( in.data[2], v, src_wh >> 2 );
         }
-        struct SwsContext *context = sws_getContext( width, height, pixfmt,
+        struct SwsContext *context = hb_sws_get_context( width, height, pixfmt,
                                                      dst_w, dst_h, PIX_FMT_YUV420P,
-                                                     SWS_LANCZOS|SWS_ACCURATE_RND,
-                                                     NULL, NULL, NULL );
+                                                     SWS_LANCZOS|SWS_ACCURATE_RND);
         sws_scale( context, in.data, in.linesize, 0, height, out.data, out.linesize );
         sws_freeContext( context );
 
@@ -672,7 +671,15 @@ static void hb_libmpeg2_close( hb_libmpeg2_t ** _m )
     for ( i = 0; i < NTAGS; ++i )
     {
         if ( m->tags[i].cc_buf )
+        {
+            if ( m->tags[i].cc_buf == m->last_cc1_buf )
+                m->last_cc1_buf = NULL;
             hb_buffer_close( &m->tags[i].cc_buf );
+        }
+    }
+    if ( m->last_cc1_buf )
+    {
+        hb_buffer_close( &m->last_cc1_buf );
     }
 
     free( m );
@@ -783,6 +790,11 @@ static int decmpeg2Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
             if ( pv->libmpeg2->last_cc1_buf )
             {
                 cc_send_to_decoder( pv->libmpeg2, pv->libmpeg2->last_cc1_buf );
+                if ( pv->libmpeg2->tags[pv->libmpeg2->cur_tag].cc_buf == 
+                     pv->libmpeg2->last_cc1_buf )
+                {
+                    pv->libmpeg2->tags[pv->libmpeg2->cur_tag].cc_buf = NULL;
+                }
                 pv->libmpeg2->last_cc1_buf = NULL;
             }
             cc_send_to_decoder( pv->libmpeg2, hb_buffer_init( 0 ) );
@@ -822,10 +834,6 @@ static void decmpeg2Close( hb_work_object_t * w )
     {
         hb_log( "mpeg2 done: %d frames", pv->libmpeg2->nframes );
     }
-    if ( pv->libmpeg2->last_cc1_buf )
-    {
-        hb_buffer_close( &pv->libmpeg2->last_cc1_buf );
-    }
     hb_list_close( &pv->list );
     if ( pv->libmpeg2->list_subtitle )
     {