From 4c45234b81c7dead5fd376893ad3e2f3e2852f15 Mon Sep 17 00:00:00 2001 From: tkchin Date: Tue, 9 Aug 2016 13:02:00 -0700 Subject: [PATCH] Fix regression for h264 VideoToolbox entering background. We need to check the pool to make sure that the encoder session is valid. Otherwise, it appears as if the encoder just does not output frames. NOTRY=True BUG= Review-Url: https://codereview.webrtc.org/2226383002 Cr-Commit-Position: refs/heads/master@{#13698} --- .../codecs/h264/h264_video_toolbox_encoder.mm | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm b/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm index 5a1fe845f7..43c3fe575b 100644 --- a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm +++ b/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm @@ -307,27 +307,30 @@ int H264VideoToolboxEncoder::Encode( return ret; } + // Get a pixel buffer from the pool and copy frame data over. + CVPixelBufferPoolRef pixel_buffer_pool = + VTCompressionSessionGetPixelBufferPool(compression_session_); +#if defined(WEBRTC_IOS) + if (!pixel_buffer_pool) { + // Kind of a hack. On backgrounding, the compression session seems to get + // invalidated, which causes this pool call to fail when the application + // is foregrounded and frames are being sent for encoding again. + // Resetting the session when this happens fixes the issue. + // In addition we request a keyframe so video can recover quickly. + ResetCompressionSession(); + pixel_buffer_pool = + VTCompressionSessionGetPixelBufferPool(compression_session_); + is_keyframe_required = true; + LOG(LS_INFO) << "Resetting compression session due to invalid pool."; + } +#endif + CVPixelBufferRef pixel_buffer = static_cast(input_image->native_handle()); if (pixel_buffer) { CVBufferRetain(pixel_buffer); + pixel_buffer_pool = nullptr; } else { - // Get a pixel buffer from the pool and copy frame data over. - CVPixelBufferPoolRef pixel_buffer_pool = - VTCompressionSessionGetPixelBufferPool(compression_session_); -#if defined(WEBRTC_IOS) - if (!pixel_buffer_pool) { - // Kind of a hack. On backgrounding, the compression session seems to get - // invalidated, which causes this pool call to fail when the application - // is foregrounded and frames are being sent for encoding again. - // Resetting the session when this happens fixes the issue. - // In addition we request a keyframe so video can recover quickly. - ResetCompressionSession(); - pixel_buffer_pool = - VTCompressionSessionGetPixelBufferPool(compression_session_); - is_keyframe_required = true; - } -#endif if (!pixel_buffer_pool) { LOG(LS_ERROR) << "Failed to get pixel buffer pool."; return WEBRTC_VIDEO_CODEC_ERROR;