mirror of
https://github.com/pikvm/ustreamer.git
synced 2025-12-23 18:50:00 +00:00
asserts
This commit is contained in:
parent
be3fff5483
commit
1d3c767617
@ -13,7 +13,7 @@
|
||||
|
||||
static int _capture_init_loop(struct device *dev, struct workers_pool *pool, sig_atomic_t *volatile stop);
|
||||
static int _capture_init(struct device *dev, struct workers_pool *pool, sig_atomic_t *volatile stop);
|
||||
static int _capture_init_workers(struct device *dev, struct workers_pool *pool, sig_atomic_t *volatile stop);
|
||||
static void _capture_init_workers(struct device *dev, struct workers_pool *pool, sig_atomic_t *volatile stop);
|
||||
static void *_capture_worker_thread(void *index);
|
||||
static void _capture_destroy_workers(struct device *dev, struct workers_pool *pool);
|
||||
static int _capture_control(struct device *dev, const bool enable);
|
||||
@ -155,9 +155,7 @@ static int _capture_init(struct device *dev, struct workers_pool *pool, sig_atom
|
||||
if (_capture_control(dev, true) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (_capture_init_workers(dev, pool, stop) < 0) {
|
||||
goto error;
|
||||
}
|
||||
_capture_init_workers(dev, pool, stop);
|
||||
|
||||
return 0;
|
||||
|
||||
@ -166,14 +164,10 @@ static int _capture_init(struct device *dev, struct workers_pool *pool, sig_atom
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int _capture_init_workers(struct device *dev, struct workers_pool *pool, sig_atomic_t *volatile stop) {
|
||||
static void _capture_init_workers(struct device *dev, struct workers_pool *pool, sig_atomic_t *volatile stop) {
|
||||
LOG_INFO("Spawning %d workers ...", dev->run->n_buffers);
|
||||
|
||||
pool->workers = NULL;
|
||||
if ((pool->workers = calloc(dev->run->n_buffers, sizeof(*pool->workers))) == NULL) {
|
||||
LOG_PERROR("Can't allocate workers pool");
|
||||
return -1;
|
||||
}
|
||||
assert((pool->workers = calloc(dev->run->n_buffers, sizeof(*pool->workers))));
|
||||
|
||||
assert(!pthread_mutex_init(&pool->busy_mutex, NULL));
|
||||
assert(!pthread_cond_init(&pool->busy_cond, NULL));
|
||||
@ -196,7 +190,6 @@ static int _capture_init_workers(struct device *dev, struct workers_pool *pool,
|
||||
}
|
||||
|
||||
LOG_DEBUG("Spawned %d workers", dev->run->n_buffers);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *_capture_worker_thread(void *params_ptr) {
|
||||
|
||||
27
src/device.c
27
src/device.c
@ -5,6 +5,7 @@
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <linux/videodev2.h>
|
||||
@ -39,7 +40,7 @@ static int _device_open_check_cap(struct device *dev);
|
||||
static int _device_open_dv_timings(struct device *dev);
|
||||
static int _device_apply_dv_timings(struct device *dev);
|
||||
static int _device_open_format(struct device *dev);
|
||||
static int _device_open_alloc_picbufs(struct device *dev);
|
||||
static void _device_open_alloc_picbufs(struct device *dev);
|
||||
static int _device_open_mmap(struct device *dev);
|
||||
static int _device_open_queue_buffers(struct device *dev);
|
||||
|
||||
@ -109,9 +110,7 @@ int device_open(struct device *dev) {
|
||||
if (_device_open_queue_buffers(dev) < 0) {
|
||||
goto error;
|
||||
}
|
||||
if (_device_open_alloc_picbufs(dev) < 0) {
|
||||
goto error;
|
||||
}
|
||||
_device_open_alloc_picbufs(dev);
|
||||
|
||||
LOG_DEBUG("Device fd=%d initialized", dev->run->fd);
|
||||
return 0;
|
||||
@ -333,11 +332,7 @@ static int _device_open_mmap(struct device *dev) {
|
||||
|
||||
LOG_DEBUG("Allocating device buffers ...");
|
||||
|
||||
dev->run->buffers = NULL;
|
||||
if ((dev->run->buffers = calloc(req.count, sizeof(*dev->run->buffers))) == NULL) {
|
||||
LOG_PERROR("Can't allocate device buffers pool");
|
||||
return -1;
|
||||
}
|
||||
assert((dev->run->buffers = calloc(req.count, sizeof(*dev->run->buffers))));
|
||||
|
||||
for (dev->run->n_buffers = 0; dev->run->n_buffers < req.count; ++dev->run->n_buffers) {
|
||||
struct v4l2_buffer buf;
|
||||
@ -382,25 +377,17 @@ static int _device_open_queue_buffers(struct device *dev) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _device_open_alloc_picbufs(struct device *dev) {
|
||||
static void _device_open_alloc_picbufs(struct device *dev) {
|
||||
LOG_DEBUG("Allocating picture buffers ...");
|
||||
|
||||
dev->run->pictures = NULL;
|
||||
if ((dev->run->pictures = calloc(dev->run->n_buffers, sizeof(*dev->run->pictures))) == NULL) {
|
||||
LOG_PERROR("Can't allocate picture buffers pool");
|
||||
return -1;
|
||||
}
|
||||
assert((dev->run->pictures = calloc(dev->run->n_buffers, sizeof(*dev->run->pictures))));
|
||||
|
||||
unsigned 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);
|
||||
if ((dev->run->pictures[index] = malloc(picture_size)) == NULL) {
|
||||
LOG_PERROR("Can't allocate picture buffer %d", index);
|
||||
return -1;
|
||||
}
|
||||
assert((dev->run->pictures[index] = malloc(picture_size)));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *_format_to_string_auto(char *buf, const size_t length, const unsigned format) {
|
||||
|
||||
16
src/jpeg.c
16
src/jpeg.c
@ -26,6 +26,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <jpeglib.h>
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
@ -72,10 +73,7 @@ int jpeg_compress_buffer(struct device *dev, int index) {
|
||||
unsigned char *line_buffer;
|
||||
int written = -1;
|
||||
|
||||
if ((line_buffer = calloc(dev->run->width * 3, sizeof(unsigned char))) == NULL) {
|
||||
LOG_PERROR("Can't allocate memory for JPEG scanline");
|
||||
return written;
|
||||
}
|
||||
assert((line_buffer = calloc(dev->run->width * 3, sizeof(unsigned char))));
|
||||
|
||||
jpeg.err = jpeg_std_error(&jpeg_error);
|
||||
jpeg_create_compress(&jpeg);
|
||||
@ -117,9 +115,9 @@ static void _jpeg_set_dest_picture(j_compress_ptr jpeg, unsigned char *picture,
|
||||
struct mjpg_destination_mgr *dest;
|
||||
|
||||
if (jpeg->dest == NULL) {
|
||||
jpeg->dest = (struct jpeg_destination_mgr *)(*jpeg->mem->alloc_small)(
|
||||
assert((jpeg->dest = (struct jpeg_destination_mgr *)(*jpeg->mem->alloc_small)(
|
||||
(j_common_ptr) jpeg, JPOOL_PERMANENT, sizeof(struct mjpg_destination_mgr)
|
||||
);
|
||||
)));
|
||||
}
|
||||
|
||||
dest = (struct mjpg_destination_mgr *) jpeg->dest;
|
||||
@ -225,10 +223,10 @@ static void _jpeg_write_scanlines_rgb565(struct jpeg_compress_struct *jpeg,
|
||||
static void _jpeg_init_destination(j_compress_ptr jpeg) {
|
||||
struct mjpg_destination_mgr *dest = (struct mjpg_destination_mgr *) jpeg->dest;
|
||||
|
||||
// Allocate the output buffer --- it will be released when done with image
|
||||
dest->buffer = (JOCTET *)(*jpeg->mem->alloc_small)(
|
||||
// Allocate the output buffer - it will be released when done with image
|
||||
assert((dest->buffer = (JOCTET *)(*jpeg->mem->alloc_small)(
|
||||
(j_common_ptr) jpeg, JPOOL_IMAGE, JPEG_OUTPUT_BUFFER_SIZE * sizeof(JOCTET)
|
||||
);
|
||||
)));
|
||||
|
||||
dest->mgr.next_output_byte = dest->buffer;
|
||||
dest->mgr.free_in_buffer = JPEG_OUTPUT_BUFFER_SIZE;
|
||||
|
||||
@ -1,3 +1,8 @@
|
||||
#include <assert.h>
|
||||
#ifdef NDEBUG
|
||||
# error WTF dude? Asserts are good things!
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user