From 020482a05aca55848acfab54ab768d445d4a080a Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Wed, 7 Nov 2018 12:11:59 +0300 Subject: [PATCH] refactoring --- src/encoder.c | 4 ---- src/stream.c | 12 +++++++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/encoder.c b/src/encoder.c index dd268df..60c988f 100644 --- a/src/encoder.c +++ b/src/encoder.c @@ -154,8 +154,6 @@ int encoder_compress_buffer(struct encoder_t *encoder, struct device_t *dev, assert(encoder->type != ENCODER_TYPE_UNKNOWN); - dev->run->pictures[buf_index].encode_begin_time = get_now_monotonic(); - if (encoder->type == ENCODER_TYPE_CPU) { jpeg_encoder_compress_buffer(dev, buf_index, encoder->quality); } @@ -167,8 +165,6 @@ int encoder_compress_buffer(struct encoder_t *encoder, struct device_t *dev, } # endif - dev->run->pictures[buf_index].encode_end_time = get_now_monotonic(); - return 0; # pragma GCC diagnostic ignored "-Wunused-label" diff --git a/src/stream.c b/src/stream.c index 887b039..3f6bb34 100644 --- a/src/stream.c +++ b/src/stream.c @@ -437,18 +437,22 @@ static void *_stream_worker_thread(void *v_ctx) { A_PTHREAD_C_WAIT_TRUE(*ctx->has_job, ctx->has_job_cond, ctx->has_job_mutex); A_PTHREAD_M_UNLOCK(ctx->has_job_mutex); +# define PICTURE(_next) ctx->dev->run->pictures[ctx->buf_index]._next + if (!*ctx->workers_stop) { LOG_DEBUG("Worker %u compressing JPEG from buffer %d ...", ctx->number, ctx->buf_index); + PICTURE(encode_begin_time) = get_now_monotonic(); if (encoder_compress_buffer(ctx->encoder, ctx->dev, ctx->number, ctx->buf_index) < 0) { *ctx->job_failed = true; } + PICTURE(encode_end_time) = get_now_monotonic(); if (_stream_release_buffer(ctx->dev, &ctx->buf_info) == 0) { - *ctx->job_start_time = ctx->dev->run->pictures[ctx->buf_index].encode_begin_time; + *ctx->job_start_time = PICTURE(encode_begin_time); *ctx->has_job = false; - long double last_comp_time = ctx->dev->run->pictures[ctx->buf_index].encode_end_time - *ctx->job_start_time; + long double last_comp_time = PICTURE(encode_end_time) - *ctx->job_start_time; A_PTHREAD_M_LOCK(ctx->last_comp_time_mutex); *ctx->last_comp_time = last_comp_time; @@ -456,7 +460,7 @@ static void *_stream_worker_thread(void *v_ctx) { LOG_VERBOSE( "Compressed JPEG size=%ld; time=%0.3Lf; worker=%u; buffer=%d", - ctx->dev->run->pictures[ctx->buf_index].size, last_comp_time, ctx->number, ctx->buf_index + PICTURE(size), last_comp_time, ctx->number, ctx->buf_index ); } else { *ctx->job_failed = true; @@ -464,6 +468,8 @@ static void *_stream_worker_thread(void *v_ctx) { } } +# undef PICTURE + A_PTHREAD_M_LOCK(ctx->free_workers_mutex); *ctx->free_workers += 1; A_PTHREAD_M_UNLOCK(ctx->free_workers_mutex);