HWVoiceOut hw;
pthread_mutex_t buf_mutex;
- AudioDeviceID outputDeviceID;
- int frameSizeSetting;
- uint32_t bufferCount;
- UInt32 audioDevicePropertyBufferFrameSize;
+ AudioDeviceID device_id;
+ int frame_size_setting;
+ uint32_t buffer_count;
+ UInt32 device_frame_size;
AudioDeviceIOProcID ioprocid;
bool enabled;
-} coreaudioVoiceOut;
+} CoreaudioVoiceOut;
-static const AudioObjectPropertyAddress voice_addr = {
+static const AudioObjectPropertyAddress voice_out_addr = {
kAudioHardwarePropertyDefaultOutputDevice,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMain
};
-static OSStatus coreaudio_get_voice(AudioDeviceID *id)
+static OSStatus coreaudio_get_voice_out(AudioDeviceID *id)
{
UInt32 size = sizeof(*id);
return AudioObjectGetPropertyData(kAudioObjectSystemObject,
- &voice_addr,
+ &voice_out_addr,
0,
NULL,
&size,
id);
}
-static OSStatus coreaudio_get_framesizerange(AudioDeviceID id,
- AudioValueRange *framerange)
+static OSStatus coreaudio_get_out_framesizerange(AudioDeviceID id,
+ AudioValueRange *framerange)
{
UInt32 size = sizeof(*framerange);
AudioObjectPropertyAddress addr = {
@@ -80,7 +80,7 @@ static OSStatus coreaudio_get_framesizerange(AudioDeviceID id,
framerange);
}
-static OSStatus coreaudio_get_framesize(AudioDeviceID id, UInt32 *framesize)
+static OSStatus coreaudio_get_out_framesize(AudioDeviceID id, UInt32
*framesize)
{
UInt32 size = sizeof(*framesize);
AudioObjectPropertyAddress addr = {
@@ -97,7 +97,7 @@ static OSStatus coreaudio_get_framesize(AudioDeviceID id,
UInt32 *framesize)
framesize);
}
-static OSStatus coreaudio_set_framesize(AudioDeviceID id, UInt32 *framesize)
+static OSStatus coreaudio_set_out_framesize(AudioDeviceID id, UInt32
*framesize)
{
UInt32 size = sizeof(*framesize);
AudioObjectPropertyAddress addr = {
@@ -114,8 +114,8 @@ static OSStatus coreaudio_set_framesize(AudioDeviceID id,
UInt32 *framesize)
framesize);
}
-static OSStatus coreaudio_set_streamformat(AudioDeviceID id,
- AudioStreamBasicDescription *d)
+static OSStatus coreaudio_set_out_streamformat(AudioDeviceID id,
+ AudioStreamBasicDescription *d)
{
UInt32 size = sizeof(*d);
AudioObjectPropertyAddress addr = {
@@ -132,7 +132,7 @@ static OSStatus coreaudio_set_streamformat(AudioDeviceID id,
d);
}
-static OSStatus coreaudio_get_isrunning(AudioDeviceID id, UInt32 *result)
+static OSStatus coreaudio_get_out_isrunning(AudioDeviceID id, UInt32 *result)
{
UInt32 size = sizeof(*result);
AudioObjectPropertyAddress addr = {
@@ -242,7 +242,8 @@ static void G_GNUC_PRINTF (3, 4) coreaudio_logerr2 (
#define coreaudio_playback_logerr(status, ...) \
coreaudio_logerr2(status, "playback", __VA_ARGS__)
-static int coreaudio_buf_lock (coreaudioVoiceOut *core, const char *fn_name)
+static int coreaudio_voice_out_buf_lock(CoreaudioVoiceOut *core,
+ const char *fn_name)
{
int err;
@@ -255,7 +256,8 @@ static int coreaudio_buf_lock (coreaudioVoiceOut *core,
const char *fn_name)
return 0;
}
-static int coreaudio_buf_unlock (coreaudioVoiceOut *core, const char *fn_name)
+static int coreaudio_voice_out_buf_unlock(CoreaudioVoiceOut *core,
+ const char *fn_name)
{
int err;
@@ -268,20 +270,20 @@ static int coreaudio_buf_unlock (coreaudioVoiceOut *core,
const char *fn_name)
return 0;
}
-#define COREAUDIO_WRAPPER_FUNC(name, ret_type, args_decl, args) \
- static ret_type glue(coreaudio_, name)args_decl \
- { \
- coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw; \
- ret_type ret; \
- \
- if (coreaudio_buf_lock(core, "coreaudio_" #name)) { \
- return 0; \
- } \
- \
- ret = glue(audio_generic_, name)args; \
- \
- coreaudio_buf_unlock(core, "coreaudio_" #name); \
- return ret; \
+#define COREAUDIO_WRAPPER_FUNC(name, ret_type, args_decl, args) \
+ static ret_type glue(coreaudio_, name)args_decl \
+ { \
+ CoreaudioVoiceOut *core = (CoreaudioVoiceOut *) hw; \
+ ret_type ret; \
+ \
+ if (coreaudio_voice_out_buf_lock(core, "coreaudio_" #name)) { \
+ return 0; \
+ } \
+ \
+ ret = glue(audio_generic_, name)args; \
+ \
+ coreaudio_voice_out_buf_unlock(core, "coreaudio_" #name); \
+ return ret; \
}
COREAUDIO_WRAPPER_FUNC(buffer_get_free, size_t, (HWVoiceOut *hw), (hw))
COREAUDIO_WRAPPER_FUNC(get_buffer_out, void *, (HWVoiceOut *hw, size_t *size),
@@ -297,7 +299,7 @@ static ret_type glue(coreaudio_, name)args_decl
\
* callback to feed audiooutput buffer. called without BQL.
* allowed to lock "buf_mutex", but disallowed to have any other locks.
*/
-static OSStatus audioDeviceIOProc(
+static OSStatus out_device_ioproc(
AudioDeviceID inDevice,
const AudioTimeStamp *inNow,
const AudioBufferList *inInputData,
@@ -306,33 +308,33 @@ static OSStatus audioDeviceIOProc(
const AudioTimeStamp *inOutputTime,
void *hwptr)
{
- UInt32 frameCount, pending_frames;
+ UInt32 frame_size, pending_frames;
void *out = outOutputData->mBuffers[0].mData;
HWVoiceOut *hw = hwptr;
- coreaudioVoiceOut *core = (coreaudioVoiceOut *) hwptr;
+ CoreaudioVoiceOut *core = (CoreaudioVoiceOut *) hwptr;
size_t len;
- if (coreaudio_buf_lock (core, "audioDeviceIOProc")) {
+ if (coreaudio_voice_out_buf_lock (core, "out_device_ioproc")) {
inInputTime = 0;
return 0;
}
- if (inDevice != core->outputDeviceID) {
- coreaudio_buf_unlock (core, "audioDeviceIOProc(old device)");
+ if (inDevice != core->device_id) {
+ coreaudio_voice_out_buf_unlock (core, "out_device_ioproc(old device)");
return 0;
}
- frameCount = core->audioDevicePropertyBufferFrameSize;
+ frame_size = core->device_frame_size;
pending_frames = hw->pending_emul / hw->info.bytes_per_frame;
/* if there are not enough samples, set signal and return */
- if (pending_frames < frameCount) {
+ if (pending_frames < frame_size) {
inInputTime = 0;
- coreaudio_buf_unlock (core, "audioDeviceIOProc(empty)");
+ coreaudio_voice_out_buf_unlock (core, "out_device_ioproc(empty)");
return 0;
}
- len = frameCount * hw->info.bytes_per_frame;
+ len = frame_size * hw->info.bytes_per_frame;
while (len) {
size_t write_len, start;
@@ -348,16 +350,16 @@ static OSStatus audioDeviceIOProc(
out += write_len;
}
- coreaudio_buf_unlock (core, "audioDeviceIOProc");
+ coreaudio_voice_out_buf_unlock (core, "out_device_ioproc");
return 0;
}
-static OSStatus init_out_device(coreaudioVoiceOut *core)
+static OSStatus init_out_device(CoreaudioVoiceOut *core)
{
OSStatus status;
- AudioValueRange frameRange;
+ AudioValueRange framerange;
- AudioStreamBasicDescription streamBasicDescription = {
+ AudioStreamBasicDescription stream_basic_description = {
.mBitsPerChannel = core->hw.info.bits,
.mBytesPerFrame = core->hw.info.bytes_per_frame,
.mBytesPerPacket = core->hw.info.bytes_per_frame,
@@ -368,20 +370,20 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
.mSampleRate = core->hw.info.freq
};
- status = coreaudio_get_voice(&core->outputDeviceID);
+ status = coreaudio_get_voice_out(&core->device_id);
if (status != kAudioHardwareNoError) {
coreaudio_playback_logerr (status,
"Could not get default output Device\n");
return status;
}
- if (core->outputDeviceID == kAudioDeviceUnknown) {
+ if (core->device_id == kAudioDeviceUnknown) {
dolog ("Could not initialize playback - Unknown Audiodevice\n");
return status;
}
/* get minimum and maximum buffer frame sizes */
- status = coreaudio_get_framesizerange(core->outputDeviceID,
- &frameRange);
+ status = coreaudio_get_out_framesizerange(core->device_id,
+ &framerange);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
@@ -391,32 +393,32 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
return status;
}
- if (frameRange.mMinimum > core->frameSizeSetting) {
- core->audioDevicePropertyBufferFrameSize = (UInt32)
frameRange.mMinimum;
- dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum);
- } else if (frameRange.mMaximum < core->frameSizeSetting) {
- core->audioDevicePropertyBufferFrameSize = (UInt32)
frameRange.mMaximum;
- dolog ("warning: Downsizing Buffer Frames to %f\n",
frameRange.mMaximum);
+ if (framerange.mMinimum > core->frame_size_setting) {
+ core->device_frame_size = (UInt32) framerange.mMinimum;
+ dolog ("warning: Upsizing Buffer Frames to %f\n", framerange.mMinimum);
+ } else if (framerange.mMaximum < core->frame_size_setting) {
+ core->device_frame_size = (UInt32) framerange.mMaximum;
+ dolog ("warning: Downsizing Buffer Frames to %f\n",
framerange.mMaximum);
} else {
- core->audioDevicePropertyBufferFrameSize = core->frameSizeSetting;
+ core->device_frame_size = core->frame_size_setting;
}
/* set Buffer Frame Size */
- status = coreaudio_set_framesize(core->outputDeviceID,
-
&core->audioDevicePropertyBufferFrameSize);
+ status = coreaudio_set_out_framesize(core->device_id,
+ &core->device_frame_size);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
if (status != kAudioHardwareNoError) {
coreaudio_playback_logerr (status,
"Could not set device buffer frame size %" PRIu32
"\n",
-
(uint32_t)core->audioDevicePropertyBufferFrameSize);
+ (uint32_t)core->device_frame_size);
return status;
}
/* get Buffer Frame Size */
- status = coreaudio_get_framesize(core->outputDeviceID,
-
&core->audioDevicePropertyBufferFrameSize);
+ status = coreaudio_get_out_framesize(core->device_id,
+ &core->device_frame_size);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
@@ -425,19 +427,19 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
"Could not get device buffer frame size\n");
return status;
}
- core->hw.samples = core->bufferCount *
core->audioDevicePropertyBufferFrameSize;
+ core->hw.samples = core->buffer_count * core->device_frame_size;
/* set Samplerate */
- status = coreaudio_set_streamformat(core->outputDeviceID,
- &streamBasicDescription);
+ status = coreaudio_set_out_streamformat(core->device_id,
+ &stream_basic_description);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
if (status != kAudioHardwareNoError) {
coreaudio_playback_logerr (status,
"Could not set samplerate %lf\n",
- streamBasicDescription.mSampleRate);
- core->outputDeviceID = kAudioDeviceUnknown;
+ stream_basic_description.mSampleRate);
+ core->device_id = kAudioDeviceUnknown;
return status;
}
@@ -452,8 +454,8 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
* with the callers of AudioObjectGetPropertyData.
*/
core->ioprocid = NULL;
- status = AudioDeviceCreateIOProcID(core->outputDeviceID,
- audioDeviceIOProc,
+ status = AudioDeviceCreateIOProcID(core->device_id,
+ out_device_ioproc,
&core->hw,
&core->ioprocid);
if (status == kAudioHardwareBadDeviceError) {
@@ -461,20 +463,20 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
}
if (status != kAudioHardwareNoError || core->ioprocid == NULL) {
coreaudio_playback_logerr (status, "Could not set IOProc\n");
- core->outputDeviceID = kAudioDeviceUnknown;
+ core->device_id = kAudioDeviceUnknown;
return status;
}
return 0;
}
-static void fini_out_device(coreaudioVoiceOut *core)
+static void fini_out_device(CoreaudioVoiceOut *core)
{
OSStatus status;
UInt32 isrunning;
/* stop playback */
- status = coreaudio_get_isrunning(core->outputDeviceID, &isrunning);
+ status = coreaudio_get_out_isrunning(core->device_id, &isrunning);
if (status != kAudioHardwareBadObjectError) {
if (status != kAudioHardwareNoError) {
coreaudio_logerr(status,
@@ -482,7 +484,7 @@ static void fini_out_device(coreaudioVoiceOut *core)
}
if (isrunning) {
- status = AudioDeviceStop(core->outputDeviceID, core->ioprocid);
+ status = AudioDeviceStop(core->device_id, core->ioprocid);
if (status != kAudioHardwareBadDeviceError && status !=
kAudioHardwareNoError) {
coreaudio_logerr(status, "Could not stop playback\n");
}
@@ -490,20 +492,20 @@ static void fini_out_device(coreaudioVoiceOut *core)
}
/* remove callback */
- status = AudioDeviceDestroyIOProcID(core->outputDeviceID,
+ status = AudioDeviceDestroyIOProcID(core->device_id,
core->ioprocid);
if (status != kAudioHardwareBadDeviceError && status !=
kAudioHardwareNoError) {
coreaudio_logerr(status, "Could not remove IOProc\n");
}
- core->outputDeviceID = kAudioDeviceUnknown;
+ core->device_id = kAudioDeviceUnknown;
}
-static void update_device_playback_state(coreaudioVoiceOut *core)
+static void update_out_device_playback_state(CoreaudioVoiceOut *core)
{
OSStatus status;
UInt32 isrunning;
- status = coreaudio_get_isrunning(core->outputDeviceID, &isrunning);
+ status = coreaudio_get_out_isrunning(core->device_id, &isrunning);
if (status != kAudioHardwareNoError) {
if (status != kAudioHardwareBadObjectError) {
coreaudio_logerr(status,
@@ -516,7 +518,7 @@ static void update_device_playback_state(coreaudioVoiceOut
*core)
if (core->enabled) {
/* start playback */
if (!isrunning) {
- status = AudioDeviceStart(core->outputDeviceID, core->ioprocid);
+ status = AudioDeviceStart(core->device_id, core->ioprocid);
if (status != kAudioHardwareBadDeviceError && status !=
kAudioHardwareNoError) {
coreaudio_logerr (status, "Could not resume playback\n");
}
@@ -524,7 +526,7 @@ static void update_device_playback_state(coreaudioVoiceOut
*core)
} else {
/* stop playback */
if (isrunning) {
- status = AudioDeviceStop(core->outputDeviceID,
+ status = AudioDeviceStop(core->device_id,
core->ioprocid);
if (status != kAudioHardwareBadDeviceError && status !=
kAudioHardwareNoError) {
coreaudio_logerr(status, "Could not pause playback\n");
@@ -534,22 +536,22 @@ static void
update_device_playback_state(coreaudioVoiceOut *core)
}
/* called without BQL. */
-static OSStatus handle_voice_change(
+static OSStatus handle_voice_out_change(
AudioObjectID in_object_id,
UInt32 in_number_addresses,
const AudioObjectPropertyAddress *in_addresses,
void *in_client_data)
{
- coreaudioVoiceOut *core = in_client_data;
+ CoreaudioVoiceOut *core = in_client_data;
bql_lock();
- if (core->outputDeviceID) {
+ if (core->device_id) {
fini_out_device(core);
}
if (!init_out_device(core)) {
- update_device_playback_state(core);
+ update_out_device_playback_state(core);
}
bql_unlock();
@@ -560,7 +562,7 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct
audsettings *as,
void *drv_opaque)
{
OSStatus status;
- coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
+ CoreaudioVoiceOut *core = (CoreaudioVoiceOut *) hw;
int err;
Audiodev *dev = drv_opaque;
AudiodevCoreaudioPerDirectionOptions *cpdo = dev->u.coreaudio.out;
@@ -578,13 +580,14 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct
audsettings *as,
as->fmt = AUDIO_FORMAT_F32;
audio_pcm_init_info (&hw->info, as);
- core->frameSizeSetting = audio_buffer_frames(
+ core->frame_size_setting = audio_buffer_frames(
qapi_AudiodevCoreaudioPerDirectionOptions_base(cpdo), as, 11610);
- core->bufferCount = cpdo->has_buffer_count ? cpdo->buffer_count : 4;
+ core->buffer_count = cpdo->has_buffer_count ? cpdo->buffer_count : 4;
status = AudioObjectAddPropertyListener(kAudioObjectSystemObject,
- &voice_addr, handle_voice_change,
+ &voice_out_addr,
+ handle_voice_out_change,
core);
if (status != kAudioHardwareNoError) {
coreaudio_playback_logerr (status,
@@ -594,8 +597,8 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct
audsettings *as,
if (init_out_device(core)) {
status = AudioObjectRemovePropertyListener(kAudioObjectSystemObject,
- &voice_addr,
- handle_voice_change,
+ &voice_out_addr,
+ handle_voice_out_change,
core);
if (status != kAudioHardwareNoError) {
coreaudio_playback_logerr(status,
@@ -612,11 +615,11 @@ static void coreaudio_fini_out (HWVoiceOut *hw)
{
OSStatus status;
int err;
- coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
+ CoreaudioVoiceOut *core = (CoreaudioVoiceOut *) hw;
status = AudioObjectRemovePropertyListener(kAudioObjectSystemObject,
- &voice_addr,
- handle_voice_change,
+ &voice_out_addr,
+ handle_voice_out_change,
core);
if (status != kAudioHardwareNoError) {
coreaudio_logerr(status, "Could not remove voice property change
listener\n");
@@ -633,7 +636,7 @@ static void coreaudio_fini_out (HWVoiceOut *hw)
static void coreaudio_enable_out(HWVoiceOut *hw, bool enable)
{
- coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
+ CoreaudioVoiceOut *core = (CoreaudioVoiceOut *) hw;
core->enabled = enable;
update_device_playback_state(core);
@@ -670,7 +673,7 @@ static void coreaudio_audio_fini (void *opaque)
.pcm_ops = &coreaudio_pcm_ops,
.max_voices_out = 1,
.max_voices_in = 0,
- .voice_size_out = sizeof (coreaudioVoiceOut),
+ .voice_size_out = sizeof (CoreaudioVoiceOut),
.voice_size_in = 0
};