From bf92496af00d0899371324b88e902c46debf203d Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sun, 4 Jul 2021 16:03:24 +0200 Subject: [PATCH] HLS: rename path into dir --- internal/hlsconverter/converter.go | 18 +++++++++--------- internal/hlsserver/server.go | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/internal/hlsconverter/converter.go b/internal/hlsconverter/converter.go index 5ae9a2bd..8785ff8e 100644 --- a/internal/hlsconverter/converter.go +++ b/internal/hlsconverter/converter.go @@ -104,11 +104,11 @@ func ipEqualOrInRange(ip net.IP, ips []interface{}) bool { // Request is an HTTP request received by an HLS server. type Request struct { - Path string - FileName string - Req *http.Request - W http.ResponseWriter - Res chan io.Reader + Dir string + File string + Req *http.Request + W http.ResponseWriter + Res chan io.Reader } type trackIDPayloadPair struct { @@ -592,7 +592,7 @@ func (c *Converter) runRequestHandler(terminate chan struct{}, done chan struct{ } switch { - case req.FileName == "stream.m3u8": + case req.File == "stream.m3u8": func() { c.tsMutex.RLock() defer c.tsMutex.RUnlock() @@ -633,8 +633,8 @@ func (c *Converter) runRequestHandler(terminate chan struct{}, done chan struct{ req.Res <- bytes.NewReader([]byte(cnt)) }() - case strings.HasSuffix(req.FileName, ".ts"): - base := strings.TrimSuffix(req.FileName, ".ts") + case strings.HasSuffix(req.File, ".ts"): + base := strings.TrimSuffix(req.File, ".ts") c.tsMutex.RLock() f, ok := c.tsByName[base] @@ -649,7 +649,7 @@ func (c *Converter) runRequestHandler(terminate chan struct{}, done chan struct{ req.W.Header().Set("Content-Type", `video/MP2T`) req.Res <- f.buf.NewReader() - case req.FileName == "": + case req.File == "": req.Res <- bytes.NewReader([]byte(index)) default: diff --git a/internal/hlsserver/server.go b/internal/hlsserver/server.go index 7797a2ee..3f29af0b 100644 --- a/internal/hlsserver/server.go +++ b/internal/hlsserver/server.go @@ -106,7 +106,7 @@ outer: for { select { case req := <-s.request: - c, ok := s.converters[req.Path] + c, ok := s.converters[req.Dir] if !ok { c = hlsconverter.New( s.ctx, @@ -115,10 +115,10 @@ outer: s.readBufferCount, &s.wg, s.stats, - req.Path, + req.Dir, s.pathMan, s) - s.converters[req.Path] = c + s.converters[req.Dir] = c } c.OnRequest(req) @@ -164,28 +164,28 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - pa, fname := func() (string, string) { + dir, fname := func() (string, string) { if strings.HasSuffix(pa, ".ts") || strings.HasSuffix(pa, ".m3u8") { return path.Dir(pa), path.Base(pa) } return pa, "" }() - if fname == "" && !strings.HasSuffix(pa, "/") { - w.Header().Add("Location", "/"+pa+"/") + if fname == "" && !strings.HasSuffix(dir, "/") { + w.Header().Add("Location", "/"+dir+"/") w.WriteHeader(http.StatusMovedPermanently) return } - pa = strings.TrimSuffix(pa, "/") + dir = strings.TrimSuffix(dir, "/") cres := make(chan io.Reader) hreq := hlsconverter.Request{ - Path: pa, - FileName: fname, - Req: r, - W: w, - Res: cres, + Dir: dir, + File: fname, + Req: r, + W: w, + Res: cres, } select {