[LAD] [LAU] cancelling I/O with libsndfile
fons at linuxaudio.org
Tue Jun 14 11:21:22 UTC 2011
On Tue, Jun 14, 2011 at 01:01:09PM +0300, Dan Muresan wrote:
> > b) Work around it.
> This is what I was trying to do via pthread_cancel + sf_open_fd. It
> seems to work with FLAC.
'Work around it' coild mean something entirely different : not
trying to cancel anything, by using a system that doesn't require
it. More below.
It's probably a Good Thing (TM) that libsndfile doesn't do its
own buffering. First, the file system will do buffering, and if
you're playing a sound file probably decide it should read ahead.
Second, any application that wants to use audio data in real time
will need to do its own buffering, typically a few seconds. How
exactly this is organised will be application dependent. Having
a third layer in between this and the system is not going to help.
If you support things like loops, random locates, shutthling,
scrubbing, etc. the buffer management logic required to support
all of this in an efficient way may become complicated. But
only the application can do it.
One way to organise the buffer is to divide it in fragments
of say 1/4 second, and have the start offset of each one
quantised to the same value. The syscall overhead becomes
trivial for such a lenght. When you need new fragments, you
send commands to the reader thread to read them. If the
requirements change before they are read, you can still
cancel all but one of them (you cancel the requests, not
the actual read() call). The one you can't cancel is no big
deal, just let it happen. It will take little time compared
to what has to be done anyway.
More information about the Linux-audio-dev