[pulseaudio-commits] r1577 - /branches/lennart/src/pulsecore/sound-file-stream.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Sun Aug 5 06:51:34 PDT 2007
Author: lennart
Date: Sun Aug 5 15:51:32 2007
New Revision: 1577
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1577&root=3Dpulseaudio&vi=
ew=3Drev
Log:
use posix_fadvise to avoid page faults when reading audio files from disk
Modified:
branches/lennart/src/pulsecore/sound-file-stream.c
Modified: branches/lennart/src/pulsecore/sound-file-stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
sound-file-stream.c?rev=3D1577&root=3Dpulseaudio&r1=3D1576&r2=3D1577&view=
=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/sound-file-stream.c (original)
+++ branches/lennart/src/pulsecore/sound-file-stream.c Sun Aug 5 15:51:32 =
2007
@@ -28,19 +28,21 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
=
#include <sndfile.h>
=
#include <pulse/xmalloc.h>
=
+#include <pulsecore/core-error.h>
#include <pulsecore/sink-input.h>
#include <pulsecore/log.h>
=
#include "sound-file-stream.h"
=
-#define BUF_SIZE (1024*10)
-
-/* FIXME: file access needs to be moved to seperate thread */
+#define BUF_SIZE (1024*16)
=
typedef struct file_stream {
pa_msgobject parent;
@@ -53,7 +55,7 @@
} file_stream;
=
enum {
- MESSAGE_DROP_FILE_STREAM
+ FILE_STREAM_MESSAGE_UNLINK
};
=
PA_DECLARE_CLASS(file_stream);
@@ -95,7 +97,7 @@
file_stream_assert_ref(u);
=
switch (code) {
- case MESSAGE_DROP_FILE_STREAM:
+ case FILE_STREAM_MESSAGE_UNLINK:
file_stream_unlink(u);
break;
}
@@ -159,7 +161,7 @@
pa_memblock_unref(u->memchunk.memblock);
pa_memchunk_reset(&u->memchunk);
=
- pa_asyncmsgq_post(u->core->asyncmsgq, PA_MSGOBJECT(u), MES=
SAGE_DROP_FILE_STREAM, NULL, 0, NULL, NULL);
+ pa_asyncmsgq_post(u->core->asyncmsgq, PA_MSGOBJECT(u), FIL=
E_STREAM_MESSAGE_UNLINK, NULL, 0, NULL, NULL);
=
sf_close(u->sndfile);
u->sndfile =3D NULL;
@@ -225,7 +227,8 @@
SF_INFO sfinfo;
pa_sample_spec ss;
pa_sink_input_new_data data;
-
+ int fd;
+ =
pa_assert(sink);
pa_assert(fname);
=
@@ -241,8 +244,31 @@
=
memset(&sfinfo, 0, sizeof(sfinfo));
=
- if (!(u->sndfile =3D sf_open(fname, SFM_READ, &sfinfo))) {
+ if ((fd =3D open(fname, O_RDONLY|O_NOCTTY)) < 0) {
+ pa_log("Failed to open file %s: %s", fname, pa_cstrerror(errno));
+ goto fail;
+ }
+
+ /* FIXME: For now we just use posix_fadvise to avoid page faults
+ * when accessing the file data. Eventually we should move the
+ * file reader into the main event loop and pass the data over the
+ * asyncmsgq. */
+
+ if (posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL) < 0) {
+ pa_log_warn("POSIX_FADV_SEQUENTIAL failed: %s", pa_cstrerror(errno=
));
+ goto fail;
+ } else
+ pa_log_debug("POSIX_FADV_SEQUENTIAL succeeded.");
+ =
+ if (posix_fadvise(fd, 0, 0, POSIX_FADV_WILLNEED) < 0) {
+ pa_log_warn("POSIX_FADV_WILLNEED failed: %s", pa_cstrerror(errno));
+ goto fail;
+ } else
+ pa_log_debug("POSIX_FADV_WILLNEED succeeded.");
+ =
+ if (!(u->sndfile =3D sf_open_fd(fd, SFM_READ, &sfinfo, 1))) {
pa_log("Failed to open file %s", fname);
+ close(fd);
goto fail;
}
=
More information about the pulseaudio-commits
mailing list