You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lal/pkg/rtsp/server_sub_session.go

71 lines
1.7 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// Copyright 2020, Chef. All rights reserved.
// https://github.com/q191201771/lal
//
// Use of this source code is governed by a MIT-style license
// that can be found in the License file.
//
// Author: Chef (191201771@qq.com)
package rtsp
import (
"encoding/hex"
"net"
"time"
"github.com/q191201771/lal/pkg/base"
"github.com/q191201771/naza/pkg/nazalog"
"github.com/q191201771/naza/pkg/nazanet"
"github.com/q191201771/naza/pkg/unique"
)
// to be continued
// 注意音频和视频是不同的UDP连接
// pub和sub挂载转发时需要对应上
type SubSession struct {
UniqueKey string
StreamName string
rtpConn *nazanet.UDPConnection
rtcpConn *nazanet.UDPConnection
stat base.StatPub
}
func NewSubSession(streamName string) *SubSession {
uk := unique.GenUniqueKey("RTSPSUB")
ss := &SubSession{
UniqueKey: uk,
StreamName: streamName,
stat: base.StatPub{
StatSession: base.StatSession{
Protocol: base.ProtocolRTSP,
StartTime: time.Now().Format("2006-01-02 15:04:05.999"),
},
},
}
nazalog.Infof("[%s] lifecycle new rtsp PubSession. session=%p, streamName=%s", uk, ss, streamName)
return ss
}
func (s *SubSession) SetRTPConn(conn *nazanet.UDPConnection) {
s.rtpConn = conn
go s.rtpConn.RunLoop(s.onReadUDPPacket)
}
func (s *SubSession) SetRTCPConn(conn *nazanet.UDPConnection) {
s.rtcpConn = conn
go s.rtcpConn.RunLoop(s.onReadUDPPacket)
}
func (s *SubSession) onReadUDPPacket(b []byte, rAddr *net.UDPAddr, err error) bool {
nazalog.Debugf("SubSession::onReadUDPPacket. %s", hex.Dump(b))
return true
}
func (s *SubSession) WriteRawRTPPacket(b []byte) {
if err := s.rtpConn.Write(b); err != nil {
nazalog.Errorf("err=%+v", err)
}
}