Use better name for variable

This commit is contained in:
Ingo Oppermann
2024-11-04 16:28:44 +01:00
parent 83ec412e05
commit 0d57a855f4
2 changed files with 10 additions and 7 deletions

View File

@@ -33,7 +33,10 @@ func (h *handler) handleHLSIngress(c echo.Context, _ string, data map[string]int
req := c.Request() req := c.Request()
path := req.URL.Path path := req.URL.Path
if strings.HasSuffix(path, ".m3u8") { isM3U8 := strings.HasSuffix(path, ".m3u8")
isSegment := strings.HasSuffix(path, ".ts") || strings.HasSuffix(path, ".mp4")
if isM3U8 {
// Read out the path of the .ts files and look them up in the ts-map. // Read out the path of the .ts files and look them up in the ts-map.
// Add it as ingress for the respective "sessionId". The "sessionId" is the .m3u8 file name. // Add it as ingress for the respective "sessionId". The "sessionId" is the .m3u8 file name.
reader := req.Body reader := req.Body
@@ -81,7 +84,7 @@ func (h *handler) handleHLSIngress(c echo.Context, _ string, data map[string]int
mem.Put(r.buffer) mem.Put(r.buffer)
}() }()
} else if strings.HasSuffix(path, ".ts") || strings.HasSuffix(path, ".mp4") { } else if isSegment {
// Get the size of the .ts file and store it in the ts-map for later use. // Get the size of the .ts file and store it in the ts-map for later use.
reader := req.Body reader := req.Body
r := &bodysizeReader{ r := &bodysizeReader{
@@ -117,7 +120,7 @@ func (h *handler) handleHLSEgress(c echo.Context, _ string, data map[string]inte
sessionID := c.QueryParam("session") sessionID := c.QueryParam("session")
isM3U8 := strings.HasSuffix(path, ".m3u8") isM3U8 := strings.HasSuffix(path, ".m3u8")
isTS := strings.HasSuffix(path, ".ts") || strings.HasSuffix(path, ".mp4") isSegment := strings.HasSuffix(path, ".ts") || strings.HasSuffix(path, ".mp4")
rewrite := false rewrite := false
@@ -213,7 +216,7 @@ func (h *handler) handleHLSEgress(c echo.Context, _ string, data map[string]inte
mem.Put(rewriter.buffer) mem.Put(rewriter.buffer)
} }
if isM3U8 || isTS { if isM3U8 || isSegment {
if res.Status >= 200 && res.Status < 300 { if res.Status >= 200 && res.Status < 300 {
// Collect how many bytes we've written in this session // Collect how many bytes we've written in this session
buffer := mem.Get() buffer := mem.Get()
@@ -221,7 +224,7 @@ func (h *handler) handleHLSEgress(c echo.Context, _ string, data map[string]inte
h.hlsEgressCollector.Egress(sessionID, res.Size) h.hlsEgressCollector.Egress(sessionID, res.Size)
mem.Put(buffer) mem.Put(buffer)
if isTS { if isSegment {
// Activate the session. If the session is already active, this is a noop // Activate the session. If the session is already active, this is a noop
h.hlsEgressCollector.Activate(sessionID) h.hlsEgressCollector.Activate(sessionID)
} }

View File

@@ -104,9 +104,9 @@ func NewWithConfig(config Config) echo.MiddlewareFunc {
data["ip"] = ip data["ip"] = ip
isM3U8 := strings.HasSuffix(path, ".m3u8") isM3U8 := strings.HasSuffix(path, ".m3u8")
isTS := strings.HasSuffix(path, ".ts") isSegment := strings.HasSuffix(path, ".ts") || strings.HasSuffix(path, ".mp4")
if isM3U8 || isTS { if isM3U8 || isSegment {
return h.handleHLS(c, ctxuser, data, next) return h.handleHLS(c, ctxuser, data, next)
} }