From 880cb533e8572cacf69912aa6dd9fbfb79013bd3 Mon Sep 17 00:00:00 2001 From: Dusan Stevanovic Date: Wed, 7 Aug 2024 16:14:38 +0200 Subject: [PATCH 1/4] If we were in active state do not clea ssrc values --- src/ccall/ccall.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ccall/ccall.c b/src/ccall/ccall.c index e46fadc5c..00b9752b3 100644 --- a/src/ccall/ccall.c +++ b/src/ccall/ccall.c @@ -929,8 +929,10 @@ static void ecall_media_estab_handler(struct icall *icall, const char *userid, } if (CCALL_STATE_CONNSENT != ccall->state) { + enum ccall_state old_state = ccall->state; set_state(ccall, CCALL_STATE_ACTIVE); - userlist_incall_clear(ccall->userl, true, false); + userlist_incall_clear(ccall->userl, true, + old_state == CCALL_STATE_ACTIVE); } else { info("ccall(%p): refusing to go to CCALL_STATE_ACTIVE " From 92a9e9966c72e423c5fc824dce9375ca2a7cf566 Mon Sep 17 00:00:00 2001 From: Dusan Stevanovic Date: Wed, 14 Aug 2024 10:29:56 +0200 Subject: [PATCH 2/4] try to minimize locking to aoid deadlock risk --- iosx/src/flowmgr/AVSFlowManager.m | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/iosx/src/flowmgr/AVSFlowManager.m b/iosx/src/flowmgr/AVSFlowManager.m index 42bc27f8a..419fd06bc 100644 --- a/iosx/src/flowmgr/AVSFlowManager.m +++ b/iosx/src/flowmgr/AVSFlowManager.m @@ -915,8 +915,20 @@ - (BOOL)renderFrame:(struct avs_vidframe *)frame forUser:(NSString *)userid BOOL found = NO; [_viewLock lock]; - for (unsigned int v = 0; v < _videoViews.count; v++) { - AVSVideoView *view = [_videoViews objectAtIndex: v]; + unsigned int cnt = _videoViews.count; + [_viewLock unlock]; + + for (unsigned int v = 0; v < cnt; v++) { + AVSVideoView *view = nil; + + [_viewLock lock]; + if (v < _videoViews.count) { + view = [_videoViews objectAtIndex: v]; + } + [_viewLock unlock]; + + if (view == nil) + continue; if (view.userid == nil) { warning("Found renderer without userid\n"); @@ -930,7 +942,6 @@ - (BOOL)renderFrame:(struct avs_vidframe *)frame forUser:(NSString *)userid found = YES; } } - [_viewLock unlock]; if (!found) { warning("flowmgr: render_frame couldnt find renderer for frame " From 9b203db5b6d8a6f2dd6eda91020a7420b192500a Mon Sep 17 00:00:00 2001 From: Dusan Stevanovic Date: Wed, 14 Aug 2024 17:03:13 +0200 Subject: [PATCH 3/4] ios: fix scaling for Metal view --- iosx/src/flowmgr/AVSVideoView_Metal.mm | 41 ++++++++++++++++---------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/iosx/src/flowmgr/AVSVideoView_Metal.mm b/iosx/src/flowmgr/AVSVideoView_Metal.mm index 86d95183f..c4a733192 100644 --- a/iosx/src/flowmgr/AVSVideoView_Metal.mm +++ b/iosx/src/flowmgr/AVSVideoView_Metal.mm @@ -43,14 +43,14 @@ @implementation AVSVideoView { int _chromaWidth; int _chromaHeight; - dispatch_semaphore_t _gpuSemaphore; + //dispatch_semaphore_t _gpuSemaphore; int _oldRotation; int _oldWidth; int _oldHeight; NSLock *_lock; - CGRect _viewFrame; + CGSize _viewFrame; BOOL _shouldFill; BOOL _forceRecalc; } @@ -80,7 +80,7 @@ - (id)init } [self setupLayer]; - _gpuSemaphore = dispatch_semaphore_create(1); + //_gpuSemaphore = dispatch_semaphore_create(1); NSLog(@"AVSVideoView_metal: compiling source...\n"); id metalLib = [_metalDevice newLibraryWithSource:g_ShaderSrc options:nil error:&err]; @@ -162,9 +162,9 @@ - (CALayer *)makeBackingLayer - (void)getVertexData:(struct avs_vidframe *)vf buffer:(float *)buffer { - CGRect frame = _viewFrame; //self.frame; - float dw = (float)frame.size.width; - float dh = (float)frame.size.height; + CGSize frame = _viewFrame; //self.frame; + float dw = (float)frame.width; + float dh = (float)frame.height; float vw = vf->w; float vh = vf->h; @@ -317,16 +317,16 @@ - (void)render:(CADisplayLink*)displayLink } [_lock unlock]; - __block dispatch_semaphore_t blockSem = _gpuSemaphore; + //__block dispatch_semaphore_t blockSem = _gpuSemaphore; - if (!_renderPassDescriptor || _viewFrame.size.width == 0 || _viewFrame.size.height == 0) { - dispatch_semaphore_signal(blockSem); + if (!_renderPassDescriptor || _viewFrame.width == 0 || _viewFrame.height == 0) { + //dispatch_semaphore_signal(blockSem); return; } id currentDrawable = [_metalLayer nextDrawable]; if (!currentDrawable) { - dispatch_semaphore_signal(blockSem); + //dispatch_semaphore_signal(blockSem); return; } @@ -339,7 +339,7 @@ - (void)render:(CADisplayLink*)displayLink if (_newFrame > 0) _newFrame--; [_lock unlock]; - dispatch_semaphore_signal(blockSem); + //dispatch_semaphore_signal(blockSem); }]; _renderPassDescriptor.colorAttachments[0].texture = currentDrawable.texture; @@ -375,14 +375,14 @@ - (BOOL)handleFrame:(struct avs_vidframe *)frame //NSLog(@"handleFrame: frame=%dx%d\n", frame->w, frame->h); @autoreleasepool { // Wait until any pending GPU work is done - __block dispatch_semaphore_t blockSem = _gpuSemaphore; - dispatch_semaphore_wait(blockSem, DISPATCH_TIME_FOREVER); + //_block dispatch_semaphore_t blockSem = _gpuSemaphore; + //dispatch_semaphore_wait(blockSem, DISPATCH_TIME_FOREVER); if ([self setupTexturesForFrame:frame]) { [_lock lock]; _newFrame++; [_lock unlock]; } else { - dispatch_semaphore_signal(blockSem); + //dispatch_semaphore_signal(blockSem); } } @@ -469,10 +469,19 @@ - (BOOL) shouldFill - (void)layoutSubviews { [_lock lock]; - _viewFrame = self.frame; + CGFloat scale = [UIScreen mainScreen].scale; + _metalLayer.drawableSize = CGSizeMake(self.bounds.size.width * scale, + self.bounds.size.height * scale); + + _viewFrame = _metalLayer.drawableSize; _forceRecalc = YES; [_lock unlock]; - + + info("layoutSubviews: bounds=%dx%d frame=%dx%d drawable=%dx%d scale=%f\n", + (int)self.bounds.size.width, (int)self.bounds.size.height, + (int)self.frame.size.width, (int)self.frame.size.height, + (int)_metalLayer.drawableSize.width, (int)_metalLayer.drawableSize.height, + scale); } -(void)dealloc From 40b6c0d66889c58d41483bf9c0b9e75a2db87cf4 Mon Sep 17 00:00:00 2001 From: Dusan Stevanovic Date: Fri, 16 Aug 2024 11:42:21 +0200 Subject: [PATCH 4/4] ios: more metal improvements --- iosx/src/flowmgr/AVSVideoView_Metal.mm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/iosx/src/flowmgr/AVSVideoView_Metal.mm b/iosx/src/flowmgr/AVSVideoView_Metal.mm index c4a733192..f264467c1 100644 --- a/iosx/src/flowmgr/AVSVideoView_Metal.mm +++ b/iosx/src/flowmgr/AVSVideoView_Metal.mm @@ -131,6 +131,9 @@ - (id)init NSLog(@"AVSVideoView-init: source compiled successfully\n"); + self.autoresizingMask = + UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + #if TARGET_OS_IPHONE [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) @@ -473,7 +476,7 @@ - (void)layoutSubviews _metalLayer.drawableSize = CGSizeMake(self.bounds.size.width * scale, self.bounds.size.height * scale); - _viewFrame = _metalLayer.drawableSize; + _viewFrame = self.bounds.size; _forceRecalc = YES; [_lock unlock];