]> code.delx.au - pulseaudio/blobdiff - src/polypcore/core-scache.c
* split pa_cstrerror() into its own file polypcore/core-error.[ch]
[pulseaudio] / src / polypcore / core-scache.c
index 6632a1710bdf52fabd7661b6950bfafa89367764..b44a7e198018fee7d5c89a1f5754742e719d67ac 100644 (file)
 
 #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"
 
@@ -122,7 +126,8 @@ static pa_scache_entry* scache_add_item(pa_core *c, const char *name) {
     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;
@@ -132,12 +137,15 @@ int pa_scache_add_item(pa_core *c, const char *name, const pa_sample_spec *ss, c
     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;
     }
 
@@ -240,7 +248,7 @@ void pa_scache_free(pa_core *c) {
         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;
@@ -257,7 +265,9 @@ int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, const pa_cv
             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)
@@ -265,12 +275,8 @@ int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, const pa_cv
 
     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);
@@ -354,7 +360,7 @@ static void add_file(pa_core *c, const char *pathname) {
     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;
     }
 
@@ -376,7 +382,7 @@ int pa_scache_add_directory_lazy(pa_core *c, const char *pathname) {
         /* 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;
         }