Update how FEC handles protection parameters for key vs delta frames.

This CL:
1) Updates RtpSenderVideo to actually populate the is_key_frame field
properly.

2) Updates UlpfecGenerator to:
 * Allow updating the protection parameters before adding any packet.
 * Apply keyframe protection parameter when at least one buffered
   media packet to be protected belongs to a keyframe.

Updating the parameters in the middle of a frame is allowed, at that
point they only determine how many _complete_ frames are needed in order
to trigger FEC generation. Only that requirement is met, will the
protection parameters (e.g. FEC rate and mask type) actually be applied.

This means that delta-frames adjecent to a key-frame (either ahead of
or after) may be protected in the same way as the key-frame itself.

Bug: webrtc:11340
Change-Id: Ieb84d0ae46de01c17b4ef72251a4cb37814569da
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/195620
Commit-Queue: Erik Språng <sprang@webrtc.org>
Reviewed-by: Ying Wang <yinwa@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32787}
This commit is contained in:
Erik Språng
2020-12-07 13:18:34 +01:00
committed by Commit Bot
parent 3ee4af4509
commit cf15cb5c94
5 changed files with 119 additions and 16 deletions

View File

@ -217,4 +217,57 @@ TEST_F(UlpfecGeneratorTest, MixedMediaRtpHeaderLengths) {
}
}
TEST_F(UlpfecGeneratorTest, UpdatesProtectionParameters) {
const FecProtectionParams kKeyFrameParams = {25, /*max_fec_frames=*/2,
kFecMaskRandom};
const FecProtectionParams kDeltaFrameParams = {25, /*max_fec_frames=*/5,
kFecMaskRandom};
ulpfec_generator_.SetProtectionParameters(kDeltaFrameParams, kKeyFrameParams);
// No params applied yet.
EXPECT_EQ(ulpfec_generator_.CurrentParams().max_fec_frames, 0);
// Helper function to add a single-packet frame market as either key-frame
// or delta-frame.
auto add_frame = [&](bool is_keyframe) {
packet_generator_.NewFrame(1);
std::unique_ptr<AugmentedPacket> packet =
packet_generator_.NextPacket(0, 10);
RtpPacketToSend rtp_packet(nullptr);
EXPECT_TRUE(rtp_packet.Parse(packet->data.data(), packet->data.size()));
rtp_packet.set_is_key_frame(is_keyframe);
ulpfec_generator_.AddPacketAndGenerateFec(rtp_packet);
};
// Add key-frame, keyframe params should apply, no FEC generated yet.
add_frame(true);
EXPECT_EQ(ulpfec_generator_.CurrentParams().max_fec_frames, 2);
EXPECT_TRUE(ulpfec_generator_.GetFecPackets().empty());
// Add delta-frame, generated FEC packet. Params will not be updated until
// next added packet though.
add_frame(false);
EXPECT_EQ(ulpfec_generator_.CurrentParams().max_fec_frames, 2);
EXPECT_FALSE(ulpfec_generator_.GetFecPackets().empty());
// Add delta-frame, now params get updated.
add_frame(false);
EXPECT_EQ(ulpfec_generator_.CurrentParams().max_fec_frames, 5);
EXPECT_TRUE(ulpfec_generator_.GetFecPackets().empty());
// Add yet another delta-frame.
add_frame(false);
EXPECT_EQ(ulpfec_generator_.CurrentParams().max_fec_frames, 5);
EXPECT_TRUE(ulpfec_generator_.GetFecPackets().empty());
// Add key-frame, params immediately switch to key-frame ones. The two
// buffered frames plus the key-frame is protected and fec emitted,
// even though the frame count is technically over the keyframe frame count
// threshold.
add_frame(true);
EXPECT_EQ(ulpfec_generator_.CurrentParams().max_fec_frames, 2);
EXPECT_FALSE(ulpfec_generator_.GetFecPackets().empty());
}
} // namespace webrtc