diff options
author | lapinskijw <jlapinski.dev@gmail.com> | 2020-05-13 13:54:44 -0400 |
---|---|---|
committer | lapinskijw <jlapinski.dev@gmail.com> | 2020-05-13 13:54:44 -0400 |
commit | 0680fc738cbd830ceb67d34992055e9c358b95f6 (patch) | |
tree | 5dd393ff1068e43a28518983a3abd383ac0c805c | |
parent | ef0ccd2f1070ce24b23bdaa5ac7cbe4f2e200eeb (diff) | |
download | sdl_ios-bugfix/issue-1620-video-stream-background-string.tar.gz |
added new helper method to invalidate compression sessionbugfix/issue-1620-video-stream-background-string
-rw-r--r-- | SmartDeviceLink/SDLH264VideoEncoder.m | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/SmartDeviceLink/SDLH264VideoEncoder.m b/SmartDeviceLink/SDLH264VideoEncoder.m index 58d6178af..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 { @@ -341,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); |