Change the timestamp calculation.

This commit is contained in:
Jonathan Naylor 2020-05-12 14:06:53 +01:00
parent df6db324fa
commit 9ebcca5b56
2 changed files with 47 additions and 40 deletions

View File

@ -41,7 +41,6 @@ m_rtcpPort(rptPort + 1U),
m_rtpPort(rptPort + 0U), m_rtpPort(rptPort + 0U),
m_sessionId(0U), m_sessionId(0U),
m_seqNo(0U), m_seqNo(0U),
m_timeStamp(0U),
m_ssrc(0U), m_ssrc(0U),
m_debug(debug), m_debug(debug),
m_startSecs(0U), m_startSecs(0U),
@ -239,30 +238,6 @@ bool CKenwoodNetwork::writeRTPVoiceHeader(const unsigned char* data)
{ {
assert(data != NULL); assert(data != NULL);
#if defined(_WIN32) || defined(_WIN64)
SYSTEMTIME st;
::GetSystemTime(&st);
unsigned int hh = st.wHour;
unsigned int mm = st.wMinute;
unsigned int ss = st.wSecond;
unsigned int ms = st.wMilliseconds;
m_timeStamp = hh * 3600U * 1000U * 80U;
m_timeStamp += mm * 60U * 1000U * 80U;
m_timeStamp += ss * 1000U * 80U;
m_timeStamp += ms * 80U;
#else
struct timeval tod;
::gettimeofday(&tod, NULL);
unsigned int ss = tod.tv_sec;
unsigned int ms = tod.tv_usec / 1000U;
m_timeStamp = ss * 1000U * 80U;
m_timeStamp += ms * 80U;
#endif
unsigned char buffer[50U]; unsigned char buffer[50U];
::memset(buffer, 0x00U, 50U); ::memset(buffer, 0x00U, 50U);
@ -273,10 +248,11 @@ bool CKenwoodNetwork::writeRTPVoiceHeader(const unsigned char* data)
buffer[2U] = (m_seqNo >> 8) & 0xFFU; buffer[2U] = (m_seqNo >> 8) & 0xFFU;
buffer[3U] = (m_seqNo >> 0) & 0xFFU; buffer[3U] = (m_seqNo >> 0) & 0xFFU;
buffer[4U] = (m_timeStamp >> 24) & 0xFFU; unsigned long timeStamp = getTimeStamp();
buffer[5U] = (m_timeStamp >> 16) & 0xFFU; buffer[4U] = (timeStamp >> 24) & 0xFFU;
buffer[6U] = (m_timeStamp >> 8) & 0xFFU; buffer[5U] = (timeStamp >> 16) & 0xFFU;
buffer[7U] = (m_timeStamp >> 0) & 0xFFU; buffer[6U] = (timeStamp >> 8) & 0xFFU;
buffer[7U] = (timeStamp >> 0) & 0xFFU;
buffer[8U] = (m_ssrc >> 24) & 0xFFU; buffer[8U] = (m_ssrc >> 24) & 0xFFU;
buffer[9U] = (m_ssrc >> 16) & 0xFFU; buffer[9U] = (m_ssrc >> 16) & 0xFFU;
@ -319,11 +295,11 @@ bool CKenwoodNetwork::writeRTPVoiceTrailer(const unsigned char* data)
buffer[2U] = (m_seqNo >> 8) & 0xFFU; buffer[2U] = (m_seqNo >> 8) & 0xFFU;
buffer[3U] = (m_seqNo >> 0) & 0xFFU; buffer[3U] = (m_seqNo >> 0) & 0xFFU;
m_timeStamp += 640U; unsigned long timeStamp = getTimeStamp();
buffer[4U] = (m_timeStamp >> 24) & 0xFFU; buffer[4U] = (timeStamp >> 24) & 0xFFU;
buffer[5U] = (m_timeStamp >> 16) & 0xFFU; buffer[5U] = (timeStamp >> 16) & 0xFFU;
buffer[6U] = (m_timeStamp >> 8) & 0xFFU; buffer[6U] = (timeStamp >> 8) & 0xFFU;
buffer[7U] = (m_timeStamp >> 0) & 0xFFU; buffer[7U] = (timeStamp >> 0) & 0xFFU;
buffer[8U] = (m_ssrc >> 24) & 0xFFU; buffer[8U] = (m_ssrc >> 24) & 0xFFU;
buffer[9U] = (m_ssrc >> 16) & 0xFFU; buffer[9U] = (m_ssrc >> 16) & 0xFFU;
@ -365,11 +341,11 @@ bool CKenwoodNetwork::writeRTPVoiceData(const unsigned char* data)
buffer[2U] = (m_seqNo >> 8) & 0xFFU; buffer[2U] = (m_seqNo >> 8) & 0xFFU;
buffer[3U] = (m_seqNo >> 0) & 0xFFU; buffer[3U] = (m_seqNo >> 0) & 0xFFU;
m_timeStamp += 640U; unsigned long timeStamp = getTimeStamp();
buffer[4U] = (m_timeStamp >> 24) & 0xFFU; buffer[4U] = (timeStamp >> 24) & 0xFFU;
buffer[5U] = (m_timeStamp >> 16) & 0xFFU; buffer[5U] = (timeStamp >> 16) & 0xFFU;
buffer[6U] = (m_timeStamp >> 8) & 0xFFU; buffer[6U] = (timeStamp >> 8) & 0xFFU;
buffer[7U] = (m_timeStamp >> 0) & 0xFFU; buffer[7U] = (timeStamp >> 0) & 0xFFU;
buffer[8U] = (m_ssrc >> 24) & 0xFFU; buffer[8U] = (m_ssrc >> 24) & 0xFFU;
buffer[9U] = (m_ssrc >> 16) & 0xFFU; buffer[9U] = (m_ssrc >> 16) & 0xFFU;
@ -842,3 +818,34 @@ void CKenwoodNetwork::processKenwoodData(unsigned char* inData)
::memcpy(inData, outData, 24U); ::memcpy(inData, outData, 24U);
} }
} }
unsigned long CKenwoodNetwork::getTimeStamp() const
{
unsigned long timeStamp = 0UL;
#if defined(_WIN32) || defined(_WIN64)
SYSTEMTIME st;
::GetSystemTime(&st);
unsigned int hh = st.wHour;
unsigned int mm = st.wMinute;
unsigned int ss = st.wSecond;
unsigned int ms = st.wMilliseconds;
timeStamp += hh * 3600U * 1000U * 80U;
timeStamp += mm * 60U * 1000U * 80U;
timeStamp += ss * 1000U * 80U;
timeStamp += ms * 80U;
#else
struct timeval tod;
::gettimeofday(&tod, NULL);
unsigned int ss = tod.tv_sec;
unsigned int ms = tod.tv_usec / 1000U;
timeStamp += ss * 1000U * 80U;
timeStamp += ms * 80U;
#endif
return timeStamp;
}

View File

@ -49,7 +49,6 @@ private:
unsigned int m_rtpPort; unsigned int m_rtpPort;
uint8_t m_sessionId; uint8_t m_sessionId;
uint16_t m_seqNo; uint16_t m_seqNo;
unsigned long m_timeStamp;
unsigned int m_ssrc; unsigned int m_ssrc;
bool m_debug; bool m_debug;
uint32_t m_startSecs; uint32_t m_startSecs;
@ -74,6 +73,7 @@ private:
bool writeRTCPHang(); bool writeRTCPHang();
unsigned int readRTP(unsigned char* data); unsigned int readRTP(unsigned char* data);
unsigned int readRTCP(unsigned char* data); unsigned int readRTCP(unsigned char* data);
unsigned long getTimeStamp() const;
}; };
#endif #endif