each channel runs in a separate thread. so in playback you could use the current thread for audio and launch another for the video.  Since they are 2 different rtp streams you could read and write from them at the same time.<div>
<br><div><br><br><div class="gmail_quote">2010/7/13 Paulo Rogério Panhoto <span dir="ltr">&lt;<a href="mailto:paulo@voicetechnology.com.br">paulo@voicetechnology.com.br</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Perhaps threading is the best to do. Does FS handle calls in separate threads?<br><br><div class="gmail_quote">2010/7/13 Anthony Minessale <span dir="ltr">&lt;<a href="mailto:anthony.minessale@gmail.com" target="_blank">anthony.minessale@gmail.com</a>&gt;</span><div>
<div></div><div class="h5"><br>
<blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">without threads for both it would require doing non blocking reads on the rtp streams.<div>We have some provisions in the code for being able to do this but I am not sure it&#39;s been proven to work.</div>

<div>We can always try to dust it off.</div>
<div><br></div><div>I think its done by passing the io_flag SWITCH_IO_FLAG_NOBLOCK to the read_frame call.</div><div><br></div><div>Another idea would be to open the audio and video tracks separately each in it&#39;s own thread and play them independently since it&#39;s 2 different IP streams.</div>


<div><br></div><div><br><br><div class="gmail_quote"><div>2010/7/13 Paulo Rogério Panhoto <span dir="ltr">&lt;<a href="mailto:paulo@voicetechnology.com.br" target="_blank">paulo@voicetechnology.com.br</a>&gt;</span><br>
</div><blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">



  

<div text="#000000" bgcolor="#ffffff">
    I&#39;ve found a way to synchronize the A/V streams with usleep() but I
don&#39;t think that&#39;s the best way to do this. Is there a switch_core....
function to perform a similar task (and maybe allow other tasks to run)?<div><div></div><div><br>
<br>
    Here&#39;s the current version of the playback loop (that takes into
consideration multiple RTP packets per video frame) :<br>
<br>
        u_int64_t videoNext = 0, audioNext = 0;<br>
        u_int64_t ts = 0;<br>
        <br>
        bool videoSent = true, audioSent = true;<div><br>
        while (switch_channel_ready(channel))<br>
        {<br></div>
            bool vOk, aOk;<br>
            if(videoSent)<div><br>
            {<br>
                vid_frame.packetlen = vid_frame.buflen;<br></div><div>
                vOk = vc.getVideoPacket(vid_frame.packet,
vid_frame.packetlen);<br></div><div>
                if (vOk)<br>
                {<br>
                    switch_rtp_hdr_t *hdr =
reinterpret_cast&lt;switch_rtp_hdr_t *&gt;(vid_frame.packet);<br>
<br></div>
                    videoNext =
vc.videoTrack().track.get90KTimestamp(ntohl(hdr-&gt;ts));<br>
                    hdr-&gt;ts = htonl(videoNext);<div><br>
                    if (pt)<br>
                        hdr-&gt;pt = pt;<br>
                }<br></div>
                videoSent = false;<br>
            }<br>
            if(audioSent)<div><br>
            {<br>
                write_frame.datalen = write_frame.buflen;<br></div><div>
                aOk = vc.getAudioPacket(write_frame.data,
write_frame.datalen);<br></div>
                audioSent = false;<br>
            }<br>
<br>
            if (!vOk &amp;&amp; !aOk) <br>
                break;<br>
<br>
<br>
            int64_t wait = min(audioNext, videoNext) - ts;<br>
            if(wait &gt; 0) <br>
            {<br>
                /* wait the time for the next A/V frame */<br>
                usleep(wait * 1000 / 90);<br>
                //switch_core_timer_next(&amp;timer);<br>
                ts += wait;<br>
            }<br>
<br>
            if (switch_channel_test_flag(channel, CF_VIDEO) &amp;&amp;
ts &gt;= videoNext)<div><br>
            {<br>
                switch_byte_t *data = (switch_byte_t *)
vid_frame.packet;<br>
<br>
                vid_frame.data = data + 12;<br>
                vid_frame.datalen = vid_frame.packetlen - 12;<br>
                switch_core_session_write_video_frame(session,
&amp;vid_frame, SWITCH_IO_FLAG_NONE, 0);<br></div>
                videoSent = true;<br>
            }<br>
<br>
            if(aOk &amp;&amp; ts &gt;= audioNext)<div><br>
            {<br>
                if (write_frame.datalen &gt; (int) write_frame.buflen)<br>
                    write_frame.datalen = write_frame.buflen;<br>
<br>
                switch_core_session_write_frame(session,
&amp;write_frame, SWITCH_IO_FLAG_NONE, 0);<br></div>
                audioSent = true;<br>
                audioNext += 90000 / 50; // 20ms<br>
            }<br>
        }<br>
<br>
    Btw, thanks for the tip. I&#39;ll keep the separate thread to store
video for the record function.<br>
<br>
    Regards,<br><font color="#888888">
<br>
    Paulo</font><div><br>
<br>
On 13/07/10 15:39, Anthony Minessale wrote:
<blockquote type="cite">we need to get nonblocking reads to the rtp working so the <br>
  <br>
  <div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse">  read_video_frame();<br>
   read_audio_frame();</span></div>
  <div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><br>
  </span></div>
  <div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse">don&#39;t
block when there is no data.</span></div>
</blockquote>
<br>
</div></div></div></div>

<br><div>_______________________________________________<br>
FreeSWITCH-dev mailing list<br>
<a href="mailto:FreeSWITCH-dev@lists.freeswitch.org" target="_blank">FreeSWITCH-dev@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-dev</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></div></blockquote></div><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>


Twitter: <a href="http://twitter.com/FreeSWITCH_wire" target="_blank">http://twitter.com/FreeSWITCH_wire</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="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org" target="_blank">googletalk:conf+888@conference.freeswitch.org</a><br>
pstn:+19193869900<br>
</div></div>
<br>_______________________________________________<br>
FreeSWITCH-dev mailing list<br>
<a href="mailto:FreeSWITCH-dev@lists.freeswitch.org" target="_blank">FreeSWITCH-dev@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-dev</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div></div></div><br>
<br>_______________________________________________<br>
FreeSWITCH-dev mailing list<br>
<a href="mailto:FreeSWITCH-dev@lists.freeswitch.org">FreeSWITCH-dev@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-dev</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>
Twitter: <a href="http://twitter.com/FreeSWITCH_wire">http://twitter.com/FreeSWITCH_wire</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="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org">googletalk:conf+888@conference.freeswitch.org</a><br>
pstn:+19193869900<br>
</div></div>