Browse Source

move utils into utils.go

pull/31/head
aler9 5 years ago
parent
commit
3a72c6ef1c
  1. 31
      main.go
  2. 14
      server-client.go
  3. 8
      server-udpl.go
  4. 7
      streamer-udpl.go
  5. 51
      utils.go

31
main.go

@ -18,37 +18,6 @@ import ( @@ -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

14
server-client.go

@ -18,20 +18,6 @@ const ( @@ -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 (

8
server-udpl.go

@ -5,7 +5,7 @@ import ( @@ -5,7 +5,7 @@ import (
"time"
)
type udpWrite struct {
type udpAddrFramePair struct {
addr *net.UDPAddr
buf []byte
}
@ -21,7 +21,7 @@ type serverUdpListener struct { @@ -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 @@ -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) { @@ -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,
}

7
streamer-udpl.go

@ -5,13 +5,6 @@ import ( @@ -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

@ -0,0 +1,51 @@ @@ -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…
Cancel
Save