summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2018-08-07 13:34:36 -0700
committerJohn Stebbins <[email protected]>2018-08-07 13:34:36 -0700
commitd80a17590a1aa6c65de0ef0f2e6e0bd273f4753e (patch)
tree9d12d136483ea460c1923cc8430d5c4ccdaef647
parent1fbea6b770f6691d4a07b60d1e370fa70c483473 (diff)
fix race in getting sequence_id of completed job
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.
-rw-r--r--gtk/src/hb-backend.c3
-rw-r--r--libhb/common.h9
-rw-r--r--libhb/hb.c7
-rw-r--r--libhb/hb_json.c5
-rw-r--r--libhb/work.c27
-rw-r--r--macosx/HBCore.m2
-rw-r--r--test/test.c2
7 files changed, 35 insertions, 20 deletions
diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c
index dc0d1f332..3a6936fb7 100644
--- a/gtk/src/hb-backend.c
+++ b/gtk/src/hb-backend.c
@@ -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:
diff --git a/libhb/common.h b/libhb/common.h
index 7ed82c65f..4fa370c03 100644
--- a/libhb/common.h
+++ b/libhb/common.h
@@ -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
{
diff --git a/libhb/hb.c b/libhb/hb.c
index f14c9b6fa..f16e72574 100644
--- a/libhb/hb.c
+++ b/libhb/hb.c
@@ -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 );
}
diff --git a/libhb/hb_json.c b/libhb/hb_json.c
index 9e6a2cc1f..3ba9de13d 100644
--- a/libhb/hb_json.c
+++ b/libhb/hb_json.c
@@ -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,
diff --git a/libhb/work.c b/libhb/work.c
index 22825840a..ceb185783 100644
--- a/libhb/work.c
+++ b/libhb/work.c
@@ -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 )
diff --git a/macosx/HBCore.m b/macosx/HBCore.m
index 6c259e25a..b2252183d 100644
--- a/macosx/HBCore.m
+++ b/macosx/HBCore.m
@@ -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;
diff --git a/test/test.c b/test/test.c
index 0cfa90432..acfe43e53 100644
--- a/test/test.c
+++ b/test/test.c
@@ -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)