Set marker bit on last encoded spatial layer.

In order to handle per-layer frame dropping both VP9 encoder wrapper
and RTP packetizer were modified.

- Encoder wrapper buffers last encoded frame and passes it to
packetizer after frame of next layer is encoded or encoding of
superframe is finished.
- Encoder wrapper sets end_of_superframe flag on last encoded frame of
superframe before passing it to packetizer.
- If end_of_superframe is True then packetizer sets marker bit on last
packet of frame.

Bug: webrtc:9066
Change-Id: I1d45319fbe6bc63d01721ea67bfb7440d4c29275
Reviewed-on: https://webrtc-review.googlesource.com/65540
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22722}
This commit is contained in:
Sergey Silkin
2018-04-04 11:45:41 +02:00
committed by Commit Bot
parent e803dbe210
commit 2a1f183e99
9 changed files with 216 additions and 61 deletions

View File

@ -576,9 +576,13 @@ bool RtpPacketizerVp9::NextPacket(RtpPacketToSend* packet) {
if (!WriteHeaderAndPayload(packet_info, packet, packets_.empty())) {
return false;
}
packet->SetMarker(packets_.empty() &&
(hdr_.spatial_idx == kNoSpatialIdx ||
hdr_.spatial_idx == hdr_.num_spatial_layers - 1));
// Ensure end_of_superframe is always set on top spatial layer when it is not
// dropped.
RTC_DCHECK(hdr_.spatial_idx < hdr_.num_spatial_layers - 1 ||
hdr_.end_of_superframe);
packet->SetMarker(packets_.empty() && hdr_.end_of_superframe);
return true;
}

View File

@ -478,7 +478,7 @@ TEST_F(RtpPacketizerVp9Test, TestSsDataDoesNotFitInAveragePacket) {
CreateParseAndCheckPackets(kExpectedHdrSizes, kExpectedSizes, kExpectedNum);
}
TEST_F(RtpPacketizerVp9Test, TestOnlyHighestSpatialLayerSetMarker) {
TEST_F(RtpPacketizerVp9Test, EndOfSuperframeSetsSetMarker) {
const size_t kFrameSize = 10;
const size_t kPacketSize = 8;
const size_t kLastPacketReductionLen = 0;
@ -492,32 +492,21 @@ TEST_F(RtpPacketizerVp9Test, TestOnlyHighestSpatialLayerSetMarker) {
RtpPacketToSend packet(kNoExtensions);
vp9_header.spatial_idx = 0;
RtpPacketizerVp9 packetizer0(vp9_header, kPacketSize,
kLastPacketReductionLen);
packetizer0.SetPayloadData(kFrame, sizeof(kFrame), kNoFragmentation);
ASSERT_TRUE(packetizer0.NextPacket(&packet));
EXPECT_FALSE(packet.Marker());
ASSERT_TRUE(packetizer0.NextPacket(&packet));
EXPECT_FALSE(packet.Marker());
vp9_header.spatial_idx = 1;
RtpPacketizerVp9 packetizer1(vp9_header, kPacketSize,
kLastPacketReductionLen);
packetizer1.SetPayloadData(kFrame, sizeof(kFrame), kNoFragmentation);
ASSERT_TRUE(packetizer1.NextPacket(&packet));
EXPECT_FALSE(packet.Marker());
ASSERT_TRUE(packetizer1.NextPacket(&packet));
EXPECT_FALSE(packet.Marker());
vp9_header.spatial_idx = 2;
RtpPacketizerVp9 packetizer2(vp9_header, kPacketSize,
kLastPacketReductionLen);
packetizer2.SetPayloadData(kFrame, sizeof(kFrame), kNoFragmentation);
ASSERT_TRUE(packetizer2.NextPacket(&packet));
EXPECT_FALSE(packet.Marker());
ASSERT_TRUE(packetizer2.NextPacket(&packet));
EXPECT_TRUE(packet.Marker());
// Drop top layer and ensure that marker bit is set on last encoded layer.
for (size_t spatial_idx = 0; spatial_idx < vp9_header.num_spatial_layers - 1;
++spatial_idx) {
const bool end_of_superframe =
spatial_idx + 1 == vp9_header.num_spatial_layers - 1;
vp9_header.spatial_idx = spatial_idx;
vp9_header.end_of_superframe = end_of_superframe;
RtpPacketizerVp9 packetizer(vp9_header, kPacketSize,
kLastPacketReductionLen);
packetizer.SetPayloadData(kFrame, sizeof(kFrame), kNoFragmentation);
ASSERT_TRUE(packetizer.NextPacket(&packet));
EXPECT_FALSE(packet.Marker());
ASSERT_TRUE(packetizer.NextPacket(&packet));
EXPECT_EQ(packet.Marker(), end_of_superframe);
}
}
TEST_F(RtpPacketizerVp9Test, TestGeneratesMinimumNumberOfPackets) {