Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Unified Diff: webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.cc

Issue 1732953003: Fix VideoToolbox backgrounding issues (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Update comments. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.cc
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 407bb6760880baf3b238abb6571aca99f9296306..c5218235dfa4901a8c3da5bfeca1d765bd13a889 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
@@ -20,6 +20,9 @@
#include "libyuv/convert_from.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
+#if defined(WEBRTC_IOS)
+#include "webrtc/base/objc/RTCUIApplication.h"
+#endif
#include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h"
#include "webrtc/system_wrappers/include/clock.h"
@@ -238,10 +241,30 @@ int H264VideoToolboxEncoder::Encode(
if (!callback_ || !compression_session_) {
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
}
-
+#if defined(WEBRTC_IOS)
+ bool is_app_active = RTCIsUIApplicationActive();
pbos-webrtc 2016/03/04 10:44:15 Just if(RTC..) ?
tkchin_webrtc 2016/03/04 19:03:07 Done.
+ if (!is_app_active) {
+ // Ignore all encode requests when app isn't active. In this state, the
+ // hardware encoder has been invalidated by the OS.
+ return WEBRTC_VIDEO_CODEC_OK;
+ }
+#endif
// Get a pixel buffer from the pool and copy frame data over.
CVPixelBufferPoolRef pixel_buffer_pool =
VTCompressionSessionGetPixelBufferPool(compression_session_);
+ 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.
+ ResetCompressionSession();
+ pixel_buffer_pool =
+ VTCompressionSessionGetPixelBufferPool(compression_session_);
+ }
+ if (!pixel_buffer_pool) {
+ LOG(LS_ERROR) << "Failed to get pixel buffer pool.";
+ return WEBRTC_VIDEO_CODEC_ERROR;
+ }
CVPixelBufferRef pixel_buffer = nullptr;
CVReturn ret = CVPixelBufferPoolCreatePixelBuffer(nullptr, pixel_buffer_pool,
&pixel_buffer);
@@ -285,7 +308,7 @@ int H264VideoToolboxEncoder::Encode(
// Update the bitrate if needed.
SetBitrateBps(bitrate_adjuster_.GetAdjustedBitrateBps());
- VTCompressionSessionEncodeFrame(
+ OSStatus status = VTCompressionSessionEncodeFrame(
compression_session_, pixel_buffer, presentation_time_stamp,
kCMTimeInvalid, frame_properties, encode_params.release(), nullptr);
if (frame_properties) {
@@ -294,6 +317,10 @@ int H264VideoToolboxEncoder::Encode(
if (pixel_buffer) {
CVBufferRelease(pixel_buffer);
}
+ if (status != noErr) {
+ LOG(LS_ERROR) << "Failed to encode frame with code: " << status;
+ return WEBRTC_VIDEO_CODEC_ERROR;
+ }
return WEBRTC_VIDEO_CODEC_OK;
}

Powered by Google App Engine
This is Rietveld 408576698