92 lines
2.1 KiB
Go
92 lines
2.1 KiB
Go
//go:build cgo && !disable_codec_livdav1d
|
|
|
|
package libdav1d
|
|
|
|
import (
|
|
"git.gammaspectra.live/S.O.N.G/Ignite/frame"
|
|
"git.gammaspectra.live/S.O.N.G/Ignite/testdata"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestVersion(t *testing.T) {
|
|
t.Logf("dav1d version: %s", Version())
|
|
}
|
|
|
|
func testDecode(sample testdata.TestSample, t *testing.T) {
|
|
var reader io.Reader
|
|
var err error
|
|
|
|
if _, err = os.Stat(sample.Path); err != nil {
|
|
if sample.SkipNotFound || sample.Url == "" {
|
|
t.Skip("skipping without sample")
|
|
}
|
|
response, err := http.DefaultClient.Get(sample.Url)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer response.Body.Close()
|
|
reader = response.Body
|
|
} else {
|
|
f, err := os.Open(sample.Path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer f.Close()
|
|
reader = f
|
|
}
|
|
|
|
if decoder, err := NewDecoder(reader, nil); err != nil {
|
|
t.Fatal(err)
|
|
} else {
|
|
defer decoder.Close()
|
|
decoded := 0
|
|
|
|
var frameProperties frame.Properties
|
|
for decodedFrame := range decoder.DecodeStream().Channel() {
|
|
if decoded == 0 {
|
|
frameProperties = decodedFrame.Properties()
|
|
}
|
|
//ingest
|
|
decoded++
|
|
if decoded%50 == 0 {
|
|
t.Logf("%d/%d", decoded, sample.Frames)
|
|
}
|
|
}
|
|
|
|
if decoded != sample.Frames {
|
|
t.Fatalf("expected %d frames, got %d", sample.Frames, decoded)
|
|
}
|
|
|
|
if frameProperties.Width != sample.Width {
|
|
t.Fatalf("expected %d width, got %d", sample.Width, frameProperties.Width)
|
|
}
|
|
|
|
if frameProperties.Height != sample.Height {
|
|
t.Fatalf("expected %d height, got %d", sample.Height, frameProperties.Height)
|
|
}
|
|
|
|
if frameProperties.ColorSpace.String() != sample.ColorSpace.String() {
|
|
t.Fatalf("expected %s color space, got %s", sample.ColorSpace.String(), frameProperties.ColorSpace.String())
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDecode_YUV420_8bit(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skipping test in short mode")
|
|
}
|
|
|
|
testDecode(testdata.AV1_Sintel_Trailer_720p24_YUV420_8bit_Low, t)
|
|
}
|
|
|
|
func TestDecode_YUV444_12bit(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("skipping test in short mode")
|
|
}
|
|
|
|
testDecode(testdata.AV1_Netflix_Sol_Levante_2160p24_YUV444_12bit_Lossy, t)
|
|
}
|