Add Rtcp parameters for PeerConnection senders

Bug: webrtc:7580
Change-Id: Ibcf5e849a1f11f21fa75f6d006fecf1cd54f8552
Reviewed-on: https://webrtc-review.googlesource.com/78063
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Commit-Queue: Florent Castelli <orphis@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23407}
This commit is contained in:
Florent Castelli 2018-05-24 16:24:21 +02:00 committed by Commit Bot
parent b06b0a689f
commit dacec71b16
16 changed files with 248 additions and 36 deletions

View File

@ -17,42 +17,13 @@
#include "api/ortc/packettransportinterface.h"
#include "api/rtcerror.h"
#include "api/rtp_headers.h"
#include "api/rtpparameters.h"
#include "common_types.h" // NOLINT(build/include)
namespace webrtc {
class RtpTransportAdapter;
struct RtcpParameters final {
// The SSRC to be used in the "SSRC of packet sender" field. If not set, one
// will be chosen by the implementation.
// TODO(deadbeef): Not implemented.
rtc::Optional<uint32_t> ssrc;
// The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages).
//
// If empty in the construction of the RtpTransport, one will be generated by
// the implementation, and returned in GetRtcpParameters. Multiple
// RtpTransports created by the same OrtcFactory will use the same generated
// CNAME.
//
// If empty when passed into SetParameters, the CNAME simply won't be
// modified.
std::string cname;
// Send reduced-size RTCP?
bool reduced_size = false;
// Send RTCP multiplexed on the RTP transport?
bool mux = true;
bool operator==(const RtcpParameters& o) const {
return ssrc == o.ssrc && cname == o.cname &&
reduced_size == o.reduced_size && mux == o.mux;
}
bool operator!=(const RtcpParameters& o) const { return !(*this == o); }
};
struct RtpTransportParameters final {
RtcpParameters rtcp;

View File

@ -65,6 +65,9 @@ RtpCodecParameters::~RtpCodecParameters() {}
RtpCapabilities::RtpCapabilities() {}
RtpCapabilities::~RtpCapabilities() {}
RtcpParameters::RtcpParameters() {}
RtcpParameters::~RtcpParameters() {}
RtpParameters::RtpParameters() {}
RtpParameters::~RtpParameters() {}

View File

@ -547,9 +547,40 @@ struct RtpCapabilities {
bool operator!=(const RtpCapabilities& o) const { return !(*this == o); }
};
// Note that unlike in ORTC, an RtcpParameters structure is not included in
// RtpParameters, because our API includes an additional "RtpTransport"
// abstraction on which RTCP parameters are set.
struct RtcpParameters final {
RtcpParameters();
~RtcpParameters();
// The SSRC to be used in the "SSRC of packet sender" field. If not set, one
// will be chosen by the implementation.
// TODO(deadbeef): Not implemented.
rtc::Optional<uint32_t> ssrc;
// The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages).
//
// If empty in the construction of the RtpTransport, one will be generated by
// the implementation, and returned in GetRtcpParameters. Multiple
// RtpTransports created by the same OrtcFactory will use the same generated
// CNAME.
//
// If empty when passed into SetParameters, the CNAME simply won't be
// modified.
std::string cname;
// Send reduced-size RTCP?
bool reduced_size = false;
// Send RTCP multiplexed on the RTP transport?
// Not used with PeerConnection senders/receivers
bool mux = true;
bool operator==(const RtcpParameters& o) const {
return ssrc == o.ssrc && cname == o.cname &&
reduced_size == o.reduced_size && mux == o.mux;
}
bool operator!=(const RtcpParameters& o) const { return !(*this == o); }
};
struct RtpParameters {
RtpParameters();
~RtpParameters();
@ -571,6 +602,11 @@ struct RtpParameters {
std::vector<RtpEncodingParameters> encodings;
// Only available with a Peerconnection RtpSender.
// In ORTC, our API includes an additional "RtpTransport"
// abstraction on which RTCP parameters are set.
RtcpParameters rtcp;
// TODO(deadbeef): Not implemented.
DegradationPreference degradation_preference =
DegradationPreference::BALANCED;
@ -578,7 +614,7 @@ struct RtpParameters {
bool operator==(const RtpParameters& o) const {
return mid == o.mid && codecs == o.codecs &&
header_extensions == o.header_extensions &&
encodings == o.encodings &&
encodings == o.encodings && rtcp == o.rtcp &&
degradation_preference == o.degradation_preference;
}
bool operator!=(const RtpParameters& o) const { return !(*this == o); }

View File

@ -33,6 +33,7 @@ webrtc::RtpParameters CreateRtpParametersWithEncodings(StreamParams sp) {
}
webrtc::RtpParameters parameters;
parameters.encodings = encodings;
parameters.rtcp.cname = sp.cname;
return parameters;
}

View File

@ -1642,6 +1642,8 @@ WebRtcVideoChannel::WebRtcVideoSendStream::WebRtcVideoSendStream(
: webrtc::RtcpMode::kCompound;
parameters_.config.rtp.mid = send_params.mid;
rtp_parameters_.rtcp.reduced_size = send_params.rtcp.reduced_size;
if (codec_settings) {
SetCodec(*codec_settings);
}
@ -1761,6 +1763,8 @@ void WebRtcVideoChannel::WebRtcVideoSendStream::SetSendParameters(
bool recreate_stream = false;
if (params.rtcp_mode) {
parameters_.config.rtp.rtcp_mode = *params.rtcp_mode;
rtp_parameters_.rtcp.reduced_size =
parameters_.config.rtp.rtcp_mode == webrtc::RtcpMode::kReducedSize;
recreate_stream = true;
}
if (params.rtp_header_extensions) {
@ -1847,6 +1851,11 @@ WebRtcVideoChannel::WebRtcVideoSendStream::ValidateRtpParameters(
RTCErrorType::INVALID_MODIFICATION,
"Attempted to set RtpParameters with different encoding count");
}
if (rtp_parameters.rtcp != rtp_parameters_.rtcp) {
LOG_AND_RETURN_ERROR(
RTCErrorType::INVALID_MODIFICATION,
"Attempted to set RtpParameters with modified RTCP parameters");
}
if (rtp_parameters.encodings[0].ssrc != rtp_parameters_.encodings[0].ssrc) {
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
"Attempted to set RtpParameters with modified SSRC");

View File

@ -4439,12 +4439,17 @@ TEST_F(WebRtcVideoChannelTest, TestSetSendRtcpReducedSize) {
// Create stream, expecting that default mode is "compound".
FakeVideoSendStream* stream1 = AddSendStream();
EXPECT_EQ(webrtc::RtcpMode::kCompound, stream1->GetConfig().rtp.rtcp_mode);
webrtc::RtpParameters rtp_parameters =
channel_->GetRtpSendParameters(last_ssrc_);
EXPECT_FALSE(rtp_parameters.rtcp.reduced_size);
// Now enable reduced size mode.
send_parameters_.rtcp.reduced_size = true;
EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
stream1 = fake_call_->GetVideoSendStreams()[0];
EXPECT_EQ(webrtc::RtcpMode::kReducedSize, stream1->GetConfig().rtp.rtcp_mode);
rtp_parameters = channel_->GetRtpSendParameters(last_ssrc_);
EXPECT_TRUE(rtp_parameters.rtcp.reduced_size);
// Create a new stream and ensure it picks up the reduced size mode.
FakeVideoSendStream* stream2 = AddSendStream();
@ -5543,6 +5548,16 @@ TEST_F(WebRtcVideoChannelTest, GetRtpSendParametersCodecs) {
rtp_parameters.codecs[1]);
}
// Test that GetRtpSendParameters returns the currently configured RTCP CNAME.
TEST_F(WebRtcVideoChannelTest, GetRtpSendParametersRtcpCname) {
StreamParams params = StreamParams::CreateLegacy(kSsrc);
params.cname = "rtcpcname";
AddSendStream(params);
webrtc::RtpParameters rtp_parameters = channel_->GetRtpSendParameters(kSsrc);
EXPECT_STREQ("rtcpcname", rtp_parameters.rtcp.cname.c_str());
}
// Test that RtpParameters for send stream has one encoding and it has
// the correct SSRC.
TEST_F(WebRtcVideoChannelTest, GetRtpSendParametersSsrc) {

View File

@ -776,6 +776,7 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream
config_.codec_pair_id = codec_pair_id;
config_.track_id = track_id;
rtp_parameters_.encodings[0].ssrc = ssrc;
rtp_parameters_.rtcp.cname = c_name;
if (send_codec_spec) {
UpdateSendCodecSpec(*send_codec_spec);
@ -945,6 +946,11 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream
RTCErrorType::INVALID_MODIFICATION,
"Attempted to set RtpParameters with different encoding count");
}
if (rtp_parameters.rtcp != rtp_parameters_.rtcp) {
LOG_AND_RETURN_ERROR(
RTCErrorType::INVALID_MODIFICATION,
"Attempted to set RtpParameters with modified RTCP parameters");
}
if (rtp_parameters.encodings[0].ssrc != rtp_parameters_.encodings[0].ssrc) {
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION,
"Attempted to set RtpParameters with modified SSRC");
@ -992,6 +998,10 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream
if (reconfigure_send_stream) {
ReconfigureAudioSendStream();
}
rtp_parameters_.rtcp.cname = config_.rtp.c_name;
rtp_parameters_.rtcp.reduced_size = false;
// parameters.encodings[0].active could have changed.
UpdateSendState();
return webrtc::RTCError::OK();

View File

@ -217,10 +217,14 @@ class WebRtcVoiceEngineTestFake : public testing::Test {
}
bool SetupSendStream() {
return SetupSendStream(cricket::StreamParams::CreateLegacy(kSsrcX));
}
bool SetupSendStream(const cricket::StreamParams& sp) {
if (!SetupChannel()) {
return false;
}
if (!channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrcX))) {
if (!channel_->AddSendStream(sp)) {
return false;
}
EXPECT_CALL(*apm_, set_output_will_be_muted(false));
@ -1131,6 +1135,16 @@ TEST_F(WebRtcVoiceEngineTestFake, GetRtpSendParametersCodecs) {
EXPECT_EQ(kPcmuCodec.ToCodecParameters(), rtp_parameters.codecs[1]);
}
// Test that GetRtpSendParameters returns the currently configured RTCP CNAME.
TEST_F(WebRtcVoiceEngineTestFake, GetRtpSendParametersRtcpCname) {
cricket::StreamParams params = cricket::StreamParams::CreateLegacy(kSsrcX);
params.cname = "rtcpcname";
EXPECT_TRUE(SetupSendStream(params));
webrtc::RtpParameters rtp_parameters = channel_->GetRtpSendParameters(kSsrcX);
EXPECT_STREQ("rtcpcname", rtp_parameters.rtcp.cname.c_str());
}
// Test that GetRtpSendParameters returns an SSRC.
TEST_F(WebRtcVoiceEngineTestFake, GetRtpSendParametersSsrc) {
EXPECT_TRUE(SetupSendStream());

View File

@ -683,6 +683,8 @@ if (is_ios || is_mac) {
"objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm",
"objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactoryOptions+Private.h",
"objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactoryOptions.mm",
"objc/Framework/Classes/PeerConnection/RTCRtcpParameters+Private.h",
"objc/Framework/Classes/PeerConnection/RTCRtcpParameters.mm",
"objc/Framework/Classes/PeerConnection/RTCRtpCodecParameters+Private.h",
"objc/Framework/Classes/PeerConnection/RTCRtpCodecParameters.mm",
"objc/Framework/Classes/PeerConnection/RTCRtpEncodingParameters+Private.h",
@ -718,6 +720,7 @@ if (is_ios || is_mac) {
"objc/Framework/Headers/WebRTC/RTCPeerConnection.h",
"objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h",
"objc/Framework/Headers/WebRTC/RTCPeerConnectionFactoryOptions.h",
"objc/Framework/Headers/WebRTC/RTCRtcpParameters.h",
"objc/Framework/Headers/WebRTC/RTCRtpCodecParameters.h",
"objc/Framework/Headers/WebRTC/RTCRtpEncodingParameters.h",
"objc/Framework/Headers/WebRTC/RTCRtpParameters.h",

View File

@ -118,8 +118,33 @@ public class RtpParameters {
}
}
public static class Rtcp {
/** The Canonical Name used by RTCP */
private final String cname;
/** Whether reduced size RTCP is configured or compound RTCP */
private final boolean reducedSize;
@CalledByNative("Rtcp")
Rtcp(String cname, boolean reducedSize) {
this.cname = cname;
this.reducedSize = reducedSize;
}
@CalledByNative("Rtcp")
public String getCname() {
return cname;
}
@CalledByNative("Rtcp")
public boolean getReducedSize() {
return reducedSize;
}
}
public final String transactionId;
private final Rtcp rtcp;
public final List<Encoding> encodings;
// Codec parameters can't currently be changed between getParameters and
// setParameters. Though in the future it will be possible to reorder them or
@ -127,8 +152,9 @@ public class RtpParameters {
public final List<Codec> codecs;
@CalledByNative
RtpParameters(String transactionId, List<Encoding> encodings, List<Codec> codecs) {
RtpParameters(String transactionId, Rtcp rtcp, List<Encoding> encodings, List<Codec> codecs) {
this.transactionId = transactionId;
this.rtcp = rtcp;
this.encodings = encodings;
this.codecs = codecs;
}
@ -138,6 +164,11 @@ public class RtpParameters {
return transactionId;
}
@CalledByNative
public Rtcp getRtcp() {
return rtcp;
}
@CalledByNative
List<Encoding> getEncodings() {
return encodings;

View File

@ -39,6 +39,13 @@ ScopedJavaLocalRef<jobject> NativeToJavaRtpCodecParameter(
NativeToJavaStringMap(env, codec.parameters));
}
ScopedJavaLocalRef<jobject> NativeToJavaRtpRtcpParameters(
JNIEnv* env,
const RtcpParameters& rtcp) {
return Java_Rtcp_Constructor(env, NativeToJavaString(env, rtcp.cname),
rtcp.reduced_size);
}
} // namespace
RtpEncodingParameters JavaToNativeRtpEncodingParameters(
@ -64,6 +71,13 @@ RtpParameters JavaToNativeRtpParameters(JNIEnv* jni,
Java_RtpParameters_getTransactionId(jni, j_parameters);
parameters.transaction_id = JavaToNativeString(jni, j_transaction_id);
ScopedJavaLocalRef<jobject> j_rtcp =
Java_RtpParameters_getRtcp(jni, j_parameters);
ScopedJavaLocalRef<jstring> j_rtcp_cname = Java_Rtcp_getCname(jni, j_rtcp);
jboolean j_rtcp_reduced_size = Java_Rtcp_getReducedSize(jni, j_rtcp);
parameters.rtcp.cname = JavaToNativeString(jni, j_rtcp_cname);
parameters.rtcp.reduced_size = j_rtcp_reduced_size;
// Convert encodings.
ScopedJavaLocalRef<jobject> j_encodings =
Java_RtpParameters_getEncodings(jni, j_parameters);
@ -99,6 +113,7 @@ ScopedJavaLocalRef<jobject> NativeToJavaRtpParameters(
const RtpParameters& parameters) {
return Java_RtpParameters_Constructor(
env, NativeToJavaString(env, parameters.transaction_id),
NativeToJavaRtpRtcpParameters(env, parameters.rtcp),
NativeToJavaList(env, parameters.encodings,
&NativeToJavaRtpEncodingParameter),
NativeToJavaList(env, parameters.codecs, &NativeToJavaRtpCodecParameter));

View File

@ -0,0 +1,27 @@
/*
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#import "WebRTC/RTCRtcpParameters.h"
#include "api/rtpparameters.h"
NS_ASSUME_NONNULL_BEGIN
@interface RTCRtcpParameters ()
/** Returns the equivalent native RtcpParameters structure. */
@property(nonatomic, readonly) webrtc::RtcpParameters nativeParameters;
/** Initialize the object with a native RtcpParameters structure. */
- (instancetype)initWithNativeParameters:(const webrtc::RtcpParameters &)nativeParameters;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,39 @@
/*
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#import "RTCRtcpParameters+Private.h"
#import "NSString+StdString.h"
@implementation RTCRtcpParameters
@synthesize cname = _cname;
@synthesize isReducedSize = _isReducedSize;
- (instancetype)init {
return [super init];
}
- (instancetype)initWithNativeParameters:(const webrtc::RtcpParameters &)nativeParameters {
if (self = [self init]) {
_cname = [NSString stringForStdString:nativeParameters.cname];
_isReducedSize = nativeParameters.reduced_size;
}
return self;
}
- (webrtc::RtcpParameters)nativeParameters {
webrtc::RtcpParameters parameters;
parameters.cname = [NSString stdStringForString:_cname];
parameters.reduced_size = _isReducedSize;
return parameters;
}
@end

View File

@ -11,12 +11,14 @@
#import "RTCRtpParameters+Private.h"
#import "NSString+StdString.h"
#import "RTCRtcpParameters+Private.h"
#import "RTCRtpCodecParameters+Private.h"
#import "RTCRtpEncodingParameters+Private.h"
@implementation RTCRtpParameters
@synthesize transactionId = _transactionId;
@synthesize rtcp = _rtcp;
@synthesize encodings = _encodings;
@synthesize codecs = _codecs;
@ -28,6 +30,7 @@
(const webrtc::RtpParameters &)nativeParameters {
if (self = [self init]) {
_transactionId = [NSString stringForStdString:nativeParameters.transaction_id];
_rtcp = [[RTCRtcpParameters alloc] initWithNativeParameters:nativeParameters.rtcp];
NSMutableArray *encodings = [[NSMutableArray alloc] init];
for (const auto &encoding : nativeParameters.encodings) {
[encodings addObject:[[RTCRtpEncodingParameters alloc]
@ -48,6 +51,7 @@
- (webrtc::RtpParameters)nativeParameters {
webrtc::RtpParameters parameters;
parameters.transaction_id = [NSString stdStringForString:_transactionId];
parameters.rtcp = [_rtcp nativeParameters];
for (RTCRtpEncodingParameters *encoding in _encodings) {
parameters.encodings.push_back(encoding.nativeParameters);
}

View File

@ -0,0 +1,30 @@
/*
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#import <Foundation/Foundation.h>
#import <WebRTC/RTCMacros.h>
NS_ASSUME_NONNULL_BEGIN
RTC_EXPORT
@interface RTCRtcpParameters : NSObject
/** The Canonical Name used by RTCP. */
@property(nonatomic, readonly, copy) NSString *cname;
/** Whether reduced size RTCP is configured or compound RTCP. */
@property(nonatomic, assign) BOOL isReducedSize;
- (instancetype)init NS_DESIGNATED_INITIALIZER;
@end
NS_ASSUME_NONNULL_END

View File

@ -11,6 +11,7 @@
#import <Foundation/Foundation.h>
#import <WebRTC/RTCMacros.h>
#import <WebRTC/RTCRtcpParameters.h>
#import <WebRTC/RTCRtpCodecParameters.h>
#import <WebRTC/RTCRtpEncodingParameters.h>
@ -22,6 +23,9 @@ RTC_EXPORT
/** A unique identifier for the last set of parameters applied. */
@property(nonatomic, copy) NSString *transactionId;
/** Parameters used for RTCP. */
@property(nonatomic, readonly, copy) RTCRtcpParameters *rtcp;
/** The currently active encodings in the order of preference. */
@property(nonatomic, copy) NSArray<RTCRtpEncodingParameters *> *encodings;