[asterisk-commits] tilghman: branch 1.4 r297818 - in /branches/1.4: ./ contrib/init.d/ utils/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Dec 7 16:35:56 CST 2010


Author: tilghman
Date: Tue Dec  7 16:35:50 2010
New Revision: 297818

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=297818
Log:
Use non-deprecated APIs for CoreAudio

Review: https://reviewboard.asterisk.org/r/1040/

Added:
    branches/1.4/contrib/init.d/org.asterisk.muted.plist   (with props)
Modified:
    branches/1.4/Makefile
    branches/1.4/utils/muted.c

Modified: branches/1.4/Makefile
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/Makefile?view=diff&rev=297818&r1=297817&r2=297818
==============================================================================
--- branches/1.4/Makefile (original)
+++ branches/1.4/Makefile Tue Dec  7 16:35:50 2010
@@ -698,8 +698,13 @@
 		elif [ -f /etc/SuSE-release -o -f /etc/novell-release ]; then \
 			$(INSTALL) -m 755 contrib/init.d/rc.suse.asterisk $(DESTDIR)/etc/init.d/asterisk; \
 			if [ -z "$(DESTDIR)" ]; then /sbin/chkconfig --add asterisk; fi; \
-		elif [ -d $(DESTDIR)/Library/LaunchDaemons -a ! -f $(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist ]; then \
-			$(INSTALL) -m 644 contrib/init.d/org.asterisk.asterisk.plist $(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist; \
+		elif [ -d $(DESTDIR)/Library/LaunchDaemons ]; then \
+			if [ ! -f $(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist ]; then \
+				$(INSTALL) -m 644 contrib/init.d/org.asterisk.asterisk.plist $(DESTDIR)/Library/LaunchDaemons/org.asterisk.asterisk.plist; \
+			fi; \
+			if [ ! -f $(DESTDIR)/Library/LaunchDaemons/org.asterisk.muted.plist ]; then \
+				$(INSTALL) -m 644 contrib/init.d/org.asterisk.muted.plist $(DESTDIR)/Library/LaunchDaemons/org.asterisk.muted.plist; \
+			fi; \
 		elif [ -f /etc/slackware-version ]; then \
 			echo "Slackware is not currently supported, although an init script does exist for it."; \
 		else \

Added: branches/1.4/contrib/init.d/org.asterisk.muted.plist
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/contrib/init.d/org.asterisk.muted.plist?view=auto&rev=297818
==============================================================================
--- branches/1.4/contrib/init.d/org.asterisk.muted.plist (added)
+++ branches/1.4/contrib/init.d/org.asterisk.muted.plist Tue Dec  7 16:35:50 2010
@@ -1,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>Label</key>
+	<string>org.asterisk.muted</string>
+	<key>Disabled</key>
+	<true/>
+	<key>UserName</key>
+	<string>asterisk</string>
+	<key>GroupName</key>
+	<string>asterisk</string>
+	<key>KeepAlive</key>
+	<true/>
+	<key>RunAtLoad</key>
+	<true/>
+	<key>Umask</key>
+	<integer>7</integer><!-- 0007 -->
+	<key>Program</key>
+	<string>/usr/sbin/muted</string>
+	<key>ProgramArguments</key>
+	<array>
+		<string>/usr/sbin/muted</string>
+		<string>-f</string>
+	</array>
+	<key>StandardInPath</key>
+	<string>/dev/null</string>
+	<key>StandardOutPath</key>
+	<string>/dev/null</string>
+	<key>StandardErrorPath</key>
+	<string>/dev/null</string>
+</dict>
+</plist>

Propchange: branches/1.4/contrib/init.d/org.asterisk.muted.plist
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: branches/1.4/contrib/init.d/org.asterisk.muted.plist
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision Yoyo

Propchange: branches/1.4/contrib/init.d/org.asterisk.muted.plist
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: branches/1.4/utils/muted.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/utils/muted.c?view=diff&rev=297818&r1=297817&r2=297818
==============================================================================
--- branches/1.4/utils/muted.c (original)
+++ branches/1.4/utils/muted.c Tue Dec  7 16:35:50 2010
@@ -37,6 +37,9 @@
 
 #ifdef __Darwin__
 #include <CoreAudio/AudioHardware.h> 
+#include <sys/types.h>
+#include <pwd.h>
+#include <sys/stat.h>
 #elif defined(__linux__) || defined(__FreeBSD__)
 #include <sys/soundcard.h>
 #endif
@@ -53,6 +56,8 @@
 #include <arpa/inet.h>
 
 #include "asterisk/autoconfig.h"
+
+#define ast_strlen_zero(a)	(!(*(a)))
 
 static char *config = "/etc/asterisk/muted.conf";
 
@@ -349,17 +354,25 @@
 	AudioDeviceID device;
 	UInt32 size;
 	UInt32 channels[2];
+	AudioObjectPropertyAddress OutputAddr = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
+	AudioObjectPropertyAddress ChannelAddr = { kAudioDevicePropertyPreferredChannelsForStereo, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementWildcard };
+	AudioObjectPropertyAddress VolumeAddr = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeOutput, };
 
 	size = sizeof(device);
-	err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, &device);
+	err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &OutputAddr, 0, NULL, &size, &device);
 	size = sizeof(channels);
-	if (!err) 
-		err = AudioDeviceGetProperty(device, 0, false, kAudioDevicePropertyPreferredChannelsForStereo, &size, &channels);
+	if (!err) {
+		err = AudioObjectGetPropertyData(device, &ChannelAddr, 0, NULL, &size, &channels);
+	}
 	size = sizeof(vol);
-	if (!err)
-		err = AudioDeviceGetProperty(device, channels[0], false, kAudioDevicePropertyVolumeScalar, &size, &volumeL);
-	if (!err)
-		err = AudioDeviceGetProperty(device, channels[1], false, kAudioDevicePropertyVolumeScalar, &size, &volumeR);
+	if (!err) {
+		VolumeAddr.mElement = channels[0];
+		err = AudioObjectGetPropertyData(device, &VolumeAddr, 0, NULL, &size, &volumeL);
+	}
+	if (!err) {
+		VolumeAddr.mElement = channels[1];
+		err = AudioObjectGetPropertyData(device, &VolumeAddr, 0, NULL, &size, &volumeR);
+	}
 	if (!err)
 		vol = (volumeL < volumeR) ? volumeR : volumeL;
 	else {
@@ -385,16 +398,23 @@
 	AudioDeviceID device;
 	UInt32 size;
 	UInt32 channels[2];
+	AudioObjectPropertyAddress OutputAddr = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
+	AudioObjectPropertyAddress ChannelAddr = { kAudioDevicePropertyPreferredChannelsForStereo, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementWildcard };
+	AudioObjectPropertyAddress VolumeAddr = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeOutput, };
 
 	size = sizeof(device);
-	err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, &device);
+	err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &OutputAddr, 0, NULL, &size, &device);
 	size = sizeof(channels);
-	err = AudioDeviceGetProperty(device, 0, false, kAudioDevicePropertyPreferredChannelsForStereo, &size, &channels);
+	err = AudioObjectGetPropertyData(device, &ChannelAddr, 0, NULL, &size, &channels);
 	size = sizeof(vol);
-	if (!err)
-		err = AudioDeviceSetProperty(device, 0, channels[0], false, kAudioDevicePropertyVolumeScalar, size, &volumeL);
-	if (!err)
-		err = AudioDeviceSetProperty(device, 0, channels[1], false, kAudioDevicePropertyVolumeScalar, size, &volumeR); 
+	if (!err) {
+		VolumeAddr.mElement = channels[0];
+		err = AudioObjectSetPropertyData(device, &VolumeAddr, 0, NULL, size, &volumeL);
+	}
+	if (!err) {
+		VolumeAddr.mElement = channels[1];
+		err = AudioObjectSetPropertyData(device, &VolumeAddr, 0, NULL, size, &volumeR);
+	}
 	if (err) {
 #endif
 
@@ -692,11 +712,35 @@
 			exit(1);
 		}
 #else
-		fprintf(stderr, "Mac OS X detected.  Use 'launchd -d muted -f' to launch.\n");
+		const char *found = NULL, *paths[] = {
+			"/Library/LaunchAgents/org.asterisk.muted.plist",
+			"/Library/LaunchDaemons/org.asterisk.muted.plist",
+			"contrib/init.d/org.asterisk.muted.plist",
+			"<path-to-asterisk-source>/contrib/init.d/org.asterisk.muted.plist" };
+		char userpath[256];
+		struct stat unused;
+		struct passwd *pwd = getpwuid(getuid());
+		int i;
+
+		snprintf(userpath, sizeof(userpath), "%s%s", pwd->pw_dir, paths[0]);
+		if (!stat(userpath, &unused)) {
+			found = userpath;
+		}
+
+		if (!found) {
+			for (i = 0; i < 3; i++) {
+				if (!stat(paths[i], &unused)) {
+					found = paths[i];
+					break;
+				}
+			}
+		}
+
+		fprintf(stderr, "Mac OS X detected.  Use 'launchctl load -w %s' to launch.\n", found ? found : paths[3]);
 		exit(1);
-#endif
-	}
-#endif
+#endif /* !defined(HAVE_SBIN_LAUNCHD */
+	}
+#endif /* HAVE_WORKING_FORK */
 	for(;;) {
 		if (wait_event()) {
 			fclose(astf);




More information about the asterisk-commits mailing list