-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtail.go
More file actions
43 lines (41 loc) · 1.07 KB
/
Copy pathtail.go
File metadata and controls
43 lines (41 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package hls
import (
"net/http"
)
// Tail serves the video as one continuous stream, starting from the next segment.
func (p *Publisher) Tail(rw http.ResponseWriter, req *http.Request) {
if p.Mode == ModeSeparateTracks {
http.NotFound(rw, req)
return
}
state, _ := p.state.Load().(hlsState)
if !state.Valid() {
http.NotFound(rw, req)
return
}
rw.Header().Set("Cache-Control", "max-age=0, no-cache, no-store")
hdr := p.tracks[p.comboID].hdr
if len(hdr.HeaderContents) != 0 {
rw.Header().Set("Content-Type", hdr.HeaderContentType)
rw.Write(hdr.HeaderContents)
} else {
rw.Header().Set("Content-Type", hdr.SegmentContentType)
}
flusher, _ := rw.(http.Flusher)
// loop until the client hangs up
msn := state.complete
msn.Part = 0
for req.Context().Err() == nil {
msn.MSN++
// wait for the next segment to begin
state = p.waitForSegment(req.Context(), msn)
cursor, _ := state.Get(msn.MSN, p.comboID)
if !cursor.Valid() || !cursor.Serve(rw, req, -1, true) {
http.Error(rw, "", http.StatusGone)
return
}
if flusher != nil {
flusher.Flush()
}
}
}