예제 #1
0
파일: client.go 프로젝트: antongulenko/RTP
func NewRtpClient(listenIP string, listenPort int) (*RtpClient, error) {
	localAddr, err := net.ResolveIPAddr("ip", listenIP)
	if err != nil {
		return nil, err
	}
	rtpTransport, err := rtp.NewTransportUDP(localAddr, listenPort)
	if err != nil {
		return nil, err
	}
	session := rtp.NewSession(rtpTransport, rtpTransport)
	err = session.StartSession()
	if err != nil {
		return nil, err
	}

	client := &RtpClient{
		listenPort:   listenPort,
		ReceiveStats: stats.NewStats("RTP received"),
		MissedStats:  stats.NewStats("RTP missed"),
		CtrlStats:    stats.NewStats("RTCP events"),
		RtpSession:   session,
		ctrlChan:     session.CreateCtrlEventChan(rtpCtrlBuffer),
		dataChan:     session.CreateDataReceiveChan(rtpDataBuffer),
		stopped:      golib.NewOneshotCondition(),
	}

	client.wg.Add(1)
	go client.handleCtrlEvents()
	client.wg.Add(1)
	go client.handleDataPackets()

	return client, nil
}
예제 #2
0
파일: udp.go 프로젝트: antongulenko/RTP
func NewUdpProxy(listenAddr, targetAddr string) (*UdpProxy, error) {
	var listenUDP, targetUDP *net.UDPAddr
	var err error
	if listenUDP, err = net.ResolveUDPAddr("udp", listenAddr); err != nil {
		return nil, err
	}
	if targetUDP, err = net.ResolveUDPAddr("udp", targetAddr); err != nil {
		return nil, err
	}

	listenConn, err := net.ListenUDP("udp", listenUDP)
	if err != nil {
		return nil, err
	}
	// TODO http://play.golang.org/p/ygGFr9oLpW
	// for per-UDP-packet addressing in case one proxy handles multiple connections
	targetConn, err := net.DialUDP("udp", nil, targetUDP)
	if err != nil {
		listenConn.Close()
		return nil, err
	}

	return &UdpProxy{
		listenConn:      listenConn,
		listenAddr:      listenUDP,
		targetConn:      targetConn,
		targetAddr:      targetUDP,
		packets:         make(chan []byte, BufferedPackets),
		proxyClosed:     golib.NewOneshotCondition(),
		writeErrors:     make(chan error, buf_write_errors),
		Stats:           stats.NewStats("UDP Proxy " + listenAddr),
		OnError:         OnErrorClose,
		writePausedCond: sync.Cond{L: new(sync.Mutex)},
	}, nil
}
예제 #3
0
파일: results.go 프로젝트: antongulenko/RTP
func NewResults() *Results {
	return &Results{
		packets:        list.New(),
		startTimestamp: time.Now(),
		stopped:        golib.NewOneshotCondition(),
	}
}
예제 #4
0
파일: client.go 프로젝트: antongulenko/RTP
func NewClient(protocol Protocol) Client {
	return &client{
		protocol: protocol,
		closed:   golib.NewOneshotCondition(),
		timeout:  DefaultTimeout,
	}
}
예제 #5
0
파일: server.go 프로젝트: antongulenko/RTP
func (proto *heartbeatProtocol) ServerHandlers(server *protocols.Server) protocols.ServerHandlerMap {
	state := &serverState{
		Server:           server,
		heartbeatRunning: golib.NewOneshotCondition(),
	}
	return protocols.ServerHandlerMap{
		codeConfigureHeartbeat: state.handleConfigureHeartbeat,
	}
}
예제 #6
0
파일: session.go 프로젝트: antongulenko/RTP
func (sessions Sessions) StartSession(key interface{}, session Session) {
	base := &SessionBase{
		Wg:      new(sync.WaitGroup),
		Stopped: golib.NewOneshotCondition(),
		Session: session,
	}
	sessions[key] = base
	base.start()
	session.Start(base)
}
예제 #7
0
func NewFaultDetectorBase(observedProtocol Protocol, server Addr) *FaultDetectorBase {
	return &FaultDetectorBase{
		lastErr: stateUnknown,
		observedServer: observedServer{
			observedProtocol,
			server,
		},
		Closed: golib.NewOneshotCondition(),
	}
}
예제 #8
0
파일: server.go 프로젝트: antongulenko/RTP
func NewServer(addr_string string, protocol Protocol) (*Server, error) {
	server := &Server{
		errors:  make(chan error, ErrorChanBuffer),
		stopped: golib.NewOneshotCondition(),
	}
	var err error
	server.protocol, err = protocol.instantiateServer(server)
	if err != nil {
		return nil, err
	}
	addr, err := protocol.Transport().Resolve(addr_string)
	if err != nil {
		return nil, err
	}
	listener, err := protocol.Transport().Listen(addr, protocol)
	if err != nil {
		return nil, err
	}
	server.listener = listener
	return server, nil
}