diff --git a/api/ortc/rtptransportinterface.h b/api/ortc/rtptransportinterface.h index 716a297c54..882230093b 100644 --- a/api/ortc/rtptransportinterface.h +++ b/api/ortc/rtptransportinterface.h @@ -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 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; diff --git a/api/rtpparameters.cc b/api/rtpparameters.cc index ed48091b92..5a873de46e 100644 --- a/api/rtpparameters.cc +++ b/api/rtpparameters.cc @@ -65,6 +65,9 @@ RtpCodecParameters::~RtpCodecParameters() {} RtpCapabilities::RtpCapabilities() {} RtpCapabilities::~RtpCapabilities() {} +RtcpParameters::RtcpParameters() {} +RtcpParameters::~RtcpParameters() {} + RtpParameters::RtpParameters() {} RtpParameters::~RtpParameters() {} diff --git a/api/rtpparameters.h b/api/rtpparameters.h index 96df9ce885..c12b0c9588 100644 --- a/api/rtpparameters.h +++ b/api/rtpparameters.h @@ -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 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 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); } diff --git a/media/base/mediaengine.cc b/media/base/mediaengine.cc index d40f765dd0..b0fede3a2a 100644 --- a/media/base/mediaengine.cc +++ b/media/base/mediaengine.cc @@ -33,6 +33,7 @@ webrtc::RtpParameters CreateRtpParametersWithEncodings(StreamParams sp) { } webrtc::RtpParameters parameters; parameters.encodings = encodings; + parameters.rtcp.cname = sp.cname; return parameters; } diff --git a/media/engine/webrtcvideoengine.cc b/media/engine/webrtcvideoengine.cc index 532f57efc2..0b89e1f490 100644 --- a/media/engine/webrtcvideoengine.cc +++ b/media/engine/webrtcvideoengine.cc @@ -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"); diff --git a/media/engine/webrtcvideoengine_unittest.cc b/media/engine/webrtcvideoengine_unittest.cc index 6ecf750ec3..7d640a6dc6 100644 --- a/media/engine/webrtcvideoengine_unittest.cc +++ b/media/engine/webrtcvideoengine_unittest.cc @@ -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) { diff --git a/media/engine/webrtcvoiceengine.cc b/media/engine/webrtcvoiceengine.cc index bb1c9c3c83..cb82bbd553 100644 --- a/media/engine/webrtcvoiceengine.cc +++ b/media/engine/webrtcvoiceengine.cc @@ -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(); diff --git a/media/engine/webrtcvoiceengine_unittest.cc b/media/engine/webrtcvoiceengine_unittest.cc index d574a72777..966ca6bbd6 100644 --- a/media/engine/webrtcvoiceengine_unittest.cc +++ b/media/engine/webrtcvoiceengine_unittest.cc @@ -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()); diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index 3f70c75566..f8bac0771a 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -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", diff --git a/sdk/android/api/org/webrtc/RtpParameters.java b/sdk/android/api/org/webrtc/RtpParameters.java index 0e893bdc5f..e376c082ac 100644 --- a/sdk/android/api/org/webrtc/RtpParameters.java +++ b/sdk/android/api/org/webrtc/RtpParameters.java @@ -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 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 codecs; @CalledByNative - RtpParameters(String transactionId, List encodings, List codecs) { + RtpParameters(String transactionId, Rtcp rtcp, List encodings, List 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 getEncodings() { return encodings; diff --git a/sdk/android/src/jni/pc/rtpparameters.cc b/sdk/android/src/jni/pc/rtpparameters.cc index b0b83eb811..385eb8ae31 100644 --- a/sdk/android/src/jni/pc/rtpparameters.cc +++ b/sdk/android/src/jni/pc/rtpparameters.cc @@ -39,6 +39,13 @@ ScopedJavaLocalRef NativeToJavaRtpCodecParameter( NativeToJavaStringMap(env, codec.parameters)); } +ScopedJavaLocalRef 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 j_rtcp = + Java_RtpParameters_getRtcp(jni, j_parameters); + ScopedJavaLocalRef 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 j_encodings = Java_RtpParameters_getEncodings(jni, j_parameters); @@ -99,6 +113,7 @@ ScopedJavaLocalRef 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)); diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCRtcpParameters+Private.h b/sdk/objc/Framework/Classes/PeerConnection/RTCRtcpParameters+Private.h new file mode 100644 index 0000000000..4157ffe746 --- /dev/null +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCRtcpParameters+Private.h @@ -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 diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCRtcpParameters.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCRtcpParameters.mm new file mode 100644 index 0000000000..1c8a31bf20 --- /dev/null +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCRtcpParameters.mm @@ -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 diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCRtpParameters.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCRtpParameters.mm index d18eba6a3d..7c00b08bc5 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCRtpParameters.mm +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCRtpParameters.mm @@ -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); } diff --git a/sdk/objc/Framework/Headers/WebRTC/RTCRtcpParameters.h b/sdk/objc/Framework/Headers/WebRTC/RTCRtcpParameters.h new file mode 100644 index 0000000000..54b254c373 --- /dev/null +++ b/sdk/objc/Framework/Headers/WebRTC/RTCRtcpParameters.h @@ -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 + +#import + +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 diff --git a/sdk/objc/Framework/Headers/WebRTC/RTCRtpParameters.h b/sdk/objc/Framework/Headers/WebRTC/RTCRtpParameters.h index b6e1f01a23..02ce9812fb 100644 --- a/sdk/objc/Framework/Headers/WebRTC/RTCRtpParameters.h +++ b/sdk/objc/Framework/Headers/WebRTC/RTCRtpParameters.h @@ -11,6 +11,7 @@ #import #import +#import #import #import @@ -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 *encodings;