Introduce InbandComfortNoise RTP header extension.

BUG: webrtc:11085
Change-Id: I9b556a0d67d3c239abc247787103af9e50af4e65
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/159710
Commit-Queue: Minyue Li <minyue@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30014}
This commit is contained in:
Minyue Li
2019-11-29 16:18:59 +01:00
committed by Commit Bot
parent 78782a806f
commit cae277959b
7 changed files with 76 additions and 1 deletions

View File

@ -55,6 +55,7 @@ enum RTPExtensionType : int {
kRtpExtensionNone,
kRtpExtensionTransmissionTimeOffset,
kRtpExtensionAudioLevel,
kRtpExtensionInbandComfortNoise,
kRtpExtensionAbsoluteSendTime,
kRtpExtensionAbsoluteCaptureTime,
kRtpExtensionVideoRotation,

View File

@ -49,6 +49,7 @@ constexpr ExtensionInfo kExtensions[] = {
CreateExtensionInfo<RtpGenericFrameDescriptorExtension01>(),
CreateExtensionInfo<RtpDependencyDescriptorExtension>(),
CreateExtensionInfo<ColorSpaceExtension>(),
CreateExtensionInfo<InbandComfortNoiseExtension>(),
};
// Because of kRtpExtensionNone, NumberOfExtension is 1 bigger than the actual

View File

@ -855,4 +855,49 @@ constexpr const char RepairedRtpStreamId::kUri[];
constexpr RTPExtensionType RtpMid::kId;
constexpr const char RtpMid::kUri[];
// An RTP Header Extension for Inband Comfort Noise
//
// The form of the audio level extension block:
//
// 0 1
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | ID | len=0 |N| level |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Sample Audio Level Encoding Using the One-Byte Header Format
//
// 0 1 2
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | ID | len=1 |N| level |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Sample Audio Level Encoding Using the Two-Byte Header Format
constexpr RTPExtensionType InbandComfortNoiseExtension::kId;
constexpr uint8_t InbandComfortNoiseExtension::kValueSizeBytes;
constexpr const char InbandComfortNoiseExtension::kUri[];
bool InbandComfortNoiseExtension::Parse(rtc::ArrayView<const uint8_t> data,
absl::optional<uint8_t>* level) {
if (data.size() != kValueSizeBytes)
return false;
*level = (data[0] & 0b1000'0000) != 0
? absl::nullopt
: absl::make_optional(data[0] & 0b0111'1111);
return true;
}
bool InbandComfortNoiseExtension::Write(rtc::ArrayView<uint8_t> data,
absl::optional<uint8_t> level) {
RTC_DCHECK_EQ(data.size(), kValueSizeBytes);
data[0] = 0b0000'0000;
if (level) {
if (*level > 127) {
return false;
}
data[0] = 0b1000'0000 | *level;
}
return true;
}
} // namespace webrtc

View File

@ -297,5 +297,23 @@ class RtpMid : public BaseRtpStringExtension {
static constexpr const char kUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid";
};
class InbandComfortNoiseExtension {
public:
using value_type = absl::optional<uint8_t>;
static constexpr RTPExtensionType kId = kRtpExtensionInbandComfortNoise;
static constexpr uint8_t kValueSizeBytes = 1;
static constexpr const char kUri[] =
"http://www.webrtc.org/experiments/rtp-hdrext/inband-cn";
static bool Parse(rtc::ArrayView<const uint8_t> data,
absl::optional<uint8_t>* level);
static size_t ValueSize(absl::optional<uint8_t> level) {
return kValueSizeBytes;
}
static bool Write(rtc::ArrayView<uint8_t> data,
absl::optional<uint8_t> level);
};
} // namespace webrtc
#endif // MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSIONS_H_

View File

@ -193,7 +193,8 @@ void RtpPacket::ZeroMutableExtensions() {
case RTPExtensionType::kRtpExtensionRepairedRtpStreamId:
case RTPExtensionType::kRtpExtensionRtpStreamId:
case RTPExtensionType::kRtpExtensionVideoContentType:
case RTPExtensionType::kRtpExtensionVideoRotation: {
case RTPExtensionType::kRtpExtensionVideoRotation:
case RTPExtensionType::kRtpExtensionInbandComfortNoise: {
// Non-mutable extension. Don't change it.
break;
}

View File

@ -543,6 +543,10 @@ void RtpHeaderParser::ParseOneByteExtensionHeader(
RTC_LOG(WARNING)
<< "RtpExtensionColorSpace unsupported by rtp header parser.";
break;
case kRtpExtensionInbandComfortNoise:
RTC_LOG(WARNING) << "Inband comfort noise extension unsupported by "
"rtp header parser.";
break;
case kRtpExtensionNone:
case kRtpExtensionNumberOfExtensions: {
RTC_NOTREACHED() << "Invalid extension type: " << type;

View File

@ -145,6 +145,11 @@ void FuzzOneInput(const uint8_t* data, size_t size) {
packet.GetExtension<ColorSpaceExtension>(&color_space);
break;
}
case kRtpExtensionInbandComfortNoise: {
absl::optional<uint8_t> noise_level;
packet.GetExtension<InbandComfortNoiseExtension>(&noise_level);
break;
}
case kRtpExtensionGenericFrameDescriptor02:
// This extension requires state to read and so complicated that
// deserves own fuzzer.