mirror of
https://github.com/mpv-player/mpv
synced 2025-03-21 02:41:13 +00:00
ao_coreaudio: add error check function and macro
WIP
This commit is contained in:
parent
3edb605172
commit
45479825ba
@ -64,6 +64,46 @@ static void print_buffer(struct mp_ring *buffer)
|
|||||||
talloc_free(tctx);
|
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
|
struct priv
|
||||||
{
|
{
|
||||||
@ -149,18 +189,13 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
|
|||||||
};
|
};
|
||||||
return CONTROL_TRUE;
|
return CONTROL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = AudioUnitGetParameter(p->theOutputUnit, kHALOutputParam_Volume,
|
err = AudioUnitGetParameter(p->theOutputUnit, kHALOutputParam_Volume,
|
||||||
kAudioUnitScope_Global, 0, &vol);
|
kAudioUnitScope_Global, 0, &vol);
|
||||||
|
|
||||||
if (err == 0) {
|
CHECK_CA_ERROR("could not get HAL output volume");
|
||||||
// printf("GET VOL=%f\n", vol);
|
control_vol->left = control_vol->right = vol * 100.0 / 4.0;
|
||||||
control_vol->left = control_vol->right = vol * 100.0 / 4.0;
|
return CONTROL_TRUE;
|
||||||
return CONTROL_TRUE;
|
|
||||||
} else {
|
|
||||||
ca_msg(MSGL_WARN,
|
|
||||||
"could not get HAL output volume: [%4.4s]\n", (char *)&err);
|
|
||||||
return CONTROL_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
case AOCONTROL_SET_VOLUME:
|
case AOCONTROL_SET_VOLUME:
|
||||||
control_vol = (ao_control_vol_t *)arg;
|
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;
|
vol = (control_vol->left + control_vol->right) * 4.0 / 200.0;
|
||||||
err = AudioUnitSetParameter(p->theOutputUnit, kHALOutputParam_Volume,
|
err = AudioUnitSetParameter(p->theOutputUnit, kHALOutputParam_Volume,
|
||||||
kAudioUnitScope_Global, 0, vol, 0);
|
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,
|
static UInt32 GetAudioPropertyArray(AudioObjectID id,
|
||||||
AudioObjectPropertySelector selector,
|
AudioObjectPropertySelector selector,
|
||||||
AudioObjectPropertyScope scope,
|
AudioObjectPropertyScope scope,
|
||||||
void **outData)
|
void **data)
|
||||||
{
|
{
|
||||||
OSStatus err;
|
OSStatus err;
|
||||||
AudioObjectPropertyAddress property_address;
|
AudioObjectPropertyAddress p_addr;
|
||||||
UInt32 i_param_size;
|
UInt32 p_size;
|
||||||
|
|
||||||
property_address.mSelector = selector;
|
p_addr.mSelector = selector;
|
||||||
property_address.mScope = scope;
|
p_addr.mScope = scope;
|
||||||
property_address.mElement = kAudioObjectPropertyElementMaster;
|
p_addr.mElement = kAudioObjectPropertyElementMaster;
|
||||||
|
|
||||||
err = AudioObjectGetPropertyDataSize(id, &property_address, 0, NULL,
|
err = AudioObjectGetPropertyDataSize(id, &p_addr, 0, NULL, &p_size);
|
||||||
&i_param_size);
|
CHECK_CA_ERROR("Can't fetch property size");
|
||||||
|
|
||||||
if (err != noErr)
|
*data = malloc(p_size);
|
||||||
return 0;
|
|
||||||
|
|
||||||
*outData = malloc(i_param_size);
|
err = AudioObjectGetPropertyData(id, &p_addr, 0, NULL, &p_size, *data);
|
||||||
|
CHECK_CA_ERROR_L(coreaudio_error_free, "Can't fetch property data %s");
|
||||||
|
|
||||||
|
return p_size;
|
||||||
|
|
||||||
err = AudioObjectGetPropertyData(id, &property_address, 0, NULL,
|
coreaudio_error_free:
|
||||||
&i_param_size, *outData);
|
free(*data);
|
||||||
|
coreaudio_error:
|
||||||
if (err != noErr) {
|
return 0;
|
||||||
free(*outData);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return i_param_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static UInt32 GetGlobalAudioPropertyArray(AudioObjectID id,
|
static UInt32 GetGlobalAudioPropertyArray(AudioObjectID id,
|
||||||
|
Loading…
Reference in New Issue
Block a user