101 lines
2.3 KiB
Go
101 lines
2.3 KiB
Go
package y4m
|
|
|
|
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 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
|
|
}
|
|
|
|
var y4m *Decoder
|
|
|
|
switch sample.Type {
|
|
case "y4m":
|
|
y4m, err = NewDecoder(reader, nil)
|
|
case "y4m.xz":
|
|
y4m, err = NewXZCompressedDecoder(reader, nil)
|
|
default:
|
|
t.Fatal("unsupported sample type")
|
|
}
|
|
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
} else {
|
|
defer y4m.Close()
|
|
decoded := 0
|
|
|
|
var frameProperties frame.Properties
|
|
for decodedFrame := range y4m.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_720p24_8bit(t *testing.T) {
|
|
testDecode(testdata.Y4M_Sintel_Trailer_720p24_YUV420_8bit, t)
|
|
}
|
|
|
|
func TestDecode_YUV444_720p50_8bit(t *testing.T) {
|
|
testDecode(testdata.Y4M_Ducks_Take_Off_720p50_YUV444_8bit, t)
|
|
}
|
|
|
|
func TestDecode_YUV422_720p50_8bit(t *testing.T) {
|
|
testDecode(testdata.Y4M_Ducks_Take_Off_720p50_YUV422_8bit, t)
|
|
}
|
|
|
|
func TestDecode_YUV420_2160p60_10bit(t *testing.T) {
|
|
testDecode(testdata.Y4M_Netflix_FoodMarket_2160p60_YUV420_10bit, t)
|
|
}
|
|
|
|
func TestDecode_YUV420_360p24_8bit_xz(t *testing.T) {
|
|
testDecode(testdata.Y4M_Big_Buck_Bunny_360p24_YUV420_8bit, t)
|
|
}
|