mirror of
https://github.com/flavioribeiro/donut.git
synced 2026-04-22 16:17:03 +08:00
add setup and clean up for srt
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
astisrt "github.com/asticode/go-astisrt/pkg"
|
||||
"github.com/flavioribeiro/donut/internal/entities"
|
||||
"go.uber.org/fx"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -11,11 +14,41 @@ type SRTController struct {
|
||||
l *zap.Logger
|
||||
}
|
||||
|
||||
func NewSRTController(c *entities.Config, l *zap.Logger) *SRTController {
|
||||
func NewSRTController(c *entities.Config, l *zap.Logger, lc fx.Lifecycle) (*SRTController, error) {
|
||||
// Handle logs
|
||||
astisrt.SetLogLevel(astisrt.LogLevel(astisrt.LogLevelError))
|
||||
astisrt.SetLogHandler(func(ll astisrt.LogLevel, file, area, msg string, line int) {
|
||||
l.Sugar().Infow("SRT",
|
||||
"ll", ll,
|
||||
"msg", msg,
|
||||
)
|
||||
})
|
||||
|
||||
// Startup srt
|
||||
if err := astisrt.Startup(); err != nil {
|
||||
l.Sugar().Errorw("failed to start up srt",
|
||||
"error", err,
|
||||
)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lc.Append(fx.Hook{
|
||||
OnStop: func(ctx context.Context) error {
|
||||
// Clean up
|
||||
if err := astisrt.CleanUp(); err != nil {
|
||||
l.Sugar().Errorw("failed to clean up srt",
|
||||
"error", err,
|
||||
)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
return &SRTController{
|
||||
c: c,
|
||||
l: l,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *SRTController) Connect(params *entities.RequestParams) (*astisrt.Connection, error) {
|
||||
@@ -36,6 +69,8 @@ func (c *SRTController) Connect(params *entities.RequestParams) (*astisrt.Connec
|
||||
ConnectionOptions: []astisrt.ConnectionOption{
|
||||
astisrt.WithLatency(c.c.SRTConnectionLatencyMS),
|
||||
astisrt.WithStreamid(params.SRTStreamID),
|
||||
astisrt.WithCongestion("live"),
|
||||
astisrt.WithTranstype(astisrt.Transtype(astisrt.TranstypeLive)),
|
||||
},
|
||||
|
||||
OnDisconnect: func(conn *astisrt.Connection, err error) {
|
||||
@@ -48,7 +83,7 @@ func (c *SRTController) Connect(params *entities.RequestParams) (*astisrt.Connec
|
||||
Port: params.SRTPort,
|
||||
})
|
||||
if err != nil {
|
||||
c.l.Sugar().Infow("failed to connect srt",
|
||||
c.l.Sugar().Errorw("failed to connect srt",
|
||||
"error", err,
|
||||
)
|
||||
return nil, err
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
# ref https://github.com/Haivision/srt/blob/master/docs/apps/srt-live-transmit.md
|
||||
srt-live-transmit \
|
||||
"udp://${SRT_UDP_TS_INPUT_HOST}:${SRT_UDP_TS_INPUT_PORT}" \
|
||||
"srt://:${SRT_LISTENING_PORT}?congestion=live&transtype=live&groupconnect=1" -v
|
||||
"srt://:${SRT_LISTENING_PORT}?congestion=live&transtype=live" -v
|
||||
Reference in New Issue
Block a user