aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pipewire
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-11-25 08:52:06 +0900
committerOphestra <cat@gensokyo.uk>2025-11-25 08:52:06 +0900
commitfc3d78fe010f9e3c22a058723bf816570553c0da (patch)
tree3b618c0e5aa1501f9ff9182fdf2c2ceb12f6d34c /internal/pipewire
parent591637264a76771d36531a3e51e7db40ef853421 (diff)
internal/pipewire: implement Core::Sync
Once again, already entirely supported, the offset is not yet fully verified but makes intuitive sense. Will verify this on future occurrences of the message. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pipewire')
-rw-r--r--internal/pipewire/core.go28
-rw-r--r--internal/pipewire/core_test.go9
-rw-r--r--internal/pipewire/header_test.go6
-rw-r--r--internal/pipewire/pipewire_test.go5
-rw-r--r--internal/pipewire/testdata/06-sendmsg00-message03-headerbin0 -> 16 bytes
-rw-r--r--internal/pipewire/testdata/07-sendmsg00-message03-PODbin0 -> 40 bytes
6 files changed, 48 insertions, 0 deletions
diff --git a/internal/pipewire/core.go b/internal/pipewire/core.go
index 137c9bc5..7a052086 100644
--- a/internal/pipewire/core.go
+++ b/internal/pipewire/core.go
@@ -83,6 +83,34 @@ func (c *CoreHello) UnmarshalBinary(data []byte) error {
return err
}
+const (
+ // CoreSyncSequenceOffset is the offset to [Header.Sequence] to produce [CoreSync.Sequence].
+ CoreSyncSequenceOffset = 0x40000000
+)
+
+// The CoreSync message will result in a Done event from the server.
+// When the Done event is received, the client can be sure that all
+// operations before the Sync method have been completed.
+type CoreSync struct {
+ // The id will be returned in the Done event,
+ // ends up as [Header.ID] in a future message.
+ ID Int
+ // Usually generated automatically and will be
+ // returned in the Done event.
+ Sequence Int
+}
+
+// MarshalBinary satisfies [encoding.BinaryMarshaler] via [MarshalAppend].
+func (c *CoreSync) MarshalBinary() ([]byte, error) {
+ return MarshalAppend(make([]byte, 0, 40), c)
+}
+
+// UnmarshalBinary satisfies [encoding.BinaryUnmarshaler] via [Unmarshal].
+func (c *CoreSync) UnmarshalBinary(data []byte) error {
+ _, err := Unmarshal(data, c)
+ return err
+}
+
// CoreGetRegistry is sent when a client requests to bind to the
// registry object and list the available objects on the server.
//
diff --git a/internal/pipewire/core_test.go b/internal/pipewire/core_test.go
index b47c4265..a04013c2 100644
--- a/internal/pipewire/core_test.go
+++ b/internal/pipewire/core_test.go
@@ -14,6 +14,15 @@ func TestCoreHello(t *testing.T) {
}.run(t)
}
+func TestCoreSync(t *testing.T) {
+ encodingTestCases[pipewire.CoreSync, *pipewire.CoreSync]{
+ {"sample", []byte(sendmsg00Message03POD), pipewire.CoreSync{
+ ID: pipewire.PW_ID_CORE,
+ Sequence: pipewire.CoreSyncSequenceOffset + 3,
+ }, nil},
+ }.run(t)
+}
+
func TestCoreGetRegistry(t *testing.T) {
encodingTestCases[pipewire.CoreGetRegistry, *pipewire.CoreGetRegistry]{
{"sample", []byte(sendmsg00Message02POD), pipewire.CoreGetRegistry{
diff --git a/internal/pipewire/header_test.go b/internal/pipewire/header_test.go
index 2d055088..d7ca468b 100644
--- a/internal/pipewire/header_test.go
+++ b/internal/pipewire/header_test.go
@@ -29,6 +29,12 @@ func TestHeader(t *testing.T) {
Size: 0x28, Sequence: 2, FileCount: 0,
}, nil},
+ {"PW_CORE_METHOD_SYNC", []byte(sendmsg00Message03Header), pipewire.Header{
+ ID: pipewire.PW_ID_CORE,
+ Opcode: pipewire.PW_CORE_METHOD_SYNC,
+ Size: 0x28, Sequence: 3, FileCount: 0,
+ }, nil},
+
{"PW_SECURITY_CONTEXT_METHOD_CREATE", []byte{
// Id
3, 0, 0, 0,
diff --git a/internal/pipewire/pipewire_test.go b/internal/pipewire/pipewire_test.go
index fe16bb53..28ba3293 100644
--- a/internal/pipewire/pipewire_test.go
+++ b/internal/pipewire/pipewire_test.go
@@ -19,4 +19,9 @@ var (
sendmsg00Message02Header string
//go:embed testdata/05-sendmsg00-message02-POD
sendmsg00Message02POD string
+
+ //go:embed testdata/06-sendmsg00-message03-header
+ sendmsg00Message03Header string
+ //go:embed testdata/07-sendmsg00-message03-POD
+ sendmsg00Message03POD string
)
diff --git a/internal/pipewire/testdata/06-sendmsg00-message03-header b/internal/pipewire/testdata/06-sendmsg00-message03-header
new file mode 100644
index 00000000..4ee05589
--- /dev/null
+++ b/internal/pipewire/testdata/06-sendmsg00-message03-header
Binary files differ
diff --git a/internal/pipewire/testdata/07-sendmsg00-message03-POD b/internal/pipewire/testdata/07-sendmsg00-message03-POD
new file mode 100644
index 00000000..e54dc273
--- /dev/null
+++ b/internal/pipewire/testdata/07-sendmsg00-message03-POD
Binary files differ