diff --git a/VoidLink/Stream/VideoDecoderRenderer.m b/VoidLink/Stream/VideoDecoderRenderer.m index 1b8eec60..27a8b3d9 100644 --- a/VoidLink/Stream/VideoDecoderRenderer.m +++ b/VoidLink/Stream/VideoDecoderRenderer.m @@ -125,6 +125,7 @@ extern int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size, _parameterSetBuffers = [[NSMutableArray alloc] init]; _frameQueue = [FrameQueue sharedInstance]; + [_frameQueue start]; _maxRefreshRate = [[UIScreen mainScreen] maximumFramesPerSecond]; DataManager* dataMan = [[DataManager alloc] init]; diff --git a/VoidLink/Utility/FrameQueue.h b/VoidLink/Utility/FrameQueue.h index 4230e67d..e680b910 100644 --- a/VoidLink/Utility/FrameQueue.h +++ b/VoidLink/Utility/FrameQueue.h @@ -28,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN - (int)currentSoftCap; - (void)waitForEnqueue; - (void)shutdown; +- (void)start; @end diff --git a/VoidLink/Utility/FrameQueue.m b/VoidLink/Utility/FrameQueue.m index a6ac6cd1..532c3269 100644 --- a/VoidLink/Utility/FrameQueue.m +++ b/VoidLink/Utility/FrameQueue.m @@ -287,10 +287,15 @@ return [self count] == 0; } -- (void)clear { - os_unfair_lock_lock(&_lock); +- (void)_clear_unsafe { _head = _tail = _count = 0; _frameDropMetrics = [[FloatBuffer alloc] initWithCapacity:512]; +} + +// The public clear method now safely calls the unsafe version. +- (void)clear { + os_unfair_lock_lock(&_lock); + [self _clear_unsafe]; os_unfair_lock_unlock(&_lock); } @@ -331,6 +336,14 @@ dispatch_semaphore_signal(_frameSemaphore); } +- (void)start { + os_unfair_lock_lock(&_lock); + [self _clear_unsafe]; // Use the version without the lock + self.isStopping = NO; + os_unfair_lock_unlock(&_lock); + Log(LOG_I, @"FrameQueue (re)started"); +} + // For use with NSLog("%@", franeQueue); - (NSString *)description { __block NSMutableArray *parts = [NSMutableArray arrayWithCapacity:_count]; diff --git a/VoidLink/ViewControllers/StreamFrameViewController.m b/VoidLink/ViewControllers/StreamFrameViewController.m index 56bd4aeb..06838968 100644 --- a/VoidLink/ViewControllers/StreamFrameViewController.m +++ b/VoidLink/ViewControllers/StreamFrameViewController.m @@ -745,7 +745,9 @@ _inactivityTimer = nil; } if (self.metalViewController) { + [self.metalViewController shutdown]; [self.metalViewController.view removeFromSuperview]; + [self.metalViewController removeFromParentViewController]; self.metalViewController = nil; NSLog(@"Metal renderer stopped and cleaned up."); }