|
@@ -25,7 +25,7 @@ static GSource *capture_source;
|
|
|
static bool pipeline_changed = true;
|
|
|
|
|
|
typedef struct invoke_set_control {
|
|
|
- uint32_t control;
|
|
|
+ MPControl *control;
|
|
|
int32_t int_value;
|
|
|
bool bool_value;
|
|
|
} invoke_set_control;
|
|
@@ -65,23 +65,19 @@ update_process_pipeline()
|
|
|
}
|
|
|
pipeline_changed = false;
|
|
|
|
|
|
- if (!state_io.gain.manual && state_io.gain.control) {
|
|
|
- state_io.gain.value = mp_camera_control_get_int32(
|
|
|
- state_io.camera, state_io.gain.control, FD_TYPE_SENSOR);
|
|
|
+ if (!state_io.gain.manual && state_io.gain.control.id) {
|
|
|
+ state_io.gain.value = mp_camera_control_get_int32(&state_io.gain.control);
|
|
|
}
|
|
|
|
|
|
- if (!state_io.exposure.manual && state_io.exposure.control) {
|
|
|
- state_io.exposure.value = mp_camera_control_get_int32(
|
|
|
- state_io.camera, state_io.exposure.control, FD_TYPE_SENSOR);
|
|
|
+ if (!state_io.exposure.manual && state_io.exposure.control.id) {
|
|
|
+ state_io.exposure.value = mp_camera_control_get_int32(&state_io.exposure.control);
|
|
|
}
|
|
|
|
|
|
float balance_red = 1.0f;
|
|
|
float balance_blue = 1.0f;
|
|
|
- if (state_io.red.control && state_io.blue.control) {
|
|
|
- int red = mp_camera_control_get_int32(state_io.camera,
|
|
|
- state_io.red.control, FD_TYPE_SENSOR);
|
|
|
- int blue = mp_camera_control_get_int32(state_io.camera,
|
|
|
- state_io.blue.control, FD_TYPE_SENSOR);
|
|
|
+ if (state_io.red.control.id && state_io.blue.control.id) {
|
|
|
+ int red = mp_camera_control_get_int32(&state_io.red.control);
|
|
|
+ int blue = mp_camera_control_get_int32(&state_io.blue.control);
|
|
|
balance_red = (float)red / (float)state_io.red.max;
|
|
|
balance_blue = (float)blue / (float)state_io.blue.max;
|
|
|
}
|
|
@@ -136,11 +132,11 @@ static void
|
|
|
set_control_int32(MPPipeline *pipeline, const void *data)
|
|
|
{
|
|
|
const invoke_set_control *control_data = (const invoke_set_control *)data;
|
|
|
- mp_camera_control_set_int32(state_io.camera, control_data->control, control_data->int_value);
|
|
|
+ mp_camera_control_set_int32(control_data->control, control_data->int_value);
|
|
|
}
|
|
|
|
|
|
void
|
|
|
-mp_io_pipeline_set_control_int32(uint32_t control, uint32_t value)
|
|
|
+mp_io_pipeline_set_control_int32(MPControl *control, uint32_t value)
|
|
|
{
|
|
|
invoke_set_control data = { 0 };
|
|
|
data.control = control;
|
|
@@ -156,16 +152,15 @@ capture(MPPipeline *pipeline, const void *data)
|
|
|
float gain_norm;
|
|
|
|
|
|
|
|
|
- mp_camera_control_set_int32(state_io.camera, V4L2_CID_AUTOGAIN, 0);
|
|
|
- mp_camera_control_set_int32(
|
|
|
- state_io.camera, V4L2_CID_EXPOSURE_AUTO, V4L2_EXPOSURE_MANUAL);
|
|
|
+ mp_camera_control_set_int32(&state_io.gain.auto_control, 0);
|
|
|
+ mp_camera_control_set_int32(&state_io.exposure.auto_control, V4L2_EXPOSURE_MANUAL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state_io.gain.value =
|
|
|
- mp_camera_control_get_int32(state_io.camera, V4L2_CID_GAIN, FD_TYPE_SENSOR);
|
|
|
+ mp_camera_control_get_int32(&state_io.gain.control);
|
|
|
gain_norm = (float)state_io.gain.value / (float)state_io.gain.max;
|
|
|
state_io.burst_length = (int)fmax(sqrtf(gain_norm) * 10, 2) + 1;
|
|
|
state_io.burst_length = MAX(1, state_io.burst_length);
|
|
@@ -221,12 +216,16 @@ start_focus()
|
|
|
!mp_camera_check_task_complete(mpcamera, focus_continuous_task))
|
|
|
return;
|
|
|
|
|
|
- if (state_io.focus.control) {
|
|
|
+ if (state_io.focus.control.id) {
|
|
|
focus_continuous_task = mp_camera_control_set_bool_bg(
|
|
|
- mpcamera, state_io.focus.control, 1);
|
|
|
+ mpcamera, &state_io.focus.control, 1);
|
|
|
} else if (state_io.can_af_trigger) {
|
|
|
+
|
|
|
+ MPControl auto_focus_start_control;
|
|
|
+ auto_focus_start_control.id = V4L2_CID_AUTO_FOCUS_START;
|
|
|
+ auto_focus_start_control.fd = state_io.camera->sensor_fd;
|
|
|
start_focus_task = mp_camera_control_set_bool_bg(
|
|
|
- mpcamera, V4L2_CID_AUTO_FOCUS_START, 1);
|
|
|
+ mpcamera, &auto_focus_start_control, 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -246,26 +245,25 @@ update_controls()
|
|
|
|
|
|
if (state_io.gain.manual != state_io.gain.manual_req) {
|
|
|
mp_camera_control_set_bool_bg(mpcamera,
|
|
|
- V4L2_CID_AUTOGAIN,
|
|
|
+ &state_io.gain.auto_control,
|
|
|
!state_io.gain.manual_req);
|
|
|
state_io.gain.manual = state_io.gain.manual_req;
|
|
|
state_changed = true;
|
|
|
}
|
|
|
|
|
|
if ((state_io.gain.manual ||
|
|
|
- (!state_io.gain.manual && state_io.gain.auto_control == 0)) &&
|
|
|
+ (!state_io.gain.manual && state_io.gain.auto_control.id == 0)) &&
|
|
|
state_io.gain.value != state_io.gain.value_req) {
|
|
|
mp_camera_control_set_int32_bg(mpcamera,
|
|
|
- state_io.gain.control,
|
|
|
- state_io.gain.value_req,
|
|
|
- FD_TYPE_SENSOR);
|
|
|
+ &state_io.gain.control,
|
|
|
+ state_io.gain.value_req);
|
|
|
state_io.gain.value = state_io.gain.value_req;
|
|
|
state_changed = true;
|
|
|
}
|
|
|
|
|
|
if (state_io.exposure.manual != state_io.exposure.manual_req) {
|
|
|
mp_camera_control_set_bool_bg(mpcamera,
|
|
|
- V4L2_CID_EXPOSURE_AUTO,
|
|
|
+ &state_io.exposure.auto_control,
|
|
|
state_io.exposure.manual_req ?
|
|
|
V4L2_EXPOSURE_MANUAL :
|
|
|
V4L2_EXPOSURE_AUTO);
|
|
@@ -276,9 +274,8 @@ update_controls()
|
|
|
if (state_io.exposure.manual &&
|
|
|
state_io.exposure.value != state_io.exposure.value_req) {
|
|
|
mp_camera_control_set_int32_bg(mpcamera,
|
|
|
- state_io.exposure.control,
|
|
|
- state_io.exposure.value_req,
|
|
|
- FD_TYPE_SENSOR);
|
|
|
+ &state_io.exposure.control,
|
|
|
+ state_io.exposure.value_req);
|
|
|
state_io.exposure.value = state_io.exposure.value_req;
|
|
|
state_changed = true;
|
|
|
}
|
|
@@ -293,7 +290,7 @@ static void
|
|
|
do_aaa()
|
|
|
{
|
|
|
bool auto_exposure =
|
|
|
- !state_io.exposure.manual && state_io.exposure.auto_control == 0;
|
|
|
+ !state_io.exposure.manual && state_io.exposure.auto_control.id == 0;
|
|
|
|
|
|
if (auto_exposure) {
|
|
|
int direction = state_io.stats.exposure;
|
|
@@ -388,14 +385,13 @@ on_frame(MPBuffer buffer, void *_data)
|
|
|
if (!state_io.exposure.manual) {
|
|
|
mp_camera_control_set_int32_bg(
|
|
|
mpcamera,
|
|
|
- V4L2_CID_EXPOSURE_AUTO,
|
|
|
- V4L2_EXPOSURE_AUTO,
|
|
|
- FD_TYPE_SENSOR);
|
|
|
+ &state_io.exposure.auto_control,
|
|
|
+ V4L2_EXPOSURE_AUTO);
|
|
|
}
|
|
|
|
|
|
if (!state_io.gain.manual) {
|
|
|
mp_camera_control_set_bool_bg(
|
|
|
- mpcamera, V4L2_CID_AUTOGAIN, true);
|
|
|
+ mpcamera, &state_io.gain.auto_control, true);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -421,88 +417,88 @@ on_frame(MPBuffer buffer, void *_data)
|
|
|
static void
|
|
|
init_controls()
|
|
|
{
|
|
|
+ MPControl focus_control;
|
|
|
if (mp_camera_query_control(
|
|
|
- state_io.camera, V4L2_CID_FOCUS_ABSOLUTE, NULL, FD_TYPE_SENSOR)) {
|
|
|
-
|
|
|
- state_io.focus.control = V4L2_CID_FOCUS_ABSOLUTE;
|
|
|
+ state_io.camera->sensor_fd, V4L2_CID_FOCUS_ABSOLUTE, &focus_control)) {
|
|
|
+ state_io.focus.control = focus_control;
|
|
|
} else {
|
|
|
- state_io.focus.control = 0;
|
|
|
+ state_io.focus.control.id = 0;
|
|
|
}
|
|
|
|
|
|
- if (mp_camera_query_control(state_io.camera, V4L2_CID_FOCUS_AUTO, NULL, FD_TYPE_SENSOR)) {
|
|
|
+ MPControl auto_focus_control;
|
|
|
+ if (mp_camera_query_control(state_io.camera->sensor_fd, V4L2_CID_FOCUS_AUTO, &auto_focus_control)) {
|
|
|
mp_camera_control_set_bool_bg(
|
|
|
- mpcamera, V4L2_CID_FOCUS_AUTO, true);
|
|
|
- state_io.focus.auto_control = V4L2_CID_FOCUS_AUTO;
|
|
|
+ mpcamera, &auto_focus_control, true);
|
|
|
+ state_io.focus.auto_control = auto_focus_control;
|
|
|
} else {
|
|
|
- state_io.focus.auto_control = 0;
|
|
|
+ state_io.focus.auto_control.id = 0;
|
|
|
}
|
|
|
|
|
|
state_io.can_af_trigger = mp_camera_query_control(
|
|
|
- state_io.camera, V4L2_CID_AUTO_FOCUS_START, NULL, FD_TYPE_SENSOR);
|
|
|
+ state_io.camera->sensor_fd, V4L2_CID_AUTO_FOCUS_START, NULL);
|
|
|
|
|
|
- MPControl control;
|
|
|
- if (mp_camera_query_control(state_io.camera, V4L2_CID_GAIN, &control, FD_TYPE_SENSOR)) {
|
|
|
- state_io.gain.control = V4L2_CID_GAIN;
|
|
|
- state_io.gain.max = control.max;
|
|
|
+ MPControl gain_control;
|
|
|
+ if (mp_camera_query_control(state_io.camera->sensor_fd, V4L2_CID_GAIN, &gain_control)) {
|
|
|
+ state_io.gain.control = gain_control;
|
|
|
+ state_io.gain.max = gain_control.max;
|
|
|
} else if (mp_camera_query_control(
|
|
|
- state_io.camera, V4L2_CID_ANALOGUE_GAIN, &control, FD_TYPE_SENSOR)) {
|
|
|
- state_io.gain.control = V4L2_CID_ANALOGUE_GAIN;
|
|
|
- state_io.gain.max = control.max;
|
|
|
+ state_io.camera->sensor_fd, V4L2_CID_ANALOGUE_GAIN, &gain_control)) {
|
|
|
+ state_io.gain.control = gain_control;
|
|
|
+ state_io.gain.max = gain_control.max;
|
|
|
} else {
|
|
|
state_io.gain.max = 0;
|
|
|
- state_io.gain.control = 0;
|
|
|
+ state_io.gain.control.id = 0;
|
|
|
}
|
|
|
- if (state_io.gain.control) {
|
|
|
- state_io.gain.value = mp_camera_control_get_int32(
|
|
|
- state_io.camera, state_io.gain.control, FD_TYPE_SENSOR);
|
|
|
+ if (state_io.gain.control.id) {
|
|
|
+ state_io.gain.value = mp_camera_control_get_int32(&state_io.gain.control);
|
|
|
} else {
|
|
|
state_io.gain.value = 0;
|
|
|
}
|
|
|
|
|
|
- if (mp_camera_query_control(state_io.camera, V4L2_CID_AUTOGAIN, &control, FD_TYPE_SENSOR)) {
|
|
|
- state_io.gain.auto_control = V4L2_CID_AUTOGAIN;
|
|
|
+ MPControl auto_gain_control;
|
|
|
+ if (mp_camera_query_control(state_io.camera->sensor_fd, V4L2_CID_AUTOGAIN, &auto_gain_control)) {
|
|
|
+ state_io.gain.auto_control = auto_gain_control;
|
|
|
state_io.gain.manual =
|
|
|
- mp_camera_control_get_bool(state_io.camera,
|
|
|
- V4L2_CID_AUTOGAIN) == 0;
|
|
|
+ mp_camera_control_get_bool(&auto_gain_control) == 0;
|
|
|
} else {
|
|
|
- state_io.gain.auto_control = 0;
|
|
|
+ state_io.gain.auto_control.id = 0;
|
|
|
}
|
|
|
|
|
|
- if (mp_camera_query_control(state_io.camera, V4L2_CID_EXPOSURE, &control, FD_TYPE_SENSOR)) {
|
|
|
- state_io.exposure.control = V4L2_CID_EXPOSURE;
|
|
|
- state_io.exposure.max = control.max;
|
|
|
- state_io.exposure.value = mp_camera_control_get_int32(
|
|
|
- state_io.camera, V4L2_CID_EXPOSURE, FD_TYPE_SENSOR);
|
|
|
-
|
|
|
+ MPControl exposure_control;
|
|
|
+ if (mp_camera_query_control(state_io.camera->sensor_fd, V4L2_CID_EXPOSURE, &exposure_control)) {
|
|
|
+ state_io.exposure.control = exposure_control;
|
|
|
+ state_io.exposure.max = exposure_control.max;
|
|
|
+ state_io.exposure.value = mp_camera_control_get_int32(&exposure_control);
|
|
|
} else {
|
|
|
- state_io.exposure.control = 0;
|
|
|
+ state_io.exposure.control.id = 0;
|
|
|
}
|
|
|
|
|
|
+ MPControl auto_exposure_control;
|
|
|
if (mp_camera_query_control(
|
|
|
- state_io.camera, V4L2_CID_EXPOSURE_AUTO, &control, FD_TYPE_SENSOR)) {
|
|
|
- state_io.exposure.auto_control = V4L2_CID_EXPOSURE_AUTO;
|
|
|
+ state_io.camera->sensor_fd, V4L2_CID_EXPOSURE_AUTO, &auto_exposure_control)) {
|
|
|
+ state_io.exposure.auto_control = auto_exposure_control;
|
|
|
state_io.exposure.manual =
|
|
|
- mp_camera_control_get_int32(state_io.camera,
|
|
|
- V4L2_CID_EXPOSURE_AUTO, FD_TYPE_SENSOR) ==
|
|
|
- V4L2_EXPOSURE_MANUAL;
|
|
|
+ mp_camera_control_get_int32(&auto_exposure_control) == V4L2_EXPOSURE_MANUAL;
|
|
|
} else {
|
|
|
- state_io.exposure.auto_control = 0;
|
|
|
+ state_io.exposure.auto_control.id = 0;
|
|
|
}
|
|
|
|
|
|
+ MPControl red_control;
|
|
|
if (mp_camera_query_control(
|
|
|
- state_io.camera, V4L2_CID_RED_BALANCE, &control, FD_TYPE_SENSOR)) {
|
|
|
- state_io.red.control = V4L2_CID_RED_BALANCE;
|
|
|
- state_io.red.max = control.max;
|
|
|
+ state_io.camera->sensor_fd, V4L2_CID_RED_BALANCE, &red_control)) {
|
|
|
+ state_io.red.control = red_control;
|
|
|
+ state_io.red.max = red_control.max;
|
|
|
} else {
|
|
|
- state_io.red.control = 0;
|
|
|
+ state_io.red.control.id = 0;
|
|
|
}
|
|
|
|
|
|
+ MPControl blue_control;
|
|
|
if (mp_camera_query_control(
|
|
|
- state_io.camera, V4L2_CID_BLUE_BALANCE, &control, FD_TYPE_SENSOR)) {
|
|
|
- state_io.blue.control = V4L2_CID_BLUE_BALANCE;
|
|
|
- state_io.blue.max = control.max;
|
|
|
+ state_io.camera->sensor_fd, V4L2_CID_BLUE_BALANCE, &blue_control)) {
|
|
|
+ state_io.blue.control = blue_control;
|
|
|
+ state_io.blue.max = blue_control.max;
|
|
|
} else {
|
|
|
- state_io.blue.control = 0;
|
|
|
+ state_io.blue.control.id = 0;
|
|
|
}
|
|
|
|
|
|
pipeline_changed = true;
|