Talking to PipeWire

March 2026

Why PipeWire?

Some challenges from last year's topic:

About PipeWire

Wikipedia says:

PipeWire is a low-level server and multimedia framework for handling audio and video streams on Linux. Created by Wim Taymans at Red Hat, it aims to unify audio and video processing by providing low-latency capture and playback functionality. PipeWire facilitates advanced multimedia routing and pipeline processing, and is designed to replace and be compatible with existing sound systems.

PipeWire is available on current Linux versions

PipeWire comes with...

The Procedure

  1. Run the examples from the API tutorial
    Easy.
  2. Run the examples from Perl, using Inline::C
    Also easy, but not too informative.
  3. Try h2xs on the PipeWire header
    Well, not really. I shall revisit that at some time.
  4. Go for FFI::Platypus

The h2xs Experience

$ h2xs /usr/include/pipewire-0.3/pipewire/pipewire.h

I had no idea what the next step would be to "translate" the C programs from the tutorial to Perl.

I could have read a XS tutorial, but...

Dave Mitchell had announced that he would rewrite the XS documentation, so I decided to postpone XS. He also recently said he intends to rewrite the XS tutorial.

The new perlxs documentation is already available.

Go for FFI::Platypus

FFI::Platypus suggests that you can build interfaces to C without writing XS.

FFI = Foreign Function Interface: libffi

From the DESCRIPTION: Platypus is a library for creating interfaces to machine code libraries written in languages like C, C++, Go, Fortran, Rust, Pascal.

Tutorial 2: Enumerating Objects

First subroutine: Create a main loop

Tutorial 2: Enumerating Objects II

Create a context

Tutorial 2: Enumerating Objects III

Connect to the core

Tutorial 2: Enumerating Objects IV

Get the registry

WTF?

$ perl tutorial2.pl
pw_core_get_registry: not found

WTF?

$ perl tutorial2.pl
pw_core_get_registry: not found

Ah. I missed something.

Some C Code Required

(no XS, though, as promised)

PipeWire uses static inline functions or functions implemented as preprocessor macros a lot.

Luckily, FFI::Platypus makes adding own C code quite easy.

Add C Code

Uses for Bundled C Code

Tutorial 2: Enumerating Objects V

Define the callback routine

Complex Data Types

Issues and Limitations

Enter Convert::Binary::C(CBC)

CBC for Code Generation

An Example Class

Tutorial 4: Playing Sound

Using what I have learned plus code generation for about a dozen classes should be easy, shouldn't it?

Tutorial 4: Playing Sound

Using what I have learned plus code generation for about a dozen classes should be easy, shouldn't it?

Thread pw_data received signal SIGSEGV, Segmentation fault.

This time, it is not my fault.

It works with Perls built without threads.

Portability Summary

FFI::Platypus Summary

Convert::Binary::C Summary

Miscellaneous Topics

Obscure Objects of Desire

See Also...

References