mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-25 12:32:01 -08:00
move utils into utils.go
This commit is contained in:
parent
4c81129cd7
commit
3a72c6ef1c
5 changed files with 55 additions and 56 deletions
31
main.go
31
main.go
|
|
@ -18,37 +18,6 @@ import (
|
|||
|
||||
var Version = "v0.0.0"
|
||||
|
||||
func parseIpCidrList(in []string) ([]interface{}, error) {
|
||||
if len(in) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var ret []interface{}
|
||||
for _, t := range in {
|
||||
_, ipnet, err := net.ParseCIDR(t)
|
||||
if err == nil {
|
||||
ret = append(ret, ipnet)
|
||||
continue
|
||||
}
|
||||
|
||||
ip := net.ParseIP(t)
|
||||
if ip != nil {
|
||||
ret = append(ret, ip)
|
||||
continue
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("unable to parse ip/network '%s'", t)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
type trackFlowType int
|
||||
|
||||
const (
|
||||
_TRACK_FLOW_RTP trackFlowType = iota
|
||||
_TRACK_FLOW_RTCP
|
||||
)
|
||||
|
||||
type track struct {
|
||||
rtpPort int
|
||||
rtcpPort int
|
||||
|
|
|
|||
|
|
@ -18,20 +18,6 @@ const (
|
|||
_UDP_STREAM_DEAD_AFTER = 10 * time.Second
|
||||
)
|
||||
|
||||
func interleavedChannelToTrack(channel uint8) (int, trackFlowType) {
|
||||
if (channel % 2) == 0 {
|
||||
return int(channel / 2), _TRACK_FLOW_RTP
|
||||
}
|
||||
return int((channel - 1) / 2), _TRACK_FLOW_RTCP
|
||||
}
|
||||
|
||||
func trackToInterleavedChannel(id int, trackFlowType trackFlowType) uint8 {
|
||||
if trackFlowType == _TRACK_FLOW_RTP {
|
||||
return uint8(id * 2)
|
||||
}
|
||||
return uint8((id * 2) + 1)
|
||||
}
|
||||
|
||||
type clientState int
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type udpWrite struct {
|
||||
type udpAddrFramePair struct {
|
||||
addr *net.UDPAddr
|
||||
buf []byte
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ type serverUdpListener struct {
|
|||
writeBuf2 []byte
|
||||
writeCurBuf bool
|
||||
|
||||
writeChan chan *udpWrite
|
||||
writeChan chan *udpAddrFramePair
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ func newServerUdpListener(p *program, port int, trackFlowType trackFlowType) (*s
|
|||
readBuf2: make([]byte, 2048),
|
||||
writeBuf1: make([]byte, 2048),
|
||||
writeBuf2: make([]byte, 2048),
|
||||
writeChan: make(chan *udpWrite),
|
||||
writeChan: make(chan *udpAddrFramePair),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
|
||||
|
|
@ -110,7 +110,7 @@ func (l *serverUdpListener) write(addr *net.UDPAddr, inbuf []byte) {
|
|||
copy(buf, inbuf)
|
||||
l.writeCurBuf = !l.writeCurBuf
|
||||
|
||||
l.writeChan <- &udpWrite{
|
||||
l.writeChan <- &udpAddrFramePair{
|
||||
addr: addr,
|
||||
buf: buf,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,13 +5,6 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type streamerUdpListenerState int
|
||||
|
||||
const (
|
||||
_UDPL_STATE_STARTING streamerUdpListenerState = iota
|
||||
_UDPL_STATE_RUNNING
|
||||
)
|
||||
|
||||
type streamerUdpListener struct {
|
||||
p *program
|
||||
streamer *streamer
|
||||
|
|
|
|||
51
utils.go
Normal file
51
utils.go
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
func parseIpCidrList(in []string) ([]interface{}, error) {
|
||||
if len(in) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var ret []interface{}
|
||||
for _, t := range in {
|
||||
_, ipnet, err := net.ParseCIDR(t)
|
||||
if err == nil {
|
||||
ret = append(ret, ipnet)
|
||||
continue
|
||||
}
|
||||
|
||||
ip := net.ParseIP(t)
|
||||
if ip != nil {
|
||||
ret = append(ret, ip)
|
||||
continue
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("unable to parse ip/network '%s'", t)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
type trackFlowType int
|
||||
|
||||
const (
|
||||
_TRACK_FLOW_RTP trackFlowType = iota
|
||||
_TRACK_FLOW_RTCP
|
||||
)
|
||||
|
||||
func interleavedChannelToTrack(channel uint8) (int, trackFlowType) {
|
||||
if (channel % 2) == 0 {
|
||||
return int(channel / 2), _TRACK_FLOW_RTP
|
||||
}
|
||||
return int((channel - 1) / 2), _TRACK_FLOW_RTCP
|
||||
}
|
||||
|
||||
func trackToInterleavedChannel(id int, trackFlowType trackFlowType) uint8 {
|
||||
if trackFlowType == _TRACK_FLOW_RTP {
|
||||
return uint8(id * 2)
|
||||
}
|
||||
return uint8((id * 2) + 1)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue