From fddcbabe288c2407d8207140e2c9b4ec96ce0d7b Mon Sep 17 00:00:00 2001 From: Laurent Fasnacht Date: Fri, 13 Jun 2014 11:30:08 +0200 Subject: [PATCH] bitstream writing is now a "normal" job in a thread --- src/encoder_state-bitstream.c | 4 ++++ src/encoder_state-bitstream.h | 1 + src/encoderstate.c | 27 +++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/encoder_state-bitstream.c b/src/encoder_state-bitstream.c index 6f866415..f7634f82 100644 --- a/src/encoder_state-bitstream.c +++ b/src/encoder_state-bitstream.c @@ -814,3 +814,7 @@ void encoder_state_write_bitstream(encoder_state * const main_state) { } } +void encoder_state_worker_write_bitstream(void * opaque) { + encoder_state_write_bitstream((encoder_state *) opaque); +} + diff --git a/src/encoder_state-bitstream.h b/src/encoder_state-bitstream.h index 2eeeb315..bd053a9e 100644 --- a/src/encoder_state-bitstream.h +++ b/src/encoder_state-bitstream.h @@ -35,6 +35,7 @@ void encoder_state_write_bitstream_slice_header(struct encoder_state * const enc void encoder_state_write_bitstream(struct encoder_state * const main_state); void encoder_state_write_bitstream_leaf(struct encoder_state * const encoder_state); void encoder_state_worker_write_bitstream_leaf(void * opaque); +void encoder_state_worker_write_bitstream(void * opaque); #endif // ENCODER_STATE_BITSTREAM_H_ diff --git a/src/encoderstate.c b/src/encoderstate.c index 75f4aac7..ecfb2ab7 100644 --- a/src/encoderstate.c +++ b/src/encoderstate.c @@ -560,7 +560,6 @@ static void encoder_state_encode(encoder_state * const main_state) { } } } - threadqueue_flush(main_state->encoder_control->threadqueue); } else { for (i=0; main_state->children[i].encoder_control; ++i) { encoder_state_worker_encode_children(&(main_state->children[i])); @@ -641,6 +640,18 @@ static void encoder_state_new_frame(encoder_state * const main_state) { } +static void _encode_one_frame_add_bitstream_deps(const encoder_state * const encoder_state, threadqueue_job * const job) { + int i; + for (i = 0; encoder_state->children[i].encoder_control; ++i) { + _encode_one_frame_add_bitstream_deps(&encoder_state->children[i], job); + } + if (encoder_state->tqj_bitstream_written) { + threadqueue_job_dep_add(job, encoder_state->tqj_bitstream_written); + } + if (encoder_state->tqj_recon_done) { + threadqueue_job_dep_add(job, encoder_state->tqj_recon_done); + } +} void encode_one_frame(encoder_state * const main_state) @@ -655,8 +666,20 @@ void encode_one_frame(encoder_state * const main_state) encoder_state_encode(main_state); PERFORMANCE_MEASURE_END(main_state->encoder_control->threadqueue, "type=encode,frame=%d", main_state->global->frame); } + //threadqueue_flush(main_state->encoder_control->threadqueue); { - encoder_state_write_bitstream(main_state); + threadqueue_job *job; +#ifdef _DEBUG + char job_description[256]; + sprintf(job_description, "frame=%d", main_state->global->frame); +#else + char* job_description = NULL; +#endif + + job = threadqueue_submit(main_state->encoder_control->threadqueue, encoder_state_worker_write_bitstream, (void*) main_state, 1, job_description); + + _encode_one_frame_add_bitstream_deps(main_state, job); + threadqueue_job_unwait_job(main_state->encoder_control->threadqueue, job); } threadqueue_flush(main_state->encoder_control->threadqueue); }