mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
Merge pull request #16254 from kencooke/macos-appnap-disabler
BUGZ-1117: On Mac OS, disable App Nap to prevent audio glitches
This commit is contained in:
commit
220123ff3b
4 changed files with 64 additions and 2 deletions
|
@ -70,12 +70,16 @@ file(GLOB_RECURSE INTERFACE_SRCS "src/*.cpp" "src/*.h")
|
|||
GroupSources("src")
|
||||
list(APPEND INTERFACE_SRCS ${RESOURCES_RCC})
|
||||
|
||||
# grab the Objective-C sources on OS X
|
||||
if (APPLE)
|
||||
file(GLOB_RECURSE INTERFACE_OBJCPP_SRCS "src/*.m" "src/*.mm")
|
||||
list(APPEND INTERFACE_SRCS ${INTERFACE_OBJCPP_SRCS})
|
||||
endif ()
|
||||
|
||||
# Add SpeechRecognizer if on Windows or OS X, otherwise remove
|
||||
if (WIN32)
|
||||
# Use .cpp and .h files as is.
|
||||
elseif (APPLE)
|
||||
file(GLOB INTERFACE_OBJCPP_SRCS "src/SpeechRecognizer.mm")
|
||||
set(INTERFACE_SRCS ${INTERFACE_SRCS} ${INTERFACE_OBJCPP_SRCS})
|
||||
get_filename_component(SPEECHRECOGNIZER_CPP "src/SpeechRecognizer.cpp" ABSOLUTE)
|
||||
list(REMOVE_ITEM INTERFACE_SRCS ${SPEECHRECOGNIZER_CPP})
|
||||
else ()
|
||||
|
|
24
interface/src/AppNapDisabler.h
Normal file
24
interface/src/AppNapDisabler.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// AppNapDisabler.h
|
||||
// interface/src
|
||||
//
|
||||
// Copyright 2019 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_AppNapDisabler_h
|
||||
#define hifi_AppNapDisabler_h
|
||||
|
||||
#import <objc/objc-runtime.h>
|
||||
|
||||
class AppNapDisabler {
|
||||
public:
|
||||
AppNapDisabler();
|
||||
~AppNapDisabler();
|
||||
private:
|
||||
id _activity;
|
||||
};
|
||||
|
||||
#endif // hifi_AppNapDisabler_h
|
28
interface/src/AppNapDisabler.mm
Normal file
28
interface/src/AppNapDisabler.mm
Normal file
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// AppNapDisabler.mm
|
||||
// interface/src
|
||||
//
|
||||
// Copyright 2019 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <QtGlobal>
|
||||
#ifdef Q_OS_MAC
|
||||
|
||||
#include "AppNapDisabler.h"
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
AppNapDisabler::AppNapDisabler() {
|
||||
_activity = [[NSProcessInfo processInfo] beginActivityWithOptions:NSActivityUserInitiated reason:@"Audio is in use"];
|
||||
[_activity retain];
|
||||
}
|
||||
|
||||
AppNapDisabler::~AppNapDisabler() {
|
||||
[[NSProcessInfo processInfo] endActivity:_activity];
|
||||
[_activity release];
|
||||
}
|
||||
|
||||
#endif // Q_OS_MAC
|
|
@ -265,6 +265,12 @@ extern "C" {
|
|||
#include "AndroidHelper.h"
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_MAC)
|
||||
// On Mac OS, disable App Nap to prevent audio glitches while running in the background
|
||||
#include "AppNapDisabler.h"
|
||||
static AppNapDisabler appNapDisabler; // disabled, while in scope
|
||||
#endif
|
||||
|
||||
#include "graphics/RenderEventHandler.h"
|
||||
|
||||
Q_LOGGING_CATEGORY(trace_app_input_mouse, "trace.app.input.mouse")
|
||||
|
|
Loading…
Reference in a new issue