Throw frames out if the encoder is not ready

This commit is contained in:
Joose Sainio 2024-01-23 12:55:57 +02:00
parent bdb606b20b
commit e10071b9b7
2 changed files with 18 additions and 7 deletions

View file

@ -270,15 +270,21 @@ static void* input_read_thread(void* in_args)
frame_in->interlacing = args->encoder->cfg.source_scan_type; frame_in->interlacing = args->encoder->cfg.source_scan_type;
} }
usleep(33000);
// Wait until main thread is ready to receive the next frame. // Wait until main thread is ready to receive the next frame.
uvg_sem_wait(args->available_input_slots); if (uvg_sem_trywait(args->available_input_slots) == 0) {
args->img_in = frame_in; args->img_in = frame_in;
args->retval = retval; args->retval = retval;
// Unlock main_thread_mutex to notify main thread that the new img_in // Unlock main_thread_mutex to notify main thread that the new img_in
// and retval have been placed to args. // and retval have been placed to args.
uvg_sem_post(args->filled_input_slots); uvg_sem_post(args->filled_input_slots);
frame_in = NULL; frame_in = NULL;
}
else {
args->api->picture_free(frame_in);
frame_in = NULL;
}
} }
done: done:

View file

@ -132,6 +132,11 @@ static INLINE void uvg_sem_wait(uvg_sem_t *sem)
sem_wait(sem); sem_wait(sem);
} }
static INLINE int uvg_sem_trywait(uvg_sem_t *sem)
{
return sem_trywait(sem);
}
static INLINE void uvg_sem_post(uvg_sem_t *sem) static INLINE void uvg_sem_post(uvg_sem_t *sem)
{ {
sem_post(sem); sem_post(sem);