Amazon Kinesis Webrtc C SDK
RtpPacket.h
Go to the documentation of this file.
1 /*******************************************
2 RTP Packet include file
3 *******************************************/
4 #ifndef __KINESIS_VIDEO_WEBRTC_CLIENT_RTP_RTPPACKET_H
5 #define __KINESIS_VIDEO_WEBRTC_CLIENT_RTP_RTPPACKET_H
6 
7 #pragma once
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 #define MIN_HEADER_LENGTH 12
14 #define VERSION_SHIFT 6
15 #define VERSION_MASK 0x3
16 #define PADDING_SHIFT 5
17 #define PADDING_MASK 0x1
18 #define EXTENSION_SHIFT 4
19 #define EXTENSION_MASK 0x1
20 #define CSRC_COUNT_MASK 0xF
21 #define MARKER_SHIFT 7
22 #define MARKER_MASK 0x1
23 #define PAYLOAD_TYPE_MASK 0x7F
24 #define SEQ_NUMBER_OFFSET 2
25 #define TIMESTAMP_OFFSET 4
26 #define SSRC_OFFSET 8
27 #define CSRC_OFFSET 12
28 #define CSRC_LENGTH 4
29 
30 #define RTP_HEADER_LEN(pRtpPacket) \
31  (12 + (pRtpPacket)->header.csrcCount * CSRC_LENGTH + ((pRtpPacket)->header.extension ? 4 + (pRtpPacket)->header.extensionLength : 0))
32 
33 #define RTP_GET_RAW_PACKET_SIZE(pRtpPacket) (RTP_HEADER_LEN(pRtpPacket) + ((pRtpPacket)->payloadLength))
34 
35 #define GET_UINT16_SEQ_NUM(seqIndex) ((UINT16) ((seqIndex) % (MAX_UINT16 + 1)))
36 
37 /*
38  *
39  0 1 2 3
40  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
41  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42  | 0xBE | 0xDE | length=1 |
43  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44  | ID | L=1 |transport-wide sequence number | zero padding |
45  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46  */
47 // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
48 #define TWCC_EXT_PROFILE 0xBEDE
49 #define TWCC_PAYLOAD(extId, sequenceNum) htonl((((extId) & 0xfu) << 28u) | (1u << 24u) | ((UINT32) (sequenceNum) << 8u))
50 #define TWCC_SEQNUM(extPayload) ((UINT16) getUnalignedInt16BigEndian(extPayload + 1))
51 
52 typedef STATUS (*DepayRtpPayloadFunc)(PBYTE, UINT32, PBYTE, PUINT32, PBOOL);
53 
54 /*
55  * 0 1 2 3
56  * 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
57  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58  * |V=2|P|X| CC |M| PT | sequence number |
59  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60  * | timestamp |
61  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62  * | synchronization source (SSRC) identifier |
63  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64  * | contributing source (CSRC[0..15]) identifiers |
65  * | .... |
66  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67  */
68 
70  UINT8 version;
71  BOOL padding;
72  BOOL extension;
73  BOOL marker;
74  UINT8 csrcCount;
75  UINT8 payloadType;
77  UINT32 timestamp;
78  UINT32 ssrc;
79  PUINT32 csrcArray;
83 };
84 typedef struct __RtpPacketHeader RtpPacketHeader;
86 
87 struct __Payloads {
89  UINT32 payloadLength;
94 };
95 typedef struct __Payloads PayloadArray;
97 
98 typedef struct __RtpPacket RtpPacket;
99 struct __RtpPacket {
101  PBYTE payload;
103  PBYTE pRawPacket;
105  // used for jitterBufferDelay calculation
106  UINT64 receivedTime;
107  // used for twcc time delta calculation
108  UINT64 sentTime;
109 };
111 
112 STATUS createRtpPacket(UINT8, BOOL, BOOL, UINT8, BOOL, UINT8, UINT16, UINT32, UINT32, PUINT32, UINT16, UINT32, PBYTE, PBYTE, UINT32, PRtpPacket*);
113 STATUS setRtpPacket(UINT8, BOOL, BOOL, UINT8, BOOL, UINT8, UINT16, UINT32, UINT32, PUINT32, UINT16, UINT32, PBYTE, PBYTE, UINT32, PRtpPacket);
114 STATUS freeRtpPacket(PRtpPacket*);
115 STATUS createRtpPacketFromBytes(PBYTE, UINT32, PRtpPacket*);
116 STATUS constructRetransmitRtpPacketFromBytes(PBYTE, UINT32, UINT16, UINT8, UINT32, PRtpPacket*);
117 STATUS setRtpPacketFromBytes(PBYTE, UINT32, PRtpPacket);
118 STATUS createBytesFromRtpPacket(PRtpPacket, PBYTE, PUINT32);
119 STATUS setBytesFromRtpPacket(PRtpPacket, PBYTE, UINT32);
120 STATUS constructRtpPackets(PPayloadArray, UINT8, UINT16, UINT32, UINT32, PRtpPacket, UINT32);
121 
122 #ifdef __cplusplus
123 }
124 #endif
125 #endif //__KINESIS_VIDEO_WEBRTC_CLIENT_RTP_RTPPACKET_H
PayloadArray * PPayloadArray
Definition: RtpPacket.h:96
RtpPacket * PRtpPacket
Definition: RtpPacket.h:110
STATUS(* DepayRtpPayloadFunc)(PBYTE, UINT32, PBYTE, PUINT32, PBOOL)
Definition: RtpPacket.h:52
STATUS createBytesFromRtpPacket(PRtpPacket, PBYTE, PUINT32)
Definition: RtpPacket.c:216
STATUS setBytesFromRtpPacket(PRtpPacket, PBYTE, UINT32)
Definition: RtpPacket.c:244
STATUS createRtpPacket(UINT8, BOOL, BOOL, UINT8, BOOL, UINT8, UINT16, UINT32, UINT32, PUINT32, UINT16, UINT32, PBYTE, PBYTE, UINT32, PRtpPacket *)
Definition: RtpPacket.c:5
STATUS freeRtpPacket(PRtpPacket *)
Definition: RtpPacket.c:66
STATUS setRtpPacket(UINT8, BOOL, BOOL, UINT8, BOOL, UINT8, UINT16, UINT32, UINT32, PUINT32, UINT16, UINT32, PBYTE, PBYTE, UINT32, PRtpPacket)
Definition: RtpPacket.c:31
STATUS constructRtpPackets(PPayloadArray, UINT8, UINT16, UINT32, UINT32, PRtpPacket, UINT32)
Definition: RtpPacket.c:325
STATUS constructRetransmitRtpPacketFromBytes(PBYTE, UINT32, UINT16, UINT8, UINT32, PRtpPacket *)
Definition: RtpPacket.c:116
STATUS setRtpPacketFromBytes(PBYTE, UINT32, PRtpPacket)
Definition: RtpPacket.c:160
RtpPacketHeader * PRtpPacketHeader
Definition: RtpPacket.h:85
STATUS createRtpPacketFromBytes(PBYTE, UINT32, PRtpPacket *)
Definition: RtpPacket.c:87
Definition: RtpPacket.h:87
UINT32 payloadLength
Definition: RtpPacket.h:89
UINT32 maxPayloadSubLenSize
Definition: RtpPacket.h:93
UINT32 payloadSubLenSize
Definition: RtpPacket.h:92
UINT32 maxPayloadLength
Definition: RtpPacket.h:90
PBYTE payloadBuffer
Definition: RtpPacket.h:88
PUINT32 payloadSubLength
Definition: RtpPacket.h:91
Definition: RtpPacket.h:69
PUINT32 csrcArray
Definition: RtpPacket.h:79
UINT32 ssrc
Definition: RtpPacket.h:78
UINT8 csrcCount
Definition: RtpPacket.h:74
UINT32 timestamp
Definition: RtpPacket.h:77
UINT8 payloadType
Definition: RtpPacket.h:75
UINT16 extensionProfile
Definition: RtpPacket.h:80
BOOL marker
Definition: RtpPacket.h:73
UINT8 version
Definition: RtpPacket.h:70
PBYTE extensionPayload
Definition: RtpPacket.h:81
BOOL extension
Definition: RtpPacket.h:72
UINT32 extensionLength
Definition: RtpPacket.h:82
BOOL padding
Definition: RtpPacket.h:71
UINT16 sequenceNumber
Definition: RtpPacket.h:76
Definition: RtpPacket.h:99
PBYTE payload
Definition: RtpPacket.h:101
PBYTE pRawPacket
Definition: RtpPacket.h:103
UINT32 rawPacketLength
Definition: RtpPacket.h:104
RtpPacketHeader header
Definition: RtpPacket.h:100
UINT64 sentTime
Definition: RtpPacket.h:108
UINT64 receivedTime
Definition: RtpPacket.h:106
UINT32 payloadLength
Definition: RtpPacket.h:102