From 5b07c240560c5dd055034fb84b74abecc9bcd0a1 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Fri, 13 Apr 2018 14:12:22 +0200 Subject: [PATCH] iOS H264 encoder: Make initial compression session respect pixel format. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:9150 Change-Id: Ib331391f585c3d94190bb67c38e2d59b22834b25 Reviewed-on: https://webrtc-review.googlesource.com/69812 Reviewed-by: Kári Helgason Commit-Queue: Anders Carlsson Cr-Commit-Position: refs/heads/master@{#22872} --- .../VideoToolbox/RTCVideoEncoderH264.mm | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm b/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm index 39620d2012..a0b6d78179 100644 --- a/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm +++ b/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm @@ -488,6 +488,16 @@ CFStringRef ExtractProfile(webrtc::SdpVideoFormat videoFormat) { withFrame:(RTCVideoFrame *)frame { BOOL resetCompressionSession = NO; + // If we're capturing native frames in another pixel format than the compression session is + // configured with, make sure the compression session is reset using the correct pixel format. + // If we're capturing non-native frames and the compression session is configured with a non-NV12 + // format, reset it to NV12. + OSType framePixelFormat = kNV12PixelFormat; + if ([frame.buffer isKindOfClass:[RTCCVPixelBuffer class]]) { + RTCCVPixelBuffer *rtcPixelBuffer = (RTCCVPixelBuffer *)frame.buffer; + framePixelFormat = CVPixelBufferGetPixelFormatType(rtcPixelBuffer.pixelBuffer); + } + #if defined(WEBRTC_IOS) if (!pixelBufferPool) { // Kind of a hack. On backgrounding, the compression session seems to get @@ -500,11 +510,6 @@ CFStringRef ExtractProfile(webrtc::SdpVideoFormat videoFormat) { } #endif - // If we're capturing native frames in another pixel format than the compression session is - // configured with, make sure the compression session is reset using the correct pixel format. - // If we're capturing non-native frames and the compression session is configured with a non-NV12 - // format, reset it to NV12. - OSType framePixelFormat = kNV12PixelFormat; if (pixelBufferPool) { // The pool attribute `kCVPixelBufferPixelFormatTypeKey` can contain either an array of pixel // formats or a single pixel format. @@ -519,11 +524,6 @@ CFStringRef ExtractProfile(webrtc::SdpVideoFormat videoFormat) { compressionSessionPixelFormats = @[ (NSNumber *)pixelFormats ]; } - if ([frame.buffer isKindOfClass:[RTCCVPixelBuffer class]]) { - RTCCVPixelBuffer *rtcPixelBuffer = (RTCCVPixelBuffer *)frame.buffer; - framePixelFormat = CVPixelBufferGetPixelFormatType(rtcPixelBuffer.pixelBuffer); - } - if (![compressionSessionPixelFormats containsObject:[NSNumber numberWithLong:framePixelFormat]]) { resetCompressionSession = YES;