From 682f7945d5e2bab2b554462e7923ed0ead0c4267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A1ri=20Tristan=20Helgason?= Date: Fri, 30 Aug 2024 12:38:27 +0200 Subject: [PATCH] Deprecate bad signature for CreateSessionDescription. Bug: webrtc:360909068 Change-Id: I8640dcf3cb89b1e07ea6745887d152fdeb7479c9 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/360020 Reviewed-by: Henrik Andreassson Reviewed-by: Peter Hanspers Commit-Queue: Harald Alvestrand Reviewed-by: Mirko Bonadei Cr-Commit-Position: refs/heads/main@{#42932} --- api/jsep.h | 14 ++++++++------ sdk/BUILD.gn | 1 + .../api/peerconnection/RTCSessionDescription.mm | 16 +++++++++++++++- sdk/objc/unittests/RTCSessionDescriptionTest.mm | 13 +++++-------- test/fuzzers/sdp_integration_fuzzer.cc | 4 ++-- test/fuzzers/sdp_parser_fuzzer.cc | 4 ++-- 6 files changed, 33 insertions(+), 19 deletions(-) diff --git a/api/jsep.h b/api/jsep.h index d8fb27ca21..296f381b1d 100644 --- a/api/jsep.h +++ b/api/jsep.h @@ -192,12 +192,14 @@ class RTC_EXPORT SessionDescriptionInterface { // Creates a SessionDescriptionInterface based on the SDP string and the type. // Returns null if the sdp string can't be parsed or the type is unsupported. // `error` may be null. -// TODO(steveanton): This function is deprecated. Please use the functions below -// which take an SdpType enum instead. Remove this once it is no longer used. -RTC_EXPORT SessionDescriptionInterface* CreateSessionDescription( - const std::string& type, - const std::string& sdp, - SdpParseError* error); +// TODO(https://issues.webrtc.org/360909068): This function is deprecated. +// Please use the functions below which take an SdpType enum instead. Remove +// this once it is no longer used. +[[deprecated("Use version with SdpType argument")]] RTC_EXPORT + SessionDescriptionInterface* + CreateSessionDescription(const std::string& type, + const std::string& sdp, + SdpParseError* error); // Creates a SessionDescriptionInterface based on the SDP string and the type. // Returns null if the SDP string cannot be parsed. diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index 6a48cbf010..0c33be3afd 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -1180,6 +1180,7 @@ if (is_ios || is_mac) { ":videoframebuffer_objc", ":videosource_objc", ":videotoolbox_objc", + "../api:libjingle_peerconnection_api", "../api:scoped_refptr", "../api/audio:audio_device", "../api/audio:audio_processing", diff --git a/sdk/objc/api/peerconnection/RTCSessionDescription.mm b/sdk/objc/api/peerconnection/RTCSessionDescription.mm index d173f22527..25bf20e8d3 100644 --- a/sdk/objc/api/peerconnection/RTCSessionDescription.mm +++ b/sdk/objc/api/peerconnection/RTCSessionDescription.mm @@ -13,6 +13,7 @@ #import "base/RTCLogging.h" #import "helpers/NSString+StdString.h" +#include "api/jsep.h" #include "rtc_base/checks.h" @implementation RTC_OBJC_TYPE (RTCSessionDescription) @@ -51,7 +52,7 @@ webrtc::SdpParseError error; std::unique_ptr description(webrtc::CreateSessionDescription( - [[self class] stdStringForType:_type], _sdp.stdString, &error)); + [[self class] nativeTypeForType:_type], _sdp.stdString, &error)); if (!description) { RTCLogError(@"Failed to create session description: %s\nline: %s", @@ -101,4 +102,17 @@ } } ++ (webrtc::SdpType)nativeTypeForType:(RTCSdpType)type { + switch (type) { + case RTCSdpTypeOffer: + return webrtc::SdpType::kOffer; + case RTCSdpTypePrAnswer: + return webrtc::SdpType::kPrAnswer; + case RTCSdpTypeAnswer: + return webrtc::SdpType::kAnswer; + case RTCSdpTypeRollback: + return webrtc::SdpType::kRollback; + } +} + @end diff --git a/sdk/objc/unittests/RTCSessionDescriptionTest.mm b/sdk/objc/unittests/RTCSessionDescriptionTest.mm index 70c82f78ce..a22c96b935 100644 --- a/sdk/objc/unittests/RTCSessionDescriptionTest.mm +++ b/sdk/objc/unittests/RTCSessionDescriptionTest.mm @@ -11,6 +11,7 @@ #import #import +#include "api/jsep.h" #include "rtc_base/gunit.h" #import "api/peerconnection/RTCSessionDescription+Private.h" @@ -42,15 +43,11 @@ } - (void)testInitFromNativeSessionDescription { - webrtc::SessionDescriptionInterface *nativeDescription; + const auto nativeDescription = + webrtc::CreateSessionDescription(webrtc::SdpType::kAnswer, [self sdp].stdString, nullptr); - nativeDescription = webrtc::CreateSessionDescription( - webrtc::SessionDescriptionInterface::kAnswer, - [self sdp].stdString, - nullptr); - - RTC_OBJC_TYPE(RTCSessionDescription) *description = - [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:nativeDescription]; + RTC_OBJC_TYPE(RTCSessionDescription) *description = [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] + initWithNativeDescription:nativeDescription.get()]; EXPECT_EQ(webrtc::SessionDescriptionInterface::kAnswer, [RTC_OBJC_TYPE(RTCSessionDescription) stdStringForType:description.type]); EXPECT_TRUE([[self sdp] isEqualToString:description.sdp]); diff --git a/test/fuzzers/sdp_integration_fuzzer.cc b/test/fuzzers/sdp_integration_fuzzer.cc index ece4b50505..9073818de4 100644 --- a/test/fuzzers/sdp_integration_fuzzer.cc +++ b/test/fuzzers/sdp_integration_fuzzer.cc @@ -30,8 +30,8 @@ class FuzzerTest : public PeerConnectionIntegrationBaseTest { rtc::make_ref_counted(); SdpParseError error; - std::unique_ptr sdp( - CreateSessionDescription("offer", std::string(message), &error)); + std::unique_ptr sdp = + CreateSessionDescription(SdpType::kOffer, std::string(message), &error); caller()->pc()->SetRemoteDescription(std::move(sdp), srd_observer); // Wait a short time for observer to be called. Timeout is short // because the fuzzer should be trying many branches. diff --git a/test/fuzzers/sdp_parser_fuzzer.cc b/test/fuzzers/sdp_parser_fuzzer.cc index c85eab4047..0df96330a5 100644 --- a/test/fuzzers/sdp_parser_fuzzer.cc +++ b/test/fuzzers/sdp_parser_fuzzer.cc @@ -21,8 +21,8 @@ void FuzzOneInput(const uint8_t* data, size_t size) { std::string message(reinterpret_cast(data), size); webrtc::SdpParseError error; - std::unique_ptr sdp( - CreateSessionDescription("offer", message, &error)); + std::unique_ptr sdp = + CreateSessionDescription(SdpType::kOffer, message, &error); } } // namespace webrtc