Add pkt_size option fort RTSP server
This commit is contained in:
+8
-1
@@ -22,6 +22,7 @@ func Init() {
|
|||||||
Username string `yaml:"username" json:"-"`
|
Username string `yaml:"username" json:"-"`
|
||||||
Password string `yaml:"password" json:"-"`
|
Password string `yaml:"password" json:"-"`
|
||||||
DefaultQuery string `yaml:"default_query" json:"default_query"`
|
DefaultQuery string `yaml:"default_query" json:"default_query"`
|
||||||
|
PacketSize uint16 `yaml:"pkt_size"`
|
||||||
} `yaml:"rtsp"`
|
} `yaml:"rtsp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +68,7 @@ func Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c := rtsp.NewServer(conn)
|
c := rtsp.NewServer(conn)
|
||||||
|
c.PacketSize = conf.Mod.PacketSize
|
||||||
// skip check auth for localhost
|
// skip check auth for localhost
|
||||||
if conf.Mod.Username != "" && !conn.RemoteAddr().(*net.TCPAddr).IP.IsLoopback() {
|
if conf.Mod.Username != "" && !conn.RemoteAddr().(*net.TCPAddr).IP.IsLoopback() {
|
||||||
c.Auth(conf.Mod.Username, conf.Mod.Password)
|
c.Auth(conf.Mod.Username, conf.Mod.Password)
|
||||||
@@ -174,13 +176,18 @@ func tcpHandler(conn *rtsp.Conn) {
|
|||||||
|
|
||||||
conn.SessionName = app.UserAgent
|
conn.SessionName = app.UserAgent
|
||||||
|
|
||||||
conn.Medias = mp4.ParseQuery(conn.URL.Query())
|
query := conn.URL.Query()
|
||||||
|
conn.Medias = mp4.ParseQuery(query)
|
||||||
if conn.Medias == nil {
|
if conn.Medias == nil {
|
||||||
for _, media := range defaultMedias {
|
for _, media := range defaultMedias {
|
||||||
conn.Medias = append(conn.Medias, media.Clone())
|
conn.Medias = append(conn.Medias, media.Clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s := query.Get("pkt_size"); s != "" {
|
||||||
|
conn.PacketSize = uint16(core.Atoi(s))
|
||||||
|
}
|
||||||
|
|
||||||
if err := stream.AddConsumer(conn); err != nil {
|
if err := stream.AddConsumer(conn); err != nil {
|
||||||
log.Warn().Err(err).Str("stream", name).Msg("[rtsp]")
|
log.Warn().Err(err).Str("stream", name).Msg("[rtsp]")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -94,6 +94,10 @@ func RTPDepay(codec *core.Codec, handler core.HandlerFunc) core.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RTPPay(mtu uint16, handler core.HandlerFunc) core.HandlerFunc {
|
func RTPPay(mtu uint16, handler core.HandlerFunc) core.HandlerFunc {
|
||||||
|
if mtu == 0 {
|
||||||
|
mtu = 1472
|
||||||
|
}
|
||||||
|
|
||||||
payloader := &Payloader{IsAVC: true}
|
payloader := &Payloader{IsAVC: true}
|
||||||
sequencer := rtp.NewRandomSequencer()
|
sequencer := rtp.NewRandomSequencer()
|
||||||
mtu -= 12 // rtp.Header size
|
mtu -= 12 // rtp.Header size
|
||||||
|
|||||||
@@ -76,6 +76,10 @@ func RTPDepay(codec *core.Codec, handler core.HandlerFunc) core.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RTPPay(mtu uint16, handler core.HandlerFunc) core.HandlerFunc {
|
func RTPPay(mtu uint16, handler core.HandlerFunc) core.HandlerFunc {
|
||||||
|
if mtu == 0 {
|
||||||
|
mtu = 1472
|
||||||
|
}
|
||||||
|
|
||||||
payloader := &Payloader{}
|
payloader := &Payloader{}
|
||||||
sequencer := rtp.NewRandomSequencer()
|
sequencer := rtp.NewRandomSequencer()
|
||||||
mtu -= 12 // rtp.Header size
|
mtu -= 12 // rtp.Header size
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ type Conn struct {
|
|||||||
// public
|
// public
|
||||||
|
|
||||||
Backchannel bool
|
Backchannel bool
|
||||||
|
PacketSize uint16
|
||||||
SessionName string
|
SessionName string
|
||||||
|
|
||||||
Medias []*core.Media
|
Medias []*core.Media
|
||||||
|
|||||||
+11
-2
@@ -104,14 +104,23 @@ func (c *Conn) packetWriter(codec *core.Codec, channel, payloadType uint8) core.
|
|||||||
if !codec.IsRTP() {
|
if !codec.IsRTP() {
|
||||||
switch codec.Name {
|
switch codec.Name {
|
||||||
case core.CodecH264:
|
case core.CodecH264:
|
||||||
handlerFunc = h264.RTPPay(1500, handlerFunc)
|
handlerFunc = h264.RTPPay(c.PacketSize, handlerFunc)
|
||||||
case core.CodecH265:
|
case core.CodecH265:
|
||||||
handlerFunc = h265.RTPPay(1500, handlerFunc)
|
handlerFunc = h265.RTPPay(c.PacketSize, handlerFunc)
|
||||||
case core.CodecAAC:
|
case core.CodecAAC:
|
||||||
handlerFunc = aac.RTPPay(handlerFunc)
|
handlerFunc = aac.RTPPay(handlerFunc)
|
||||||
case core.CodecJPEG:
|
case core.CodecJPEG:
|
||||||
handlerFunc = mjpeg.RTPPay(handlerFunc)
|
handlerFunc = mjpeg.RTPPay(handlerFunc)
|
||||||
}
|
}
|
||||||
|
} else if c.PacketSize != 0 {
|
||||||
|
switch codec.Name {
|
||||||
|
case core.CodecH264:
|
||||||
|
handlerFunc = h264.RTPPay(c.PacketSize, handlerFunc)
|
||||||
|
handlerFunc = h264.RTPDepay(codec, handlerFunc)
|
||||||
|
case core.CodecH265:
|
||||||
|
handlerFunc = h265.RTPPay(c.PacketSize, handlerFunc)
|
||||||
|
handlerFunc = h265.RTPDepay(codec, handlerFunc)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return handlerFunc
|
return handlerFunc
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ReceiveMTU = Ethernet MTU (1500) - IP Header (20) - UDP Header (8)
|
// ReceiveMTU = Ethernet MTU (1500) - IP Header (20) - UDP Header (8)
|
||||||
|
// https://ffmpeg.org/ffmpeg-all.html#Muxer
|
||||||
const ReceiveMTU = 1472
|
const ReceiveMTU = 1472
|
||||||
|
|
||||||
func NewAPI(address string) (*webrtc.API, error) {
|
func NewAPI(address string) (*webrtc.API, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user