Access UIApplication on main thread

Track UIApplication applicationState changes from a C++ class. Uses
NSNotificationCenter to access changes on the main thread and exposes
a local variable that can be checked from any thread.

This fixes a runtime warning on iOS 11 beta.

My Objective-C++ is a little rusty so please check if this follows
the conventions for C++ code in the project. It also changes the
interface exposed by RTCUIApplication.h, not sure if that has impact
on any public APIs that needs to be documented somewhere?

Bug: webrtc:7773
Change-Id: I9c8ba090ef9f28d812114026a906cef742192c39
Reviewed-on: https://chromium-review.googlesource.com/527442
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Kári Tristan Helgason <kthelgason@webrtc.org>
Commit-Queue: Anders Carlsson <andersc@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#18558}
This commit is contained in:
Anders Carlsson
2017-06-12 14:16:20 +02:00
committed by Commit Bot
parent 5b383c0ebd
commit fc309750a9
7 changed files with 99 additions and 61 deletions

View File

@ -13,9 +13,6 @@
#include <memory>
#if defined(WEBRTC_IOS)
#include "Common/RTCUIApplication.h"
#endif
#include "libyuv/convert.h"
#include "webrtc/api/video/video_frame.h"
#include "webrtc/base/checks.h"
@ -24,6 +21,10 @@
#include "webrtc/sdk/objc/Framework/Classes/Video/corevideo_frame_buffer.h"
#include "webrtc/sdk/objc/Framework/Classes/VideoToolbox/nalu_rewriter.h"
#if defined(WEBRTC_IOS)
#import "Common/RTCUIApplicationStatusObserver.h"
#endif
namespace webrtc {
namespace {
@ -74,9 +75,7 @@ void VTDecompressionOutputCallback(void* decoder,
} // namespace
H264VideoToolboxDecoder::H264VideoToolboxDecoder()
: callback_(nullptr),
video_format_(nullptr),
decompression_session_(nullptr) {}
: callback_(nullptr), video_format_(nullptr), decompression_session_(nullptr) {}
H264VideoToolboxDecoder::~H264VideoToolboxDecoder() {
DestroyDecompressionSession();
@ -97,7 +96,7 @@ int H264VideoToolboxDecoder::Decode(
RTC_DCHECK(input_image._buffer);
#if defined(WEBRTC_IOS)
if (!RTCIsUIApplicationActive()) {
if (![[RTCUIApplicationStatusObserver sharedInstance] isApplicationActive]) {
// Ignore all decode requests when app isn't active. In this state, the
// hardware decoder has been invalidated by the OS.
// Reset video format so that we won't process frames until the next