Skip to content

Commit

Permalink
HLS: rename path into dir
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Jul 4, 2021
1 parent b48f65c commit bf92496
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
18 changes: 9 additions & 9 deletions internal/hlsconverter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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]
Expand All @@ -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:
Expand Down
24 changes: 12 additions & 12 deletions internal/hlsserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bf92496

Please sign in to comment.