106 lines
2.1 KiB
Go
106 lines
2.1 KiB
Go
//go:build !disable_format_flac && !disable_codec_libflac && cgo
|
|
|
|
package packetizer
|
|
|
|
import (
|
|
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format/flac"
|
|
"git.gammaspectra.live/S.O.N.G/Kirika/test"
|
|
"io"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestPacketizeOggFLAC(t *testing.T) {
|
|
t.Parallel()
|
|
fp, err := os.Open(test.SingleSample24)
|
|
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()
|
|
options := make(map[string]interface{})
|
|
options["ogg"] = true
|
|
err = flac.NewFormat().Encode(source, writer, options)
|
|
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 != 1059 {
|
|
t.Errorf("Wrong Packet Count %d != %d", packetCount, 1059)
|
|
}
|
|
if packetBytes < 50000000 {
|
|
t.Errorf("Wrong Packet Bytes %d < %d", packetBytes, 50000000)
|
|
}
|
|
}
|
|
|
|
func TestPacketizeOggFLACOffset(t *testing.T) {
|
|
t.Parallel()
|
|
fp, err := os.Open(test.SingleSample24)
|
|
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()
|
|
options := make(map[string]interface{})
|
|
options["ogg"] = true
|
|
err = flac.NewFormat().Encode(source, writer, options)
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
}()
|
|
|
|
pipePacketizer := NewOggPacketizer(reader)
|
|
packetCount := 0
|
|
packetBytes := 0
|
|
for {
|
|
packet := pipePacketizer.GetPacket()
|
|
if packet == nil {
|
|
break
|
|
}
|
|
packetCount++
|
|
if offsetablePacket, ok := packet.(OffsetablePacket); ok {
|
|
packetBytes += len(offsetablePacket.GetDataOffset(4096))
|
|
}
|
|
}
|
|
if packetCount != 1059 {
|
|
t.Errorf("Wrong Packet Count %d != %d", packetCount, 1059)
|
|
}
|
|
if packetBytes < 50000000 {
|
|
t.Errorf("Wrong Packet Bytes %d < %d", packetBytes, 50000000)
|
|
}
|
|
}
|