diff --git a/src/camera.c b/src/camera.c index ad32215..458c71b 100644 --- a/src/camera.c +++ b/src/camera.c @@ -672,9 +672,7 @@ mp_control_list_free(MPControlList *list) } bool -mp_camera_query_control(int fd, - uint32_t id, - MPControl *control) +mp_camera_query_control(int fd, uint32_t id, MPControl *control) { struct v4l2_query_ext_ctrl ctrl = {}; ctrl.id = id; @@ -706,9 +704,7 @@ mp_camera_query_control(int fd, } static bool -control_impl_int32(MPControl *control, - int request, - int32_t *value) +control_impl_int32(MPControl *control, int request, int32_t *value) { struct v4l2_ext_control ctrl = {}; ctrl.id = control->id; diff --git a/src/io_pipeline.c b/src/io_pipeline.c index 78fea58..6f9bcae 100644 --- a/src/io_pipeline.c +++ b/src/io_pipeline.c @@ -66,11 +66,13 @@ update_process_pipeline() pipeline_changed = false; // Grab the latest control values 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) { - 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; @@ -153,14 +155,14 @@ capture(MPPipeline *pipeline, const void *data) // 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.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; // 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 // for manual gain you can go up to 11 frames - 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); 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); @@ -254,9 +256,8 @@ update_controls() if ((state_io.gain.manual || (!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); + mp_camera_control_set_int32_bg( + mpcamera, &state_io.gain.control, state_io.gain.value_req); state_io.gain.value = state_io.gain.value_req; state_changed = true; } @@ -334,8 +335,9 @@ do_aaa() static void on_frame(MPBuffer buffer, void *_data) { - // Don't process frame when the window is not active, unless we're capturing an image, - // in which case the flash window may be active instead of this window + // Don't process frame when the window is not active, unless we're capturing + // an image, in which case the flash window may be active instead of this + // window if (!check_window_active() && state_io.captures_remaining == 0) { return; } @@ -418,17 +420,19 @@ static void init_controls() { MPControl focus_control; - if (mp_camera_query_control( - state_io.camera->sensor_fd, V4L2_CID_FOCUS_ABSOLUTE, &focus_control)) { + if (mp_camera_query_control(state_io.camera->sensor_fd, + V4L2_CID_FOCUS_ABSOLUTE, + &focus_control)) { state_io.focus.control = focus_control; } else { state_io.focus.control.id = 0; } 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, &auto_focus_control, true); + if (mp_camera_query_control(state_io.camera->sensor_fd, + V4L2_CID_FOCUS_AUTO, + &auto_focus_control)) { + mp_camera_control_set_bool_bg(mpcamera, &auto_focus_control, true); state_io.focus.auto_control = auto_focus_control; } else { state_io.focus.auto_control.id = 0; @@ -438,11 +442,13 @@ init_controls() state_io.camera->sensor_fd, V4L2_CID_AUTO_FOCUS_START, NULL); 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.max = gain_control.max; - } else if (mp_camera_query_control( - state_io.camera->sensor_fd, V4L2_CID_ANALOGUE_GAIN, &gain_control)) { + } else if (mp_camera_query_control(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 { @@ -450,13 +456,16 @@ init_controls() state_io.gain.control.id = 0; } 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 { state_io.gain.value = 0; } 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.manual = mp_camera_control_get_bool(&auto_gain_control) == 0; @@ -465,27 +474,33 @@ init_controls() } 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.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 { state_io.exposure.control.id = 0; } MPControl auto_exposure_control; - if (mp_camera_query_control( - state_io.camera->sensor_fd, V4L2_CID_EXPOSURE_AUTO, &auto_exposure_control)) { + if (mp_camera_query_control(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(&auto_exposure_control) == V4L2_EXPOSURE_MANUAL; + mp_camera_control_get_int32(&auto_exposure_control) == + V4L2_EXPOSURE_MANUAL; } else { state_io.exposure.auto_control.id = 0; } MPControl red_control; - if (mp_camera_query_control( - state_io.camera->sensor_fd, V4L2_CID_RED_BALANCE, &red_control)) { + if (mp_camera_query_control(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 { @@ -493,8 +508,9 @@ init_controls() } MPControl blue_control; - if (mp_camera_query_control( - state_io.camera->sensor_fd, V4L2_CID_BLUE_BALANCE, &blue_control)) { + if (mp_camera_query_control(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 { @@ -621,10 +637,10 @@ update_state(MPPipeline *pipeline, const mp_state_io *new_state) void mp_io_pipeline_update_state(const mp_state_io *state) { - if (!pipeline) { - printf("no pipeline\n"); - exit(1); - } + if (!pipeline) { + printf("no pipeline\n"); + exit(1); + } mp_pipeline_invoke(pipeline, (MPPipelineCallback)update_state, state, diff --git a/src/main.c b/src/main.c index cdf9ec4..4a1fb18 100644 --- a/src/main.c +++ b/src/main.c @@ -160,12 +160,15 @@ static bool update_state(const mp_state_main *new_state) { 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); } 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); } @@ -201,7 +204,8 @@ update_state(const mp_state_main *new_state) // Make the right settings available for the camera gtk_widget_set_visible(iso_button, state.gain.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); return false; @@ -914,8 +918,8 @@ set_shutter_auto(bool is_auto) static void open_shutter_controls(GtkWidget *button, gpointer user_data) { - float value = - (float)state.exposure.value * 360.0f / (float)state.camera->current_mode->height; + float value = (float)state.exposure.value * 360.0f / + (float)state.camera->current_mode->height; open_controls(button, "Shutter", 1.0, @@ -940,30 +944,33 @@ flash_button_clicked(GtkWidget *button, gpointer user_data) void notify_movie_progress(void) { - if (!movie_start) { + if (!movie_start) { // 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 notify_movie_message(gchar *msg) { - gtk_button_set_label(GTK_BUTTON(movie), msg); + gtk_button_set_label(GTK_BUTTON(movie), msg); } void on_movie_clicked(GtkWidget *widget, gpointer user_data) { - if (movie_start) { - movie_start = 0; - gtk_button_set_icon_name(GTK_BUTTON(movie), "video-processing-symbolic"); - on_movie_stop(); - } else { - movie_start = 1; - gtk_button_set_icon_name(GTK_BUTTON(movie), "video-recording-symbolic"); - on_movie_start(); - } + if (movie_start) { + movie_start = 0; + gtk_button_set_icon_name(GTK_BUTTON(movie), + "video-processing-symbolic"); + on_movie_stop(); + } else { + movie_start = 1; + gtk_button_set_icon_name(GTK_BUTTON(movie), + "video-recording-symbolic"); + on_movie_start(); + } } static void @@ -1266,7 +1273,7 @@ activate(GtkApplication *app, gpointer data) preview_top_box = GTK_WIDGET(gtk_builder_get_object(builder, "top-box")); preview_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_label = GTK_WIDGET(gtk_builder_get_object(builder, "message-label")); @@ -1286,10 +1293,9 @@ activate(GtkApplication *app, gpointer data) g_signal_connect( flash_button, "clicked", G_CALLBACK(flash_button_clicked), NULL); - g_signal_connect(movie, "clicked", - G_CALLBACK(on_movie_clicked), NULL); + g_signal_connect(movie, "clicked", G_CALLBACK(on_movie_clicked), NULL); - setup_fb_switch(builder); + setup_fb_switch(builder); // Setup actions create_simple_action(app, "capture", G_CALLBACK(run_capture_action));