mirror of
https://github.com/aler9/gortsplib
synced 2025-09-27 03:25:52 +08:00
rename Transport* into Protocol* (#895)
This commit is contained in:
46
client.go
46
client.go
@@ -446,10 +446,10 @@ type Client struct {
|
||||
// timeout of write operations.
|
||||
// It defaults to 10 seconds.
|
||||
WriteTimeout time.Duration
|
||||
// a TLS configuration to connect to TLS (RTSPS) servers.
|
||||
// a TLS configuration to connect to TLS/RTSPS servers.
|
||||
// It defaults to nil.
|
||||
TLSConfig *tls.Config
|
||||
// tunnel.
|
||||
// tunneling method.
|
||||
Tunnel Tunnel
|
||||
// transport protocol (UDP, Multicast or TCP).
|
||||
// If nil, it is chosen automatically (first UDP, then, if it fails, TCP).
|
||||
@@ -985,7 +985,7 @@ func (c *Client) trySwitchingProtocol() error {
|
||||
c.reset()
|
||||
|
||||
c.setuppedTransport = &SessionTransport{
|
||||
Protocol: TransportTCP,
|
||||
Protocol: ProtocolTCP,
|
||||
}
|
||||
|
||||
// some Hikvision cameras require a describe before a setup
|
||||
@@ -1022,23 +1022,23 @@ func (c *Client) startTransportRoutines() {
|
||||
cm.start()
|
||||
}
|
||||
|
||||
if c.setuppedTransport.Protocol == TransportTCP {
|
||||
if c.setuppedTransport.Protocol == ProtocolTCP {
|
||||
c.tcpFrame = &base.InterleavedFrame{}
|
||||
c.tcpBuffer = make([]byte, c.MaxPacketSize+4)
|
||||
}
|
||||
|
||||
// always enable keepalives unless we are recording with TCP
|
||||
if c.state == clientStatePlay || c.setuppedTransport.Protocol != TransportTCP {
|
||||
if c.state == clientStatePlay || c.setuppedTransport.Protocol != ProtocolTCP {
|
||||
c.keepAliveTimer = time.NewTimer(c.keepAlivePeriod)
|
||||
}
|
||||
|
||||
if c.state == clientStatePlay && c.stdChannelSetupped {
|
||||
switch c.setuppedTransport.Protocol {
|
||||
case TransportUDP:
|
||||
case ProtocolUDP:
|
||||
c.checkTimeoutTimer = time.NewTimer(c.InitialUDPReadTimeout)
|
||||
c.checkTimeoutInitial = true
|
||||
|
||||
case TransportUDPMulticast:
|
||||
case ProtocolUDPMulticast:
|
||||
c.checkTimeoutTimer = time.NewTimer(c.checkTimeoutPeriod)
|
||||
|
||||
default: // TCP
|
||||
@@ -1048,7 +1048,7 @@ func (c *Client) startTransportRoutines() {
|
||||
}
|
||||
}
|
||||
|
||||
if c.setuppedTransport.Protocol == TransportTCP {
|
||||
if c.setuppedTransport.Protocol == ProtocolTCP {
|
||||
c.reader.setAllowInterleavedFrames(true)
|
||||
}
|
||||
}
|
||||
@@ -1284,8 +1284,8 @@ func (c *Client) isInTCPTimeout() bool {
|
||||
}
|
||||
|
||||
func (c *Client) doCheckTimeout() error {
|
||||
if c.setuppedTransport.Protocol == TransportUDP ||
|
||||
c.setuppedTransport.Protocol == TransportUDPMulticast {
|
||||
if c.setuppedTransport.Protocol == ProtocolUDP ||
|
||||
c.setuppedTransport.Protocol == ProtocolUDPMulticast {
|
||||
if c.checkTimeoutInitial && !c.backChannelSetupped && c.Protocol == nil {
|
||||
c.checkTimeoutInitial = false
|
||||
|
||||
@@ -1491,7 +1491,7 @@ func (c *Client) doAnnounce(u *base.URL, desc *description.Session) (*base.Respo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if c.Protocol != nil && *c.Protocol == TransportUDPMulticast {
|
||||
if c.Protocol != nil && *c.Protocol == ProtocolUDPMulticast {
|
||||
return nil, fmt.Errorf("recording with UDP multicast is not supported")
|
||||
}
|
||||
|
||||
@@ -1613,9 +1613,9 @@ func (c *Client) doSetup(
|
||||
}
|
||||
|
||||
if c.Tunnel == TunnelNone && (th.Profile == headers.TransportProfileSAVP || c.Scheme == "rtsp") {
|
||||
protocol = TransportUDP
|
||||
protocol = ProtocolUDP
|
||||
} else {
|
||||
protocol = TransportTCP
|
||||
protocol = ProtocolTCP
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1652,14 +1652,14 @@ func (c *Client) doSetup(
|
||||
}()
|
||||
|
||||
switch protocol {
|
||||
case TransportUDP, TransportUDPMulticast:
|
||||
case ProtocolUDP, ProtocolUDPMulticast:
|
||||
if c.Scheme == "rtsps" && !isSecure(th.Profile) {
|
||||
return nil, fmt.Errorf("unable to setup secure UDP")
|
||||
}
|
||||
|
||||
th.Protocol = headers.TransportProtocolUDP
|
||||
|
||||
if protocol == TransportUDP {
|
||||
if protocol == ProtocolUDP {
|
||||
if (rtpPort == 0 && rtcpPort != 0) ||
|
||||
(rtpPort != 0 && rtcpPort == 0) {
|
||||
return nil, liberrors.ErrClientUDPPortsZero{}
|
||||
@@ -1688,7 +1688,7 @@ func (c *Client) doSetup(
|
||||
th.Delivery = &v1
|
||||
}
|
||||
|
||||
case TransportTCP:
|
||||
case ProtocolTCP:
|
||||
v1 := headers.TransportDeliveryUnicast
|
||||
th.Delivery = &v1
|
||||
th.Protocol = headers.TransportProtocolTCP
|
||||
@@ -1768,7 +1768,7 @@ func (c *Client) doSetup(
|
||||
c.setuppedTransport == nil && c.Protocol == nil {
|
||||
c.OnTransportSwitch(liberrors.ErrClientSwitchToTCP2{})
|
||||
c.setuppedTransport = &SessionTransport{
|
||||
Protocol: TransportTCP,
|
||||
Protocol: ProtocolTCP,
|
||||
Profile: th.Profile,
|
||||
}
|
||||
|
||||
@@ -1785,7 +1785,7 @@ func (c *Client) doSetup(
|
||||
}
|
||||
|
||||
switch protocol {
|
||||
case TransportUDP, TransportUDPMulticast:
|
||||
case ProtocolUDP, ProtocolUDPMulticast:
|
||||
if thRes.Protocol == headers.TransportProtocolTCP {
|
||||
// switch transport automatically
|
||||
if c.setuppedTransport == nil && c.Protocol == nil {
|
||||
@@ -1796,7 +1796,7 @@ func (c *Client) doSetup(
|
||||
c.reset()
|
||||
|
||||
c.setuppedTransport = &SessionTransport{
|
||||
Protocol: TransportTCP,
|
||||
Protocol: ProtocolTCP,
|
||||
Profile: th.Profile,
|
||||
}
|
||||
|
||||
@@ -1814,7 +1814,7 @@ func (c *Client) doSetup(
|
||||
}
|
||||
|
||||
switch protocol {
|
||||
case TransportUDP:
|
||||
case ProtocolUDP:
|
||||
if thRes.Delivery != nil && *thRes.Delivery != headers.TransportDeliveryUnicast {
|
||||
return nil, liberrors.ErrClientTransportHeaderInvalidDelivery{}
|
||||
}
|
||||
@@ -1865,7 +1865,7 @@ func (c *Client) doSetup(
|
||||
}
|
||||
udpRTCPListener.readIP = remoteIP
|
||||
|
||||
case TransportUDPMulticast:
|
||||
case ProtocolUDPMulticast:
|
||||
if thRes.Delivery == nil || *thRes.Delivery != headers.TransportDeliveryMulticast {
|
||||
return nil, liberrors.ErrClientTransportHeaderInvalidDelivery{}
|
||||
}
|
||||
@@ -1936,7 +1936,7 @@ func (c *Client) doSetup(
|
||||
Port: thRes.Ports[1],
|
||||
}
|
||||
|
||||
case TransportTCP:
|
||||
case ProtocolTCP:
|
||||
if thRes.Protocol != headers.TransportProtocolTCP {
|
||||
return nil, liberrors.ErrClientServerRequestedUDP{}
|
||||
}
|
||||
@@ -2128,7 +2128,7 @@ func (c *Client) doPlay(ra *headers.Range) (*base.Response, error) {
|
||||
// when protocol is UDP,
|
||||
// open the firewall by sending empty packets to the remote part.
|
||||
// do this before sending the PLAY request.
|
||||
if c.setuppedTransport.Protocol == TransportUDP {
|
||||
if c.setuppedTransport.Protocol == ProtocolUDP {
|
||||
for _, cm := range c.setuppedMedias {
|
||||
if !cm.media.IsBackChannel && cm.udpRTPListener.writeAddr != nil {
|
||||
buf, _ := (&rtp.Packet{Header: rtp.Header{Version: 2}}).Marshal()
|
||||
|
@@ -610,15 +610,15 @@ func TestClientPlay(t *testing.T) {
|
||||
Protocol: func() *Protocol {
|
||||
switch ca.transport {
|
||||
case "udp":
|
||||
v := TransportUDP
|
||||
v := ProtocolUDP
|
||||
return &v
|
||||
|
||||
case "multicast":
|
||||
v := TransportUDPMulticast
|
||||
v := ProtocolUDPMulticast
|
||||
return &v
|
||||
|
||||
default: // tcp
|
||||
v := TransportTCP
|
||||
v := ProtocolTCP
|
||||
return &v
|
||||
}
|
||||
}(),
|
||||
@@ -1041,7 +1041,7 @@ func TestClientPlayPartial(t *testing.T) {
|
||||
c := Client{
|
||||
Scheme: u.Scheme,
|
||||
Host: u.Host,
|
||||
Protocol: ptrOf(TransportTCP),
|
||||
Protocol: ptrOf(ProtocolTCP),
|
||||
}
|
||||
|
||||
err = c.Start()
|
||||
@@ -1987,7 +1987,7 @@ func TestClientPlayDifferentInterleavedIDs(t *testing.T) {
|
||||
packetRecv := make(chan struct{})
|
||||
|
||||
c := Client{
|
||||
Protocol: ptrOf(TransportTCP),
|
||||
Protocol: ptrOf(ProtocolTCP),
|
||||
}
|
||||
|
||||
err = readAll(&c, "rtsp://localhost:8554/teststream",
|
||||
@@ -2423,10 +2423,10 @@ func TestClientPlayPausePlay(t *testing.T) {
|
||||
c := Client{
|
||||
Protocol: func() *Protocol {
|
||||
if transport == "udp" {
|
||||
v := TransportUDP
|
||||
v := ProtocolUDP
|
||||
return &v
|
||||
}
|
||||
v := TransportTCP
|
||||
v := ProtocolTCP
|
||||
return &v
|
||||
}(),
|
||||
}
|
||||
@@ -2743,11 +2743,11 @@ func TestClientPlayErrorTimeout(t *testing.T) {
|
||||
Protocol: func() *Protocol {
|
||||
switch transport {
|
||||
case "udp":
|
||||
v := TransportUDP
|
||||
v := ProtocolUDP
|
||||
return &v
|
||||
|
||||
case "tcp":
|
||||
v := TransportTCP
|
||||
v := ProtocolTCP
|
||||
return &v
|
||||
}
|
||||
return nil
|
||||
@@ -2876,7 +2876,7 @@ func TestClientPlayIgnoreTCPInvalidMedia(t *testing.T) {
|
||||
recv := make(chan struct{})
|
||||
|
||||
c := Client{
|
||||
Protocol: ptrOf(TransportTCP),
|
||||
Protocol: ptrOf(ProtocolTCP),
|
||||
}
|
||||
|
||||
err = readAll(&c, "rtsp://localhost:8554/teststream",
|
||||
@@ -3027,7 +3027,7 @@ func TestClientPlayKeepAlive(t *testing.T) {
|
||||
n := 0
|
||||
m := 0
|
||||
|
||||
v := TransportTCP
|
||||
v := ProtocolTCP
|
||||
c := Client{
|
||||
Protocol: &v,
|
||||
OnResponse: func(_ *base.Response) {
|
||||
@@ -3174,7 +3174,7 @@ func TestClientPlayDifferentSource(t *testing.T) {
|
||||
}()
|
||||
|
||||
c := Client{
|
||||
Protocol: ptrOf(TransportUDP),
|
||||
Protocol: ptrOf(ProtocolUDP),
|
||||
}
|
||||
|
||||
err = readAll(&c, "rtsp://localhost:8554/test/stream?param=value",
|
||||
@@ -3420,10 +3420,10 @@ func TestClientPlayDecodeErrors(t *testing.T) {
|
||||
c := Client{
|
||||
Protocol: func() *Protocol {
|
||||
if ca.proto == "udp" {
|
||||
v := TransportUDP
|
||||
v := ProtocolUDP
|
||||
return &v
|
||||
}
|
||||
v := TransportTCP
|
||||
v := ProtocolTCP
|
||||
return &v
|
||||
}(),
|
||||
OnPacketsLost: func(lost uint64) {
|
||||
@@ -3904,9 +3904,9 @@ func TestClientPlayBackChannel(t *testing.T) {
|
||||
RequestBackChannels: true,
|
||||
Protocol: func() *Protocol {
|
||||
if transport == "tcp" {
|
||||
return ptrOf(TransportTCP)
|
||||
return ptrOf(ProtocolTCP)
|
||||
}
|
||||
return ptrOf(TransportUDP)
|
||||
return ptrOf(ProtocolUDP)
|
||||
}(),
|
||||
senderReportPeriod: 500 * time.Millisecond,
|
||||
receiverReportPeriod: 750 * time.Millisecond,
|
||||
|
@@ -419,10 +419,10 @@ func TestClientRecord(t *testing.T) {
|
||||
},
|
||||
Protocol: func() *Protocol {
|
||||
if ca.transport == "udp" {
|
||||
v := TransportUDP
|
||||
v := ProtocolUDP
|
||||
return &v
|
||||
}
|
||||
v := TransportTCP
|
||||
v := ProtocolTCP
|
||||
return &v
|
||||
}(),
|
||||
}
|
||||
@@ -589,10 +589,10 @@ func TestClientRecordSocketError(t *testing.T) {
|
||||
},
|
||||
Protocol: func() *Protocol {
|
||||
if transport == "udp" {
|
||||
v := TransportUDP
|
||||
v := ProtocolUDP
|
||||
return &v
|
||||
}
|
||||
v := TransportTCP
|
||||
v := ProtocolTCP
|
||||
return &v
|
||||
}(),
|
||||
}
|
||||
@@ -733,10 +733,10 @@ func TestClientRecordPauseRecordSerial(t *testing.T) {
|
||||
c := Client{
|
||||
Protocol: func() *Protocol {
|
||||
if transport == "udp" {
|
||||
v := TransportUDP
|
||||
v := ProtocolUDP
|
||||
return &v
|
||||
}
|
||||
v := TransportTCP
|
||||
v := ProtocolTCP
|
||||
return &v
|
||||
}(),
|
||||
}
|
||||
@@ -892,10 +892,10 @@ func TestClientRecordPauseRecordParallel(t *testing.T) {
|
||||
c := Client{
|
||||
Protocol: func() *Protocol {
|
||||
if transport == "udp" {
|
||||
v := TransportUDP
|
||||
v := ProtocolUDP
|
||||
return &v
|
||||
}
|
||||
v := TransportTCP
|
||||
v := ProtocolTCP
|
||||
return &v
|
||||
}(),
|
||||
}
|
||||
@@ -1217,10 +1217,10 @@ func TestClientRecordDecodeErrors(t *testing.T) {
|
||||
c := Client{
|
||||
Protocol: func() *Protocol {
|
||||
if ca.proto == "udp" {
|
||||
v := TransportUDP
|
||||
v := ProtocolUDP
|
||||
return &v
|
||||
}
|
||||
v := TransportTCP
|
||||
v := ProtocolTCP
|
||||
return &v
|
||||
}(),
|
||||
OnDecodeError: func(err error) {
|
||||
@@ -1391,10 +1391,10 @@ func TestClientRecordRTCPReport(t *testing.T) {
|
||||
c := Client{
|
||||
Protocol: func() *Protocol {
|
||||
if ca == "udp" {
|
||||
v := TransportUDP
|
||||
v := ProtocolUDP
|
||||
return &v
|
||||
}
|
||||
v := TransportTCP
|
||||
v := ProtocolTCP
|
||||
return &v
|
||||
}(),
|
||||
timeNow: func() time.Time {
|
||||
@@ -1536,7 +1536,7 @@ func TestClientRecordIgnoreTCPRTPPackets(t *testing.T) {
|
||||
rtcpReceived := make(chan struct{})
|
||||
|
||||
c := Client{
|
||||
Protocol: ptrOf(TransportTCP),
|
||||
Protocol: ptrOf(ProtocolTCP),
|
||||
}
|
||||
|
||||
medias := []*description.Media{testH264Media}
|
||||
|
@@ -28,6 +28,8 @@ func main() {
|
||||
c := gortsplib.Client{
|
||||
Scheme: u.Scheme,
|
||||
Host: u.Host,
|
||||
// tunneling method.
|
||||
Tunnel: gortsplib.TunnelNone,
|
||||
// transport protocol (UDP, Multicast or TCP). If nil, it is chosen automatically
|
||||
Protocol: nil,
|
||||
// timeout of read operations
|
||||
|
@@ -175,9 +175,9 @@ func TestClientVsServer(t *testing.T) {
|
||||
var publisherProto gortsplib.Protocol
|
||||
switch ca.publisherProto {
|
||||
case "udp":
|
||||
publisherProto = gortsplib.TransportUDP
|
||||
publisherProto = gortsplib.ProtocolUDP
|
||||
case "tcp":
|
||||
publisherProto = gortsplib.TransportTCP
|
||||
publisherProto = gortsplib.ProtocolTCP
|
||||
}
|
||||
|
||||
publisher := &gortsplib.Client{
|
||||
@@ -201,11 +201,11 @@ func TestClientVsServer(t *testing.T) {
|
||||
var readerProto gortsplib.Protocol
|
||||
switch ca.readerProto {
|
||||
case "udp":
|
||||
readerProto = gortsplib.TransportUDP
|
||||
readerProto = gortsplib.ProtocolUDP
|
||||
case "tcp":
|
||||
readerProto = gortsplib.TransportTCP
|
||||
readerProto = gortsplib.ProtocolTCP
|
||||
case "multicast":
|
||||
readerProto = gortsplib.TransportUDPMulticast
|
||||
readerProto = gortsplib.ProtocolUDPMulticast
|
||||
}
|
||||
|
||||
u, err := base.ParseURL(ca.readerScheme + "://" + multicastCapableIP(t) + ":8554/test/stream?key=val")
|
||||
|
@@ -682,13 +682,13 @@ func TestServerPlay(t *testing.T) {
|
||||
var proto Protocol
|
||||
switch ca.transport {
|
||||
case "udp":
|
||||
proto = TransportUDP
|
||||
proto = ProtocolUDP
|
||||
|
||||
case "tcp":
|
||||
proto = TransportTCP
|
||||
proto = ProtocolTCP
|
||||
|
||||
case "multicast":
|
||||
proto = TransportUDPMulticast
|
||||
proto = ProtocolUDPMulticast
|
||||
}
|
||||
|
||||
var profile headers.TransportProfile
|
||||
|
@@ -624,10 +624,10 @@ func TestServerRecord(t *testing.T) {
|
||||
var proto Protocol
|
||||
switch ca.transport {
|
||||
case "udp":
|
||||
proto = TransportUDP
|
||||
proto = ProtocolUDP
|
||||
|
||||
case "tcp":
|
||||
proto = TransportTCP
|
||||
proto = ProtocolTCP
|
||||
}
|
||||
|
||||
var profile headers.TransportProfile
|
||||
|
@@ -885,8 +885,8 @@ func (ss *ServerSession) runInner() error {
|
||||
// and transport is UDP or UDP-multicast.
|
||||
if (ss.state == ServerSessionStatePrePlay ||
|
||||
ss.state == ServerSessionStatePlay) &&
|
||||
(ss.setuppedTransport.Protocol == TransportUDP ||
|
||||
ss.setuppedTransport.Protocol == TransportUDPMulticast) {
|
||||
(ss.setuppedTransport.Protocol == ProtocolUDP ||
|
||||
ss.setuppedTransport.Protocol == ProtocolUDPMulticast) {
|
||||
v := uint(ss.s.sessionTimeout / time.Second)
|
||||
return &v
|
||||
}
|
||||
@@ -922,7 +922,7 @@ func (ss *ServerSession) runInner() error {
|
||||
// close the session.
|
||||
if ((ss.state != ServerSessionStateRecord &&
|
||||
ss.state != ServerSessionStatePlay) ||
|
||||
ss.setuppedTransport.Protocol == TransportTCP) &&
|
||||
ss.setuppedTransport.Protocol == ProtocolTCP) &&
|
||||
len(ss.conns) == 0 {
|
||||
return liberrors.ErrServerSessionNotInUse{}
|
||||
}
|
||||
@@ -930,7 +930,7 @@ func (ss *ServerSession) runInner() error {
|
||||
case <-ss.chAsyncStartWriter:
|
||||
if (ss.state == ServerSessionStateRecord ||
|
||||
ss.state == ServerSessionStatePlay) &&
|
||||
ss.setuppedTransport.Protocol == TransportTCP {
|
||||
ss.setuppedTransport.Protocol == ProtocolTCP {
|
||||
ss.startWriter()
|
||||
}
|
||||
|
||||
@@ -1134,13 +1134,13 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
||||
switch inTH.Protocol {
|
||||
case headers.TransportProtocolUDP:
|
||||
if inTH.Delivery != nil && *inTH.Delivery == headers.TransportDeliveryMulticast {
|
||||
protocol = TransportUDPMulticast
|
||||
protocol = ProtocolUDPMulticast
|
||||
} else {
|
||||
protocol = TransportUDP
|
||||
protocol = ProtocolUDP
|
||||
}
|
||||
|
||||
case headers.TransportProtocolTCP:
|
||||
protocol = TransportTCP
|
||||
protocol = ProtocolTCP
|
||||
}
|
||||
|
||||
var srtpInCtx *wrappedSRTPContext
|
||||
@@ -1176,14 +1176,14 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
||||
}
|
||||
|
||||
switch protocol {
|
||||
case TransportUDP:
|
||||
case ProtocolUDP:
|
||||
if inTH.ClientPorts == nil {
|
||||
return &base.Response{
|
||||
StatusCode: base.StatusBadRequest,
|
||||
}, liberrors.ErrServerTransportHeaderNoClientPorts{}
|
||||
}
|
||||
|
||||
case TransportTCP:
|
||||
case ProtocolTCP:
|
||||
if inTH.InterleavedIDs != nil {
|
||||
if (inTH.InterleavedIDs[0] + 1) != inTH.InterleavedIDs[1] {
|
||||
return &base.Response{
|
||||
@@ -1208,7 +1208,7 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
||||
}
|
||||
|
||||
default: // record
|
||||
if protocol == TransportUDPMulticast {
|
||||
if protocol == ProtocolUDPMulticast {
|
||||
return &base.Response{
|
||||
StatusCode: base.StatusUnsupportedTransport,
|
||||
}, nil
|
||||
@@ -1363,10 +1363,10 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
||||
var tcpChannel int
|
||||
|
||||
switch protocol {
|
||||
case TransportUDP, TransportUDPMulticast:
|
||||
case ProtocolUDP, ProtocolUDPMulticast:
|
||||
th.Protocol = headers.TransportProtocolUDP
|
||||
|
||||
if protocol == TransportUDP {
|
||||
if protocol == ProtocolUDP {
|
||||
udpRTPReadPort = inTH.ClientPorts[0]
|
||||
udpRTCPReadPort = inTH.ClientPorts[1]
|
||||
|
||||
@@ -1496,7 +1496,7 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
||||
}
|
||||
|
||||
if ss.state != ServerSessionStatePlay &&
|
||||
ss.setuppedTransport.Protocol != TransportUDPMulticast {
|
||||
ss.setuppedTransport.Protocol != ProtocolUDPMulticast {
|
||||
ss.createWriter()
|
||||
}
|
||||
|
||||
@@ -1529,17 +1529,17 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
||||
}
|
||||
}
|
||||
|
||||
if ss.setuppedTransport.Protocol == TransportTCP {
|
||||
if ss.setuppedTransport.Protocol == ProtocolTCP {
|
||||
ss.tcpFrame = &base.InterleavedFrame{}
|
||||
ss.tcpBuffer = make([]byte, ss.s.MaxPacketSize+4)
|
||||
}
|
||||
|
||||
switch ss.setuppedTransport.Protocol {
|
||||
case TransportUDP:
|
||||
case ProtocolUDP:
|
||||
ss.udpCheckStreamTimer = time.NewTimer(ss.s.checkStreamPeriod)
|
||||
ss.startWriter()
|
||||
|
||||
case TransportUDPMulticast:
|
||||
case ProtocolUDPMulticast:
|
||||
ss.udpCheckStreamTimer = time.NewTimer(ss.s.checkStreamPeriod)
|
||||
|
||||
default: // TCP
|
||||
@@ -1567,7 +1567,7 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
||||
}
|
||||
} else {
|
||||
if ss.state != ServerSessionStatePlay &&
|
||||
ss.setuppedTransport.Protocol != TransportUDPMulticast {
|
||||
ss.setuppedTransport.Protocol != ProtocolUDPMulticast {
|
||||
ss.destroyWriter()
|
||||
}
|
||||
}
|
||||
@@ -1624,13 +1624,13 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
||||
}
|
||||
}
|
||||
|
||||
if ss.setuppedTransport.Protocol == TransportTCP {
|
||||
if ss.setuppedTransport.Protocol == ProtocolTCP {
|
||||
ss.tcpFrame = &base.InterleavedFrame{}
|
||||
ss.tcpBuffer = make([]byte, ss.s.MaxPacketSize+4)
|
||||
}
|
||||
|
||||
switch ss.setuppedTransport.Protocol {
|
||||
case TransportUDP:
|
||||
case ProtocolUDP:
|
||||
ss.udpCheckStreamTimer = time.NewTimer(ss.s.checkStreamPeriod)
|
||||
ss.startWriter()
|
||||
|
||||
@@ -1688,10 +1688,10 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
||||
ss.propsMutex.Unlock()
|
||||
|
||||
switch ss.setuppedTransport.Protocol {
|
||||
case TransportUDP:
|
||||
case ProtocolUDP:
|
||||
ss.udpCheckStreamTimer = emptyTimer()
|
||||
|
||||
case TransportUDPMulticast:
|
||||
case ProtocolUDPMulticast:
|
||||
ss.udpCheckStreamTimer = emptyTimer()
|
||||
|
||||
default: // TCP
|
||||
@@ -1701,7 +1701,7 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
||||
|
||||
case ServerSessionStateRecord:
|
||||
switch ss.setuppedTransport.Protocol {
|
||||
case TransportUDP:
|
||||
case ProtocolUDP:
|
||||
ss.udpCheckStreamTimer = emptyTimer()
|
||||
|
||||
default: // TCP
|
||||
@@ -1721,7 +1721,7 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
||||
case base.Teardown:
|
||||
var err error
|
||||
if (ss.state == ServerSessionStatePlay || ss.state == ServerSessionStateRecord) &&
|
||||
ss.setuppedTransport.Protocol == TransportTCP {
|
||||
ss.setuppedTransport.Protocol == ProtocolTCP {
|
||||
err = switchReadFuncError{false}
|
||||
}
|
||||
|
||||
|
@@ -31,8 +31,8 @@ func (sf *serverSessionFormat) initialize() {
|
||||
sf.rtpPacketsSent = new(uint64)
|
||||
sf.rtpPacketsLost = new(uint64)
|
||||
|
||||
udp := sf.sm.ss.setuppedTransport.Protocol == TransportUDP ||
|
||||
sf.sm.ss.setuppedTransport.Protocol == TransportUDPMulticast
|
||||
udp := sf.sm.ss.setuppedTransport.Protocol == ProtocolUDP ||
|
||||
sf.sm.ss.setuppedTransport.Protocol == ProtocolUDPMulticast
|
||||
|
||||
if udp {
|
||||
sf.writePacketRTPInQueue = sf.writePacketRTPInQueueUDP
|
||||
|
@@ -59,10 +59,10 @@ func (sm *serverSessionMedia) initialize() {
|
||||
}
|
||||
|
||||
switch sm.ss.setuppedTransport.Protocol {
|
||||
case TransportUDP, TransportUDPMulticast:
|
||||
case ProtocolUDP, ProtocolUDPMulticast:
|
||||
sm.writePacketRTCPInQueue = sm.writePacketRTCPInQueueUDP
|
||||
|
||||
case TransportTCP:
|
||||
case ProtocolTCP:
|
||||
sm.writePacketRTCPInQueue = sm.writePacketRTCPInQueueTCP
|
||||
|
||||
if sm.ss.tcpCallbackByChannel == nil {
|
||||
@@ -89,8 +89,8 @@ func (sm *serverSessionMedia) close() {
|
||||
|
||||
func (sm *serverSessionMedia) start() error {
|
||||
switch sm.ss.setuppedTransport.Protocol {
|
||||
case TransportUDP, TransportUDPMulticast:
|
||||
if sm.ss.setuppedTransport.Protocol == TransportUDP {
|
||||
case ProtocolUDP, ProtocolUDPMulticast:
|
||||
if sm.ss.setuppedTransport.Protocol == ProtocolUDP {
|
||||
if sm.ss.state == ServerSessionStatePlay {
|
||||
if sm.media.IsBackChannel {
|
||||
sm.ss.s.udpRTPListener.addClient(sm.ss.author.ip(), sm.udpRTPReadPort, sm.readPacketRTPUDPPlay)
|
||||
@@ -136,7 +136,7 @@ func (sm *serverSessionMedia) start() error {
|
||||
}
|
||||
|
||||
func (sm *serverSessionMedia) stop() {
|
||||
if sm.ss.setuppedTransport.Protocol == TransportUDP {
|
||||
if sm.ss.setuppedTransport.Protocol == ProtocolUDP {
|
||||
sm.ss.s.udpRTPListener.removeClient(sm.ss.author.ip(), sm.udpRTPReadPort)
|
||||
sm.ss.s.udpRTCPListener.removeClient(sm.ss.author.ip(), sm.udpRTCPReadPort)
|
||||
}
|
||||
|
@@ -188,10 +188,10 @@ func (st *ServerStream) readerAdd(
|
||||
}
|
||||
|
||||
switch protocol {
|
||||
case TransportUDP:
|
||||
case ProtocolUDP:
|
||||
// check whether UDP ports and IP are already assigned to another reader
|
||||
for r := range st.readers {
|
||||
if protocol == TransportUDP &&
|
||||
if protocol == ProtocolUDP &&
|
||||
r.author.ip().Equal(ss.author.ip()) &&
|
||||
r.author.zone() == ss.author.zone() {
|
||||
for _, rt := range r.setuppedMedias {
|
||||
@@ -202,7 +202,7 @@ func (st *ServerStream) readerAdd(
|
||||
}
|
||||
}
|
||||
|
||||
case TransportUDPMulticast:
|
||||
case ProtocolUDPMulticast:
|
||||
if st.multicastReaderCount == 0 {
|
||||
for _, media := range st.medias {
|
||||
mw := &serverMulticastWriter{
|
||||
@@ -233,7 +233,7 @@ func (st *ServerStream) readerRemove(ss *ServerSession) {
|
||||
|
||||
delete(st.readers, ss)
|
||||
|
||||
if ss.setuppedTransport.Protocol == TransportUDPMulticast {
|
||||
if ss.setuppedTransport.Protocol == ProtocolUDPMulticast {
|
||||
st.multicastReaderCount--
|
||||
if st.multicastReaderCount == 0 {
|
||||
for _, media := range st.medias {
|
||||
@@ -252,7 +252,7 @@ func (st *ServerStream) readerSetActive(ss *ServerSession) {
|
||||
return
|
||||
}
|
||||
|
||||
if ss.setuppedTransport.Protocol == TransportUDPMulticast {
|
||||
if ss.setuppedTransport.Protocol == ProtocolUDPMulticast {
|
||||
for medi, sm := range ss.setuppedMedias {
|
||||
streamMedia := st.medias[medi]
|
||||
streamMedia.multicastWriter.rtcpl.addClient(
|
||||
@@ -271,7 +271,7 @@ func (st *ServerStream) readerSetInactive(ss *ServerSession) {
|
||||
return
|
||||
}
|
||||
|
||||
if ss.setuppedTransport.Protocol == TransportUDPMulticast {
|
||||
if ss.setuppedTransport.Protocol == ProtocolUDPMulticast {
|
||||
for medi := range ss.setuppedMedias {
|
||||
streamMedia := st.medias[medi]
|
||||
streamMedia.multicastWriter.rtcpl.removeClient(ss.author.ip(), streamMedia.multicastWriter.rtcpl.port())
|
||||
|
@@ -7,15 +7,15 @@ type Protocol int
|
||||
|
||||
// transport protocols.
|
||||
const (
|
||||
TransportUDP Protocol = iota
|
||||
TransportUDPMulticast
|
||||
TransportTCP
|
||||
ProtocolUDP Protocol = iota
|
||||
ProtocolUDPMulticast
|
||||
ProtocolTCP
|
||||
)
|
||||
|
||||
var transportLabels = map[Protocol]string{
|
||||
TransportUDP: "UDP",
|
||||
TransportUDPMulticast: "UDP-multicast",
|
||||
TransportTCP: "TCP",
|
||||
ProtocolUDP: "UDP",
|
||||
ProtocolUDPMulticast: "UDP-multicast",
|
||||
ProtocolTCP: "TCP",
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func TestProtocolString(t *testing.T) {
|
||||
tr := TransportUDPMulticast
|
||||
tr := ProtocolUDPMulticast
|
||||
require.NotEqual(t, "unknown", tr.String())
|
||||
|
||||
tr = Protocol(15)
|
||||
|
Reference in New Issue
Block a user