summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2014-07-01 19:14:55 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2014-07-02 21:43:07 +0200
commitfa85bfde6943e5d2955830cd5e51f24210022719 (patch)
tree4a29678e8fb8eb585da620a574b7b73b6616210d
parentf317d24a3972b65349d7860da48822fbd058f36c (diff)
downloadmpv-fa85bfde6943e5d2955830cd5e51f24210022719.tar.bz2
mpv-fa85bfde6943e5d2955830cd5e51f24210022719.tar.xz
ao_coreaudio: split control to helper functions
-rw-r--r--audio/out/ao_coreaudio.c53
1 files changed, 30 insertions, 23 deletions
diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c
index 35baf6ebf9..615bb41fa0 100644
--- a/audio/out/ao_coreaudio.c
+++ b/audio/out/ao_coreaudio.c
@@ -68,34 +68,41 @@ static OSStatus render_cb_lpcm(void *ctx, AudioUnitRenderActionFlags *aflags,
return noErr;
}
+static int get_volume(struct ao *ao, struct ao_control_vol *vol) {
+ struct priv *p = ao->priv;
+ float auvol;
+ OSStatus err =
+ AudioUnitGetParameter(p->audio_unit, kHALOutputParam_Volume,
+ kAudioUnitScope_Global, 0, &auvol);
+
+ CHECK_CA_ERROR("could not get HAL output volume");
+ vol->left = vol->right = auvol * 100.0;
+ return CONTROL_TRUE;
+coreaudio_error:
+ return CONTROL_ERROR;
+}
+
+static int set_volume(struct ao *ao, struct ao_control_vol *vol) {
+ struct priv *p = ao->priv;
+ float auvol = (vol->left + vol->right) / 200.0;
+ OSStatus err =
+ AudioUnitSetParameter(p->audio_unit, kHALOutputParam_Volume,
+ kAudioUnitScope_Global, 0, auvol, 0);
+ CHECK_CA_ERROR("could not set HAL output volume");
+ return CONTROL_TRUE;
+coreaudio_error:
+ return CONTROL_ERROR;
+}
+
static int control(struct ao *ao, enum aocontrol cmd, void *arg)
{
- struct priv *p = ao->priv;
switch (cmd) {
- case AOCONTROL_GET_VOLUME: {
- ao_control_vol_t *control_vol = (ao_control_vol_t *)arg;
- float vol;
- OSStatus err =
- AudioUnitGetParameter(p->audio_unit, kHALOutputParam_Volume,
- kAudioUnitScope_Global, 0, &vol);
- CHECK_CA_ERROR("could not get HAL output volume");
- control_vol->left = control_vol->right = vol * 100.0;
- return CONTROL_TRUE;
- }
- case AOCONTROL_SET_VOLUME: {
- ao_control_vol_t *control_vol = (ao_control_vol_t *)arg;
- float vol = (control_vol->left + control_vol->right) / 200.0;
- OSStatus err =
- AudioUnitSetParameter(p->audio_unit, kHALOutputParam_Volume,
- kAudioUnitScope_Global, 0, vol, 0);
- CHECK_CA_ERROR("could not set HAL output volume");
- return CONTROL_TRUE;
- }
+ case AOCONTROL_GET_VOLUME:
+ return get_volume(ao, arg);
+ case AOCONTROL_SET_VOLUME:
+ return set_volume(ao, arg);
} // end switch
return CONTROL_UNKNOWN;
-
-coreaudio_error:
- return CONTROL_ERROR;
}
static bool init_chmap(struct ao *ao);