mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
no message
This commit is contained in:
parent
c4761bcb59
commit
abc63a5389
2 changed files with 57 additions and 85 deletions
|
|
@ -126,13 +126,13 @@ typedef NS_ENUM(int32_t, OngoingCallDataSavingWebrtc) {
|
|||
@property (nonatomic, copy) void (^ _Nullable stateChanged)(OngoingCallStateWebrtc, OngoingCallVideoStateWebrtc, OngoingCallRemoteVideoStateWebrtc, OngoingCallRemoteAudioStateWebrtc, OngoingCallRemoteBatteryLevelWebrtc, float);
|
||||
@property (nonatomic, copy) void (^ _Nullable signalBarsChanged)(int32_t);
|
||||
|
||||
- (instancetype _Nonnull)initWithVersion:(NSString * _Nonnull)version queue:(id<OngoingCallThreadLocalContextQueueWebrtc> _Nonnull)queue proxy:(VoipProxyServerWebrtc * _Nullable)proxy networkType:(OngoingCallNetworkTypeWebrtc)networkType dataSaving:(OngoingCallDataSavingWebrtc)dataSaving derivedState:(NSData * _Nonnull)derivedState key:(NSData * _Nonnull)key isOutgoing:(bool)isOutgoing connections:(NSArray<OngoingCallConnectionDescriptionWebrtc *> * _Nonnull)connections maxLayer:(int32_t)maxLayer allowP2P:(BOOL)allowP2P logPath:(NSString * _Nonnull)logPath sendSignalingData:(void (^ _Nonnull)(NSData * _Nonnull))sendSignalingData videoCapturer:(OngoingCallThreadLocalContextVideoCapturer * _Nullable)videoCapturer preferredAspectRatio:(float)preferredAspectRatio preferredVideoCodec:(NSString * _Nullable)preferredVideoCodec;
|
||||
- (instancetype _Nonnull)initWithVersion:(NSString * _Nonnull)version queue:(id<OngoingCallThreadLocalContextQueueWebrtc> _Nonnull)queue proxy:(VoipProxyServerWebrtc * _Nullable)proxy networkType:(OngoingCallNetworkTypeWebrtc)networkType dataSaving:(OngoingCallDataSavingWebrtc)dataSaving derivedState:(NSData * _Nonnull)derivedState key:(NSData * _Nonnull)key isOutgoing:(bool)isOutgoing connections:(NSArray<OngoingCallConnectionDescriptionWebrtc *> * _Nonnull)connections maxLayer:(int32_t)maxLayer allowP2P:(BOOL)allowP2P logPath:(NSString * _Nonnull)logPath sendSignalingData:(void (^ _Nonnull)(NSData * _Nonnull))sendSignalingData videoCapturer:(OngoingCallThreadLocalContextVideoCapturer * _Nullable)videoCapturer preferredAspectRatio:(float)preferredAspectRatio enableHighBitrateVideoCalls:(bool)enableHighBitrateVideoCalls;
|
||||
|
||||
- (void)beginTermination;
|
||||
- (void)stop:(void (^_Nullable)(NSString * _Nullable debugLog, int64_t bytesSentWifi, int64_t bytesReceivedWifi, int64_t bytesSentMobile, int64_t bytesReceivedMobile))completion;
|
||||
|
||||
- (bool)needRate;
|
||||
|
||||
|
||||
- (NSString * _Nullable)debugInfo;
|
||||
- (NSString * _Nullable)version;
|
||||
- (NSData * _Nonnull)getDerivedState;
|
||||
|
|
|
|||
|
|
@ -166,9 +166,9 @@
|
|||
if ([VideoMetalView isSupported]) {
|
||||
VideoMetalView *remoteRenderer = [[VideoMetalView alloc] initWithFrame:CGRectZero];
|
||||
remoteRenderer.videoContentMode = UIViewContentModeScaleAspectFill;
|
||||
#if !TARGET_OS_IPHONE
|
||||
#if !TARGET_OS_IPHONE
|
||||
[remoteRenderer setIsForceMirrored:YES];
|
||||
#endif
|
||||
#endif
|
||||
std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink = [remoteRenderer getSink];
|
||||
interface->setOutput(sink);
|
||||
|
||||
|
|
@ -177,9 +177,9 @@
|
|||
GLVideoView *remoteRenderer = [[GLVideoView alloc] initWithFrame:CGRectZero];
|
||||
|
||||
remoteRenderer.videoContentMode = UIViewContentModeScaleAspectFill;
|
||||
#if !TARGET_OS_IPHONE
|
||||
#if !TARGET_OS_IPHONE
|
||||
[remoteRenderer setIsForceMirrored:YES];
|
||||
#endif
|
||||
#endif
|
||||
std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink = [remoteRenderer getSink];
|
||||
interface->setOutput(sink);
|
||||
|
||||
|
|
@ -212,7 +212,7 @@
|
|||
NSString *_version;
|
||||
id<OngoingCallThreadLocalContextQueueWebrtc> _queue;
|
||||
int32_t _contextId;
|
||||
|
||||
|
||||
OngoingCallNetworkTypeWebrtc _networkType;
|
||||
NSTimeInterval _callReceiveTimeout;
|
||||
NSTimeInterval _callRingTimeout;
|
||||
|
|
@ -220,6 +220,7 @@
|
|||
NSTimeInterval _callPacketTimeout;
|
||||
|
||||
std::unique_ptr<tgcalls::Instance> _tgVoip;
|
||||
OngoingCallThreadLocalContextWebrtcTerminationResult *_terminationResult;
|
||||
|
||||
OngoingCallStateWebrtc _state;
|
||||
OngoingCallVideoStateWebrtc _videoState;
|
||||
|
|
@ -237,7 +238,7 @@
|
|||
void (^_sendSignalingData)(NSData *);
|
||||
|
||||
float _remotePreferredAspectRatio;
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void)controllerStateChanged:(tgcalls::State)state;
|
||||
|
|
@ -262,29 +263,29 @@
|
|||
|
||||
static tgcalls::NetworkType callControllerNetworkTypeForType(OngoingCallNetworkTypeWebrtc type) {
|
||||
switch (type) {
|
||||
case OngoingCallNetworkTypeWifi:
|
||||
return tgcalls::NetworkType::WiFi;
|
||||
case OngoingCallNetworkTypeCellularGprs:
|
||||
return tgcalls::NetworkType::Gprs;
|
||||
case OngoingCallNetworkTypeCellular3g:
|
||||
return tgcalls::NetworkType::ThirdGeneration;
|
||||
case OngoingCallNetworkTypeCellularLte:
|
||||
return tgcalls::NetworkType::Lte;
|
||||
default:
|
||||
return tgcalls::NetworkType::ThirdGeneration;
|
||||
case OngoingCallNetworkTypeWifi:
|
||||
return tgcalls::NetworkType::WiFi;
|
||||
case OngoingCallNetworkTypeCellularGprs:
|
||||
return tgcalls::NetworkType::Gprs;
|
||||
case OngoingCallNetworkTypeCellular3g:
|
||||
return tgcalls::NetworkType::ThirdGeneration;
|
||||
case OngoingCallNetworkTypeCellularLte:
|
||||
return tgcalls::NetworkType::Lte;
|
||||
default:
|
||||
return tgcalls::NetworkType::ThirdGeneration;
|
||||
}
|
||||
}
|
||||
|
||||
static tgcalls::DataSaving callControllerDataSavingForType(OngoingCallDataSavingWebrtc type) {
|
||||
switch (type) {
|
||||
case OngoingCallDataSavingNever:
|
||||
return tgcalls::DataSaving::Never;
|
||||
case OngoingCallDataSavingCellular:
|
||||
return tgcalls::DataSaving::Mobile;
|
||||
case OngoingCallDataSavingAlways:
|
||||
return tgcalls::DataSaving::Always;
|
||||
default:
|
||||
return tgcalls::DataSaving::Never;
|
||||
case OngoingCallDataSavingNever:
|
||||
return tgcalls::DataSaving::Never;
|
||||
case OngoingCallDataSavingCellular:
|
||||
return tgcalls::DataSaving::Mobile;
|
||||
case OngoingCallDataSavingAlways:
|
||||
return tgcalls::DataSaving::Always;
|
||||
default:
|
||||
return tgcalls::DataSaving::Never;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -311,21 +312,15 @@ static void (*InternalVoipLoggingFunction)(NSString *) = NULL;
|
|||
return 92;
|
||||
}
|
||||
|
||||
+ (NSArray<NSString *> * _Nonnull)versionsWithIncludeReference:(bool)__unused includeReference {
|
||||
return @[@"2.7.7", @"3.0.0"];
|
||||
}
|
||||
|
||||
+ (tgcalls::ProtocolVersion)protocolVersionFromLibraryVersion:(NSString *)version {
|
||||
if ([version isEqualToString:@"2.7.7"]) {
|
||||
return tgcalls::ProtocolVersion::V0;
|
||||
} else if ([version isEqualToString:@"3.0.0"]) {
|
||||
return tgcalls::ProtocolVersion::V1;
|
||||
+ (NSArray<NSString *> * _Nonnull)versionsWithIncludeReference:(bool)includeReference {
|
||||
if (includeReference) {
|
||||
return @[@"2.7.7", @"2.8.8"];
|
||||
} else {
|
||||
return tgcalls::ProtocolVersion::V0;
|
||||
return @[@"2.7.7"];
|
||||
}
|
||||
}
|
||||
|
||||
- (instancetype _Nonnull)initWithVersion:(NSString * _Nonnull)version queue:(id<OngoingCallThreadLocalContextQueueWebrtc> _Nonnull)queue proxy:(VoipProxyServerWebrtc * _Nullable)proxy networkType:(OngoingCallNetworkTypeWebrtc)networkType dataSaving:(OngoingCallDataSavingWebrtc)dataSaving derivedState:(NSData * _Nonnull)derivedState key:(NSData * _Nonnull)key isOutgoing:(bool)isOutgoing connections:(NSArray<OngoingCallConnectionDescriptionWebrtc *> * _Nonnull)connections maxLayer:(int32_t)maxLayer allowP2P:(BOOL)allowP2P logPath:(NSString * _Nonnull)logPath sendSignalingData:(void (^)(NSData * _Nonnull))sendSignalingData videoCapturer:(OngoingCallThreadLocalContextVideoCapturer * _Nullable)videoCapturer preferredAspectRatio:(float)preferredAspectRatio preferredVideoCodec:(NSString * _Nullable)preferredVideoCodec {
|
||||
- (instancetype _Nonnull)initWithVersion:(NSString * _Nonnull)version queue:(id<OngoingCallThreadLocalContextQueueWebrtc> _Nonnull)queue proxy:(VoipProxyServerWebrtc * _Nullable)proxy networkType:(OngoingCallNetworkTypeWebrtc)networkType dataSaving:(OngoingCallDataSavingWebrtc)dataSaving derivedState:(NSData * _Nonnull)derivedState key:(NSData * _Nonnull)key isOutgoing:(bool)isOutgoing connections:(NSArray<OngoingCallConnectionDescriptionWebrtc *> * _Nonnull)connections maxLayer:(int32_t)maxLayer allowP2P:(BOOL)allowP2P logPath:(NSString * _Nonnull)logPath sendSignalingData:(void (^)(NSData * _Nonnull))sendSignalingData videoCapturer:(OngoingCallThreadLocalContextVideoCapturer * _Nullable)videoCapturer preferredAspectRatio:(float)preferredAspectRatio enableHighBitrateVideoCalls:(bool)enableHighBitrateVideoCalls {
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_version = version;
|
||||
|
|
@ -388,11 +383,6 @@ static void (*InternalVoipLoggingFunction)(NSString *) = NULL;
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> preferredVideoCodecs;
|
||||
if (preferredVideoCodec != nil) {
|
||||
preferredVideoCodecs.push_back([preferredVideoCodec UTF8String]);
|
||||
}
|
||||
|
||||
std::vector<tgcalls::Endpoint> endpoints;
|
||||
|
||||
tgcalls::Config config = {
|
||||
|
|
@ -407,9 +397,7 @@ static void (*InternalVoipLoggingFunction)(NSString *) = NULL;
|
|||
.logPath = "",//logPath.length == 0 ? "" : std::string(logPath.UTF8String),
|
||||
.maxApiLayer = [OngoingCallThreadLocalContextWebrtc maxLayer],
|
||||
.preferredAspectRatio = preferredAspectRatio,
|
||||
.enableHighBitrateVideo = true,
|
||||
.preferredVideoCodecs = preferredVideoCodecs,
|
||||
.protocolVersion = [OngoingCallThreadLocalContextWebrtc protocolVersionFromLibraryVersion:version]
|
||||
.enableHighBitrateVideo = enableHighBitrateVideoCalls
|
||||
};
|
||||
|
||||
auto encryptionKeyValue = std::make_shared<std::array<uint8_t, 256>>();
|
||||
|
|
@ -421,6 +409,7 @@ static void (*InternalVoipLoggingFunction)(NSString *) = NULL;
|
|||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
tgcalls::Register<tgcalls::InstanceImpl>();
|
||||
tgcalls::Register<tgcalls::InstanceImplReference>();
|
||||
});
|
||||
_tgVoip = tgcalls::Meta::Create([version UTF8String], (tgcalls::Descriptor){
|
||||
.config = config,
|
||||
|
|
@ -553,19 +542,29 @@ static void (*InternalVoipLoggingFunction)(NSString *) = NULL;
|
|||
return false;
|
||||
}
|
||||
|
||||
- (void)beginTermination {
|
||||
- (void)stopInstanceIfNeeded {
|
||||
if (!_tgVoip) {
|
||||
return;
|
||||
}
|
||||
tgcalls::FinalState finalState = _tgVoip->stop();
|
||||
_tgVoip.reset();
|
||||
_terminationResult = [[OngoingCallThreadLocalContextWebrtcTerminationResult alloc] initWithFinalState:finalState];
|
||||
}
|
||||
|
||||
- (void)stopWithTerminationResult:(OngoingCallThreadLocalContextWebrtcTerminationResult *)terminationResult completion:(void (^)(NSString *, int64_t, int64_t, int64_t, int64_t))completion {
|
||||
_tgVoip.reset();
|
||||
- (void)beginTermination {
|
||||
[self stopInstanceIfNeeded];
|
||||
}
|
||||
|
||||
- (void)stop:(void (^)(NSString *, int64_t, int64_t, int64_t, int64_t))completion {
|
||||
[self stopInstanceIfNeeded];
|
||||
|
||||
if (completion) {
|
||||
if (terminationResult) {
|
||||
NSString *debugLog = [NSString stringWithUTF8String:terminationResult.finalState.debugLog.c_str()];
|
||||
_lastDerivedState = [[NSData alloc] initWithBytes:terminationResult.finalState.persistentState.value.data() length:terminationResult.finalState.persistentState.value.size()];
|
||||
if (_terminationResult) {
|
||||
NSString *debugLog = [NSString stringWithUTF8String:_terminationResult.finalState.debugLog.c_str()];
|
||||
_lastDerivedState = [[NSData alloc] initWithBytes:_terminationResult.finalState.persistentState.value.data() length:_terminationResult.finalState.persistentState.value.size()];
|
||||
|
||||
if (completion) {
|
||||
completion(debugLog, terminationResult.finalState.trafficStats.bytesSentWifi, terminationResult.finalState.trafficStats.bytesReceivedWifi, terminationResult.finalState.trafficStats.bytesSentMobile, terminationResult.finalState.trafficStats.bytesReceivedMobile);
|
||||
completion(debugLog, _terminationResult.finalState.trafficStats.bytesSentWifi, _terminationResult.finalState.trafficStats.bytesReceivedWifi, _terminationResult.finalState.trafficStats.bytesSentMobile, _terminationResult.finalState.trafficStats.bytesReceivedMobile);
|
||||
}
|
||||
} else {
|
||||
if (completion) {
|
||||
|
|
@ -575,33 +574,6 @@ static void (*InternalVoipLoggingFunction)(NSString *) = NULL;
|
|||
}
|
||||
}
|
||||
|
||||
- (void)stop:(void (^)(NSString *, int64_t, int64_t, int64_t, int64_t))completion {
|
||||
if (!_tgVoip) {
|
||||
return;
|
||||
}
|
||||
if (completion == nil) {
|
||||
_tgVoip->stop([](tgcalls::FinalState finalState) {
|
||||
});
|
||||
_tgVoip.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
__weak OngoingCallThreadLocalContextWebrtc *weakSelf = self;
|
||||
id<OngoingCallThreadLocalContextQueueWebrtc> queue = _queue;
|
||||
_tgVoip->stop([weakSelf, queue, completion = [completion copy]](tgcalls::FinalState finalState) {
|
||||
[queue dispatch:^{
|
||||
__strong OngoingCallThreadLocalContextWebrtc *strongSelf = weakSelf;
|
||||
if (!strongSelf) {
|
||||
return;
|
||||
}
|
||||
|
||||
OngoingCallThreadLocalContextWebrtcTerminationResult *terminationResult = [[OngoingCallThreadLocalContextWebrtcTerminationResult alloc] initWithFinalState:finalState];
|
||||
|
||||
[strongSelf stopWithTerminationResult:terminationResult completion:completion];
|
||||
}];
|
||||
});
|
||||
}
|
||||
|
||||
- (NSString *)debugInfo {
|
||||
if (_tgVoip != nullptr) {
|
||||
NSString *version = [self version];
|
||||
|
|
@ -706,11 +678,11 @@ static void (*InternalVoipLoggingFunction)(NSString *) = NULL;
|
|||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if ([VideoMetalView isSupported]) {
|
||||
VideoMetalView *remoteRenderer = [[VideoMetalView alloc] initWithFrame:CGRectZero];
|
||||
#if TARGET_OS_IPHONE
|
||||
#if TARGET_OS_IPHONE
|
||||
remoteRenderer.videoContentMode = UIViewContentModeScaleAspectFill;
|
||||
#else
|
||||
#else
|
||||
remoteRenderer.videoContentMode = UIViewContentModeScaleAspect;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink = [remoteRenderer getSink];
|
||||
__strong OngoingCallThreadLocalContextWebrtc *strongSelf = weakSelf;
|
||||
|
|
@ -723,11 +695,11 @@ static void (*InternalVoipLoggingFunction)(NSString *) = NULL;
|
|||
completion(remoteRenderer);
|
||||
} else {
|
||||
GLVideoView *remoteRenderer = [[GLVideoView alloc] initWithFrame:CGRectZero];
|
||||
#if TARGET_OS_IPHONE
|
||||
#if TARGET_OS_IPHONE
|
||||
remoteRenderer.videoContentMode = UIViewContentModeScaleAspectFill;
|
||||
#else
|
||||
#else
|
||||
remoteRenderer.videoContentMode = UIViewContentModeScaleAspect;
|
||||
#endif
|
||||
#endif
|
||||
std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink = [remoteRenderer getSink];
|
||||
__strong OngoingCallThreadLocalContextWebrtc *strongSelf = weakSelf;
|
||||
if (strongSelf) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue