-
Notifications
You must be signed in to change notification settings - Fork 24
/
rtcp.c
108 lines (100 loc) · 3.28 KB
/
rtcp.c
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* rtcp.c: SAT>IP plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include "config.h"
#include "common.h"
#include "log.h"
#include "rtcp.h"
cSatipRtcp::cSatipRtcp(cSatipTunerIf &tunerP)
: tunerM(tunerP),
bufferLenM(eApplicationMaxSizeB),
bufferM(MALLOC(unsigned char, bufferLenM))
{
debug1("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
if (bufferM)
memset(bufferM, 0, bufferLenM);
else
error("Cannot create RTCP buffer! [device %d]", tunerM.GetId());
}
cSatipRtcp::~cSatipRtcp()
{
debug1("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
FREE_POINTER(bufferM);
}
int cSatipRtcp::GetFd(void)
{
debug16("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
return Fd();
}
int cSatipRtcp::GetApplicationOffset(unsigned char *bufferP, int *lengthP)
{
debug16("%s (%d) [device %d]", __PRETTY_FUNCTION__, lengthP ? *lengthP : -1, tunerM.GetId());
if (!lengthP)
return -1;
int offset = 0;
int total = *lengthP;
while (total > 0) {
// Version
unsigned int v = (bufferP[offset] >> 6) & 0x03;
// Padding
//unsigned int p = (bufferP[offset] >> 5) & 0x01;
// Subtype
//unsigned int st = bufferP[offset] & 0x1F;
// Payload type
unsigned int pt = bufferP[offset + 1] & 0xFF;
// Length
unsigned int length = ((bufferP[offset + 2] & 0xFF) << 8) | (bufferP[offset + 3] & 0xFF);
// Convert it to bytes
length = (length + 1) * 4;
// V=2, APP = 204
if ((v == 2) && (pt == 204)) {
// SSCR/CSCR
//unsigned int ssrc = ((bufferP[offset + 4] & 0xFF) << 24) | ((bufferP[offset + 5] & 0xFF) << 16) |
// ((bufferP[offset + 6] & 0xFF) << 8) | (bufferP[offset + 7] & 0xFF);
// Name
if ((bufferP[offset + 8] == 'S') && (bufferP[offset + 9] == 'E') &&
(bufferP[offset + 10] == 'S') && (bufferP[offset + 11] == '1')) {
// Identifier
//unsigned int id = ((bufferP[offset + 12] & 0xFF) << 8) | (bufferP[offset + 13] & 0xFF);
// String length
int string_length = ((bufferP[offset + 14] & 0xFF) << 8) | (bufferP[offset + 15] & 0xFF);
if (string_length > 0) {
*lengthP = string_length;
return (offset + 16);
}
}
}
offset += length;
total -= length;
}
*lengthP = 0;
return -1;
}
void cSatipRtcp::Process(void)
{
debug16("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
if (bufferM) {
int length;
while ((length = Read(bufferM, bufferLenM)) > 0) {
int offset = GetApplicationOffset(bufferM, &length);
if (offset >= 0)
tunerM.ProcessApplicationData(bufferM + offset, length);
}
}
}
void cSatipRtcp::Process(unsigned char *dataP, int lengthP)
{
debug16("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
if (dataP && lengthP > 0) {
int offset = GetApplicationOffset(dataP, &lengthP);
if (offset >= 0)
tunerM.ProcessApplicationData(dataP + offset, lengthP);
}
}
cString cSatipRtcp::ToString(void) const
{
return cString::sprintf("RTCP [device %d]", tunerM.GetId());
}