Documentation ¶
Index ¶
- Constants
- Variables
- func CalcM3u8Duration(content []byte) (durationSec float64, err error)
- func GetAppNameFromUrlCtx(urlCtx base.UrlContext, hlsUrlPattern string) string
- func GetStreamNameFromUrlCtx(urlCtx base.UrlContext) string
- func ReadFile(filename string) ([]byte, error)
- func RemoveAll(path string) error
- func SetUseMemoryAsDiskFlag(flag bool)
- func SplitFragment2TsPackets(content []byte) (ret [][]byte, err error)
- type DefaultPathStrategy
- func (*DefaultPathStrategy) GetLiveM3u8FileName(outPath string, streamName string) string
- func (*DefaultPathStrategy) GetMuxerOutPath(rootOutPath string, streamName string) string
- func (*DefaultPathStrategy) GetRecordM3u8FileName(outPath string, streamName string) string
- func (dps *DefaultPathStrategy) GetRequestInfo(urlCtx base.UrlContext, rootOutPath string) (ri RequestInfo)
- func (*DefaultPathStrategy) GetTsFileName(streamName string, index int, timestamp int) string
- func (*DefaultPathStrategy) GetTsFileNameWithPath(outPath string, fileName string) string
- type Fragment
- type IHlsServerHandlerObserver
- type IMuxerObserver
- type IPathRequestStrategy
- type IPathStrategy
- type IPathWriteStrategy
- type Muxer
- func (m *Muxer) Dispose()
- func (m *Muxer) FeedMpegts(tsPackets []byte, frame *mpegts.Frame, boundary bool)
- func (m *Muxer) FeedPatPmt(b []byte)
- func (m *Muxer) OnPatPmt(b []byte)
- func (m *Muxer) OnTsPackets(tsPackets []byte, frame *mpegts.Frame, boundary bool)
- func (m *Muxer) OutPath() string
- func (m *Muxer) Start()
- type MuxerConfig
- type RequestInfo
- type ServerHandler
- type SubSession
- func (s *SubSession) AddWroteBytesSum(wbs uint64)
- func (s *SubSession) AppName() string
- func (s *SubSession) GetStat() base.StatSession
- func (s *SubSession) IsAlive() (readAlive, writeAlive bool)
- func (s *SubSession) IsExpired() bool
- func (s *SubSession) KeepAlive()
- func (s *SubSession) RawQuery() string
- func (s *SubSession) StreamName() string
- func (s *SubSession) UniqueKey() string
- func (s *SubSession) UpdateStat(intervalSec uint32)
- func (s *SubSession) Url() string
Constants ¶
const ( CleanupModeNever = 0 CleanupModeInTheEnd = 1 CleanupModeAsap = 2 )
Variables ¶
var ( PathStrategy IPathStrategy = &DefaultPathStrategy{} Clock = mock.NewStdClock() Log = nazalog.GetGlobalLogger() )
Functions ¶
func CalcM3u8Duration ¶ added in v0.23.0
CalcM3u8Duration
@param content 传入m3u8文件内容
@return durationSec m3u8中所有ts的时间总和。注意,使用的是m3u8文件中描述的ts时间,而不是读取ts文件中实际音视频数据的时间。
func GetAppNameFromUrlCtx ¶ added in v0.33.0
func GetAppNameFromUrlCtx(urlCtx base.UrlContext, hlsUrlPattern string) string
func GetStreamNameFromUrlCtx ¶ added in v0.33.0
func GetStreamNameFromUrlCtx(urlCtx base.UrlContext) string
func SetUseMemoryAsDiskFlag ¶ added in v0.22.0
func SetUseMemoryAsDiskFlag(flag bool)
func SplitFragment2TsPackets ¶ added in v0.23.0
Types ¶
type DefaultPathStrategy ¶ added in v0.23.0
type DefaultPathStrategy struct { }
DefaultPathStrategy 默认的路由,落盘策略
每个流在<rootPath>下以流名称生成一个子目录,目录下包含:
- playlist.m3u8 实时的HLS文件,定期刷新,写入当前最新的TS文件列表,淘汰过期的TS文件列表 - record.m3u8 录制回放的HLS文件,包含了从流开始至今的所有TS文件 - test110-1620540712084-0.ts TS分片文件,命名格式为{liveid}-{timestamp}-{index}.ts - test110-1620540716095-1.ts - ... 一系列的TS文件
假设 流名称="test110" rootPath="/tmp/lal/hls/"
则 http://127.0.0.1:8080/hls/test110/playlist.m3u8 -> /tmp/lal/hls/test110/playlist.m3u8 http://127.0.0.1:8080/hls/test110/record.m3u8 -> /tmp/lal/hls/test110/record.m3u8 http://127.0.0.1:8080/hls/test110/test110-1620540712084-0.ts -> /tmp/lal/hls/test110/test110-1620540712084-0.ts
http://127.0.0.1:8080/hls/test110.m3u8 -> /tmp/lal/hls/test110/playlist.m3u8 http://127.0.0.1:8080/hls/test110-1620540712084-0.ts -> /tmp/lal/hls/test110/test110-1620540712084-0.ts 最下面这两个做了特殊映射
func (*DefaultPathStrategy) GetLiveM3u8FileName ¶ added in v0.23.0
func (*DefaultPathStrategy) GetLiveM3u8FileName(outPath string, streamName string) string
func (*DefaultPathStrategy) GetMuxerOutPath ¶ added in v0.23.0
func (*DefaultPathStrategy) GetMuxerOutPath(rootOutPath string, streamName string) string
GetMuxerOutPath <rootOutPath>/<streamName>
func (*DefaultPathStrategy) GetRecordM3u8FileName ¶ added in v0.23.0
func (*DefaultPathStrategy) GetRecordM3u8FileName(outPath string, streamName string) string
func (*DefaultPathStrategy) GetRequestInfo ¶ added in v0.23.0
func (dps *DefaultPathStrategy) GetRequestInfo(urlCtx base.UrlContext, rootOutPath string) (ri RequestInfo)
GetRequestInfo
RequestURI example: uri -> FileName StreamName FileType FileNameWithPath /hls/test110.m3u8 -> test110.m3u8 test110 m3u8 {rootOutPath}/test110/playlist.m3u8 /hls/test110/playlist.m3u8 -> playlist.m3u8 test110 m3u8 {rootOutPath}/test110/playlist.m3u8 /hls/test110/record.m3u8 -> record.m3u8 test110 m3u8 {rootOutPath}/test110/record.m3u8 /hls/test110/test110-1620540712084-.ts -> test110-1620540712084-.ts test110 ts {rootOutPath/test110/test110-1620540712084-.ts /hls/test110-1620540712084-.ts -> test110-1620540712084-.ts test110 ts {rootOutPath/test110/test110-1620540712084-.ts
func (*DefaultPathStrategy) GetTsFileName ¶ added in v0.23.0
func (*DefaultPathStrategy) GetTsFileName(streamName string, index int, timestamp int) string
func (*DefaultPathStrategy) GetTsFileNameWithPath ¶ added in v0.23.0
func (*DefaultPathStrategy) GetTsFileNameWithPath(outPath string, fileName string) string
type Fragment ¶ added in v0.14.0
type Fragment struct {
// contains filtered or unexported fields
}
type IHlsServerHandlerObserver ¶ added in v0.33.0
type IHlsServerHandlerObserver interface { OnNewHlsSubSession(session *SubSession) error OnDelHlsSubSession(session *SubSession) }
type IMuxerObserver ¶ added in v0.28.0
type IMuxerObserver interface { OnHlsMakeTs(info base.HlsMakeTsInfo) // OnFragmentOpen // // 内部决定开启新的fragment切片,将该事件通知给上层 // // TODO(chef): [refactor] 考虑用OnHlsMakeTs替代OnFragmentOpen 202206 // OnFragmentOpen() }
type IPathRequestStrategy ¶ added in v0.23.0
type IPathRequestStrategy interface { // GetRequestInfo // // 解析HTTP请求,得到流名称、文件所在路径 // GetRequestInfo(urlCtx base.UrlContext, rootOutPath string) RequestInfo }
IPathRequestStrategy
路由策略 接到HTTP请求时,对应文件路径的映射逻辑
type IPathStrategy ¶ added in v0.23.0
type IPathStrategy interface { IPathRequestStrategy IPathWriteStrategy }
type IPathWriteStrategy ¶ added in v0.23.0
type IPathWriteStrategy interface { // GetMuxerOutPath 获取单个流对应的文件根路径 GetMuxerOutPath(rootOutPath string, streamName string) string // GetLiveM3u8FileName 获取单个流对应的m3u8文件路径 // // @param outPath: func GetMuxerOutPath的结果 GetLiveM3u8FileName(outPath string, streamName string) string // GetRecordM3u8FileName 获取单个流对应的record类型的m3u8文件路径 // // live m3u8和record m3u8的区别: // live记录的是当前最近的可播放内容,record记录的是从流开始时的可播放内容 // // @param outPath: func GetMuxerOutPath的结果 GetRecordM3u8FileName(outPath string, streamName string) string // GetTsFileNameWithPath 获取单个流对应的ts文件路径 // // @param outPath: func GetMuxerOutPath的结果 GetTsFileNameWithPath(outPath string, fileName string) string // GetTsFileName ts文件名的生成策略 GetTsFileName(streamName string, index int, timestamp int) string }
IPathWriteStrategy 落盘策略
type Muxer ¶
type Muxer struct { UniqueKey string // contains filtered or unexported fields }
Muxer
输入mpegts流,输出hls(m3u8+ts)至文件中
func NewMuxer ¶
func NewMuxer(streamName string, config *MuxerConfig, observer IMuxerObserver) *Muxer
NewMuxer
@param observer 可以为nil,如果不为nil,TS流将回调给上层
func (*Muxer) FeedMpegts ¶ added in v0.28.0
func (*Muxer) FeedPatPmt ¶ added in v0.28.0
func (*Muxer) OnPatPmt ¶ added in v0.23.0
OnPatPmt OnTsPackets
实现 remux.IRtmp2MpegtsRemuxerObserver,方便直接将 remux.Rtmp2MpegtsRemuxer 的数据喂入 hls.Muxer
func (*Muxer) OnTsPackets ¶ added in v0.28.0
type MuxerConfig ¶
type MuxerConfig struct { OutPath string `json:"out_path"` FragmentDurationMs int `json:"fragment_duration_ms"` FragmentNum int `json:"fragment_num"` DeleteThreshold int `json:"delete_threshold"` CleanupMode int `json:"cleanup_mode"` // TODO chef: lalserver的模式1的逻辑是在上层做的,应该重构到hls模块中 }
MuxerConfig
各字段含义见文档: https://pengrl.com/lal/#/ConfigBrief
type RequestInfo ¶ added in v0.23.0
type ServerHandler ¶ added in v0.23.0
type ServerHandler struct {
// contains filtered or unexported fields
}
func NewServerHandler ¶ added in v0.23.0
func NewServerHandler(outPath, urlPattern, subSessionHashKey string, subSessionTimeoutMs int, observer IHlsServerHandlerObserver) *ServerHandler
func (*ServerHandler) ServeHTTP ¶ added in v0.23.0
func (s *ServerHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request)
func (*ServerHandler) ServeHTTPWithUrlCtx ¶ added in v0.27.0
func (s *ServerHandler) ServeHTTPWithUrlCtx(resp http.ResponseWriter, req *http.Request, urlCtx base.UrlContext)
type SubSession ¶ added in v0.33.0
func NewSubSession ¶ added in v0.33.0
func NewSubSession(req *http.Request, urlCtx base.UrlContext, hlsUrlPattern, sessionHashKey string, timeout time.Duration) *SubSession
func (*SubSession) AddWroteBytesSum ¶ added in v0.33.0
func (s *SubSession) AddWroteBytesSum(wbs uint64)
func (*SubSession) AppName ¶ added in v0.33.0
func (s *SubSession) AppName() string
func (*SubSession) GetStat ¶ added in v0.33.0
func (s *SubSession) GetStat() base.StatSession
func (*SubSession) IsAlive ¶ added in v0.33.0
func (s *SubSession) IsAlive() (readAlive, writeAlive bool)
func (*SubSession) IsExpired ¶ added in v0.33.0
func (s *SubSession) IsExpired() bool
func (*SubSession) KeepAlive ¶ added in v0.33.0
func (s *SubSession) KeepAlive()
func (*SubSession) RawQuery ¶ added in v0.33.0
func (s *SubSession) RawQuery() string
func (*SubSession) StreamName ¶ added in v0.33.0
func (s *SubSession) StreamName() string
func (*SubSession) UniqueKey ¶ added in v0.33.0
func (s *SubSession) UniqueKey() string
func (*SubSession) UpdateStat ¶ added in v0.33.0
func (s *SubSession) UpdateStat(intervalSec uint32)
func (*SubSession) Url ¶ added in v0.33.0
func (s *SubSession) Url() string