mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-11 18:13:41 +00:00
refactoring
This commit is contained in:
@@ -154,8 +154,6 @@ int encoder_compress_buffer(struct encoder_t *encoder, struct device_t *dev,
|
|||||||
|
|
||||||
assert(encoder->type != ENCODER_TYPE_UNKNOWN);
|
assert(encoder->type != ENCODER_TYPE_UNKNOWN);
|
||||||
|
|
||||||
dev->run->pictures[buf_index].encode_begin_time = get_now_monotonic();
|
|
||||||
|
|
||||||
if (encoder->type == ENCODER_TYPE_CPU) {
|
if (encoder->type == ENCODER_TYPE_CPU) {
|
||||||
jpeg_encoder_compress_buffer(dev, buf_index, encoder->quality);
|
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
|
# endif
|
||||||
|
|
||||||
dev->run->pictures[buf_index].encode_end_time = get_now_monotonic();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
# pragma GCC diagnostic ignored "-Wunused-label"
|
# pragma GCC diagnostic ignored "-Wunused-label"
|
||||||
|
|||||||
12
src/stream.c
12
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_C_WAIT_TRUE(*ctx->has_job, ctx->has_job_cond, ctx->has_job_mutex);
|
||||||
A_PTHREAD_M_UNLOCK(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) {
|
if (!*ctx->workers_stop) {
|
||||||
LOG_DEBUG("Worker %u compressing JPEG from buffer %d ...", ctx->number, ctx->buf_index);
|
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) {
|
if (encoder_compress_buffer(ctx->encoder, ctx->dev, ctx->number, ctx->buf_index) < 0) {
|
||||||
*ctx->job_failed = true;
|
*ctx->job_failed = true;
|
||||||
}
|
}
|
||||||
|
PICTURE(encode_end_time) = get_now_monotonic();
|
||||||
|
|
||||||
if (_stream_release_buffer(ctx->dev, &ctx->buf_info) == 0) {
|
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;
|
*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);
|
A_PTHREAD_M_LOCK(ctx->last_comp_time_mutex);
|
||||||
*ctx->last_comp_time = last_comp_time;
|
*ctx->last_comp_time = last_comp_time;
|
||||||
@@ -456,7 +460,7 @@ static void *_stream_worker_thread(void *v_ctx) {
|
|||||||
|
|
||||||
LOG_VERBOSE(
|
LOG_VERBOSE(
|
||||||
"Compressed JPEG size=%ld; time=%0.3Lf; worker=%u; buffer=%d",
|
"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 {
|
} else {
|
||||||
*ctx->job_failed = true;
|
*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);
|
A_PTHREAD_M_LOCK(ctx->free_workers_mutex);
|
||||||
*ctx->free_workers += 1;
|
*ctx->free_workers += 1;
|
||||||
A_PTHREAD_M_UNLOCK(ctx->free_workers_mutex);
|
A_PTHREAD_M_UNLOCK(ctx->free_workers_mutex);
|
||||||
|
|||||||
Reference in New Issue
Block a user