<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr">Tanu,</div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr"><br></div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr">Thanks for the reply.</div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr"><br></div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr">On further examination, the segfault is happening on pa_stream_write. I've not yet figured out why. However the largest hurdle I can't seem to overcome is getting a write callback with prebuffering enabled. I understand that assigning that attribute only affects playback on the server side of the stream, but it most definitely affects write callbacks in some way I don't understand.</div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr"><br></div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr">Output with prebuf=-1 (note 1st write callback happens before 1st read so it returns).</div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr"><br></div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr" class="" style="">Stream write callback: Ready to write 384000 bytes</div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr" class="" style="">no buffer to write: length 0 </div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr" class="" style="">Can read     724 read     724 buffer address 0x17da0d0, length,     724</div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr" class="" style="">Can read     724 read     724 buffer address 0x17da0d0, length,    1448</div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr" class="" style="">Can read     724 read     724 buffer address 0x17da0d0, length,    2172</div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr" class="" style="">Can read     724 read     724 buffer address 0x17da0d0, length,    2896</div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr" class="" style="">Can read     724 read     724 buffer address 0x17da0d0, length,    3620</div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr" class="" style="">Can read     724 read     724 buffer address 0x17da0d0, length,    4344</div><div id="yui_3_16_0_1_1425005346966_3229" dir="ltr" class="" style="">Can read     724 read     724 buffer address 0x17da0d0, length,    5068</div><div class="" style="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr"><br></div><div class="" style="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr">....and on and on...</div><div class="" style="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr"><br></div><div class="" style="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr">Now with no prebuf attribute on write stream, I have the following output</div><div class="" style="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr"><br></div><div class="" style="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr"><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">no buffer to write: length 0 </div><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">Can read     288 read     288 buffer address 0x249a0d0, length,     288</div><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">Can read     104 read     104 buffer address 0x249a0d0, length,     392</div><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">Can read      88 read      88 buffer address 0x249a0d0, length,     480</div><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">Can read      32 read      32 buffer address 0x249a0d0, length,     512</div><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">Can read      64 read      64 buffer address 0x249a0d0, length,     576</div><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">Can read     104 read     104 buffer address 0x249a0d0, length,     680</div><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">Can read      24 read      24 buffer address 0x249a0d0, length,     704</div><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">Can read      24 read      24 buffer address 0x249a0d0, length,     728</div><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">Can read      24 read      24 buffer address 0x249a0d0, length,     752</div><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">Can read      24 read      24 buffer address 0x249a0d0, length,     776</div><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">Stream write callback: Ready to write 437712 bytes</div><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">Wrote 776 of 776 bytes from 0x249a0d0</div><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">freeing buffer</div><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">Can read      40 read      40 buffer address 0x249a3e0, length,      40</div><div class="" id="yui_3_16_0_1_1425005346966_4994" dir="ltr" style="">Can read      32 read      32 buffer address 0x249a3e0, length,      72</div><div class="" style="" dir="ltr" id="yui_3_16_0_1_1425005346966_5460"><br></div><div class="" style="" dir="ltr" id="yui_3_16_0_1_1425005346966_5460">...and I things act fairly normal except for random segfaults on 2 of the 3 computers i've tested it on.</div><div class="" style="" dir="ltr" id="yui_3_16_0_1_1425005346966_5460"><br></div><div class="" style="" dir="ltr" id="yui_3_16_0_1_1425005346966_5460"><br></div></div> <div class="qtdSeparateBR" id="yui_3_16_0_1_1425005346966_3248" dir="ltr">Thanks,</div><div class="qtdSeparateBR" id="yui_3_16_0_1_1425005346966_3248" dir="ltr"><br></div><div class="qtdSeparateBR" id="yui_3_16_0_1_1425005346966_3248" dir="ltr">Eric<br><br></div><div class="yahoo_quoted" style="display: block;" id="yui_3_16_0_1_1425005346966_3247"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;" id="yui_3_16_0_1_1425005346966_3246"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;" id="yui_3_16_0_1_1425005346966_3245"> <div dir="ltr" id="yui_3_16_0_1_1425005346966_4507"> <font size="2" face="Arial" id="yui_3_16_0_1_1425005346966_4506"> On Wednesday, February 25, 2015 12:06 PM, Tanu Kaskinen <tanu.kaskinen@linux.intel.com> wrote:<br> </font> </div>  <br><br> <div class="y_msg_container" id="yui_3_16_0_1_1425005346966_3244">On Mon, 2015-02-23 at 02:22 +0000, Eric Thornton wrote:<br clear="none">> All,<br clear="none">> <br clear="none">> <br clear="none">> I'm working on a basic asynchronous read/write program to understand<br clear="none">> the API before applying it to another piece of software.  On a read<br clear="none">> callback I create (or add to) a buffer, and then on write callback I<br clear="none">> write back as much of it as allowed. The code follows pacat.c and<br clear="none">> several examples I've found on Jan Newmarch's site. The main<br clear="none">> difference, is rather than checking for writable size and writing<br clear="none">> immediately following a read, piling it onto the buffer and waiting<br clear="none">> for write callback seems to reduce CPU load on the remote hardware<br clear="none">> (raspberry pi) by 50% or more.<br clear="none">> <br clear="none">> <br clear="none">> Here is the erratic behavior...<br clear="none">> 1)I don't get any write callbacks (after the initial one) with the<br clear="none">> prebuf attribute = -1. The sample buffer size continues to increment<br clear="none">> with nowhere to go. This is probably related to the next two issues.<br clear="none"><br clear="none">The prebuf attribute shouldn't cause any segfaults, so I don't think<br clear="none">it's directly related to issue 3.<br clear="none"><br clear="none">I didn't read your code thoroughly, but you probably don't fully<br clear="none">understand what the prebuf attribute does. If you set prebuf to -1, the<br clear="none">server will decide the value for you, and that value will be non-zero.<br clear="none">If the prebuf is non-zero, playback will not start until PulseAudio has<br clear="none">received prebuf amount of data from your application. Also, if you're<br clear="none">too slow to write audio after the playback has started, so that there's<br clear="none">an underrun on the stream, that will also trigger the prebuffering mode,<br clear="none">meaning that the stream is stopped until you have again written prebuf<br clear="none">amount of data.<div class="yqt0542072018" id="yqtfd39872"><br clear="none"><br clear="none">> 2)If I comment out the prebuf and tlength attribute it works...<br clear="none">> kind-of.  I sometimes don't get sound on one computer even though the<br clear="none">> data on the screen indicates the program is running normally. If there<br clear="none">> is no sound, I can immediately ctl-c and restart and then I get sound.<br clear="none">> 3)On a slower computer, I get a segfault and gdb gives the following.<br clear="none">> I sometimes get a message about memcpy and unaligned memory.</div><br clear="none"><br clear="none">To get better backtraces from gdb, you need to install the debug symbols<br clear="none">for the program and the libraries that it uses. In this case at least<br clear="none">the debug symbols for libpulse are not available. If you're using<br clear="none">Raspbian, the package name is libpulse0-dbg.<br clear="none"><br clear="none">-- <br clear="none">Tanu<div class="yqt0542072018" id="yqtfd67796"><br clear="none"><br clear="none"><br clear="none"></div><br><br></div>  </div> </div>  </div> </div></body></html>