Context

digraph inheritance { rankdir=LR; GObject -> WpContext; WpContext -> WpMainContext; WpContext -> WpClientContext; }

struct WpContext

The base class of the contexts that WirePlumber runs PipeWire objects in. A context wraps a pw_context that runs on a loop, owns a WpConnection that connects it to the PipeWire server, and is associated with the GMainContext of the core.

GObject Properties

core

The core of the context

WpCore *

G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY

g-main-context

The GMainContext of the core

GMainContext *

G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY

spa-libs

The "context.spa-libs" description of the pw_context

WpSpaJson *

G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY

modules

The "context.modules" description of the pw_context

WpSpaJson *

G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY

properties

The properties of the pw_context

WpProperties *

G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY

struct WpMainContext

The context wraps a pw_context and glues the PipeWire library's event loop system with GMainLoop. It owns the WpConnection that connects it to the PipeWire server. It is created by wp_core_new().

struct WpClientContext

The client context is a secondary context that runs a pw_context on its own pw_thread_loop, with its own connection to PipeWire. It is created by the "client-context" built-in component, which starts it and registers it on the core, and wp_client_context_find() returns it, or NULL if it does not exist.

When it exists, it hosts every PipeWire object that WirePlumber implements in-process: PipeWire modules loaded with WpImplModule, nodes created with WpImplNode and SPA devices wrapped by WpSpaDevice. Otherwise, these objects live in the WpMainContext.

The purpose is isolation: the GMainContext of the core also dispatches the event dispatcher, whose hooks are Lua scripts that can run for an arbitrarily long time, and GSource priorities do not preempt, so anything sharing that loop stalls for as long as a hook runs. Media objects cannot afford that.

Threading

All the GObjects remain owned by the thread that runs the GMainContext of the core (the main thread), so their API does not change. The pw_context and the pw_core of the client context, and everything that lives on them, are owned by the loop thread instead:

  • the objects returned by wp_context_get_pw_context() and wp_context_get_pw_core() on a client context must not be used from the main thread

  • WirePlumber hands events that arrive on the loop thread over to the main thread, in order, so signals are always emitted on the main thread

GMainContext *wp_context_get_g_main_context(WpContext *self)

Gets the GMainContext of the context.

Parameters:
  • self -- the context

Returns:

(transfer none) (nullable): the GMainContext that is in use by this context for events

WpSpaJson *wp_context_get_spa_libs(WpContext *self)

Gets the "context.spa-libs" description of the context.

Parameters:
  • self -- the context

Returns:

(transfer none) (nullable): the "context.spa-libs" description of self

WpSpaJson *wp_context_get_modules(WpContext *self)

Gets the "context.modules" description of the context.

Parameters:
  • self -- the context

Returns:

(transfer none) (nullable): the "context.modules" description of self

WpProperties *wp_context_get_properties(WpContext *self)

Gets the properties of the context.

Parameters:
  • self -- the context

Returns:

(transfer full): the properties of self

struct pw_context *wp_context_get_pw_context(WpContext *self)

Gets the internal PipeWire context.

Parameters:
  • self -- the context

Returns:

(transfer none): the internal pw_context object

gchar *wp_context_get_vm_type(WpContext *self)

Gets the virtual machine type of the context.

Parameters:
  • self -- the context

Returns:

(transfer full) (nullable): a comma separated string with all the virtual machine types that this context matches, or NULL if the context is not running in a virtual machine. VM types that are not known to WirePlumber are reported as "unknown".

void wp_context_idle_add(WpContext *self, GSource **source, GSourceFunc function, gpointer data, GDestroyNotify destroy)

Adds an idle callback to be called in the same GMainContext as the one used by this context.

This is essentially the same as g_idle_add_full(), but it adds the created GSource on the GMainContext used by this context instead of the default context.

Parameters:
  • self -- the context

  • source -- (out) (optional): the source

  • function -- (scope notified)(closure data)(destroy destroy): the function to call

  • data -- data to pass to function

  • destroy -- (nullable): a function to destroy data

void wp_context_idle_add_closure(WpContext *self, GSource **source, GClosure *closure)

Adds an idle callback to be called in the same GMainContext as the one used by this context.

This is the same as wp_context_idle_add(), but it allows you to specify a GClosure instead of a C callback.

Parameters:
  • self -- the context

  • source -- (out) (optional): the source

  • closure -- the closure to invoke

void wp_context_timeout_add(WpContext *self, GSource **source, guint timeout_ms, GSourceFunc function, gpointer data, GDestroyNotify destroy)

Adds a timeout callback to be called at regular intervals in the same GMainContext as the one used by this context.

The function is called repeatedly until it returns FALSE, at which point the timeout is automatically destroyed and the function will not be called again. The first call to the function will be at the end of the first interval.

This is essentially the same as g_timeout_add_full(), but it adds the created GSource on the GMainContext used by this context instead of the default context.

Parameters:
  • self -- the context

  • source -- (out) (optional): the source

  • timeout_ms -- the timeout in milliseconds

  • function -- (scope notified)(closure data)(destroy destroy): the function to call

  • data -- data to pass to function

  • destroy -- (nullable): a function to destroy data

void wp_context_timeout_add_closure(WpContext *self, GSource **source, guint timeout_ms, GClosure *closure)

Adds a timeout callback to be called at regular intervals in the same GMainContext as the one used by this context.

This is the same as wp_context_timeout_add(), but it allows you to specify a GClosure instead of a C callback.

Parameters:
  • self -- the context

  • source -- (out) (optional): the source

  • timeout_ms -- the timeout in milliseconds

  • closure -- the closure to invoke

struct pw_core *wp_context_get_pw_core(WpContext *self)

Gets the connection of the context to PipeWire.

Parameters:
  • self -- the context

Returns:

(transfer none) (nullable): the internal pw_core object, or NULL if the context is not connected to PipeWire

WpCore *wp_context_get_core(WpContext *self)

Gets the core of the context.

Parameters:
  • self -- the context

Returns:

(transfer full) (nullable): the core of self, or NULL if that core is gone

WpConnection *wp_main_context_get_connection(WpMainContext *self)

Gets the connection of the context to PipeWire.

Parameters:
  • self -- the context

Returns:

(transfer none): the connection of self

WpClientContext *wp_client_context_find(WpCore *core)

Finds the registered client context of the core.

When it exists, the client context hosts the objects that are implemented in this process: WpImplModule, WpImplNode and WpSpaDevice.

Parameters:
  • core -- the WpCore

Returns:

(transfer full) (nullable): the client context of core, or NULL if the "client-context" component is not loaded

WP_TYPE_CONTEXT (wp_context_get_type ())

The WpContext GType.

WP_TYPE_MAIN_CONTEXT (wp_main_context_get_type ())

The WpMainContext GType.

WP_TYPE_CLIENT_CONTEXT (wp_client_context_get_type ())

The WpClientContext GType.