Make RTCAudioSession accessible to Swift. This is done by: 1. removing the <vector> include from RTCAudioSession+Private, 2. creating a audio_session_objc package that excludes the RTCNativeAudioSessionDelegateAdapter class. Bug: webrtc:11237 Change-Id: I36c86542a19e3244456fd164d908563b1435de29 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/163900 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Kári Helgason <kthelgason@webrtc.org> Reviewed-by: Chuck Hays <haysc@webrtc.org> Reviewed-by: Henrik Andreassson <henrika@webrtc.org> Commit-Queue: Kári Helgason <kthelgason@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30177}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 34f8230..c200609 100755 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py
@@ -521,7 +521,7 @@ """Checks that public_deps is not used without a good reason.""" result = [] no_presubmit_check_re = input_api.re.compile( - r'# no-presubmit-check TODO\(webrtc:8603\)') + r'# no-presubmit-check TODO\(webrtc:\d+\)') error_msg = ('public_deps is not recommended in WebRTC BUILD.gn files ' 'because it doesn\'t map well to downstream build systems.\n' 'Used in: %s (line %d).\n'
diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index d326630..c80da5a 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn
@@ -286,7 +286,37 @@ libs = [ "AudioToolbox.framework" ] } - rtc_library("audio_objc") { + # This target exists to expose :audio_session_objc and + # :audio_session_delegate_adapter_objc for backward compatibility, + # and should be deprecated. + group("audio_objc") { + public_deps = [ # no-presubmit-check TODO(webrtc:11238) + ":audio_session_delegate_adapter_objc", + ":audio_session_objc", + ] + } + + rtc_library("audio_session_delegate_adapter_objc") { + sources = [ + "objc/components/audio/RTCNativeAudioSessionDelegateAdapter.h", + "objc/components/audio/RTCNativeAudioSessionDelegateAdapter.mm", + ] + + configs += [ + "..:common_objc", + ":used_from_extension", + ] + + public_configs = [ ":common_config_objc" ] + + deps = [ + ":audio_session_objc", + ":audio_session_observer", + ":base_objc", + ] + } + + rtc_library("audio_session_objc") { sources = [ "objc/components/audio/RTCAudioSession+Configuration.mm", "objc/components/audio/RTCAudioSession+Private.h", @@ -294,9 +324,8 @@ "objc/components/audio/RTCAudioSession.mm", "objc/components/audio/RTCAudioSessionConfiguration.h", "objc/components/audio/RTCAudioSessionConfiguration.m", - "objc/components/audio/RTCNativeAudioSessionDelegateAdapter.h", - "objc/components/audio/RTCNativeAudioSessionDelegateAdapter.mm", ] + configs += [ "..:common_objc", ":used_from_extension", @@ -307,7 +336,6 @@ libs = [ "AVFoundation.framework" ] deps = [ - ":audio_session_observer", ":base_objc", ":helpers_objc", "../rtc_base", @@ -1073,7 +1101,7 @@ deps = [ ":audio_device", - ":audio_objc", + ":audio_session_objc", ":base_objc", ":callback_logger_objc", ":framework_objc", @@ -1225,7 +1253,7 @@ if (is_ios) { sources += [ "objc/unittests/RTCAudioSessionTest.mm" ] - deps += [ ":audio_objc" ] + deps += [ ":audio_session_objc" ] } } }
diff --git a/sdk/objc/components/audio/RTCAudioSession+Private.h b/sdk/objc/components/audio/RTCAudioSession+Private.h index 8ad0c21..8cf9339 100644 --- a/sdk/objc/components/audio/RTCAudioSession+Private.h +++ b/sdk/objc/components/audio/RTCAudioSession+Private.h
@@ -10,8 +10,6 @@ #import "RTCAudioSession.h" -#include <vector> - NS_ASSUME_NONNULL_BEGIN @class RTCAudioSessionConfiguration; @@ -77,8 +75,6 @@ - (NSError *)configurationErrorWithDescription:(NSString *)description; // Properties and methods for tests. -@property(nonatomic, readonly) std::vector<__weak id<RTCAudioSessionDelegate> > delegates; - - (void)notifyDidBeginInterruption; - (void)notifyDidEndInterruptionWithShouldResumeSession:(BOOL)shouldResumeSession; - (void)notifyDidChangeRouteWithReason:(AVAudioSessionRouteChangeReason)reason
diff --git a/sdk/objc/components/audio/RTCAudioSession.mm b/sdk/objc/components/audio/RTCAudioSession.mm index 09ffa16..229a6ea 100644 --- a/sdk/objc/components/audio/RTCAudioSession.mm +++ b/sdk/objc/components/audio/RTCAudioSession.mm
@@ -12,6 +12,8 @@ #import <UIKit/UIKit.h> +#include <vector> + #include "rtc_base/atomic_ops.h" #include "rtc_base/checks.h" #include "rtc_base/critical_section.h" @@ -25,6 +27,10 @@ NSInteger const kRTCAudioSessionErrorConfiguration = -2; NSString * const kRTCAudioSessionOutputVolumeSelector = @"outputVolume"; +@interface RTCAudioSession () +@property(nonatomic, readonly) std::vector<__weak id<RTCAudioSessionDelegate> > delegates; +@end + // This class needs to be thread-safe because it is accessed from many threads. // TODO(tkchin): Consider more granular locking. We're not expecting a lot of // lock contention so coarse locks should be fine for now.
diff --git a/sdk/objc/unittests/RTCAudioSessionTest.mm b/sdk/objc/unittests/RTCAudioSessionTest.mm index 6bb46ae..c2140c3 100644 --- a/sdk/objc/unittests/RTCAudioSessionTest.mm +++ b/sdk/objc/unittests/RTCAudioSessionTest.mm
@@ -11,6 +11,8 @@ #import <Foundation/Foundation.h> #import <OCMock/OCMock.h> +#include <vector> + #include "rtc_base/gunit.h" #import "components/audio/RTCAudioSession+Private.h" @@ -20,6 +22,8 @@ @interface RTCAudioSession (UnitTesting) +@property(nonatomic, readonly) std::vector<__weak id<RTCAudioSessionDelegate> > delegates; + - (instancetype)initWithAudioSession:(id)audioSession; @end