<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3314" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=192541611-06052008><FONT face=Arial
color=#0000ff size=2>Anthony seams to be right.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=192541611-06052008><FONT face=Arial
color=#0000ff size=2>I tested around a little bit and i see:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=192541611-06052008><FONT face=Arial
color=#0000ff 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 class=192541611-06052008><FONT face=Arial
color=#0000ff 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 class=192541611-06052008><FONT face=Arial
color=#0000ff 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 class=192541611-06052008>() 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 class=192541611-06052008><FONT face=Arial><FONT
color=#0000ff><FONT size=2><SPAN class=192541611-06052008>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 class=192541611-06052008><FONT face=Arial><FONT
color=#0000ff><FONT size=2><SPAN class=192541611-06052008>- i use
HighPerformanceCounter to measure the time in
WinXP</SPAN></FONT></FONT></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=192541611-06052008><FONT face=Arial><FONT
color=#0000ff><FONT size=2><SPAN
class=192541611-06052008></SPAN></FONT></FONT></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=192541611-06052008><FONT><FONT><SPAN
class=192541611-06052008><FONT face=Arial color=#0000ff size=2>I thought we
could use </FONT><FONT face=Arial><FONT color=#0000ff><FONT
size=2>switch_core_timer_check<SPAN class=192541611-06052008>() 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 class=192541611-06052008><FONT><FONT><SPAN
class=192541611-06052008><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=192541611-06052008>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 class=192541611-06052008><FONT><FONT><SPAN
class=192541611-06052008><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=192541611-06052008></SPAN></FONT></FONT></FONT></SPAN></FONT></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=192541611-06052008><FONT><FONT><SPAN
class=192541611-06052008><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=192541611-06052008>Thomas</SPAN></FONT></FONT></FONT></SPAN></FONT></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=192541611-06052008><FONT><FONT><SPAN
class=192541611-06052008><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=192541611-06052008></SPAN></FONT></FONT></FONT></SPAN></FONT></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=192541611-06052008><FONT><FONT><SPAN
class=192541611-06052008><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=192541611-06052008>PS: i attach a patch for better
understanding </SPAN></FONT></FONT></FONT></SPAN></FONT></FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=de dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>Von:</B>
freeswitch-users-bounces@lists.freeswitch.org
[mailto:freeswitch-users-bounces@lists.freeswitch.org] <B>Im Auftrag von
</B>Anthony Minessale<BR><B>Gesendet:</B> Dienstag, 6. Mai 2008
00:38<BR><B>An:</B> freeswitch-users@lists.freeswitch.org<BR><B>Betreff:</B> Re:
[Freeswitch-users] mod_portaudio send 3 rtp packet/60ms insteadof1
packet/20ms<BR></FONT><BR></DIV>
<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">mike@jerris.com</A>> wrote:<BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">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 class=Wj3C7c><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">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">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">freeswitch-users-bounces@lists.freeswitch.org</A><BR>>>
[mailto:<A
href="mailto:freeswitch-users-bounces@lists.freeswitch.org">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">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">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">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">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" target=_blank>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"
target=_blank>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<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>>><BR>><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><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></DIV></DIV></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
</BODY></HTML>