<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body 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)?<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;<br>
while (switch_channel_ready(channel))<br>
{<br>
bool vOk, aOk;<br>
if(videoSent)<br>
{<br>
vid_frame.packetlen = vid_frame.buflen;<br>
vOk = vc.getVideoPacket(vid_frame.packet,
vid_frame.packetlen);<br>
if (vOk)<br>
{<br>
switch_rtp_hdr_t *hdr =
reinterpret_cast<switch_rtp_hdr_t *>(vid_frame.packet);<br>
<br>
videoNext =
vc.videoTrack().track.get90KTimestamp(ntohl(hdr->ts));<br>
hdr->ts = htonl(videoNext);<br>
if (pt)<br>
hdr->pt = pt;<br>
}<br>
videoSent = false;<br>
}<br>
if(audioSent)<br>
{<br>
write_frame.datalen = write_frame.buflen;<br>
aOk = vc.getAudioPacket(write_frame.data,
write_frame.datalen);<br>
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)<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>
videoSent = true;<br>
}<br>
<br>
if(aOk && ts >= audioNext)<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>
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>
<br>
Paulo<br>
<br>
On 13/07/10 15:39, Anthony Minessale wrote:
<blockquote
cite="mid:AANLkTilbEYXhJ5y-PainYteiIrblayT7d8Tw1W4zKbVy@mail.gmail.com"
type="cite">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't
block when there is no data.</span></div>
</blockquote>
<br>
</body>
</html>