diff --git a/VoidLink/Stream/VideoDecoderRenderer.m b/VoidLink/Stream/VideoDecoderRenderer.m index b1b9238d..246194ef 100644 --- a/VoidLink/Stream/VideoDecoderRenderer.m +++ b/VoidLink/Stream/VideoDecoderRenderer.m @@ -39,11 +39,10 @@ extern int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size, - (void)reinitializeDisplayLayer { - if (_displayLayer == nil) { - _displayLayer = [[AVSampleBufferDisplayLayer alloc] init]; - _displayLayer.backgroundColor = [UIColor blackColor].CGColor; - [_view.layer addSublayer:_displayLayer]; - } + CALayer *oldLayer = _displayLayer; + + _displayLayer = [[AVSampleBufferDisplayLayer alloc] init]; + _displayLayer.backgroundColor = [UIColor blackColor].CGColor; // Ensure the AVSampleBufferDisplayLayer is sized to preserve the aspect ratio // of the video stream. We used to use AVLayerVideoGravityResizeAspect, but that @@ -64,6 +63,14 @@ extern int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size, // can see the loading progress label as the stream is starting. _displayLayer.hidden = YES; + if (oldLayer != nil) { + // Switch out the old display layer with the new one + [_view.layer replaceSublayer:oldLayer with:_displayLayer]; + } + else { + [_view.layer addSublayer:_displayLayer]; + } + if (formatDesc != nil) { CFRelease(formatDesc); formatDesc = nil;