Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ObjC] Expose properties / methods required for AV1 codec support #60

Merged
merged 21 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sdk/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,9 @@ if (is_ios || is_mac) {
"objc/api/peerconnection/RTCRtcpParameters+Private.h",
"objc/api/peerconnection/RTCRtcpParameters.h",
"objc/api/peerconnection/RTCRtcpParameters.mm",
"objc/api/peerconnection/RTCRtpCodecCapability.h",
"objc/api/peerconnection/RTCRtpCodecCapability.mm",
"objc/api/peerconnection/RTCRtpCodecCapability+Private.h",
"objc/api/peerconnection/RTCRtpCodecParameters+Private.h",
"objc/api/peerconnection/RTCRtpCodecParameters.h",
"objc/api/peerconnection/RTCRtpCodecParameters.mm",
Expand Down Expand Up @@ -1382,6 +1385,7 @@ if (is_ios || is_mac) {
"objc/api/peerconnection/RTCPeerConnectionFactory.h",
"objc/api/peerconnection/RTCPeerConnectionFactoryOptions.h",
"objc/api/peerconnection/RTCRtcpParameters.h",
"objc/api/peerconnection/RTCRtpCodecCapability.h",
"objc/api/peerconnection/RTCRtpCodecParameters.h",
"objc/api/peerconnection/RTCRtpEncodingParameters.h",
"objc/api/peerconnection/RTCRtpHeaderExtension.h",
Expand Down Expand Up @@ -1503,6 +1507,7 @@ if (is_ios || is_mac) {
"objc/api/peerconnection/RTCPeerConnectionFactory.h",
"objc/api/peerconnection/RTCPeerConnectionFactoryOptions.h",
"objc/api/peerconnection/RTCRtcpParameters.h",
"objc/api/peerconnection/RTCRtpCodecCapability.h",
"objc/api/peerconnection/RTCRtpCodecParameters.h",
"objc/api/peerconnection/RTCRtpEncodingParameters.h",
"objc/api/peerconnection/RTCRtpHeaderExtension.h",
Expand Down
7 changes: 7 additions & 0 deletions sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ NS_ASSUME_NONNULL_BEGIN
@class RTC_OBJC_TYPE(RTCVideoTrack);
@class RTC_OBJC_TYPE(RTCPeerConnectionFactoryOptions);
@class RTC_OBJC_TYPE(RTCAudioDeviceModule);
@class RTC_OBJC_TYPE(RTCRtpCodecCapability);

typedef NS_ENUM(NSInteger, RTCRtpMediaType);

@protocol RTC_OBJC_TYPE
(RTCPeerConnectionDelegate);
Expand Down Expand Up @@ -54,6 +57,10 @@ RTC_OBJC_EXPORT

@property(nonatomic, readonly) RTCAudioDeviceModule *audioDeviceModule;

- (NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *)rtpSenderCapabilitiesFor:(RTCRtpMediaType)mediaType;

- (NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *)rtpReceiverCapabilitiesFor:(RTCRtpMediaType)mediaType;

/** Initialize an RTCAudioSource with constraints. */
- (RTC_OBJC_TYPE(RTCAudioSource) *)audioSourceWithConstraints:
(nullable RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints;
Expand Down
31 changes: 31 additions & 0 deletions sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#import "RTCPeerConnection+Private.h"
#import "RTCVideoSource+Private.h"
#import "RTCVideoTrack+Private.h"
#import "RTCRtpReceiver+Private.h"
#import "RTCRtpCodecCapability.h"
#import "RTCRtpCodecCapability+Private.h"
#import "base/RTCLogging.h"
#import "base/RTCVideoDecoderFactory.h"
#import "base/RTCVideoEncoderFactory.h"
Expand Down Expand Up @@ -113,6 +116,34 @@ - (instancetype)init {
#endif
}

- (NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *)rtpSenderCapabilitiesFor:(RTCRtpMediaType)mediaType {

NSMutableArray *result = [NSMutableArray array];

webrtc::RtpCapabilities capabilities = _nativeFactory->GetRtpSenderCapabilities([RTCRtpReceiver nativeMediaTypeForMediaType: mediaType]);

for (auto & element : capabilities.codecs) {
RTCRtpCodecCapability *object = [[RTCRtpCodecCapability alloc] initWithNativeCodecCapability: element];
[result addObject: object];
}

return result;
}

- (NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *)rtpReceiverCapabilitiesFor:(RTCRtpMediaType)mediaType {

NSMutableArray *result = [NSMutableArray array];

webrtc::RtpCapabilities capabilities = _nativeFactory->GetRtpReceiverCapabilities([RTCRtpReceiver nativeMediaTypeForMediaType: mediaType]);

for (auto & element : capabilities.codecs) {
RTCRtpCodecCapability *object = [[RTCRtpCodecCapability alloc] initWithNativeCodecCapability: element];
[result addObject: object];
}

return result;
}

- (instancetype)
initWithBypassVoiceProcessing:(BOOL)bypassVoiceProcessing
encoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
Expand Down
27 changes: 27 additions & 0 deletions sdk/objc/api/peerconnection/RTCRtpCodecCapability+Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2016 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 "RTCRtpCodecCapability.h"

#include "api/rtp_parameters.h"

NS_ASSUME_NONNULL_BEGIN

@interface RTC_OBJC_TYPE (RTCRtpCodecCapability)
()

@property(nonatomic, readonly) webrtc::RtpCodecCapability nativeCodecCapability;

- (instancetype)initWithNativeCodecCapability:(const webrtc::RtpCodecCapability &)nativeCodecCapability
NS_DESIGNATED_INITIALIZER;

@end

NS_ASSUME_NONNULL_END
26 changes: 26 additions & 0 deletions sdk/objc/api/peerconnection/RTCRtpCodecCapability.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2016 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 <Foundation/Foundation.h>

#import "RTCMacros.h"

NS_ASSUME_NONNULL_BEGIN

RTC_OBJC_EXPORT
@interface RTC_OBJC_TYPE (RTCRtpCodecCapability) : NSObject

@property(nonatomic, readonly) NSString *mimeType;

@property(nonatomic, copy) NSString *name;

@end

NS_ASSUME_NONNULL_END
49 changes: 49 additions & 0 deletions sdk/objc/api/peerconnection/RTCRtpCodecCapability.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2016 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 "RTCRtpCodecCapability+Private.h"

#import "RTCMediaStreamTrack.h"
#import "helpers/NSString+StdString.h"

#include "media/base/media_constants.h"
#include "rtc_base/checks.h"

@implementation RTC_OBJC_TYPE (RTCRtpCodecCapability)

@synthesize nativeCodecCapability = _nativeCodecCapability;

- (instancetype)init {
webrtc::RtpCodecCapability nativeCodecCapability;
return [self initWithNativeCodecCapability:nativeCodecCapability];
}

- (instancetype)initWithNativeCodecCapability:(const webrtc::RtpCodecCapability &)nativeCodecCapability {

if (self = [super init]) {
_nativeCodecCapability = nativeCodecCapability;
}

return self;
}

- (NSString *)mimeType {
return [NSString stringWithUTF8String:_nativeCodecCapability.mime_type().c_str()];
}

- (NSString *)name {
return [NSString stringWithUTF8String:_nativeCodecCapability.name.c_str()];
}

- (void)setName:(NSString *)name {
_nativeCodecCapability.name = std::string([name UTF8String]);
}

@end
1 change: 1 addition & 0 deletions sdk/objc/api/peerconnection/RTCRtpCodecParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ RTC_EXTERN const NSString *const kRTCComfortNoiseCodecName;
RTC_EXTERN const NSString *const kRTCVp8CodecName;
RTC_EXTERN const NSString *const kRTCVp9CodecName;
RTC_EXTERN const NSString *const kRTCH264CodecName;
RTC_EXTERN const NSString *const kRTCAv1CodecName;

/** Defined in https://www.w3.org/TR/webrtc/#idl-def-rtcrtpcodecparameters */
RTC_OBJC_EXPORT
Expand Down
1 change: 1 addition & 0 deletions sdk/objc/api/peerconnection/RTCRtpCodecParameters.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
const NSString * const kRTCVp8CodecName = @(cricket::kVp8CodecName);
const NSString * const kRTCVp9CodecName = @(cricket::kVp9CodecName);
const NSString * const kRTCH264CodecName = @(cricket::kH264CodecName);
const NSString * const kRTCAv1CodecName = @(cricket::kAv1CodecName);

@implementation RTC_OBJC_TYPE (RTCRtpCodecParameters)

Expand Down
4 changes: 4 additions & 0 deletions sdk/objc/api/peerconnection/RTCRtpEncodingParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ RTC_OBJC_EXPORT
https://w3c.github.io/webrtc-extensions/#dom-rtcrtpencodingparameters-adaptiveptime */
@property(nonatomic, assign) BOOL adaptiveAudioPacketTime;

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

- (instancetype)init;

@end
Expand Down
7 changes: 7 additions & 0 deletions sdk/objc/api/peerconnection/RTCRtpEncodingParameters.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ @implementation RTC_OBJC_TYPE (RTCRtpEncodingParameters)
@synthesize bitratePriority = _bitratePriority;
@synthesize networkPriority = _networkPriority;
@synthesize adaptiveAudioPacketTime = _adaptiveAudioPacketTime;
@synthesize scalabilityMode = _scalabilityMode;

- (instancetype)init {
webrtc::RtpEncodingParameters nativeParameters;
Expand Down Expand Up @@ -59,6 +60,9 @@ - (instancetype)initWithNativeParameters:
if (nativeParameters.ssrc) {
_ssrc = [NSNumber numberWithUnsignedLong:*nativeParameters.ssrc];
}
if (nativeParameters.scalability_mode) {
_scalabilityMode = [NSString stringWithUTF8String:nativeParameters.scalability_mode->c_str()];
}
_bitratePriority = nativeParameters.bitrate_priority;
_networkPriority = [RTC_OBJC_TYPE(RTCRtpEncodingParameters)
priorityFromNativePriority:nativeParameters.network_priority];
Expand Down Expand Up @@ -92,6 +96,9 @@ - (instancetype)initWithNativeParameters:
if (_ssrc != nil) {
parameters.ssrc = absl::optional<uint32_t>(_ssrc.unsignedLongValue);
}
if (_scalabilityMode != nil) {
parameters.scalability_mode = absl::optional<std::string>(std::string([_scalabilityMode UTF8String]));
}
parameters.bitrate_priority = _bitratePriority;
parameters.network_priority =
[RTC_OBJC_TYPE(RTCRtpEncodingParameters) nativePriorityFromPriority:_networkPriority];
Expand Down
5 changes: 5 additions & 0 deletions sdk/objc/api/peerconnection/RTCRtpTransceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#import "RTCRtpReceiver.h"
#import "RTCRtpSender.h"

@class RTC_OBJC_TYPE(RTCRtpCodecCapability);

NS_ASSUME_NONNULL_BEGIN

extern NSString *const kRTCRtpTransceiverErrorDomain;
Expand Down Expand Up @@ -104,6 +106,9 @@ RTC_OBJC_EXPORT
*/
@property(nonatomic, readonly) RTCRtpTransceiverDirection direction;

// NSArray<RTC_OBJC_TYPE(RTCRtpEncodingParameters) *> *
@property(nonatomic, copy) NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *codecPreferences;

/** The currentDirection attribute indicates the current direction negotiated
* for this transceiver. If this transceiver has never been represented in an
* offer/answer exchange, or if the transceiver is stopped, the value is not
Expand Down
31 changes: 31 additions & 0 deletions sdk/objc/api/peerconnection/RTCRtpTransceiver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#import "RTCRtpParameters+Private.h"
#import "RTCRtpReceiver+Private.h"
#import "RTCRtpSender+Private.h"
#import "RTCRtpCodecCapability.h"
#import "RTCRtpCodecCapability+Private.h"
#import "base/RTCLogging.h"
#import "helpers/NSString+StdString.h"

Expand Down Expand Up @@ -65,6 +67,35 @@ - (NSString *)mid {
}
}

- (void)setCodecPreferences:(NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *)codecPreferences {

std::vector<webrtc::RtpCodecCapability> objects;

for (RTCRtpCodecCapability *object in codecPreferences) {
objects.push_back(object.nativeCodecCapability);
}

webrtc::RTCError e = _nativeRtpTransceiver->SetCodecPreferences(rtc::ArrayView<webrtc::RtpCodecCapability>(objects.data(), objects.size()));

if (!e.ok()) {
[NSException raise:@"WebRTC error" format:[NSString stringWithUTF8String: e.message()]];
}
}

- (NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *)codecPreferences {

NSMutableArray *result = [NSMutableArray array];

std::vector<webrtc::RtpCodecCapability> capabilities = _nativeRtpTransceiver->codec_preferences();

for (auto & element : capabilities) {
RTCRtpCodecCapability *object = [[RTCRtpCodecCapability alloc] initWithNativeCodecCapability: element];
[result addObject: object];
}

return result;
}

@synthesize sender = _sender;
@synthesize receiver = _receiver;

Expand Down