author | coleenp |
Fri, 09 Mar 2018 12:03:20 -0500 | |
changeset 49366 | f95ef5511e1f |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
12047
diff
changeset
|
2 |
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
12047 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
#include <CoreAudio/CoreAudio.h> |
|
27 |
#include <pthread.h> |
|
28 |
||
29 |
extern "C" { |
|
30 |
#include "Utilities.h" |
|
31 |
} |
|
32 |
||
33 |
||
34 |
#ifdef USE_ERROR |
|
35 |
#define OS_ERROR_END(err) { \ |
|
36 |
char errStr[32]; \ |
|
37 |
snprintf(errStr, 32, "%d('%c%c%c%c')>", (int)err, (char)(err >> 24), (char)(err >> 16), (char)(err >> 8), (char)err); \ |
|
38 |
ERROR1(" ERROR %s\n", errStr); \ |
|
39 |
} |
|
40 |
#define OS_ERROR0(err, string) { ERROR0(string); OS_ERROR_END(err); } |
|
41 |
#define OS_ERROR1(err, string, p1) { ERROR1(string, p1); OS_ERROR_END(err); } |
|
42 |
#define OS_ERROR2(err, string, p1, p2) { ERROR2(string, p1, p2); OS_ERROR_END(err); } |
|
43 |
#define OS_ERROR3(err, string, p1, p2, p3) { ERROR3(string, p1, p2, p3); OS_ERROR_END(err); } |
|
44 |
#define OS_ERROR4(err, string, p1, p2, p3, p4) { ERROR4(string, p1, p2, p3, p4); OS_ERROR_END(err); } |
|
45 |
#else |
|
46 |
#define OS_ERROR0(err, string) |
|
47 |
#define OS_ERROR1(err, string, p1) |
|
48 |
#define OS_ERROR2(err, string, p1, p2) |
|
49 |
#define OS_ERROR3(err, string, p1, p2, p3) |
|
50 |
#define OS_ERROR4(err, string, p1, p2, p3, p4) |
|
51 |
#endif |
|
52 |
||
53 |
||
54 |
// Simple mutex wrapper class |
|
55 |
class MutexLock { |
|
56 |
private: |
|
57 |
pthread_mutex_t lockMutex; |
|
58 |
public: |
|
59 |
MutexLock() { pthread_mutex_init(&lockMutex, NULL); } |
|
60 |
~MutexLock() { pthread_mutex_destroy(&lockMutex); } |
|
61 |
||
62 |
void Lock() { pthread_mutex_lock(&lockMutex); } |
|
63 |
void Unlock() { pthread_mutex_unlock(&lockMutex); } |
|
64 |
||
65 |
class Locker { |
|
66 |
public: |
|
67 |
Locker(MutexLock &lock) : pLock(&lock) { pLock->Lock(); } |
|
68 |
~Locker() { pLock->Unlock(); } |
|
69 |
private: |
|
70 |
MutexLock *pLock; |
|
71 |
}; |
|
72 |
}; |
|
73 |
||
74 |
||
75 |
// DirectAudio and Ports need own caches of the device list |
|
76 |
class DeviceList { |
|
77 |
public: |
|
78 |
DeviceList(); |
|
79 |
~DeviceList(); |
|
80 |
||
81 |
OSStatus Refresh(); |
|
82 |
||
83 |
int GetCount(); |
|
84 |
AudioDeviceID GetDeviceID(int index); |
|
85 |
// stringLength specified length of name, vendor, description & version strings |
|
86 |
bool GetDeviceInfo(int index, AudioDeviceID *deviceID, int stringLength, char *name, char *vendor, char *description, char *version); |
|
87 |
||
88 |
private: |
|
89 |
int count; |
|
90 |
AudioDeviceID *devices; |
|
91 |
MutexLock lock; |
|
92 |
void Free(); |
|
93 |
||
94 |
static OSStatus NotificationCallback(AudioObjectID inObjectID, |
|
95 |
UInt32 inNumberAddresses, const AudioObjectPropertyAddress inAddresses[], void *inClientData); |
|
96 |
||
97 |
}; |
|
98 |
||
99 |
int MACOSX_DAUDIO_Init(); |
|
100 |
||
101 |
AudioDeviceID GetDefaultDevice(int isSource); |
|
102 |
int GetChannelCount(AudioDeviceID deviceID, int isSource); |
|
103 |
float GetSampleRate(AudioDeviceID deviceID, int isSource); |
|
104 |
||
105 |
||
106 |
// wrappers for AudioObjectGetPropertyDataSize/AudioObjectGetPropertyData (master element) |
|
107 |
OSStatus GetAudioObjectPropertySize(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 *size); |
|
108 |
OSStatus GetAudioObjectProperty(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 *size, void *data); |
|
109 |
OSStatus GetAudioObjectProperty(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 size, void *data, int checkSize); |
|
110 |
||
111 |
// wrapper for AudioObjectSetPropertyData (kAudioObjectPropertyElementMaster) |
|
112 |
OSStatus SetAudioObjectProperty(AudioObjectID object, AudioObjectPropertyScope scope, AudioObjectPropertySelector prop, UInt32 size, void *data); |
|
113 |