diff options
author | John Stebbins <[email protected]> | 2018-08-07 13:34:36 -0700 |
---|---|---|
committer | John Stebbins <[email protected]> | 2018-08-07 13:34:36 -0700 |
commit | d80a17590a1aa6c65de0ef0f2e6e0bd273f4753e (patch) | |
tree | 9d12d136483ea460c1923cc8430d5c4ccdaef647 /libhb | |
parent | 1fbea6b770f6691d4a07b60d1e370fa70c483473 (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.
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/common.h | 9 | ||||
-rw-r--r-- | libhb/hb.c | 7 | ||||
-rw-r--r-- | libhb/hb_json.c | 5 | ||||
-rw-r--r-- | libhb/work.c | 27 |
4 files changed, 31 insertions, 17 deletions
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 ) |