]> granicus.if.org Git - handbrake/commitdiff
fix race in getting sequence_id of completed job
authorJohn Stebbins <jstebbins.hb@gmail.com>
Tue, 7 Aug 2018 20:34:36 +0000 (13:34 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Tue, 7 Aug 2018 20:34:36 +0000 (13:34 -0700)
The sequence_id was only available for the WORKING state and not the
WORKDONE state.  But frontends poll for status periodically and can miss
all status updates for the WORKING state if the file is very short or an
error occurs early during transcoding.  When WORKING status is missed,
there was no way to know the sequence_id associated with the WORKDONE
status.

gtk/src/hb-backend.c
libhb/common.h
libhb/hb.c
libhb/hb_json.c
libhb/work.c
macosx/HBCore.m
test/test.c

index dc0d1f3326b16d482ae4799dadead75ebf140ab7..3a6936fb7fbb139d65c1dcf190c01c221859df77 100644 (file)
@@ -3553,7 +3553,7 @@ update_status(hb_state_t *state, ghb_instance_status_t *status)
         status->state &= ~GHB_STATE_SEARCHING;
     }
 #undef p
-#define p state->param.workdone
+#define p state->param.working
     if (state->state & HB_STATE_WORKDONE)
     {
         status->state |= GHB_STATE_WORKDONE;
@@ -3561,6 +3561,7 @@ update_status(hb_state_t *state, ghb_instance_status_t *status)
         status->state &= ~GHB_STATE_PAUSED;
         status->state &= ~GHB_STATE_WORKING;
         status->state &= ~GHB_STATE_SEARCHING;
+        status->unique_id = p.sequence_id;
         switch (p.error)
         {
         case HB_ERROR_NONE:
index 7ed82c65fe6eb06d251dbfe2314d09894f087cbe..4fa370c03505c683520140f15cef00717e82566c 100644 (file)
@@ -1097,7 +1097,7 @@ struct hb_state_s
 
         struct
         {
-            /* HB_STATE_WORKING */
+            /* HB_STATE_WORKING || HB_STATE_SEARCHING || HB_STATE_WORKDONE */
 #define HB_PASS_SUBTITLE    -1
 #define HB_PASS_ENCODE      0
 #define HB_PASS_ENCODE_1ST  1   // Some code depends on these values being
@@ -1112,13 +1112,8 @@ struct hb_state_s
             int   minutes;
             int   seconds;
             int   sequence_id;
-        } working;
-
-        struct
-        {
-            /* HB_STATE_WORKDONE */
             hb_error_code error;
-        } workdone;
+        } working;
 
         struct
         {
index f14c9b6faf109db107973a1e18008d05e88dd11a..f16e72574e2476718e68379e602e6204a715a62c 100644 (file)
@@ -1805,11 +1805,10 @@ static void thread_func( void * _h )
         {
             hb_thread_close( &h->work_thread );
 
-            hb_log( "libhb: work result = %d",
-                    h->work_error );
+            hb_log( "libhb: work result = %d", h->work_error );
             hb_lock( h->state_lock );
-            h->state.state                = HB_STATE_WORKDONE;
-            h->state.param.workdone.error = h->work_error;
+            h->state.state               = HB_STATE_WORKDONE;
+            h->state.param.working.error = h->work_error;
 
             hb_unlock( h->state_lock );
         }
index 9e6a2cc1fd92241e4d85cbfb805506a545079d1c..3ba9de13d3ebe34b7be5f71c928f6000ddafc806 100644 (file)
@@ -92,10 +92,11 @@ hb_dict_t* hb_state_to_dict( hb_state_t * state)
         break;
     case HB_STATE_WORKDONE:
         dict = json_pack_ex(&error, 0,
-            "{s:o, s{s:o}}",
+            "{s:o, s{s:o, s:o}}",
             "State", hb_value_string(state_s),
             "WorkDone",
-                "Error",    hb_value_int(state->param.workdone.error));
+                "SequenceID",   hb_value_int(state->param.working.sequence_id),
+                "Error",        hb_value_int(state->param.working.error));
         break;
     case HB_STATE_MUXING:
         dict = json_pack_ex(&error, 0,
index 22825840a67345e881f2c8924aa3ea7c631de7f8..ceb185783bff6faef2df218061793e18a51795ff 100644 (file)
@@ -77,6 +77,25 @@ static void InitWorkState(hb_handle_t *h, int pass_id, int pass, int pass_count)
 
 }
 
+static void SetWorkdoneState(hb_job_t *job)
+{
+    hb_state_t state;
+
+
+    if (job == NULL)
+    {
+        return;
+    }
+    hb_get_state2(job->h, &state);
+
+    state.state                     = HB_STATE_WORKDONE;
+    state.param.working.error       = *job->done_error;
+    state.param.working.sequence_id = job->sequence_id;
+
+    hb_set_state( job->h, &state );
+
+}
+
 /**
  * Iterates through job list and calls do_job for each job.
  * @param _work Handle work object.
@@ -136,8 +155,10 @@ static void work_func( void * _work )
             do_job( job );
             *(work->current_job) = NULL;
         }
-        // Clean up any incomplete jobs
-        for (; pass < pass_count; pass++)
+        SetWorkdoneState(job);
+
+        // Clean job passes
+        for (pass = 0; pass < pass_count; pass++)
         {
             job = hb_list_item(passes, pass);
             hb_job_close(&job);
@@ -1854,8 +1875,6 @@ cleanup:
     }
 
     hb_buffer_pool_free();
-
-    hb_job_close(&job);
 }
 
 static inline void copy_chapter( hb_buffer_t * dst, hb_buffer_t * src )
index 6c259e25a00836273d9480abb68fc0961910f9ae..b2252183d1c0c99ab7dc518cc5f2313dff587433 100644 (file)
@@ -456,7 +456,7 @@ typedef void (^HBCoreCleanupHandler)(void);
     }
 
     HBCoreResult result = HBCoreResultDone;
-    switch (_hb_state->param.workdone.error)
+    switch (_hb_state->param.working.error)
     {
         case HB_ERROR_NONE:
             result = HBCoreResultDone;
index 0cfa90432b4fc85e3a7560156ce252df17d8c710..acfe43e5358c915709f2791ededadbb6f69f633c 100644 (file)
@@ -1022,7 +1022,7 @@ static int HandleEvents(hb_handle_t * h, hb_dict_t *preset_dict)
         }
 #undef p
 
-#define p s.param.workdone
+#define p s.param.working
         case HB_STATE_WORKDONE:
             /* Print error if any, then exit */
             if (json)