mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-04-12 17:46:13 +00:00
refactoring
This commit is contained in:
13
src/device.c
13
src/device.c
@@ -84,7 +84,6 @@ static const char *_standard_to_string(v4l2_std_id standard);
|
|||||||
|
|
||||||
|
|
||||||
struct device_t *device_init(void) {
|
struct device_t *device_init(void) {
|
||||||
struct controls_t *ctl;
|
|
||||||
struct device_runtime_t *run;
|
struct device_runtime_t *run;
|
||||||
struct device_t *dev;
|
struct device_t *dev;
|
||||||
long cores_sysconf;
|
long cores_sysconf;
|
||||||
@@ -94,8 +93,6 @@ struct device_t *device_init(void) {
|
|||||||
cores_sysconf = (cores_sysconf < 0 ? 0 : cores_sysconf);
|
cores_sysconf = (cores_sysconf < 0 ? 0 : cores_sysconf);
|
||||||
cores_available = max_u(min_u(cores_sysconf, 4), 1);
|
cores_available = max_u(min_u(cores_sysconf, 4), 1);
|
||||||
|
|
||||||
A_CALLOC(ctl, 1);
|
|
||||||
|
|
||||||
A_CALLOC(run, 1);
|
A_CALLOC(run, 1);
|
||||||
run->fd = -1;
|
run->fd = -1;
|
||||||
|
|
||||||
@@ -109,14 +106,12 @@ struct device_t *device_init(void) {
|
|||||||
dev->n_workers = min_u(cores_available, dev->n_buffers);
|
dev->n_workers = min_u(cores_available, dev->n_buffers);
|
||||||
dev->timeout = 1;
|
dev->timeout = 1;
|
||||||
dev->error_delay = 1;
|
dev->error_delay = 1;
|
||||||
dev->ctl = ctl;
|
|
||||||
dev->run = run;
|
dev->run = run;
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
void device_destroy(struct device_t *dev) {
|
void device_destroy(struct device_t *dev) {
|
||||||
free(dev->run);
|
free(dev->run);
|
||||||
free(dev->ctl);
|
|
||||||
free(dev);
|
free(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -618,14 +613,14 @@ static void _device_apply_controls(struct device_t *dev) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# define SET_CID_MANUAL(_cid, _dest) { \
|
# define SET_CID_MANUAL(_cid, _dest) { \
|
||||||
if (dev->ctl->_dest.value_set) { \
|
if (dev->ctl._dest.value_set) { \
|
||||||
SET_CID(_cid, _dest, dev->ctl->_dest.value, false); \
|
SET_CID(_cid, _dest, dev->ctl._dest.value, false); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
# define SET_CID_AUTO(_cid_auto, _cid_manual, _dest) { \
|
# define SET_CID_AUTO(_cid_auto, _cid_manual, _dest) { \
|
||||||
if (dev->ctl->_dest.value_set || dev->ctl->_dest.auto_set) { \
|
if (dev->ctl._dest.value_set || dev->ctl._dest.auto_set) { \
|
||||||
SET_CID(_cid_auto, _dest##_auto, dev->ctl->_dest.auto_set, dev->ctl->_dest.value_set); \
|
SET_CID(_cid_auto, _dest##_auto, dev->ctl._dest.auto_set, dev->ctl._dest.value_set); \
|
||||||
SET_CID_MANUAL(_cid_manual, _dest); \
|
SET_CID_MANUAL(_cid_manual, _dest); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ struct device_t {
|
|||||||
unsigned timeout;
|
unsigned timeout;
|
||||||
unsigned error_delay;
|
unsigned error_delay;
|
||||||
|
|
||||||
struct controls_t *ctl;
|
struct controls_t ctl;
|
||||||
|
|
||||||
struct device_runtime_t *run;
|
struct device_runtime_t *run;
|
||||||
};
|
};
|
||||||
|
|||||||
10
src/main.c
10
src/main.c
@@ -264,15 +264,15 @@ static int _parse_options(int argc, char *argv[], struct device_t *dev, struct e
|
|||||||
}
|
}
|
||||||
|
|
||||||
# define OPT_CTL(_dest) { \
|
# define OPT_CTL(_dest) { \
|
||||||
dev->ctl->_dest.value_set = true; \
|
dev->ctl._dest.value_set = true; \
|
||||||
dev->ctl->_dest.auto_set = false; \
|
dev->ctl._dest.auto_set = false; \
|
||||||
OPT_NUMBER("--"#_dest, dev->ctl->_dest.value, INT_MIN, INT_MAX, 0); \
|
OPT_NUMBER("--"#_dest, dev->ctl._dest.value, INT_MIN, INT_MAX, 0); \
|
||||||
break; \
|
break; \
|
||||||
}
|
}
|
||||||
|
|
||||||
# define OPT_CTL_AUTO(_dest) { \
|
# define OPT_CTL_AUTO(_dest) { \
|
||||||
dev->ctl->_dest.value_set = false; \
|
dev->ctl._dest.value_set = false; \
|
||||||
dev->ctl->_dest.auto_set = true; \
|
dev->ctl._dest.auto_set = true; \
|
||||||
break; \
|
break; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user