From fcf5e7b131e75751aed2177cf93650e21a0e23d8 Mon Sep 17 00:00:00 2001 From: Harald Alvestrand Date: Mon, 17 Aug 2020 10:07:26 +0200 Subject: [PATCH] Make Objective-C interface use SetDirectionWithError MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also moves implementation of legacy setDirection() without error to the api/ directory. This is one step in the plan for changing the API to return RTCError. Bug: chromium:980879 Change-Id: Ibce8edf8e3c6d41de7ce49d2ffc33f5b282a0e9f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/181520 Reviewed-by: Kári Helgason Reviewed-by: Guido Urdaneta Commit-Queue: Harald Alvestrand Cr-Commit-Position: refs/heads/master@{#31943} --- pc/rtp_transceiver.cc | 4 ---- pc/rtp_transceiver.h | 2 -- sdk/objc/api/peerconnection/RTCRtpTransceiver.h | 14 ++++++++++---- sdk/objc/api/peerconnection/RTCRtpTransceiver.mm | 15 +++++++++++++-- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/pc/rtp_transceiver.cc b/pc/rtp_transceiver.cc index 701b83ffc2..b267e4e333 100644 --- a/pc/rtp_transceiver.cc +++ b/pc/rtp_transceiver.cc @@ -299,10 +299,6 @@ RtpTransceiverDirection RtpTransceiver::direction() const { return direction_; } -void RtpTransceiver::SetDirection(RtpTransceiverDirection new_direction) { - SetDirectionWithError(new_direction); -} - RTCError RtpTransceiver::SetDirectionWithError( RtpTransceiverDirection new_direction) { if (unified_plan_ && stopping()) { diff --git a/pc/rtp_transceiver.h b/pc/rtp_transceiver.h index 980d64ca76..1d3ceaef61 100644 --- a/pc/rtp_transceiver.h +++ b/pc/rtp_transceiver.h @@ -189,7 +189,6 @@ class RtpTransceiver final bool stopped() const override; bool stopping() const override; RtpTransceiverDirection direction() const override; - void SetDirection(RtpTransceiverDirection new_direction) override; RTCError SetDirectionWithError( RtpTransceiverDirection new_direction) override; absl::optional current_direction() const override; @@ -248,7 +247,6 @@ PROXY_CONSTMETHOD0(rtc::scoped_refptr, receiver) PROXY_CONSTMETHOD0(bool, stopped) PROXY_CONSTMETHOD0(bool, stopping) PROXY_CONSTMETHOD0(RtpTransceiverDirection, direction) -PROXY_METHOD1(void, SetDirection, RtpTransceiverDirection) PROXY_METHOD1(webrtc::RTCError, SetDirectionWithError, RtpTransceiverDirection) PROXY_CONSTMETHOD0(absl::optional, current_direction) PROXY_CONSTMETHOD0(absl::optional, fired_direction) diff --git a/sdk/objc/api/peerconnection/RTCRtpTransceiver.h b/sdk/objc/api/peerconnection/RTCRtpTransceiver.h index 17054f5e43..fd59013639 100644 --- a/sdk/objc/api/peerconnection/RTCRtpTransceiver.h +++ b/sdk/objc/api/peerconnection/RTCRtpTransceiver.h @@ -16,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN +extern NSString *const kRTCRtpTransceiverErrorDomain; + /** https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiverdirection */ typedef NS_ENUM(NSInteger, RTCRtpTransceiverDirection) { RTCRtpTransceiverDirectionSendRecv, @@ -98,12 +100,9 @@ RTC_OBJC_EXPORT /** The direction attribute indicates the preferred direction of this * transceiver, which will be used in calls to createOffer and createAnswer. - * An update of directionality does not take effect immediately. Instead, - * future calls to createOffer and createAnswer mark the corresponding media - * descriptions as sendrecv, sendonly, recvonly, or inactive. * https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction */ -@property(nonatomic) RTCRtpTransceiverDirection direction; +@property(nonatomic, readonly) RTCRtpTransceiverDirection direction; /** The currentDirection attribute indicates the current direction negotiated * for this transceiver. If this transceiver has never been represented in an @@ -119,6 +118,13 @@ RTC_OBJC_EXPORT */ - (void)stopInternal; +/** An update of directionality does not take effect immediately. Instead, + * future calls to createOffer and createAnswer mark the corresponding media + * descriptions as sendrecv, sendonly, recvonly, or inactive. + * https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction + */ +- (void)setDirection:(RTCRtpTransceiverDirection)direction error:(NSError **)error; + @end RTC_OBJC_EXPORT diff --git a/sdk/objc/api/peerconnection/RTCRtpTransceiver.mm b/sdk/objc/api/peerconnection/RTCRtpTransceiver.mm index 5d0d8eda37..ae1cf79864 100644 --- a/sdk/objc/api/peerconnection/RTCRtpTransceiver.mm +++ b/sdk/objc/api/peerconnection/RTCRtpTransceiver.mm @@ -17,6 +17,8 @@ #import "base/RTCLogging.h" #import "helpers/NSString+StdString.h" +NSString *const kRTCRtpTransceiverErrorDomain = @"org.webrtc.RTCRtpTranceiver"; + @implementation RTC_OBJC_TYPE (RTCRtpTransceiverInit) @synthesize direction = _direction; @@ -75,9 +77,18 @@ rtpTransceiverDirectionFromNativeDirection:_nativeRtpTransceiver->direction()]; } -- (void)setDirection:(RTCRtpTransceiverDirection)direction { - _nativeRtpTransceiver->SetDirection( +- (void)setDirection:(RTCRtpTransceiverDirection)direction error:(NSError **)error { + webrtc::RTCError nativeError = _nativeRtpTransceiver->SetDirectionWithError( [RTC_OBJC_TYPE(RTCRtpTransceiver) nativeRtpTransceiverDirectionFromDirection:direction]); + + if (!nativeError.ok() && error) { + *error = [NSError errorWithDomain:kRTCRtpTransceiverErrorDomain + code:static_cast(nativeError.type()) + userInfo:@{ + @"message" : [NSString stringWithCString:nativeError.message() + encoding:NSUTF8StringEncoding] + }]; + } } - (BOOL)currentDirection:(RTCRtpTransceiverDirection *)currentDirectionOut {