Example #1
0
func startProxies(proxy_port, rtp_port int) (string, int) {
	proxy_ip := rtp_ip
	if !pretend_proxy {
		if use_pcp {
			proxy_ip = pcpProxyIp()
			client, err := pcp.NewClientFor(pcp_url)
			client.SetTimeout(time.Duration(client_timeout * float64(time.Second)))
			golib.Checkerr(err)
			log.Printf("Starting external proxies using %v\n", client)
			makeProxyPCP(client, proxy_port, rtp_port)
			makeProxyPCP(client, proxy_port+1, rtp_port+1)
			tasks.AddNamed("proxy", &golib.CleanupTask{Description: "stop proxies",
				Cleanup: func() {
					closeProxyPCP(client, proxy_port, rtp_port)
					closeProxyPCP(client, proxy_port+1, rtp_port+1)
					golib.Printerr(client.Close())
				}})
		} else {
			proxy1 := makeProxy(proxy_port, rtp_port)
			proxy2 := makeProxy(proxy_port+1, rtp_port+1)
			statistics = append(statistics, proxy1.Stats, proxy2.Stats)
			tasks.AddNamed("proxy", proxy1, proxy2, &golib.CleanupTask{
				Description: "print proxy errors",
				Cleanup: func() {
					if proxy1.Err != nil {
						log.Printf("Proxy %v error: %v\n", proxy_port, proxy1.Err)
					}
					if proxy2.Err != nil {
						log.Printf("Proxy %v error: %v\n", proxy_port+1, proxy2.Err)
					}
				}})
		}
	}
	return proxy_ip, proxy_port
}
Example #2
0
func startStream(target_ip string, rtp_port int) {
	if use_amp {
		log.Println("Starting stream using AMP at", amp_url)
		client, err := amp.NewClientFor(amp_url)
		golib.Checkerr(err)
		client.SetTimeout(time.Duration(client_timeout * float64(time.Second)))
		golib.Checkerr(client.StartStream(target_ip, rtp_port, amp_media_file))
		tasks.AddNamed("stream", &golib.CleanupTask{Description: "stop rtp stream",
			Cleanup: func() {
				golib.Printerr(client.StopStream(target_ip, rtp_port))
				golib.Printerr(client.Close())
			}})
	}
	if use_rtsp {
		if target_ip != rtp_ip {
			log.Printf("Warning: RTSP server will stream media to %v, but we are expecting it on %v\n", rtp_ip, target_ip)
		}
		log.Println("Starting stream using RTSP at", rtsp_url)
		rtspCommand, err := rtpClient.StartRtspClient(rtsp_url, rtp_port, "main.log")
		golib.Checkerr(err)
		tasks.AddNamed("rtsp", rtspCommand)
	}
}
Example #3
0
func closeProxyPCP(client *pcp.Client, listenPort, targetPort int) {
	golib.Printerr(client.StopProxy(pcpProxyAddrs(listenPort, targetPort)))
}