#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
use core::ffi::c_void;
pub type UInt32 = u32;
pub type UInt64 = u64;
pub type SInt32 = i32;
pub type Float64 = f64;
pub type OSStatus = i32;
pub type Boolean = u8;
pub type pid_t = i32;
pub type AudioObjectID = u32;
pub type CFStringRef = *const c_void;
pub type CFDictionaryRef = *const c_void;
pub type CFAllocatorRef = *const c_void;
pub type AudioServerPlugInDriverRef = *mut *const AudioServerPlugInDriverInterface;
pub type AudioServerPlugInHostRef = *mut c_void;
#[repr(C)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct AudioObjectPropertyAddress {
pub mSelector: UInt32,
pub mScope: UInt32,
pub mElement: UInt32,
}
#[repr(C)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct AudioValueRange {
pub mMinimum: Float64,
pub mMaximum: Float64,
}
#[repr(C)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct AudioStreamBasicDescription {
pub mSampleRate: Float64,
pub mFormatID: UInt32,
pub mFormatFlags: UInt32,
pub mBytesPerPacket: UInt32,
pub mFramesPerPacket: UInt32,
pub mBytesPerFrame: UInt32,
pub mChannelsPerFrame: UInt32,
pub mBitsPerChannel: UInt32,
pub mReserved: UInt32,
}
#[repr(C)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Default)]
pub struct SMPTETime {
pub mCounter: UInt64,
pub mType: UInt32,
pub mFlags: UInt32,
pub mHours: i16,
pub mMinutes: i16,
pub mSeconds: i16,
pub mFrames: i16,
}
#[repr(C)]
#[derive(Copy, Clone, PartialEq, Debug, Default)]
pub struct AudioTimeStamp {
pub mSampleTime: Float64,
pub mHostTime: UInt64,
pub mRateScalar: Float64,
pub mWordClockTime: UInt64,
pub mSMPTETime: SMPTETime,
pub mFlags: UInt32,
pub mReserved: UInt32,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct AudioServerPlugInClientInfo {
pub mClientID: UInt32,
pub mProcessID: pid_t,
pub mIsNativeEndian: Boolean,
pub mBundleID: CFStringRef,
}
#[repr(C)]
#[derive(Copy, Clone, PartialEq, Debug, Default)]
pub struct AudioServerPlugInIOCycleInfo {
pub mInputTime: AudioTimeStamp,
pub mOutputTime: AudioTimeStamp,
}
#[repr(C)]
pub struct AudioServerPlugInDriverInterface {
pub _reserved: *const c_void,
pub QueryInterface: Option<
unsafe extern "C" fn(
this: *mut c_void,
in_uuid_bytes: CFUUIDBytes,
out_interface: *mut *mut c_void,
) -> i32,
>,
pub AddRef: Option<unsafe extern "C" fn(this: *mut c_void) -> u32>,
pub Release: Option<unsafe extern "C" fn(this: *mut c_void) -> u32>,
pub Initialize: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
host: AudioServerPlugInHostRef,
) -> OSStatus,
>,
pub CreateDevice: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
description: CFDictionaryRef,
client_info: *const AudioServerPlugInClientInfo,
out_device_id: *mut AudioObjectID,
) -> OSStatus,
>,
pub DestroyDevice: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
device_id: AudioObjectID,
) -> OSStatus,
>,
pub AddDeviceClient: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
device_id: AudioObjectID,
client_info: *const AudioServerPlugInClientInfo,
) -> OSStatus,
>,
pub RemoveDeviceClient: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
device_id: AudioObjectID,
client_info: *const AudioServerPlugInClientInfo,
) -> OSStatus,
>,
pub PerformDeviceConfigurationChange: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
device_id: AudioObjectID,
change_action: UInt64,
change_info: *mut c_void,
) -> OSStatus,
>,
pub AbortDeviceConfigurationChange: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
device_id: AudioObjectID,
change_action: UInt64,
change_info: *mut c_void,
) -> OSStatus,
>,
pub HasProperty: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
object_id: AudioObjectID,
client_pid: pid_t,
address: *const AudioObjectPropertyAddress,
) -> Boolean,
>,
pub IsPropertySettable: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
object_id: AudioObjectID,
client_pid: pid_t,
address: *const AudioObjectPropertyAddress,
out_is_settable: *mut Boolean,
) -> OSStatus,
>,
pub GetPropertyDataSize: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
object_id: AudioObjectID,
client_pid: pid_t,
address: *const AudioObjectPropertyAddress,
qualifier_size: UInt32,
qualifier_data: *const c_void,
out_data_size: *mut UInt32,
) -> OSStatus,
>,
pub GetPropertyData: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
object_id: AudioObjectID,
client_pid: pid_t,
address: *const AudioObjectPropertyAddress,
qualifier_size: UInt32,
qualifier_data: *const c_void,
data_size: UInt32,
out_data_size: *mut UInt32,
out_data: *mut c_void,
) -> OSStatus,
>,
pub SetPropertyData: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
object_id: AudioObjectID,
client_pid: pid_t,
address: *const AudioObjectPropertyAddress,
qualifier_size: UInt32,
qualifier_data: *const c_void,
data_size: UInt32,
data: *const c_void,
) -> OSStatus,
>,
pub StartIO: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
device_id: AudioObjectID,
client_id: UInt32,
) -> OSStatus,
>,
pub StopIO: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
device_id: AudioObjectID,
client_id: UInt32,
) -> OSStatus,
>,
pub GetZeroTimeStamp: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
device_id: AudioObjectID,
client_id: UInt32,
out_sample_time: *mut Float64,
out_host_time: *mut UInt64,
out_seed: *mut UInt64,
) -> OSStatus,
>,
pub WillDoIOOperation: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
device_id: AudioObjectID,
client_id: UInt32,
operation_id: UInt32,
out_will_do: *mut Boolean,
out_will_do_in_place: *mut Boolean,
) -> OSStatus,
>,
pub BeginIOOperation: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
device_id: AudioObjectID,
client_id: UInt32,
operation_id: UInt32,
io_buffer_frame_size: UInt32,
io_cycle_info: *const AudioServerPlugInIOCycleInfo,
) -> OSStatus,
>,
pub DoIOOperation: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
device_id: AudioObjectID,
stream_id: AudioObjectID,
client_id: UInt32,
operation_id: UInt32,
io_buffer_frame_size: UInt32,
io_cycle_info: *const AudioServerPlugInIOCycleInfo,
io_main_buffer: *mut c_void,
io_secondary_buffer: *mut c_void,
) -> OSStatus,
>,
pub EndIOOperation: Option<
unsafe extern "C" fn(
driver: AudioServerPlugInDriverRef,
device_id: AudioObjectID,
client_id: UInt32,
operation_id: UInt32,
io_buffer_frame_size: UInt32,
io_cycle_info: *const AudioServerPlugInIOCycleInfo,
) -> OSStatus,
>,
}
#[repr(C)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Default)]
pub struct CFUUIDBytes {
pub byte0: u8,
pub byte1: u8,
pub byte2: u8,
pub byte3: u8,
pub byte4: u8,
pub byte5: u8,
pub byte6: u8,
pub byte7: u8,
pub byte8: u8,
pub byte9: u8,
pub byte10: u8,
pub byte11: u8,
pub byte12: u8,
pub byte13: u8,
pub byte14: u8,
pub byte15: u8,
}
pub type FactoryFn = unsafe extern "C" fn(
allocator: CFAllocatorRef,
requested_type_uuid: CFStringRef,
) -> *mut c_void;
#[cfg(test)]
mod tests {
use super::*;
use core::mem::{align_of, size_of};
#[test]
fn property_address_is_three_packed_u32s() {
assert_eq!(size_of::<AudioObjectPropertyAddress>(), 12);
assert_eq!(align_of::<AudioObjectPropertyAddress>(), 4);
}
#[test]
fn value_range_is_two_f64s() {
assert_eq!(size_of::<AudioValueRange>(), 16);
assert_eq!(align_of::<AudioValueRange>(), 8);
}
#[test]
fn asbd_is_40_bytes() {
assert_eq!(size_of::<AudioStreamBasicDescription>(), 40);
assert_eq!(
size_of::<AudioStreamBasicDescription>(),
crate::format::ASBD_SIZE
);
assert_eq!(align_of::<AudioStreamBasicDescription>(), 8);
}
#[test]
fn smpte_time_layout() {
assert_eq!(size_of::<SMPTETime>(), 24);
}
#[test]
fn audio_timestamp_layout() {
assert_eq!(size_of::<AudioTimeStamp>(), 64);
assert_eq!(align_of::<AudioTimeStamp>(), 8);
}
#[test]
fn io_cycle_info_is_two_timestamps() {
assert_eq!(
size_of::<AudioServerPlugInIOCycleInfo>(),
2 * size_of::<AudioTimeStamp>()
);
}
#[test]
fn client_info_layout() {
assert_eq!(size_of::<AudioServerPlugInClientInfo>(), 24);
assert_eq!(align_of::<AudioServerPlugInClientInfo>(), 8);
}
#[test]
fn cfuuid_bytes_is_16_bytes() {
assert_eq!(size_of::<CFUUIDBytes>(), 16);
assert_eq!(align_of::<CFUUIDBytes>(), 1);
}
#[test]
fn driver_interface_is_a_dense_pointer_table() {
const SLOTS: usize = 23;
assert_eq!(
size_of::<AudioServerPlugInDriverInterface>(),
SLOTS * size_of::<*const c_void>()
);
assert_eq!(
align_of::<AudioServerPlugInDriverInterface>(),
align_of::<*const c_void>()
);
}
#[test]
fn option_fn_is_abi_compatible_with_a_bare_fn_pointer() {
assert_eq!(
size_of::<Option<unsafe extern "C" fn() -> OSStatus>>(),
size_of::<*const c_void>()
);
}
#[test]
fn scalar_aliases_have_the_expected_widths() {
assert_eq!(size_of::<UInt32>(), 4);
assert_eq!(size_of::<UInt64>(), 8);
assert_eq!(size_of::<SInt32>(), 4);
assert_eq!(size_of::<Float64>(), 8);
assert_eq!(size_of::<OSStatus>(), 4);
assert_eq!(size_of::<Boolean>(), 1);
assert_eq!(size_of::<AudioObjectID>(), 4);
}
}