[pulseaudio-discuss] Erratic behavior with asynchronous reading and writing

Eric Thornton gonesurfingnc at yahoo.com
Sun Feb 22 18:22:47 PST 2015


All,
I'm working on a basic asynchronous read/write program to understand the API before applying it to another piece of software.  On a read callback I create (or add to) a buffer, and then on write callback I write back as much of it as allowed. The code follows pacat.c and several examples I've found on Jan Newmarch's site. The main difference, is rather than checking for writable size and writing immediately following a read, piling it onto the buffer and waiting for write callback seems to reduce CPU load on the remote hardware (raspberry pi) by 50% or more.
Here is the erratic behavior...1)I don't get any write callbacks (after the initial one) with the prebuf attribute = -1. The sample buffer size continues to increment with nowhere to go. This is probably related to the next two issues.2)If I comment out the prebuf and tlength attribute it works... kind-of.  I sometimes don't get sound on one computer even though the data on the screen indicates the program is running normally. If there is no sound, I can immediately ctl-c and restart and then I get sound.3)On a slower computer, I get a segfault and gdb gives the following. I sometimes get a message about memcpy and unaligned memory.
Program received signal SIGSEGV, Segmentation fault.__memcpy_ssse3 () at ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S:20002000 ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S: No such file or directory.(gdb) backtrace#0  __memcpy_ssse3 () at ../sysdeps/i386/i686/multiarch/memcpy-ssse3.S:2000#1  0xb7fbf000 in ?? () from /usr/lib/i386-linux-gnu/libpulse.so.0Backtrace stopped: previous frame inner to this frame (corrupt stack?)(gdb) 
I plan on using a fixed size ring buffer in the final implementation, but for the life of me cannot figure out why this program won't run using dynamic allocation.  Granted, I am not a very proficient programmer but it appears I'm missing some key concept resulting in the above issues.  I've attached the c code file.  If you have a minute to take a look and tell me what I'm missing I would really appreciate it. 
Thanks,
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20150223/3636b842/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: paloop2.c
Type: text/x-csrc
Size: 7569 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20150223/3636b842/attachment.c>


More information about the pulseaudio-discuss mailing list