Wait for postprocess process to complete before updating preview

Fixes #27
Fixes #28
This commit is contained in:
Benjamin Schaaf
2021-01-06 19:12:11 +11:00
parent 52e2fdcbd0
commit 153d8c93e2
3 changed files with 48 additions and 7 deletions

View File

@@ -301,6 +301,28 @@ process_image_for_capture(const MPImage *image, int count)
TIFFClose(tif);
}
static void
post_process_finished(GSubprocess *proc, GAsyncResult *res, gpointer user_data)
{
char *stdout;
g_subprocess_communicate_utf8_finish(proc, res, &stdout, NULL, NULL);
// The last line contains the file name
int end = strlen(stdout);
// Skip the newline at the end
stdout[--end] = '\0';
char *path = path = stdout + end - 1;
do {
if (*path == '\n') {
break;
}
--path;
} while (path > stdout);
mp_main_capture_completed(path);
}
static void
process_capture_burst()
{
@@ -315,9 +337,27 @@ process_capture_burst()
// Start post-processing the captured burst
g_print("Post process %s to %s.ext\n", burst_dir, capture_fname);
char command[1024];
sprintf(command, "%s %s %s &", processing_script, burst_dir, capture_fname);
system(command);
GError *error = NULL;
GSubprocess *proc = g_subprocess_new(
G_SUBPROCESS_FLAGS_STDOUT_PIPE,
&error,
processing_script,
burst_dir,
capture_fname,
NULL);
if (!proc) {
g_printerr("Failed to spawn postprocess process: %s\n",
error->message);
return;
}
g_subprocess_communicate_utf8_async(
proc,
NULL,
NULL,
(GAsyncReadyCallback)post_process_finished,
NULL);
}
static void
@@ -335,8 +375,6 @@ process_image(MPPipeline *pipeline, const MPImage *image)
if (captures_remaining == 0) {
process_capture_burst();
mp_main_capture_completed(capture_fname);
}
}