Add example flv file of CustomPubSession

pull/244/head
Jae-Sung Lee 2 years ago
parent 6951a904d4
commit 0ed0d75a2b

@ -11,13 +11,16 @@ package main
import (
"flag"
"fmt"
"github.com/q191201771/lal/pkg/aac"
"github.com/q191201771/lal/pkg/avc"
"github.com/q191201771/naza/pkg/nazalog"
"io/ioutil"
"os"
"time"
"github.com/q191201771/lal/pkg/aac"
"github.com/q191201771/lal/pkg/avc"
"github.com/q191201771/lal/pkg/httpflv"
"github.com/q191201771/lal/pkg/remux"
"github.com/q191201771/naza/pkg/nazalog"
"github.com/q191201771/lal/pkg/base"
"github.com/q191201771/lal/pkg/logic"
@ -38,6 +41,7 @@ func main() {
// 比常规lalserver多加了这一行
go showHowToCustomizePub(lals)
go showHowToFlvCustomizePub(lals)
err := lals.RunLoop()
nazalog.Infof("server manager done. err=%+v", err)
@ -57,6 +61,35 @@ func parseFlag() string {
return *cf
}
func showHowToFlvCustomizePub(lals logic.ILalServer) {
const (
flvfilename = "/tmp/test.flv"
customizePubStreamName = "f110"
)
time.Sleep(200 * time.Millisecond)
tags, err := httpflv.ReadAllTagsFromFlvFile(flvfilename)
nazalog.Assert(nil, err)
session, err := lals.AddCustomizePubSession(customizePubStreamName)
nazalog.Assert(nil, err)
startRealTime := time.Now()
startTs := int64(0)
for _, tag := range tags {
msg := remux.FlvTag2RtmpMsg(tag)
diffTs := int64(msg.Header.TimestampAbs) - startTs
diffReal := time.Since(startRealTime).Milliseconds()
if diffReal < diffTs {
time.Sleep(time.Duration(diffTs-diffReal) * time.Millisecond)
}
session.FeedRtmpMsg(msg)
}
lals.DelCustomizePubSession(session)
}
func showHowToCustomizePub(lals logic.ILalServer) {
const (
h264filename = "/tmp/test.h264"

@ -36,6 +36,7 @@ func NewCustomizePubSessionContext(streamName string) *CustomizePubSessionContex
}
func (ctx *CustomizePubSessionContext) WithOnRtmpMsg(onRtmpMsg func(msg base.RtmpMsg)) *CustomizePubSessionContext {
ctx.onRtmpMsg = onRtmpMsg
ctx.remuxer.WithOnRtmpMsg(onRtmpMsg)
return ctx
}
@ -76,3 +77,11 @@ func (ctx *CustomizePubSessionContext) FeedAvPacket(packet base.AvPacket) error
ctx.remuxer.FeedAvPacket(packet)
return nil
}
func (ctx *CustomizePubSessionContext) FeedRtmpMsg(msg base.RtmpMsg) error {
if ctx.disposeFlag.Load() {
return base.ErrDisposedInStream
}
ctx.onRtmpMsg(msg)
return nil
}

@ -9,8 +9,9 @@
package logic
import (
"github.com/q191201771/lal/pkg/base"
"path/filepath"
"github.com/q191201771/lal/pkg/base"
)
// ---------------------------------------------------------------------------------------------------------------------
@ -60,6 +61,8 @@ type ICustomizePubSessionContext interface {
//
base.IAvPacketStream
FeedRtmpMsg(msg base.RtmpMsg) error
UniqueKey() string
StreamName() string
}

Loading…
Cancel
Save