Path: blob/master/src/java.desktop/macosx/native/libjsound/PLATFORM_API_MacOSX_Utils.h
41152 views
/*1* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <CoreAudio/CoreAudio.h>26#include <pthread.h>2728extern "C" {29#include "Utilities.h"30}313233#ifdef USE_ERROR34#define OS_ERROR_END(err) { \35char errStr[32]; \36snprintf(errStr, 32, "%d('%c%c%c%c')>", (int)err, (char)(err >> 24), (char)(err >> 16), (char)(err >> 8), (char)err); \37ERROR1(" ERROR %s\n", errStr); \38}39#define OS_ERROR0(err, string) { ERROR0(string); OS_ERROR_END(err); }40#define OS_ERROR1(err, string, p1) { ERROR1(string, p1); OS_ERROR_END(err); }41#define OS_ERROR2(err, string, p1, p2) { ERROR2(string, p1, p2); OS_ERROR_END(err); }42#define OS_ERROR3(err, string, p1, p2, p3) { ERROR3(string, p1, p2, p3); OS_ERROR_END(err); }43#define OS_ERROR4(err, string, p1, p2, p3, p4) { ERROR4(string, p1, p2, p3, p4); OS_ERROR_END(err); }44#else45#define OS_ERROR0(err, string)46#define OS_ERROR1(err, string, p1)47#define OS_ERROR2(err, string, p1, p2)48#define OS_ERROR3(err, string, p1, p2, p3)49#define OS_ERROR4(err, string, p1, p2, p3, p4)50#endif515253// Simple mutex wrapper class54class MutexLock {55private:56pthread_mutex_t lockMutex;57public:58MutexLock() { pthread_mutex_init(&lockMutex, NULL); }59~MutexLock() { pthread_mutex_destroy(&lockMutex); }6061void Lock() { pthread_mutex_lock(&lockMutex); }62void Unlock() { pthread_mutex_unlock(&lockMutex); }6364class Locker {65public:66Locker(MutexLock &lock) : pLock(&lock) { pLock->Lock(); }67~Locker() { pLock->Unlock(); }68private:69MutexLock *pLock;70};71};727374// DirectAudio and Ports need own caches of the device list75class DeviceList {76public:77DeviceList();78~DeviceList();7980OSStatus Refresh();8182int GetCount();83AudioDeviceID GetDeviceID(int index);84// stringLength specified length of name, vendor, description & version strings85bool GetDeviceInfo(int index, AudioDeviceID *deviceID, int stringLength, char *name, char *vendor, char *description, char *version);8687private:88int count;89AudioDeviceID *devices;90MutexLock lock;91void Free();9293static OSStatus NotificationCallback(AudioObjectID inObjectID,94UInt32 inNumberAddresses, const AudioObjectPropertyAddress inAddresses[], void *inClientData);9596};9798int MACOSX_DAUDIO_Init();99100AudioDeviceID GetDefaultDevice(int isSource);101int GetChannelCount(AudioDeviceID deviceID, int isSource);102float GetSampleRate(AudioDeviceID deviceID, int isSource);103104105// wrappers for AudioObjectGetPropertyDataSize/AudioObjectGetPropertyData (master element)106OSStatus GetAudioObjectPropertySize(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 *size);107OSStatus GetAudioObjectProperty(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 *size, void *data);108OSStatus GetAudioObjectProperty(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 size, void *data, int checkSize);109110// wrapper for AudioObjectSetPropertyData (kAudioObjectPropertyElementMaster)111OSStatus SetAudioObjectProperty(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 size, void *data);112113114115