Add support for injecting VideoBitrateAllocatorFactory also on IOS
This patch exposes webrtc::PeerConnectionDependencies c++-object and makes it possible to supply one when creating a PeerConnection. This makes it possible to e.g inject a VideoBitrateAllocatorFactory. Bug: webrtc:10547 Change-Id: Ib7431bdcec1380e7903dc5f66f3583501aeab0a5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168307 Commit-Queue: Jonas Oreland <jonaso@webrtc.org> Reviewed-by: Anders Carlsson <andersc@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30480}
This commit is contained in:
committed by
Commit Bot
parent
56e611bbda
commit
285f83d47b
@ -78,7 +78,17 @@ class PeerConnectionDelegateAdapter : public PeerConnectionObserver {
|
||||
- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
|
||||
configuration:(RTCConfiguration *)configuration
|
||||
constraints:(RTCMediaConstraints *)constraints
|
||||
delegate:(nullable id<RTCPeerConnectionDelegate>)delegate
|
||||
delegate:(nullable id<RTCPeerConnectionDelegate>)delegate;
|
||||
|
||||
/** Initialize an RTCPeerConnection with a configuration, constraints,
|
||||
* delegate and PeerConnectionDependencies.
|
||||
*/
|
||||
- (instancetype)initWithDependencies:(RTCPeerConnectionFactory *)factory
|
||||
configuration:(RTCConfiguration *)configuration
|
||||
constraints:(RTCMediaConstraints *)constraints
|
||||
dependencies:
|
||||
(std::unique_ptr<webrtc::PeerConnectionDependencies>)dependencies
|
||||
delegate:(nullable id<RTCPeerConnectionDelegate>)delegate
|
||||
NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
+ (webrtc::PeerConnectionInterface::SignalingState)nativeSignalingStateForState:
|
||||
|
||||
@ -307,6 +307,23 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
|
||||
constraints:(RTCMediaConstraints *)constraints
|
||||
delegate:(id<RTCPeerConnectionDelegate>)delegate {
|
||||
NSParameterAssert(factory);
|
||||
std::unique_ptr<webrtc::PeerConnectionDependencies> dependencies =
|
||||
std::make_unique<webrtc::PeerConnectionDependencies>(nullptr);
|
||||
return [self initWithDependencies:factory
|
||||
configuration:configuration
|
||||
constraints:constraints
|
||||
dependencies:std::move(dependencies)
|
||||
delegate:delegate];
|
||||
}
|
||||
|
||||
- (instancetype)initWithDependencies:(RTCPeerConnectionFactory *)factory
|
||||
configuration:(RTCConfiguration *)configuration
|
||||
constraints:(RTCMediaConstraints *)constraints
|
||||
dependencies:
|
||||
(std::unique_ptr<webrtc::PeerConnectionDependencies>)dependencies
|
||||
delegate:(id<RTCPeerConnectionDelegate>)delegate {
|
||||
NSParameterAssert(factory);
|
||||
NSParameterAssert(dependencies.get());
|
||||
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config(
|
||||
[configuration createNativeConfiguration]);
|
||||
if (!config) {
|
||||
@ -315,13 +332,12 @@ void PeerConnectionDelegateAdapter::OnRemoveTrack(
|
||||
if (self = [super init]) {
|
||||
_observer.reset(new webrtc::PeerConnectionDelegateAdapter(self));
|
||||
_nativeConstraints = constraints.nativeConstraints;
|
||||
CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(),
|
||||
config.get());
|
||||
_peerConnection =
|
||||
factory.nativeFactory->CreatePeerConnection(*config,
|
||||
nullptr,
|
||||
nullptr,
|
||||
_observer.get());
|
||||
CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(), config.get());
|
||||
|
||||
webrtc::PeerConnectionDependencies deps = std::move(*dependencies.release());
|
||||
deps.observer = _observer.get();
|
||||
_peerConnection = factory.nativeFactory->CreatePeerConnection(*config, std::move(deps));
|
||||
|
||||
if (!_peerConnection) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ class NetworkControllerFactoryInterface;
|
||||
class VideoEncoderFactory;
|
||||
class VideoDecoderFactory;
|
||||
class AudioProcessing;
|
||||
struct PeerConnectionDependencies;
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -87,6 +88,16 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
decoderFactory:(nullable id<RTCVideoDecoderFactory>)decoderFactory
|
||||
mediaTransportFactory:
|
||||
(std::unique_ptr<webrtc::MediaTransportFactory>)mediaTransportFactory;
|
||||
|
||||
/** Initialize an RTCPeerConnection with a configuration, constraints, and
|
||||
* dependencies.
|
||||
*/
|
||||
- (RTCPeerConnection *)
|
||||
peerConnectionWithDependencies:(RTCConfiguration *)configuration
|
||||
constraints:(RTCMediaConstraints *)constraints
|
||||
dependencies:(std::unique_ptr<webrtc::PeerConnectionDependencies>)dependencies
|
||||
delegate:(nullable id<RTCPeerConnectionDelegate>)delegate;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@ -296,6 +296,18 @@
|
||||
delegate:delegate];
|
||||
}
|
||||
|
||||
- (RTCPeerConnection *)
|
||||
peerConnectionWithDependencies:(RTCConfiguration *)configuration
|
||||
constraints:(RTCMediaConstraints *)constraints
|
||||
dependencies:(std::unique_ptr<webrtc::PeerConnectionDependencies>)dependencies
|
||||
delegate:(id<RTCPeerConnectionDelegate>)delegate {
|
||||
return [[RTCPeerConnection alloc] initWithDependencies:self
|
||||
configuration:configuration
|
||||
constraints:constraints
|
||||
dependencies:std::move(dependencies)
|
||||
delegate:delegate];
|
||||
}
|
||||
|
||||
- (void)setOptions:(nonnull RTCPeerConnectionFactoryOptions *)options {
|
||||
RTC_DCHECK(options != nil);
|
||||
_nativeFactory->SetOptions(options.nativeOptions);
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "rtc_base/gunit.h"
|
||||
@ -20,11 +21,13 @@
|
||||
#import "api/peerconnection/RTCIceServer.h"
|
||||
#import "api/peerconnection/RTCMediaConstraints.h"
|
||||
#import "api/peerconnection/RTCPeerConnection.h"
|
||||
#import "api/peerconnection/RTCPeerConnectionFactory+Native.h"
|
||||
#import "api/peerconnection/RTCPeerConnectionFactory.h"
|
||||
#import "helpers/NSString+StdString.h"
|
||||
|
||||
@interface RTCPeerConnectionTest : NSObject
|
||||
- (void)testConfigurationGetter;
|
||||
- (void)testWithDependencies;
|
||||
@end
|
||||
|
||||
@implementation RTCPeerConnectionTest
|
||||
@ -104,6 +107,29 @@
|
||||
newConfig.cryptoOptions.sframeRequireFrameEncryption);
|
||||
}
|
||||
|
||||
- (void)testWithDependencies {
|
||||
NSArray *urlStrings = @[ @"stun:stun1.example.net" ];
|
||||
RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings];
|
||||
|
||||
RTCConfiguration *config = [[RTCConfiguration alloc] init];
|
||||
config.iceServers = @[ server ];
|
||||
RTCMediaConstraints *contraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:@{}
|
||||
optionalConstraints:nil];
|
||||
RTCPeerConnectionFactory *factory = [[RTCPeerConnectionFactory alloc] init];
|
||||
|
||||
RTCConfiguration *newConfig;
|
||||
std::unique_ptr<webrtc::PeerConnectionDependencies> pc_dependencies =
|
||||
std::make_unique<webrtc::PeerConnectionDependencies>(nullptr);
|
||||
@autoreleasepool {
|
||||
RTCPeerConnection *peerConnection =
|
||||
[factory peerConnectionWithDependencies:config
|
||||
constraints:contraints
|
||||
dependencies:std::move(pc_dependencies)
|
||||
delegate:nil];
|
||||
newConfig = peerConnection.configuration;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
TEST(RTCPeerConnectionTest, ConfigurationGetterTest) {
|
||||
@ -112,3 +138,10 @@ TEST(RTCPeerConnectionTest, ConfigurationGetterTest) {
|
||||
[test testConfigurationGetter];
|
||||
}
|
||||
}
|
||||
|
||||
TEST(RTCPeerConnectionTest, TestWithDependencies) {
|
||||
@autoreleasepool {
|
||||
RTCPeerConnectionTest *test = [[RTCPeerConnectionTest alloc] init];
|
||||
[test testWithDependencies];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user