Add even more of the source
This should be about everything needed to build so far?
This commit is contained in:
parent
af3619d4fa
commit
849723c9cf
547 changed files with 149239 additions and 0 deletions
241
RTPMetaInfoLib/RTPMetaInfoPacket.cpp
Normal file
241
RTPMetaInfoLib/RTPMetaInfoPacket.cpp
Normal file
|
@ -0,0 +1,241 @@
|
|||
/*
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* Copyright (c) 1999-2008 Apple Inc. All Rights Reserved.
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
*
|
||||
*/
|
||||
//
|
||||
// RTPMetaInfo.h:
|
||||
// Some defs for RTP-Meta-Info payloads.
|
||||
|
||||
|
||||
#include "RTPMetaInfoPacket.h"
|
||||
#include "MyAssert.h"
|
||||
#include "StringParser.h"
|
||||
#include "OS.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifndef __Win32__
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
const RTPMetaInfoPacket::FieldName RTPMetaInfoPacket::kFieldNameMap[] =
|
||||
{
|
||||
TW0_CHARS_TO_INT('p', 'p'),
|
||||
TW0_CHARS_TO_INT('t', 't'),
|
||||
TW0_CHARS_TO_INT('f', 't'),
|
||||
TW0_CHARS_TO_INT('p', 'n'),
|
||||
TW0_CHARS_TO_INT('s', 'q'),
|
||||
TW0_CHARS_TO_INT('m', 'd')
|
||||
};
|
||||
|
||||
const UInt32 RTPMetaInfoPacket::kFieldLengthValidator[] =
|
||||
{
|
||||
8, //pp
|
||||
8, //tt
|
||||
2, //ft
|
||||
8, //pn
|
||||
2, //sq
|
||||
0, //md
|
||||
0 //illegal / unknown
|
||||
};
|
||||
|
||||
|
||||
RTPMetaInfoPacket::FieldIndex RTPMetaInfoPacket::GetFieldIndexForName(FieldName inName)
|
||||
{
|
||||
for (int x = 0; x < kNumFields; x++)
|
||||
{
|
||||
if (inName == kFieldNameMap[x])
|
||||
return x;
|
||||
}
|
||||
return kIllegalField;
|
||||
}
|
||||
|
||||
void RTPMetaInfoPacket::ConstructFieldIDArrayFromHeader(StrPtrLen* inHeader, FieldID* ioFieldIDArray)
|
||||
{
|
||||
for (UInt32 x = 0; x < kNumFields; x++)
|
||||
ioFieldIDArray[x] = kFieldNotUsed;
|
||||
|
||||
//
|
||||
// Walk through the fields in this header
|
||||
StringParser theParser(inHeader);
|
||||
|
||||
UInt16 fieldNameValue = 0;
|
||||
|
||||
while (theParser.GetDataRemaining() > 0)
|
||||
{
|
||||
StrPtrLen theFieldP;
|
||||
(void)theParser.GetThru(&theFieldP, ';');
|
||||
|
||||
//
|
||||
// Corrupt or something... just bail
|
||||
if (theFieldP.Len < 2)
|
||||
break;
|
||||
|
||||
//
|
||||
// Extract the Field Name and convert it to a Field Index
|
||||
::memcpy (&fieldNameValue, theFieldP.Ptr, sizeof(UInt16));
|
||||
FieldIndex theIndex = RTPMetaInfoPacket::GetFieldIndexForName(ntohs(fieldNameValue));
|
||||
// FieldIndex theIndex = RTPMetaInfoPacket::GetFieldIndexForName(ntohs(*(UInt16*)theFieldP.Ptr));
|
||||
|
||||
//
|
||||
// Get the Field ID if there is one.
|
||||
FieldID theID = kUncompressed;
|
||||
if (theFieldP.Len > 3)
|
||||
{
|
||||
StringParser theIDExtractor(&theFieldP);
|
||||
theIDExtractor.ConsumeLength(NULL, 3);
|
||||
theID = theIDExtractor.ConsumeInteger(NULL);
|
||||
}
|
||||
|
||||
if (theIndex != kIllegalField)
|
||||
ioFieldIDArray[theIndex] = theID;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Bool16 RTPMetaInfoPacket::ParsePacket(UInt8* inPacketBuffer, UInt32 inPacketLen, FieldID* inFieldIDArray)
|
||||
{
|
||||
UInt8* theFieldP = inPacketBuffer + 12; // skip RTP header
|
||||
UInt8* theEndP = inPacketBuffer + inPacketLen;
|
||||
|
||||
SInt64 sInt64Val = 0;
|
||||
UInt16 uInt16Val = 0;
|
||||
|
||||
while (theFieldP < (theEndP - 2))
|
||||
{
|
||||
FieldIndex theFieldIndex = kIllegalField;
|
||||
UInt32 theFieldLen = 0;
|
||||
FieldName* theFieldName = (FieldName*)theFieldP;
|
||||
|
||||
if (*theFieldName & 0x8000)
|
||||
{
|
||||
Assert(inFieldIDArray != NULL);
|
||||
|
||||
// If this is a compressed field, find to which field the ID maps
|
||||
UInt8 theFieldID = *theFieldP & 0x7F;
|
||||
|
||||
for (int x = 0; x < kNumFields; x++)
|
||||
{
|
||||
if (theFieldID == inFieldIDArray[x])
|
||||
{
|
||||
theFieldIndex = x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
theFieldLen = *(theFieldP + 1);
|
||||
theFieldP += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is not a compressed field. Make sure there is enough room
|
||||
// in the packet for this to make sense
|
||||
if (theFieldP >= (theEndP - 4))
|
||||
break;
|
||||
|
||||
::memcpy(&uInt16Val, theFieldP, sizeof(uInt16Val));
|
||||
theFieldIndex = this->GetFieldIndexForName(ntohs(uInt16Val));
|
||||
|
||||
::memcpy(&uInt16Val, theFieldP + 2, sizeof(uInt16Val));
|
||||
theFieldLen = ntohs(uInt16Val);
|
||||
theFieldP += 4;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate the length of this field if possible.
|
||||
// If the field is of the wrong length, return an error.
|
||||
if ((kFieldLengthValidator[theFieldIndex] > 0) &&
|
||||
(kFieldLengthValidator[theFieldIndex] != theFieldLen))
|
||||
return false;
|
||||
if ((theFieldP + theFieldLen) > theEndP)
|
||||
return false;
|
||||
|
||||
//
|
||||
// We now know what field we are dealing with, so store off
|
||||
// the proper value depending on the field
|
||||
switch (theFieldIndex)
|
||||
{
|
||||
case kPacketPosField:
|
||||
{
|
||||
::memcpy(&sInt64Val, theFieldP, sizeof(sInt64Val));
|
||||
fPacketPosition = (UInt64)OS::NetworkToHostSInt64(sInt64Val);
|
||||
break;
|
||||
}
|
||||
case kTransTimeField:
|
||||
{
|
||||
::memcpy(&sInt64Val, theFieldP, sizeof(sInt64Val));
|
||||
fTransmitTime = (UInt64)OS::NetworkToHostSInt64(sInt64Val);
|
||||
break;
|
||||
}
|
||||
case kFrameTypeField:
|
||||
{
|
||||
fFrameType = ntohs(*((FrameTypeField*)theFieldP));
|
||||
break;
|
||||
}
|
||||
case kPacketNumField:
|
||||
{
|
||||
::memcpy(&sInt64Val, theFieldP, sizeof(sInt64Val));
|
||||
fPacketNumber = (UInt64)OS::NetworkToHostSInt64(sInt64Val);
|
||||
break;
|
||||
}
|
||||
case kSeqNumField:
|
||||
{
|
||||
|
||||
::memcpy(&uInt16Val, theFieldP, sizeof(uInt16Val));
|
||||
fSeqNum = ntohs(uInt16Val);
|
||||
break;
|
||||
}
|
||||
case kMediaDataField:
|
||||
{
|
||||
fMediaDataP = theFieldP;
|
||||
fMediaDataLen = theFieldLen;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Skip onto the next field
|
||||
theFieldP += theFieldLen;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
UInt8* RTPMetaInfoPacket::MakeRTPPacket(UInt32* outPacketLen)
|
||||
{
|
||||
if (fMediaDataP == NULL)
|
||||
return NULL;
|
||||
|
||||
//
|
||||
// Just move the RTP header to right before the media data.
|
||||
::memmove(fMediaDataP - 12, fPacketBuffer, 12);
|
||||
|
||||
//
|
||||
// Report the length of the resulting RTP packet
|
||||
if (outPacketLen != NULL)
|
||||
*outPacketLen = fMediaDataLen + 12;
|
||||
|
||||
return fMediaDataP - 12;
|
||||
}
|
||||
|
||||
|
148
RTPMetaInfoLib/RTPMetaInfoPacket.h
Normal file
148
RTPMetaInfoLib/RTPMetaInfoPacket.h
Normal file
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* Copyright (c) 1999-2008 Apple Inc. All Rights Reserved.
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
*
|
||||
*/
|
||||
//
|
||||
// RTPMetaInfoPacket.h:
|
||||
// Some defs for RTP-Meta-Info payloads. This class also parses RTP meta info packets
|
||||
|
||||
#ifndef __QTRTP_META_INFO_PACKET_H__
|
||||
#define __QTRTP_META_INFO_PACKET_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "SafeStdLib.h"
|
||||
#include "OSHeaders.h"
|
||||
#include "StrPtrLen.h"
|
||||
|
||||
class RTPMetaInfoPacket
|
||||
{
|
||||
public:
|
||||
|
||||
//
|
||||
// RTP Meta Info Fields
|
||||
|
||||
enum
|
||||
{
|
||||
kPacketPosField = 0, //TW0_CHARS_TO_INT('p', 'p'),
|
||||
kTransTimeField = 1, //TW0_CHARS_TO_INT('t', 't'),
|
||||
kFrameTypeField = 2, //TW0_CHARS_TO_INT('f', 't'),
|
||||
kPacketNumField = 3, //TW0_CHARS_TO_INT('p', 'n'),
|
||||
kSeqNumField = 4, //TW0_CHARS_TO_INT('s', 'q'),
|
||||
kMediaDataField = 5, //TW0_CHARS_TO_INT('m', 'd'),
|
||||
|
||||
kIllegalField = 6,
|
||||
kNumFields = 6
|
||||
};
|
||||
typedef UInt16 FieldIndex;
|
||||
|
||||
//
|
||||
// Types
|
||||
|
||||
typedef UInt16 FieldName;
|
||||
typedef SInt32 FieldID;
|
||||
|
||||
//
|
||||
// Special field IDs
|
||||
enum
|
||||
{
|
||||
kUncompressed = -1, // No field ID (not a compressed field)
|
||||
kFieldNotUsed = -2 // This field is not being used
|
||||
};
|
||||
|
||||
//
|
||||
// Routine that converts the above enum items into real field names
|
||||
static FieldName GetFieldNameForIndex(FieldIndex inIndex) { return kFieldNameMap[inIndex]; }
|
||||
static FieldIndex GetFieldIndexForName(FieldName inName);
|
||||
|
||||
//
|
||||
// Routine that constructs a standard FieldID Array out of a x-RTP-Meta-Info header
|
||||
static void ConstructFieldIDArrayFromHeader(StrPtrLen* inHeader, FieldID* ioFieldIDArray);
|
||||
|
||||
//
|
||||
// Values for the Frame Type Field
|
||||
enum
|
||||
{
|
||||
kUnknownFrameType = 0,
|
||||
kKeyFrameType = 1,
|
||||
kBFrameType = 2,
|
||||
kPFrameType = 3
|
||||
};
|
||||
typedef UInt16 FrameTypeField;
|
||||
|
||||
|
||||
//
|
||||
// CONSTRUCTOR
|
||||
|
||||
RTPMetaInfoPacket() : fPacketBuffer(NULL),
|
||||
fPacketLen(0),
|
||||
fTransmitTime(0),
|
||||
fFrameType(kUnknownFrameType),
|
||||
fPacketNumber(0),
|
||||
fPacketPosition(0),
|
||||
fMediaDataP(NULL),
|
||||
fMediaDataLen(0),
|
||||
fSeqNum(0) {}
|
||||
~RTPMetaInfoPacket() {}
|
||||
|
||||
//
|
||||
// Call this to parse the RTP-Meta-Info packet.
|
||||
// Pass in an array of FieldIDs, make sure it is kNumFields in length.
|
||||
// This function will use the array as a guide to tell which field IDs in the
|
||||
// packet refer to which fields.
|
||||
Bool16 ParsePacket(UInt8* inPacketBuffer, UInt32 inPacketLen, FieldID* inFieldIDArray);
|
||||
|
||||
//
|
||||
// Call this if you would like to rewrite the Meta-Info packet
|
||||
// as a normal RTP packet (strip off the extensions). Note that
|
||||
// this will overwrite data in the buffer!
|
||||
// Returns a pointer to the new RTP packet, and its length
|
||||
UInt8* MakeRTPPacket(UInt32* outPacketLen);
|
||||
|
||||
//
|
||||
// Field Accessors
|
||||
SInt64 GetTransmitTime() { return fTransmitTime; }
|
||||
FrameTypeField GetFrameType() { return fFrameType; }
|
||||
UInt64 GetPacketNumber() { return fPacketNumber; }
|
||||
UInt64 GetPacketPosition() { return fPacketPosition; }
|
||||
UInt8* GetMediaDataP() { return fMediaDataP; }
|
||||
UInt32 GetMediaDataLen() { return fMediaDataLen; }
|
||||
UInt16 GetSeqNum() { return fSeqNum; }
|
||||
|
||||
private:
|
||||
|
||||
UInt8* fPacketBuffer;
|
||||
UInt32 fPacketLen;
|
||||
|
||||
SInt64 fTransmitTime;
|
||||
FrameTypeField fFrameType;
|
||||
UInt64 fPacketNumber;
|
||||
UInt64 fPacketPosition;
|
||||
UInt8* fMediaDataP;
|
||||
UInt32 fMediaDataLen;
|
||||
UInt16 fSeqNum;
|
||||
|
||||
static const FieldName kFieldNameMap[];
|
||||
static const UInt32 kFieldLengthValidator[];
|
||||
};
|
||||
|
||||
#endif // __QTRTP_META_INFO_PACKET_H__
|
Loading…
Add table
Add a link
Reference in a new issue