Default Nodes Scripts

These scripts contain logic to select default source and sink nodes and also manage user preferences regarding those.

Hooks

Management of the default source and sink nodes is implemented by scanning all the available nodes in the graph and assigning them a priority based on certain logic. The node with the highest priority in each category becomes the default.

Scanning is implemented using a “rescan-for-default-nodes” event. The “default-nodes/rescan-trigger” hook is the one that monitors graph changes and schedules “rescan-for-default-nodes”. Then, the “default-nodes/rescan” hook is executed for the “rescan-for-default-nodes” event and it pushes a “select-default-node” event for each one of the categories where a default node is required:

  • Audio sink

  • Audio source

  • Video source

Note

The actual order of the “default-nodes/find-*” hooks is not defined and doesn’t matter. The only thing that matters is that “default-nodes/apply-default-node” is the last hook.

select-default-node event

High priority event to select the default node for a given category (media.type & direction combination).

In this event, each hook is tasked to find the highest priority node of the category it runs for. In order to do that, a list of available nodes is calculated in advance, by the “default-nodes/rescan” hook, and passed on to each of the “select-default-node” hooks via event data. Each hook then has to go through this list and select a node, placing it in the “selected-node” event data together with its priority number in “selected-node-priority”. The next hook, then, may override the “selected-node” and “selected-node-priority” with something else, but only if the new priority is higher than the old one.

Event properties

Property name

Description

default-node.type

the suffix of the metadata keys related to this default node (audio.sink, audio.source or video.source)

Exchanged event data

Name

Description

available-nodes

JSON array of all selectable nodes, with each element containing all node properties

selected-node

the selected node’s node.name (string)

selected-node-priority

the priority (integer)