-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathrtp_packet.cpp
More file actions
70 lines (61 loc) · 2.36 KB
/
rtp_packet.cpp
File metadata and controls
70 lines (61 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "rtp_packet.h"
#include "bits.h"
#include <assert.h>
#include <WinSock2.h>
namespace media
{
rtp_packet::rtp_packet(void* buffer, size_t size)
: header((rtp_header*)buffer), packet_size(size)
{
// Make sure size is at least large enough for the header, including
// CSRC list.
assert(size >= (sizeof(rtp_header) + 4 * get_CC()));
csrc = (uint32_t*)(header + 1);
}
int rtp_packet::get_V() { return bf_get(header->V_P_X_CC, 6, 2); }
bool rtp_packet::get_P() { return bit_get(header->V_P_X_CC, 5); }
bool rtp_packet::get_X() { return bit_get(header->V_P_X_CC, 4); }
int rtp_packet::get_CC() { return bf_get(header->V_P_X_CC, 0, 4); }
bool rtp_packet::get_M() { return bit_get(header->M_PT, 7); }
int rtp_packet::get_PT() { return bf_get(header->M_PT, 0, 7); }
uint16_t rtp_packet::get_sequence_number() { return ntohs(header->sequence_number); }
int rtp_packet::get_timestamp() { return ntohl(header->timestamp); }
int rtp_packet::get_ssrc() { return ntohl(header->ssrc); }
int rtp_packet::get_csrc(int index)
{
assert(index < get_CC());
return ntohl(csrc[index]);
}
void rtp_packet::set_V(int v) { bf_set(header->V_P_X_CC, v, 6, 2); }
void rtp_packet::set_P(bool p) { bit_set(header->V_P_X_CC, 5); }
void rtp_packet::set_X(bool x) { bit_set(header->V_P_X_CC, 4); }
void rtp_packet::set_CC(int cc) { bf_set(header->V_P_X_CC, cc, 0, 4); }
void rtp_packet::set_M(bool m) { bit_set(header->M_PT, 7); }
void rtp_packet::set_PT(int pt) { bf_set(header->M_PT, pt, 0, 7); }
void rtp_packet::set_sequence_number(uint16_t seq) { header->sequence_number = htons(seq); }
void rtp_packet::set_timestamp(int timestamp) { header->timestamp = htonl(timestamp); }
void rtp_packet::set_ssrc(int src) { header->ssrc = htonl(src); }
void rtp_packet::set_csrc(int index, int src)
{
assert(index < get_CC());
csrc[index] = htonl(src);
}
void* rtp_packet::data()
{
return header;
}
size_t rtp_packet::size()
{
return packet_size;
}
size_t rtp_packet::payload_size()
{
int ret = packet_size - sizeof(rtp_header) - 4 * get_CC();
if (get_P())
{
char* data = (char*)header;
ret -= data[packet_size - 1];
}
return ret;
}
}