Fix video playback hanging at end (#2996)

Co-authored-by: gerit1a <10052885+gerit1a@users.noreply.github.com>
This commit is contained in:
WithoutPants 2022-10-11 14:24:09 +11:00 committed by GitHub
parent 6b5d5cc628
commit a6fd577f03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -206,7 +206,10 @@ func (rs sceneRoutes) streamTranscode(w http.ResponseWriter, r *http.Request, st
lm := manager.GetInstance().ReadLockManager
streamRequestCtx := manager.NewStreamRequestContext(w, r)
lockCtx := lm.ReadLock(streamRequestCtx, f.Path)
defer lockCtx.Cancel()
// hijacking and closing the connection here causes video playback to hang in Chrome
// due to ERR_INCOMPLETE_CHUNKED_ENCODING
// We trust that the request context will be closed, so we don't need to call Cancel on the returned context here.
stream, err := encoder.GetTranscodeStream(lockCtx, options)
@ -222,6 +225,7 @@ func (rs sceneRoutes) streamTranscode(w http.ResponseWriter, r *http.Request, st
lockCtx.AttachCommand(stream.Cmd)
stream.Serve(w, r)
w.(http.Flusher).Flush()
}
func (rs sceneRoutes) Screenshot(w http.ResponseWriter, r *http.Request) {

View File

@ -34,8 +34,21 @@ func (c *StreamRequestContext) Cancel() {
}
// hijack and close the connection
conn, _, _ := hj.Hijack()
conn, bw, _ := hj.Hijack()
if conn != nil {
if bw != nil {
// notify end of stream
_, err := bw.WriteString("0\r\n")
if err != nil {
logger.Warnf("unable to write end of stream: %v", err)
}
_, err = bw.WriteString("\r\n")
if err != nil {
logger.Warnf("unable to write end of stream: %v", err)
}
_ = bw.Flush()
}
conn.Close()
}
}