internal/pipewire: seq access method for consume
All checks were successful
Test / Create distribution (push) Successful in 40s
Test / Sandbox (push) Successful in 2m41s
Test / Sandbox (race detector) (push) Successful in 4m48s
Test / Hakurei (push) Successful in 4m56s
Test / Hpkg (push) Successful in 5m7s
Test / Hakurei (race detector) (push) Successful in 6m32s
Test / Flake checks (push) Successful in 1m33s

This improves readability as the offset is not immediately obvious.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
Ophestra 2025-12-07 17:07:30 +09:00
parent 15c2839a09
commit 8cdd659239
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
5 changed files with 12 additions and 5 deletions

View File

@ -112,7 +112,8 @@ func TestClientInfo(t *testing.T) {
{Key: "settings.check-rate", Value: "false"},
{Key: pipewire.PW_KEY_CORE_VERSION, Value: "1.4.7"},
{Key: pipewire.PW_KEY_ACCESS, Value: "unrestricted"},
}}, nil},
},
}, nil},
}.run(t)
}

View File

@ -634,7 +634,7 @@ func (core *Core) consume(opcode byte, files []int, unmarshal func(v any)) error
case PW_CORE_EVENT_DONE:
var done CoreDone
unmarshal(&done)
if done.ID == roundtripSyncID && done.Sequence == CoreSyncSequenceOffset+core.ctx.sequence-1 {
if done.ID == roundtripSyncID && done.Sequence == CoreSyncSequenceOffset+core.ctx.currentSeq() {
if core.done {
return ErrUnexpectedDone
}

View File

@ -209,7 +209,8 @@ func TestCoreBoundProps(t *testing.T) {
{Key: pipewire.PW_KEY_SEC_PID, Value: "1443"},
{Key: pipewire.PW_KEY_SEC_UID, Value: "1000"},
{Key: pipewire.PW_KEY_SEC_GID, Value: "100"},
{Key: pipewire.PW_KEY_SEC_SOCKET, Value: "pipewire-0-manager"}},
{Key: pipewire.PW_KEY_SEC_SOCKET, Value: "pipewire-0-manager"},
},
}, nil},
/* recvmsg 1 */

View File

@ -628,6 +628,10 @@ func (ctx *Context) roundtrip() (err error) {
}
}
// currentSeq returns the current sequence number.
// This must only be called from eventProxy.consume.
func (ctx *Context) currentSeq() Int { return ctx.sequence - 1 }
// currentRemoteSeq returns the current remote sequence number.
// This must only be called from eventProxy.consume.
func (ctx *Context) currentRemoteSeq() Int { return ctx.remoteSequence - 1 }

View File

@ -78,7 +78,7 @@ func TestContext(t *testing.T) {
}
wantCoreInfo0 := pipewire.CoreInfo{
ID: 0,
ID: pipewire.PW_ID_CORE,
Cookie: -2069267610,
UserName: "alice",
HostName: "nixos",
@ -116,7 +116,8 @@ func TestContext(t *testing.T) {
{Key: "settings.check-quantum", Value: "false"},
{Key: "settings.check-rate", Value: "false"},
{Key: pipewire.PW_KEY_OBJECT_ID, Value: "0"},
{Key: pipewire.PW_KEY_OBJECT_SERIAL, Value: "0"}},
{Key: pipewire.PW_KEY_OBJECT_SERIAL, Value: "0"},
},
}
wantClient0 := pipewire.Client{