Browse Source

hls: fix error that caused primary playlist not to be served to more than 1 client

pull/591/head
aler9 4 years ago
parent
commit
2710189945
  1. 12
      internal/hls/primaryplaylist.go
  2. 13
      internal/hls/streamplaylist.go

12
internal/hls/primaryplaylist.go

@ -14,7 +14,7 @@ type primaryPlaylist struct { @@ -14,7 +14,7 @@ type primaryPlaylist struct {
audioTrack *gortsplib.Track
h264Conf *gortsplib.TrackConfigH264
breader *bytes.Reader
cnt []byte
}
func newPrimaryPlaylist(
@ -38,15 +38,13 @@ func newPrimaryPlaylist( @@ -38,15 +38,13 @@ func newPrimaryPlaylist(
codecs = append(codecs, "mp4a.40.2")
}
cnt := "#EXTM3U\n"
cnt += "#EXT-X-STREAM-INF:BANDWIDTH=200000,CODECS=\"" + strings.Join(codecs, ",") + "\"\n"
cnt += "stream.m3u8\n"
p.breader = bytes.NewReader([]byte(cnt))
p.cnt = []byte("#EXTM3U\n" +
"#EXT-X-STREAM-INF:BANDWIDTH=200000,CODECS=\"" + strings.Join(codecs, ",") + "\"\n" +
"stream.m3u8\n")
return p
}
func (p *primaryPlaylist) reader() io.Reader {
return p.breader
return bytes.NewReader(p.cnt)
}

13
internal/hls/streamplaylist.go

@ -9,15 +9,14 @@ import ( @@ -9,15 +9,14 @@ import (
"sync"
)
type readerFunc struct {
wrapped func() []byte
reader *bytes.Reader
type asyncReader struct {
generator func() []byte
reader *bytes.Reader
}
func (r *readerFunc) Read(buf []byte) (int, error) {
func (r *asyncReader) Read(buf []byte) (int, error) {
if r.reader == nil {
cnt := r.wrapped()
r.reader = bytes.NewReader(cnt)
r.reader = bytes.NewReader(r.generator())
}
return r.reader.Read(buf)
}
@ -53,7 +52,7 @@ func (p *streamPlaylist) close() { @@ -53,7 +52,7 @@ func (p *streamPlaylist) close() {
}
func (p *streamPlaylist) reader() io.Reader {
return &readerFunc{wrapped: func() []byte {
return &asyncReader{generator: func() []byte {
p.mutex.Lock()
defer p.mutex.Unlock()

Loading…
Cancel
Save