internal/pipewire: store sample iovec continuously
All checks were successful
Test / Create distribution (push) Successful in 39s
Test / Sandbox (push) Successful in 2m22s
Test / Hpkg (push) Successful in 4m8s
Test / Sandbox (race detector) (push) Successful in 4m28s
Test / Hakurei (race detector) (push) Successful in 5m14s
Test / Hakurei (push) Successful in 2m26s
Test / Flake checks (push) Successful in 1m39s

This removes the need for manual splitting. The understanding of the format is robust enough to allow this to happen anyway.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-11-28 00:34:32 +09:00
parent 1dab87aaf0
commit 72a2601d74
31 changed files with 72 additions and 74 deletions

View File

@@ -2,60 +2,58 @@ package pipewire_test
import (
_ "embed"
"encoding/binary"
"hakurei.app/internal/pipewire"
)
var (
//go:embed testdata/c0s0p0
c0s0header string
//go:embed testdata/c0s0p1
c0s0pod string
//go:embed testdata/pw-container-00-sendmsg
samplePWContainer00 string
//go:embed testdata/pw-container-01-recvmsg
samplePWContainer01 string
//go:embed testdata/pw-container-03-sendmsg
samplePWContainer03 string
//go:embed testdata/pw-container-04-recvmsg
samplePWContainer04 string
//go:embed testdata/pw-container-06-sendmsg
samplePWContainer06 string
//go:embed testdata/pw-container-07-recvmsg
samplePWContainer07 string
//go:embed testdata/c0s1p0
c0s1header string
//go:embed testdata/c0s1p1
c0s1pod string
//go:embed testdata/c0s2p0
c0s2header string
//go:embed testdata/c0s2p1
c0s2pod string
//go:embed testdata/c0s3p0
c0s3header string
//go:embed testdata/c0s3p1
c0s3pod string
//go:embed testdata/c1r0p0
c1r0header string
//go:embed testdata/c1r0p1
c1r0pod string
//go:embed testdata/c1r0p2
c1r0footer string
//go:embed testdata/c1r1p0
c1r1header string
//go:embed testdata/c1r1p1
c1r1pod string
//go:embed testdata/c1r2p0
c1r2header string
//go:embed testdata/c1r2p1
c1r2pod string
//go:embed testdata/c1r3p0
c1r3header string
//go:embed testdata/c1r3p1
c1r3pod string
//go:embed testdata/c1r4p0
c1r4header string
//go:embed testdata/c1r4p1
c1r4pod string
//go:embed testdata/c1r5p0
c1r5header string
//go:embed testdata/c1r5p1
c1r5pod string
//go:embed testdata/c1r5p2
c1r5footer string
// samplePWContainer is a collection of messages from the pw-container sample.
samplePWContainer = [...][][3][]byte{
splitMessages(samplePWContainer00),
splitMessages(samplePWContainer01),
nil,
splitMessages(samplePWContainer03),
splitMessages(samplePWContainer04),
nil,
splitMessages(samplePWContainer06),
splitMessages(samplePWContainer07),
nil,
}
)
// splitMessages splits concatenated messages into groups of
// header, payload, footer of each individual message.
// splitMessages panics on any decoding error.
func splitMessages(iovec string) (messages [][3][]byte) {
data := []byte(iovec)
messages = make([][3][]byte, 0, 1<<7)
var header pipewire.Header
for len(data) != 0 {
if err := header.UnmarshalBinary(data[:pipewire.SizeHeader]); err != nil {
panic(err)
}
size := pipewire.SizePrefix + binary.NativeEndian.Uint32(data[pipewire.SizeHeader:])
messages = append(messages, [3][]byte{
data[:pipewire.SizeHeader],
data[pipewire.SizeHeader : pipewire.SizeHeader+size],
data[pipewire.SizeHeader+size : pipewire.SizeHeader+header.Size],
})
data = data[pipewire.SizeHeader+header.Size:]
}
return
}