Skip to content

Commit

Permalink
Never format short if statements on a single line
Browse files Browse the repository at this point in the history
  • Loading branch information
killenheladagen authored and pataxis committed Feb 14, 2024
1 parent a0c1e9c commit ad57aa3
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ AlignConsecutiveMacros: Consecutive
AlignEscapedNewlines: Left
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: true
AlwaysBreakBeforeMultilineStrings: true
BinPackArguments: false
Expand Down
3 changes: 2 additions & 1 deletion object-detection-cv25/app/imgutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ void test_buffer_to_jpeg_file() {
for (int i = 0; i < width * height; i++) {
for (int channel = 0; channel < channels; channel++) {
int green_mask = 1;
if (channel == 2) green_mask = 0;
if (channel == 2)
green_mask = 0;
image_buffer[i * channels + channel] = (double)i / (width * height) * 255 * green_mask;
}
}
Expand Down
15 changes: 10 additions & 5 deletions object-detection-cv25/app/postprocessing.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ int loadDetectionStruct(const float* locations,
return 0;
}
float max(float a, float b) {
if (a > b) return a;
if (a > b)
return a;
return b;
}
float min(float a, float b) {
if (a < b) return a;
if (a < b)
return a;
return b;
}

Expand Down Expand Up @@ -174,8 +176,10 @@ void sortBoxesEfficient(box* boxes, int num_of_detections) {
j--;
}
}
if (j > 0) sortBoxesEfficient(boxes, j + 1);
if (i < num_of_detections - 1) sortBoxesEfficient(boxes + i, num_of_detections - i);
if (j > 0)
sortBoxesEfficient(boxes, j + 1);
if (i < num_of_detections - 1)
sortBoxesEfficient(boxes + i, num_of_detections - i);
}

// Calculate IOU
Expand Down Expand Up @@ -209,7 +213,8 @@ void suppressOverlappingBoxes(box* boxes, int num_of_detections, float iou_thres
int countNonNullBoxes(box* boxes, int num_of_detections) {
int count = 0;
for (int i = 0; i < num_of_detections; i++) {
if (boxes[i].score > 0) count++;
if (boxes[i].score > 0)
count++;
}
return count;
}
Expand Down
3 changes: 2 additions & 1 deletion object-detection/app/imgutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ void test_buffer_to_jpeg_file() {
for (int i = 0; i < width * height; i++) {
for (int channel = 0; channel < channels; channel++) {
int green_mask = 1;
if (channel == 2) green_mask = 0;
if (channel == 2)
green_mask = 0;
image_buffer[i * channels + channel] = (double)i / (width * height) * 255 * green_mask;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ int main(void) {
syslog(LOG_INFO, "*** 2. Transfer Failed: Unexpected result, error code: %d ***", rv);

// Close file after transfer and cleanup curl easy handle
if (fetch_file.stream) fclose(fetch_file.stream);
if (fetch_file.stream)
fclose(fetch_file.stream);
curl_easy_cleanup(curl);
}
// Cleanup of curl global environment
Expand Down
30 changes: 20 additions & 10 deletions vdo-opencl-filtering/app/vdo_cl_filter_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,16 @@ int main(int argc, char* argv[]) {
/* Create a new stream */
stream = vdo_stream_new(settings, NULL, &error);
g_clear_object(&settings);
if (!stream) goto exit;
if (!stream)
goto exit;

if (!vdo_stream_attach(stream, NULL, &error)) goto exit;
if (!vdo_stream_attach(stream, NULL, &error))
goto exit;

/* Collect stream information */
vdo_stream_info = vdo_stream_get_info(stream, &error);
if (!vdo_stream_info) goto exit;
if (!vdo_stream_info)
goto exit;

syslog(LOG_INFO,
"Starting stream: %s in %s, %ux%u, %u fps.",
Expand All @@ -427,7 +430,8 @@ int main(int argc, char* argv[]) {
g_clear_object(&vdo_stream_info);

/* Start the stream */
if (!vdo_stream_start(stream, &error)) goto exit;
if (!vdo_stream_start(stream, &error))
goto exit;

/* Open output file */
char file_path[128];
Expand Down Expand Up @@ -485,7 +489,8 @@ int main(int argc, char* argv[]) {
VdoFrame* frame = vdo_buffer_get_frame(buffer);

/* Error occurred */
if (!frame) goto exit;
if (!frame)
goto exit;

/* Get VDO frame buffer data */
gpointer in_data = vdo_buffer_get_data(buffer);
Expand All @@ -501,7 +506,8 @@ int main(int argc, char* argv[]) {
* For HALF_AREA however, we need to write the background image data
* as the cl program will not render a full image.
*/
if (cur_render_area != FULL_AREA) memcpy(out_data, in_data, image_y_size + image_cbcr_size);
if (cur_render_area != FULL_AREA)
memcpy(out_data, in_data, image_y_size + image_cbcr_size);

/*
* Map a received VDO frame buffer with a cl memory object. A cl buffer
Expand Down Expand Up @@ -533,28 +539,32 @@ int main(int argc, char* argv[]) {
}

/* Release the buffer and allow the server to reuse it */
if (!vdo_stream_buffer_unref(stream, &buffer, &error)) goto exit;
if (!vdo_stream_buffer_unref(stream, &buffer, &error))
goto exit;
}

exit:
/* Ignore expected error */
if (vdo_error_is_expected(&error)) g_clear_error(&error);
if (vdo_error_is_expected(&error))
g_clear_error(&error);

if (munmap(out_data, image_y_size + image_cbcr_size)) {
syslog(LOG_ERR, "Unable to unmap image output buffer");
}

hash_table_destroy();

if (in_images) free(in_images);
if (in_images)
free(in_images);

gint ret = EXIT_SUCCESS;
if (error) {
syslog(LOG_INFO, "vdo-encode-client: %s", error->message);
ret = EXIT_FAILURE;
}

if (output_file) fclose(output_file);
if (output_file)
fclose(output_file);

if (free_opencl() != 0) {
syslog(LOG_ERR, "Unable to clean up opencl");
Expand Down
36 changes: 24 additions & 12 deletions vdostream/app/vdoencodeclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ static void handle_sigint(int signum) { shutdown = TRUE; }

// Determine and log the received frame type
static void print_frame(VdoFrame* frame) {
if (!vdo_frame_get_is_last_buffer(frame)) return;
if (!vdo_frame_get_is_last_buffer(frame))
return;

gchar* frame_type;
switch (vdo_frame_get_frame_type(frame)) {
Expand Down Expand Up @@ -165,11 +166,13 @@ int main(int argc, char* argv[]) {
}};

GOptionContext* context = g_option_context_new(param_desc);
if (!context) return -1;
if (!context)
return -1;

g_option_context_set_summary(context, summary);
g_option_context_add_main_entries(context, options, NULL);
if (!g_option_context_parse(context, &argc, &argv, &error)) goto exit;
if (!g_option_context_parse(context, &argc, &argv, &error))
goto exit;

dest_f = fopen(output_file, "wb");
if (!dest_f) {
Expand All @@ -183,7 +186,8 @@ int main(int argc, char* argv[]) {
}

VdoMap* settings = vdo_map_new();
if (!set_format(settings, format, &error)) goto exit;
if (!set_format(settings, format, &error))
goto exit;

// Set default arguments
vdo_map_set_uint32(settings, "width", 640);
Expand All @@ -192,12 +196,15 @@ int main(int argc, char* argv[]) {
// Create a new stream
stream = vdo_stream_new(settings, NULL, &error);
g_clear_object(&settings);
if (!stream) goto exit;
if (!stream)
goto exit;

if (!vdo_stream_attach(stream, NULL, &error)) goto exit;
if (!vdo_stream_attach(stream, NULL, &error))
goto exit;

VdoMap* info = vdo_stream_get_info(stream, &error);
if (!info) goto exit;
if (!info)
goto exit;

syslog(LOG_INFO,
"Starting stream: %s, %ux%u, %u fps\n",
Expand All @@ -209,7 +216,8 @@ int main(int argc, char* argv[]) {
g_clear_object(&info);

// Start the stream
if (!vdo_stream_start(stream, &error)) goto exit;
if (!vdo_stream_start(stream, &error))
goto exit;

// Loop until interrupt by Ctrl-C or reaching G_MAXUINT
for (guint n = 0; n < frames; ++n) {
Expand All @@ -218,7 +226,8 @@ int main(int argc, char* argv[]) {
VdoFrame* frame = vdo_buffer_get_frame(buffer);

// Error occurred
if (!frame) goto exit;
if (!frame)
goto exit;

// SIGINT occurred
if (shutdown) {
Expand All @@ -242,20 +251,23 @@ int main(int argc, char* argv[]) {
}

// Release the buffer and allow the server to reuse it
if (!vdo_stream_buffer_unref(stream, &buffer, &error)) goto exit;
if (!vdo_stream_buffer_unref(stream, &buffer, &error))
goto exit;
}

exit:
// Ignore SIGINT and server maintenance
if (shutdown || vdo_error_is_expected(&error)) g_clear_error(&error);
if (shutdown || vdo_error_is_expected(&error))
g_clear_error(&error);

gint ret = EXIT_SUCCESS;
if (error) {
syslog(LOG_INFO, "vdo-encode-client: %s\n", error->message);
ret = EXIT_FAILURE;
}

if (dest_f) fclose(dest_f);
if (dest_f)
fclose(dest_f);

g_clear_error(&error);
g_clear_object(&stream);
Expand Down

0 comments on commit ad57aa3

Please sign in to comment.