we need to get nonblocking reads to the rtp working so the <br><br><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">  read_video_frame();<br>   read_audio_frame();</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">don&#39;t block when there is no data.</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br></span></div><div><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;">    Hi,<br>
<br>
    This is my first post to this list and I hope this is the right one<br>
to ask. For the last couple of weeks, I&#39;ve been working on a mod to play<br>
MP4 Video files (recording will be the next step). For simplicity, I<br>
chose to use the same kind of MP4 files as the Asterisk app: H26x/MPEG<br>
Video track + PCMU audio track. I used as base the mod_fsv code and<br>
added code based on the mpeg4ip library. I&#39;ve actually got a video to<br>
work but I&#39;m having some problem to synchronize the audio and video. I<br>
have an idea of how the algorithm should be but I don&#39;t know how to use<br>
the switch_core_timer to implement it.<br>
<br>
the current loop is much like mod_fsv:<br>
<br>
    while (switch_channel_ready(channel))<br>
    {<br>
        vid_frame.packetlen = vid_frame.buflen;<br>
        write_frame.datalen = write_frame.buflen;<br>
        bool vOk = vc.getVideoPacket(vid_frame.packet, vid_frame.packetlen);<br>
        bool aOk = vc.getAudioPacket(write_frame.data, write_frame.datalen);<br>
<br>
        if (!vOk &amp;&amp; !aOk)<br>
            break;<br>
<br>
        if (vOk)<br>
        {<br>
            switch_rtp_hdr_t *hdr = reinterpret_cast&lt;switch_rtp_hdr_t<br>
*&gt;(vid_frame.packet);<br>
<br>
            // Adjusts timestamp to standard 90KHz clock.<br>
            ts = ntohl(hdr-&gt;ts) * 90000 / vc.videoTrack().track.clock;<br>
            hdr-&gt;ts = htonl(ts);<br>
            if (pt)<br>
                hdr-&gt;pt = pt;<br>
<br>
            if (switch_channel_test_flag(channel, CF_VIDEO))<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,<br>
&amp;vid_frame, SWITCH_IO_FLAG_NONE, 0);<br>
            }<br>
            if (ts &amp;&amp; last &amp;&amp; last != ts) {<br>
                switch_cond_next();<br>
            }<br>
            last = ts;<br>
        }<br>
<br>
        if(aOk)<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,<br>
SWITCH_IO_FLAG_NONE, 0);<br>
<br>
        }<br>
        switch_core_timer_next(&amp;timer);<br>
    }<br>
<br>
I think it should be like this (pseudocode)<br>
<br>
nextAudio = nextVideo = ts = 0<br>
<br>
while(switch_channel_ready())<br>
{<br>
    read_video_frame();<br>
    read_audio_frame();<br>
<br>
    nextVideo = ntohl(hdr-&gt;ts) * 90000 / video.clock;<br>
<br>
    waitTime = min(nextAudio, nextVideo) - ts;<br>
    if(waitTime &gt; 0)<br>
     {<br>
        wait(waitTime);<br>
        ts += waitTime;<br>
    }<br>
<br>
    if(ts &gt;= nextAudio)<br>
    {<br>
       send_audio_frame();<br>
       nextAudio += 20 * 90/8; // use the same clock source<br>
    }<br>
    if(ts &gt;= nextVideo)<br>
    {<br>
        send_video_frame();<br>
    }<br>
}<br>
<br>
    Any suggestion is much appreciated.<br>
<br>
    Regards,<br>
<br>
    Paulo R. Panhoto<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>
</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>