Skip to content

Commit

Permalink
Merge branch 'release-9.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
z-dule committed Aug 16, 2024
2 parents e0c7602 + 40b6c0d commit 701f6e4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
17 changes: 14 additions & 3 deletions iosx/src/flowmgr/AVSFlowManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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 "
Expand Down
44 changes: 28 additions & 16 deletions iosx/src/flowmgr/AVSVideoView_Metal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<MTLLibrary> metalLib = [_metalDevice newLibraryWithSource:g_ShaderSrc options:nil error:&err];
Expand Down Expand Up @@ -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:)
Expand Down Expand Up @@ -162,9 +165,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;
Expand Down Expand Up @@ -317,16 +320,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<CAMetalDrawable> currentDrawable = [_metalLayer nextDrawable];
if (!currentDrawable) {
dispatch_semaphore_signal(blockSem);
//dispatch_semaphore_signal(blockSem);
return;
}

Expand All @@ -339,7 +342,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;
Expand Down Expand Up @@ -375,14 +378,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);
}
}

Expand Down Expand Up @@ -469,10 +472,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 = self.bounds.size;
_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
Expand Down

0 comments on commit 701f6e4

Please sign in to comment.