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"><<a href="mailto:anthony.minessale@gmail.com">anthony.minessale@gmail.com</a>></span><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'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's own thread and play them independently since it's 2 different IP streams.</div>
<div><br></div><div><br><br><div class="gmail_quote"><div class="im">2010/7/13 Paulo Rogério Panhoto <span dir="ltr"><<a href="mailto:paulo@voicetechnology.com.br" target="_blank">paulo@voicetechnology.com.br</a>></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've found a way to synchronize the A/V streams with usleep() but I
don't think that'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 class="h5"><br>
<br>
Here'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<switch_rtp_hdr_t *>(vid_frame.packet);<br>
<br></div>
videoNext =
vc.videoTrack().track.get90KTimestamp(ntohl(hdr->ts));<br>
hdr->ts = htonl(videoNext);<div><br>
if (pt)<br>
hdr->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 && !aOk) <br>
break;<br>
<br>
<br>
int64_t wait = min(audioNext, videoNext) - ts;<br>
if(wait > 0) <br>
{<br>
/* wait the time for the next A/V frame */<br>
usleep(wait * 1000 / 90);<br>
//switch_core_timer_next(&timer);<br>
ts += wait;<br>
}<br>
<br>
if (switch_channel_test_flag(channel, CF_VIDEO) &&
ts >= 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,
&vid_frame, SWITCH_IO_FLAG_NONE, 0);<br></div>
videoSent = true;<br>
}<br>
<br>
if(aOk && ts >= audioNext)<div><br>
{<br>
if (write_frame.datalen > (int) write_frame.buflen)<br>
write_frame.datalen = write_frame.buflen;<br>
<br>
switch_core_session_write_frame(session,
&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'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't
block when there is no data.</span></div>
</blockquote>
<br>
</div></div></div></div>
<br><div class="im">_______________________________________________<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 class="im"><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">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>