mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-17 04:53:42 +00:00
refactoring
This commit is contained in:
@@ -805,14 +805,14 @@ static void _http_exposed_refresh(UNUSED int fd, UNUSED short what, void *v_serv
|
|||||||
bool picture_updated = false;
|
bool picture_updated = false;
|
||||||
|
|
||||||
# define UNLOCK_STREAM { \
|
# define UNLOCK_STREAM { \
|
||||||
atomic_store(&STREAM(updated), false); \
|
atomic_store(&STREAM(video->updated), false); \
|
||||||
A_MUTEX_UNLOCK(&STREAM(mutex)); \
|
A_MUTEX_UNLOCK(&STREAM(video->mutex)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atomic_load(&STREAM(updated))) {
|
if (atomic_load(&STREAM(video->updated))) {
|
||||||
LOG_DEBUG("Refreshing HTTP exposed ...");
|
LOG_DEBUG("Refreshing HTTP exposed ...");
|
||||||
A_MUTEX_LOCK(&STREAM(mutex));
|
A_MUTEX_LOCK(&STREAM(video->mutex));
|
||||||
if (STREAM(online)) {
|
if (STREAM(video->online)) {
|
||||||
picture_updated = _expose_new_picture_unsafe(server);
|
picture_updated = _expose_new_picture_unsafe(server);
|
||||||
UNLOCK_STREAM;
|
UNLOCK_STREAM;
|
||||||
} else {
|
} else {
|
||||||
@@ -847,14 +847,14 @@ static void _http_exposed_refresh(UNUSED int fd, UNUSED short what, void *v_serv
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool _expose_new_picture_unsafe(struct http_server_t *server) {
|
static bool _expose_new_picture_unsafe(struct http_server_t *server) {
|
||||||
EX(captured_fps) = STREAM(captured_fps);
|
EX(captured_fps) = STREAM(video->captured_fps);
|
||||||
EX(expose_begin_ts) = get_now_monotonic();
|
EX(expose_begin_ts) = get_now_monotonic();
|
||||||
|
|
||||||
if (server->drop_same_frames) {
|
if (server->drop_same_frames) {
|
||||||
if (
|
if (
|
||||||
EX(online)
|
EX(online)
|
||||||
&& EX(dropped) < server->drop_same_frames
|
&& EX(dropped) < server->drop_same_frames
|
||||||
&& picture_compare(EX(picture), STREAM(picture))
|
&& picture_compare(EX(picture), STREAM(video->picture))
|
||||||
) {
|
) {
|
||||||
EX(expose_cmp_ts) = get_now_monotonic();
|
EX(expose_cmp_ts) = get_now_monotonic();
|
||||||
EX(expose_end_ts) = EX(expose_cmp_ts);
|
EX(expose_end_ts) = EX(expose_cmp_ts);
|
||||||
@@ -869,7 +869,7 @@ static bool _expose_new_picture_unsafe(struct http_server_t *server) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
picture_copy(STREAM(picture), EX(picture));
|
picture_copy(STREAM(video->picture), EX(picture));
|
||||||
|
|
||||||
EX(online) = true;
|
EX(online) = true;
|
||||||
EX(dropped) = 0;
|
EX(dropped) = 0;
|
||||||
|
|||||||
@@ -84,32 +84,35 @@ static long double _workers_pool_get_fluency_delay(struct _workers_pool_t *pool,
|
|||||||
|
|
||||||
struct stream_t *stream_init(struct device_t *dev, struct encoder_t *encoder) {
|
struct stream_t *stream_init(struct device_t *dev, struct encoder_t *encoder) {
|
||||||
struct process_t *proc;
|
struct process_t *proc;
|
||||||
|
struct video_t *video;
|
||||||
struct stream_t *stream;
|
struct stream_t *stream;
|
||||||
|
|
||||||
A_CALLOC(proc, 1);
|
A_CALLOC(proc, 1);
|
||||||
atomic_init(&proc->stop, false);
|
atomic_init(&proc->stop, false);
|
||||||
atomic_init(&proc->slowdown, false);
|
atomic_init(&proc->slowdown, false);
|
||||||
|
|
||||||
|
A_CALLOC(video, 1);
|
||||||
|
video->picture = picture_init();
|
||||||
|
atomic_init(&video->updated, false);
|
||||||
|
A_MUTEX_INIT(&video->mutex);
|
||||||
|
|
||||||
A_CALLOC(stream, 1);
|
A_CALLOC(stream, 1);
|
||||||
// FIXME
|
|
||||||
stream->error_delay = 1;
|
stream->error_delay = 1;
|
||||||
# ifdef WITH_RAWSINK
|
# ifdef WITH_RAWSINK
|
||||||
stream->rawsink_name = "";
|
stream->rawsink_name = "";
|
||||||
stream->rawsink_mode = 0660;
|
stream->rawsink_mode = 0660;
|
||||||
# endif
|
# endif
|
||||||
// end-of-fixme
|
stream->proc = proc;
|
||||||
stream->picture = picture_init();
|
stream->video = video;
|
||||||
stream->dev = dev;
|
stream->dev = dev;
|
||||||
stream->encoder = encoder;
|
stream->encoder = encoder;
|
||||||
atomic_init(&stream->updated, false);
|
|
||||||
A_MUTEX_INIT(&stream->mutex);
|
|
||||||
stream->proc = proc;
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
void stream_destroy(struct stream_t *stream) {
|
void stream_destroy(struct stream_t *stream) {
|
||||||
A_MUTEX_DESTROY(&stream->mutex);
|
A_MUTEX_DESTROY(&stream->video->mutex);
|
||||||
picture_destroy(stream->picture);
|
picture_destroy(stream->video->picture);
|
||||||
|
free(stream->video);
|
||||||
free(stream->proc);
|
free(stream->proc);
|
||||||
free(stream);
|
free(stream);
|
||||||
}
|
}
|
||||||
@@ -138,7 +141,7 @@ void stream_loop(struct stream_t *stream) {
|
|||||||
LOG_INFO("Capturing ...");
|
LOG_INFO("Capturing ...");
|
||||||
|
|
||||||
LOG_DEBUG("Pre-allocating memory for stream picture ...");
|
LOG_DEBUG("Pre-allocating memory for stream picture ...");
|
||||||
picture_realloc_data(stream->picture, picture_get_generous_size(DEV(run->width), DEV(run->height)));
|
picture_realloc_data(stream->video->picture, picture_get_generous_size(DEV(run->width), DEV(run->height)));
|
||||||
|
|
||||||
while (!atomic_load(&stream->proc->stop)) {
|
while (!atomic_load(&stream->proc->stop)) {
|
||||||
struct _worker_t *ready_wr;
|
struct _worker_t *ready_wr;
|
||||||
@@ -252,10 +255,10 @@ void stream_loop(struct stream_t *stream) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
A_MUTEX_LOCK(&stream->mutex);
|
A_MUTEX_LOCK(&stream->video->mutex);
|
||||||
stream->online = false;
|
stream->video->online = false;
|
||||||
atomic_store(&stream->updated, true);
|
atomic_store(&stream->video->updated, true);
|
||||||
A_MUTEX_UNLOCK(&stream->mutex);
|
A_MUTEX_UNLOCK(&stream->video->mutex);
|
||||||
|
|
||||||
_workers_pool_destroy(pool);
|
_workers_pool_destroy(pool);
|
||||||
device_switch_capturing(stream->dev, false);
|
device_switch_capturing(stream->dev, false);
|
||||||
@@ -331,15 +334,15 @@ static struct _workers_pool_t *_stream_init_one(struct stream_t *stream) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void _stream_expose_picture(struct stream_t *stream, struct picture_t *picture, unsigned captured_fps) {
|
static void _stream_expose_picture(struct stream_t *stream, struct picture_t *picture, unsigned captured_fps) {
|
||||||
A_MUTEX_LOCK(&stream->mutex);
|
A_MUTEX_LOCK(&stream->video->mutex);
|
||||||
|
|
||||||
picture_copy(picture, stream->picture);
|
picture_copy(picture, stream->video->picture);
|
||||||
|
|
||||||
stream->online = true;
|
stream->video->online = true;
|
||||||
stream->captured_fps = captured_fps;
|
stream->video->captured_fps = captured_fps;
|
||||||
atomic_store(&stream->updated, true);
|
atomic_store(&stream->video->updated, true);
|
||||||
|
|
||||||
A_MUTEX_UNLOCK(&stream->mutex);
|
A_MUTEX_UNLOCK(&stream->video->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct _workers_pool_t *_workers_pool_init(struct stream_t *stream) {
|
static struct _workers_pool_t *_workers_pool_init(struct stream_t *stream) {
|
||||||
|
|||||||
@@ -51,25 +51,27 @@ struct process_t {
|
|||||||
atomic_bool slowdown;
|
atomic_bool slowdown;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct stream_t {
|
struct video_t {
|
||||||
struct picture_t *picture;
|
struct picture_t *picture;
|
||||||
bool online;
|
bool online;
|
||||||
unsigned captured_fps;
|
unsigned captured_fps;
|
||||||
atomic_bool updated;
|
atomic_bool updated;
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
|
};
|
||||||
|
|
||||||
// FIXME: Config params, move other to runtime
|
struct stream_t {
|
||||||
unsigned error_delay;
|
unsigned error_delay;
|
||||||
# ifdef WITH_RAWSINK
|
# ifdef WITH_RAWSINK
|
||||||
char *rawsink_name;
|
char *rawsink_name;
|
||||||
mode_t rawsink_mode;
|
mode_t rawsink_mode;
|
||||||
bool rawsink_rm;
|
bool rawsink_rm;
|
||||||
# endif
|
# endif
|
||||||
// end-of-fixme
|
|
||||||
|
|
||||||
struct process_t *proc;
|
|
||||||
struct device_t *dev;
|
struct device_t *dev;
|
||||||
struct encoder_t *encoder;
|
struct encoder_t *encoder;
|
||||||
|
|
||||||
|
struct process_t *proc;
|
||||||
|
struct video_t *video;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user