mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-16 08:56:45 -05:00
examples: catch signal and clean up
This commit is contained in:
parent
702976ab9c
commit
6b313de2ae
3 changed files with 23 additions and 8 deletions
|
|
@ -24,12 +24,8 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <time.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <sys/mman.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include <spa/param/audio/format-utils.h>
|
|
||||||
#include <spa/param/props.h>
|
|
||||||
|
|
||||||
#include <pipewire/pipewire.h>
|
#include <pipewire/pipewire.h>
|
||||||
#include <pipewire/filter.h>
|
#include <pipewire/filter.h>
|
||||||
|
|
@ -82,6 +78,12 @@ static const struct pw_filter_events filter_events = {
|
||||||
.process = on_process,
|
.process = on_process,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void do_quit(void *userdata, int signal_number)
|
||||||
|
{
|
||||||
|
struct data *data = userdata;
|
||||||
|
pw_main_loop_quit(data->loop);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct data data = { 0, };
|
struct data data = { 0, };
|
||||||
|
|
@ -92,6 +94,9 @@ int main(int argc, char *argv[])
|
||||||
* the fd of this pipewire mainloop to it. */
|
* the fd of this pipewire mainloop to it. */
|
||||||
data.loop = pw_main_loop_new(NULL);
|
data.loop = pw_main_loop_new(NULL);
|
||||||
|
|
||||||
|
pw_loop_add_signal(pw_main_loop_get_loop(data.loop), SIGINT, do_quit, &data);
|
||||||
|
pw_loop_add_signal(pw_main_loop_get_loop(data.loop), SIGTERM, do_quit, &data);
|
||||||
|
|
||||||
/* Create a simple filter, the simple filter manages the core and remote
|
/* Create a simple filter, the simple filter manages the core and remote
|
||||||
* objects for you if you don't need to deal with them.
|
* objects for you if you don't need to deal with them.
|
||||||
*
|
*
|
||||||
|
|
@ -147,6 +152,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
pw_filter_destroy(data.filter);
|
pw_filter_destroy(data.filter);
|
||||||
pw_main_loop_destroy(data.loop);
|
pw_main_loop_destroy(data.loop);
|
||||||
|
pw_deinit();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
pw_filter_destroy(data.filter);
|
pw_filter_destroy(data.filter);
|
||||||
pw_main_loop_destroy(data.loop);
|
pw_main_loop_destroy(data.loop);
|
||||||
|
pw_deinit();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,10 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <time.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <sys/mman.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include <spa/param/audio/format-utils.h>
|
#include <spa/param/audio/format-utils.h>
|
||||||
#include <spa/param/props.h>
|
|
||||||
|
|
||||||
#include <pipewire/pipewire.h>
|
#include <pipewire/pipewire.h>
|
||||||
|
|
||||||
|
|
@ -105,6 +103,12 @@ static const struct pw_stream_events stream_events = {
|
||||||
.process = on_process,
|
.process = on_process,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void do_quit(void *userdata, int signal_number)
|
||||||
|
{
|
||||||
|
struct data *data = userdata;
|
||||||
|
pw_main_loop_quit(data->loop);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct data data = { 0, };
|
struct data data = { 0, };
|
||||||
|
|
@ -118,6 +122,9 @@ int main(int argc, char *argv[])
|
||||||
* the fd of this pipewire mainloop to it. */
|
* the fd of this pipewire mainloop to it. */
|
||||||
data.loop = pw_main_loop_new(NULL);
|
data.loop = pw_main_loop_new(NULL);
|
||||||
|
|
||||||
|
pw_loop_add_signal(pw_main_loop_get_loop(data.loop), SIGINT, do_quit, &data);
|
||||||
|
pw_loop_add_signal(pw_main_loop_get_loop(data.loop), SIGTERM, do_quit, &data);
|
||||||
|
|
||||||
/* Create a simple stream, the simple stream manages the core and remote
|
/* Create a simple stream, the simple stream manages the core and remote
|
||||||
* objects for you if you don't need to deal with them.
|
* objects for you if you don't need to deal with them.
|
||||||
*
|
*
|
||||||
|
|
@ -163,6 +170,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
pw_stream_destroy(data.stream);
|
pw_stream_destroy(data.stream);
|
||||||
pw_main_loop_destroy(data.loop);
|
pw_main_loop_destroy(data.loop);
|
||||||
|
pw_deinit();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue