mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 19:22:57 +02:00
On Mac OS, disable App Nap to prevent audio glitches while running in the background
This commit is contained in:
parent
1e94a82ee6
commit
ae62b96f67
3 changed files with 57 additions and 0 deletions
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
|
27
interface/src/AppNapDisabler.mm
Normal file
27
interface/src/AppNapDisabler.mm
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
|
||||||
|
#include "AppNapDisabler.h"
|
||||||
|
|
||||||
|
#import <AppKit/AppKit.h>
|
||||||
|
|
||||||
|
AppNapDisabler::AppNapDisabler() {
|
||||||
|
_activity = [[NSProcessInfo processInfo] beginActivityWithOptions:NSActivityBackground 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"
|
#include "AndroidHelper.h"
|
||||||
#endif
|
#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"
|
#include "graphics/RenderEventHandler.h"
|
||||||
|
|
||||||
Q_LOGGING_CATEGORY(trace_app_input_mouse, "trace.app.input.mouse")
|
Q_LOGGING_CATEGORY(trace_app_input_mouse, "trace.app.input.mouse")
|
||||||
|
|
Loading…
Reference in a new issue