From 9ff9c6540b245615e28282812aeaa99c2bdf911f Mon Sep 17 00:00:00 2001 From: tkchin Date: Mon, 11 Apr 2016 11:40:25 -0700 Subject: [PATCH] iOS h264: Request keyframe after coming back from background. BUG= Review URL: https://codereview.webrtc.org/1877613002 Cr-Commit-Position: refs/heads/master@{#12319} --- .../video_coding/codecs/h264/h264_video_toolbox_encoder.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.cc b/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.cc index 8cfe63dbb7..feacfc57b3 100644 --- a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.cc +++ b/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.cc @@ -248,6 +248,7 @@ int H264VideoToolboxEncoder::Encode( return WEBRTC_VIDEO_CODEC_OK; } #endif + bool is_keyframe_required = false; // Get a pixel buffer from the pool and copy frame data over. CVPixelBufferPoolRef pixel_buffer_pool = VTCompressionSessionGetPixelBufferPool(compression_session_); @@ -257,9 +258,11 @@ int H264VideoToolboxEncoder::Encode( // 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) { @@ -283,8 +286,7 @@ int H264VideoToolboxEncoder::Encode( } // Check if we need a keyframe. - bool is_keyframe_required = false; - if (frame_types) { + if (!is_keyframe_required && frame_types) { for (auto frame_type : *frame_types) { if (frame_type == kVideoFrameKey) { is_keyframe_required = true;