Skip to content

Commit 0228e1d

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). Co-authored-by: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com>
1 parent 61fc7d6 commit 0228e1d

24 files changed

+999
-236
lines changed

media/engine/webrtc_video_engine.cc

+7-10
Original file line numberDiff line numberDiff line change
@@ -642,18 +642,15 @@ WebRtcVideoEngine::GetRtpHeaderExtensions() const {
642642
webrtc::RtpExtension::kVideoContentTypeUri,
643643
webrtc::RtpExtension::kVideoTimingUri,
644644
webrtc::RtpExtension::kColorSpaceUri, webrtc::RtpExtension::kMidUri,
645-
webrtc::RtpExtension::kRidUri, webrtc::RtpExtension::kRepairedRidUri}) {
645+
webrtc::RtpExtension::kRidUri, webrtc::RtpExtension::kRepairedRidUri,
646+
// "WebRTC-DependencyDescriptorAdvertised"
647+
webrtc::RtpExtension::kDependencyDescriptorUri}) {
646648
result.emplace_back(uri, id++, webrtc::RtpTransceiverDirection::kSendRecv);
647649
}
648650
result.emplace_back(webrtc::RtpExtension::kGenericFrameDescriptorUri00, id++,
649651
IsEnabled(trials_, "WebRTC-GenericDescriptorAdvertised")
650652
? webrtc::RtpTransceiverDirection::kSendRecv
651653
: webrtc::RtpTransceiverDirection::kStopped);
652-
result.emplace_back(
653-
webrtc::RtpExtension::kDependencyDescriptorUri, id++,
654-
IsEnabled(trials_, "WebRTC-DependencyDescriptorAdvertised")
655-
? webrtc::RtpTransceiverDirection::kSendRecv
656-
: webrtc::RtpTransceiverDirection::kStopped);
657654

658655
result.emplace_back(
659656
webrtc::RtpExtension::kVideoLayersAllocationUri, id++,
@@ -931,7 +928,7 @@ void WebRtcVideoChannel::RequestEncoderSwitch(
931928
void WebRtcVideoChannel::StartReceive(uint32_t ssrc) {
932929
RTC_DCHECK_RUN_ON(&thread_checker_);
933930
WebRtcVideoReceiveStream* stream = FindReceiveStream(ssrc);
934-
if(!stream) {
931+
if (!stream) {
935932
return;
936933
}
937934
stream->StartStream();
@@ -940,7 +937,7 @@ void WebRtcVideoChannel::StartReceive(uint32_t ssrc) {
940937
void WebRtcVideoChannel::StopReceive(uint32_t ssrc) {
941938
RTC_DCHECK_RUN_ON(&thread_checker_);
942939
WebRtcVideoReceiveStream* stream = FindReceiveStream(ssrc);
943-
if(!stream) {
940+
if (!stream) {
944941
return;
945942
}
946943
stream->StopStream();
@@ -3200,12 +3197,12 @@ void WebRtcVideoChannel::WebRtcVideoReceiveStream::SetRecvParameters(
32003197
}
32013198
}
32023199

3203-
void WebRtcVideoChannel::WebRtcVideoReceiveStream::StartStream(){
3200+
void WebRtcVideoChannel::WebRtcVideoReceiveStream::StartStream() {
32043201
if (stream_) {
32053202
stream_->Start();
32063203
}
32073204
}
3208-
void WebRtcVideoChannel::WebRtcVideoReceiveStream::StopStream(){
3205+
void WebRtcVideoChannel::WebRtcVideoReceiveStream::StopStream() {
32093206
if (stream_) {
32103207
stream_->Stop();
32113208
}

sdk/BUILD.gn

+17-5
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,15 @@ if (is_ios || is_mac) {
143143
"objc/helpers/RTCDispatcher+Private.h",
144144
"objc/helpers/RTCDispatcher.h",
145145
"objc/helpers/RTCDispatcher.m",
146+
"objc/helpers/RTCYUVHelper.h",
147+
"objc/helpers/RTCYUVHelper.mm",
146148
"objc/helpers/scoped_cftyperef.h",
147149
]
148150

149151
deps = [
150152
":base_objc",
151153
"../rtc_base:checks",
154+
"//third_party/libyuv",
152155
]
153156

154157
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
@@ -635,17 +638,13 @@ if (is_ios || is_mac) {
635638
"Metal.framework",
636639
"MetalKit.framework",
637640
]
638-
if (is_ios) {
641+
if (is_ios || is_mac) {
639642
sources += [
640643
"objc/components/renderer/metal/RTCMTLVideoView.h",
641644
"objc/components/renderer/metal/RTCMTLVideoView.m",
642645
]
643646
}
644647
if (is_mac) {
645-
sources += [
646-
"objc/components/renderer/metal/RTCMTLNSVideoView.h",
647-
"objc/components/renderer/metal/RTCMTLNSVideoView.m",
648-
]
649648
frameworks += [ "AppKit.framework" ]
650649
}
651650
deps = [
@@ -1032,6 +1031,12 @@ if (is_ios || is_mac) {
10321031
"objc/api/peerconnection/RTCRtcpParameters+Private.h",
10331032
"objc/api/peerconnection/RTCRtcpParameters.h",
10341033
"objc/api/peerconnection/RTCRtcpParameters.mm",
1034+
"objc/api/peerconnection/RTCRtpCapabilities.h",
1035+
"objc/api/peerconnection/RTCRtpCapabilities.mm",
1036+
"objc/api/peerconnection/RTCRtpCapabilities+Private.h",
1037+
"objc/api/peerconnection/RTCRtpCodecCapability.h",
1038+
"objc/api/peerconnection/RTCRtpCodecCapability.mm",
1039+
"objc/api/peerconnection/RTCRtpCodecCapability+Private.h",
10351040
"objc/api/peerconnection/RTCRtpCodecParameters+Private.h",
10361041
"objc/api/peerconnection/RTCRtpCodecParameters.h",
10371042
"objc/api/peerconnection/RTCRtpCodecParameters.mm",
@@ -1329,6 +1334,7 @@ if (is_ios || is_mac) {
13291334
"objc/components/video_frame_buffer/RTCCVPixelBuffer.h",
13301335
"objc/helpers/RTCCameraPreviewView.h",
13311336
"objc/helpers/RTCDispatcher.h",
1337+
"objc/helpers/RTCYUVHelper.h",
13321338
"objc/helpers/UIDevice+RTCDevice.h",
13331339
"objc/api/peerconnection/RTCAudioDeviceModule.h",
13341340
"objc/api/peerconnection/RTCIODevice.h",
@@ -1352,6 +1358,8 @@ if (is_ios || is_mac) {
13521358
"objc/api/peerconnection/RTCPeerConnectionFactory.h",
13531359
"objc/api/peerconnection/RTCPeerConnectionFactoryOptions.h",
13541360
"objc/api/peerconnection/RTCRtcpParameters.h",
1361+
"objc/api/peerconnection/RTCRtpCapabilities.h",
1362+
"objc/api/peerconnection/RTCRtpCodecCapability.h",
13551363
"objc/api/peerconnection/RTCRtpCodecParameters.h",
13561364
"objc/api/peerconnection/RTCRtpEncodingParameters.h",
13571365
"objc/api/peerconnection/RTCRtpHeaderExtension.h",
@@ -1474,6 +1482,8 @@ if (is_ios || is_mac) {
14741482
"objc/api/peerconnection/RTCPeerConnectionFactory.h",
14751483
"objc/api/peerconnection/RTCPeerConnectionFactoryOptions.h",
14761484
"objc/api/peerconnection/RTCRtcpParameters.h",
1485+
"objc/api/peerconnection/RTCRtpCapabilities.h",
1486+
"objc/api/peerconnection/RTCRtpCodecCapability.h",
14771487
"objc/api/peerconnection/RTCRtpCodecParameters.h",
14781488
"objc/api/peerconnection/RTCRtpEncodingParameters.h",
14791489
"objc/api/peerconnection/RTCRtpHeaderExtension.h",
@@ -1517,6 +1527,7 @@ if (is_ios || is_mac) {
15171527
"objc/base/RTCYUVPlanarBuffer.h",
15181528
"objc/components/capturer/RTCCameraVideoCapturer.h",
15191529
"objc/components/capturer/RTCFileVideoCapturer.h",
1530+
"objc/components/renderer/metal/RTCMTLVideoView.h",
15201531
"objc/components/renderer/metal/RTCMTLNSVideoView.h",
15211532
"objc/components/renderer/opengl/RTCNSGLVideoView.h",
15221533
"objc/components/renderer/opengl/RTCVideoViewShading.h",
@@ -1530,6 +1541,7 @@ if (is_ios || is_mac) {
15301541
"objc/components/video_codec/RTCVideoEncoderH264.h",
15311542
"objc/components/video_frame_buffer/RTCCVPixelBuffer.h",
15321543
"objc/helpers/RTCDispatcher.h",
1544+
"objc/helpers/RTCYUVHelper.h",
15331545
# Added for Simulcast support
15341546
"objc/components/video_codec/RTCVideoEncoderFactorySimulcast.h",
15351547
"objc/api/video_codec/RTCVideoEncoderSimulcast.h",

sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ NS_ASSUME_NONNULL_BEGIN
2424
@class RTC_OBJC_TYPE(RTCVideoTrack);
2525
@class RTC_OBJC_TYPE(RTCPeerConnectionFactoryOptions);
2626
@class RTC_OBJC_TYPE(RTCAudioDeviceModule);
27+
@class RTC_OBJC_TYPE(RTCRtpCapabilities);
28+
29+
typedef NS_ENUM(NSInteger, RTCRtpMediaType);
30+
2731
@protocol RTC_OBJC_TYPE
2832
(RTCPeerConnectionDelegate);
2933
@protocol RTC_OBJC_TYPE
@@ -61,6 +65,10 @@ RTC_OBJC_EXPORT
6165

6266
@property(nonatomic, readonly) RTCAudioDeviceModule *audioDeviceModule;
6367

68+
- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpSenderCapabilitiesFor:(RTCRtpMediaType)mediaType;
69+
70+
- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpReceiverCapabilitiesFor:(RTCRtpMediaType)mediaType;
71+
6472
/** Initialize an RTCAudioSource with constraints. */
6573
- (RTC_OBJC_TYPE(RTCAudioSource) *)audioSourceWithConstraints:
6674
(nullable RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints;

sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm

+17
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#import "RTCPeerConnection+Private.h"
2525
#import "RTCVideoSource+Private.h"
2626
#import "RTCVideoTrack+Private.h"
27+
#import "RTCRtpReceiver+Private.h"
28+
#import "RTCRtpCapabilities+Private.h"
29+
#import "RTCRtpCodecCapability+Private.h"
2730
#import "base/RTCLogging.h"
2831
#import "base/RTCVideoDecoderFactory.h"
2932
#import "base/RTCVideoEncoderFactory.h"
@@ -124,6 +127,20 @@ - (instancetype)init {
124127
#endif
125128
}
126129

130+
- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpSenderCapabilitiesFor:(RTCRtpMediaType)mediaType {
131+
132+
webrtc::RtpCapabilities capabilities = _nativeFactory->GetRtpSenderCapabilities([RTCRtpReceiver nativeMediaTypeForMediaType: mediaType]);
133+
134+
return [[RTCRtpCapabilities alloc] initWithNativeCapabilities: capabilities];
135+
}
136+
137+
- (RTC_OBJC_TYPE(RTCRtpCapabilities) *)rtpReceiverCapabilitiesFor:(RTCRtpMediaType)mediaType {
138+
139+
webrtc::RtpCapabilities capabilities = _nativeFactory->GetRtpReceiverCapabilities([RTCRtpReceiver nativeMediaTypeForMediaType: mediaType]);
140+
141+
return [[RTCRtpCapabilities alloc] initWithNativeCapabilities: capabilities];
142+
}
143+
127144
- (instancetype)
128145
initWithBypassVoiceProcessing:(BOOL)bypassVoiceProcessing
129146
encoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2023 LiveKit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import "RTCRtpCapabilities.h"
18+
19+
#include "api/rtp_parameters.h"
20+
21+
NS_ASSUME_NONNULL_BEGIN
22+
23+
@interface RTC_OBJC_TYPE (RTCRtpCapabilities)
24+
()
25+
26+
@property(nonatomic, readonly) webrtc::RtpCapabilities nativeCapabilities;
27+
28+
- (instancetype)initWithNativeCapabilities:(const webrtc::RtpCapabilities &)nativeCapabilities
29+
NS_DESIGNATED_INITIALIZER;
30+
31+
@end
32+
33+
NS_ASSUME_NONNULL_END
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2023 LiveKit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
#import "RTCMacros.h"
20+
21+
@class RTC_OBJC_TYPE(RTCRtpCodecCapability);
22+
23+
NS_ASSUME_NONNULL_BEGIN
24+
25+
RTC_OBJC_EXPORT
26+
@interface RTC_OBJC_TYPE (RTCRtpCapabilities) : NSObject
27+
28+
- (instancetype)init NS_UNAVAILABLE;
29+
30+
@property(nonatomic, readonly) NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *codecs;
31+
32+
// Not implemented.
33+
// std::vector<RtpHeaderExtensionCapability> header_extensions;
34+
35+
// Not implemented.
36+
// std::vector<FecMechanism> fec;
37+
38+
@end
39+
40+
NS_ASSUME_NONNULL_END
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2023 LiveKit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import "RTCRtpCapabilities+Private.h"
18+
#import "RTCRtpCodecCapability+Private.h"
19+
20+
#import "RTCMediaStreamTrack.h"
21+
#import "helpers/NSString+StdString.h"
22+
23+
#include "media/base/media_constants.h"
24+
#include "rtc_base/checks.h"
25+
26+
@implementation RTC_OBJC_TYPE (RTCRtpCapabilities)
27+
28+
@synthesize nativeCapabilities = _nativeCapabilities;
29+
30+
- (instancetype)initWithNativeCapabilities:(const webrtc::RtpCapabilities &)nativeCapabilities {
31+
if (self = [super init]) {
32+
_nativeCapabilities = nativeCapabilities;
33+
}
34+
35+
return self;
36+
}
37+
38+
- (NSArray<RTC_OBJC_TYPE(RTCRtpCodecCapability) *> *)codecs {
39+
NSMutableArray *result = [NSMutableArray array];
40+
41+
for (auto &element : _nativeCapabilities.codecs) {
42+
RTCRtpCodecCapability *object =
43+
[[RTCRtpCodecCapability alloc] initWithNativeCodecCapability:element];
44+
[result addObject:object];
45+
}
46+
47+
return result;
48+
}
49+
50+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2023 LiveKit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import "RTCRtpCodecCapability.h"
18+
19+
#include "api/rtp_parameters.h"
20+
21+
NS_ASSUME_NONNULL_BEGIN
22+
23+
@interface RTC_OBJC_TYPE (RTCRtpCodecCapability)
24+
()
25+
26+
@property(nonatomic, readonly) webrtc::RtpCodecCapability nativeCodecCapability;
27+
28+
- (instancetype)initWithNativeCodecCapability:
29+
(const webrtc::RtpCodecCapability &)nativeCodecCapability NS_DESIGNATED_INITIALIZER;
30+
31+
@end
32+
33+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)