examples: add signal handler for clean exit

This commit is contained in:
Wim Taymans 2020-06-04 10:10:08 +02:00
parent 197ffe32ba
commit 33cd2495b8
2 changed files with 21 additions and 6 deletions

View file

@ -61,6 +61,7 @@ struct data {
double crop;
double accumulator;
int res;
};
static void draw_elipse(uint32_t *dst, int width, int height, uint32_t color)
@ -296,8 +297,11 @@ int main(int argc, char *argv[])
data.timer = pw_loop_add_timer(pw_main_loop_get_loop(data.loop), on_timeout, &data);
data.core = pw_context_connect(data.context, NULL, 0);
if (data.core == NULL)
return -1;
if (data.core == NULL) {
fprintf(stderr, "can't connect: %m\n");
data.res = -errno;
goto cleanup;
}
data.stream = pw_stream_new(data.core, "video-src",
pw_properties_new(
@ -329,9 +333,10 @@ int main(int argc, char *argv[])
pw_main_loop_run(data.loop);
cleanup:
pw_context_destroy(data.context);
pw_main_loop_destroy(data.loop);
pw_deinit();
return 0;
return data.res;
}