iOS H264 encoder: Make initial compression session respect pixel format.

Bug: webrtc:9150
Change-Id: Ib331391f585c3d94190bb67c38e2d59b22834b25
Reviewed-on: https://webrtc-review.googlesource.com/69812
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Commit-Queue: Anders Carlsson <andersc@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22872}
This commit is contained in:
Anders Carlsson
2018-04-13 14:12:22 +02:00
committed by Commit Bot
parent b1f063db32
commit 5b07c24056

View File

@ -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;