1 
2 // Some definitions from the kernel headers
3 
4 // const SNDRV_PCM_MMAP_OFFSET_DATA: c_uint = 0x00000000;
5 pub const SNDRV_PCM_MMAP_OFFSET_STATUS: libc::c_uint = 0x80000000;
6 pub const SNDRV_PCM_MMAP_OFFSET_CONTROL: libc::c_uint = 0x81000000;
7 
8 
9 pub const SNDRV_PCM_SYNC_PTR_HWSYNC: libc::c_uint = 1;
10 pub const SNDRV_PCM_SYNC_PTR_APPL: libc::c_uint = 2;
11 pub const SNDRV_PCM_SYNC_PTR_AVAIL_MIN: libc::c_uint = 4;
12 
13 // #[repr(C)]
14 #[allow(non_camel_case_types)]
15 pub type snd_pcm_state_t = libc::c_int;
16 
17 // #[repr(C)]
18 #[allow(non_camel_case_types)]
19 pub type snd_pcm_uframes_t = libc::c_ulong;
20 
21 // I think?! Not sure how this will work with X32 ABI?!
22 #[allow(non_camel_case_types)]
23 pub type __kernel_off_t = libc::c_long;
24 
25 #[repr(C)]
26 #[derive(Copy, Clone)]
27 pub struct snd_pcm_mmap_status {
28 	pub state: snd_pcm_state_t,		/* RO: state - SNDRV_PCM_STATE_XXXX */
29 	pub pad1: libc::c_int,			/* Needed for 64 bit alignment */
30 	pub hw_ptr: snd_pcm_uframes_t,	/* RO: hw ptr (0...boundary-1) */
31 	pub tstamp: libc::timespec,		/* Timestamp */
32 	pub suspended_state: snd_pcm_state_t, /* RO: suspended stream state */
33 	pub audio_tstamp: libc::timespec,	/* from sample counter or wall clock */
34 }
35 
36 #[repr(C)]
37 #[derive(Debug, Copy, Clone)]
38 pub struct snd_pcm_mmap_control {
39 	pub appl_ptr: snd_pcm_uframes_t,	/* RW: appl ptr (0...boundary-1) */
40 	pub avail_min: snd_pcm_uframes_t,	/* RW: min available frames for wakeup */
41 }
42 
43 #[repr(C)]
44 #[derive(Debug)]
45 pub struct snd_pcm_channel_info {
46 	pub channel: libc::c_uint,
47 	pub offset: __kernel_off_t,		/* mmap offset */
48 	pub first: libc::c_uint,		/* offset to first sample in bits */
49 	pub step: libc::c_uint, 		/* samples distance in bits */
50 }
51 
52 #[repr(C)]
53 #[derive(Copy, Clone)]
54 pub union snd_pcm_mmap_status_r {
55 	pub status: snd_pcm_mmap_status,
56 	pub reserved: [libc::c_uchar; 64],
57 }
58 
59 #[repr(C)]
60 #[derive(Copy, Clone)]
61 pub union snd_pcm_mmap_control_r {
62 	pub control: snd_pcm_mmap_control,
63 	pub reserved: [libc::c_uchar; 64],
64 }
65 
66 #[repr(C)]
67 #[derive(Copy, Clone)]
68 pub struct snd_pcm_sync_ptr {
69 	pub flags: libc::c_uint,
70 	pub s: snd_pcm_mmap_status_r,
71 	pub c: snd_pcm_mmap_control_r,
72 }
73 
74 ioctl_read!(sndrv_pcm_ioctl_channel_info, b'A', 0x32, snd_pcm_channel_info);
75 ioctl_readwrite!(sndrv_pcm_ioctl_sync_ptr, b'A', 0x23, snd_pcm_sync_ptr);
76 
pagesize() -> usize77 pub fn pagesize() -> usize {
78     unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize }
79 }
80