Skip to content

Commit

Permalink
SDP Attribute Fixes (#2082)
Browse files Browse the repository at this point in the history
* fix nack pli overwrite bug (#2035)

* fix nack pli overwrite bug

* create generic strings instead of hard coding

* remove stale comment in tests

* Check that the sdp lines are not missing, append SDP_LINE_SEPARATOR to lines checked

* Remove duplicate session attribute lines, add missing attribute name

* Clang format

---------

Co-authored-by: Hassan Sahibzada <hsahibza@amazon.com>
  • Loading branch information
stefankiesz and hassanctech authored Nov 22, 2024
1 parent fe0a6d9 commit 2815eac
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/source/PeerConnection/SessionDescription.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,19 +693,12 @@ STATUS populateSingleMediaSection(PKvsPeerConnection pKvsPeerConnection, PKvsRtp
amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue,
SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " nack", payloadType);
CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full H264 rtcp-fb nack value could not be written");
amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue,
SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " nack pli", payloadType);
CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full H264 rtcp-fb nack-pli value could not be written");
attributeCount++;

STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "rtcp-fb");
SPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, "%" PRId64 " nack", payloadType);
SPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, "%" PRId64 " nack pli", payloadType);
attributeCount++;

STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "rtcp-fb");
SPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, "%" PRId64 " nack", payloadType);
SPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue, "%" PRId64 " nack pli", payloadType);
amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue,
SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " nack pli", payloadType);
CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full H264 rtcp-fb nack-pli value could not be written");
attributeCount++;

// TODO: If level asymmetry is allowed, consider sending back DEFAULT_H264_FMTP instead of the received fmtp value.
Expand Down Expand Up @@ -801,6 +794,9 @@ STATUS populateSingleMediaSection(PKvsPeerConnection pKvsPeerConnection, PKvsRtp
amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue,
SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " nack", payloadType);
CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full H265 rtcp-fb nack value could not be written");
attributeCount++;

STRCPY(pSdpMediaDescription->sdpAttributes[attributeCount].attributeName, "rtcp-fb");
amountWritten = SNPRINTF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue,
SIZEOF(pSdpMediaDescription->sdpAttributes[attributeCount].attributeValue), "%" PRId64 " nack pli", payloadType);
CHK_ERR(amountWritten > 0, STATUS_INTERNAL_ERROR, "Full H265 rtcp-fb nack-pli value could not be written");
Expand Down
32 changes: 32 additions & 0 deletions tst/SdpApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ namespace video {
namespace webrtcclient {

class SdpApiTest : public WebRtcClientTestBase {
public:
const std::string m_rtcp_h264_nack_line = "a=rtcp-fb:" + std::to_string(DEFAULT_PAYLOAD_H264) + " nack" + SDP_LINE_SEPARATOR;
const std::string m_rtcp_h264_nack_pli_line = "a=rtcp-fb:" + std::to_string(DEFAULT_PAYLOAD_H264) + " nack pli" + SDP_LINE_SEPARATOR;
const std::string m_rtcp_h265_nack_line = "a=rtcp-fb:" + std::to_string(DEFAULT_PAYLOAD_H265) + " nack" + SDP_LINE_SEPARATOR;
const std::string m_rtcp_h265_nack_pli_line = "a=rtcp-fb:" + std::to_string(DEFAULT_PAYLOAD_H265) + " nack pli" + SDP_LINE_SEPARATOR;
};

/*
Expand Down Expand Up @@ -361,6 +366,15 @@ TEST_F(SdpApiTest, populateSingleMediaSection_TestTxSendRecv)
EXPECT_EQ(STATUS_SUCCESS, createOffer(offerPc, &sessionDescriptionInit));
EXPECT_PRED_FORMAT2(testing::IsSubstring, "sendrecv", sessionDescriptionInit.sdp);

std::string offerSdp(sessionDescriptionInit.sdp);

// check nack and nack pli lines
std::string::size_type posPliOnly = offerSdp.find(m_rtcp_h264_nack_line);
std::string::size_type posPliNack = offerSdp.find(m_rtcp_h264_nack_pli_line);
EXPECT_NE(posPliOnly, posPliNack);
EXPECT_NE(posPliOnly, std::string::npos);
EXPECT_NE(posPliNack, std::string::npos);

closePeerConnection(offerPc);
freePeerConnection(&offerPc);
}
Expand Down Expand Up @@ -431,6 +445,15 @@ TEST_F(SdpApiTest, populateSingleMediaSection_TestTxSendOnly)
EXPECT_EQ(STATUS_SUCCESS, createOffer(offerPc, &sessionDescriptionInit));
EXPECT_PRED_FORMAT2(testing::IsSubstring, "sendonly", sessionDescriptionInit.sdp);

std::string offerSdp(sessionDescriptionInit.sdp);

// check nack and nack pli lines
std::string::size_type posPliOnly = offerSdp.find(m_rtcp_h264_nack_line);
std::string::size_type posPliNack = offerSdp.find(m_rtcp_h264_nack_pli_line);
EXPECT_NE(posPliOnly, posPliNack);
EXPECT_NE(posPliOnly, std::string::npos);
EXPECT_NE(posPliNack, std::string::npos);

closePeerConnection(offerPc);
freePeerConnection(&offerPc);
}
Expand Down Expand Up @@ -462,6 +485,15 @@ TEST_F(SdpApiTest, populateSingleMediaSection_TestTxSendOnly_H265)
EXPECT_EQ(STATUS_SUCCESS, createOffer(offerPc, &sessionDescriptionInit));
EXPECT_PRED_FORMAT2(testing::IsSubstring, "sendonly", sessionDescriptionInit.sdp);

std::string offerSdp(sessionDescriptionInit.sdp);

// check nack and nack pli lines
std::string::size_type posPliOnly = offerSdp.find(m_rtcp_h265_nack_line);
std::string::size_type posPliNack = offerSdp.find(m_rtcp_h265_nack_pli_line);
EXPECT_NE(posPliOnly, posPliNack);
EXPECT_NE(posPliOnly, std::string::npos);
EXPECT_NE(posPliNack, std::string::npos);

closePeerConnection(offerPc);
freePeerConnection(&offerPc);
}
Expand Down

0 comments on commit 2815eac

Please sign in to comment.