From 7d387dc63f75da867a1b9e07cd957b456de99c12 Mon Sep 17 00:00:00 2001 From: volzhs Date: Fri, 14 Dec 2018 00:35:01 +0900 Subject: [PATCH] Request mic access only when is needed --- doc/classes/ProjectSettings.xml | 3 +++ drivers/coreaudio/audio_driver_coreaudio.cpp | 5 ++++- servers/audio/audio_stream.cpp | 7 +++++++ servers/audio_server.cpp | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 7a9918237f6..bf9eaa04a7b 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -210,6 +210,9 @@ + + This option should be enabled if project works with microphone. + Mix rate used for audio. In general, it's better to not touch this and leave it to the host operating system. diff --git a/drivers/coreaudio/audio_driver_coreaudio.cpp b/drivers/coreaudio/audio_driver_coreaudio.cpp index 726cee10a45..3d093b965a0 100644 --- a/drivers/coreaudio/audio_driver_coreaudio.cpp +++ b/drivers/coreaudio/audio_driver_coreaudio.cpp @@ -159,7 +159,10 @@ Error AudioDriverCoreAudio::init() { result = AudioUnitInitialize(audio_unit); ERR_FAIL_COND_V(result != noErr, FAILED); - return capture_init(); + if (GLOBAL_GET("audio/enable_audio_input")) { + return capture_init(); + } + return OK; } OSStatus AudioDriverCoreAudio::output_callback(void *inRefCon, diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp index 02a0bed9649..21073a1cd1b 100644 --- a/servers/audio/audio_stream.cpp +++ b/servers/audio/audio_stream.cpp @@ -30,6 +30,7 @@ #include "audio_stream.h" #include "core/os/os.h" +#include "core/project_settings.h" ////////////////////////////// @@ -184,6 +185,12 @@ float AudioStreamPlaybackMicrophone::get_stream_sampling_rate() { } void AudioStreamPlaybackMicrophone::start(float p_from_pos) { + + if (!GLOBAL_GET("audio/enable_audio_input")) { + WARN_PRINTS("Need to enable Project settings > Audio > Enable Audio Input option to use capturing."); + return; + } + input_ofs = 0; AudioDriver::get_singleton()->capture_start(); diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index 530976f0840..759dd779268 100644 --- a/servers/audio_server.cpp +++ b/servers/audio_server.cpp @@ -172,6 +172,7 @@ int AudioDriverManager::get_driver_count() { } void AudioDriverManager::initialize(int p_driver) { + GLOBAL_DEF_RST("audio/enable_audio_input", false); int failed_driver = -1; // Check if there is a selected driver