[Live-devel] 答复: regardint every rtp packet's timestamp is same

Ross Finlayson finlayson at live555.com
Thu Sep 13 23:21:55 PDT 2012


> Thank you for your answer.
> Now I change the code as below:
> AudioFramedSource::AudioFrameSource()
> {
> gettimeofday(&m_timescale);

OK, this is good, in principle.  It aligns the presentation time with 'wall-clock' time.  However, the constructor is not the right time to be calling "gettimeofday()", because you don't know how long you'll be waiting until "doGetNextFrame()" is first called.  Instead, declare a member variable
	Boolean fIsFirstPresentationTime;
and, in the constructor, do
	fIsFirstPresentationTime = True;


> void AudioFrameSource::doGetNextFrame()
> {
>      CamerManager::GetInstance()->GetAudioFrame(“test”,(char*)fTo,fMaxSize,&fFrameSize,&fNumTruncatedBytes);
>       Int64_t usec = m_timescale.tv_usec;
>       usec += 40/8; //since every frame has 40 samples.
>      If(usec>=1000)
> {
>    m_timescale.tv_sec+= usec/1000;
>   m_timescale.tv_usec += usec%1000;
> }
> else
> {
> m_timescale.tv_usec = usec;
> }

This is all very wrong, because the "tv_usec" field is in microseconds, but you're treating it as if it were in milliseconds.  Also, you're incrementing "fPresentationTime" too soon.  The correct code would be something like this:

void AudioFrameSource::doGetNextFrame() {
	CamerManager::GetInstance()->GetAudioFrame(“test”,(char*)fTo,fMaxSize,&fFrameSize,&fNumTruncatedBytes);
	if (fIsFirstPresentationTime) {
		gettimeofday(&m_timescale);
		fIsFirstPresentationTime = False; // from now on
	}
	fPresentationTime = m_timescale;
	fDurationInMicroseconds = 5000; // because 40 samples at 8000 samples-per-second have a duration of 5 ms (== 5000 us)

	// Compute the next presentation time (i.e., to be used on the next call to "doGetNextFrame()"):
	m_timescale.tv_usec += fDurationInMicroseconds;
	if (m_timescale.tv_usec > 1000000) {
		++m_timescale.tv_sec;
		m_timescale.tv_usec -= 1000000;
	}
}


Ross Finlayson
Live Networks, Inc.
http://www.live555.com/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20120913/775a171e/attachment-0001.html>


More information about the live-devel mailing list