#include <polyp/mainloop.h>
#include <polyp/channelmap.h>
+#include <polyp/timeval.h>
+#include <polyp/util.h>
#include <polyp/volume.h>
+#include <polyp/xmalloc.h>
+
#include <polypcore/sink-input.h>
#include <polypcore/sample-util.h>
#include <polypcore/play-memchunk.h>
-#include <polypcore/xmalloc.h>
#include <polypcore/core-subscribe.h>
#include <polypcore/namereg.h>
#include <polypcore/sound-file.h>
-#include <polypcore/util.h>
+#include <polypcore/core-util.h>
#include <polypcore/log.h>
+#include <polypcore/core-error.h>
#include "core-scache.h"
e->lazy = 0;
e->last_used_time = 0;
- memset(&e->sample_spec, 0, sizeof(pa_sample_spec));
+ memset(&e->sample_spec, 0, sizeof(e->sample_spec));
+ pa_channel_map_init(&e->channel_map);
pa_cvolume_reset(&e->volume, PA_CHANNELS_MAX);
return e;
pa_scache_entry *e;
assert(c && name);
+ if (chunk && chunk->length > PA_SCACHE_ENTRY_SIZE_MAX)
+ return -1;
+
if (!(e = scache_add_item(c, name)))
return -1;
if (ss) {
e->sample_spec = *ss;
- pa_channel_map_init_auto(&e->channel_map, ss->channels);
+ pa_channel_map_init_auto(&e->channel_map, ss->channels, PA_CHANNEL_MAP_DEFAULT);
e->volume.channels = e->sample_spec.channels;
}
c->mainloop->time_free(c->scache_auto_unload_event);
}
-int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, const pa_cvolume *volume) {
+int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, pa_volume_t volume) {
pa_scache_entry *e;
char *t;
pa_cvolume r;
return -1;
pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_CHANGE, e->index);
- e->volume.channels = e->sample_spec.channels;
+
+ if (e->volume.channels > e->sample_spec.channels)
+ e->volume.channels = e->sample_spec.channels;
}
if (!e->memchunk.memblock)
t = pa_sprintf_malloc("sample:%s", name);
- if (volume) {
- r = *volume;
- r.channels = e->volume.channels;
- pa_sw_cvolume_multiply(&r, &r, &e->volume);
- } else
- r = e->volume;
+ pa_cvolume_set(&r, e->volume.channels, volume);
+ pa_sw_cvolume_multiply(&r, &r, &e->volume);
if (pa_play_memchunk(sink, t, &e->sample_spec, &e->channel_map, &e->memchunk, &r) < 0) {
pa_xfree(t);
e = pa_path_get_filename(pathname);
if (stat(pathname, &st) < 0) {
- pa_log(__FILE__": stat('%s') failed: %s", pathname, strerror(errno));
+ pa_log(__FILE__": stat('%s'): %s", pathname, pa_cstrerror(errno));
return;
}
/* If that fails, try to open it as shell glob */
if (glob(pathname, GLOB_ERR|GLOB_NOSORT, NULL, &p) < 0) {
- pa_log(__FILE__": Failed to open directory: %s", strerror(errno));
+ pa_log(__FILE__": failed to open directory '%s': %s", pathname, pa_cstrerror(errno));
return -1;
}