Skip to content

Commit

Permalink
Fix counting HLSv7 sessions (datarhei/restreamer#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioppermann committed Nov 4, 2024
1 parent 6872ba0 commit 0f3dfe4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions http/middleware/session/HLS.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (h *hls) handleIngress(c echo.Context, next echo.HandlerFunc) error {
h.lock.Unlock()
}
}()
} else if strings.HasSuffix(path, ".ts") {
} else if strings.HasSuffix(path, ".ts") || strings.HasSuffix(path, ".mp4") {
// Get the size of the .ts file and store it in the ts-map for later use.
reader := req.Body
r := &bodysizeReader{
Expand Down Expand Up @@ -171,7 +171,7 @@ func (h *hls) handleEgress(c echo.Context, next echo.HandlerFunc) error {
sessionID := c.QueryParam("session")

isM3U8 := strings.HasSuffix(path, ".m3u8")
isTS := strings.HasSuffix(path, ".ts")
isSegment := strings.HasSuffix(path, ".ts") || strings.HasSuffix(path, ".mp4")

rewrite := false

Expand Down Expand Up @@ -257,12 +257,12 @@ func (h *hls) handleEgress(c echo.Context, next echo.HandlerFunc) error {
res.Write(rewriter.buffer.Bytes())
}

if isM3U8 || isTS {
if isM3U8 || isSegment {
// Collect how many bytes we've written in this session
h.egressCollector.Egress(sessionID, headerSize(res.Header()))
h.egressCollector.Egress(sessionID, res.Size)

if isTS {
if isSegment {
// Activate the session. If the session is already active, this is a noop
h.egressCollector.Activate(sessionID)
}
Expand Down Expand Up @@ -329,7 +329,7 @@ func (r *bodyReader) getSegments(dir string) []string {
}

// Ignore anything that doesn't end in .ts
if !strings.HasSuffix(u.Path, ".ts") {
if !strings.HasSuffix(u.Path, ".ts") && !strings.HasSuffix(u.Path, ".mp4") {
continue
}

Expand Down Expand Up @@ -402,7 +402,7 @@ func (g *sessionRewriter) rewriteHLS(sessionID string, requestURL *url.URL) {
}

// Write anything that doesn't end in .m3u8 or .ts unmodified
if !strings.HasSuffix(u.Path, ".m3u8") && !strings.HasSuffix(u.Path, ".ts") {
if !strings.HasSuffix(u.Path, ".m3u8") && !strings.HasSuffix(u.Path, ".ts") && !strings.HasSuffix(u.Path, ".mp4") {
buffer.WriteString(line + "\n")
continue
}
Expand Down

0 comments on commit 0f3dfe4

Please sign in to comment.