Skip to content

Commit

Permalink
Update packet type functions
Browse files Browse the repository at this point in the history
  • Loading branch information
moninom1 committed Jul 11, 2024
1 parent 2a17bd8 commit 21d60c9
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CMake/Dependencies/libkvsrtcp-CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ else()
endif()

ExternalProject_Add(libkvsrtcp
GIT_REPOSITORY https://github.com/moninom1/kvs-rtcp.git
GIT_REPOSITORY git@github.com:moninom1/amazon-kinesis-video-streams-rtcp.git
GIT_TAG wrapper
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/build
CMAKE_ARGS
Expand Down
51 changes: 46 additions & 5 deletions src/source/PeerConnection/Rtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,47 @@
#include "../Include_i.h"
#include "kvsrtcp/rtcp_api.h"

static RtcpPacketType_t getDetailedRtcpPacketType(uint8_t packetType, uint8_t receptionReportCount)
{
RtcpPacketType_t result = RTCP_PACKET_UNKNOWN;

switch (packetType) {
case RTCP_PACKET_TYPE_FIR: {
if (receptionReportCount == 0) {
result = RTCP_PACKET_FIR;
}
} break;

case RTCP_PACKET_TYPE_SENDER_REPORT: {
result = RTCP_PACKET_SENDER_REPORT;
} break;

case RTCP_PACKET_TYPE_RECEIVER_REPORT: {
result = RTCP_PACKET_RECEIVER_REPORT;
} break;

case RTCP_PACKET_TYPE_GENERIC_RTP_FEEDBACK: {
if (receptionReportCount == RTCP_FMT_TRANSPORT_SPECIFIC_FEEDBACK_NACK) {
result = RTCP_PACKET_TRANSPORT_FEEDBACK_NACK;
} else if (receptionReportCount == RTCP_FMT_TRANSPORT_SPECIFIC_FEEDBACK_TWCC) {
result = RTCP_PACKET_TRANSPORT_FEEDBACK_TWCC;
}
} break;

case RTCP_PACKET_TYPE_PAYLOAD_SPECIFIC_FEEDBACK: {
if (receptionReportCount == RTCP_FMT_PAYLOAD_SPECIFIC_FEEDBACK_PLI) {
result = RTCP_PACKET_PAYLOAD_FEEDBACK_PLI;
} else if (receptionReportCount == RTCP_FMT_PAYLOAD_SPECIFIC_FEEDBACK_SLI) {
result = RTCP_PACKET_PAYLOAD_FEEDBACK_SLI;
} else if (receptionReportCount == RTCP_FMT_PAYLOAD_SPECIFIC_FEEDBACK_REMB) {
result = RTCP_PACKET_PAYLOAD_FEEDBACK_REMB;
}
} break;
}

return result;
}

// TODO handle FIR packet https://tools.ietf.org/html/rfc2032#section-5.2.1
static STATUS onRtcpFIRPacket(PRtcpPacket pRtcpPacket, PKvsPeerConnection pKvsPeerConnection)
{
Expand All @@ -18,7 +59,7 @@ static STATUS onRtcpFIRPacket(PRtcpPacket pRtcpPacket, PKvsPeerConnection pKvsPe
rtcpResult = Rtcp_Init(&ctx);
CHK(rtcpResult == RTP_RESULT_OK, convertRtcpErrorCode(rtcpResult));

rtcpPacket.header.packetType = GetRtcpPacketType(pRtcpPacket->header.packetType, pRtcpPacket->header.receptionReportCount);
rtcpPacket.header.packetType = getDetailedRtcpPacketType(pRtcpPacket->header.packetType, pRtcpPacket->header.receptionReportCount);
rtcpPacket.header.receptionReportCount = pRtcpPacket->header.receptionReportCount;
rtcpPacket.pPayload = (const PBYTE) pRtcpPacket->payload;
rtcpPacket.payloadLength = (size_t) pRtcpPacket->payloadLength;
Expand Down Expand Up @@ -58,7 +99,7 @@ STATUS onRtcpSLIPacket(PRtcpPacket pRtcpPacket, PKvsPeerConnection pKvsPeerConne
rtcpResult = Rtcp_Init(&ctx);
CHK(rtcpResult == RTP_RESULT_OK, convertRtcpErrorCode(rtcpResult));

rtcpPacket.header.packetType = GetRtcpPacketType(pRtcpPacket->header.packetType, pRtcpPacket->header.receptionReportCount);
rtcpPacket.header.packetType = getDetailedRtcpPacketType(pRtcpPacket->header.packetType, pRtcpPacket->header.receptionReportCount);
rtcpPacket.header.receptionReportCount = pRtcpPacket->header.receptionReportCount;
rtcpPacket.pPayload = (const PBYTE) pRtcpPacket->payload;
rtcpPacket.payloadLength = (size_t) pRtcpPacket->payloadLength;
Expand Down Expand Up @@ -112,7 +153,7 @@ static STATUS onRtcpSenderReport(PRtcpPacket pRtcpPacket, PKvsPeerConnection pKv

rtcpPacket.pPayload = (const PBYTE) pRtcpPacket->payload;
rtcpPacket.payloadLength = (size_t) pRtcpPacket->payloadLength;
rtcpPacket.header.packetType = GetRtcpPacketType(pRtcpPacket->header.packetType, pRtcpPacket->header.receptionReportCount);
rtcpPacket.header.packetType = getDetailedRtcpPacketType(pRtcpPacket->header.packetType, pRtcpPacket->header.receptionReportCount);
rtcpPacket.header.receptionReportCount = pRtcpPacket->header.receptionReportCount;

rtcpResult = Rtcp_ParseSenderReport(&ctx, &rtcpPacket, &senderReport);
Expand Down Expand Up @@ -167,7 +208,7 @@ static STATUS onRtcpReceiverReport(PRtcpPacket pRtcpPacket, PKvsPeerConnection p

rtcpPacket.pPayload = (const PBYTE) pRtcpPacket->payload;
rtcpPacket.payloadLength = (size_t) pRtcpPacket->payloadLength;
rtcpPacket.header.packetType = GetRtcpPacketType(pRtcpPacket->header.packetType, pRtcpPacket->header.receptionReportCount);
rtcpPacket.header.packetType = getDetailedRtcpPacketType(pRtcpPacket->header.packetType, pRtcpPacket->header.receptionReportCount);
rtcpPacket.header.receptionReportCount = pRtcpPacket->header.receptionReportCount;
receiverReport.numReceptionReports = (size_t) pRtcpPacket->header.receptionReportCount;
if (receiverReport.numReceptionReports > 0) {
Expand Down Expand Up @@ -585,7 +626,7 @@ STATUS onRtcpPLIPacket(PRtcpPacket pRtcpPacket, PKvsPeerConnection pKvsPeerConne
rtcpResult = Rtcp_Init(&ctx);
CHK(rtcpResult == RTP_RESULT_OK, convertRtcpErrorCode(rtcpResult));

rtcpPacket.header.packetType = GetRtcpPacketType(pRtcpPacket->header.packetType, pRtcpPacket->header.receptionReportCount);
rtcpPacket.header.packetType = getDetailedRtcpPacketType(pRtcpPacket->header.packetType, pRtcpPacket->header.receptionReportCount);
rtcpPacket.header.receptionReportCount = pRtcpPacket->header.receptionReportCount;
rtcpPacket.pPayload = (const PBYTE) pRtcpPacket->payload;
rtcpPacket.payloadLength = (size_t) pRtcpPacket->payloadLength;
Expand Down
19 changes: 9 additions & 10 deletions src/source/Rtcp/RtcpPacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
#include "../Include_i.h"
#include "kvsrtcp/rtcp_api.h"

static RTCP_PACKET_TYPE getPacketType( RtcpPacketType_t packetType )
static RTCP_PACKET_TYPE getStandardRtcpPacketType(RtcpPacketType_t packetType)
{
RTCP_PACKET_TYPE ret = 0;

switch( packetType )
{
switch (packetType) {
case RTCP_PACKET_FIR:
ret = RTCP_PACKET_TYPE_FIR;
ret = RTCP_PACKET_TYPE_FIR;
break;

case RTCP_PACKET_SENDER_REPORT:
Expand All @@ -31,9 +30,9 @@ static RTCP_PACKET_TYPE getPacketType( RtcpPacketType_t packetType )
case RTCP_PACKET_PAYLOAD_FEEDBACK_REMB:
ret = RTCP_PACKET_TYPE_PAYLOAD_SPECIFIC_FEEDBACK;
break;
}
}

return ret;
return ret;
}

STATUS setRtcpPacketFromBytes(PBYTE pRawPacket, UINT32 pRawPacketsLen, PRtcpPacket pRtcpPacket)
Expand All @@ -52,9 +51,9 @@ STATUS setRtcpPacketFromBytes(PBYTE pRawPacket, UINT32 pRawPacketsLen, PRtcpPack
CHK(rtcpResult == RTP_RESULT_OK, convertRtcpErrorCode(rtcpResult));
pRtcpPacket->header.version = RTCP_PACKET_VERSION_VAL;
pRtcpPacket->header.receptionReportCount = rtcpPacket.header.receptionReportCount;
pRtcpPacket->header.packetType = getPacketType(rtcpPacket.header.packetType);
pRtcpPacket->header.packetType = getStandardRtcpPacketType(rtcpPacket.header.packetType);
pRtcpPacket->header.packetLength = (UINT32) (rtcpPacket.payloadLength / 4);
pRtcpPacket->payloadLength = (UINT32)(rtcpPacket.payloadLength);
pRtcpPacket->payloadLength = (UINT32) (rtcpPacket.payloadLength);
pRtcpPacket->payload = (PBYTE) rtcpPacket.pPayload;

CleanUp:
Expand Down Expand Up @@ -186,8 +185,8 @@ STATUS rembValueGet(PBYTE pPayload, UINT32 payloadLen, PDOUBLE pMaximumBitRate,
CHK(rtcpResult == RTP_RESULT_OK, convertRtcpErrorCode(rtcpResult));

rtcpPacket.header.packetType = RTCP_PACKET_PAYLOAD_FEEDBACK_REMB;
rtcpPacket.pPayload = (const PBYTE)pPayload;
rtcpPacket.payloadLength = (size_t)payloadLen;
rtcpPacket.pPayload = (const PBYTE) pPayload;
rtcpPacket.payloadLength = (size_t) payloadLen;
rembPacket.pSsrcList = pSsrcList;
rembPacket.ssrcListLength = SIZEOF(pSsrcList) / SIZEOF(UINT32);

Expand Down
8 changes: 8 additions & 0 deletions src/source/Rtcp/RtcpPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ extern "C" {
// is set to 5 seconds.
#define RTCP_FIRST_REPORT_DELAY (3 * HUNDREDS_OF_NANOS_IN_A_SECOND)

#define RTCP_FMT_PAYLOAD_SPECIFIC_FEEDBACK_PLI 1 // https://datatracker.ietf.org/doc/html/rfc4585#section-6.3
#define RTCP_FMT_PAYLOAD_SPECIFIC_FEEDBACK_SLI 2 // https://datatracker.ietf.org/doc/html/rfc4585#section-6.3
#define RTCP_FMT_PAYLOAD_SPECIFIC_FEEDBACK_RPSI 3 // https://datatracker.ietf.org/doc/html/rfc4585#section-6.3
#define RTCP_FMT_PAYLOAD_SPECIFIC_FEEDBACK_REMB 15 // https://datatracker.ietf.org/doc/html/draft-alvestrand-rmcat-remb-03#section-2.2
#define RTCP_FMT_TRANSPORT_SPECIFIC_FEEDBACK_NACK 1 // https://datatracker.ietf.org/doc/html/rfc4585#section-6.2.1
#define RTCP_FMT_TRANSPORT_SPECIFIC_FEEDBACK_TWCC \
15 // https://datatracker.ietf.org/doc/html/draft-holmer-rmcat-transport-wide-cc-extensions-01#section-3.1

typedef enum {
RTCP_PACKET_TYPE_FIR = 192, // https://tools.ietf.org/html/rfc2032#section-5.2.1
RTCP_PACKET_TYPE_SENDER_REPORT = 200,
Expand Down
2 changes: 1 addition & 1 deletion src/source/Rtcp/RtcpUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ STATUS convertRtcpErrorCode(RtcpResult_t rtcpResult)
case RTCP_RESULT_INPUT_PACKET_TOO_SMALL:
retStatus = STATUS_RTCP_INPUT_PACKET_TOO_SMALL;
break;
case RTCP_RESULT_INPUT_REMB_INVALID:
case RTCP_RESULT_INPUT_REMB_PACKET_INVALID:
retStatus = STATUS_RTCP_INPUT_REMB_INVALID;
break;
default:
Expand Down

0 comments on commit 21d60c9

Please sign in to comment.