From 6c92a724a1893eceac644a65ff5660e73ba6d42e Mon Sep 17 00:00:00 2001
From: Monroe Linden <monroe@lindenlab.com>
Date: Wed, 27 Jan 2010 16:48:09 -0800
Subject: [PATCH] Implemented LLAppViewerMacOSX::setMasterSystemAudioMute() and
 LLAppViewerMacOSX::getMasterSystemAudioMute() using CoreAudio APIs.

This required adding a reference to the CoreAudio framework in indra/newview/CMakeLists.txt
---
 indra/newview/CMakeLists.txt        |  2 ++
 indra/newview/llappviewermacosx.cpp | 50 ++++++++++++++++++++++++++---
 2 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt
index 7ddeb90d295..4c0c895a7df 100644
--- a/indra/newview/CMakeLists.txt
+++ b/indra/newview/CMakeLists.txt
@@ -1064,11 +1064,13 @@ if (DARWIN)
   find_library(APPKIT_LIBRARY AppKit)
   find_library(COCOA_LIBRARY Cocoa)
   find_library(IOKIT_LIBRARY IOKit)
+  find_library(COREAUDIO_LIBRARY CoreAudio)
 
   set(viewer_LIBRARIES
     ${COCOA_LIBRARY}
     ${AGL_LIBRARY}
     ${IOKIT_LIBRARY}
+    ${COREAUDIO_LIBRARY}
     )
 
   # Add resource files to the project.
diff --git a/indra/newview/llappviewermacosx.cpp b/indra/newview/llappviewermacosx.cpp
index cc38a0940cb..f8f8f50cd6c 100644
--- a/indra/newview/llappviewermacosx.cpp
+++ b/indra/newview/llappviewermacosx.cpp
@@ -50,6 +50,7 @@
 #include <Carbon/Carbon.h>
 #include "lldir.h"
 #include <signal.h>
+#include <CoreAudio/CoreAudio.h>	// for systemwide mute
 class LLMediaCtrl;		// for LLURLDispatcher
 
 namespace 
@@ -444,18 +445,57 @@ std::string LLAppViewerMacOSX::generateSerialNumber()
 	return serial_md5;
 }
 
+static AudioDeviceID get_default_audio_output_device(void)
+{
+	AudioDeviceID device = 0;
+	UInt32 size;
+	OSStatus err;
+	
+	size = sizeof(device);
+	err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, &device);
+	if(err != noErr)
+	{
+		LL_DEBUGS("SystemMute") << "Couldn't get default audio output device (0x" << std::hex << err << ")" << LL_ENDL;
+	}
+	
+	return device;
+}
+
 //virtual
-void LLAppViewerMacOSX::setMasterSystemAudioMute(bool mute)
+void LLAppViewerMacOSX::setMasterSystemAudioMute(bool new_mute)
 {
-	// XXX TODO: make this actually set the OS's audio mute state
-	gSavedSettings.setBOOL("MuteAudio", mute);
+	AudioDeviceID device = get_default_audio_output_device();
+	
+	if(device != 0)
+	{
+		UInt32 mute = new_mute;
+		OSStatus err = AudioDeviceSetProperty(device, NULL, 0, false, kAudioDevicePropertyMute, sizeof(mute), &mute);
+		if(err != noErr)
+		{
+			LL_INFOS("SystemMute") << "Couldn't set audio mute property (0x" << std::hex << err << ")" << LL_ENDL;
+		}
+	}
 }
 
 //virtual
 bool LLAppViewerMacOSX::getMasterSystemAudioMute()
 {
-	// XXX TODO: make this actually get the OS's audio mute state
-	return gSavedSettings.getBOOL("MuteAudio");
+	// Assume the system isn't muted 
+	UInt32 mute = 0;
+	
+	AudioDeviceID device = get_default_audio_output_device();
+	
+	if(device != 0)
+	{
+		UInt32 size = sizeof(mute);
+		OSStatus err = AudioDeviceGetProperty(device, 0, false, kAudioDevicePropertyMute, &size, &mute);
+		if(err != noErr)
+		{
+			LL_DEBUGS("SystemMute") << "Couldn't get audio mute property (0x" << std::hex << err << ")" << LL_ENDL;
+		}
+	}
+	
+	return (mute != 0);
 }
 
 OSErr AEGURLHandler(const AppleEvent *messagein, AppleEvent *reply, long refIn)
-- 
GitLab