mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-02-18 02:55:46 +00:00
refactoring
This commit is contained in:
parent
d6b5d4b302
commit
0e8ec793a5
@ -12,6 +12,7 @@
|
|||||||
#include "capture.h"
|
#include "capture.h"
|
||||||
|
|
||||||
|
|
||||||
|
static long double _capture_get_fluency_delay(struct device_t *dev, struct workers_pool_t *pool);
|
||||||
static int _capture_init_loop(struct device_t *dev, struct workers_pool_t *pool, sig_atomic_t *volatile global_stop);
|
static int _capture_init_loop(struct device_t *dev, struct workers_pool_t *pool, sig_atomic_t *volatile global_stop);
|
||||||
static int _capture_init(struct device_t *dev, struct workers_pool_t *pool, sig_atomic_t *volatile global_stop);
|
static int _capture_init(struct device_t *dev, struct workers_pool_t *pool, sig_atomic_t *volatile global_stop);
|
||||||
static void _capture_init_workers(struct device_t *dev, struct workers_pool_t *pool, sig_atomic_t *volatile global_stop);
|
static void _capture_init_workers(struct device_t *dev, struct workers_pool_t *pool, sig_atomic_t *volatile global_stop);
|
||||||
@ -125,15 +126,7 @@ void capture_loop(struct device_t *dev, sig_atomic_t *volatile global_stop) {
|
|||||||
++fps;
|
++fps;
|
||||||
}
|
}
|
||||||
|
|
||||||
long double delay = 0;
|
long double delay = _capture_get_fluency_delay(dev, &pool);
|
||||||
for (unsigned index = 0; index < dev->run->n_buffers; ++index) {
|
|
||||||
A_PTHREAD_M_LOCK(&pool.workers[index].last_comp_time_mutex);
|
|
||||||
if (pool.workers[index].last_comp_time > 0) {
|
|
||||||
delay += pool.workers[index].last_comp_time;
|
|
||||||
}
|
|
||||||
A_PTHREAD_M_UNLOCK(&pool.workers[index].last_comp_time_mutex);
|
|
||||||
}
|
|
||||||
delay = delay / dev->run->n_buffers / dev->run->n_buffers;
|
|
||||||
grab_after = now + delay;
|
grab_after = now + delay;
|
||||||
LOG_PERF("Fluency delay=%.03Lf; grab_after=%.03Lf", delay, grab_after);
|
LOG_PERF("Fluency delay=%.03Lf; grab_after=%.03Lf", delay, grab_after);
|
||||||
}
|
}
|
||||||
@ -146,7 +139,7 @@ void capture_loop(struct device_t *dev, sig_atomic_t *volatile global_stop) {
|
|||||||
A_PTHREAD_M_UNLOCK(&pool.workers[buf_info.index].has_job_mutex);
|
A_PTHREAD_M_UNLOCK(&pool.workers[buf_info.index].has_job_mutex);
|
||||||
A_PTHREAD_C_SIGNAL(&pool.workers[buf_info.index].has_job_cond);
|
A_PTHREAD_C_SIGNAL(&pool.workers[buf_info.index].has_job_cond);
|
||||||
|
|
||||||
goto next_handlers;
|
goto next_handlers; // Поток сам освободит буфер
|
||||||
|
|
||||||
pass_frame:
|
pass_frame:
|
||||||
|
|
||||||
@ -177,6 +170,20 @@ void capture_loop(struct device_t *dev, sig_atomic_t *volatile global_stop) {
|
|||||||
device_close(dev);
|
device_close(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static long double _capture_get_fluency_delay(struct device_t *dev, struct workers_pool_t *pool) {
|
||||||
|
long double delay = 0;
|
||||||
|
|
||||||
|
for (unsigned index = 0; index < dev->run->n_buffers; ++index) {
|
||||||
|
A_PTHREAD_M_LOCK(&pool->workers[index].last_comp_time_mutex);
|
||||||
|
if (pool->workers[index].last_comp_time > 0) {
|
||||||
|
delay += pool->workers[index].last_comp_time;
|
||||||
|
}
|
||||||
|
A_PTHREAD_M_UNLOCK(&pool->workers[index].last_comp_time_mutex);
|
||||||
|
}
|
||||||
|
// Среднее арифметическое деленное на количество воркеров
|
||||||
|
return delay / dev->run->n_buffers / dev->run->n_buffers;
|
||||||
|
}
|
||||||
|
|
||||||
static int _capture_init_loop(struct device_t *dev, struct workers_pool_t *pool, sig_atomic_t *volatile global_stop) {
|
static int _capture_init_loop(struct device_t *dev, struct workers_pool_t *pool, sig_atomic_t *volatile global_stop) {
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user