Skip to content

Commit

Permalink
encoder: removed cpu_forced logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevaev committed Apr 4, 2024
1 parent ae2f270 commit 65c652e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
28 changes: 7 additions & 21 deletions src/ustreamer/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,24 @@ void us_encoder_open(us_encoder_s *enc, us_capture_s *cap) {

assert(run->pool == NULL);

us_encoder_type_e type = (run->cpu_forced ? US_ENCODER_TYPE_CPU : enc->type);
us_encoder_type_e type = enc->type;
uint quality = cap->jpeg_quality;
uint n_workers = US_MIN(enc->n_workers, cr->n_bufs);
bool cpu_forced = false;

if (us_is_jpeg(cr->format) && type != US_ENCODER_TYPE_HW) {
US_LOG_INFO("Switching to HW encoder: the input is (M)JPEG ...");
type = US_ENCODER_TYPE_HW;
}

if (type == US_ENCODER_TYPE_HW) {
if (!us_is_jpeg(cr->format)) {
if (us_is_jpeg(cr->format) {
quality = cr->jpeg_quality;
n_workers = 1;
} else {
US_LOG_INFO("Switching to CPU encoder: the input format is not (M)JPEG ...");
goto use_cpu;
type = US_ENCODER_TYPE_CPU;
quality = cap->jpeg_quality;
}
quality = cr->jpeg_quality;
n_workers = 1;

} else if (type == US_ENCODER_TYPE_M2M_VIDEO || type == US_ENCODER_TYPE_M2M_IMAGE) {
US_LOG_DEBUG("Preparing M2M-%s encoder ...", (type == US_ENCODER_TYPE_M2M_VIDEO ? "VIDEO" : "IMAGE"));
Expand All @@ -150,13 +151,6 @@ void us_encoder_open(us_encoder_s *enc, us_capture_s *cap) {
}
}

goto ok;

use_cpu:
type = US_ENCODER_TYPE_CPU;
quality = cap->jpeg_quality;

ok:
if (quality == 0) {
US_LOG_INFO("Using JPEG quality: encoder default");
} else {
Expand All @@ -166,9 +160,6 @@ void us_encoder_open(us_encoder_s *enc, us_capture_s *cap) {
US_MUTEX_LOCK(run->mutex);
run->type = type;
run->quality = quality;
if (cpu_forced) {
run->cpu_forced = true;
}
US_MUTEX_UNLOCK(run->mutex);

const ldf desired_interval = (
Expand Down Expand Up @@ -243,14 +234,9 @@ static bool _worker_run_job(us_worker_s *wr) {
job->dest->encode_end_ts - job->dest->encode_begin_ts,
wr->name,
job->hw->buf.index);

return true;

error:
US_LOG_ERROR("Compression failed: worker=%s, buffer=%u", wr->name, job->hw->buf.index);
US_LOG_ERROR("Error while compressing buffer, falling back to CPU");
US_MUTEX_LOCK(run->mutex);
run->cpu_forced = true;
US_MUTEX_UNLOCK(run->mutex);
return false;
}
1 change: 0 additions & 1 deletion src/ustreamer/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ typedef enum {
typedef struct {
us_encoder_type_e type;
uint quality;
bool cpu_forced;
pthread_mutex_t mutex;

uint n_m2ms;
Expand Down

0 comments on commit 65c652e

Please sign in to comment.