Ignore inactive chains when writing DependencyDescriptor rtp header extension.
To implement rule "Chains protecting no active decode targets MUST be ignored." from https://aomediacodec.github.io/av1-rtp-spec/#a44-switching Bug: webrtc:10342 Change-Id: Ibe5e0b7b6ab8955419d0d9f996c6397f442e1cda Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/177668 Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Philip Eliasson <philipel@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31566}
This commit is contained in:
parent
39adce1498
commit
e3296b6d4c
@ -10,6 +10,7 @@
|
||||
|
||||
#include "modules/rtp_rtcp/source/rtp_dependency_descriptor_extension.h"
|
||||
|
||||
#include <bitset>
|
||||
#include <cstdint>
|
||||
|
||||
#include "api/array_view.h"
|
||||
@ -23,6 +24,7 @@ namespace webrtc {
|
||||
|
||||
constexpr RTPExtensionType RtpDependencyDescriptorExtension::kId;
|
||||
constexpr char RtpDependencyDescriptorExtension::kUri[];
|
||||
constexpr std::bitset<32> RtpDependencyDescriptorExtension::kAllChainsAreActive;
|
||||
|
||||
bool RtpDependencyDescriptorExtension::Parse(
|
||||
rtc::ArrayView<const uint8_t> data,
|
||||
@ -34,16 +36,20 @@ bool RtpDependencyDescriptorExtension::Parse(
|
||||
|
||||
size_t RtpDependencyDescriptorExtension::ValueSize(
|
||||
const FrameDependencyStructure& structure,
|
||||
std::bitset<32> active_chains,
|
||||
const DependencyDescriptor& descriptor) {
|
||||
RtpDependencyDescriptorWriter writer(/*data=*/{}, structure, descriptor);
|
||||
RtpDependencyDescriptorWriter writer(/*data=*/{}, structure, active_chains,
|
||||
descriptor);
|
||||
return DivideRoundUp(writer.ValueSizeBits(), 8);
|
||||
}
|
||||
|
||||
bool RtpDependencyDescriptorExtension::Write(
|
||||
rtc::ArrayView<uint8_t> data,
|
||||
const FrameDependencyStructure& structure,
|
||||
std::bitset<32> active_chains,
|
||||
const DependencyDescriptor& descriptor) {
|
||||
RtpDependencyDescriptorWriter writer(data, structure, descriptor);
|
||||
RtpDependencyDescriptorWriter writer(data, structure, active_chains,
|
||||
descriptor);
|
||||
return writer.Write();
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#ifndef MODULES_RTP_RTCP_SOURCE_RTP_DEPENDENCY_DESCRIPTOR_EXTENSION_H_
|
||||
#define MODULES_RTP_RTCP_SOURCE_RTP_DEPENDENCY_DESCRIPTOR_EXTENSION_H_
|
||||
|
||||
#include <bitset>
|
||||
#include <cstdint>
|
||||
|
||||
#include "api/array_view.h"
|
||||
@ -34,10 +35,24 @@ class RtpDependencyDescriptorExtension {
|
||||
DependencyDescriptor* descriptor);
|
||||
|
||||
static size_t ValueSize(const FrameDependencyStructure& structure,
|
||||
const DependencyDescriptor& descriptor) {
|
||||
return ValueSize(structure, kAllChainsAreActive, descriptor);
|
||||
}
|
||||
static size_t ValueSize(const FrameDependencyStructure& structure,
|
||||
std::bitset<32> active_chains,
|
||||
const DependencyDescriptor& descriptor);
|
||||
static bool Write(rtc::ArrayView<uint8_t> data,
|
||||
const FrameDependencyStructure& structure,
|
||||
const DependencyDescriptor& descriptor) {
|
||||
return Write(data, structure, kAllChainsAreActive, descriptor);
|
||||
}
|
||||
static bool Write(rtc::ArrayView<uint8_t> data,
|
||||
const FrameDependencyStructure& structure,
|
||||
std::bitset<32> active_chains,
|
||||
const DependencyDescriptor& descriptor);
|
||||
|
||||
private:
|
||||
static constexpr std::bitset<32> kAllChainsAreActive = ~uint32_t{0};
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -63,5 +63,57 @@ TEST(RtpDependencyDescriptorExtensionTest, WriteZeroInUnusedBits) {
|
||||
EXPECT_THAT(rtc::MakeArrayView(unused_bytes, num_unused_bytes), Each(0));
|
||||
}
|
||||
|
||||
// In practice chain diff for inactive chain will grow uboundly because no
|
||||
// frames are produced for it, that shouldn't block writing the extension.
|
||||
TEST(RtpDependencyDescriptorExtensionTest,
|
||||
TemplateMatchingSkipsInactiveChains) {
|
||||
uint8_t buffer[3];
|
||||
FrameDependencyStructure structure;
|
||||
structure.num_decode_targets = 2;
|
||||
structure.num_chains = 2;
|
||||
structure.templates = {
|
||||
FrameDependencyTemplate().Dtis("SR").ChainDiffs({2, 2})};
|
||||
DependencyDescriptor descriptor;
|
||||
descriptor.frame_dependencies = structure.templates[0];
|
||||
|
||||
// Set only 1st chain as active.
|
||||
std::bitset<32> active_chains = 0b01;
|
||||
descriptor.frame_dependencies.chain_diffs[1] = 1000;
|
||||
|
||||
// Expect perfect template match since the only difference is for an inactive
|
||||
// chain. Pefect template match consumes 3 bytes.
|
||||
EXPECT_EQ(RtpDependencyDescriptorExtension::ValueSize(
|
||||
structure, active_chains, descriptor),
|
||||
3u);
|
||||
EXPECT_TRUE(RtpDependencyDescriptorExtension::Write(
|
||||
buffer, structure, active_chains, descriptor));
|
||||
}
|
||||
|
||||
TEST(RtpDependencyDescriptorExtensionTest,
|
||||
AcceptsInvalidChainDiffForInactiveChainWhenChainsAreCustom) {
|
||||
uint8_t buffer[256];
|
||||
FrameDependencyStructure structure;
|
||||
structure.num_decode_targets = 2;
|
||||
structure.num_chains = 2;
|
||||
structure.templates = {
|
||||
FrameDependencyTemplate().Dtis("SR").ChainDiffs({2, 2})};
|
||||
DependencyDescriptor descriptor;
|
||||
descriptor.frame_dependencies = structure.templates[0];
|
||||
|
||||
// Set only 1st chain as active.
|
||||
std::bitset<32> active_chains = 0b01;
|
||||
// Set chain_diff different to the template to make it custom.
|
||||
descriptor.frame_dependencies.chain_diffs[0] = 1;
|
||||
// Set chain diff for inactive chain beyound limit of 255 max chain diff.
|
||||
descriptor.frame_dependencies.chain_diffs[1] = 1000;
|
||||
|
||||
// Because chains are custom, should use more than base 3 bytes.
|
||||
EXPECT_GT(RtpDependencyDescriptorExtension::ValueSize(
|
||||
structure, active_chains, descriptor),
|
||||
3u);
|
||||
EXPECT_TRUE(RtpDependencyDescriptorExtension::Write(
|
||||
buffer, structure, active_chains, descriptor));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace webrtc
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
*/
|
||||
#include "modules/rtp_rtcp/source/rtp_dependency_descriptor_writer.h"
|
||||
|
||||
#include <bitset>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <iterator>
|
||||
@ -55,9 +56,11 @@ NextLayerIdc GetNextLayerIdc(const FrameDependencyTemplate& previous,
|
||||
RtpDependencyDescriptorWriter::RtpDependencyDescriptorWriter(
|
||||
rtc::ArrayView<uint8_t> data,
|
||||
const FrameDependencyStructure& structure,
|
||||
std::bitset<32> active_chains,
|
||||
const DependencyDescriptor& descriptor)
|
||||
: descriptor_(descriptor),
|
||||
structure_(structure),
|
||||
active_chains_(active_chains),
|
||||
bit_writer_(data.data(), data.size()) {
|
||||
FindBestTemplate();
|
||||
}
|
||||
@ -128,8 +131,14 @@ RtpDependencyDescriptorWriter::CalculateMatch(
|
||||
result.need_custom_dtis =
|
||||
descriptor_.frame_dependencies.decode_target_indications !=
|
||||
frame_template->decode_target_indications;
|
||||
result.need_custom_chains =
|
||||
descriptor_.frame_dependencies.chain_diffs != frame_template->chain_diffs;
|
||||
result.need_custom_chains = false;
|
||||
for (int i = 0; i < structure_.num_chains; ++i) {
|
||||
if (active_chains_[i] && descriptor_.frame_dependencies.chain_diffs[i] !=
|
||||
frame_template->chain_diffs[i]) {
|
||||
result.need_custom_chains = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
result.extra_size_bits = 0;
|
||||
if (result.need_custom_fdiffs) {
|
||||
@ -366,7 +375,9 @@ void RtpDependencyDescriptorWriter::WriteFrameFdiffs() {
|
||||
void RtpDependencyDescriptorWriter::WriteFrameChains() {
|
||||
RTC_DCHECK_EQ(descriptor_.frame_dependencies.chain_diffs.size(),
|
||||
structure_.num_chains);
|
||||
for (int chain_diff : descriptor_.frame_dependencies.chain_diffs) {
|
||||
for (int i = 0; i < structure_.num_chains; ++i) {
|
||||
int chain_diff =
|
||||
active_chains_[i] ? descriptor_.frame_dependencies.chain_diffs[i] : 0;
|
||||
RTC_DCHECK_GE(chain_diff, 0);
|
||||
RTC_DCHECK_LT(chain_diff, 1 << 8);
|
||||
WriteBits(chain_diff, 8);
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#ifndef MODULES_RTP_RTCP_SOURCE_RTP_DEPENDENCY_DESCRIPTOR_WRITER_H_
|
||||
#define MODULES_RTP_RTCP_SOURCE_RTP_DEPENDENCY_DESCRIPTOR_WRITER_H_
|
||||
|
||||
#include <bitset>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
@ -25,6 +26,7 @@ class RtpDependencyDescriptorWriter {
|
||||
// |descriptor| matches the |structure|.
|
||||
RtpDependencyDescriptorWriter(rtc::ArrayView<uint8_t> data,
|
||||
const FrameDependencyStructure& structure,
|
||||
std::bitset<32> active_chains,
|
||||
const DependencyDescriptor& descriptor);
|
||||
|
||||
// Serializes DependencyDescriptor rtp header extension.
|
||||
@ -77,6 +79,7 @@ class RtpDependencyDescriptorWriter {
|
||||
bool build_failed_ = false;
|
||||
const DependencyDescriptor& descriptor_;
|
||||
const FrameDependencyStructure& structure_;
|
||||
std::bitset<32> active_chains_;
|
||||
rtc::BitBufferWriter bit_writer_;
|
||||
TemplateMatch best_template_;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user