2021-08-23 10:26:06 +00:00
|
|
|
package hls
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/hex"
|
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/aler9/gortsplib"
|
|
|
|
)
|
|
|
|
|
2021-09-07 10:02:44 +00:00
|
|
|
type muxerPrimaryPlaylist struct {
|
2021-08-23 10:26:06 +00:00
|
|
|
videoTrack *gortsplib.Track
|
|
|
|
audioTrack *gortsplib.Track
|
2021-08-25 17:51:59 +00:00
|
|
|
h264Conf *gortsplib.TrackConfigH264
|
2021-08-23 10:26:06 +00:00
|
|
|
|
2021-09-06 17:40:24 +00:00
|
|
|
cnt []byte
|
2021-08-23 10:26:06 +00:00
|
|
|
}
|
|
|
|
|
2021-09-07 10:02:44 +00:00
|
|
|
func newMuxerPrimaryPlaylist(
|
2021-08-23 10:26:06 +00:00
|
|
|
videoTrack *gortsplib.Track,
|
|
|
|
audioTrack *gortsplib.Track,
|
2021-08-25 17:51:59 +00:00
|
|
|
h264Conf *gortsplib.TrackConfigH264,
|
2021-09-07 10:02:44 +00:00
|
|
|
) *muxerPrimaryPlaylist {
|
|
|
|
p := &muxerPrimaryPlaylist{
|
2021-08-23 10:26:06 +00:00
|
|
|
videoTrack: videoTrack,
|
|
|
|
audioTrack: audioTrack,
|
2021-08-25 17:51:59 +00:00
|
|
|
h264Conf: h264Conf,
|
2021-08-23 10:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var codecs []string
|
|
|
|
|
|
|
|
if p.videoTrack != nil {
|
2021-08-25 17:51:59 +00:00
|
|
|
codecs = append(codecs, "avc1."+hex.EncodeToString(p.h264Conf.SPS[1:4]))
|
2021-08-23 10:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if p.audioTrack != nil {
|
|
|
|
codecs = append(codecs, "mp4a.40.2")
|
|
|
|
}
|
|
|
|
|
2021-09-06 17:40:24 +00:00
|
|
|
p.cnt = []byte("#EXTM3U\n" +
|
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=200000,CODECS=\"" + strings.Join(codecs, ",") + "\"\n" +
|
|
|
|
"stream.m3u8\n")
|
2021-08-23 10:26:06 +00:00
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2021-09-07 10:02:44 +00:00
|
|
|
func (p *muxerPrimaryPlaylist) reader() io.Reader {
|
2021-09-06 17:40:24 +00:00
|
|
|
return bytes.NewReader(p.cnt)
|
2021-08-23 10:26:06 +00:00
|
|
|
}
|