summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2007-08-05 13:52:01 +0000
committerLennart Poettering <lennart@poettering.net>2007-08-05 13:52:01 +0000
commit41d67c40d9603228f3bd1a748fa774e49ff50c3e (patch)
treeef44544440f0da538db2a276d100278f94bd4bb7
parent872951cca18d9c595706b3543570cc764d886cf4 (diff)
minor optimization for cacheing in of samples by using posix_fadvise
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1578 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r--src/pulsecore/sound-file.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/pulsecore/sound-file.c b/src/pulsecore/sound-file.c
index 416ae93e..7c8b5970 100644
--- a/src/pulsecore/sound-file.c
+++ b/src/pulsecore/sound-file.c
@@ -26,12 +26,16 @@
#endif
#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
#include <sndfile.h>
#include <pulse/sample.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
+#include <pulsecore/core-error.h>
#include "sound-file.h"
#include "core-scache.h"
@@ -49,6 +53,7 @@ int pa_sound_file_load(
size_t l;
sf_count_t (*readf_function)(SNDFILE *sndfile, void *ptr, sf_count_t frames) = NULL;
void *ptr = NULL;
+ int fd;
pa_assert(fname);
pa_assert(ss);
@@ -57,8 +62,20 @@ int pa_sound_file_load(
pa_memchunk_reset(chunk);
memset(&sfinfo, 0, sizeof(sfinfo));
- if (!(sf = sf_open(fname, SFM_READ, &sfinfo))) {
+ if ((fd = open(fname, O_RDONLY|O_NOCTTY)) < 0) {
+ pa_log("Failed to open file %s: %s", fname, pa_cstrerror(errno));
+ goto finish;
+ }
+
+ if (posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL) < 0) {
+ pa_log_warn("POSIX_FADV_SEQUENTIAL failed: %s", pa_cstrerror(errno));
+ goto finish;
+ } else
+ pa_log_debug("POSIX_FADV_SEQUENTIAL succeeded.");
+
+ if (!(sf = sf_open_fd(fd, SFM_READ, &sfinfo, 1))) {
pa_log("Failed to open file %s", fname);
+ close(fd);
goto finish;
}