summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--audio/out/ao_coreaudio.c109
1 files changed, 68 insertions, 41 deletions
diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c
index d2712d5521..bfc12a9e8a 100644
--- a/audio/out/ao_coreaudio.c
+++ b/audio/out/ao_coreaudio.c
@@ -64,6 +64,46 @@ static void print_buffer(struct mp_ring *buffer)
talloc_free(tctx);
}
+static bool check_ca_st(int level, OSStatus code, const char *message)
+{
+ if (code == noErr) return true;
+
+ // Extract FourCC letters from the uint32_t and finde out if it's a valid
+ // code that is made of letters.
+ char fcc[4] = {
+ (code >> 24) & 0xFF,
+ (code >> 16) & 0xFF,
+ (code >> 8) & 0xFF,
+ code & 0xFF,
+ };
+
+ bool valid_fourcc = true;
+ for (int i = 0; i < 4; i++)
+ if (!isprint(fcc[i]))
+ valid_fourcc = false;
+
+ char *error_string;
+ if (valid_fourcc)
+ error_string =
+ talloc_asprintf(NULL, "'%c%c%c%c'", fcc[0], fcc[1], fcc[2], fcc[3]);
+ else
+ error_string = talloc_asprintf(NULL, "%d", code);
+
+ ca_msg(level, "%s (%s)\n", message, error_string);
+
+ talloc_free(error_string);
+
+ return false;
+}
+
+#define CHECK_CA_ERROR_L(label, message) \
+ do { \
+ if (!check_ca_st(MSGL_ERR, err, message)) { \
+ goto label; \
+ } \
+ } while (0)
+
+#define CHECK_CA_ERROR(message) CHECK_CA_ERROR_L(coreaudio_error, message)
struct priv
{
@@ -149,18 +189,13 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
};
return CONTROL_TRUE;
}
+
err = AudioUnitGetParameter(p->theOutputUnit, kHALOutputParam_Volume,
kAudioUnitScope_Global, 0, &vol);
- if (err == 0) {
- // printf("GET VOL=%f\n", vol);
- control_vol->left = control_vol->right = vol * 100.0 / 4.0;
- return CONTROL_TRUE;
- } else {
- ca_msg(MSGL_WARN,
- "could not get HAL output volume: [%4.4s]\n", (char *)&err);
- return CONTROL_FALSE;
- }
+ CHECK_CA_ERROR("could not get HAL output volume");
+ control_vol->left = control_vol->right = vol * 100.0 / 4.0;
+ return CONTROL_TRUE;
case AOCONTROL_SET_VOLUME:
control_vol = (ao_control_vol_t *)arg;
@@ -183,19 +218,15 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
vol = (control_vol->left + control_vol->right) * 4.0 / 200.0;
err = AudioUnitSetParameter(p->theOutputUnit, kHALOutputParam_Volume,
kAudioUnitScope_Global, 0, vol, 0);
- if (err == 0) {
- // printf("SET VOL=%f\n", vol);
- return CONTROL_TRUE;
- } else {
- ca_msg(MSGL_WARN,
- "could not set HAL output volume: [%4.4s]\n", (char *)&err);
- return CONTROL_FALSE;
- }
- /* Everything is currently unimplemented */
- default:
- return CONTROL_FALSE;
- }
+ CHECK_CA_ERROR("could not set HAL output volume");
+ return CONTROL_TRUE;
+
+ } // end switch
+ return CONTROL_UNKNOWN;
+
+coreaudio_error:
+ return CONTROL_ERROR;
}
@@ -238,34 +269,30 @@ static OSStatus GetAudioProperty(AudioObjectID id,
static UInt32 GetAudioPropertyArray(AudioObjectID id,
AudioObjectPropertySelector selector,
AudioObjectPropertyScope scope,
- void **outData)
+ void **data)
{
OSStatus err;
- AudioObjectPropertyAddress property_address;
- UInt32 i_param_size;
+ AudioObjectPropertyAddress p_addr;
+ UInt32 p_size;
- property_address.mSelector = selector;
- property_address.mScope = scope;
- property_address.mElement = kAudioObjectPropertyElementMaster;
-
- err = AudioObjectGetPropertyDataSize(id, &property_address, 0, NULL,
- &i_param_size);
-
- if (err != noErr)
- return 0;
+ p_addr.mSelector = selector;
+ p_addr.mScope = scope;
+ p_addr.mElement = kAudioObjectPropertyElementMaster;
- *outData = malloc(i_param_size);
+ err = AudioObjectGetPropertyDataSize(id, &p_addr, 0, NULL, &p_size);
+ CHECK_CA_ERROR("Can't fetch property size");
+ *data = malloc(p_size);
- err = AudioObjectGetPropertyData(id, &property_address, 0, NULL,
- &i_param_size, *outData);
+ err = AudioObjectGetPropertyData(id, &p_addr, 0, NULL, &p_size, *data);
+ CHECK_CA_ERROR_L(coreaudio_error_free, "Can't fetch property data %s");
- if (err != noErr) {
- free(*outData);
- return 0;
- }
+ return p_size;
- return i_param_size;
+coreaudio_error_free:
+ free(*data);
+coreaudio_error:
+ return 0;
}
static UInt32 GetGlobalAudioPropertyArray(AudioObjectID id,