2014-11-14 21:28:27 +01:00
|
|
|
/*
|
|
|
|
* rtcp.c: SAT>IP plugin for the Video Disk Recorder
|
|
|
|
*
|
|
|
|
* See the README file for copyright information and how to reach the author.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-12-03 18:57:23 +01:00
|
|
|
#include "config.h"
|
2014-11-14 21:28:27 +01:00
|
|
|
#include "common.h"
|
2014-12-05 22:14:40 +01:00
|
|
|
#include "log.h"
|
2014-11-14 21:28:27 +01:00
|
|
|
#include "rtcp.h"
|
|
|
|
|
2014-12-13 22:15:58 +01:00
|
|
|
cSatipRtcp::cSatipRtcp(cSatipTunerIf &tunerP)
|
2014-11-16 16:02:30 +01:00
|
|
|
: tunerM(tunerP),
|
2014-12-13 22:15:58 +01:00
|
|
|
bufferLenM(eApplicationMaxSizeB),
|
2014-11-14 21:28:27 +01:00
|
|
|
bufferM(MALLOC(unsigned char, bufferLenM))
|
|
|
|
{
|
2014-12-13 22:15:58 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
|
2014-11-14 21:28:27 +01:00
|
|
|
if (bufferM)
|
|
|
|
memset(bufferM, 0, bufferLenM);
|
|
|
|
else
|
2014-12-13 22:15:58 +01:00
|
|
|
error("Cannot create RTCP buffer! [device %d]", tunerM.GetId());
|
2014-11-14 21:28:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cSatipRtcp::~cSatipRtcp()
|
|
|
|
{
|
2014-12-06 16:02:45 +01:00
|
|
|
debug1("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
|
2015-01-21 21:40:24 +01:00
|
|
|
FREE_POINTER(bufferM);
|
2014-11-14 21:28:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int cSatipRtcp::GetFd(void)
|
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
|
2014-11-14 21:28:27 +01:00
|
|
|
return Fd();
|
|
|
|
}
|
|
|
|
|
2014-11-16 09:31:34 +01:00
|
|
|
int cSatipRtcp::GetApplicationOffset(int *lengthP)
|
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s (%d) [device %d]", __PRETTY_FUNCTION__, *lengthP, tunerM.GetId());
|
2014-11-16 09:31:34 +01:00
|
|
|
if (!lengthP)
|
|
|
|
return -1;
|
|
|
|
int offset = 0;
|
|
|
|
int total = *lengthP;
|
|
|
|
while (total > 0) {
|
|
|
|
// Version
|
|
|
|
unsigned int v = (bufferM[offset] >> 6) & 0x03;
|
|
|
|
// Padding
|
|
|
|
//unsigned int p = (bufferM[offset] >> 5) & 0x01;
|
|
|
|
// Subtype
|
|
|
|
//unsigned int st = bufferM[offset] & 0x1F;
|
|
|
|
// Payload type
|
|
|
|
unsigned int pt = bufferM[offset + 1] & 0xFF;
|
2015-01-14 16:58:13 +01:00
|
|
|
// Length
|
2014-11-16 09:31:34 +01:00
|
|
|
unsigned int length = ((bufferM[offset + 2] & 0xFF) << 8) | (bufferM[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 = ((bufferM[offset + 4] & 0xFF) << 24) | ((bufferM[offset + 5] & 0xFF) << 16) |
|
|
|
|
// ((bufferM[offset + 6] & 0xFF) << 8) | (bufferM[offset + 7] & 0xFF);
|
|
|
|
// Name
|
|
|
|
if ((bufferM[offset + 8] == 'S') && (bufferM[offset + 9] == 'E') &&
|
|
|
|
(bufferM[offset + 10] == 'S') && (bufferM[offset + 11] == '1')) {
|
|
|
|
// Identifier
|
|
|
|
//unsigned int id = ((bufferM[offset + 12] & 0xFF) << 8) | (bufferM[offset + 13] & 0xFF);
|
|
|
|
// String length
|
|
|
|
int string_length = ((bufferM[offset + 14] & 0xFF) << 8) | (bufferM[offset + 15] & 0xFF);
|
|
|
|
if (string_length > 0) {
|
|
|
|
*lengthP = string_length;
|
|
|
|
return (offset + 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
offset += length;
|
|
|
|
total -= length;
|
|
|
|
}
|
|
|
|
*lengthP = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-25 21:04:34 +01:00
|
|
|
void cSatipRtcp::Process(void)
|
2014-11-14 21:28:27 +01:00
|
|
|
{
|
2014-12-14 16:45:55 +01:00
|
|
|
debug16("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
|
2014-11-14 21:28:27 +01:00
|
|
|
if (bufferM) {
|
2014-11-29 14:37:21 +01:00
|
|
|
int length;
|
|
|
|
while ((length = Read(bufferM, bufferLenM)) > 0) {
|
|
|
|
int offset = GetApplicationOffset(&length);
|
|
|
|
if (offset >= 0)
|
|
|
|
tunerM.ProcessApplicationData(bufferM + offset, length);
|
|
|
|
}
|
|
|
|
if (errno != EAGAIN && errno != EWOULDBLOCK)
|
|
|
|
error("Error %d reading in %s", errno, *ToString());
|
2014-11-14 21:28:27 +01:00
|
|
|
}
|
|
|
|
}
|
2014-11-29 13:44:30 +01:00
|
|
|
|
|
|
|
cString cSatipRtcp::ToString(void) const
|
|
|
|
{
|
|
|
|
return cString::sprintf("RTCP [device %d]", tunerM.GetId());
|
|
|
|
}
|