fix: background stream issues
This commit is contained in:
1 parent
4b8691b943
commit
e61e96b352
2 files changed
+13
-14
No files matched your search
@@ -39,10 +39,12 @@ extern int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size,
|
|||||||
|
|
||||||
- (void)reinitializeDisplayLayer
|
- (void)reinitializeDisplayLayer
|
||||||
{
|
{
|
||||||
CALayer *oldLayer = _displayLayer;
|
if (_displayLayer == nil) {
|
||||||
|
_displayLayer = [[AVSampleBufferDisplayLayer alloc] init];
|
||||||
_displayLayer = [[AVSampleBufferDisplayLayer alloc] init];
|
_displayLayer.backgroundColor = [UIColor blackColor].CGColor;
|
||||||
_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
|
||||||
@@ -55,22 +57,17 @@ extern int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size,
|
|||||||
} else {
|
} else {
|
||||||
videoSize = CGSizeMake(_view.bounds.size.width, _view.bounds.size.width / _streamAspectRatio);
|
videoSize = CGSizeMake(_view.bounds.size.width, _view.bounds.size.width / _streamAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[CATransaction begin];
|
||||||
|
[CATransaction setDisableActions:YES];
|
||||||
_displayLayer.position = CGPointMake(CGRectGetMidX(_view.bounds), CGRectGetMidY(_view.bounds));
|
_displayLayer.position = CGPointMake(CGRectGetMidX(_view.bounds), CGRectGetMidY(_view.bounds));
|
||||||
_displayLayer.bounds = CGRectMake(0, 0, videoSize.width, videoSize.height);
|
_displayLayer.bounds = CGRectMake(0, 0, videoSize.width, videoSize.height);
|
||||||
_displayLayer.videoGravity = AVLayerVideoGravityResize;
|
[CATransaction commit];
|
||||||
|
|
||||||
// Hide the layer until we get an IDR frame. This ensures we
|
// Hide the layer until we get an IDR frame. This ensures we
|
||||||
// can see the loading progress label as the stream is starting.
|
// can see the loading progress label as the stream is starting.
|
||||||
_displayLayer.hidden = YES;
|
_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) {
|
if (formatDesc != nil) {
|
||||||
CFRelease(formatDesc);
|
CFRelease(formatDesc);
|
||||||
formatDesc = nil;
|
formatDesc = nil;
|
||||||
@@ -525,6 +522,8 @@ int DrSubmitDecodeUnit(PDECODE_UNIT decodeUnit);
|
|||||||
if (_displayLayer.status == AVQueuedSampleBufferRenderingStatusFailed) {
|
if (_displayLayer.status == AVQueuedSampleBufferRenderingStatusFailed) {
|
||||||
Log(LOG_E, @"Display layer rendering failed: %@", _displayLayer.error);
|
Log(LOG_E, @"Display layer rendering failed: %@", _displayLayer.error);
|
||||||
|
|
||||||
|
[self->_displayLayer flushAndRemoveImage];
|
||||||
|
|
||||||
// Recreate the display layer. We are already on the main thread,
|
// Recreate the display layer. We are already on the main thread,
|
||||||
// so this is safe to do right here.
|
// so this is safe to do right here.
|
||||||
[self reinitializeDisplayLayer];
|
[self reinitializeDisplayLayer];
|
||||||
|
|||||||
@@ -889,7 +889,7 @@
|
|||||||
#if !TARGET_OS_TV
|
#if !TARGET_OS_TV
|
||||||
// Terminate the stream if the app is inactive for 60 seconds
|
// Terminate the stream if the app is inactive for 60 seconds
|
||||||
Log(LOG_I, @"Starting inactivity termination timer");
|
Log(LOG_I, @"Starting inactivity termination timer");
|
||||||
_inactivityTimer = [NSTimer scheduledTimerWithTimeInterval:60
|
_inactivityTimer = [NSTimer scheduledTimerWithTimeInterval:1800
|
||||||
target:self
|
target:self
|
||||||
selector:@selector(inactiveTimerExpired:)
|
selector:@selector(inactiveTimerExpired:)
|
||||||
userInfo:nil
|
userInfo:nil
|
||||||
|
|||||||
Reference in new issue
Block a user