diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2020-05-14 09:16:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-14 09:16:32 -0400 |
commit | 1f8a9889f255d09b4e414f8be76dbac8f67298b8 (patch) | |
tree | aa4964b5c82a99208793fd99861a50ea7549a917 | |
parent | 89fb252858b50d6ed18c5eb66ab1b1de08f6fe05 (diff) | |
parent | 0680fc738cbd830ceb67d34992055e9c358b95f6 (diff) | |
download | sdl_ios-1f8a9889f255d09b4e414f8be76dbac8f67298b8.tar.gz |
Merge pull request #1651 from smartdevicelink/bugfix/issue-1620-video-stream-background-string
Video Background String Not Showing
-rw-r--r-- | SmartDeviceLink/SDLH264VideoEncoder.m | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/SmartDeviceLink/SDLH264VideoEncoder.m b/SmartDeviceLink/SDLH264VideoEncoder.m index 7ce981f5e..f00f1a18d 100644 --- a/SmartDeviceLink/SDLH264VideoEncoder.m +++ b/SmartDeviceLink/SDLH264VideoEncoder.m @@ -135,11 +135,7 @@ static NSDictionary<NSString *, id>* _defaultVideoEncoderSettings; _currentFrameNumber = 0; _timestampOffset = 0.0; - if (self.compressionSession != NULL) { - VTCompressionSessionInvalidate(self.compressionSession); - CFRelease(self.compressionSession); - self.compressionSession = NULL; - } + [self sdl_invalidateCompressionSession]; } - (BOOL)encodeFrame:(CVImageBufferRef)imageBuffer { @@ -159,6 +155,12 @@ static NSDictionary<NSString *, id>* _defaultVideoEncoderSettings; OSStatus status = VTCompressionSessionEncodeFrame(_compressionSession, imageBuffer, presentationTimestamp, kCMTimeInvalid, NULL, (__bridge void *)self, NULL); + // HAX: [#1620](https://github.com/smartdevicelink/sdl_ios/issues/1620) On some older iPhones VTCompressionSessionEncodeFrame fails with a kVTInvalidSessionErr when the device is locked. Attempt to fix this by recreating the compression session. + if (status == kVTInvalidSessionErr) { + VTCompressionSessionCompleteFrames(_compressionSession, presentationTimestamp); + [self sdl_resetCompressionSession]; + } + return (status == noErr); } @@ -335,14 +337,20 @@ void sdl_videoEncoderOutputCallback(void * CM_NULLABLE outputCallbackRefCon, voi return nalUnits; } +/// Forces the completion of any pending frames and invalidates the current VTCompressionSession +- (void)sdl_invalidateCompressionSession { + if (self.compressionSession == NULL) { return; } + + VTCompressionSessionCompleteFrames(self.compressionSession, kCMTimeInvalid); + VTCompressionSessionInvalidate(self.compressionSession); + CFRelease(self.compressionSession); + self.compressionSession = NULL; +} + /// Attempts to create a new VTCompressionSession using the dimensions passed when the video encoder was created and returns whether or not creating the new compression session was created successfully. - (BOOL)sdl_resetCompressionSession { // Destroy the current compression session before attempting to create a new one. Otherwise the attempt to create a new compression session sometimes fails. - if (self.compressionSession != NULL) { - VTCompressionSessionInvalidate(self.compressionSession); - CFRelease(self.compressionSession); - self.compressionSession = NULL; - } + [self sdl_invalidateCompressionSession]; OSStatus status = VTCompressionSessionCreate(NULL, (int32_t)self.dimensions.width, (int32_t)self.dimensions.height, kCMVideoCodecType_H264, NULL, self.sdl_pixelBufferOptions, NULL, &sdl_videoEncoderOutputCallback, (__bridge void *)self, &_compressionSession); return (status == noErr); |