Skip to content

Commit 3c116f2

Browse files
committed
device: some v4l2 cameras do not accept parameters unless streaming
This fixes 3DO camera not accepting `--camera-options=focus_absolute=100` and `--camera-options=focus_automatic_continuous=0`, and not properly configuring the sensor. The settings are applied twice (if failed) to ignore ordering problems related to auto-focus and focus-absolute value command line order.
1 parent 82dea91 commit 3c116f2

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

device/camera/camera.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,15 @@ void camera_capture_add_callbacks(camera_t *camera, buffer_list_t *capture, link
9999
int camera_set_params(camera_t *camera)
100100
{
101101
device_set_fps(camera->camera, camera->options.fps);
102-
device_set_option_list(camera->camera, camera->options.options);
102+
103+
// HACK:
104+
// Some cameras require to be in streaming to apply settings
105+
// This applies twice to avoid ordering issues (auto-focus vs focus value)
106+
if (camera->camera->n_capture_list > 0)
107+
buffer_list_set_stream(camera->camera->capture_lists[0], true);
108+
if (device_set_option_list(camera->camera, camera->options.options) < 0)
109+
device_set_option_list(camera->camera, camera->options.options);
110+
103111
device_set_option_list(camera->isp, camera->options.isp.options);
104112

105113
if (camera->options.auto_focus) {

device/device.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,32 +250,40 @@ int device_set_option_string(device_t *dev, const char *key, const char *value)
250250
return -1;
251251
}
252252

253-
void device_set_option_list(device_t *dev, const char *option_list)
253+
int device_set_option_list(device_t *dev, const char *option_list)
254254
{
255255
if (!dev || !option_list || !option_list[0]) {
256-
return;
256+
return 0;
257257
}
258258

259259
char *start = strdup(option_list);
260260
char *string = start;
261261
char *option;
262+
bool err = false;
263+
int count = 0;
262264

263265
while ((option = strsep(&string, OPTION_VALUE_LIST_SEP)) != NULL) {
264266
char *value = option;
265267
char *key = strsep(&value, "=");
266268

267269
if (value) {
268-
device_set_option_string(dev, key, value);
270+
if (device_set_option_string(dev, key, value) < 0) {
271+
err = true;
272+
}
269273
} else {
270274
LOG_INFO(dev, "Missing 'key=value' for '%s'", option);
271275
continue;
272276
}
273277

274278
// consume all separators
275279
while (strsep(&value, "="));
280+
281+
count++;
276282
}
277283

278284
free(start);
285+
286+
return err ? -count : count;
279287
}
280288

281289
int device_output_enqueued(device_t *dev)

device/device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int device_dump_options2(device_t *dev, device_option_fn fn, void *opaque);
112112
int device_set_fps(device_t *dev, int desired_fps);
113113
int device_set_rotation(device_t *dev, bool vflip, bool hflip);
114114
int device_set_option_string(device_t *dev, const char *option, const char *value);
115-
void device_set_option_list(device_t *dev, const char *option_list);
115+
int device_set_option_list(device_t *dev, const char *option_list);
116116

117117
int device_output_enqueued(device_t *dev);
118118
int device_capture_enqueued(device_t *dev, int *max);

0 commit comments

Comments
 (0)