Run clang-format on a few files

This commit is contained in:
Kristian Vos
2024-08-04 10:40:24 +02:00
committed by Martijn Braam
parent 3280c1d113
commit 64f93cd8f2
3 changed files with 78 additions and 60 deletions

View File

@@ -672,9 +672,7 @@ mp_control_list_free(MPControlList *list)
} }
bool bool
mp_camera_query_control(int fd, mp_camera_query_control(int fd, uint32_t id, MPControl *control)
uint32_t id,
MPControl *control)
{ {
struct v4l2_query_ext_ctrl ctrl = {}; struct v4l2_query_ext_ctrl ctrl = {};
ctrl.id = id; ctrl.id = id;
@@ -706,9 +704,7 @@ mp_camera_query_control(int fd,
} }
static bool static bool
control_impl_int32(MPControl *control, control_impl_int32(MPControl *control, int request, int32_t *value)
int request,
int32_t *value)
{ {
struct v4l2_ext_control ctrl = {}; struct v4l2_ext_control ctrl = {};
ctrl.id = control->id; ctrl.id = control->id;

View File

@@ -66,11 +66,13 @@ update_process_pipeline()
pipeline_changed = false; pipeline_changed = false;
// Grab the latest control values // Grab the latest control values
if (!state_io.gain.manual && state_io.gain.control.id) { if (!state_io.gain.manual && state_io.gain.control.id) {
state_io.gain.value = mp_camera_control_get_int32(&state_io.gain.control); state_io.gain.value =
mp_camera_control_get_int32(&state_io.gain.control);
} }
if (!state_io.exposure.manual && state_io.exposure.control.id) { if (!state_io.exposure.manual && state_io.exposure.control.id) {
state_io.exposure.value = mp_camera_control_get_int32(&state_io.exposure.control); state_io.exposure.value =
mp_camera_control_get_int32(&state_io.exposure.control);
} }
float balance_red = 1.0f; float balance_red = 1.0f;
@@ -153,14 +155,14 @@ capture(MPPipeline *pipeline, const void *data)
// Disable the autogain/exposure while taking the burst // Disable the autogain/exposure while taking the burst
mp_camera_control_set_int32(&state_io.gain.auto_control, 0); mp_camera_control_set_int32(&state_io.gain.auto_control, 0);
mp_camera_control_set_int32(&state_io.exposure.auto_control, V4L2_EXPOSURE_MANUAL); mp_camera_control_set_int32(&state_io.exposure.auto_control,
V4L2_EXPOSURE_MANUAL);
// Get current gain to calculate a burst length; // Get current gain to calculate a burst length;
// with low gain there's 3, with the max automatic gain of the ov5640 // with low gain there's 3, with the max automatic gain of the ov5640
// the value seems to be 248 which creates a 5 frame burst // the value seems to be 248 which creates a 5 frame burst
// for manual gain you can go up to 11 frames // for manual gain you can go up to 11 frames
state_io.gain.value = state_io.gain.value = mp_camera_control_get_int32(&state_io.gain.control);
mp_camera_control_get_int32(&state_io.gain.control);
gain_norm = (float)state_io.gain.value / (float)state_io.gain.max; 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 = (int)fmax(sqrtf(gain_norm) * 10, 2) + 1;
state_io.burst_length = MAX(1, state_io.burst_length); state_io.burst_length = MAX(1, state_io.burst_length);
@@ -254,9 +256,8 @@ update_controls()
if ((state_io.gain.manual || if ((state_io.gain.manual ||
(!state_io.gain.manual && state_io.gain.auto_control.id == 0)) && (!state_io.gain.manual && state_io.gain.auto_control.id == 0)) &&
state_io.gain.value != state_io.gain.value_req) { state_io.gain.value != state_io.gain.value_req) {
mp_camera_control_set_int32_bg(mpcamera, mp_camera_control_set_int32_bg(
&state_io.gain.control, mpcamera, &state_io.gain.control, state_io.gain.value_req);
state_io.gain.value_req);
state_io.gain.value = state_io.gain.value_req; state_io.gain.value = state_io.gain.value_req;
state_changed = true; state_changed = true;
} }
@@ -334,8 +335,9 @@ do_aaa()
static void static void
on_frame(MPBuffer buffer, void *_data) on_frame(MPBuffer buffer, void *_data)
{ {
// Don't process frame when the window is not active, unless we're capturing an image, // Don't process frame when the window is not active, unless we're capturing
// in which case the flash window may be active instead of this window // an image, in which case the flash window may be active instead of this
// window
if (!check_window_active() && state_io.captures_remaining == 0) { if (!check_window_active() && state_io.captures_remaining == 0) {
return; return;
} }
@@ -418,17 +420,19 @@ static void
init_controls() init_controls()
{ {
MPControl focus_control; MPControl focus_control;
if (mp_camera_query_control( if (mp_camera_query_control(state_io.camera->sensor_fd,
state_io.camera->sensor_fd, V4L2_CID_FOCUS_ABSOLUTE, &focus_control)) { V4L2_CID_FOCUS_ABSOLUTE,
&focus_control)) {
state_io.focus.control = focus_control; state_io.focus.control = focus_control;
} else { } else {
state_io.focus.control.id = 0; state_io.focus.control.id = 0;
} }
MPControl auto_focus_control; MPControl auto_focus_control;
if (mp_camera_query_control(state_io.camera->sensor_fd, V4L2_CID_FOCUS_AUTO, &auto_focus_control)) { if (mp_camera_query_control(state_io.camera->sensor_fd,
mp_camera_control_set_bool_bg( V4L2_CID_FOCUS_AUTO,
mpcamera, &auto_focus_control, true); &auto_focus_control)) {
mp_camera_control_set_bool_bg(mpcamera, &auto_focus_control, true);
state_io.focus.auto_control = auto_focus_control; state_io.focus.auto_control = auto_focus_control;
} else { } else {
state_io.focus.auto_control.id = 0; state_io.focus.auto_control.id = 0;
@@ -438,11 +442,13 @@ init_controls()
state_io.camera->sensor_fd, V4L2_CID_AUTO_FOCUS_START, NULL); state_io.camera->sensor_fd, V4L2_CID_AUTO_FOCUS_START, NULL);
MPControl gain_control; MPControl gain_control;
if (mp_camera_query_control(state_io.camera->sensor_fd, V4L2_CID_GAIN, &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.control = gain_control;
state_io.gain.max = gain_control.max; state_io.gain.max = gain_control.max;
} else if (mp_camera_query_control( } else if (mp_camera_query_control(state_io.camera->sensor_fd,
state_io.camera->sensor_fd, V4L2_CID_ANALOGUE_GAIN, &gain_control)) { V4L2_CID_ANALOGUE_GAIN,
&gain_control)) {
state_io.gain.control = gain_control; state_io.gain.control = gain_control;
state_io.gain.max = gain_control.max; state_io.gain.max = gain_control.max;
} else { } else {
@@ -450,13 +456,16 @@ init_controls()
state_io.gain.control.id = 0; state_io.gain.control.id = 0;
} }
if (state_io.gain.control.id) { if (state_io.gain.control.id) {
state_io.gain.value = mp_camera_control_get_int32(&state_io.gain.control); state_io.gain.value =
mp_camera_control_get_int32(&state_io.gain.control);
} else { } else {
state_io.gain.value = 0; state_io.gain.value = 0;
} }
MPControl auto_gain_control; MPControl auto_gain_control;
if (mp_camera_query_control(state_io.camera->sensor_fd, V4L2_CID_AUTOGAIN, &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.auto_control = auto_gain_control;
state_io.gain.manual = state_io.gain.manual =
mp_camera_control_get_bool(&auto_gain_control) == 0; mp_camera_control_get_bool(&auto_gain_control) == 0;
@@ -465,27 +474,33 @@ init_controls()
} }
MPControl exposure_control; MPControl exposure_control;
if (mp_camera_query_control(state_io.camera->sensor_fd, V4L2_CID_EXPOSURE, &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.control = exposure_control;
state_io.exposure.max = exposure_control.max; state_io.exposure.max = exposure_control.max;
state_io.exposure.value = mp_camera_control_get_int32(&exposure_control); state_io.exposure.value =
mp_camera_control_get_int32(&exposure_control);
} else { } else {
state_io.exposure.control.id = 0; state_io.exposure.control.id = 0;
} }
MPControl auto_exposure_control; MPControl auto_exposure_control;
if (mp_camera_query_control( if (mp_camera_query_control(state_io.camera->sensor_fd,
state_io.camera->sensor_fd, V4L2_CID_EXPOSURE_AUTO, &auto_exposure_control)) { V4L2_CID_EXPOSURE_AUTO,
&auto_exposure_control)) {
state_io.exposure.auto_control = auto_exposure_control; state_io.exposure.auto_control = auto_exposure_control;
state_io.exposure.manual = state_io.exposure.manual =
mp_camera_control_get_int32(&auto_exposure_control) == V4L2_EXPOSURE_MANUAL; mp_camera_control_get_int32(&auto_exposure_control) ==
V4L2_EXPOSURE_MANUAL;
} else { } else {
state_io.exposure.auto_control.id = 0; state_io.exposure.auto_control.id = 0;
} }
MPControl red_control; MPControl red_control;
if (mp_camera_query_control( if (mp_camera_query_control(state_io.camera->sensor_fd,
state_io.camera->sensor_fd, V4L2_CID_RED_BALANCE, &red_control)) { V4L2_CID_RED_BALANCE,
&red_control)) {
state_io.red.control = red_control; state_io.red.control = red_control;
state_io.red.max = red_control.max; state_io.red.max = red_control.max;
} else { } else {
@@ -493,8 +508,9 @@ init_controls()
} }
MPControl blue_control; MPControl blue_control;
if (mp_camera_query_control( if (mp_camera_query_control(state_io.camera->sensor_fd,
state_io.camera->sensor_fd, V4L2_CID_BLUE_BALANCE, &blue_control)) { V4L2_CID_BLUE_BALANCE,
&blue_control)) {
state_io.blue.control = blue_control; state_io.blue.control = blue_control;
state_io.blue.max = blue_control.max; state_io.blue.max = blue_control.max;
} else { } else {
@@ -621,10 +637,10 @@ update_state(MPPipeline *pipeline, const mp_state_io *new_state)
void void
mp_io_pipeline_update_state(const mp_state_io *state) mp_io_pipeline_update_state(const mp_state_io *state)
{ {
if (!pipeline) { if (!pipeline) {
printf("no pipeline\n"); printf("no pipeline\n");
exit(1); exit(1);
} }
mp_pipeline_invoke(pipeline, mp_pipeline_invoke(pipeline,
(MPPipelineCallback)update_state, (MPPipelineCallback)update_state,
state, state,

View File

@@ -160,12 +160,15 @@ static bool
update_state(const mp_state_main *new_state) update_state(const mp_state_main *new_state)
{ {
if (state.exposure.manual != new_state->exposure.manual) { if (state.exposure.manual != new_state->exposure.manual) {
const char *icon_name = new_state->exposure.manual ? "shutter-man-symbolic" : "shutter-auto-symbolic"; const char *icon_name = new_state->exposure.manual ?
"shutter-man-symbolic" :
"shutter-auto-symbolic";
gtk_button_set_icon_name(GTK_BUTTON(shutter_button), icon_name); gtk_button_set_icon_name(GTK_BUTTON(shutter_button), icon_name);
} }
if (state.gain.manual != new_state->gain.manual) { if (state.gain.manual != new_state->gain.manual) {
const char *icon_name = new_state->gain.manual ? "iso-man-symbolic" : "iso-auto-symbolic"; const char *icon_name = new_state->gain.manual ? "iso-man-symbolic" :
"iso-auto-symbolic";
gtk_button_set_icon_name(GTK_BUTTON(iso_button), icon_name); gtk_button_set_icon_name(GTK_BUTTON(iso_button), icon_name);
} }
@@ -201,7 +204,8 @@ update_state(const mp_state_main *new_state)
// Make the right settings available for the camera // Make the right settings available for the camera
gtk_widget_set_visible(iso_button, state.gain.control.id != 0); gtk_widget_set_visible(iso_button, state.gain.control.id != 0);
gtk_widget_set_visible(shutter_button, state.exposure.control.id != 0); gtk_widget_set_visible(shutter_button, state.exposure.control.id != 0);
// Even if there's no flash led/v4l, it'll just default to using the screen as flash, so always enable this button // Even if there's no flash led/v4l, it'll just default to using the screen
// as flash, so always enable this button
gtk_widget_set_visible(flash_button, true); gtk_widget_set_visible(flash_button, true);
return false; return false;
@@ -914,8 +918,8 @@ set_shutter_auto(bool is_auto)
static void static void
open_shutter_controls(GtkWidget *button, gpointer user_data) open_shutter_controls(GtkWidget *button, gpointer user_data)
{ {
float value = float value = (float)state.exposure.value * 360.0f /
(float)state.exposure.value * 360.0f / (float)state.camera->current_mode->height; (float)state.camera->current_mode->height;
open_controls(button, open_controls(button,
"Shutter", "Shutter",
1.0, 1.0,
@@ -940,30 +944,33 @@ flash_button_clicked(GtkWidget *button, gpointer user_data)
void void
notify_movie_progress(void) notify_movie_progress(void)
{ {
if (!movie_start) { if (!movie_start) {
// Recording started // Recording started
gtk_button_set_icon_name(GTK_BUTTON(movie), "video-recording-symbolic"); gtk_button_set_icon_name(GTK_BUTTON(movie),
"video-recording-symbolic");
} }
} }
void void
notify_movie_message(gchar *msg) notify_movie_message(gchar *msg)
{ {
gtk_button_set_label(GTK_BUTTON(movie), msg); gtk_button_set_label(GTK_BUTTON(movie), msg);
} }
void void
on_movie_clicked(GtkWidget *widget, gpointer user_data) on_movie_clicked(GtkWidget *widget, gpointer user_data)
{ {
if (movie_start) { if (movie_start) {
movie_start = 0; movie_start = 0;
gtk_button_set_icon_name(GTK_BUTTON(movie), "video-processing-symbolic"); gtk_button_set_icon_name(GTK_BUTTON(movie),
on_movie_stop(); "video-processing-symbolic");
} else { on_movie_stop();
movie_start = 1; } else {
gtk_button_set_icon_name(GTK_BUTTON(movie), "video-recording-symbolic"); movie_start = 1;
on_movie_start(); gtk_button_set_icon_name(GTK_BUTTON(movie),
} "video-recording-symbolic");
on_movie_start();
}
} }
static void static void
@@ -1266,7 +1273,7 @@ activate(GtkApplication *app, gpointer data)
preview_top_box = GTK_WIDGET(gtk_builder_get_object(builder, "top-box")); preview_top_box = GTK_WIDGET(gtk_builder_get_object(builder, "top-box"));
preview_bottom_box = preview_bottom_box =
GTK_WIDGET(gtk_builder_get_object(builder, "bottom-box")); GTK_WIDGET(gtk_builder_get_object(builder, "bottom-box"));
movie = GTK_WIDGET(gtk_builder_get_object(builder, "movie")); movie = GTK_WIDGET(gtk_builder_get_object(builder, "movie"));
message_box = GTK_WIDGET(gtk_builder_get_object(builder, "message-box")); message_box = GTK_WIDGET(gtk_builder_get_object(builder, "message-box"));
message_label = GTK_WIDGET(gtk_builder_get_object(builder, "message-label")); message_label = GTK_WIDGET(gtk_builder_get_object(builder, "message-label"));
@@ -1286,10 +1293,9 @@ activate(GtkApplication *app, gpointer data)
g_signal_connect( g_signal_connect(
flash_button, "clicked", G_CALLBACK(flash_button_clicked), NULL); flash_button, "clicked", G_CALLBACK(flash_button_clicked), NULL);
g_signal_connect(movie, "clicked", g_signal_connect(movie, "clicked", G_CALLBACK(on_movie_clicked), NULL);
G_CALLBACK(on_movie_clicked), NULL);
setup_fb_switch(builder); setup_fb_switch(builder);
// Setup actions // Setup actions
create_simple_action(app, "capture", G_CALLBACK(run_capture_action)); create_simple_action(app, "capture", G_CALLBACK(run_capture_action));