[pulseaudio-discuss] [PATCH 13/19] core-scache: Fire hooks for new, changed and removed events

Juho Hämäläinen juho.hamalainen at tieto.com
Thu Mar 19 04:50:54 PDT 2015


---
 src/pulsecore/core-scache.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/pulsecore/core-scache.c b/src/pulsecore/core-scache.c
index 3e12b34..9e88b7b 100644
--- a/src/pulsecore/core-scache.c
+++ b/src/pulsecore/core-scache.c
@@ -79,6 +79,7 @@ static void free_entry(pa_scache_entry *e) {
 
     pa_namereg_unregister(e->core, e->name);
     pa_subscription_post(e->core, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_REMOVE, e->index);
+    pa_hook_fire(&e->core->hooks[PA_CORE_HOOK_SAMPLE_CACHE_REMOVED], e);
     pa_xfree(e->name);
     pa_xfree(e->filename);
     if (e->memchunk.memblock)
@@ -88,7 +89,7 @@ static void free_entry(pa_scache_entry *e) {
     pa_xfree(e);
 }
 
-static pa_scache_entry* scache_add_item(pa_core *c, const char *name) {
+static pa_scache_entry* scache_add_item(pa_core *c, const char *name, bool *new_sample) {
     pa_scache_entry *e;
 
     pa_assert(c);
@@ -104,6 +105,8 @@ static pa_scache_entry* scache_add_item(pa_core *c, const char *name) {
         pa_assert(e->core == c);
 
         pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_CHANGE, e->index);
+        if (new_sample)
+            *new_sample = false;
     } else {
         e = pa_xnew(pa_scache_entry, 1);
 
@@ -119,6 +122,8 @@ static pa_scache_entry* scache_add_item(pa_core *c, const char *name) {
         pa_idxset_put(c->scache, e, &e->index);
 
         pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_NEW, e->index);
+        if (new_sample)
+            *new_sample = true;
     }
 
     e->last_used_time = 0;
@@ -137,6 +142,15 @@ static pa_scache_entry* scache_add_item(pa_core *c, const char *name) {
     return e;
 }
 
+static void scache_hook(pa_scache_entry *e, bool new_sample) {
+    pa_assert(e);
+
+    if (new_sample)
+        pa_hook_fire(&e->core->hooks[PA_CORE_HOOK_SAMPLE_CACHE_NEW], e);
+    else
+        pa_hook_fire(&e->core->hooks[PA_CORE_HOOK_SAMPLE_CACHE_CHANGED], e);
+}
+
 int pa_scache_add_item(
         pa_core *c,
         const char *name,
@@ -149,6 +163,7 @@ int pa_scache_add_item(
     pa_scache_entry *e;
     char st[PA_SAMPLE_SPEC_SNPRINT_MAX];
     pa_channel_map tmap;
+    bool new_sample;
 
     pa_assert(c);
     pa_assert(name);
@@ -163,7 +178,7 @@ int pa_scache_add_item(
     if (chunk && chunk->length > PA_SCACHE_ENTRY_SIZE_MAX)
         return -1;
 
-    if (!(e = scache_add_item(c, name)))
+    if (!(e = scache_add_item(c, name, &new_sample)))
         return -1;
 
     pa_sample_spec_init(&e->sample_spec);
@@ -190,6 +205,8 @@ int pa_scache_add_item(
     if (idx)
         *idx = e->index;
 
+    scache_hook(e, new_sample);
+
     pa_log_debug("Created sample \"%s\" (#%d), %lu bytes with sample spec %s",
                  name, e->index, (unsigned long) e->memchunk.length,
                  pa_sample_spec_snprint(st, sizeof(st), &e->sample_spec));
@@ -232,6 +249,7 @@ int pa_scache_add_file(pa_core *c, const char *name, const char *filename, uint3
 
 int pa_scache_add_file_lazy(pa_core *c, const char *name, const char *filename, uint32_t *idx) {
     pa_scache_entry *e;
+    bool new_sample;
 
 #ifdef OS_IS_WIN32
     char buf[MAX_PATH];
@@ -244,7 +262,7 @@ int pa_scache_add_file_lazy(pa_core *c, const char *name, const char *filename,
     pa_assert(name);
     pa_assert(filename);
 
-    if (!(e = scache_add_item(c, name)))
+    if (!(e = scache_add_item(c, name, &new_sample)))
         return -1;
 
     e->lazy = true;
@@ -258,6 +276,8 @@ int pa_scache_add_file_lazy(pa_core *c, const char *name, const char *filename,
     if (idx)
         *idx = e->index;
 
+    scache_hook(e, new_sample);
+
     return 0;
 }
 
-- 
1.9.1



More information about the pulseaudio-discuss mailing list