aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pipewire/core.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/pipewire/core.go')
-rw-r--r--internal/pipewire/core.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/internal/pipewire/core.go b/internal/pipewire/core.go
index a6d47256..fc3edd4e 100644
--- a/internal/pipewire/core.go
+++ b/internal/pipewire/core.go
@@ -533,6 +533,30 @@ func (c *RegistryGlobal) MarshalBinary() ([]byte, error) { return Marshal(c) }
// UnmarshalBinary satisfies [encoding.BinaryUnmarshaler] via [Unmarshal].
func (c *RegistryGlobal) UnmarshalBinary(data []byte) error { return Unmarshal(data, c) }
+// A RegistryGlobalRemove event is emitted when a global with id was removed.
+type RegistryGlobalRemove struct {
+ // The global id that was removed.
+ ID Int `json:"id"`
+}
+
+// Opcode satisfies [Message] with a constant value.
+func (c *RegistryGlobalRemove) Opcode() byte { return PW_REGISTRY_EVENT_GLOBAL_REMOVE }
+
+// FileCount satisfies [Message] with a constant value.
+func (c *RegistryGlobalRemove) FileCount() Int { return 0 }
+
+// Size satisfies [KnownSize] with a constant value.
+func (c *RegistryGlobalRemove) Size() Word {
+ return SizePrefix +
+ Size(SizeInt)
+}
+
+// MarshalBinary satisfies [encoding.BinaryMarshaler] via [Marshal].
+func (c *RegistryGlobalRemove) MarshalBinary() ([]byte, error) { return Marshal(c) }
+
+// UnmarshalBinary satisfies [encoding.BinaryUnmarshaler] via [Unmarshal].
+func (c *RegistryGlobalRemove) UnmarshalBinary(data []byte) error { return Unmarshal(data, c) }
+
// RegistryBind is sent when the client requests to bind to the
// global object with id and use the client proxy with new_id as
// the proxy. After this call, methods can be sent to the remote
@@ -714,6 +738,14 @@ func (e *GlobalIDCollisionError) Error() string {
" stepping on previous id " + strconv.Itoa(int(e.ID)) + " for " + e.Previous.Type
}
+// An UnknownGlobalIDRemoveError describes a [RegistryGlobalRemove] event announcing the removal of
+// a global id that is not yet known to [Registry] or was already deleted.
+type UnknownGlobalIDRemoveError Int
+
+func (e UnknownGlobalIDRemoveError) Error() string {
+ return "Registry::GlobalRemove event targets unknown id " + strconv.Itoa(int(e))
+}
+
func (registry *Registry) consume(opcode byte, files []int, unmarshal func(v any)) error {
closeReceivedFiles(files...)
switch opcode {
@@ -727,6 +759,17 @@ func (registry *Registry) consume(opcode byte, files []int, unmarshal func(v any
registry.Objects[global.ID] = global
return nil
+ case PW_REGISTRY_EVENT_GLOBAL_REMOVE:
+ var globalRemove RegistryGlobalRemove
+ unmarshal(&globalRemove)
+ l := len(registry.Objects)
+ delete(registry.Objects, globalRemove.ID)
+ if len(registry.Objects) != l-1 {
+ // this should never happen so is non-recoverable if it does
+ panic(UnknownGlobalIDRemoveError(globalRemove.ID))
+ }
+ return nil
+
default:
return &UnsupportedOpcodeError{opcode, registry.String()}
}