Skip to content

Commit e71c396

Browse files
Darwin improvements
[Mac/iOS] feat: Add RTCYUVHelper for darwin. (#28) Cross-platform `RTCMTLVideoView` for both iOS / macOS (#40) rotationOverride should not be assign (#44) [ObjC] Expose properties / methods required for AV1 codec support (#60) Workaround: Render PixelBuffer in RTCMTLVideoView (#58) Improve iOS/macOS H264 encoder (#70) fix: fix video encoder not resuming correctly upon foregrounding (#75). add PrivacyInfo.xcprivacy to darwin frameworks. (#112) Add NSPrivacyCollectedDataTypes key to xcprivacy file (#114) Thread-safe `RTCInitFieldTrialDictionary` (#116) Co-authored-by: Hiroshi Horie <[email protected]>
1 parent 9aaaab5 commit e71c396

18 files changed

+661
-222
lines changed

sdk/BUILD.gn

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,15 @@ if (is_ios || is_mac) {
144144
"objc/helpers/RTCDispatcher+Private.h",
145145
"objc/helpers/RTCDispatcher.h",
146146
"objc/helpers/RTCDispatcher.m",
147+
"objc/helpers/RTCYUVHelper.h",
148+
"objc/helpers/RTCYUVHelper.mm",
147149
"objc/helpers/scoped_cftyperef.h",
148150
]
149151

150152
deps = [
151153
":base_objc",
152154
"../rtc_base:checks",
155+
"//third_party/libyuv",
153156
]
154157

155158
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
@@ -617,17 +620,13 @@ if (is_ios || is_mac) {
617620
"Metal.framework",
618621
"MetalKit.framework",
619622
]
620-
if (is_ios) {
623+
if (is_ios || is_mac) {
621624
sources += [
622625
"objc/components/renderer/metal/RTCMTLVideoView.h",
623626
"objc/components/renderer/metal/RTCMTLVideoView.m",
624627
]
625628
}
626629
if (is_mac) {
627-
sources += [
628-
"objc/components/renderer/metal/RTCMTLNSVideoView.h",
629-
"objc/components/renderer/metal/RTCMTLNSVideoView.m",
630-
]
631630
frameworks += [ "AppKit.framework" ]
632631
}
633632
deps = [
@@ -1287,6 +1286,13 @@ if (is_ios || is_mac) {
12871286
}
12881287
}
12891288

1289+
bundle_data("darwin_privacy_info") {
1290+
sources = [
1291+
"objc/PrivacyInfo.xcprivacy",
1292+
]
1293+
outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
1294+
}
1295+
12901296
if (is_ios) {
12911297
apple_framework_bundle_with_umbrella_header("framework_objc") {
12921298
info_plist = "objc/Info.plist"
@@ -1334,6 +1340,7 @@ if (is_ios || is_mac) {
13341340
"objc/components/video_frame_buffer/RTCCVPixelBuffer.h",
13351341
"objc/helpers/RTCCameraPreviewView.h",
13361342
"objc/helpers/RTCDispatcher.h",
1343+
"objc/helpers/RTCYUVHelper.h",
13371344
"objc/helpers/UIDevice+RTCDevice.h",
13381345
"objc/api/peerconnection/RTCAudioDeviceModule.h",
13391346
"objc/api/peerconnection/RTCIODevice.h",
@@ -1417,6 +1424,7 @@ if (is_ios || is_mac) {
14171424
":videocapture_objc",
14181425
":videocodec_objc",
14191426
":videotoolbox_objc",
1427+
":darwin_privacy_info",
14201428
]
14211429
if (!build_with_chromium) {
14221430
deps += [
@@ -1526,6 +1534,7 @@ if (is_ios || is_mac) {
15261534
"objc/base/RTCYUVPlanarBuffer.h",
15271535
"objc/components/capturer/RTCCameraVideoCapturer.h",
15281536
"objc/components/capturer/RTCFileVideoCapturer.h",
1537+
"objc/components/renderer/metal/RTCMTLVideoView.h",
15291538
"objc/components/renderer/metal/RTCMTLNSVideoView.h",
15301539
"objc/components/renderer/opengl/RTCVideoViewShading.h",
15311540
"objc/components/video_codec/RTCCodecSpecificInfoH264.h",
@@ -1538,6 +1547,7 @@ if (is_ios || is_mac) {
15381547
"objc/components/video_codec/RTCVideoEncoderH264.h",
15391548
"objc/components/video_frame_buffer/RTCCVPixelBuffer.h",
15401549
"objc/helpers/RTCDispatcher.h",
1550+
"objc/helpers/RTCYUVHelper.h",
15411551
# Added for Simulcast support
15421552
"objc/components/video_codec/RTCVideoEncoderFactorySimulcast.h",
15431553
"objc/api/video_codec/RTCVideoEncoderSimulcast.h",
@@ -1558,6 +1568,7 @@ if (is_ios || is_mac) {
15581568
":videocapture_objc",
15591569
":videocodec_objc",
15601570
":videotoolbox_objc",
1571+
":darwin_privacy_info",
15611572
]
15621573
if (!build_with_chromium) {
15631574
deps += [

sdk/objc/PrivacyInfo.xcprivacy

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>NSPrivacyCollectedDataTypes</key>
6+
<array/>
7+
<key>NSPrivacyAccessedAPITypes</key>
8+
<array>
9+
<dict>
10+
<key>NSPrivacyAccessedAPIType</key>
11+
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
12+
<key>NSPrivacyAccessedAPITypeReasons</key>
13+
<array>
14+
<string>C617.1</string>
15+
</array>
16+
</dict>
17+
<dict>
18+
<key>NSPrivacyAccessedAPIType</key>
19+
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
20+
<key>NSPrivacyAccessedAPITypeReasons</key>
21+
<array>
22+
<string>35F9.1</string>
23+
<string>8FFB.1</string>
24+
</array>
25+
</dict>
26+
</array>
27+
</dict>
28+
</plist>

sdk/objc/api/peerconnection/RTCFieldTrials.mm

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,58 @@
1010

1111
#import "RTCFieldTrials.h"
1212

13+
#import <os/lock.h>
1314
#include <memory>
14-
1515
#import "base/RTCLogging.h"
1616

1717
#include "system_wrappers/include/field_trial.h"
1818

1919
NSString *const kRTCFieldTrialAudioForceABWENoTWCCKey = @"WebRTC-Audio-ABWENoTWCC";
20-
NSString * const kRTCFieldTrialFlexFec03AdvertisedKey = @"WebRTC-FlexFEC-03-Advertised";
21-
NSString * const kRTCFieldTrialFlexFec03Key = @"WebRTC-FlexFEC-03";
22-
NSString * const kRTCFieldTrialH264HighProfileKey = @"WebRTC-H264HighProfile";
23-
NSString * const kRTCFieldTrialMinimizeResamplingOnMobileKey =
20+
NSString *const kRTCFieldTrialFlexFec03AdvertisedKey = @"WebRTC-FlexFEC-03-Advertised";
21+
NSString *const kRTCFieldTrialFlexFec03Key = @"WebRTC-FlexFEC-03";
22+
NSString *const kRTCFieldTrialH264HighProfileKey = @"WebRTC-H264HighProfile";
23+
NSString *const kRTCFieldTrialMinimizeResamplingOnMobileKey =
2424
@"WebRTC-Audio-MinimizeResamplingOnMobile";
2525
NSString *const kRTCFieldTrialUseNWPathMonitor = @"WebRTC-Network-UseNWPathMonitor";
26-
NSString * const kRTCFieldTrialEnabledValue = @"Enabled";
26+
NSString *const kRTCFieldTrialEnabledValue = @"Enabled";
2727

2828
// InitFieldTrialsFromString stores the char*, so the char array must outlive
2929
// the application.
3030
static char *gFieldTrialInitString = nullptr;
31+
static os_unfair_lock fieldTrialLock = OS_UNFAIR_LOCK_INIT;
3132

3233
void RTCInitFieldTrialDictionary(NSDictionary<NSString *, NSString *> *fieldTrials) {
3334
if (!fieldTrials) {
3435
RTCLogWarning(@"No fieldTrials provided.");
3536
return;
3637
}
38+
3739
// Assemble the keys and values into the field trial string.
38-
// We don't perform any extra format checking. That should be done by the underlying WebRTC calls.
3940
NSMutableString *fieldTrialInitString = [NSMutableString string];
4041
for (NSString *key in fieldTrials) {
4142
NSString *fieldTrialEntry = [NSString stringWithFormat:@"%@/%@/", key, fieldTrials[key]];
4243
[fieldTrialInitString appendString:fieldTrialEntry];
4344
}
45+
4446
size_t len = fieldTrialInitString.length + 1;
47+
48+
// Locking before modifying global variable
49+
os_unfair_lock_lock(&fieldTrialLock);
4550
if (gFieldTrialInitString != nullptr) {
4651
delete[] gFieldTrialInitString;
52+
gFieldTrialInitString = nullptr;
4753
}
54+
4855
gFieldTrialInitString = new char[len];
49-
if (![fieldTrialInitString getCString:gFieldTrialInitString
50-
maxLength:len
51-
encoding:NSUTF8StringEncoding]) {
56+
bool success = [fieldTrialInitString getCString:gFieldTrialInitString
57+
maxLength:len
58+
encoding:NSUTF8StringEncoding];
59+
if (!success) {
5260
RTCLogError(@"Failed to convert field trial string.");
61+
os_unfair_lock_unlock(&fieldTrialLock);
5362
return;
5463
}
64+
5565
webrtc::field_trial::InitFieldTrialsFromString(gFieldTrialInitString);
66+
os_unfair_lock_unlock(&fieldTrialLock);
5667
}

sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ NS_ASSUME_NONNULL_BEGIN
2525
@class RTC_OBJC_TYPE(RTCVideoTrack);
2626
@class RTC_OBJC_TYPE(RTCPeerConnectionFactoryOptions);
2727
@class RTC_OBJC_TYPE(RTCAudioDeviceModule);
28+
@class RTC_OBJC_TYPE(RTCRtpCapabilities);
29+
30+
typedef NS_ENUM(NSInteger, RTCRtpMediaType);
31+
2832
@protocol RTC_OBJC_TYPE
2933
(RTCPeerConnectionDelegate);
3034
@protocol RTC_OBJC_TYPE

sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#import "RTCPeerConnection+Private.h"
2626
#import "RTCVideoSource+Private.h"
2727
#import "RTCVideoTrack+Private.h"
28+
#import "RTCRtpReceiver+Private.h"
29+
#import "RTCRtpCapabilities+Private.h"
30+
#import "RTCRtpCodecCapability+Private.h"
2831
#import "base/RTCLogging.h"
2932
#import "base/RTCVideoDecoderFactory.h"
3033
#import "base/RTCVideoEncoderFactory.h"
@@ -130,6 +133,20 @@ - (instancetype)init {
130133
#endif
131134
}
132135

136+
- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpSenderCapabilitiesFor:(RTCRtpMediaType)mediaType {
137+
138+
webrtc::RtpCapabilities capabilities = _nativeFactory->GetRtpSenderCapabilities([RTCRtpReceiver nativeMediaTypeForMediaType: mediaType]);
139+
140+
return [[RTCRtpCapabilities alloc] initWithNativeRtpCapabilities: capabilities];
141+
}
142+
143+
- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpReceiverCapabilitiesFor:(RTCRtpMediaType)mediaType {
144+
145+
webrtc::RtpCapabilities capabilities = _nativeFactory->GetRtpReceiverCapabilities([RTCRtpReceiver nativeMediaTypeForMediaType: mediaType]);
146+
147+
return [[RTCRtpCapabilities alloc] initWithNativeRtpCapabilities: capabilities];
148+
}
149+
133150
- (instancetype)
134151
initWithBypassVoiceProcessing:(BOOL)bypassVoiceProcessing
135152
encoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory

sdk/objc/api/peerconnection/RTCRtpCodecParameters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ RTC_EXTERN const NSString *const kRTCComfortNoiseCodecName;
3030
RTC_EXTERN const NSString *const kRTCVp8CodecName;
3131
RTC_EXTERN const NSString *const kRTCVp9CodecName;
3232
RTC_EXTERN const NSString *const kRTCH264CodecName;
33+
RTC_EXTERN const NSString *const kRTCAv1CodecName;
3334

3435
/** Defined in https://www.w3.org/TR/webrtc/#idl-def-rtcrtpcodecparameters */
3536
RTC_OBJC_EXPORT

sdk/objc/api/peerconnection/RTCRtpCodecParameters.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
const NSString * const kRTCVp8CodecName = @(cricket::kVp8CodecName);
3333
const NSString * const kRTCVp9CodecName = @(cricket::kVp9CodecName);
3434
const NSString * const kRTCH264CodecName = @(cricket::kH264CodecName);
35+
const NSString * const kRTCAv1CodecName = @(cricket::kAv1CodecName);
3536

3637
@implementation RTC_OBJC_TYPE (RTCRtpCodecParameters)
3738

sdk/objc/api/peerconnection/RTCRtpEncodingParameters.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ RTC_OBJC_EXPORT
6969
https://w3c.github.io/webrtc-extensions/#dom-rtcrtpencodingparameters-adaptiveptime */
7070
@property(nonatomic, assign) BOOL adaptiveAudioPacketTime;
7171

72+
/** A case-sensitive identifier of the scalability mode to be used for this stream.
73+
https://w3c.github.io/webrtc-svc/#rtcrtpencodingparameters */
74+
@property(nonatomic, copy, nullable) NSString *scalabilityMode;
75+
7276
- (instancetype)init;
7377

7478
@end

sdk/objc/api/peerconnection/RTCRtpEncodingParameters.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ @implementation RTC_OBJC_TYPE (RTCRtpEncodingParameters)
2525
@synthesize bitratePriority = _bitratePriority;
2626
@synthesize networkPriority = _networkPriority;
2727
@synthesize adaptiveAudioPacketTime = _adaptiveAudioPacketTime;
28+
@synthesize scalabilityMode = _scalabilityMode;
2829

2930
- (instancetype)init {
3031
webrtc::RtpEncodingParameters nativeParameters;
@@ -59,6 +60,9 @@ - (instancetype)initWithNativeParameters:
5960
if (nativeParameters.ssrc) {
6061
_ssrc = [NSNumber numberWithUnsignedLong:*nativeParameters.ssrc];
6162
}
63+
if (nativeParameters.scalability_mode) {
64+
_scalabilityMode = [NSString stringWithUTF8String:nativeParameters.scalability_mode->c_str()];
65+
}
6266
_bitratePriority = nativeParameters.bitrate_priority;
6367
_networkPriority = [RTC_OBJC_TYPE(RTCRtpEncodingParameters)
6468
priorityFromNativePriority:nativeParameters.network_priority];
@@ -92,6 +96,9 @@ - (instancetype)initWithNativeParameters:
9296
if (_ssrc != nil) {
9397
parameters.ssrc = absl::optional<uint32_t>(_ssrc.unsignedLongValue);
9498
}
99+
if (_scalabilityMode != nil) {
100+
parameters.scalability_mode = absl::optional<std::string>(std::string([_scalabilityMode UTF8String]));
101+
}
95102
parameters.bitrate_priority = _bitratePriority;
96103
parameters.network_priority =
97104
[RTC_OBJC_TYPE(RTCRtpEncodingParameters) nativePriorityFromPriority:_networkPriority];

sdk/objc/api/peerconnection/RTCRtpTransceiver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#import "RTCRtpReceiver.h"
1515
#import "RTCRtpSender.h"
1616

17+
@class RTC_OBJC_TYPE(RTCRtpCodecCapability);
18+
1719
NS_ASSUME_NONNULL_BEGIN
1820

1921
extern NSString *const kRTCRtpTransceiverErrorDomain;
@@ -105,6 +107,8 @@ RTC_OBJC_EXPORT
105107
*/
106108
@property(nonatomic, readonly) RTCRtpTransceiverDirection direction;
107109

110+
@property(nonatomic, copy) NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *codecPreferences;
111+
108112
/** The currentDirection attribute indicates the current direction negotiated
109113
* for this transceiver. If this transceiver has never been represented in an
110114
* offer/answer exchange, or if the transceiver is stopped, the value is not

0 commit comments

Comments
 (0)