X-Git-Url: https://code.delx.au/pulseaudio/blobdiff_plain/5c10b84e0f020de8a0d9f5adc6b0affbae4343cb..5205e6a85ac8699c464e2d676c4d8b1c2b7989e5:/src/pulsecore/core-scache.c diff --git a/src/pulsecore/core-scache.c b/src/pulsecore/core-scache.c index 086f5fcb..5ec6159d 100644 --- a/src/pulsecore/core-scache.c +++ b/src/pulsecore/core-scache.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -54,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -61,11 +63,10 @@ #include "core-scache.h" -#define UNLOAD_POLL_TIME 60 +#define UNLOAD_POLL_TIME (60 * PA_USEC_PER_SEC) -static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, const struct timeval *tv, void *userdata) { +static void timeout_callback(pa_mainloop_api *m, pa_time_event *e, const struct timeval *t, void *userdata) { pa_core *c = userdata; - struct timeval ntv; pa_assert(c); pa_assert(c->mainloop == m); @@ -73,9 +74,7 @@ static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, const struct t pa_scache_unload_unused(c); - pa_gettimeofday(&ntv); - ntv.tv_sec += UNLOAD_POLL_TIME; - m->time_restart(e, &ntv); + pa_core_rttime_restart(c, e, pa_rtclock_now() + UNLOAD_POLL_TIME); } static void free_entry(pa_scache_entry *e) { @@ -256,12 +255,8 @@ int pa_scache_add_file_lazy(pa_core *c, const char *name, const char *filename, pa_proplist_sets(e->proplist, PA_PROP_MEDIA_FILENAME, filename); - if (!c->scache_auto_unload_event) { - struct timeval ntv; - pa_gettimeofday(&ntv); - ntv.tv_sec += UNLOAD_POLL_TIME; - c->scache_auto_unload_event = c->mainloop->time_new(c->mainloop, &ntv, timeout_callback, c); - } + if (!c->scache_auto_unload_event) + c->scache_auto_unload_event = pa_core_rttime_new(c, pa_rtclock_now() + UNLOAD_POLL_TIME, timeout_callback, c); if (idx) *idx = e->index; @@ -315,7 +310,8 @@ int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, pa_volume_t return -1; merged = pa_proplist_new(); - pa_proplist_setf(merged, PA_PROP_MEDIA_NAME, "Sample %s", name); + pa_proplist_sets(merged, PA_PROP_MEDIA_NAME, name); + pa_proplist_sets(merged, PA_PROP_EVENT_ID, name); if (e->lazy && !e->memchunk.memblock) { pa_channel_map old_channel_map = e->channel_map; @@ -340,12 +336,12 @@ int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, pa_volume_t pass_volume = TRUE; - if (e->volume_is_set && volume != (pa_volume_t) -1) { + if (e->volume_is_set && PA_VOLUME_IS_VALID(volume)) { pa_cvolume_set(&r, e->sample_spec.channels, volume); pa_sw_cvolume_multiply(&r, &r, &e->volume); } else if (e->volume_is_set) r = e->volume; - else if (volume != (pa_volume_t) -1) + else if (PA_VOLUME_IS_VALID(volume)) pa_cvolume_set(&r, e->sample_spec.channels, volume); else pass_volume = FALSE; @@ -355,7 +351,12 @@ int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, pa_volume_t if (p) pa_proplist_update(merged, PA_UPDATE_REPLACE, p); - if (pa_play_memchunk(sink, &e->sample_spec, &e->channel_map, &e->memchunk, pass_volume ? &r : NULL, merged, sink_input_idx) < 0) + if (pa_play_memchunk(sink, + &e->sample_spec, &e->channel_map, + &e->memchunk, + pass_volume ? &r : NULL, + merged, + PA_SINK_INPUT_NO_CREATE_ON_SUSPEND|PA_SINK_INPUT_KILL_ON_SUSPEND, sink_input_idx) < 0) goto fail; pa_proplist_free(merged); @@ -499,13 +500,14 @@ int pa_scache_add_directory_lazy(pa_core *c, const char *pathname) { struct dirent *e; while ((e = readdir(dir))) { - char p[PATH_MAX]; + char *p; if (e->d_name[0] == '.') continue; - pa_snprintf(p, sizeof(p), "%s/%s", pathname, e->d_name); + p = pa_sprintf_malloc("%s" PA_PATH_SEP "%s", pathname, e->d_name); add_file(c, p); + pa_xfree(p); } closedir(dir);