2016-01-20 13:40:30 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright 2015 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-09-17 17:06:18 +02:00
|
|
|
#include <memory>
|
|
|
|
|
|
2017-08-29 03:57:22 -07:00
|
|
|
#import "RTCPeerConnectionFactory+Native.h"
|
2016-04-27 01:54:20 -07:00
|
|
|
#import "RTCPeerConnectionFactory+Private.h"
|
2018-01-02 13:33:16 +03:00
|
|
|
#import "RTCPeerConnectionFactoryOptions+Private.h"
|
2016-01-20 13:40:30 -08:00
|
|
|
|
2016-08-30 11:56:05 -07:00
|
|
|
#import "RTCAudioSource+Private.h"
|
2016-04-27 01:54:20 -07:00
|
|
|
#import "RTCAudioTrack+Private.h"
|
2016-08-30 11:56:05 -07:00
|
|
|
#import "RTCMediaConstraints+Private.h"
|
2016-04-27 01:54:20 -07:00
|
|
|
#import "RTCMediaStream+Private.h"
|
|
|
|
|
#import "RTCPeerConnection+Private.h"
|
|
|
|
|
#import "RTCVideoSource+Private.h"
|
|
|
|
|
#import "RTCVideoTrack+Private.h"
|
2018-08-30 09:30:29 +02:00
|
|
|
#import "base/RTCLogging.h"
|
|
|
|
|
#import "base/RTCVideoDecoderFactory.h"
|
|
|
|
|
#import "base/RTCVideoEncoderFactory.h"
|
2022-05-13 14:46:42 +00:00
|
|
|
#import "helpers/NSString+StdString.h"
|
2021-10-28 15:49:46 +09:00
|
|
|
#include "rtc_base/checks.h"
|
2020-08-19 16:41:54 -07:00
|
|
|
#include "sdk/objc/native/api/network_monitor_factory.h"
|
2022-03-11 09:22:08 +01:00
|
|
|
#include "sdk/objc/native/api/ssl_certificate_verifier.h"
|
2020-08-19 16:41:54 -07:00
|
|
|
#include "system_wrappers/include/field_trial.h"
|
|
|
|
|
|
2022-06-24 10:00:49 +02:00
|
|
|
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
|
|
|
|
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
|
2019-06-26 15:49:47 +02:00
|
|
|
#include "api/rtc_event_log/rtc_event_log_factory.h"
|
2019-05-17 13:20:14 +02:00
|
|
|
#include "api/task_queue/default_task_queue_factory.h"
|
2020-09-22 11:36:35 +02:00
|
|
|
#include "api/transport/field_trial_based_config.h"
|
2022-06-24 10:00:49 +02:00
|
|
|
#import "components/video_codec/RTCVideoDecoderFactoryH264.h"
|
|
|
|
|
#import "components/video_codec/RTCVideoEncoderFactoryH264.h"
|
|
|
|
|
#include "media/engine/webrtc_media_engine.h"
|
|
|
|
|
#include "modules/audio_device/include/audio_device.h"
|
|
|
|
|
#include "modules/audio_processing/include/audio_processing.h"
|
2018-02-01 15:47:05 +01:00
|
|
|
|
2022-08-29 12:22:35 +02:00
|
|
|
#include "sdk/objc/native/api/objc_audio_device_module.h"
|
2018-08-30 09:30:29 +02:00
|
|
|
#include "sdk/objc/native/api/video_decoder_factory.h"
|
|
|
|
|
#include "sdk/objc/native/api/video_encoder_factory.h"
|
|
|
|
|
#include "sdk/objc/native/src/objc_video_decoder_factory.h"
|
|
|
|
|
#include "sdk/objc/native/src/objc_video_encoder_factory.h"
|
2016-05-01 14:53:46 -07:00
|
|
|
|
2018-05-15 10:22:36 +02:00
|
|
|
#if defined(WEBRTC_IOS)
|
2018-08-30 09:30:29 +02:00
|
|
|
#import "sdk/objc/native/api/audio_device_module.h"
|
2018-05-15 10:22:36 +02:00
|
|
|
#endif
|
|
|
|
|
|
2020-05-04 16:14:32 +02:00
|
|
|
@implementation RTC_OBJC_TYPE (RTCPeerConnectionFactory) {
|
2016-05-17 01:52:02 -07:00
|
|
|
std::unique_ptr<rtc::Thread> _networkThread;
|
2016-05-01 14:53:46 -07:00
|
|
|
std::unique_ptr<rtc::Thread> _workerThread;
|
2016-05-17 01:52:02 -07:00
|
|
|
std::unique_ptr<rtc::Thread> _signalingThread;
|
2016-08-30 12:58:11 -07:00
|
|
|
BOOL _hasStartedAecDump;
|
2016-01-20 13:40:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@synthesize nativeFactory = _nativeFactory;
|
|
|
|
|
|
2018-05-15 10:22:36 +02:00
|
|
|
- (rtc::scoped_refptr<webrtc::AudioDeviceModule>)audioDeviceModule {
|
|
|
|
|
#if defined(WEBRTC_IOS)
|
|
|
|
|
return webrtc::CreateAudioDeviceModule();
|
|
|
|
|
#else
|
|
|
|
|
return nullptr;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-20 13:40:30 -08:00
|
|
|
- (instancetype)init {
|
2020-05-04 16:14:32 +02:00
|
|
|
return [self
|
|
|
|
|
initWithNativeAudioEncoderFactory:webrtc::CreateBuiltinAudioEncoderFactory()
|
|
|
|
|
nativeAudioDecoderFactory:webrtc::CreateBuiltinAudioDecoderFactory()
|
|
|
|
|
nativeVideoEncoderFactory:webrtc::ObjCToNativeVideoEncoderFactory([[RTC_OBJC_TYPE(
|
|
|
|
|
RTCVideoEncoderFactoryH264) alloc] init])
|
|
|
|
|
nativeVideoDecoderFactory:webrtc::ObjCToNativeVideoDecoderFactory([[RTC_OBJC_TYPE(
|
|
|
|
|
RTCVideoDecoderFactoryH264) alloc] init])
|
2022-04-25 10:46:59 +02:00
|
|
|
audioDeviceModule:[self audioDeviceModule].get()
|
2020-06-10 17:36:17 +02:00
|
|
|
audioProcessingModule:nullptr];
|
Reland of Injectable Obj-C video codecs (patchset #1 id:1 of https://codereview.webrtc.org/2980173002/ )
Reason for revert:
Relanding after fixing issues with no video.
Original issue's description:
> Revert of Injectable Obj-C video codecs (patchset #2 id:370001 of https://codereview.webrtc.org/2979983002/ )
>
> Reason for revert:
> Still having problems with no video. Reverting.
> Once no video is visible, no video is available from then on even if the callee app is in the foreground.
>
>
> Original issue's description:
> > Reland of Injectable Obj-C video codecs (patchset #1 id:1 of https://codereview.webrtc.org/2979973002/ )
> >
> > Reason for revert:
> > Fix the broken build file
> >
> > Original issue's description:
> > > Revert of Injectable Obj-C video codecs (patchset #3 id:400001 of https://codereview.webrtc.org/2981583002/ )
> > >
> > > Reason for revert:
> > > Breaks bots. Build file incorrect.
> > >
> > > Original issue's description:
> > > > Reland of Injectable Obj-C video codecs (patchset #1 id:1 of https://codereview.webrtc.org/2975963002/ )
> > > >
> > > > Reason for revert:
> > > > New CL for fixing the issues
> > > >
> > > > Original issue's description:
> > > > > Revert of Injectable Obj-C video codecs (patchset #8 id:140001 of https://codereview.webrtc.org/2966023002/ )
> > > > >
> > > > > Reason for revert:
> > > > > Causes no video in certain scenarios. Please come up with a test plan or unit test to prevent such problems in the future.
> > > > >
> > > > > Original issue's description:
> > > > > > Injectable Obj-C video codecs
> > > > > >
> > > > > > Initial CL for this effort, with a working RTCVideoEncoder/Decoder for H264
> > > > > > (wrapping the VideoToolbox codec).
> > > > > >
> > > > > > Some notes / things left to do:
> > > > > > - There are some hard-coded references to codec types that are supported by
> > > > > > webrtc::VideoCodec, cricket::VideoCodec, webrtc::CodecSpecificInfo etc
> > > > > > since we need to convert to/from these types in ObjCVideoEncoder/Decoder.
> > > > > > These types would need to be more codec agnostic to avoid this.
> > > > > > - Most interfaces are borrowed from the design document for injectable
> > > > > > codecs in Android. Some data in the corresponding C++ classes is discarded
> > > > > > when converting to the Obj-C version, since it has fewer fields. I have not
> > > > > > verified whether all data that we do keep is needed, or whether we might be
> > > > > > losing anything useful in these conversions.
> > > > > > - Implement the VideoToolbox codec code directly in the RTCVideoEncoderH264
> > > > > > classes, instead of wrapping webrtc::H264VideoToolboxEncoder / decoder.
> > > > > > Eliminates converting between ObjC/C++ types outside the ObjCVideoEncoder/
> > > > > > Decoder wrapper classes.
> > > > > > - List the injected codec factory's supported codecs in the list of codecs in
> > > > > > AppRTCMobile.
> > > > > >
> > > > > > BUG=webrtc:7924
> > > > > > R=magjed@webrtc.org
> > > > > >
> > > > > > Review-Url: https://codereview.webrtc.org/2966023002 .
> > > > > > Cr-Commit-Position: refs/heads/master@{#18928}
> > > > > > Committed: https://chromium.googlesource.com/external/webrtc/+/a0349c138db62c52435be84b6c837f5f4758e264
> > > > >
> > > > > TBR=magjed@webrtc.org,andersc@webrtc.org
> > > > > # Not skipping CQ checks because original CL landed more than 1 days ago.
> > > > > BUG=webrtc:7924
> > > > > NOTRY=true
> > > > >
> > > > > Review-Url: https://codereview.webrtc.org/2975963002
> > > > > Cr-Commit-Position: refs/heads/master@{#18979}
> > > > > Committed: https://chromium.googlesource.com/external/webrtc/+/1095ada7ad56fe29b7b2bbc560a8f6475a7978ce
> > > >
> > > > R=magjed@webrtc.org
> > > > TBR=tkchin@webrtc.org
> > > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > > NOPRESUBMIT=true
> > > > NOTREECHECKS=true
> > > > NOTRY=true
> > > > BUG=webrtc:7924
> > > >
> > > > Review-Url: https://codereview.webrtc.org/2981583002 .
> > > > Cr-Commit-Position: refs/heads/master@{#19002}
> > > > Committed: https://chromium.googlesource.com/external/webrtc/+/a5f1de1e6541de03f944bcbf49be87c01f57a18b
> > >
> > > TBR=magjed@webrtc.org,tkchin@webrtc.org,jtteh@webrtc.org,andersc@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:7924
> > >
> > > Review-Url: https://codereview.webrtc.org/2979973002
> > > Cr-Commit-Position: refs/heads/master@{#19004}
> > > Committed: https://chromium.googlesource.com/external/webrtc/+/81d40ee1491d5229c2677cc04b1f40d67c2babef
> >
> > TBR=magjed@webrtc.org,tkchin@webrtc.org,jtteh@webrtc.org,sprang@webrtc.org
> > BUG=webrtc:7924
> >
> > Review-Url: https://codereview.webrtc.org/2979983002
> > Cr-Commit-Position: refs/heads/master@{#19005}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/732a3437da4db7b452758b8e1cf26fce0ce3bf65
>
> TBR=magjed@webrtc.org,tkchin@webrtc.org,sprang@webrtc.org,haysc@webrtc.org,andersc@webrtc.org
> # Not skipping CQ checks because original CL landed more than 1 days ago.
> BUG=webrtc:7924
>
> Review-Url: https://codereview.webrtc.org/2980173002
> Cr-Commit-Position: refs/heads/master@{#19036}
> Committed: https://chromium.googlesource.com/external/webrtc/+/860f7298166084d966749e22b69aa2fdcf4d4ed6
TBR=magjed@webrtc.org,tkchin@webrtc.org,sprang@webrtc.org,haysc@webrtc.org,andersc@webrtc.org,jtteh@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:7924
Review-Url: https://codereview.webrtc.org/2977213002
Cr-Commit-Position: refs/heads/master@{#19135}
2017-07-25 07:55:58 -07:00
|
|
|
}
|
|
|
|
|
|
2020-05-04 16:14:32 +02:00
|
|
|
- (instancetype)
|
|
|
|
|
initWithEncoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
|
2020-06-10 17:36:17 +02:00
|
|
|
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)decoderFactory {
|
2022-08-29 12:22:35 +02:00
|
|
|
return [self initWithEncoderFactory:encoderFactory decoderFactory:decoderFactory audioDevice:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (instancetype)
|
|
|
|
|
initWithEncoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoEncoderFactory)>)encoderFactory
|
|
|
|
|
decoderFactory:(nullable id<RTC_OBJC_TYPE(RTCVideoDecoderFactory)>)decoderFactory
|
|
|
|
|
audioDevice:(nullable id<RTC_OBJC_TYPE(RTCAudioDevice)>)audioDevice {
|
|
|
|
|
#ifdef HAVE_NO_MEDIA
|
|
|
|
|
return [self initWithNoMedia];
|
|
|
|
|
#else
|
2017-10-05 16:55:38 +02:00
|
|
|
std::unique_ptr<webrtc::VideoEncoderFactory> native_encoder_factory;
|
|
|
|
|
std::unique_ptr<webrtc::VideoDecoderFactory> native_decoder_factory;
|
|
|
|
|
if (encoderFactory) {
|
2018-02-01 15:47:05 +01:00
|
|
|
native_encoder_factory = webrtc::ObjCToNativeVideoEncoderFactory(encoderFactory);
|
2017-10-05 16:55:38 +02:00
|
|
|
}
|
|
|
|
|
if (decoderFactory) {
|
2018-02-01 15:47:05 +01:00
|
|
|
native_decoder_factory = webrtc::ObjCToNativeVideoDecoderFactory(decoderFactory);
|
2017-10-05 16:55:38 +02:00
|
|
|
}
|
2022-08-29 12:22:35 +02:00
|
|
|
rtc::scoped_refptr<webrtc::AudioDeviceModule> audio_device_module;
|
|
|
|
|
if (audioDevice) {
|
|
|
|
|
audio_device_module = webrtc::CreateAudioDeviceModule(audioDevice);
|
|
|
|
|
} else {
|
|
|
|
|
audio_device_module = [self audioDeviceModule];
|
|
|
|
|
}
|
2017-08-29 03:57:22 -07:00
|
|
|
return [self initWithNativeAudioEncoderFactory:webrtc::CreateBuiltinAudioEncoderFactory()
|
|
|
|
|
nativeAudioDecoderFactory:webrtc::CreateBuiltinAudioDecoderFactory()
|
2017-10-05 16:55:38 +02:00
|
|
|
nativeVideoEncoderFactory:std::move(native_encoder_factory)
|
2017-10-30 07:50:17 -07:00
|
|
|
nativeVideoDecoderFactory:std::move(native_decoder_factory)
|
2022-08-29 12:22:35 +02:00
|
|
|
audioDeviceModule:audio_device_module.get()
|
2020-06-10 17:36:17 +02:00
|
|
|
audioProcessingModule:nullptr];
|
2022-08-29 12:22:35 +02:00
|
|
|
#endif
|
2017-08-29 03:57:22 -07:00
|
|
|
}
|
2022-08-29 12:22:35 +02:00
|
|
|
|
2017-10-05 16:55:38 +02:00
|
|
|
- (instancetype)initNative {
|
Reland of Injectable Obj-C video codecs (patchset #1 id:1 of https://codereview.webrtc.org/2980173002/ )
Reason for revert:
Relanding after fixing issues with no video.
Original issue's description:
> Revert of Injectable Obj-C video codecs (patchset #2 id:370001 of https://codereview.webrtc.org/2979983002/ )
>
> Reason for revert:
> Still having problems with no video. Reverting.
> Once no video is visible, no video is available from then on even if the callee app is in the foreground.
>
>
> Original issue's description:
> > Reland of Injectable Obj-C video codecs (patchset #1 id:1 of https://codereview.webrtc.org/2979973002/ )
> >
> > Reason for revert:
> > Fix the broken build file
> >
> > Original issue's description:
> > > Revert of Injectable Obj-C video codecs (patchset #3 id:400001 of https://codereview.webrtc.org/2981583002/ )
> > >
> > > Reason for revert:
> > > Breaks bots. Build file incorrect.
> > >
> > > Original issue's description:
> > > > Reland of Injectable Obj-C video codecs (patchset #1 id:1 of https://codereview.webrtc.org/2975963002/ )
> > > >
> > > > Reason for revert:
> > > > New CL for fixing the issues
> > > >
> > > > Original issue's description:
> > > > > Revert of Injectable Obj-C video codecs (patchset #8 id:140001 of https://codereview.webrtc.org/2966023002/ )
> > > > >
> > > > > Reason for revert:
> > > > > Causes no video in certain scenarios. Please come up with a test plan or unit test to prevent such problems in the future.
> > > > >
> > > > > Original issue's description:
> > > > > > Injectable Obj-C video codecs
> > > > > >
> > > > > > Initial CL for this effort, with a working RTCVideoEncoder/Decoder for H264
> > > > > > (wrapping the VideoToolbox codec).
> > > > > >
> > > > > > Some notes / things left to do:
> > > > > > - There are some hard-coded references to codec types that are supported by
> > > > > > webrtc::VideoCodec, cricket::VideoCodec, webrtc::CodecSpecificInfo etc
> > > > > > since we need to convert to/from these types in ObjCVideoEncoder/Decoder.
> > > > > > These types would need to be more codec agnostic to avoid this.
> > > > > > - Most interfaces are borrowed from the design document for injectable
> > > > > > codecs in Android. Some data in the corresponding C++ classes is discarded
> > > > > > when converting to the Obj-C version, since it has fewer fields. I have not
> > > > > > verified whether all data that we do keep is needed, or whether we might be
> > > > > > losing anything useful in these conversions.
> > > > > > - Implement the VideoToolbox codec code directly in the RTCVideoEncoderH264
> > > > > > classes, instead of wrapping webrtc::H264VideoToolboxEncoder / decoder.
> > > > > > Eliminates converting between ObjC/C++ types outside the ObjCVideoEncoder/
> > > > > > Decoder wrapper classes.
> > > > > > - List the injected codec factory's supported codecs in the list of codecs in
> > > > > > AppRTCMobile.
> > > > > >
> > > > > > BUG=webrtc:7924
> > > > > > R=magjed@webrtc.org
> > > > > >
> > > > > > Review-Url: https://codereview.webrtc.org/2966023002 .
> > > > > > Cr-Commit-Position: refs/heads/master@{#18928}
> > > > > > Committed: https://chromium.googlesource.com/external/webrtc/+/a0349c138db62c52435be84b6c837f5f4758e264
> > > > >
> > > > > TBR=magjed@webrtc.org,andersc@webrtc.org
> > > > > # Not skipping CQ checks because original CL landed more than 1 days ago.
> > > > > BUG=webrtc:7924
> > > > > NOTRY=true
> > > > >
> > > > > Review-Url: https://codereview.webrtc.org/2975963002
> > > > > Cr-Commit-Position: refs/heads/master@{#18979}
> > > > > Committed: https://chromium.googlesource.com/external/webrtc/+/1095ada7ad56fe29b7b2bbc560a8f6475a7978ce
> > > >
> > > > R=magjed@webrtc.org
> > > > TBR=tkchin@webrtc.org
> > > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > > NOPRESUBMIT=true
> > > > NOTREECHECKS=true
> > > > NOTRY=true
> > > > BUG=webrtc:7924
> > > >
> > > > Review-Url: https://codereview.webrtc.org/2981583002 .
> > > > Cr-Commit-Position: refs/heads/master@{#19002}
> > > > Committed: https://chromium.googlesource.com/external/webrtc/+/a5f1de1e6541de03f944bcbf49be87c01f57a18b
> > >
> > > TBR=magjed@webrtc.org,tkchin@webrtc.org,jtteh@webrtc.org,andersc@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:7924
> > >
> > > Review-Url: https://codereview.webrtc.org/2979973002
> > > Cr-Commit-Position: refs/heads/master@{#19004}
> > > Committed: https://chromium.googlesource.com/external/webrtc/+/81d40ee1491d5229c2677cc04b1f40d67c2babef
> >
> > TBR=magjed@webrtc.org,tkchin@webrtc.org,jtteh@webrtc.org,sprang@webrtc.org
> > BUG=webrtc:7924
> >
> > Review-Url: https://codereview.webrtc.org/2979983002
> > Cr-Commit-Position: refs/heads/master@{#19005}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/732a3437da4db7b452758b8e1cf26fce0ce3bf65
>
> TBR=magjed@webrtc.org,tkchin@webrtc.org,sprang@webrtc.org,haysc@webrtc.org,andersc@webrtc.org
> # Not skipping CQ checks because original CL landed more than 1 days ago.
> BUG=webrtc:7924
>
> Review-Url: https://codereview.webrtc.org/2980173002
> Cr-Commit-Position: refs/heads/master@{#19036}
> Committed: https://chromium.googlesource.com/external/webrtc/+/860f7298166084d966749e22b69aa2fdcf4d4ed6
TBR=magjed@webrtc.org,tkchin@webrtc.org,sprang@webrtc.org,haysc@webrtc.org,andersc@webrtc.org,jtteh@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:7924
Review-Url: https://codereview.webrtc.org/2977213002
Cr-Commit-Position: refs/heads/master@{#19135}
2017-07-25 07:55:58 -07:00
|
|
|
if (self = [super init]) {
|
2016-05-17 01:52:02 -07:00
|
|
|
_networkThread = rtc::Thread::CreateWithSocketServer();
|
2018-05-01 00:58:43 +03:00
|
|
|
_networkThread->SetName("network_thread", _networkThread.get());
|
2016-05-17 01:52:02 -07:00
|
|
|
BOOL result = _networkThread->Start();
|
2021-10-28 15:49:46 +09:00
|
|
|
RTC_DCHECK(result) << "Failed to start network thread.";
|
2016-05-17 01:52:02 -07:00
|
|
|
|
|
|
|
|
_workerThread = rtc::Thread::Create();
|
2018-05-01 00:58:43 +03:00
|
|
|
_workerThread->SetName("worker_thread", _workerThread.get());
|
2016-01-20 13:40:30 -08:00
|
|
|
result = _workerThread->Start();
|
2021-10-28 15:49:46 +09:00
|
|
|
RTC_DCHECK(result) << "Failed to start worker thread.";
|
2016-01-20 13:40:30 -08:00
|
|
|
|
2016-05-17 01:52:02 -07:00
|
|
|
_signalingThread = rtc::Thread::Create();
|
2018-05-01 00:58:43 +03:00
|
|
|
_signalingThread->SetName("signaling_thread", _signalingThread.get());
|
2016-05-17 01:52:02 -07:00
|
|
|
result = _signalingThread->Start();
|
2021-10-28 15:49:46 +09:00
|
|
|
RTC_DCHECK(result) << "Failed to start signaling thread.";
|
2017-10-05 16:55:38 +02:00
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithNoMedia {
|
|
|
|
|
if (self = [self initNative]) {
|
2019-05-17 13:20:14 +02:00
|
|
|
webrtc::PeerConnectionFactoryDependencies dependencies;
|
|
|
|
|
dependencies.network_thread = _networkThread.get();
|
|
|
|
|
dependencies.worker_thread = _workerThread.get();
|
|
|
|
|
dependencies.signaling_thread = _signalingThread.get();
|
2020-08-19 16:41:54 -07:00
|
|
|
if (webrtc::field_trial::IsEnabled("WebRTC-Network-UseNWPathMonitor")) {
|
|
|
|
|
dependencies.network_monitor_factory = webrtc::CreateNetworkMonitorFactory();
|
|
|
|
|
}
|
2019-05-17 13:20:14 +02:00
|
|
|
_nativeFactory = webrtc::CreateModularPeerConnectionFactory(std::move(dependencies));
|
2017-10-05 16:55:38 +02:00
|
|
|
NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!");
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithNativeAudioEncoderFactory:
|
|
|
|
|
(rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory
|
|
|
|
|
nativeAudioDecoderFactory:
|
|
|
|
|
(rtc::scoped_refptr<webrtc::AudioDecoderFactory>)audioDecoderFactory
|
|
|
|
|
nativeVideoEncoderFactory:
|
|
|
|
|
(std::unique_ptr<webrtc::VideoEncoderFactory>)videoEncoderFactory
|
|
|
|
|
nativeVideoDecoderFactory:
|
2017-10-30 07:50:17 -07:00
|
|
|
(std::unique_ptr<webrtc::VideoDecoderFactory>)videoDecoderFactory
|
2019-04-23 10:24:03 +02:00
|
|
|
audioDeviceModule:(webrtc::AudioDeviceModule *)audioDeviceModule
|
2017-11-13 14:56:02 +01:00
|
|
|
audioProcessingModule:
|
|
|
|
|
(rtc::scoped_refptr<webrtc::AudioProcessing>)audioProcessingModule {
|
2018-10-08 09:43:21 -07:00
|
|
|
return [self initWithNativeAudioEncoderFactory:audioEncoderFactory
|
|
|
|
|
nativeAudioDecoderFactory:audioDecoderFactory
|
|
|
|
|
nativeVideoEncoderFactory:std::move(videoEncoderFactory)
|
|
|
|
|
nativeVideoDecoderFactory:std::move(videoDecoderFactory)
|
|
|
|
|
audioDeviceModule:audioDeviceModule
|
|
|
|
|
audioProcessingModule:audioProcessingModule
|
2020-06-10 17:36:17 +02:00
|
|
|
networkControllerFactory:nullptr];
|
2019-04-23 10:24:03 +02:00
|
|
|
}
|
|
|
|
|
- (instancetype)initWithNativeAudioEncoderFactory:
|
|
|
|
|
(rtc::scoped_refptr<webrtc::AudioEncoderFactory>)audioEncoderFactory
|
|
|
|
|
nativeAudioDecoderFactory:
|
|
|
|
|
(rtc::scoped_refptr<webrtc::AudioDecoderFactory>)audioDecoderFactory
|
|
|
|
|
nativeVideoEncoderFactory:
|
|
|
|
|
(std::unique_ptr<webrtc::VideoEncoderFactory>)videoEncoderFactory
|
|
|
|
|
nativeVideoDecoderFactory:
|
|
|
|
|
(std::unique_ptr<webrtc::VideoDecoderFactory>)videoDecoderFactory
|
|
|
|
|
audioDeviceModule:(webrtc::AudioDeviceModule *)audioDeviceModule
|
|
|
|
|
audioProcessingModule:
|
|
|
|
|
(rtc::scoped_refptr<webrtc::AudioProcessing>)audioProcessingModule
|
|
|
|
|
networkControllerFactory:
|
|
|
|
|
(std::unique_ptr<webrtc::NetworkControllerFactoryInterface>)
|
2020-06-10 17:36:17 +02:00
|
|
|
networkControllerFactory {
|
2017-10-05 16:55:38 +02:00
|
|
|
if (self = [self initNative]) {
|
2018-10-08 09:43:21 -07:00
|
|
|
webrtc::PeerConnectionFactoryDependencies dependencies;
|
|
|
|
|
dependencies.network_thread = _networkThread.get();
|
|
|
|
|
dependencies.worker_thread = _workerThread.get();
|
|
|
|
|
dependencies.signaling_thread = _signalingThread.get();
|
2020-08-19 16:41:54 -07:00
|
|
|
if (webrtc::field_trial::IsEnabled("WebRTC-Network-UseNWPathMonitor")) {
|
|
|
|
|
dependencies.network_monitor_factory = webrtc::CreateNetworkMonitorFactory();
|
|
|
|
|
}
|
2020-09-22 11:36:35 +02:00
|
|
|
dependencies.trials = std::make_unique<webrtc::FieldTrialBasedConfig>();
|
2022-08-23 12:57:16 +02:00
|
|
|
dependencies.task_queue_factory =
|
|
|
|
|
webrtc::CreateDefaultTaskQueueFactory(dependencies.trials.get());
|
2019-05-17 13:20:14 +02:00
|
|
|
cricket::MediaEngineDependencies media_deps;
|
|
|
|
|
media_deps.adm = std::move(audioDeviceModule);
|
|
|
|
|
media_deps.task_queue_factory = dependencies.task_queue_factory.get();
|
|
|
|
|
media_deps.audio_encoder_factory = std::move(audioEncoderFactory);
|
|
|
|
|
media_deps.audio_decoder_factory = std::move(audioDecoderFactory);
|
|
|
|
|
media_deps.video_encoder_factory = std::move(videoEncoderFactory);
|
|
|
|
|
media_deps.video_decoder_factory = std::move(videoDecoderFactory);
|
|
|
|
|
if (audioProcessingModule) {
|
|
|
|
|
media_deps.audio_processing = std::move(audioProcessingModule);
|
|
|
|
|
} else {
|
|
|
|
|
media_deps.audio_processing = webrtc::AudioProcessingBuilder().Create();
|
|
|
|
|
}
|
2020-09-22 11:36:35 +02:00
|
|
|
media_deps.trials = dependencies.trials.get();
|
2019-05-17 13:20:14 +02:00
|
|
|
dependencies.media_engine = cricket::CreateMediaEngine(std::move(media_deps));
|
|
|
|
|
dependencies.call_factory = webrtc::CreateCallFactory();
|
|
|
|
|
dependencies.event_log_factory =
|
2019-09-17 17:06:18 +02:00
|
|
|
std::make_unique<webrtc::RtcEventLogFactory>(dependencies.task_queue_factory.get());
|
2019-04-23 10:24:03 +02:00
|
|
|
dependencies.network_controller_factory = std::move(networkControllerFactory);
|
2018-10-08 09:43:21 -07:00
|
|
|
_nativeFactory = webrtc::CreateModularPeerConnectionFactory(std::move(dependencies));
|
2017-10-05 16:55:38 +02:00
|
|
|
NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!");
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 16:14:32 +02:00
|
|
|
- (RTC_OBJC_TYPE(RTCAudioSource) *)audioSourceWithConstraints:
|
|
|
|
|
(nullable RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints {
|
2016-08-30 11:56:05 -07:00
|
|
|
std::unique_ptr<webrtc::MediaConstraints> nativeConstraints;
|
|
|
|
|
if (constraints) {
|
|
|
|
|
nativeConstraints = constraints.nativeConstraints;
|
|
|
|
|
}
|
2018-05-21 11:23:35 +02:00
|
|
|
cricket::AudioOptions options;
|
|
|
|
|
CopyConstraintsIntoAudioOptions(nativeConstraints.get(), &options);
|
|
|
|
|
|
2016-08-30 11:56:05 -07:00
|
|
|
rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
|
2018-05-21 11:23:35 +02:00
|
|
|
_nativeFactory->CreateAudioSource(options);
|
2020-05-04 16:14:32 +02:00
|
|
|
return [[RTC_OBJC_TYPE(RTCAudioSource) alloc] initWithFactory:self nativeAudioSource:source];
|
2016-03-23 11:29:27 -07:00
|
|
|
}
|
2016-03-22 10:57:40 -07:00
|
|
|
|
2020-05-04 16:14:32 +02:00
|
|
|
- (RTC_OBJC_TYPE(RTCAudioTrack) *)audioTrackWithTrackId:(NSString *)trackId {
|
|
|
|
|
RTC_OBJC_TYPE(RTCAudioSource) *audioSource = [self audioSourceWithConstraints:nil];
|
2016-08-30 11:56:05 -07:00
|
|
|
return [self audioTrackWithSource:audioSource trackId:trackId];
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 16:14:32 +02:00
|
|
|
- (RTC_OBJC_TYPE(RTCAudioTrack) *)audioTrackWithSource:(RTC_OBJC_TYPE(RTCAudioSource) *)source
|
|
|
|
|
trackId:(NSString *)trackId {
|
|
|
|
|
return [[RTC_OBJC_TYPE(RTCAudioTrack) alloc] initWithFactory:self source:source trackId:trackId];
|
2016-03-22 10:57:40 -07:00
|
|
|
}
|
|
|
|
|
|
2020-05-04 16:14:32 +02:00
|
|
|
- (RTC_OBJC_TYPE(RTCVideoSource) *)videoSource {
|
|
|
|
|
return [[RTC_OBJC_TYPE(RTCVideoSource) alloc] initWithFactory:self
|
|
|
|
|
signalingThread:_signalingThread.get()
|
|
|
|
|
workerThread:_workerThread.get()];
|
2017-03-28 01:56:41 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-06 16:17:12 +02:00
|
|
|
- (RTC_OBJC_TYPE(RTCVideoSource) *)videoSourceForScreenCast:(BOOL)forScreenCast {
|
|
|
|
|
return [[RTC_OBJC_TYPE(RTCVideoSource) alloc] initWithFactory:self
|
|
|
|
|
signalingThread:_signalingThread.get()
|
|
|
|
|
workerThread:_workerThread.get()
|
|
|
|
|
isScreenCast:forScreenCast];
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 16:14:32 +02:00
|
|
|
- (RTC_OBJC_TYPE(RTCVideoTrack) *)videoTrackWithSource:(RTC_OBJC_TYPE(RTCVideoSource) *)source
|
|
|
|
|
trackId:(NSString *)trackId {
|
|
|
|
|
return [[RTC_OBJC_TYPE(RTCVideoTrack) alloc] initWithFactory:self source:source trackId:trackId];
|
2016-03-22 10:57:40 -07:00
|
|
|
}
|
|
|
|
|
|
2020-05-04 16:14:32 +02:00
|
|
|
- (RTC_OBJC_TYPE(RTCMediaStream) *)mediaStreamWithStreamId:(NSString *)streamId {
|
|
|
|
|
return [[RTC_OBJC_TYPE(RTCMediaStream) alloc] initWithFactory:self streamId:streamId];
|
2016-03-22 10:57:40 -07:00
|
|
|
}
|
|
|
|
|
|
2021-03-02 23:25:10 +03:00
|
|
|
- (nullable RTC_OBJC_TYPE(RTCPeerConnection) *)
|
2020-05-04 16:14:32 +02:00
|
|
|
peerConnectionWithConfiguration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
|
|
|
|
|
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
|
|
|
|
|
delegate:
|
|
|
|
|
(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate {
|
|
|
|
|
return [[RTC_OBJC_TYPE(RTCPeerConnection) alloc] initWithFactory:self
|
|
|
|
|
configuration:configuration
|
|
|
|
|
constraints:constraints
|
2022-03-11 09:22:08 +01:00
|
|
|
certificateVerifier:nil
|
|
|
|
|
delegate:delegate];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (nullable RTC_OBJC_TYPE(RTCPeerConnection) *)
|
|
|
|
|
peerConnectionWithConfiguration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
|
|
|
|
|
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
|
|
|
|
|
certificateVerifier:
|
|
|
|
|
(id<RTC_OBJC_TYPE(RTCSSLCertificateVerifier)>)certificateVerifier
|
|
|
|
|
delegate:
|
|
|
|
|
(nullable id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate {
|
|
|
|
|
return [[RTC_OBJC_TYPE(RTCPeerConnection) alloc] initWithFactory:self
|
|
|
|
|
configuration:configuration
|
|
|
|
|
constraints:constraints
|
|
|
|
|
certificateVerifier:certificateVerifier
|
2020-05-04 16:14:32 +02:00
|
|
|
delegate:delegate];
|
2016-03-22 10:57:40 -07:00
|
|
|
}
|
|
|
|
|
|
2021-03-02 23:25:10 +03:00
|
|
|
- (nullable RTC_OBJC_TYPE(RTCPeerConnection) *)
|
2020-05-04 16:14:32 +02:00
|
|
|
peerConnectionWithDependencies:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration
|
|
|
|
|
constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints
|
2020-02-07 10:30:08 +01:00
|
|
|
dependencies:(std::unique_ptr<webrtc::PeerConnectionDependencies>)dependencies
|
2020-05-04 16:14:32 +02:00
|
|
|
delegate:(id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate {
|
|
|
|
|
return [[RTC_OBJC_TYPE(RTCPeerConnection) alloc] initWithDependencies:self
|
|
|
|
|
configuration:configuration
|
|
|
|
|
constraints:constraints
|
|
|
|
|
dependencies:std::move(dependencies)
|
|
|
|
|
delegate:delegate];
|
2020-02-07 10:30:08 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-04 16:14:32 +02:00
|
|
|
- (void)setOptions:(nonnull RTC_OBJC_TYPE(RTCPeerConnectionFactoryOptions) *)options {
|
2018-01-02 13:33:16 +03:00
|
|
|
RTC_DCHECK(options != nil);
|
|
|
|
|
_nativeFactory->SetOptions(options.nativeOptions);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-29 09:49:43 +00:00
|
|
|
- (BOOL)startAecDumpWithFilePath:(NSString *)filePath
|
|
|
|
|
maxSizeInBytes:(int64_t)maxSizeInBytes {
|
2016-08-30 12:58:11 -07:00
|
|
|
RTC_DCHECK(filePath.length);
|
|
|
|
|
RTC_DCHECK_GT(maxSizeInBytes, 0);
|
|
|
|
|
|
|
|
|
|
if (_hasStartedAecDump) {
|
|
|
|
|
RTCLogError(@"Aec dump already started.");
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
2019-06-24 09:39:56 +02:00
|
|
|
FILE *f = fopen(filePath.UTF8String, "wb");
|
|
|
|
|
if (!f) {
|
|
|
|
|
RTCLogError(@"Error opening file: %@. Error: %s", filePath, strerror(errno));
|
2016-08-30 12:58:11 -07:00
|
|
|
return NO;
|
|
|
|
|
}
|
2019-06-24 09:39:56 +02:00
|
|
|
_hasStartedAecDump = _nativeFactory->StartAecDump(f, maxSizeInBytes);
|
2016-08-30 12:58:11 -07:00
|
|
|
return _hasStartedAecDump;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)stopAecDump {
|
|
|
|
|
_nativeFactory->StopAecDump();
|
|
|
|
|
_hasStartedAecDump = NO;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-21 09:19:34 +09:00
|
|
|
- (rtc::Thread *)signalingThread {
|
|
|
|
|
return _signalingThread.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (rtc::Thread *)workerThread {
|
|
|
|
|
return _workerThread.get();
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-20 13:40:30 -08:00
|
|
|
@end
|