summaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2020-08-13 17:00:08 +0200
committerWim Taymans <wtaymans@redhat.com>2020-08-13 17:00:08 +0200
commitcf6ffcacb8c4537dfa05eb7da922d7464c6eb987 (patch)
tree45b0440ff1c02185764db1cc0a926707456ebc7f /src/examples
parentebc659330e542bdb47652dc9a34073cd4c047827 (diff)
media-session: do some more cleanup
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/media-session/default-nodes.c39
1 files changed, 13 insertions, 26 deletions
diff --git a/src/examples/media-session/default-nodes.c b/src/examples/media-session/default-nodes.c
index f57951fe..e838b91f 100644
--- a/src/examples/media-session/default-nodes.c
+++ b/src/examples/media-session/default-nodes.c
@@ -44,7 +44,7 @@
#define NAME "default-nodes"
#define SESSION_KEY "default-nodes"
-#define SAVE_INTERVAL 5
+#define SAVE_INTERVAL 1
struct impl {
struct timespec now;
@@ -113,32 +113,14 @@ static const char *find_name_for_id(struct impl *impl, uint32_t id)
return NULL;
}
-static int load_state(struct impl *impl)
-{
- int res;
-
- if ((res = sm_media_session_load_state(impl->session, SESSION_KEY, impl->properties)) < 0) {
- pw_log_error("can't load "SESSION_KEY" state: %s", spa_strerror(res));
- return res;
- }
- return res;
-}
-
-static int save_state(struct impl *impl)
-{
- int res;
-
- if ((res = sm_media_session_save_state(impl->session, SESSION_KEY, impl->properties)) < 0) {
- pw_log_error("can't save "SESSION_KEY" state: %s", spa_strerror(res));
- return res;
- }
- return res;
-}
-
static void remove_idle_timeout(struct impl *impl)
{
struct pw_loop *main_loop = pw_context_get_main_loop(impl->context);
+ int res;
+
if (impl->idle_timeout) {
+ if ((res = sm_media_session_save_state(impl->session, SESSION_KEY, impl->properties)) < 0)
+ pw_log_error("can't save "SESSION_KEY" state: %s", spa_strerror(res));
pw_loop_destroy_source(main_loop, impl->idle_timeout);
impl->idle_timeout = NULL;
}
@@ -147,10 +129,8 @@ static void remove_idle_timeout(struct impl *impl)
static void idle_timeout(void *data, uint64_t expirations)
{
struct impl *impl = data;
-
pw_log_debug(NAME " %p: idle timeout", impl);
remove_idle_timeout(impl);
- save_state(impl);
}
static void add_idle_timeout(struct impl *impl)
@@ -206,7 +186,10 @@ static const struct pw_metadata_events metadata_events = {
static void session_destroy(void *data)
{
struct impl *impl = data;
+ remove_idle_timeout(impl);
spa_hook_remove(&impl->listener);
+ if (impl->session->metadata)
+ spa_hook_remove(&impl->meta_listener);
pw_properties_free(impl->properties);
free(impl);
}
@@ -224,6 +207,8 @@ static void session_create(void *data, struct sm_object *object)
if (find_name(&d, object)) {
char val[16];
snprintf(val, sizeof(val)-1, "%u", d.id);
+ pw_log_info("found %s with id:%s restore as %s",
+ it->value, val, it->key);
pw_metadata_set_property(impl->session->metadata,
PW_ID_CORE, it->key, SPA_TYPE_INFO_BASE"Id", val);
}
@@ -255,6 +240,7 @@ static const struct sm_media_session_events session_events = {
int sm_default_nodes_start(struct sm_media_session *session)
{
struct impl *impl;
+ int res;
impl = calloc(1, sizeof(struct impl));
if (impl == NULL)
@@ -273,7 +259,8 @@ int sm_default_nodes_start(struct sm_media_session *session)
return -ENOMEM;
}
- load_state(impl);
+ if ((res = sm_media_session_load_state(impl->session, SESSION_KEY, impl->properties)) < 0)
+ pw_log_info("can't load "SESSION_KEY" state: %s", spa_strerror(res));
sm_media_session_add_listener(impl->session, &impl->listener, &session_events, impl);