internal/pipewire: implement Core::Info and generation footer
All checks were successful
Test / Create distribution (push) Successful in 37s
Test / Sandbox (push) Successful in 2m19s
Test / Hakurei (push) Successful in 3m17s
Test / Hpkg (push) Successful in 4m15s
Test / Sandbox (race detector) (push) Successful in 4m20s
Test / Hakurei (race detector) (push) Successful in 5m7s
Test / Flake checks (push) Successful in 1m21s

These are not directly related but are first encountered on the same message in the capture.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
Ophestra 2025-11-25 15:15:20 +09:00
parent 05391da556
commit cfeb7818eb
Signed by: cat
SSH Key Fingerprint: SHA256:wr6yH7sDDbUFi81k/GsIGwpM3O2QrwqYlLF26CcJa4w
7 changed files with 113 additions and 0 deletions

View File

@ -66,6 +66,51 @@ const (
PW_VERSION_REGISTRY_METHODS = 0 PW_VERSION_REGISTRY_METHODS = 0
) )
const (
FOOTER_CORE_OPCODE_GENERATION = iota
FOOTER_CORE_OPCODE_LAST
)
// The FooterCoreGeneration indicates to the client what is the current
// registry generation number of the Context on the server side.
//
// The server shall include this footer in the next message it sends that
// follows the increment of the registry generation number.
type FooterCoreGeneration struct {
RegistryGeneration Long
}
// A CoreInfo event is emitted by the server upon connection
// with the more information about the server.
type CoreInfo struct {
// The id of the server (PW_ID_CORE).
ID Int
// A unique cookie for this server.
Cookie Int
// The name of the user running the server.
UserName String
// The name of the host running the server.
HostName String
// A version string of the server.
Version String
// The name of the server.
Name String
// A set of bits with changes to the info.
ChangeMask Long
// Optional key/value properties, valid when change_mask has PW_CORE_CHANGE_MASK_PROPS.
Props *SPADict
}
// MarshalBinary satisfies [encoding.BinaryMarshaler] via [Marshal].
func (c *CoreInfo) MarshalBinary() ([]byte, error) { return Marshal(c) }
// UnmarshalBinary satisfies [encoding.BinaryUnmarshaler] via [Unmarshal].
func (c *CoreInfo) UnmarshalBinary(data []byte) error {
_, err := Unmarshal(data, c)
return err
}
// CoreHello is the first message sent by a client. // CoreHello is the first message sent by a client.
type CoreHello struct { type CoreHello struct {
// The version number of the client, usually PW_VERSION_CORE. // The version number of the client, usually PW_VERSION_CORE.

View File

@ -6,6 +6,61 @@ import (
"hakurei.app/internal/pipewire" "hakurei.app/internal/pipewire"
) )
func TestFooterCoreGeneration(t *testing.T) {
encodingTestCases[pipewire.Footer[pipewire.FooterCoreGeneration], *pipewire.Footer[pipewire.FooterCoreGeneration]]{
{"sample", []byte(recvmsg00Message00Footer), pipewire.Footer[pipewire.FooterCoreGeneration]{
Opcode: pipewire.FOOTER_CORE_OPCODE_GENERATION,
Payload: pipewire.FooterCoreGeneration{RegistryGeneration: 34},
}, nil},
}.run(t)
}
func TestCoreInfo(t *testing.T) {
encodingTestCases[pipewire.CoreInfo, *pipewire.CoreInfo]{
{"sample", []byte(recvmsg00Message00POD), pipewire.CoreInfo{
ID: 0,
Cookie: -2069267610,
UserName: "alice",
HostName: "nixos",
Version: "1.4.7",
Name: "pipewire-0",
ChangeMask: pipewire.PW_CORE_CHANGE_MASK_PROPS,
Props: &pipewire.SPADict{NItems: 31, Items: []pipewire.SPADictItem{
{Key: "config.name", Value: "pipewire.conf"},
{Key: "application.name", Value: "pipewire"},
{Key: "application.process.binary", Value: "pipewire"},
{Key: "application.language", Value: "en_US.UTF-8"},
{Key: "application.process.id", Value: "1446"},
{Key: "application.process.user", Value: "alice"},
{Key: "application.process.host", Value: "nixos"},
{Key: "window.x11.display", Value: ":0"},
{Key: "cpu.vm.name", Value: "qemu"},
{Key: "link.max-buffers", Value: "16"},
{Key: "core.daemon", Value: "true"},
{Key: "core.name", Value: "pipewire-0"},
{Key: "default.clock.min-quantum", Value: "1024"},
{Key: "cpu.max-align", Value: "32"},
{Key: "default.clock.rate", Value: "48000"},
{Key: "default.clock.quantum", Value: "1024"},
{Key: "default.clock.max-quantum", Value: "2048"},
{Key: "default.clock.quantum-limit", Value: "8192"},
{Key: "default.clock.quantum-floor", Value: "4"},
{Key: "default.video.width", Value: "640"},
{Key: "default.video.height", Value: "480"},
{Key: "default.video.rate.num", Value: "25"},
{Key: "default.video.rate.denom", Value: "1"},
{Key: "log.level", Value: "2"},
{Key: "clock.power-of-two-quantum", Value: "true"},
{Key: "mem.warn-mlock", Value: "false"},
{Key: "mem.allow-mlock", Value: "true"},
{Key: "settings.check-quantum", Value: "false"},
{Key: "settings.check-rate", Value: "false"},
{Key: "object.id", Value: "0"},
{Key: "object.serial", Value: "0"}},
}}, nil},
}.run(t)
}
func TestCoreHello(t *testing.T) { func TestCoreHello(t *testing.T) {
encodingTestCases[pipewire.CoreHello, *pipewire.CoreHello]{ encodingTestCases[pipewire.CoreHello, *pipewire.CoreHello]{
{"sample", []byte(sendmsg00Message00POD), pipewire.CoreHello{ {"sample", []byte(sendmsg00Message00POD), pipewire.CoreHello{

View File

@ -35,6 +35,12 @@ func TestHeader(t *testing.T) {
Size: 0x28, Sequence: 3, FileCount: 0, Size: 0x28, Sequence: 3, FileCount: 0,
}, nil}, }, nil},
{"PW_CORE_EVENT_INFO", []byte(recvmsg00Message00Header), pipewire.Header{
ID: pipewire.PW_ID_CORE,
Opcode: pipewire.PW_CORE_EVENT_INFO,
Size: 0x6b8, Sequence: 0, FileCount: 0,
}, nil},
{"PW_SECURITY_CONTEXT_METHOD_CREATE", []byte{ {"PW_SECURITY_CONTEXT_METHOD_CREATE", []byte{
// Id // Id
3, 0, 0, 0, 3, 0, 0, 0,

View File

@ -24,4 +24,11 @@ var (
sendmsg00Message03Header string sendmsg00Message03Header string
//go:embed testdata/07-sendmsg00-message03-POD //go:embed testdata/07-sendmsg00-message03-POD
sendmsg00Message03POD string sendmsg00Message03POD string
//go:embed testdata/08-recvmsg00-message00-header
recvmsg00Message00Header string
//go:embed testdata/09-recvmsg00-message00-POD
recvmsg00Message00POD string
//go:embed testdata/10-recvmsg00-message00-footer
recvmsg00Message00Footer string
) )

Binary file not shown.

Binary file not shown.

Binary file not shown.