mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-09 13:29:59 -05:00
move sample cache to namereg
documentation git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@141 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
e0fe68a2d4
commit
f9b58fb0ea
27 changed files with 252 additions and 136 deletions
|
|
@ -35,9 +35,11 @@
|
|||
#include "play-memchunk.h"
|
||||
#include "xmalloc.h"
|
||||
#include "subscribe.h"
|
||||
#include "namereg.h"
|
||||
|
||||
static void free_entry(struct pa_scache_entry *e) {
|
||||
assert(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_xfree(e->name);
|
||||
if (e->memchunk.memblock)
|
||||
|
|
@ -45,25 +47,32 @@ static void free_entry(struct pa_scache_entry *e) {
|
|||
pa_xfree(e);
|
||||
}
|
||||
|
||||
void pa_scache_add_item(struct pa_core *c, const char *name, struct pa_sample_spec *ss, struct pa_memchunk *chunk, uint32_t *index) {
|
||||
int pa_scache_add_item(struct pa_core *c, const char *name, struct pa_sample_spec *ss, struct pa_memchunk *chunk, uint32_t *index) {
|
||||
struct pa_scache_entry *e;
|
||||
int put;
|
||||
assert(c && name);
|
||||
|
||||
if (c->scache_hashmap && (e = pa_hashmap_get(c->scache_hashmap, name))) {
|
||||
if ((e = pa_namereg_get(c, name, PA_NAMEREG_SAMPLE, 0))) {
|
||||
put = 0;
|
||||
if (e->memchunk.memblock)
|
||||
pa_memblock_unref(e->memchunk.memblock);
|
||||
assert(e->core == c);
|
||||
} else {
|
||||
|
||||
put = 1;
|
||||
e = pa_xmalloc(sizeof(struct pa_scache_entry));
|
||||
|
||||
if (!pa_namereg_register(c, name, PA_NAMEREG_SAMPLE, e, 1)) {
|
||||
pa_xfree(e);
|
||||
return -1;
|
||||
}
|
||||
|
||||
e->name = pa_xstrdup(name);
|
||||
e->core = c;
|
||||
}
|
||||
|
||||
e->volume = 0x100;
|
||||
|
||||
e->volume = PA_VOLUME_NORM;
|
||||
|
||||
if (ss)
|
||||
e->sample_spec = *ss;
|
||||
else
|
||||
|
|
@ -78,35 +87,31 @@ void pa_scache_add_item(struct pa_core *c, const char *name, struct pa_sample_sp
|
|||
}
|
||||
|
||||
if (put) {
|
||||
if (!c->scache_hashmap) {
|
||||
c->scache_hashmap = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
assert(c->scache_hashmap);
|
||||
if (!c->scache) {
|
||||
c->scache = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
|
||||
assert(c->scache);
|
||||
}
|
||||
|
||||
if (!c->scache_idxset) {
|
||||
c->scache_idxset = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
|
||||
assert(c->scache_idxset);
|
||||
}
|
||||
|
||||
pa_idxset_put(c->scache_idxset, e, &e->index);
|
||||
pa_hashmap_put(c->scache_hashmap, e->name, e);
|
||||
pa_idxset_put(c->scache, e, &e->index);
|
||||
|
||||
pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_NEW, e->index);
|
||||
}
|
||||
} else
|
||||
pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_CHANGE, e->index);
|
||||
|
||||
if (index)
|
||||
*index = e->index;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pa_scache_remove_item(struct pa_core *c, const char *name) {
|
||||
struct pa_scache_entry *e;
|
||||
assert(c && name);
|
||||
|
||||
if (!c->scache_hashmap || !(e = pa_hashmap_get(c->scache_hashmap, name)))
|
||||
if (!(e = pa_namereg_get(c, name, PA_NAMEREG_SAMPLE, 0)))
|
||||
return -1;
|
||||
|
||||
pa_hashmap_remove(c->scache_hashmap, name);
|
||||
if (pa_idxset_remove_by_data(c->scache_idxset, e, NULL) != e)
|
||||
if (pa_idxset_remove_by_data(c->scache, e, NULL) != e)
|
||||
assert(0);
|
||||
|
||||
free_entry(e);
|
||||
|
|
@ -122,14 +127,9 @@ static void free_cb(void *p, void *userdata) {
|
|||
void pa_scache_free(struct pa_core *c) {
|
||||
assert(c);
|
||||
|
||||
if (c->scache_hashmap) {
|
||||
pa_hashmap_free(c->scache_hashmap, free_cb, NULL);
|
||||
c->scache_hashmap = NULL;
|
||||
}
|
||||
|
||||
if (c->scache_idxset) {
|
||||
pa_idxset_free(c->scache_idxset, NULL, NULL);
|
||||
c->scache_idxset = NULL;
|
||||
if (c->scache) {
|
||||
pa_idxset_free(c->scache, free_cb, NULL);
|
||||
c->scache = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ int pa_scache_play_item(struct pa_core *c, const char *name, struct pa_sink *sin
|
|||
struct pa_scache_entry *e;
|
||||
assert(c && name && sink);
|
||||
|
||||
if (!c->scache_hashmap || !(e = pa_hashmap_get(c->scache_hashmap, name)))
|
||||
if (!(e = pa_namereg_get(c, name, PA_NAMEREG_SAMPLE, 0)))
|
||||
return -1;
|
||||
|
||||
if (!e->memchunk.memblock)
|
||||
|
|
@ -153,19 +153,9 @@ const char * pa_scache_get_name_by_id(struct pa_core *c, uint32_t id) {
|
|||
struct pa_scache_entry *e;
|
||||
assert(c && id != PA_IDXSET_INVALID);
|
||||
|
||||
if (!c->scache_idxset || !(e = pa_idxset_get_by_index(c->scache_idxset, id)))
|
||||
if (!c->scache || !(e = pa_idxset_get_by_index(c->scache, id)))
|
||||
return NULL;
|
||||
|
||||
return e->name;
|
||||
|
||||
}
|
||||
|
||||
uint32_t pa_scache_get_id_by_name(struct pa_core *c, const char *name) {
|
||||
struct pa_scache_entry *e;
|
||||
assert(c && name);
|
||||
|
||||
if (!c->scache_hashmap || !(e = pa_hashmap_get(c->scache_hashmap, name)))
|
||||
return PA_IDXSET_INVALID;
|
||||
|
||||
return e->index;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue