# AES67 config file for PipeWire version @VERSION@ #
#
# Copy and edit this file in @PIPEWIRE_CONFIG_DIR@ for system-wide changes
# or in ~/.config/pipewire for local changes.
#
# It is also possible to place a file with an updated section in
# @PIPEWIRE_CONFIG_DIR@/pipewire-aes67.conf.d/ for system-wide changes or in
# ~/.config/pipewire/pipewire-aes67.conf.d/ for local changes.
#

context.properties = {
    ## Configure properties in the system.
    #mem.warn-mlock  = false
    #mem.allow-mlock = true
    #mem.mlock-all   = false
    #log.level       = 2

    #default.clock.quantum-limit = 8192
}

context.spa-libs = {
    support.*       = support/libspa-support
}

context.objects = [
    # An example clock reading from /dev/ptp0. Another option is to sync the
    # ptp clock to CLOCK_TAI and then set clock.id = tai.
    # If both device and ID are given and available, device takes precedence
    { factory = spa-node-factory
        args = {
            factory.name    = support.node.driver
            node.name       = PTP0-Driver
            node.group      = pipewire.ptp0
            # This driver should only be used for network nodes marked with group
            priority.driver = 0
            clock.name      = "clock.system.ptp0"
            clock.device    = "/dev/ptp0"
            clock.id        = tai
            object.export   = true
        }
    }
]

context.modules = [
    { name = libpipewire-module-rt
        args = {
            nice.level   = -11
            #rt.prio      = 88
            #rt.time.soft = -1
            #rt.time.hard = -1
        }
        flags = [ ifexists nofail ]
    }
    { name = libpipewire-module-protocol-native }
    { name = libpipewire-module-client-node }
    { name = libpipewire-module-spa-node-factory }
    { name = libpipewire-module-adapter }
    { name = libpipewire-module-rtp-sap
        args = {
            local.ifname = eth0
            sap.ip = 239.255.255.255
            sap.port = 9875
            net.ttl = 32
            net.loop = true

            stream.rules = [
                {
                    matches = [
                        {
                            rtp.session = "~.*"
                        }
                    ]
                    actions = {
                        create-stream = {
                            node.virtual = false
                            media.class = "Audio/Source"
                            device.api = aes67
                            sess.latency.msec = 10
                            node.group = pipewire.ptp0
                        }
                    }
                },
                {
                    matches = [
                        {
                            sess.sap.announce = true
                        }
                    ]
                    actions = {
                        announce-stream = {}
                    }
               }
            ]
        }
    },
    { name = libpipewire-module-rtp-sink
        args = {
            local.ifname = eth0
            destination.ip = 239.69.150.243
            destination.port = 5004
            net.mtu = 1280
            net.ttl = 32
            net.loop = true
            sess.min-ptime = 1
            sess.max-ptime = 1
            sess.name = "PipeWire RTP stream"
            sess.media = "audio"
            sess.ts-refclk = "ptp=traceable"
            sess.ts-offset = 0
            sess.ptime = 1
            sess.latency.msec = 1
            sess.announce = true
            audio.format = "S24BE"
            audio.rate = 48000
            audio.channels = 2
            audio.position = [ FL FR ]

            stream.props = {
                node.name = "rtp-sink"
                media.class = "Audio/Sink"
                node.virtual = false
                device.api = aes67
                sess.sap.announce = true
                node.always-process = true
                node.group = pipewire.ptp0
            }
        }
    },
]
