mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-02-18 02:55:46 +00:00
refactoring
This commit is contained in:
parent
eb1b61a144
commit
2d1a8e43f9
10
src/device.c
10
src/device.c
@ -52,10 +52,10 @@ struct device_t *device_init() {
|
||||
struct device_runtime_t *run;
|
||||
struct device_t *dev;
|
||||
|
||||
A_CALLOC(run, 1, sizeof(*run));
|
||||
A_CALLOC(run, 1);
|
||||
run->fd = -1;
|
||||
|
||||
A_CALLOC(dev, 1, sizeof(*dev));
|
||||
A_CALLOC(dev, 1);
|
||||
dev->path = (char *)DEFAULT_DEVICE;
|
||||
dev->width = 640;
|
||||
dev->height = 480;
|
||||
@ -337,7 +337,7 @@ static int _device_open_mmap(struct device_t *dev) {
|
||||
|
||||
LOG_DEBUG("Allocating HW buffers ...");
|
||||
|
||||
A_CALLOC(dev->run->hw_buffers, req.count, sizeof(*dev->run->hw_buffers));
|
||||
A_CALLOC(dev->run->hw_buffers, req.count);
|
||||
for (dev->run->n_buffers = 0; dev->run->n_buffers < req.count; ++dev->run->n_buffers) {
|
||||
struct v4l2_buffer buf_info;
|
||||
|
||||
@ -383,12 +383,12 @@ static int _device_open_queue_buffers(struct device_t *dev) {
|
||||
|
||||
static void _device_open_alloc_picbufs(struct device_t *dev) {
|
||||
LOG_DEBUG("Allocating picture buffers ...");
|
||||
A_CALLOC(dev->run->pictures, dev->run->n_buffers, sizeof(*dev->run->pictures));
|
||||
A_CALLOC(dev->run->pictures, dev->run->n_buffers);
|
||||
|
||||
dev->run->max_picture_size = (dev->run->width * dev->run->height) << 1;
|
||||
for (unsigned index = 0; index < dev->run->n_buffers; ++index) {
|
||||
LOG_DEBUG("Allocating picture buffer %d ...", index);
|
||||
A_CALLOC(dev->run->pictures[index].data, dev->run->max_picture_size, sizeof(*dev->run->pictures[index].data));
|
||||
A_CALLOC(dev->run->pictures[index].data, dev->run->max_picture_size);
|
||||
dev->run->pictures[index].allocated = dev->run->max_picture_size;
|
||||
}
|
||||
}
|
||||
|
||||
11
src/http.c
11
src/http.c
@ -33,13 +33,13 @@ struct http_server_t *http_server_init(struct stream_t *stream) {
|
||||
struct http_server_t *server;
|
||||
struct exposed_t *exposed;
|
||||
|
||||
A_CALLOC(exposed, 1, sizeof(*exposed));
|
||||
A_CALLOC(exposed, 1);
|
||||
|
||||
A_CALLOC(run, 1, sizeof(*run));
|
||||
A_CALLOC(run, 1);
|
||||
run->stream = stream;
|
||||
run->exposed = exposed;
|
||||
|
||||
A_CALLOC(server, 1, sizeof(*server));
|
||||
A_CALLOC(server, 1);
|
||||
server->host = (char *)DEFAULT_HOST;
|
||||
server->port = 8080;
|
||||
server->run = run;
|
||||
@ -152,10 +152,7 @@ static void _http_update_exposed(struct http_server_t *server) {
|
||||
if (server->run->stream->updated) {
|
||||
A_PTHREAD_M_LOCK(&server->run->stream->mutex);
|
||||
if (server->run->stream->picture.allocated > server->run->exposed->picture.allocated) {
|
||||
A_REALLOC(
|
||||
server->run->exposed->picture.data,
|
||||
server->run->stream->picture.allocated * sizeof(*server->run->exposed->picture.data)
|
||||
);
|
||||
A_REALLOC(server->run->exposed->picture.data, server->run->stream->picture.allocated);
|
||||
server->run->exposed->picture.allocated = server->run->stream->picture.allocated;
|
||||
}
|
||||
memcpy(
|
||||
|
||||
@ -72,7 +72,7 @@ unsigned long jpeg_compress_buffer(struct device_t *dev, int index) {
|
||||
struct jpeg_error_mgr jpeg_error;
|
||||
unsigned char *line_buffer;
|
||||
|
||||
A_CALLOC(line_buffer, dev->run->width * 3, sizeof(unsigned char));
|
||||
A_CALLOC(line_buffer, dev->run->width * 3);
|
||||
|
||||
jpeg.err = jpeg_std_error(&jpeg_error);
|
||||
jpeg_create_compress(&jpeg);
|
||||
|
||||
@ -35,7 +35,7 @@ static int _stream_handle_event(struct device_t *dev);
|
||||
struct stream_t *stream_init(struct device_t *dev) {
|
||||
struct stream_t *stream;
|
||||
|
||||
A_CALLOC(stream, 1, sizeof(*stream));
|
||||
A_CALLOC(stream, 1);
|
||||
stream->dev = dev;
|
||||
A_PTHREAD_M_INIT(&stream->mutex);
|
||||
return stream;
|
||||
@ -86,7 +86,7 @@ void stream_loop(struct stream_t *stream) {
|
||||
long long fps_second = 0;
|
||||
|
||||
LOG_DEBUG("Allocation memory for stream picture ...");
|
||||
A_CALLOC(stream->picture.data, stream->dev->run->max_picture_size, sizeof(*stream->picture.data));
|
||||
A_CALLOC(stream->picture.data, stream->dev->run->max_picture_size);
|
||||
|
||||
A_PTHREAD_M_LOCK(&stream->mutex);
|
||||
stream->width = stream->dev->run->width;
|
||||
@ -313,7 +313,7 @@ static void _stream_init_workers(struct device_t *dev, struct workers_pool_t *po
|
||||
LOG_DEBUG("Spawning %d workers ...", dev->run->n_buffers);
|
||||
|
||||
*pool->workers_stop = false;
|
||||
A_CALLOC(pool->workers, dev->run->n_buffers, sizeof(*pool->workers));
|
||||
A_CALLOC(pool->workers, dev->run->n_buffers);
|
||||
|
||||
A_PTHREAD_M_INIT(&pool->has_free_workers_mutex);
|
||||
A_PTHREAD_C_INIT(&pool->has_free_workers_cond);
|
||||
|
||||
@ -66,10 +66,10 @@ unsigned log_level;
|
||||
{ while(!_var) assert(!pthread_cond_wait(_cond, _mutex)); }
|
||||
|
||||
|
||||
#define A_CALLOC(_dest, _nmemb, _size) assert((_dest = calloc(_nmemb, _size)))
|
||||
#define A_REALLOC(_dest, _size) assert((_dest = realloc(_dest, _size)))
|
||||
#define MEMSET_ZERO(_x_obj) memset(&(_x_obj), 0, sizeof(_x_obj))
|
||||
#define MEMSET_ZERO_PTR(_x_ptr) memset(_x_ptr, 0, sizeof(*(_x_ptr)))
|
||||
#define A_CALLOC(_dest, _nmemb) assert((_dest = calloc(_nmemb, sizeof(*(_dest)))))
|
||||
#define A_REALLOC(_dest, _nmemb) assert((_dest = realloc(_dest, _nmemb * sizeof(*(_dest)))))
|
||||
#define MEMSET_ZERO(_x_obj) memset(&(_x_obj), 0, sizeof(_x_obj))
|
||||
#define MEMSET_ZERO_PTR(_x_ptr) memset(_x_ptr, 0, sizeof(*(_x_ptr)))
|
||||
|
||||
|
||||
#define INLINE inline __attribute__((always_inline))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user