mirror of https://github.com/tongzx/nt5src
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
215 lines
9.9 KiB
215 lines
9.9 KiB
/////////////////////////////////////////////////////////////////////////////
|
|
// INTEL Corporation Proprietary Information
|
|
// This listing is supplied under the terms of a license agreement with Intel
|
|
// Corporation and many not be copied nor disclosed except in accordance
|
|
// with the terms of that agreement.
|
|
// Copyright (c) 1995, 1996 Intel Corporation.
|
|
//
|
|
//
|
|
// Module Name: rtpclass.h
|
|
// Environment: MSVC 4.0, OLE 2
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef RTPCLASS_H
|
|
#define RTPCLASS_H
|
|
|
|
#ifdef _DEBUG
|
|
#include <rtp.h>
|
|
//#include "..\..\rrcm\rrcminc\rrcm.h"
|
|
#endif
|
|
|
|
//Note: RTP header data generated by PPM are in network order
|
|
|
|
class RTP_Header {
|
|
public:
|
|
enum { fixed_header_size = 12 };
|
|
|
|
private:
|
|
#if defined(_DEBUG) && !defined(MICROSOFT) && defined(_0_)
|
|
union {
|
|
unsigned char bytes[fixed_header_size];
|
|
RTP_HDR_T header; /* This is here for convenience in debugging only */
|
|
};
|
|
#else
|
|
unsigned char bytes[fixed_header_size];
|
|
#endif
|
|
|
|
public:
|
|
int v() const { return (bytes[0] >> 6) & 3; }
|
|
void set_v(int v) { bytes[0] = (bytes[0] & 0x3f) | ((v & 3) << 6); }
|
|
|
|
int p() const { return (bytes[0] >> 5) & 1; }
|
|
void set_p(int v) { bytes[0] = (bytes[0] & 0xdf) | ((v & 1) << 5); }
|
|
|
|
int x() const { return (bytes[0] >> 4) & 1; }
|
|
void set_x(int v) { bytes[0] = (bytes[0] & 0xef) | ((v & 1) << 4); }
|
|
|
|
int cc() const { return bytes[0] & 0x0f; }
|
|
void set_cc(int v) { bytes[0] = (bytes[0] & 0xf0) | (v & 0x0f); }
|
|
|
|
int m() const { return (bytes[1] >> 7) & 1; }
|
|
void set_m(int v) { bytes[1] = (bytes[1] & 0x7f) | ((v & 1) << 7); }
|
|
|
|
int pt() const { return (bytes[1] & 0x7f); }
|
|
void set_pt(int v) { bytes[1] = (bytes[1] & 0x80) | (v & 0x7f); }
|
|
|
|
unsigned short seq() const { return bytes[2] << 8 | bytes[3]; };
|
|
void set_seq(unsigned short v) { bytes[2] = (unsigned char)(v >> 8);
|
|
bytes[3] = (unsigned char)(v);
|
|
}
|
|
|
|
unsigned long ts() const { return (unsigned long)bytes[4] << 24
|
|
| (unsigned long)bytes[5] << 16
|
|
| (unsigned long)bytes[6] << 8
|
|
| (unsigned long)bytes[7];
|
|
}
|
|
void set_ts(unsigned long v) { bytes[4] = (unsigned char)(v >> 24);
|
|
bytes[5] = (unsigned char)(v >> 16);
|
|
bytes[6] = (unsigned char)(v >> 8);
|
|
bytes[7] = (unsigned char)(v);
|
|
}
|
|
|
|
unsigned long ssrc() const { return (unsigned long)bytes[8] << 24
|
|
| (unsigned long)bytes[9] << 16
|
|
| (unsigned long)bytes[10] << 8
|
|
| (unsigned long)bytes[11];
|
|
}
|
|
void set_ssrc(unsigned long v) { bytes[8] = (unsigned char)(v >> 24);
|
|
bytes[9] = (unsigned char)(v >> 16);
|
|
bytes[10] = (unsigned char)(v >> 8);
|
|
bytes[11] = (unsigned char)(v);
|
|
}
|
|
|
|
|
|
//refer to section 5.3.1 of the RTP spec to understand the RTP Extension header.
|
|
int header_size() const
|
|
{
|
|
int NumCSRCBytes = cc() * 4;
|
|
int NumExtensionBytes = 0;
|
|
|
|
if ( x() == 1 )
|
|
{
|
|
//tmp points to the first word of the extended header.
|
|
//bytes 2 and 3 of this word contain the length of the extended header
|
|
//in 32-bit words (not counting the first word)
|
|
const unsigned char *tmp = bytes + fixed_header_size + NumCSRCBytes;
|
|
unsigned short x_len = ((unsigned short)tmp[2] << 8) | (unsigned short)tmp[3];
|
|
|
|
//number of words plus the length field itself.
|
|
NumExtensionBytes = (x_len + 1) * 4;
|
|
}
|
|
|
|
//the fixed header plus the csrc list plus the extended header
|
|
return ( fixed_header_size + NumCSRCBytes + NumExtensionBytes );
|
|
}
|
|
};
|
|
|
|
class RTCPSR_Header {
|
|
public:
|
|
enum { fixed_header_size = 28 };
|
|
|
|
private:
|
|
unsigned char bytes[fixed_header_size];
|
|
|
|
public:
|
|
int v() const { return (bytes[0] >> 6) & 3; }
|
|
void set_v(int v) { bytes[0] = (bytes[0] & 0x3f) | ((v & 3) << 6); }
|
|
|
|
int p() const { return (bytes[0] >> 5) & 1; }
|
|
void set_p(int v) { bytes[0] = (bytes[0] & 0xdf) | ((v & 1) << 5); }
|
|
|
|
int cc() const { return bytes[0] & 0x1f; }
|
|
void set_cc(int v) { bytes[0] = (bytes[0] & 0xe0) | (v & 0x1f); }
|
|
|
|
int pt() const { return (bytes[1]); }
|
|
void set_pt(int v) { bytes[1] = (unsigned char)v; }
|
|
|
|
unsigned short length() const { return bytes[2] << 8 | bytes[3]; };
|
|
void set_length(unsigned short v) { bytes[2] = (unsigned char)(v >> 8);
|
|
bytes[3] = (unsigned char)(v);
|
|
}
|
|
|
|
unsigned long ssrc() const { return (unsigned long)bytes[4] << 24
|
|
| (unsigned long)bytes[5] << 16
|
|
| (unsigned long)bytes[6] << 8
|
|
| (unsigned long)bytes[7];
|
|
}
|
|
void set_ssrc(unsigned long v) { bytes[4] = (unsigned char)(v >> 24);
|
|
bytes[5] = (unsigned char)(v >> 16);
|
|
bytes[6] = (unsigned char)(v >> 8);
|
|
bytes[7] = (unsigned char)(v);
|
|
}
|
|
|
|
unsigned long ntp_mid() const { return (unsigned long)bytes[10] << 24
|
|
| (unsigned long)bytes[11] << 16
|
|
| (unsigned long)bytes[12] << 8
|
|
| (unsigned long)bytes[13];
|
|
}
|
|
void set_ntp_mid(unsigned long v) { bytes[10] = (unsigned char)(v >> 24);
|
|
bytes[11] = (unsigned char)(v >> 16);
|
|
bytes[12] = (unsigned char)(v >> 8);
|
|
bytes[13] = (unsigned char)(v);
|
|
}
|
|
|
|
unsigned long ntp_sec() const { return (unsigned long)bytes[8] << 24
|
|
| (unsigned long)bytes[9] << 16
|
|
| (unsigned long)bytes[10] << 8
|
|
| (unsigned long)bytes[11];
|
|
}
|
|
void set_ntp_sec(unsigned long v) { bytes[8] = (unsigned char)(v >> 24);
|
|
bytes[9] = (unsigned char)(v >> 16);
|
|
bytes[10] = (unsigned char)(v >> 8);
|
|
bytes[11] = (unsigned char)(v);
|
|
}
|
|
|
|
unsigned long ntp_frac() const { return (unsigned long)bytes[12] << 24
|
|
| (unsigned long)bytes[13] << 16
|
|
| (unsigned long)bytes[14] << 8
|
|
| (unsigned long)bytes[15];
|
|
}
|
|
void set_ntp_frac(unsigned long v) { bytes[12] = (unsigned char)(v >> 24);
|
|
bytes[13] = (unsigned char)(v >> 16);
|
|
bytes[14] = (unsigned char)(v >> 8);
|
|
bytes[15] = (unsigned char)(v);
|
|
}
|
|
|
|
unsigned long ts() const { return (unsigned long)bytes[16] << 24
|
|
| (unsigned long)bytes[17] << 16
|
|
| (unsigned long)bytes[18] << 8
|
|
| (unsigned long)bytes[19];
|
|
}
|
|
void set_ts(unsigned long v) { bytes[16] = (unsigned char)(v >> 24);
|
|
bytes[17] = (unsigned char)(v >> 16);
|
|
bytes[18] = (unsigned char)(v >> 8);
|
|
bytes[19] = (unsigned char)(v);
|
|
}
|
|
|
|
unsigned long packets() const { return (unsigned long)bytes[20] << 24
|
|
| (unsigned long)bytes[21] << 16
|
|
| (unsigned long)bytes[22] << 8
|
|
| (unsigned long)bytes[23];
|
|
}
|
|
void set_packets(unsigned long v) { bytes[20] = (unsigned char)(v >> 24);
|
|
bytes[21] = (unsigned char)(v >> 16);
|
|
bytes[22] = (unsigned char)(v >> 8);
|
|
bytes[23] = (unsigned char)(v);
|
|
}
|
|
|
|
unsigned long octets() const { return (unsigned long)bytes[24] << 24
|
|
| (unsigned long)bytes[25] << 16
|
|
| (unsigned long)bytes[26] << 8
|
|
| (unsigned long)bytes[27];
|
|
}
|
|
void set_octets(unsigned long v) { bytes[24] = (unsigned char)(v >> 24);
|
|
bytes[25] = (unsigned char)(v >> 16);
|
|
bytes[26] = (unsigned char)(v >> 8);
|
|
bytes[27] = (unsigned char)(v);
|
|
}
|
|
|
|
int header_size() const
|
|
{
|
|
return length();
|
|
}
|
|
};
|
|
|
|
#endif
|