Refactored files according to google style since http://review.webrtc.org/314001/ is blocked on this and formatting changes should not be done with code changes.

Review URL: https://webrtc-codereview.appspot.com/387005

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1648 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrike@webrtc.org 2012-02-08 23:41:49 +00:00
parent 68da6adafe
commit d5657c2f69
3 changed files with 2708 additions and 3004 deletions

File diff suppressed because it is too large Load Diff

View File

@ -10,11 +10,9 @@
#include "rtp_utility.h" #include "rtp_utility.h"
#include <cstring> // memcpy
#include <cmath> // ceil
#include <cassert> #include <cassert>
#include <cmath> // ceil
#include "trace.h" #include <cstring> // memcpy
#if defined(_WIN32) #if defined(_WIN32)
#include <Windows.h> // FILETIME #include <Windows.h> // FILETIME
@ -24,9 +22,13 @@
#include <sys/time.h> // gettimeofday #include <sys/time.h> // gettimeofday
#include <time.h> #include <time.h>
#endif #endif
#if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400)) #if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
#include <stdio.h> #include <stdio.h>
#endif
#include "trace.h"
#if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400))
#define DEBUG_PRINT(...) \ #define DEBUG_PRINT(...) \
{ \ { \
char msg[256]; \ char msg[256]; \
@ -40,23 +42,23 @@
namespace webrtc { namespace webrtc {
namespace ModuleRTPUtility {
/* /*
* Time routines. * Time routines.
*/ */
#if defined(_WIN32) #if defined(_WIN32)
namespace ModuleRTPUtility {
class WindowsHelpTimer
{ class WindowsHelpTimer {
public: public:
struct reference_point struct reference_point {
{
FILETIME file_time; FILETIME file_time;
LARGE_INTEGER counterMS; LARGE_INTEGER counterMS;
}; };
WindowsHelpTimer() WindowsHelpTimer() {
{
// set timer accuracy to 1 ms // set timer accuracy to 1 ms
timeBeginPeriod(1); timeBeginPeriod(1);
@ -65,20 +67,19 @@ namespace webrtc {
synchronize(); synchronize();
}; };
virtual ~WindowsHelpTimer() virtual ~WindowsHelpTimer() {
{
timeEndPeriod(1); timeEndPeriod(1);
}; };
void get_time(FILETIME& current_time) void get_time(FILETIME& current_time) {
{
// we can't use query performance counter due to speed stepping // we can't use query performance counter due to speed stepping
DWORD t = timeGetTime(); DWORD t = timeGetTime();
// NOTE: we have a miss match in sign between _timeInMs(LONG) and t(DWORD) however we only use it here without +- etc // NOTE: we have a miss match in sign between _timeInMs(LONG) and t(DWORD)
// however we only use it here without +- etc
volatile LONG* timeInMsPtr = &_timeInMs; volatile LONG* timeInMsPtr = &_timeInMs;
DWORD old = InterlockedExchange(timeInMsPtr, t); // make sure that we only inc wrapper once DWORD old = InterlockedExchange(timeInMsPtr, t); // make sure that we only
if(old > t) // inc wrapper once
{ if (old > t) {
// wrap // wrap
_numWrapTimeInMs++; _numWrapTimeInMs++;
} }
@ -96,7 +97,8 @@ namespace webrtc {
filetime_ref_as_ul.HighPart = _ref_point.file_time.dwHighDateTime; filetime_ref_as_ul.HighPart = _ref_point.file_time.dwHighDateTime;
filetime_ref_as_ul.LowPart = _ref_point.file_time.dwLowDateTime; filetime_ref_as_ul.LowPart = _ref_point.file_time.dwLowDateTime;
filetime_ref_as_ul.QuadPart += (ULONGLONG)((elapsedMS.QuadPart)*1000*10); filetime_ref_as_ul.QuadPart +=
(ULONGLONG)((elapsedMS.QuadPart) * 1000 * 10);
// //
// Copy to result // Copy to result
// //
@ -105,27 +107,24 @@ namespace webrtc {
}; };
private: private:
void synchronize() void synchronize() {
{ FILETIME ft0 = { 0, 0 }, ft1 = { 0, 0 };
FILETIME ft0 = { 0, 0 },
ft1 = { 0, 0 };
// //
// Spin waiting for a change in system time. Get the matching // Spin waiting for a change in system time. Get the matching
// performance counter value for that time. // performance counter value for that time.
// //
::GetSystemTimeAsFileTime(&ft0); ::GetSystemTimeAsFileTime(&ft0);
do do {
{
::GetSystemTimeAsFileTime(&ft1); ::GetSystemTimeAsFileTime(&ft1);
_ref_point.counterMS.QuadPart = ::timeGetTime(); _ref_point.counterMS.QuadPart = ::timeGetTime();
::Sleep(0); ::Sleep(0);
} } while ((ft0.dwHighDateTime == ft1.dwHighDateTime) &&
while ((ft0.dwHighDateTime == ft1.dwHighDateTime) &&
(ft0.dwLowDateTime == ft1.dwLowDateTime)); (ft0.dwLowDateTime == ft1.dwLowDateTime));
_ref_point.file_time = ft1; _ref_point.file_time = ft1;
} }
volatile LONG _timeInMs; // this needs to be long due to Windows, not an issue due to its usage // this needs to be long due to Windows, not an issue due to its usage
volatile LONG _timeInMs;
volatile WebRtc_UWord32 _numWrapTimeInMs; volatile WebRtc_UWord32 _numWrapTimeInMs;
reference_point _ref_point; reference_point _ref_point;
}; };
@ -145,11 +144,9 @@ namespace webrtc {
private: private:
WindowsHelpTimer _helpTimer; WindowsHelpTimer _helpTimer;
}; };
}; // namespace ModuleRTPUtility
#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
namespace ModuleRTPUtility {
// A clock reading times from the POSIX API. // A clock reading times from the POSIX API.
class UnixSystemClock : public RtpRtcpClock { class UnixSystemClock : public RtpRtcpClock {
public: public:
@ -160,28 +157,25 @@ namespace webrtc {
virtual void CurrentNTP(WebRtc_UWord32& secs, WebRtc_UWord32& frac); virtual void CurrentNTP(WebRtc_UWord32& secs, WebRtc_UWord32& frac);
}; };
}; // namespace ModuleRTPUtility
#endif #endif
namespace ModuleRTPUtility {
#if defined(_WIN32) #if defined(_WIN32)
WebRtc_UWord32 WindowsSystemClock::GetTimeInMS() WebRtc_UWord32 WindowsSystemClock::GetTimeInMS() {
{
return timeGetTime(); return timeGetTime();
} }
// Use the system time (roughly synchronised to the tick, and // Use the system time (roughly synchronised to the tick, and
// extrapolated using the system performance counter. // extrapolated using the system performance counter.
void WindowsSystemClock::CurrentNTP(WebRtc_UWord32& secs, WebRtc_UWord32& frac) void WindowsSystemClock::CurrentNTP(WebRtc_UWord32& secs,
{ WebRtc_UWord32& frac) {
const WebRtc_UWord64 FILETIME_1970 = 0x019db1ded53e8000; const WebRtc_UWord64 FILETIME_1970 = 0x019db1ded53e8000;
FILETIME StartTime; FILETIME StartTime;
WebRtc_UWord64 Time; WebRtc_UWord64 Time;
struct timeval tv; struct timeval tv;
// we can't use query performance counter since they can change depending on speed steping // we can't use query performance counter since they can change depending on
// speed steping
_helpTimer.get_time(StartTime); _helpTimer.get_time(StartTime);
Time = (((WebRtc_UWord64) StartTime.dwHighDateTime) << 32) + Time = (((WebRtc_UWord64) StartTime.dwHighDateTime) << 32) +
@ -198,12 +192,10 @@ void WindowsSystemClock::CurrentNTP(WebRtc_UWord32& secs, WebRtc_UWord32& frac)
secs = tv.tv_sec + NTP_JAN_1970; secs = tv.tv_sec + NTP_JAN_1970;
dtemp = tv.tv_usec / 1e6; dtemp = tv.tv_usec / 1e6;
if (dtemp >= 1) if (dtemp >= 1) {
{
dtemp -= 1; dtemp -= 1;
secs++; secs++;
} else if (dtemp < -1) } else if (dtemp < -1) {
{
dtemp += 1; dtemp += 1;
secs--; secs--;
} }
@ -213,8 +205,7 @@ void WindowsSystemClock::CurrentNTP(WebRtc_UWord32& secs, WebRtc_UWord32& frac)
#elif ((defined WEBRTC_LINUX) || (defined WEBRTC_MAC)) #elif ((defined WEBRTC_LINUX) || (defined WEBRTC_MAC))
WebRtc_UWord32 UnixSystemClock::GetTimeInMS() WebRtc_UWord32 UnixSystemClock::GetTimeInMS() {
{
struct timeval tv; struct timeval tv;
struct timezone tz; struct timezone tz;
WebRtc_UWord32 val; WebRtc_UWord32 val;
@ -225,8 +216,7 @@ WebRtc_UWord32 UnixSystemClock::GetTimeInMS()
} }
// Use the system time. // Use the system time.
void UnixSystemClock::CurrentNTP(WebRtc_UWord32& secs, WebRtc_UWord32& frac) void UnixSystemClock::CurrentNTP(WebRtc_UWord32& secs, WebRtc_UWord32& frac) {
{
double dtemp; double dtemp;
struct timeval tv; struct timeval tv;
struct timezone tz; struct timezone tz;
@ -236,12 +226,10 @@ void UnixSystemClock::CurrentNTP(WebRtc_UWord32& secs, WebRtc_UWord32& frac)
secs = tv.tv_sec + NTP_JAN_1970; secs = tv.tv_sec + NTP_JAN_1970;
dtemp = tv.tv_usec / 1e6; dtemp = tv.tv_usec / 1e6;
if (dtemp >= 1) if (dtemp >= 1) {
{
dtemp -= 1; dtemp -= 1;
secs++; secs++;
} else if (dtemp < -1) } else if (dtemp < -1) {
{
dtemp += 1; dtemp += 1;
secs--; secs--;
} }
@ -250,8 +238,7 @@ void UnixSystemClock::CurrentNTP(WebRtc_UWord32& secs, WebRtc_UWord32& frac)
} }
#endif #endif
RtpRtcpClock* GetSystemClock() RtpRtcpClock* GetSystemClock() {
{
// TODO(hellner): violates the style guide (non-POD static instance). // TODO(hellner): violates the style guide (non-POD static instance).
#if defined(_WIN32) #if defined(_WIN32)
static WindowsSystemClock system_clock; static WindowsSystemClock system_clock;
@ -261,8 +248,7 @@ RtpRtcpClock* GetSystemClock()
return &system_clock; return &system_clock;
} }
WebRtc_UWord32 GetCurrentRTP(RtpRtcpClock* clock, WebRtc_UWord32 freq) WebRtc_UWord32 GetCurrentRTP(RtpRtcpClock* clock, WebRtc_UWord32 freq) {
{
if (clock == NULL) if (clock == NULL)
clock = GetSystemClock(); clock = GetSystemClock();
WebRtc_UWord32 secs = 0, frac = 0; WebRtc_UWord32 secs = 0, frac = 0;
@ -272,16 +258,14 @@ WebRtc_UWord32 GetCurrentRTP(RtpRtcpClock* clock, WebRtc_UWord32 freq)
WebRtc_UWord32 ConvertNTPTimeToRTP(WebRtc_UWord32 NTPsec, WebRtc_UWord32 ConvertNTPTimeToRTP(WebRtc_UWord32 NTPsec,
WebRtc_UWord32 NTPfrac, WebRtc_UWord32 NTPfrac,
WebRtc_UWord32 freq) WebRtc_UWord32 freq) {
{
float ftemp = (float)NTPfrac / (float)NTP_FRAC; float ftemp = (float)NTPfrac / (float)NTP_FRAC;
WebRtc_UWord32 tmp = (WebRtc_UWord32)(ftemp * freq); WebRtc_UWord32 tmp = (WebRtc_UWord32)(ftemp * freq);
return NTPsec * freq + tmp; return NTPsec * freq + tmp;
} }
WebRtc_UWord32 ConvertNTPTimeToMS(WebRtc_UWord32 NTPsec, WebRtc_UWord32 ConvertNTPTimeToMS(WebRtc_UWord32 NTPsec,
WebRtc_UWord32 NTPfrac) WebRtc_UWord32 NTPfrac) {
{
int freq = 1000; int freq = 1000;
float ftemp = (float)NTPfrac / (float)NTP_FRAC; float ftemp = (float)NTPfrac / (float)NTP_FRAC;
WebRtc_UWord32 tmp = (WebRtc_UWord32)(ftemp * freq); WebRtc_UWord32 tmp = (WebRtc_UWord32)(ftemp * freq);
@ -291,48 +275,34 @@ WebRtc_UWord32 ConvertNTPTimeToMS(WebRtc_UWord32 NTPsec,
bool OldTimestamp(uint32_t newTimestamp, bool OldTimestamp(uint32_t newTimestamp,
uint32_t existingTimestamp, uint32_t existingTimestamp,
bool* wrapped) bool* wrapped) {
{
bool tmpWrapped = bool tmpWrapped =
(newTimestamp < 0x0000ffff && existingTimestamp > 0xffff0000) || (newTimestamp < 0x0000ffff && existingTimestamp > 0xffff0000) ||
(newTimestamp > 0xffff0000 && existingTimestamp < 0x0000ffff); (newTimestamp > 0xffff0000 && existingTimestamp < 0x0000ffff);
*wrapped = tmpWrapped; *wrapped = tmpWrapped;
if (existingTimestamp > newTimestamp && !tmpWrapped) if (existingTimestamp > newTimestamp && !tmpWrapped) {
{
return true; return true;
} } else if (existingTimestamp <= newTimestamp && !tmpWrapped) {
else if (existingTimestamp <= newTimestamp && !tmpWrapped)
{
return false; return false;
} } else if (existingTimestamp < newTimestamp && tmpWrapped) {
else if (existingTimestamp < newTimestamp && tmpWrapped)
{
return true; return true;
} } else {
else
{
return false; return false;
} }
} }
} // namespace ModuleRTPUtility
/* /*
* Misc utility routines * Misc utility routines
*/ */
#if defined(_WIN32) #if defined(_WIN32)
bool ModuleRTPUtility::StringCompare(const char* str1, bool StringCompare(const char* str1, const char* str2,
const char* str2, const WebRtc_UWord32 length) {
const WebRtc_UWord32 length)
{
return (_strnicmp(str1, str2, length) == 0) ? true : false; return (_strnicmp(str1, str2, length) == 0) ? true : false;
} }
#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC)
bool ModuleRTPUtility::StringCompare(const char* str1, bool StringCompare(const char* str1, const char* str2,
const char* str2, const WebRtc_UWord32 length) {
const WebRtc_UWord32 length)
{
return (strncasecmp(str1, str2, length) == 0) ? true : false; return (strncasecmp(str1, str2, length) == 0) ? true : false;
} }
#endif #endif
@ -345,9 +315,7 @@ bool ModuleRTPUtility::StringCompare(const char* str1,
All integer fields are carried in network byte order, that is, most All integer fields are carried in network byte order, that is, most
significant byte (octet) first. AKA big-endian. significant byte (octet) first. AKA big-endian.
*/ */
void void AssignUWord32ToBuffer(WebRtc_UWord8* dataBuffer, WebRtc_UWord32 value) {
ModuleRTPUtility::AssignUWord32ToBuffer(WebRtc_UWord8* dataBuffer, WebRtc_UWord32 value)
{
#if defined(WEBRTC_LITTLE_ENDIAN) #if defined(WEBRTC_LITTLE_ENDIAN)
dataBuffer[0] = static_cast<WebRtc_UWord8>(value >> 24); dataBuffer[0] = static_cast<WebRtc_UWord8>(value >> 24);
dataBuffer[1] = static_cast<WebRtc_UWord8>(value >> 16); dataBuffer[1] = static_cast<WebRtc_UWord8>(value >> 16);
@ -359,9 +327,7 @@ ModuleRTPUtility::AssignUWord32ToBuffer(WebRtc_UWord8* dataBuffer, WebRtc_UWord3
#endif #endif
} }
void void AssignUWord24ToBuffer(WebRtc_UWord8* dataBuffer, WebRtc_UWord32 value) {
ModuleRTPUtility::AssignUWord24ToBuffer(WebRtc_UWord8* dataBuffer, WebRtc_UWord32 value)
{
#if defined(WEBRTC_LITTLE_ENDIAN) #if defined(WEBRTC_LITTLE_ENDIAN)
dataBuffer[0] = static_cast<WebRtc_UWord8>(value >> 16); dataBuffer[0] = static_cast<WebRtc_UWord8>(value >> 16);
dataBuffer[1] = static_cast<WebRtc_UWord8>(value >> 8); dataBuffer[1] = static_cast<WebRtc_UWord8>(value >> 8);
@ -373,9 +339,7 @@ ModuleRTPUtility::AssignUWord24ToBuffer(WebRtc_UWord8* dataBuffer, WebRtc_UWord3
#endif #endif
} }
void void AssignUWord16ToBuffer(WebRtc_UWord8* dataBuffer, WebRtc_UWord16 value) {
ModuleRTPUtility::AssignUWord16ToBuffer(WebRtc_UWord8* dataBuffer, WebRtc_UWord16 value)
{
#if defined(WEBRTC_LITTLE_ENDIAN) #if defined(WEBRTC_LITTLE_ENDIAN)
dataBuffer[0] = static_cast<WebRtc_UWord8>(value >> 8); dataBuffer[0] = static_cast<WebRtc_UWord8>(value >> 8);
dataBuffer[1] = static_cast<WebRtc_UWord8>(value); dataBuffer[1] = static_cast<WebRtc_UWord8>(value);
@ -385,9 +349,7 @@ ModuleRTPUtility::AssignUWord16ToBuffer(WebRtc_UWord8* dataBuffer, WebRtc_UWord1
#endif #endif
} }
WebRtc_UWord16 WebRtc_UWord16 BufferToUWord16(const WebRtc_UWord8* dataBuffer) {
ModuleRTPUtility::BufferToUWord16(const WebRtc_UWord8* dataBuffer)
{
#if defined(WEBRTC_LITTLE_ENDIAN) #if defined(WEBRTC_LITTLE_ENDIAN)
return (dataBuffer[0] << 8) + dataBuffer[1]; return (dataBuffer[0] << 8) + dataBuffer[1];
#else #else
@ -395,15 +357,11 @@ ModuleRTPUtility::BufferToUWord16(const WebRtc_UWord8* dataBuffer)
#endif #endif
} }
WebRtc_UWord32 WebRtc_UWord32 BufferToUWord24(const WebRtc_UWord8* dataBuffer) {
ModuleRTPUtility::BufferToUWord24(const WebRtc_UWord8* dataBuffer)
{
return (dataBuffer[0] << 16) + (dataBuffer[1] << 8) + dataBuffer[2]; return (dataBuffer[0] << 16) + (dataBuffer[1] << 8) + dataBuffer[2];
} }
WebRtc_UWord32 WebRtc_UWord32 BufferToUWord32(const WebRtc_UWord8* dataBuffer) {
ModuleRTPUtility::BufferToUWord32(const WebRtc_UWord8* dataBuffer)
{
#if defined(WEBRTC_LITTLE_ENDIAN) #if defined(WEBRTC_LITTLE_ENDIAN)
return (dataBuffer[0] << 24) + (dataBuffer[1] << 16) + (dataBuffer[2] << 8) + return (dataBuffer[0] << 24) + (dataBuffer[1] << 16) + (dataBuffer[2] << 8) +
dataBuffer[3]; dataBuffer[3];
@ -412,23 +370,17 @@ ModuleRTPUtility::BufferToUWord32(const WebRtc_UWord8* dataBuffer)
#endif #endif
} }
WebRtc_UWord32 WebRtc_UWord32 pow2(WebRtc_UWord8 exp) {
ModuleRTPUtility::pow2(WebRtc_UWord8 exp)
{
return 1 << exp; return 1 << exp;
} }
void void RTPPayload::SetType(RtpVideoCodecTypes videoType) {
ModuleRTPUtility::RTPPayload::SetType(RtpVideoCodecTypes videoType)
{
type = videoType; type = videoType;
switch (type) switch (type) {
{
case kRtpNoVideo: case kRtpNoVideo:
break; break;
case kRtpVp8Video: case kRtpVp8Video: {
{
info.VP8.nonReferenceFrame = false; info.VP8.nonReferenceFrame = false;
info.VP8.beginningOfPartition = false; info.VP8.beginningOfPartition = false;
info.VP8.partitionID = 0; info.VP8.partitionID = 0;
@ -449,20 +401,16 @@ ModuleRTPUtility::RTPPayload::SetType(RtpVideoCodecTypes videoType)
} }
} }
ModuleRTPUtility::RTPHeaderParser::RTPHeaderParser(const WebRtc_UWord8* rtpData, RTPHeaderParser::RTPHeaderParser(const WebRtc_UWord8* rtpData,
const WebRtc_UWord32 rtpDataLength): const WebRtc_UWord32 rtpDataLength)
_ptrRTPDataBegin(rtpData), : _ptrRTPDataBegin(rtpData),
_ptrRTPDataEnd(rtpData ? (rtpData + rtpDataLength) : NULL) _ptrRTPDataEnd(rtpData ? (rtpData + rtpDataLength) : NULL) {
{
} }
ModuleRTPUtility::RTPHeaderParser::~RTPHeaderParser() RTPHeaderParser::~RTPHeaderParser() {
{
} }
bool bool RTPHeaderParser::RTCP() const {
ModuleRTPUtility::RTPHeaderParser::RTCP() const
{
// 72 to 76 is reserved for RTP // 72 to 76 is reserved for RTP
// 77 to 79 is not reserver but they are not assigned we will block them // 77 to 79 is not reserver but they are not assigned we will block them
// for RTCP 200 SR == marker bit + 72 // for RTCP 200 SR == marker bit + 72
@ -472,7 +420,8 @@ ModuleRTPUtility::RTPHeaderParser::RTCP() const
* *
* FIR full INTRA-frame request 192 [RFC2032] supported * FIR full INTRA-frame request 192 [RFC2032] supported
* NACK negative acknowledgement 193 [RFC2032] * NACK negative acknowledgement 193 [RFC2032]
* IJ Extended inter-arrival jitter report 195 [RFC-ietf-avt-rtp-toffset-07.txt] http://tools.ietf.org/html/draft-ietf-avt-rtp-toffset-07 * IJ Extended inter-arrival jitter report 195 [RFC-ietf-avt-rtp-toff
* set-07.txt] http://tools.ietf.org/html/draft-ietf-avt-rtp-toffset-07
* SR sender report 200 [RFC3551] supported * SR sender report 200 [RFC3551] supported
* RR receiver report 201 [RFC3551] supported * RR receiver report 201 [RFC3551] supported
* SDES source description 202 [RFC3551] supported * SDES source description 202 [RFC3551] supported
@ -506,8 +455,7 @@ ModuleRTPUtility::RTPHeaderParser::RTCP() const
bool RTCP = false; bool RTCP = false;
// check if this is a RTCP packet // check if this is a RTCP packet
switch(payloadType) switch (payloadType) {
{
case 192: case 192:
RTCP = true; RTCP = true;
break; break;
@ -530,26 +478,27 @@ ModuleRTPUtility::RTPHeaderParser::RTCP() const
return RTCP; return RTCP;
} }
bool bool RTPHeaderParser::Parse(WebRtcRTPHeader& parsedPacket,
ModuleRTPUtility::RTPHeaderParser::Parse( RtpHeaderExtensionMap* ptrExtensionMap) const {
WebRtcRTPHeader& parsedPacket, RtpHeaderExtensionMap* ptrExtensionMap) const
{
const ptrdiff_t length = _ptrRTPDataEnd - _ptrRTPDataBegin; const ptrdiff_t length = _ptrRTPDataEnd - _ptrRTPDataBegin;
if (length < 12) if (length < 12) {
{
return false; return false;
} }
const WebRtc_UWord8 V = _ptrRTPDataBegin[0] >> 6 ; // Version // Version
const bool P = ((_ptrRTPDataBegin[0] & 0x20) == 0) ? false : true; // Padding const WebRtc_UWord8 V = _ptrRTPDataBegin[0] >> 6;
const bool X = ((_ptrRTPDataBegin[0] & 0x10) == 0) ? false : true; // eXtension // Padding
const bool P = ((_ptrRTPDataBegin[0] & 0x20) == 0) ? false : true;
// eXtension
const bool X = ((_ptrRTPDataBegin[0] & 0x10) == 0) ? false : true;
const WebRtc_UWord8 CC = _ptrRTPDataBegin[0] & 0x0f; const WebRtc_UWord8 CC = _ptrRTPDataBegin[0] & 0x0f;
const bool M = ((_ptrRTPDataBegin[1] & 0x80) == 0) ? false : true; const bool M = ((_ptrRTPDataBegin[1] & 0x80) == 0) ? false : true;
const WebRtc_UWord8 PT = _ptrRTPDataBegin[1] & 0x7f; const WebRtc_UWord8 PT = _ptrRTPDataBegin[1] & 0x7f;
const WebRtc_UWord16 sequenceNumber = (_ptrRTPDataBegin[2] << 8) + _ptrRTPDataBegin[3]; const WebRtc_UWord16 sequenceNumber = (_ptrRTPDataBegin[2] << 8) +
_ptrRTPDataBegin[3];
const WebRtc_UWord8* ptr = &_ptrRTPDataBegin[4]; const WebRtc_UWord8* ptr = &_ptrRTPDataBegin[4];
@ -563,15 +512,13 @@ ModuleRTPUtility::RTPHeaderParser::Parse(
SSRC += *ptr++ << 8; SSRC += *ptr++ << 8;
SSRC += *ptr++; SSRC += *ptr++;
if (V != 2) if (V != 2) {
{
return false; return false;
} }
const WebRtc_UWord8 CSRCocts = CC * 4; const WebRtc_UWord8 CSRCocts = CC * 4;
if ((ptr + CSRCocts) > _ptrRTPDataEnd) if ((ptr + CSRCocts) > _ptrRTPDataEnd) {
{
return false; return false;
} }
@ -583,8 +530,7 @@ ModuleRTPUtility::RTPHeaderParser::Parse(
parsedPacket.header.numCSRCs = CC; parsedPacket.header.numCSRCs = CC;
parsedPacket.header.paddingLength = P ? *(_ptrRTPDataEnd - 1) : 0; parsedPacket.header.paddingLength = P ? *(_ptrRTPDataEnd - 1) : 0;
for (unsigned int i = 0; i < CC; ++i) for (unsigned int i = 0; i < CC; ++i) {
{
WebRtc_UWord32 CSRC = *ptr++ << 24; WebRtc_UWord32 CSRC = *ptr++ << 24;
CSRC += *ptr++ << 16; CSRC += *ptr++ << 16;
CSRC += *ptr++ << 8; CSRC += *ptr++ << 8;
@ -599,8 +545,7 @@ ModuleRTPUtility::RTPHeaderParser::Parse(
// is zero. // is zero.
parsedPacket.extension.transmissionTimeOffset = 0; parsedPacket.extension.transmissionTimeOffset = 0;
if (X) if (X) {
{
/* RTP header extension, RFC 3550. /* RTP header extension, RFC 3550.
0 1 2 3 0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@ -611,8 +556,7 @@ ModuleRTPUtility::RTPHeaderParser::Parse(
| .... | | .... |
*/ */
const ptrdiff_t remain = _ptrRTPDataEnd - ptr; const ptrdiff_t remain = _ptrRTPDataEnd - ptr;
if (remain < 4) if (remain < 4) {
{
return false; return false;
} }
@ -625,12 +569,10 @@ ModuleRTPUtility::RTPHeaderParser::Parse(
XLen += *ptr++; // in 32 bit words XLen += *ptr++; // in 32 bit words
XLen *= 4; // in octs XLen *= 4; // in octs
if (remain < (4 + XLen)) if (remain < (4 + XLen)) {
{
return false; return false;
} }
if (definedByProfile == RTP_ONE_BYTE_HEADER_EXTENSION) if (definedByProfile == RTP_ONE_BYTE_HEADER_EXTENSION) {
{
const WebRtc_UWord8* ptrRTPDataExtensionEnd = ptr + XLen; const WebRtc_UWord8* ptrRTPDataExtensionEnd = ptr + XLen;
ParseOneByteExtensionHeader(parsedPacket, ParseOneByteExtensionHeader(parsedPacket,
ptrExtensionMap, ptrExtensionMap,
@ -639,23 +581,20 @@ ModuleRTPUtility::RTPHeaderParser::Parse(
} }
parsedPacket.header.headerLength += XLen; parsedPacket.header.headerLength += XLen;
} }
return true; return true;
} }
void ModuleRTPUtility::RTPHeaderParser::ParseOneByteExtensionHeader( void RTPHeaderParser::ParseOneByteExtensionHeader(
WebRtcRTPHeader& parsedPacket, WebRtcRTPHeader& parsedPacket,
const RtpHeaderExtensionMap* ptrExtensionMap, const RtpHeaderExtensionMap* ptrExtensionMap,
const WebRtc_UWord8* ptrRTPDataExtensionEnd, const WebRtc_UWord8* ptrRTPDataExtensionEnd,
const WebRtc_UWord8* ptr) const const WebRtc_UWord8* ptr) const {
{
if (!ptrExtensionMap) { if (!ptrExtensionMap) {
WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, -1, "No extension map."); WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, -1, "No extension map.");
return; return;
} }
while (ptrRTPDataExtensionEnd - ptr > 0) while (ptrRTPDataExtensionEnd - ptr > 0) {
{
// 0 // 0
// 0 1 2 3 4 5 6 7 // 0 1 2 3 4 5 6 7
// +-+-+-+-+-+-+-+-+ // +-+-+-+-+-+-+-+-+
@ -679,12 +618,9 @@ void ModuleRTPUtility::RTPHeaderParser::ParseOneByteExtensionHeader(
return; return;
} }
switch (type) switch (type) {
{ case kRtpExtensionTransmissionTimeOffset: {
case kRtpExtensionTransmissionTimeOffset: if (len != 2) {
{
if (len != 2)
{
WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, -1, WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, -1,
"Incorrect transmission time offset len: %d", len); "Incorrect transmission time offset len: %d", len);
return; return;
@ -701,8 +637,7 @@ void ModuleRTPUtility::RTPHeaderParser::ParseOneByteExtensionHeader(
parsedPacket.extension.transmissionTimeOffset = transmissionTimeOffset; parsedPacket.extension.transmissionTimeOffset = transmissionTimeOffset;
break; break;
} }
case kRtpExtensionAudioLevel: case kRtpExtensionAudioLevel: {
{
// --- Only used for debugging --- // --- Only used for debugging ---
// 0 1 2 3 // 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@ -714,12 +649,11 @@ void ModuleRTPUtility::RTPHeaderParser::ParseOneByteExtensionHeader(
// Parse out the fields but only use it for debugging for now. // Parse out the fields but only use it for debugging for now.
// const WebRtc_UWord8 V = (*ptr & 0x80) >> 7; // const WebRtc_UWord8 V = (*ptr & 0x80) >> 7;
// const WebRtc_UWord8 level = (*ptr & 0x7f); // const WebRtc_UWord8 level = (*ptr & 0x7f);
//DEBUG_PRINT("RTP_AUDIO_LEVEL_UNIQUE_ID: ID=%u, len=%u, V=%u, level=%u", // DEBUG_PRINT("RTP_AUDIO_LEVEL_UNIQUE_ID: ID=%u, len=%u, V=%u,
// ID, len, V, level); // level=%u", ID, len, V, level);
break; break;
} }
default: default: {
{
WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, -1, WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, -1,
"Extension type not implemented."); "Extension type not implemented.");
return; return;
@ -730,7 +664,7 @@ void ModuleRTPUtility::RTPHeaderParser::ParseOneByteExtensionHeader(
} }
} }
WebRtc_UWord8 ModuleRTPUtility::RTPHeaderParser::ParsePaddingBytes( WebRtc_UWord8 RTPHeaderParser::ParsePaddingBytes(
const WebRtc_UWord8* ptrRTPDataExtensionEnd, const WebRtc_UWord8* ptrRTPDataExtensionEnd,
const WebRtc_UWord8* ptr) const { const WebRtc_UWord8* ptr) const {
@ -746,30 +680,24 @@ WebRtc_UWord8 ModuleRTPUtility::RTPHeaderParser::ParsePaddingBytes(
} }
// RTP payload parser // RTP payload parser
ModuleRTPUtility::RTPPayloadParser::RTPPayloadParser( RTPPayloadParser::RTPPayloadParser(const RtpVideoCodecTypes videoType,
const RtpVideoCodecTypes videoType,
const WebRtc_UWord8* payloadData, const WebRtc_UWord8* payloadData,
const WebRtc_UWord16 payloadDataLength, WebRtc_UWord16 payloadDataLength,
const WebRtc_Word32 id) WebRtc_Word32 id)
: :
_id(id), _id(id),
_dataPtr(payloadData), _dataPtr(payloadData),
_dataLength(payloadDataLength), _dataLength(payloadDataLength),
_videoType(videoType) _videoType(videoType) {
{
} }
ModuleRTPUtility::RTPPayloadParser::~RTPPayloadParser() RTPPayloadParser::~RTPPayloadParser() {
{
} }
bool bool RTPPayloadParser::Parse(RTPPayload& parsedPacket) const {
ModuleRTPUtility::RTPPayloadParser::Parse( RTPPayload& parsedPacket) const
{
parsedPacket.SetType(_videoType); parsedPacket.SetType(_videoType);
switch (_videoType) switch (_videoType) {
{
case kRtpNoVideo: case kRtpNoVideo:
return ParseGeneric(parsedPacket); return ParseGeneric(parsedPacket);
case kRtpVp8Video: case kRtpVp8Video:
@ -779,9 +707,7 @@ ModuleRTPUtility::RTPPayloadParser::Parse( RTPPayload& parsedPacket) const
} }
} }
bool bool RTPPayloadParser::ParseGeneric(RTPPayload& /*parsedPacket*/) const {
ModuleRTPUtility::RTPPayloadParser::ParseGeneric(RTPPayload& /*parsedPacket*/) const
{
return false; return false;
} }
@ -810,9 +736,7 @@ ModuleRTPUtility::RTPPayloadParser::ParseGeneric(RTPPayload& /*parsedPacket*/) c
// | ... | // | ... |
// + + // + +
bool bool RTPPayloadParser::ParseVP8(RTPPayload& parsedPacket) const {
ModuleRTPUtility::RTPPayloadParser::ParseVP8(RTPPayload& parsedPacket) const
{
RTPPayloadVP8* vp8 = &parsedPacket.info.VP8; RTPPayloadVP8* vp8 = &parsedPacket.info.VP8;
const WebRtc_UWord8* dataPtr = _dataPtr; const WebRtc_UWord8* dataPtr = _dataPtr;
int dataLength = _dataLength; int dataLength = _dataLength;
@ -823,8 +747,7 @@ ModuleRTPUtility::RTPPayloadParser::ParseVP8(RTPPayload& parsedPacket) const
vp8->beginningOfPartition = (*dataPtr & 0x10) ? true : false; // S bit vp8->beginningOfPartition = (*dataPtr & 0x10) ? true : false; // S bit
vp8->partitionID = (*dataPtr & 0x0F); // PartID field vp8->partitionID = (*dataPtr & 0x0F); // PartID field
if (vp8->partitionID > 8) if (vp8->partitionID > 8) {
{
// Weak check for corrupt data: PartID MUST NOT be larger than 8. // Weak check for corrupt data: PartID MUST NOT be larger than 8.
return false; return false;
} }
@ -833,32 +756,26 @@ ModuleRTPUtility::RTPPayloadParser::ParseVP8(RTPPayload& parsedPacket) const
dataPtr++; dataPtr++;
dataLength--; dataLength--;
if (extension) if (extension) {
{
const int parsedBytes = ParseVP8Extension(vp8, dataPtr, dataLength); const int parsedBytes = ParseVP8Extension(vp8, dataPtr, dataLength);
if (parsedBytes < 0) return false; if (parsedBytes < 0) return false;
dataPtr += parsedBytes; dataPtr += parsedBytes;
dataLength -= parsedBytes; dataLength -= parsedBytes;
} }
if (dataLength <= 0) if (dataLength <= 0) {
{
WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id, WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, _id,
"Error parsing VP8 payload descriptor; payload too short"); "Error parsing VP8 payload descriptor; payload too short");
return false; return false;
} }
// Read P bit from payload header (only at beginning of first partition) // Read P bit from payload header (only at beginning of first partition)
if (dataLength > 0 && vp8->beginningOfPartition && vp8->partitionID == 0) if (dataLength > 0 && vp8->beginningOfPartition && vp8->partitionID == 0) {
{
parsedPacket.frameType = (*dataPtr & 0x01) ? kPFrame : kIFrame; parsedPacket.frameType = (*dataPtr & 0x01) ? kPFrame : kIFrame;
} } else {
else
{
parsedPacket.frameType = kPFrame; parsedPacket.frameType = kPFrame;
} }
if (0 != ParseVP8FrameSize(parsedPacket, dataPtr, dataLength)) if (0 != ParseVP8FrameSize(parsedPacket, dataPtr, dataLength)) {
{
return false; return false;
} }
parsedPacket.info.VP8.data = dataPtr; parsedPacket.info.VP8.data = dataPtr;
@ -866,18 +783,14 @@ ModuleRTPUtility::RTPPayloadParser::ParseVP8(RTPPayload& parsedPacket) const
return true; return true;
} }
int ModuleRTPUtility::RTPPayloadParser::ParseVP8FrameSize( int RTPPayloadParser::ParseVP8FrameSize(RTPPayload& parsedPacket,
RTPPayload &parsedPacket,
const WebRtc_UWord8* dataPtr, const WebRtc_UWord8* dataPtr,
int dataLength) const int dataLength) const {
{ if (parsedPacket.frameType != kIFrame) {
if (parsedPacket.frameType != kIFrame)
{
// Included in payload header for I-frames. // Included in payload header for I-frames.
return 0; return 0;
} }
if (dataLength < 10) if (dataLength < 10) {
{
// For an I-frame we should always have the uncompressed VP8 header // For an I-frame we should always have the uncompressed VP8 header
// in the beginning of the partition. // in the beginning of the partition.
return -1; return -1;
@ -888,11 +801,9 @@ int ModuleRTPUtility::RTPPayloadParser::ParseVP8FrameSize(
return 0; return 0;
} }
int ModuleRTPUtility::RTPPayloadParser::ParseVP8Extension( int RTPPayloadParser::ParseVP8Extension(RTPPayloadVP8* vp8,
RTPPayloadVP8 *vp8,
const WebRtc_UWord8* dataPtr, const WebRtc_UWord8* dataPtr,
int dataLength) const int dataLength) const {
{
int parsedBytes = 0; int parsedBytes = 0;
if (dataLength <= 0) return -1; if (dataLength <= 0) return -1;
// Optional X field is present // Optional X field is present
@ -906,43 +817,33 @@ int ModuleRTPUtility::RTPPayloadParser::ParseVP8Extension(
parsedBytes++; parsedBytes++;
dataLength--; dataLength--;
if (vp8->hasPictureID) if (vp8->hasPictureID) {
{ if (ParseVP8PictureID(vp8, &dataPtr, &dataLength, &parsedBytes) != 0) {
if (ParseVP8PictureID(vp8, &dataPtr, &dataLength, &parsedBytes) != 0)
{
return -1; return -1;
} }
} }
if (vp8->hasTl0PicIdx) if (vp8->hasTl0PicIdx) {
{ if (ParseVP8Tl0PicIdx(vp8, &dataPtr, &dataLength, &parsedBytes) != 0) {
if (ParseVP8Tl0PicIdx(vp8, &dataPtr, &dataLength, &parsedBytes) != 0)
{
return -1; return -1;
} }
} }
if (vp8->hasTID || vp8->hasKeyIdx) if (vp8->hasTID || vp8->hasKeyIdx) {
{ if (ParseVP8TIDAndKeyIdx(vp8, &dataPtr, &dataLength, &parsedBytes) != 0) {
if (ParseVP8TIDAndKeyIdx(vp8, &dataPtr, &dataLength, &parsedBytes) != 0)
{
return -1; return -1;
} }
} }
return parsedBytes; return parsedBytes;
} }
int int RTPPayloadParser::ParseVP8PictureID(RTPPayloadVP8* vp8,
ModuleRTPUtility::RTPPayloadParser::ParseVP8PictureID(
RTPPayloadVP8 *vp8,
const WebRtc_UWord8** dataPtr, const WebRtc_UWord8** dataPtr,
int* dataLength, int* dataLength,
int *parsedBytes) const int* parsedBytes) const {
{
if (*dataLength <= 0) return -1; if (*dataLength <= 0) return -1;
vp8->pictureID = (**dataPtr & 0x7F); vp8->pictureID = (**dataPtr & 0x7F);
if (**dataPtr & 0x80) if (**dataPtr & 0x80) {
{
(*dataPtr)++; (*dataPtr)++;
(*parsedBytes)++; (*parsedBytes)++;
if (--(*dataLength) <= 0) return -1; if (--(*dataLength) <= 0) return -1;
@ -955,13 +856,10 @@ ModuleRTPUtility::RTPPayloadParser::ParseVP8PictureID(
return 0; return 0;
} }
int int RTPPayloadParser::ParseVP8Tl0PicIdx(RTPPayloadVP8* vp8,
ModuleRTPUtility::RTPPayloadParser::ParseVP8Tl0PicIdx(
RTPPayloadVP8 *vp8,
const WebRtc_UWord8** dataPtr, const WebRtc_UWord8** dataPtr,
int* dataLength, int* dataLength,
int *parsedBytes) const int* parsedBytes) const {
{
if (*dataLength <= 0) return -1; if (*dataLength <= 0) return -1;
vp8->tl0PicIdx = **dataPtr; vp8->tl0PicIdx = **dataPtr;
(*dataPtr)++; (*dataPtr)++;
@ -970,20 +868,16 @@ ModuleRTPUtility::RTPPayloadParser::ParseVP8Tl0PicIdx(
return 0; return 0;
} }
int ModuleRTPUtility::RTPPayloadParser::ParseVP8TIDAndKeyIdx( int RTPPayloadParser::ParseVP8TIDAndKeyIdx(RTPPayloadVP8* vp8,
RTPPayloadVP8 *vp8,
const WebRtc_UWord8** dataPtr, const WebRtc_UWord8** dataPtr,
int* dataLength, int* dataLength,
int *parsedBytes) const int* parsedBytes) const {
{
if (*dataLength <= 0) return -1; if (*dataLength <= 0) return -1;
if (vp8->hasTID) if (vp8->hasTID) {
{
vp8->tID = ((**dataPtr >> 6) & 0x03); vp8->tID = ((**dataPtr >> 6) & 0x03);
vp8->layerSync = (**dataPtr & 0x20) ? true : false; // Y bit vp8->layerSync = (**dataPtr & 0x20) ? true : false; // Y bit
} }
if (vp8->hasKeyIdx) if (vp8->hasKeyIdx) {
{
vp8->keyIdx = (**dataPtr & 0x1F); vp8->keyIdx = (**dataPtr & 0x1F);
} }
(*dataPtr)++; (*dataPtr)++;
@ -991,4 +885,7 @@ int ModuleRTPUtility::RTPPayloadParser::ParseVP8TIDAndKeyIdx(
(*dataLength)--; (*dataLength)--;
return 0; return 0;
} }
} // namespace ModuleRTPUtility
} // namespace webrtc } // namespace webrtc

View File

@ -233,7 +233,9 @@ namespace ModuleRTPUtility
const WebRtc_UWord16 _dataLength; const WebRtc_UWord16 _dataLength;
const RtpVideoCodecTypes _videoType; const RtpVideoCodecTypes _videoType;
}; };
}
} // namespace ModuleRTPUtility
} // namespace webrtc } // namespace webrtc
#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_UTILITY_H_ #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_UTILITY_H_