OSDN Git Service

libhb dll fix by RandomEngy
[handbrake-jp/handbrake-jp-git.git] / libhb / hb.c
index 898650a..11afcc1 100644 (file)
@@ -38,6 +38,7 @@ struct hb_handle_s
     /* For MacGui active queue
        increments each time the scan thread completes*/
     int            scanCount;
+    volatile int   scan_die;
     
     /* Stash of persistent data between jobs, for stuff
        like correcting frame count and framerate estimates
@@ -48,9 +49,16 @@ struct hb_handle_s
 
 hb_lock_t *hb_avcodec_lock;
 hb_work_object_t * hb_objects = NULL;
+hb_process_initialized = 0;
 
 static void thread_func( void * );
 
+
+int hello_world(){
+       return 55555;
+}
+
+
 void hb_avcodec_init()
 {
     hb_avcodec_lock  = hb_lock_init();
@@ -93,6 +101,16 @@ void hb_register( hb_work_object_t * w )
  */
 hb_handle_t * hb_init( int verbose, int update_check )
 {
+       if (!hb_process_initialized)
+       {
+#ifdef USE_PTHREAD
+#if defined( _WIN32 ) || defined( __MINGW32__ )
+               pthread_win32_process_attach_np();
+#endif
+#endif
+               hb_process_initialized =1;
+       }
+       
     hb_handle_t * h = calloc( sizeof( hb_handle_t ), 1 );
     uint64_t      date;
 
@@ -157,7 +175,8 @@ hb_handle_t * hb_init( int verbose, int update_check )
     h->die         = 0;
     h->main_thread = hb_thread_init( "libhb", thread_func, h,
                                      HB_NORMAL_PRIORITY );
-    hb_register( &hb_sync );
+    hb_register( &hb_sync_video );
+    hb_register( &hb_sync_audio );
        hb_register( &hb_decmpeg2 );
        hb_register( &hb_decvobsub );
     hb_register( &hb_encvobsub );
@@ -177,6 +196,7 @@ hb_handle_t * hb_init( int verbose, int update_check )
        hb_register( &hb_encfaac );
        hb_register( &hb_enclame );
        hb_register( &hb_encvorbis );
+       hb_register( &hb_muxer );
 #ifdef __APPLE__
        hb_register( &hb_encca_aac );
 #endif
@@ -254,7 +274,8 @@ hb_handle_t * hb_init_dl( int verbose, int update_check )
     h->main_thread = hb_thread_init( "libhb", thread_func, h,
                                      HB_NORMAL_PRIORITY );
 
-    hb_register( &hb_sync );
+    hb_register( &hb_sync_video );
+    hb_register( &hb_sync_audio );
        hb_register( &hb_decmpeg2 );
        hb_register( &hb_decvobsub );
     hb_register( &hb_encvobsub );
@@ -274,6 +295,7 @@ hb_handle_t * hb_init_dl( int verbose, int update_check )
        hb_register( &hb_encfaac );
        hb_register( &hb_enclame );
        hb_register( &hb_encvorbis );
+       hb_register( &hb_muxer );
 #ifdef __APPLE__
        hb_register( &hb_encca_aac );
 #endif
@@ -379,6 +401,8 @@ void hb_scan( hb_handle_t * h, const char * path, int title_index,
 {
     hb_title_t * title;
 
+    h->scan_die = 0;
+
     /* Clean up from previous scan */
     hb_remove_previews( h );
     while( ( title = hb_list_item( h->list_title, 0 ) ) )
@@ -388,8 +412,9 @@ void hb_scan( hb_handle_t * h, const char * path, int title_index,
     }
 
     hb_log( "hb_scan: path=%s, title_index=%d", path, title_index );
-    h->scan_thread = hb_scan_init( h, path, title_index, h->list_title,
-                                   preview_count, store_previews );
+    h->scan_thread = hb_scan_init( h, &h->scan_die, path, title_index, 
+                                   h->list_title, preview_count, 
+                                   store_previews );
 }
 
 /**
@@ -1195,6 +1220,8 @@ void hb_pause( hb_handle_t * h )
         hb_lock( h->pause_lock );
         h->paused = 1;
 
+        hb_current_job( h )->st_pause_date = hb_get_date();
+
         hb_lock( h->state_lock );
         h->state.state = HB_STATE_PAUSED;
         hb_unlock( h->state_lock );
@@ -1209,6 +1236,13 @@ void hb_resume( hb_handle_t * h )
 {
     if( h->paused )
     {
+#define job hb_current_job( h )
+        if( job->st_pause_date != -1 )
+        {
+           job->st_paused += hb_get_date() - job->st_pause_date;
+        }
+#undef job
+
         hb_unlock( h->pause_lock );
         h->paused = 0;
     }
@@ -1229,6 +1263,20 @@ void hb_stop( hb_handle_t * h )
 }
 
 /**
+ * Stops the conversion process.
+ * @param h Handle to hb_handle_t.
+ */
+void hb_scan_stop( hb_handle_t * h )
+{
+    h->scan_die = 1;
+
+    h->job_count = hb_count(h);
+    h->job_count_permanent = 0;
+
+    hb_resume( h );
+}
+
+/**
  * Returns the state of the conversion process.
  * @param h Handle to hb_handle_t.
  * @param s Handle to hb_state_t which to copy the state data.
@@ -1331,8 +1379,24 @@ static void thread_func( void * _h )
         {
             hb_thread_close( &h->scan_thread );
 
-            hb_log( "libhb: scan thread found %d valid title(s)",
-                    hb_list_count( h->list_title ) );
+            if ( h->scan_die )
+            {
+                hb_title_t * title;
+
+                hb_remove_previews( h );
+                while( ( title = hb_list_item( h->list_title, 0 ) ) )
+                {
+                    hb_list_rem( h->list_title, title );
+                    hb_title_close( &title );
+                }
+
+                hb_log( "hb_scan: canceled" );
+            }
+            else
+            {
+                hb_log( "libhb: scan thread found %d valid title(s)",
+                        hb_list_count( h->list_title ) );
+            }
             hb_lock( h->state_lock );
             h->state.state = HB_STATE_SCANDONE; //originally state.state
                        hb_unlock( h->state_lock );
@@ -1407,7 +1471,8 @@ void hb_set_state( hb_handle_t * h, hb_state_t * s )
     hb_lock( h->pause_lock );
     hb_lock( h->state_lock );
     memcpy( &h->state, s, sizeof( hb_state_t ) );
-    if( h->state.state == HB_STATE_WORKING )
+    if( h->state.state == HB_STATE_WORKING ||
+        h->state.state == HB_STATE_SEARCHING )
     {
         /* XXX Hack */
         if (h->job_count < 1)