fix: frozen image when switching from metal to AVSB

This commit is contained in:
Acaki committed 2025-08-16 17:03:36 +08:00
1 parent d6aa64b816
commit 2b052fef1e
1 file changed
+30 -5
+30 -5
View File
@@ -59,13 +59,19 @@ extern int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size,
- (void)reinitializeDisplayLayer - (void)reinitializeDisplayLayer
{ {
if (_displayLayer == nil) { // Clean up existing display layer if it exists
_displayLayer = [[AVSampleBufferDisplayLayer alloc] init]; if (_displayLayer != nil) {
_displayLayer.backgroundColor = [UIColor blackColor].CGColor; [_displayLayer flushAndRemoveImage];
_displayLayer.videoGravity = AVLayerVideoGravityResize; [_displayLayer removeFromSuperlayer];
[_view.layer addSublayer:_displayLayer]; _displayLayer = nil;
} }
// Create a new display layer
_displayLayer = [[AVSampleBufferDisplayLayer alloc] init];
_displayLayer.backgroundColor = [UIColor blackColor].CGColor;
_displayLayer.videoGravity = AVLayerVideoGravityResize;
[_view.layer addSublayer:_displayLayer];
// Ensure the AVSampleBufferDisplayLayer is sized to preserve the aspect ratio // Ensure the AVSampleBufferDisplayLayer is sized to preserve the aspect ratio
// of the video stream. We used to use AVLayerVideoGravityResizeAspect, but that // of the video stream. We used to use AVLayerVideoGravityResizeAspect, but that
// respects the PAR encoded in the SPS which causes our computed video-relative // respects the PAR encoded in the SPS which causes our computed video-relative
@@ -358,6 +364,14 @@ int DrSubmitDecodeUnit(PDECODE_UNIT decodeUnit);
if (_renderingBackend == RENDER_AVSB) { if (_renderingBackend == RENDER_AVSB) {
[_displayLink invalidate]; [_displayLink invalidate];
_displayLink = nil;
// Properly clean up the display layer
if (_displayLayer != nil) {
[_displayLayer flushAndRemoveImage];
[_displayLayer removeFromSuperlayer];
_displayLayer = nil;
}
} }
if (_decompressionSession != NULL) { if (_decompressionSession != NULL) {
@@ -365,6 +379,17 @@ int DrSubmitDecodeUnit(PDECODE_UNIT decodeUnit);
CFRelease(_decompressionSession); CFRelease(_decompressionSession);
_decompressionSession = nil; _decompressionSession = nil;
} }
// Clean up format descriptors
if (_formatDesc != nil) {
CFRelease(_formatDesc);
_formatDesc = nil;
}
if (_formatDescImageBuffer != nil) {
CFRelease(_formatDescImageBuffer);
_formatDescImageBuffer = nil;
}
} }
#define NALU_START_PREFIX_SIZE 3 #define NALU_START_PREFIX_SIZE 3