Use RtcpPacket to send APP in RtcpSender

BUG=webrtc:2450
R=asapersson@webrtc.org

Review URL: https://codereview.webrtc.org/1311453002 .

Cr-Commit-Position: refs/heads/master@{#9827}
This commit is contained in:
Erik Språng
2015-09-01 10:11:16 +02:00
parent e551f12a41
commit 521875a9a4
2 changed files with 23 additions and 25 deletions

View File

@ -741,32 +741,15 @@ RTCPSender::BuildResult RTCPSender::BuildTMMBN(RtcpContext* ctx) {
}
RTCPSender::BuildResult RTCPSender::BuildAPP(RtcpContext* ctx) {
// sanity
if (app_data_ == NULL) {
LOG(LS_WARNING) << "Failed to build app specific.";
return BuildResult::kError;
}
if (ctx->position + 12 + app_length_ >= IP_PACKET_SIZE) {
LOG(LS_WARNING) << "Failed to build app specific.";
rtcp::App app;
app.From(ssrc_);
app.WithSubType(app_sub_type_);
app.WithName(app_name_);
app.WithData(app_data_.get(), app_length_);
PacketBuiltCallback callback(ctx);
if (!callback.BuildPacket(app))
return BuildResult::kTruncated;
}
*ctx->AllocateData(1) = 0x80 + app_sub_type_;
// Add APP ID
*ctx->AllocateData(1) = 204;
uint16_t length = (app_length_ >> 2) + 2; // include SSRC and name
*ctx->AllocateData(1) = static_cast<uint8_t>(length >> 8);
*ctx->AllocateData(1) = static_cast<uint8_t>(length);
// Add our own SSRC
ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), ssrc_);
// Add our application name
ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), app_name_);
// Add the data
memcpy(ctx->AllocateData(app_length_), app_data_.get(), app_length_);
return BuildResult::kSuccess;
}

View File

@ -389,6 +389,21 @@ TEST_F(RtcpSenderTest, SendApp) {
parser()->app_item()->DataLength()));
}
TEST_F(RtcpSenderTest, SendEmptyApp) {
const uint8_t kSubType = 30;
const uint32_t kName = 0x6E616D65;
EXPECT_EQ(
0, rtcp_sender_->SetApplicationSpecificData(kSubType, kName, nullptr, 0));
rtcp_sender_->SetRTCPStatus(kRtcpNonCompound);
EXPECT_EQ(0, rtcp_sender_->SendRTCP(feedback_state(), kRtcpApp));
EXPECT_EQ(1, parser()->app()->num_packets());
EXPECT_EQ(kSubType, parser()->app()->SubType());
EXPECT_EQ(kName, parser()->app()->Name());
EXPECT_EQ(0, parser()->app_item()->num_packets());
}
TEST_F(RtcpSenderTest, SetInvalidApplicationSpecificData) {
const uint8_t kData[] = {'t', 'e', 's', 't', 'd', 'a', 't'};
const uint16_t kInvalidDataLength = sizeof(kData) / sizeof(kData[0]);