Kirika/audio/packetizer/ogg_test.go
2022-05-20 17:23:50 +02:00

57 lines
1.1 KiB
Go

//go:build !disable_format_opus && cgo
package packetizer
import (
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format/flac"
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format/opus"
"git.gammaspectra.live/S.O.N.G/Kirika/test"
"io"
"os"
"testing"
)
func TestPacketizeOgg(t *testing.T) {
t.Parallel()
fp, err := os.Open(test.TestSingleSample24)
if err != nil {
t.Error(err)
return
}
defer fp.Close()
source, err := flac.NewFormat().Open(fp)
if err != nil {
t.Error(err)
return
}
reader, writer := io.Pipe()
go func() {
defer writer.Close()
err = opus.NewFormat().Encode(source, writer, nil)
if err != nil {
t.Error(err)
return
}
}()
pipePacketizer := NewOggPacketizer(reader)
packetCount := 0
packetBytes := 0
for {
packet := pipePacketizer.GetPacket()
if packet == nil {
break
}
packetCount++
packetBytes += len(packet.GetData())
}
if packetCount != 395 {
t.Errorf("Wrong Packet Count %d != %d", packetCount, 395)
}
if packetBytes != 5962688 {
t.Errorf("Wrong Packet Bytes %d != %d", packetBytes, 5962688)
}
}