diff options
author | lapinskijw <jlapinski.dev@gmail.com> | 2020-05-12 11:13:32 -0400 |
---|---|---|
committer | lapinskijw <jlapinski.dev@gmail.com> | 2020-05-12 11:13:32 -0400 |
commit | 88f083e98e5de93541f94bdf3cfe3e1923b6178a (patch) | |
tree | a9e99fba4e1d3b1617ce6a22b96573ea6925d8ed | |
parent | d329d65aaeda2df45ad21c40bd4ba0a1b73b4c63 (diff) | |
download | sdl_ios-88f083e98e5de93541f94bdf3cfe3e1923b6178a.tar.gz |
removed current implementation and added VTCompressionSessionCompleteFrames
-rw-r--r-- | SmartDeviceLink/SDLH264VideoEncoder.h | 4 | ||||
-rw-r--r-- | SmartDeviceLink/SDLH264VideoEncoder.m | 47 | ||||
-rw-r--r-- | SmartDeviceLink/SDLStreamingVideoLifecycleManager.m | 15 | ||||
-rw-r--r-- | SmartDeviceLink/SDLVideoEncoderDelegate.h | 2 |
4 files changed, 4 insertions, 64 deletions
diff --git a/SmartDeviceLink/SDLH264VideoEncoder.h b/SmartDeviceLink/SDLH264VideoEncoder.h index d1a43484d..58bde0508 100644 --- a/SmartDeviceLink/SDLH264VideoEncoder.h +++ b/SmartDeviceLink/SDLH264VideoEncoder.h @@ -66,10 +66,6 @@ extern NSString *const SDLErrorDomainVideoEncoder; - (BOOL)encodeFrame:(CVImageBufferRef)imageBuffer presentationTimestamp:(CMTime)presentationTimestamp; -- (void)encodeSavedFrame:(CVImageBufferRef)imageBuffer; - -- (void)encodeSavedFrame:(CVImageBufferRef)imageBuffer presentationTimestamp:(CMTime)presentationTimestamp; - /** * Creates a new pixel buffer using the pixelBufferPool property. */ diff --git a/SmartDeviceLink/SDLH264VideoEncoder.m b/SmartDeviceLink/SDLH264VideoEncoder.m index 15f5554a5..aaa868f42 100644 --- a/SmartDeviceLink/SDLH264VideoEncoder.m +++ b/SmartDeviceLink/SDLH264VideoEncoder.m @@ -142,52 +142,6 @@ static NSDictionary<NSString *, id>* _defaultVideoEncoderSettings; } } -- (void)encodeSavedFrame:(CVImageBufferRef)imageBuffer { - [self encodeSavedFrame:imageBuffer presentationTimestamp:kCMTimeInvalid]; -} - -- (void)encodeSavedFrame:(CVImageBufferRef)imageBuffer presentationTimestamp:(CMTime)presentationTimestamp { - if (!CMTIME_IS_VALID(presentationTimestamp)) { - int32_t timeRate = 30; - if (self.videoEncoderSettings[(__bridge NSString *)kVTCompressionPropertyKey_ExpectedFrameRate] != nil) { - timeRate = ((NSNumber *)self.videoEncoderSettings[(__bridge NSString *)kVTCompressionPropertyKey_ExpectedFrameRate]).intValue; - } - - presentationTimestamp = CMTimeMake((int64_t)self.currentFrameNumber, timeRate); - } - self.currentFrameNumber++; - - VTCompressionSessionEncodeFrameWithOutputHandler(_compressionSession, imageBuffer, presentationTimestamp, kCMTimeInvalid, NULL, NULL, ^(OSStatus status, VTEncodeInfoFlags infoFlags, CMSampleBufferRef _Nullable sampleBuffer) { - if (status != noErr) { - SDLLogW(@"Error encoding video frame: %d", (int)status); - return; - } - - if (sampleBuffer == NULL) { - return; - } - - NSArray *nalUnits = [self.class sdl_extractNalUnitsFromSampleBuffer:sampleBuffer]; - - const CMTime presentationTimestampInCMTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer); - double presentationTimestamp = 0.0; - if (CMTIME_IS_VALID(presentationTimestampInCMTime)) { - presentationTimestamp = CMTimeGetSeconds(presentationTimestampInCMTime); - } - if (self.timestampOffset == 0.0) { - // remember this first timestamp as the offset - self.timestampOffset = presentationTimestamp; - } - - NSArray *packets = [self.packetizer createPackets:nalUnits - presentationTimestamp:(presentationTimestamp - self.timestampOffset)]; - - if ([self.delegate respondsToSelector:@selector(videoEncoder:hasEncodedFramesToBeSaved:)]) { - [self.delegate videoEncoder:self hasEncodedFramesToBeSaved:packets]; - } - }); -} - - (BOOL)encodeFrame:(CVImageBufferRef)imageBuffer { return [self encodeFrame:imageBuffer presentationTimestamp:kCMTimeInvalid]; } @@ -204,6 +158,7 @@ static NSDictionary<NSString *, id>* _defaultVideoEncoderSettings; self.currentFrameNumber++; OSStatus status = VTCompressionSessionEncodeFrame(_compressionSession, imageBuffer, presentationTimestamp, kCMTimeInvalid, NULL, (__bridge void *)self, NULL); + VTCompressionSessionCompleteFrames(_compressionSession, presentationTimestamp); return (status == noErr); } diff --git a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m index 3d4541c19..be9135cb8 100644 --- a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m +++ b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m @@ -81,8 +81,6 @@ typedef void(^SDLVideoCapabilityResponseHandler)(SDLVideoStreamingCapability *_N @property (assign, nonatomic, readwrite, getter=isVideoEncrypted) BOOL videoEncrypted; -@property (nonatomic, copy) NSArray *savedBackgroundFrames; - /** * SSRC of RTP header field. * @@ -303,9 +301,7 @@ typedef void(^SDLVideoCapabilityResponseHandler)(SDLVideoStreamingCapability *_N } if (_showVideoBackgroundDisplay) { - for (NSData *packet in _savedBackgroundFrames) { - [self.videoEncoder.delegate videoEncoder:self.videoEncoder hasEncodedFrame:packet]; - } + [self sdl_sendBackgroundFrames]; } [self.touchManager cancelPendingTouches]; @@ -470,7 +466,6 @@ typedef void(^SDLVideoCapabilityResponseHandler)(SDLVideoStreamingCapability *_N } self.backgroundingPixelBuffer = backgroundingPixelBuffer; - [self sdl_sendBackgroundFrames]; } self.lastPresentationTimestamp = kCMTimeInvalid; } @@ -671,10 +666,6 @@ typedef void(^SDLVideoCapabilityResponseHandler)(SDLVideoStreamingCapability *_N } } -- (void)videoEncoder:(SDLH264VideoEncoder *)encoder hasEncodedFramesToBeSaved:(NSArray *)encodedVideoFrames { - _savedBackgroundFrames = encodedVideoFrames; -} - #pragma mark - Streaming session helpers - (void)sdl_startVideoSession { @@ -746,9 +737,9 @@ typedef void(^SDLVideoCapabilityResponseHandler)(SDLVideoStreamingCapability *_N for (int frameCount = 0; frameCount < FramesToSendOnBackground; frameCount++) { if (CMTIME_IS_VALID(self.lastPresentationTimestamp)) { self.lastPresentationTimestamp = CMTimeAdd(self.lastPresentationTimestamp, interval); - [self.videoEncoder encodeSavedFrame:self.backgroundingPixelBuffer presentationTimestamp:self.lastPresentationTimestamp]; + [self.videoEncoder encodeFrame:self.backgroundingPixelBuffer presentationTimestamp:self.lastPresentationTimestamp]; } else { - [self.videoEncoder encodeSavedFrame:self.backgroundingPixelBuffer]; + [self.videoEncoder encodeFrame:self.backgroundingPixelBuffer]; } } } diff --git a/SmartDeviceLink/SDLVideoEncoderDelegate.h b/SmartDeviceLink/SDLVideoEncoderDelegate.h index 42754fec2..a8bf27f22 100644 --- a/SmartDeviceLink/SDLVideoEncoderDelegate.h +++ b/SmartDeviceLink/SDLVideoEncoderDelegate.h @@ -14,6 +14,4 @@ - (void)videoEncoder:(SDLH264VideoEncoder *)encoder hasEncodedFrame:(NSData*)encodedVideo; -- (void)videoEncoder:(SDLH264VideoEncoder *)encoder hasEncodedFramesToBeSaved:(NSArray *)encodedVideoFrames; - @end |