mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-13 02:53:42 +00:00
refactoring
This commit is contained in:
@@ -46,7 +46,7 @@ struct rawsink_t *rawsink_init(const char *name, mode_t mode, bool rm, bool mast
|
|||||||
|
|
||||||
A_CALLOC(rawsink, 1);
|
A_CALLOC(rawsink, 1);
|
||||||
rawsink->fd = -1;
|
rawsink->fd = -1;
|
||||||
rawsink->picture = MAP_FAILED;
|
rawsink->shared = MAP_FAILED;
|
||||||
rawsink->signal_sem = SEM_FAILED;
|
rawsink->signal_sem = SEM_FAILED;
|
||||||
rawsink->lock_sem = SEM_FAILED;
|
rawsink->lock_sem = SEM_FAILED;
|
||||||
rawsink->rm = rm;
|
rawsink->rm = rm;
|
||||||
@@ -80,14 +80,14 @@ struct rawsink_t *rawsink_init(const char *name, mode_t mode, bool rm, bool mast
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ftruncate(rawsink->fd, sizeof(struct rawsink_picture_t)) < 0) {
|
if (ftruncate(rawsink->fd, sizeof(struct rawsink_shared_t)) < 0) {
|
||||||
LOG_PERROR("Can't truncate RAW sink memory");
|
LOG_PERROR("Can't truncate RAW sink memory");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rawsink->picture = mmap(
|
if ((rawsink->shared = mmap(
|
||||||
NULL,
|
NULL,
|
||||||
sizeof(struct rawsink_picture_t),
|
sizeof(struct rawsink_shared_t),
|
||||||
PROT_READ | PROT_WRITE,
|
PROT_READ | PROT_WRITE,
|
||||||
MAP_SHARED,
|
MAP_SHARED,
|
||||||
rawsink->fd,
|
rawsink->fd,
|
||||||
@@ -131,8 +131,8 @@ void rawsink_destroy(struct rawsink_t *rawsink) {
|
|||||||
|
|
||||||
# undef CLOSE_SEM
|
# undef CLOSE_SEM
|
||||||
|
|
||||||
if (rawsink->picture != MAP_FAILED) {
|
if (rawsink->shared != MAP_FAILED) {
|
||||||
if (munmap(rawsink->picture, sizeof(struct rawsink_picture_t)) < 0) {
|
if (munmap(rawsink->shared, sizeof(struct rawsink_shared_t)) < 0) {
|
||||||
LOG_PERROR("Can't unmap RAW sink memory");
|
LOG_PERROR("Can't unmap RAW sink memory");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,14 +181,14 @@ void rawsink_put(
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
# define PIC(_next) rawsink->picture->_next
|
# define SH(_field) rawsink->shared->_field = _field
|
||||||
PIC(format) = format;
|
SH(format);
|
||||||
PIC(width) = width;
|
SH(width);
|
||||||
PIC(height) = height;
|
SH(height);
|
||||||
PIC(grab_ts) = grab_ts;
|
SH(grab_ts);
|
||||||
PIC(size) = size;
|
SH(size);
|
||||||
memcpy(PIC(data), data, size);
|
memcpy(rawsink->shared->data, data, size);
|
||||||
# undef PIC
|
# undef SH
|
||||||
|
|
||||||
if (sem_post(rawsink->signal_sem) < 0) {
|
if (sem_post(rawsink->signal_sem) < 0) {
|
||||||
LOG_PERROR("RAWSINK: Can't post %s", rawsink->signal_name);
|
LOG_PERROR("RAWSINK: Can't post %s", rawsink->signal_name);
|
||||||
@@ -237,14 +237,14 @@ int rawsink_get(
|
|||||||
WAIT_SEM(signal);
|
WAIT_SEM(signal);
|
||||||
WAIT_SEM(lock);
|
WAIT_SEM(lock);
|
||||||
|
|
||||||
# define PIC(_next) rawsink->picture->_next
|
# define SH(_field) *_field = rawsink->shared->_field
|
||||||
*format = PIC(format);
|
SH(format);
|
||||||
*width = PIC(width);
|
SH(width);
|
||||||
*height = PIC(height);
|
SH(height);
|
||||||
*grab_ts = PIC(grab_ts);
|
SH(grab_ts);
|
||||||
*size = PIC(size);
|
SH(size);
|
||||||
memcpy(data, PIC(data), *size);
|
memcpy(data, rawsink->shared->data, *size);
|
||||||
# undef PIC
|
# undef SH
|
||||||
|
|
||||||
if (sem_post(rawsink->lock_sem) < 0) {
|
if (sem_post(rawsink->lock_sem) < 0) {
|
||||||
LOG_PERROR("RAWSINK: Can't post %s", rawsink->lock_name);
|
LOG_PERROR("RAWSINK: Can't post %s", rawsink->lock_name);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
#define RAWSINK_MAX_DATA ((size_t)(CFG_RAWSINK_MAX_DATA))
|
#define RAWSINK_MAX_DATA ((size_t)(CFG_RAWSINK_MAX_DATA))
|
||||||
|
|
||||||
|
|
||||||
struct rawsink_picture_t {
|
struct rawsink_shared_t {
|
||||||
unsigned format;
|
unsigned format;
|
||||||
unsigned width;
|
unsigned width;
|
||||||
unsigned height;
|
unsigned height;
|
||||||
@@ -50,7 +50,7 @@ struct rawsink_t {
|
|||||||
char *lock_name;
|
char *lock_name;
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
struct rawsink_picture_t *picture;
|
struct rawsink_shared_t *shared;
|
||||||
|
|
||||||
sem_t *signal_sem;
|
sem_t *signal_sem;
|
||||||
sem_t *lock_sem;
|
sem_t *lock_sem;
|
||||||
|
|||||||
Reference in New Issue
Block a user