mk-fg / python-pulse-control

Python high-level interface and ctypes-based bindings for PulseAudio (libpulse)
https://pypi.org/project/pulsectl/
MIT License
170 stars 36 forks source link

c_uint32 type for the 'channels' field in PA_SAMPLE_SPEC #79

Closed xdegaye closed 1 year ago

xdegaye commented 1 year ago

The channels field's type is defined as uint8_t in the sample.h pulselib header.

In the PA_SAMPLE_SPEC Structure defined in _pulsectl.py, it is defined as c_uint32 instead. This works on little endian architectures (most platforms currently) when the compiler has zeroed all the bytes in the structure, but it fails on big endian ones: it is the highest significant byte on a big endian uint32_t that is located at the lowest memory location.

Using Python, one can check that byte 0x01 is the first byte in memory for little endian and the fourth byte for big endian.

>>> import struct
>>> print(struct.pack('<I', 0x04030201))    # integer little endian
b'\x01\x02\x03\x04'
>>> print(struct.pack('>I', 0x04030201))    # integer big endian
b'\x04\x03\x02\x01'

The other Structures that use the 'channels' field define correctly the type as c_uint8.

BTW many thanks for this great project !

mk-fg commented 1 year ago

Should be fixed in 338276f, thanks!

Feel like with ctypes bindings having this amount of header-matching, an automated parser should've definitely been used instead of sloppy manual copy-paste, but it started from pre-written bindings in pulsemixer and just kinda accumulated more. Probably no need to bother changing it by now, with pipewire replacing pulse anyway.