media-session: install ctrl-C handler

..so that we can clean up.
This commit is contained in:
Wim Taymans 2020-06-01 18:14:53 +02:00
parent 1246116f06
commit 34dada9c4c

View file

@ -28,6 +28,7 @@
#include <math.h> #include <math.h>
#include <getopt.h> #include <getopt.h>
#include <time.h> #include <time.h>
#include <signal.h>
#include "config.h" #include "config.h"
@ -1637,7 +1638,7 @@ static void core_error(void *data, uint32_t id, int seq, int res, const char *me
pw_log_error("error id:%u seq:%d res:%d (%s): %s", pw_log_error("error id:%u seq:%d res:%d (%s): %s",
id, seq, res, spa_strerror(res), message); id, seq, res, spa_strerror(res), message);
if (id == 0) { if (id == PW_ID_CORE) {
if (res == -EPIPE) if (res == -EPIPE)
pw_main_loop_quit(impl->loop); pw_main_loop_quit(impl->loop);
} }
@ -1691,6 +1692,8 @@ static void session_shutdown(struct impl *impl)
{ {
struct sm_object *obj; struct sm_object *obj;
pw_log_info(NAME" %p", impl);
spa_list_for_each(obj, &impl->global_list, link) spa_list_for_each(obj, &impl->global_list, link)
sm_media_session_emit_remove(impl, obj); sm_media_session_emit_remove(impl, obj);
@ -1706,6 +1709,13 @@ static void session_shutdown(struct impl *impl)
pw_core_info_free(impl->this.info); pw_core_info_free(impl->this.info);
} }
static void do_quit(void *data, int signal_number)
{
struct impl *impl = data;
pw_main_loop_quit(impl->loop);
}
#define DEFAULT_ENABLED "alsa-pcm,alsa-seq,v4l2,bluez5,metadata,suspend-node,policy-node" #define DEFAULT_ENABLED "alsa-pcm,alsa-seq,v4l2,bluez5,metadata,suspend-node,policy-node"
#define DEFAULT_DISABLED "" #define DEFAULT_DISABLED ""
@ -1815,6 +1825,10 @@ int main(int argc, char *argv[])
if (impl.loop == NULL) if (impl.loop == NULL)
return -1; return -1;
impl.this.loop = pw_main_loop_get_loop(impl.loop); impl.this.loop = pw_main_loop_get_loop(impl.loop);
pw_loop_add_signal(impl.this.loop, SIGINT, do_quit, &impl);
pw_loop_add_signal(impl.this.loop, SIGTERM, do_quit, &impl);
impl.this.context = pw_context_new(impl.this.loop, NULL, 0); impl.this.context = pw_context_new(impl.this.loop, NULL, 0);
if (impl.this.context == NULL) if (impl.this.context == NULL)
return -1; return -1;