feat(subsonic): support timeOffset in stream.view (#384)

as per
https://github.com/opensubsonic/open-subsonic-api/pull/54
https://github.com/opensubsonic/open-subsonic-api/discussions/21

dont cache partial transcodes

add a transcode seek test
This commit is contained in:
Senan Kelly
2023-10-08 17:10:49 +01:00
committed by GitHub
parent 318b62415d
commit 7eaf602e69
4 changed files with 48 additions and 1 deletions

View File

@@ -64,3 +64,39 @@ func TestTranscode(t *testing.T) {
// we should have 5 seconds of PCM data
require.Equal(t, testFileLen*bytesPerSec, buf.Len())
}
// TestTranscodeWithSeek starts a web server that transcodes a 5s FLAC file to PCM audio, but with a 2 second offset.
// A client consumes the result over a 3 second period.
func TestTranscodeWithSeek(t *testing.T) {
t.Parallel()
testFile := "testdata/5s.flac"
testFileLen := 5
seekSecs := 2
profile := transcode.WithSeek(testProfile, time.Duration(seekSecs)*time.Second)
tr := transcode.NewFFmpegTranscoder()
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.NoError(t, tr.Transcode(r.Context(), profile, testFile, w))
w.(http.Flusher).Flush()
}))
defer server.Close()
resp, err := server.Client().Get(server.URL)
require.NoError(t, err)
defer resp.Body.Close()
var buf bytes.Buffer
for {
n, err := io.Copy(&buf, io.LimitReader(resp.Body, bytesPerSec))
require.NoError(t, err)
if n == 0 {
break
}
time.Sleep(1 * time.Second)
}
// since we seeked 2 seconds, we should have 5-2 = 3 seconds of PCM data
require.Equal(t, (testFileLen-seekSecs)*bytesPerSec, buf.Len())
}