<html><head><base href="x-msg://6545/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div lang="ZH-CN" link="blue" vlink="purple"><div class="WordSection1" style="page: WordSection1; "><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Thank you for your answer.<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Now I change the code as below:<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">AudioFramedSource::AudioFrameSource()<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">{<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; text-indent: 10.5pt; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">gettimeofday(&m_timescale);<br></span></div></div></div></span></blockquote><div><br></div>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</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Boolean fIsFirstPresentationTime;</div><div>and, in the constructor, do</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>fIsFirstPresentationTime = True;</div><div><br></div><div><br></div><div><blockquote type="cite"><span class="Apple-style-span" style="color: rgb(31, 73, 125); font-family: Calibri, sans-serif; font-size: 14px; ">void AudioFrameSource::doGetNextFrame()</span><span class="Apple-style-span" style="border-collapse: separate; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div lang="ZH-CN" link="blue" vlink="purple"><div class="WordSection1" style="page: WordSection1; "><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">{</span><span lang="EN-US"><o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> CamerManager::GetInstance()->GetAudioFrame(“test”,(char*)fTo,fMaxSize,&fFrameSize,&fNumTruncatedBytes);<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> Int64_t usec = m_timescale.tv_usec;<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> usec += 40/8; //since every frame has 40 samples.<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> If(usec>=1000)<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; text-indent: 10.5pt; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">{<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; text-indent: 10.5pt; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> m_timescale.tv_sec+= usec/1000;<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; text-indent: 10.5pt; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> m_timescale.tv_usec += usec%1000;<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; text-indent: 10.5pt; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">}<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; text-indent: 10.5pt; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">else<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 12pt; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">{<o:p></o:p></span></div><div style="margin-top: 0cm; margin-right: 0cm; margin-left: 12pt; margin-bottom: 0.0001pt; font-size: 12pt; font-family: 宋体; text-indent: 10.5pt; "><span lang="EN-US" style="font-size: 10.5pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">m_timescale.tv_usec = usec;<br>}</span></div></div></div></span></blockquote><div><br></div>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:</div><div><br></div><div><div>void AudioFrameSource::doGetNextFrame() {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>CamerManager::GetInstance()->GetAudioFrame(“test”,(char*)fTo,fMaxSize,&fFrameSize,&fNumTruncatedBytes);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>if (fIsFirstPresentationTime) {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-style-span" style="color: rgb(31, 73, 125); font-family: Calibri, sans-serif; font-size: 14px; ">gettimeofday(&m_timescale);</span></div><div><span class="Apple-style-span" style="color: rgb(31, 73, 125); font-family: Calibri, sans-serif; font-size: 14px; "><span class="Apple-tab-span" style="white-space:pre"> </span>fIsFirstPresentationTime = False; // from now on</span></div><div><font class="Apple-style-span" color="#1f497d" face="Calibri, sans-serif"><span class="Apple-tab-span" style="white-space:pre"> </span>}</font></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>fPresentationTime = m_timescale;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>fDurationInMicroseconds = 5000; // because 40 samples at 8000 samples-per-second have a duration of 5 ms (== 5000 us)</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// Compute the next presentation time (i.e., to be used on the next call to "doGetNextFrame()"):</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>m_timescale.tv_usec += fDurationInMicroseconds;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>if (m_timescale.tv_usec > 1000000) {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>++m_timescale.tv_sec;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>m_timescale.tv_usec -= 1000000;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div>}</div></div><br><br><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">Ross Finlayson<br>Live Networks, Inc.<br><a href="http://www.live555.com/">http://www.live555.com/</a></span></span>
</div>
<br></body></html>