|
|
|
@ -26,10 +26,34 @@ import (
|
|
|
|
|
"github.com/q191201771/naza/pkg/bininfo"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 注意,使用这个demo时,请确保这三个文件存在,文件下载地址 https://github.com/q191201771/lalext/tree/master/avfile
|
|
|
|
|
const (
|
|
|
|
|
h264filename = "/tmp/test.h264"
|
|
|
|
|
aacfilename = "/tmp/test.aac"
|
|
|
|
|
flvfilename = "/tmp/test.flv"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 文档见 <lalserver二次开发 - pub接入自定义流>
|
|
|
|
|
// https://pengrl.com/lal/#/customize_pub
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// MySession 演示业务方实现 logic.ICustomizeHookSessionContext 接口,从而hook所有输入到lalserver中的流以及流中的数据。
|
|
|
|
|
type MySession struct {
|
|
|
|
|
uniqueKey string
|
|
|
|
|
streamName string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (i *MySession) OnMsg(msg base.RtmpMsg) {
|
|
|
|
|
// 业务方可以在这里对流做处理
|
|
|
|
|
if msg.IsAacSeqHeader() || msg.IsVideoKeySeqHeader() || msg.IsVideoKeyNalu() {
|
|
|
|
|
nazalog.Debugf("%s", msg.DebugString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (i *MySession) OnStop() {
|
|
|
|
|
nazalog.Debugf("OnStop")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
defer nazalog.Sync()
|
|
|
|
|
|
|
|
|
@ -38,7 +62,16 @@ func main() {
|
|
|
|
|
option.ConfFilename = confFilename
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 比常规lalserver多加了这一行
|
|
|
|
|
// 在常规lalserver基础上增加这行,用于演示hook lalserver中的流
|
|
|
|
|
lals.WithOnHookSession(func(uniqueKey string, streamName string) logic.ICustomizeHookSessionContext {
|
|
|
|
|
// 有新的流了,创建业务层的对象,用于hook这个流
|
|
|
|
|
return &MySession{
|
|
|
|
|
uniqueKey: uniqueKey,
|
|
|
|
|
streamName: streamName,
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 在常规lalserver基础上增加这两个例子,用于演示向lalserver输入自定义流
|
|
|
|
|
go showHowToCustomizePub(lals)
|
|
|
|
|
go showHowToFlvCustomizePub(lals)
|
|
|
|
|
|
|
|
|
@ -61,10 +94,7 @@ func parseFlag() string {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func showHowToFlvCustomizePub(lals logic.ILalServer) {
|
|
|
|
|
const (
|
|
|
|
|
flvfilename = "/tmp/test.flv"
|
|
|
|
|
customizePubStreamName = "f110"
|
|
|
|
|
)
|
|
|
|
|
const customizePubStreamName = "f110"
|
|
|
|
|
|
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
|
|
|
|
|
@ -90,12 +120,7 @@ func showHowToFlvCustomizePub(lals logic.ILalServer) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func showHowToCustomizePub(lals logic.ILalServer) {
|
|
|
|
|
const (
|
|
|
|
|
h264filename = "/tmp/test.h264"
|
|
|
|
|
aacfilename = "/tmp/test.aac"
|
|
|
|
|
|
|
|
|
|
customizePubStreamName = "c110"
|
|
|
|
|
)
|
|
|
|
|
const customizePubStreamName = "c110"
|
|
|
|
|
|
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
|
|
|
|
|
|