关于vlc中是如何同步live库得到的rtp audio,video流?

ear5cm 2010-11-22 11:46:17
请问下,有谁知道关于vlc中是如何同步rtsp的 audio,video流的呢,基本的同步策略是怎样的,麻烦解下惑,谢谢拉?
...全文
248 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
CyberLogix 2010-11-30
  • 打赏
  • 举报
回复
搂住理解的没错
ear5cm 2010-11-23
  • 打赏
  • 举报
回复
hi,dengzikun
Thank you~

我看vlc中是在live555.cpp里的函数 static void StreamRead( void *p_private, unsigned int i_size,
unsigned int i_truncated_bytes, struct timeval pts,
unsigned int duration ) 中, 直接 用的 struct timeval pts 作为其 pts 的。请问下这个pts是否已经是live库里面 经过rtcp同步过的 绝对时间呢? 我要是直接用,是否还需要做什么处理或是修正?


我看到这个pts的来源位于live库的:
void RTPReceptionStats
::noteIncomingPacket()函数里:
// Return the 'presentation time' that corresponds to "rtpTimestamp":
if (fSyncTime.tv_sec == 0 && fSyncTime.tv_usec == 0) {
// This is the first timestamp that we've seen, so use the current
// 'wall clock' time as the synchronization time. (This will be
// corrected later when we receive RTCP SRs.)
fSyncTimestamp = rtpTimestamp;
fSyncTime = timeNow;
}

int timestampDiff = rtpTimestamp - fSyncTimestamp;
// Note: This works even if the timestamp wraps around
// (as long as "int" is 32 bits)

// Divide this by the timestamp frequency to get real time:
double timeDiff = timestampDiff/(double)timestampFrequency;

// Add this to the 'sync time' to get our result:
unsigned const million = 1000000;
unsigned seconds, uSeconds;
if (timeDiff >= 0.0) {
seconds = fSyncTime.tv_sec + (unsigned)(timeDiff);
uSeconds = fSyncTime.tv_usec
+ (unsigned)((timeDiff - (unsigned)timeDiff)*million);
if (uSeconds >= million) {
uSeconds -= million;
++seconds;
}
} else {
timeDiff = -timeDiff;
seconds = fSyncTime.tv_sec - (unsigned)(timeDiff);
uSeconds = fSyncTime.tv_usec
- (unsigned)((timeDiff - (unsigned)timeDiff)*million);
if ((int)uSeconds < 0) {
uSeconds += million;
--seconds;
}
}
resultPresentationTime.tv_sec = seconds;
resultPresentationTime.tv_usec = uSeconds;
resultHasBeenSyncedUsingRTCP = fHasBeenSynchronized;

// Save these as the new synchronization timestamp & time:
fSyncTimestamp = rtpTimestamp;
fSyncTime = resultPresentationTime;

fPreviousPacketRTPTimestamp = rtpTimestamp;


以及对应的:
void RTPReceptionStats::noteIncomingSR(u_int32_t ntpTimestampMSW,
u_int32_t ntpTimestampLSW,
u_int32_t rtpTimestamp) {
fLastReceivedSR_NTPmsw = ntpTimestampMSW;
fLastReceivedSR_NTPlsw = ntpTimestampLSW;

gettimeofday(&fLastReceivedSR_time, NULL);

// Use this SR to update time synchronization information:
fSyncTimestamp = rtpTimestamp;
fSyncTime.tv_sec = ntpTimestampMSW - 0x83AA7E80; // 1/1/1900 -> 1/1/1970
double microseconds = (ntpTimestampLSW*15625.0)/0x04000000; // 10^6/2^32
fSyncTime.tv_usec = (unsigned)(microseconds+0.5);
fHasBeenSynchronized = True;
}
这个函数好像是在 每次来一个rtcp的时候,取出其npt做个校对。


不知道我的理解是否有偏差?谢谢~
dengzikun 2010-11-23
  • 打赏
  • 举报
回复
把A/V的RTP时间戳同步到RTCP的绝对时间,实现A/V同步。

2,543

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 多媒体/流媒体开发
社区管理员
  • 多媒体/流媒体开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧