if switch_yield for windows is not working properly maybe if we fix that the code will work as planned.<br><br>switch_timer_check tells you if the timer has ticked or not and it's based on a single timer thread that also has the necessity to do 1ms sleeps to broadcast the time changes to the rest of the system. so let's try using performance counters to implement proper switch_yield and see if the code begins to work as planned. I'll try to come up with a patch because there are several places including the RTP code where semi-accurate 1ms sleeps are absolutely necessary. <br>
<br>This is one of the many joys of being cross platform. =D<br><br><br><br><br><div class="gmail_quote">On Tue, May 6, 2008 at 7:37 AM, Sluschny, Thomas <<a href="mailto:Thomas.Sluschny@siemens.com">Thomas.Sluschny@siemens.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2">Anthony seams to be right.</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2">I tested around a little bit and i see:</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2">- the main problem is the soundcard (-driver), it gives 480
frames all 60 ms </font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2">- if i chose 160 (256) frames ringbuffer size i get only
160 frames all 60 ms, and it sounds really croppy (of course, there are not
enough samples ...)</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2">- i get really good results if i store the last timestamp
when </font><font face="Arial"><font color="#0000ff"><font size="2">ReadAudioStream<span>() returns, and if current
timestamp is less than 20ms from last i wait 20
ms,</span></font></font></font></span></div>
<div dir="ltr" align="left"><span><font face="Arial"><font color="#0000ff"><font size="2"><span>so the packet
difference went from 60-0-0-60-0-0 ms to
20-20-20-20-20-20</span></font></font></font></span></div>
<div dir="ltr" align="left"><span><font face="Arial"><font color="#0000ff"><font size="2"><span>- i use
HighPerformanceCounter to measure the time in
WinXP</span></font></font></font></span></div>
<div dir="ltr" align="left"><span><font face="Arial"><font color="#0000ff"><font size="2"><span></span></font></font></font></span> </div>
<div dir="ltr" align="left"><span><font><font><span><font color="#0000ff" face="Arial" size="2">I thought we
could use </font><font face="Arial"><font color="#0000ff"><font size="2">switch_core_timer_check<span>() to do that
timestamp work, but it doesn't work as
expected,</span></font></font></font></span></font></font></span></div>
<div dir="ltr" align="left"><span><font><font><span><font face="Arial"><font color="#0000ff"><font size="2"><span>seams we have to synchronize to the 60ms clock from
soundcard, at least at the beginning, which means the delay
increase.</span></font></font></font></span></font></font></span></div>
<div dir="ltr" align="left"><span><font><font><span><font face="Arial"><font color="#0000ff"><font size="2"><span></span></font></font></font></span></font></font></span> </div>
<div dir="ltr" align="left"><span><font><font><span><font face="Arial"><font color="#0000ff"><font size="2"><span>Thomas</span></font></font></font></span></font></font></span></div>
<div dir="ltr" align="left"><span><font><font><span><font face="Arial"><font color="#0000ff"><font size="2"><span></span></font></font></font></span></font></font></span> </div>
<div dir="ltr" align="left"><span><font><font><span><font face="Arial"><font color="#0000ff"><font size="2"><span>PS: i attach a patch for better
understanding </span></font></font></font></span></font></font></span></div><br>
<div dir="ltr" align="left" lang="de">
<hr>
<font face="Tahoma" size="2"><b>Von:</b>
<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a>
[mailto:<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a>] <b>Im Auftrag von
</b>Anthony Minessale<br><b>Gesendet:</b> Dienstag, 6. Mai 2008
00:38<div class="Ih2E3d"><br><b>An:</b> <a href="mailto:freeswitch-users@lists.freeswitch.org" target="_blank">freeswitch-users@lists.freeswitch.org</a><br></div><b>Betreff:</b> Re:
[Freeswitch-users] mod_portaudio send 3 rtp packet/60ms insteadof1
packet/20ms<br></font><br></div><div><div></div><div class="Wj3C7c">
<div></div>This is not normal sleep it's microsecond sleep. Its done
because we are doing nonblocking read on the ringbuffer that's tied to the
hardware. Since this is voip, we must drop audio frames when they are late
and in order to do that we must have a high resolution loop. This is only
a problem when the audio device is not sending audio at the interval we asked it
to. Some cheap hardware cannot reliably deliver audio at 20ms intervals
which is why i suggested higher value intervals in the config. The request
to remove the sleep is to confirm the proposition that sleep 1ms was really
taking 15ms.<br><br>I appreciate the suggestion and I understand you are not
trying to be a smart ass.<br><br><br><br>
<div class="gmail_quote">On Mon, May 5, 2008 at 4:35 PM, Michael Jerris <<a href="mailto:mike@jerris.com" target="_blank">mike@jerris.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">The
place this is trickiest is when you are in a loop where you want<br>to wait
for audio, AND do something every x ms or so. You can't do a<br>blocking
read, and a read with timeout tends to be quite expensive.<br>There are some
ways around this, but sometimes its just the most<br>efficient, even if not
preferred method.<br><br>Mike<br>
<div>
<div></div>
<div><br><br>On May 5, 2008, at 5:26 PM, ?ukasz Zwierko
wrote:<br><br>> Hi,<br>><br>> Just a thought here: using calls like
delay(), sleep() etc. for very<br>> short amount of time (like in this case
a couple of miliseconds)<br>> should in my opinion be really discouraged.
It is often a symptom of<br>> bad programming even in an embedded
enviroment, not mentioning<br>> platforms like Windows or Linux where you
can't really tell what<br>> priority does your task have, and will it not
be starved for a long<br>> time by other tasks. I should be avoided
whenever possible.<br>> Don't want to sound like a smart ass here, but
isn't there any other<br>> way? From what I understood you wait until some
amount of voice<br>> samples is collected? If that's the case than
perhaps you can measure<br>> an amount of data collected not the time... If
these are PCM samples<br>> than the correlation is straightforward.<br>>
Again, sorry if I'm being a smart ass here but I've seen some really<br>>
bad code with sleep() calls and such like, and I can tell you that it<br>>
only worked fine in specific conditions, and had a tendency to work<br>>
very poorly when for example CPU was under heavy load.<br>><br>>
Luaksz<br>><br>> 2008/5/5 Anthony Minessale <<a href="mailto:anthony.minessale@gmail.com" target="_blank">anthony.minessale@gmail.com</a>>:<br>>>
did you try setting the ptime on the rtp to 30 or 60ms<br>>><br>>>
when you choose a codec in your sip settings on FS in vars.xml,<br>>>
instead of<br>>> PCMU try PCMU@30i or PCMU@60i<br>>> it may be
that the other side is doing 30 or 60 ms and not telling<br>>>
us.<br>>><br>>> also in pablio.c in the portaudio_mod directory in
ReadAudioStream<br>>> func,<br>>> there is a sleep 1 ms
too<br>>> if the windows is really sleeping a lot longer than that,
try<br>>> omitting line<br>>> 158.<br>>> This probably will
consume the whole cpu but if it fixes your<br>>> problem it<br>>>
will support the theory that the sleep on windows in
inaccurate.<br>>><br>>><br>>><br>>><br>>><br>>>
On Mon, May 5, 2008 at 11:38 AM, Csaba Zelei<br>>> <<a href="mailto:csaba.zelei@gmail.com" target="_blank">csaba.zelei@gmail.com</a>>
wrote:<br>>>><br>>>><br>>>><br>>>><br>>>>
With a little hack I can make mod_portaudio to send rtp packets
with<br>>> ~24ms, ~16ms delay alternately on linux. This result in a
constant<br>>> 4ms<br>>> jitter but its better than the original.
(diff attached)<br>>>> However on windows the delta between rtp
packets is 15-32 ms<br>>>> randomly,<br>>> with occasionally
high 70-100ms delta.<br>>>> I also tried to tweak the windows timer
without success.<br>>>> Does anybody has any idea how to make windows
xp more accurate?<br>>>><br>>>> Sluschny, Thomas
wrote:<br>>>><br>>>><br>>>><br>>>><br>>>>
as you can see here:<br>>>><br>>>><br>>>> <a href="http://jira.freeswitch.org/browse/MODENDP-40" target="_blank">http://jira.freeswitch.org/browse/MODENDP-40</a><br>>>><br>>>>
i have this problem all the time (the error mentioned in this<br>>>>
issue was<br>>> only related with this).<br>>>><br>>>>
It has to do with windows handle sleep() method, you has say<br>>>>
sleep(1) for<br>>> 1ms but on my<br>>>><br>>>> machine
it waits 15ms (it depends on your hardware, other PCs behave<br>>>
different!). So i tested around with high performance
counters.<br>>>><br>>>> For now i ignore that problem an set
jitterbuffers on other device<br>>>> big<br>>>
enough.<br>>>><br>>>> Thomas<br>>>><br>>>>
________________________________<br>>> Von: <a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a><br>>>
[mailto:<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a>]
Im Auftrag<br>>> von Zelei<br>>> Csaba<br>>>> Gesendet:
Donnerstag, 24. April 2008 19:05<br>>>> An: <a href="mailto:freeswitch-users@lists.freeswitch.org" target="_blank">freeswitch-users@lists.freeswitch.org</a><br>>>>
Betreff: [Freeswitch-users] mod_portaudio send 3 rtp
packet/60ms<br>>>> instead<br>>> of1
packet/20ms<br>>>><br>>>> Dear
all,<br>>>><br>>>> I tried to use FS in client mode,
starting calls with<br>>>> mod_portaudio to our<br>>> providers
gateway ( a Cirpack softswitch )<br>>>> I experienced that there is
2-3 sec delay in the call, its choppy<br>>>> and<br>>> robot
like.<br>>>> I tested it with a softphone, and an ip phone and
everything was<br>>>> fine. I<br>>> traced back the problem to
mod_portaudio sending 3 rtp packet in 60ms<br>>> instead of 1
packet/20ms.<br>>>><br>>>> Here is an rtp statistic from a
call: (see<br>>> <a href="http://pastebin.freeswitch.org/4307" target="_blank">http://pastebin.freeswitch.org/4307</a> for the complete list
and sip<br>>> trace)<br>>>><br>>>> Packet
Sequence Delta (ms)<br>>>> 42 26138
0.00<br>>>> 43 26139
0.02<br>>>> 46 26140
45.69<br>>>> 47 26141
0.02<br>>>> 48 26142
2.96<br>>>> 52 26143
56.31<br>>>> 53 26144
5.75<br>>>> 54 26145
0.02<br>>>> 58 26146
51.99<br>>>> 59 26147
0.03<br>>>> 60 26148
2.96<br>>>> 63 26149
42.95<br>>>> 65 26150
17.06<br>>>> 66 26151
0.02<br>>>> 67 26152
2.90<br>>>> 71 26153
56.99<br>>>> 72 26154
0.03<br>>>> 73 26155
0.02<br>>>><br>>>> Did anyone else experience similar
problems?<br>>>> Is this the desired behaviour, because portaudio get
data in 60ms<br>>>> interval<br>>> or can I set it to 20ms
somehow?<br>>>><br>>>>
Thanks,<br>>>><br>>>> Csaba
Zelei<br>>>><br>>>><br>>>>
________________________________<br>>><br>>>>
_______________________________________________<br>>>>
Freeswitch-users mailing list<br>>>> <a href="mailto:Freeswitch-users@lists.freeswitch.org" target="_blank">Freeswitch-users@lists.freeswitch.org</a><br>>>>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>>>>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>>>>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>>>><br>>>><br>>>><br>>>>
Index: mod_portaudio.c<br>>>>
===================================================================<br>>>>
--- mod_portaudio.c (revision 8260)<br>>>> +++
mod_portaudio.c (working copy)<br>>>> @@ -121,6 +121,7
@@<br>>>> int ring_interval;<br>>>>
GFLAGS flags;<br>>>>
switch_timer_t timer;<br>>>> + switch_timer_t
sync_timer;<br>>>> }
globals;<br>>>><br>>>><br>>>> @@ -282,7 +283,15
@@<br>>>> }<br>>>><br>>>>
switch_set_flag_locked(tech_pvt,
TFLAG_IO);<br>>>> +<br>>>> + /* Start
Synchronization Timer */<br>>>> + //Is it ok to
always use 20ms? What about the 160 sample????<br>>>> +
if (<br>>>
switch_core_timer_init(&globals.sync_timer,"soft",<br>>>
20,160,switch_core_session_get_pool(session))<br>>> !=
SWITCH_STATUS_SUCCESS)<br>>>> +
{<br>>>> +
switch_log_printf(SWITCH_CHANNEL_LOG,<br>>>>
SWITCH_LOG_DEBUG,<br>>> "Sync Timer failed!!\n");<br>>>> +
}<br>>>><br>>>> +<br>>>>
/* Move Channel's State Machine to RING
*/<br>>>> switch_channel_set_state(channel,
CS_RING);<br>>>><br>>>> @@ -412,6 +421,8 @@<br>>>>
}<br>>>><br>>>>
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s<br>>>>
CHANNEL<br>>> HANGUP\n",<br>>>
switch_channel_get_name(switch_core_session_get_channel(session)));<br>>>>
+ /* Destroy timer */<br>>>> +
switch_core_timer_destroy(&globals.sync_timer);<br>>>><br>>>>
return SWITCH_STATUS_SUCCESS;<br>>>>
}<br>>>> @@ -542,12 +553,17 @@<br>>>>
switch_mutex_lock(globals.device_lock);<br>>>><br>>>>
get_samples:<br>>>> -<br>>>> +<br>>>>
if ((samples = ReadAudioStream(globals.audio_stream,<br>>>
globals.read_frame.data,<br>>>><br>>>
globals.read_codec.implementation->samples_per_frame,<br>>>><br>>>
&globals.timer)) == 0) {<br>>>> +<br>>>> +
//switch_log_printf(SWITCH_CHANNEL_LOG,
SWITCH_LOG_DEBUG,<br>>>> "No data<br>>> reset
timer\n");<br>>>> +
switch_core_timer_sync(&globals.sync_timer);<br>>>>
switch_yield(1000);<br>>>> +<br>>>>
goto get_samples;<br>>>> +<br>>>>
} else {<br>>>>
globals.read_frame.datalen = samples * 2;<br>>>>
globals.read_frame.samples =
samples;<br>>>> @@ -562,7 +578,9 @@<br>>>>
status =
SWITCH_STATUS_SUCCESS;<br>>>> }<br>>>>
switch_mutex_unlock(globals.device_lock);<br>>>>
-<br>>>> +<br>>>> +
switch_core_timer_next(&globals.sync_timer);<br>>>>
+<br>>>> return
status;<br>>>><br>>>>
}<br>>>><br>>>><br>>>>
_______________________________________________<br>>>>
Freeswitch-users mailing list<br>>>> <a href="mailto:Freeswitch-users@lists.freeswitch.org" target="_blank">Freeswitch-users@lists.freeswitch.org</a><br>>>>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>>>>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>>>>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>>>><br>>>><br>>><br>>><br>>><br>>>
--<br>>> Anthony Minessale II<br>>><br>>> FreeSWITCH <a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org/</a><br>>> ClueCon <a href="http://www.cluecon.com/" target="_blank">http://www.cluecon.com/</a><br>
>><br>>> AIM:
anthm<br>>> <a href="mailto:MSN%3Aanthony_minessale@hotmail.com" target="_blank">MSN:anthony_minessale@hotmail.com</a><br>>>
GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com" target="_blank">PAYPAL:anthony.minessale@gmail.com</a><br>>>
IRC: <a href="http://irc.freenode.net" target="_blank">irc.freenode.net</a>
#freeswitch<br>>><br>>> FreeSWITCH Developer
Conference<br>>> <a href="mailto:sip%3A888@conference.freeswitch.org" target="_blank">sip:888@conference.freeswitch.org</a><br>>>
<a href="http://iax:guest@conference.freeswitch.org/888" target="_blank">iax:guest@conference.freeswitch.org/888</a><br>>> <a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org" target="_blank">googletalk:conf+888@conference.freeswitch.org</a><br>
>>
pstn:213-799-1400<br>>>
_______________________________________________<br>>> Freeswitch-users
mailing list<br>>> <a href="mailto:Freeswitch-users@lists.freeswitch.org" target="_blank">Freeswitch-users@lists.freeswitch.org</a><br>>>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>>>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>>>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>>><br>>><br>><br>>
_______________________________________________<br>> Freeswitch-users
mailing list<br>> <a href="mailto:Freeswitch-users@lists.freeswitch.org" target="_blank">Freeswitch-users@lists.freeswitch.org</a><br>>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br><br><br>_______________________________________________<br>Freeswitch-users
mailing list<br><a href="mailto:Freeswitch-users@lists.freeswitch.org" target="_blank">Freeswitch-users@lists.freeswitch.org</a><br><a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br><a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Anthony Minessale II<br><br>FreeSWITCH <a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org/</a><br>ClueCon <a href="http://www.cluecon.com/" target="_blank">http://www.cluecon.com/</a><br>
<br>AIM:
anthm<br><a href="mailto:MSN%3Aanthony_minessale@hotmail.com" target="_blank">MSN:anthony_minessale@hotmail.com</a><br>GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com" target="_blank">PAYPAL:anthony.minessale@gmail.com</a><br>
IRC:
<a href="http://irc.freenode.net" target="_blank">irc.freenode.net</a>
#freeswitch<br><br>FreeSWITCH Developer Conference<br><a href="mailto:sip%3A888@conference.freeswitch.org" target="_blank">sip:888@conference.freeswitch.org</a><br><a href="http://iax:guest@conference.freeswitch.org/888" target="_blank">iax:guest@conference.freeswitch.org/888</a><br>
<a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org" target="_blank">googletalk:conf+888@conference.freeswitch.org</a><br>pstn:213-799-1400
</div></div></div>
<br>_______________________________________________<br>
Freeswitch-users mailing list<br>
<a href="mailto:Freeswitch-users@lists.freeswitch.org">Freeswitch-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Anthony Minessale II<br><br>FreeSWITCH <a href="http://www.freeswitch.org/">http://www.freeswitch.org/</a><br>ClueCon <a href="http://www.cluecon.com/">http://www.cluecon.com/</a><br>
<br>AIM: anthm<br><a href="mailto:MSN%3Aanthony_minessale@hotmail.com">MSN:anthony_minessale@hotmail.com</a><br>GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com">PAYPAL:anthony.minessale@gmail.com</a><br>
IRC: <a href="http://irc.freenode.net">irc.freenode.net</a> #freeswitch<br><br>FreeSWITCH Developer Conference<br><a href="mailto:sip%3A888@conference.freeswitch.org">sip:888@conference.freeswitch.org</a><br><a href="http://iax:guest@conference.freeswitch.org/888">iax:guest@conference.freeswitch.org/888</a><br>
<a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org">googletalk:conf+888@conference.freeswitch.org</a><br>pstn:213-799-1400