Skip to content

Commit

Permalink
[ObjC] Expose properties / methods required for AV1 codec support (#60)
Browse files Browse the repository at this point in the history
* expose scalabilityMode

* expose AV1 codec name

* sender / receiver capabilities

* setCodecPreferences

* ref

* RTCRtpCapabilities

* kind

* fix compile warnings

* clean up

* lk header

* clockRate

* preferredPayloadType

* numChannels

* parameters

* Update RTCRtpCodecCapability.h

* format

* format

* always include kDependencyDescriptorUri

* clean up

* don't throw when setCodecPreferences fails

* unused variable
  • Loading branch information
hiroshihorie authored and cloudwebrtc committed Jan 18, 2023
1 parent 8670af4 commit d79d77e
Show file tree
Hide file tree
Showing 16 changed files with 451 additions and 10 deletions.
17 changes: 7 additions & 10 deletions media/engine/webrtc_video_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -645,18 +645,15 @@ WebRtcVideoEngine::GetRtpHeaderExtensions() const {
webrtc::RtpExtension::kVideoContentTypeUri,
webrtc::RtpExtension::kVideoTimingUri,
webrtc::RtpExtension::kColorSpaceUri, webrtc::RtpExtension::kMidUri,
webrtc::RtpExtension::kRidUri, webrtc::RtpExtension::kRepairedRidUri}) {
webrtc::RtpExtension::kRidUri, webrtc::RtpExtension::kRepairedRidUri,
// "WebRTC-DependencyDescriptorAdvertised"
webrtc::RtpExtension::kDependencyDescriptorUri}) {
result.emplace_back(uri, id++, webrtc::RtpTransceiverDirection::kSendRecv);
}
result.emplace_back(webrtc::RtpExtension::kGenericFrameDescriptorUri00, id++,
IsEnabled(trials_, "WebRTC-GenericDescriptorAdvertised")
? webrtc::RtpTransceiverDirection::kSendRecv
: webrtc::RtpTransceiverDirection::kStopped);
result.emplace_back(
webrtc::RtpExtension::kDependencyDescriptorUri, id++,
IsEnabled(trials_, "WebRTC-DependencyDescriptorAdvertised")
? webrtc::RtpTransceiverDirection::kSendRecv
: webrtc::RtpTransceiverDirection::kStopped);

result.emplace_back(
webrtc::RtpExtension::kVideoLayersAllocationUri, id++,
Expand Down Expand Up @@ -939,7 +936,7 @@ void WebRtcVideoChannel::RequestEncoderSwitch(
void WebRtcVideoChannel::StartReceive(uint32_t ssrc) {
RTC_DCHECK_RUN_ON(&thread_checker_);
WebRtcVideoReceiveStream* stream = FindReceiveStream(ssrc);
if(!stream) {
if (!stream) {
return;
}
stream->StartStream();
Expand All @@ -948,7 +945,7 @@ void WebRtcVideoChannel::StartReceive(uint32_t ssrc) {
void WebRtcVideoChannel::StopReceive(uint32_t ssrc) {
RTC_DCHECK_RUN_ON(&thread_checker_);
WebRtcVideoReceiveStream* stream = FindReceiveStream(ssrc);
if(!stream) {
if (!stream) {
return;
}
stream->StopStream();
Expand Down Expand Up @@ -3161,12 +3158,12 @@ void WebRtcVideoChannel::WebRtcVideoReceiveStream::SetRecvParameters(
}
}

void WebRtcVideoChannel::WebRtcVideoReceiveStream::StartStream(){
void WebRtcVideoChannel::WebRtcVideoReceiveStream::StartStream() {
if (stream_) {
stream_->Start();
}
}
void WebRtcVideoChannel::WebRtcVideoReceiveStream::StopStream(){
void WebRtcVideoChannel::WebRtcVideoReceiveStream::StopStream() {
if (stream_) {
stream_->Stop();
}
Expand Down
10 changes: 10 additions & 0 deletions sdk/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,12 @@ if (is_ios || is_mac) {
"objc/api/peerconnection/RTCRtcpParameters+Private.h",
"objc/api/peerconnection/RTCRtcpParameters.h",
"objc/api/peerconnection/RTCRtcpParameters.mm",
"objc/api/peerconnection/RTCRtpCapabilities.h",
"objc/api/peerconnection/RTCRtpCapabilities.mm",
"objc/api/peerconnection/RTCRtpCapabilities+Private.h",
"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 +1388,8 @@ if (is_ios || is_mac) {
"objc/api/peerconnection/RTCPeerConnectionFactory.h",
"objc/api/peerconnection/RTCPeerConnectionFactoryOptions.h",
"objc/api/peerconnection/RTCRtcpParameters.h",
"objc/api/peerconnection/RTCRtpCapabilities.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 @@ -1500,6 +1508,8 @@ if (is_ios || is_mac) {
"objc/api/peerconnection/RTCPeerConnectionFactory.h",
"objc/api/peerconnection/RTCPeerConnectionFactoryOptions.h",
"objc/api/peerconnection/RTCRtcpParameters.h",
"objc/api/peerconnection/RTCRtpCapabilities.h",
"objc/api/peerconnection/RTCRtpCodecCapability.h",
"objc/api/peerconnection/RTCRtpCodecParameters.h",
"objc/api/peerconnection/RTCRtpEncodingParameters.h",
"objc/api/peerconnection/RTCRtpHeaderExtension.h",
Expand Down
11 changes: 11 additions & 0 deletions sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ NS_ASSUME_NONNULL_BEGIN
@class RTC_OBJC_TYPE(RTCVideoSource);
@class RTC_OBJC_TYPE(RTCVideoTrack);
@class RTC_OBJC_TYPE(RTCPeerConnectionFactoryOptions);
@class RTC_OBJC_TYPE(RTCAudioDeviceModule);
@class RTC_OBJC_TYPE(RTCRtpCapabilities);

typedef NS_ENUM(NSInteger, RTCRtpMediaType);

@protocol RTC_OBJC_TYPE
(RTCPeerConnectionDelegate);
@protocol RTC_OBJC_TYPE
Expand Down Expand Up @@ -58,6 +63,12 @@ RTC_OBJC_EXPORT
decoderFactory:
(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)decoderFactory;

@property(nonatomic, readonly) RTCAudioDeviceModule *audioDeviceModule;

- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpSenderCapabilitiesFor:(RTCRtpMediaType)mediaType;

- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpReceiverCapabilitiesFor:(RTCRtpMediaType)mediaType;

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

- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpSenderCapabilitiesFor:(RTCRtpMediaType)mediaType {

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

return [[RTCRtpCapabilities alloc] initWithNativeCapabilities: capabilities];
}

- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpReceiverCapabilitiesFor:(RTCRtpMediaType)mediaType {

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

return [[RTCRtpCapabilities alloc] initWithNativeCapabilities: capabilities];
}

- (instancetype)
initWithBypassVoiceProcessing:(BOOL)bypassVoiceProcessing
encoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
Expand Down
33 changes: 33 additions & 0 deletions sdk/objc/api/peerconnection/RTCRtpCapabilities+Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2023 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "RTCRtpCapabilities.h"

#include "api/rtp_parameters.h"

NS_ASSUME_NONNULL_BEGIN

@interface RTC_OBJC_TYPE (RTCRtpCapabilities)
()

@property(nonatomic, readonly) webrtc::RtpCapabilities nativeCapabilities;

- (instancetype)initWithNativeCapabilities:(const webrtc::RtpCapabilities &)nativeCapabilities
NS_DESIGNATED_INITIALIZER;

@end

NS_ASSUME_NONNULL_END
40 changes: 40 additions & 0 deletions sdk/objc/api/peerconnection/RTCRtpCapabilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2023 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>

#import "RTCMacros.h"

@class RTC_OBJC_TYPE(RTCRtpCodecCapability);

NS_ASSUME_NONNULL_BEGIN

RTC_OBJC_EXPORT
@interface RTC_OBJC_TYPE (RTCRtpCapabilities) : NSObject

- (instancetype)init NS_UNAVAILABLE;

@property(nonatomic, readonly) NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *codecs;

// Not implemented.
// std::vector<RtpHeaderExtensionCapability> header_extensions;

// Not implemented.
// std::vector<FecMechanism> fec;

@end

NS_ASSUME_NONNULL_END
50 changes: 50 additions & 0 deletions sdk/objc/api/peerconnection/RTCRtpCapabilities.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2023 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "RTCRtpCapabilities+Private.h"
#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 (RTCRtpCapabilities)

@synthesize nativeCapabilities = _nativeCapabilities;

- (instancetype)initWithNativeCapabilities:(const webrtc::RtpCapabilities &)nativeCapabilities {
if (self = [super init]) {
_nativeCapabilities = nativeCapabilities;
}

return self;
}

- (NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *)codecs {
NSMutableArray *result = [NSMutableArray array];

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

return result;
}

@end
33 changes: 33 additions & 0 deletions sdk/objc/api/peerconnection/RTCRtpCodecCapability+Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2023 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#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
63 changes: 63 additions & 0 deletions sdk/objc/api/peerconnection/RTCRtpCodecCapability.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2023 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>

#import "RTCMacros.h"

typedef NS_ENUM(NSInteger, RTCRtpMediaType);

NS_ASSUME_NONNULL_BEGIN

RTC_OBJC_EXPORT
@interface RTC_OBJC_TYPE (RTCRtpCodecCapability) : NSObject

// Build MIME "type/subtype" string from `name` and `kind`.
@property(nonatomic, readonly) NSString *mimeType;

// Used to identify the codec. Equivalent to MIME subtype.
@property(nonatomic, copy) NSString *name;

// The media type of this codec. Equivalent to MIME top-level type.
@property(nonatomic, assign) RTCRtpMediaType kind;

// Clock rate in Hertz. If unset, the codec is applicable to any clock rate.
@property(nonatomic, copy, nullable) NSNumber *clockRate;

// Default payload type for this codec. Mainly needed for codecs that use
// that have statically assigned payload types.
@property(nonatomic, copy, nullable) NSNumber *preferredPayloadType;

// The number of audio channels supported. Unused for video codecs.
@property(nonatomic, copy, nullable) NSNumber *numChannels;

// Codec-specific parameters that must be signaled to the remote party.
//
// Corresponds to "a=fmtp" parameters in SDP.
//
// Contrary to ORTC, these parameters are named using all lowercase strings.
// This helps make the mapping to SDP simpler, if an application is using SDP.
// Boolean values are represented by the string "1".
// std::map<std::string, std::string> parameters;
@property(nonatomic, copy) NSDictionary<NSString *, NSString *> *parameters;

// Feedback mechanisms supported for this codec.
// std::vector<RtcpFeedback> rtcp_feedback;
// Not implemented.

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit d79d77e

Please sign in to comment.