Esempio n. 1
0
func (proxy *AmpProxy) newStreamSession(desc *amp.StartStream) (*streamSession, error) {
	client := desc.Client()
	rtcpClient := net.JoinHostPort(desc.ReceiverHost, strconv.Itoa(desc.Port+1))
	rtpProxy, rtcpProxy, err := NewUdpProxyPair(proxy.proxyHost, client, rtcpClient)
	if err != nil {
		return nil, err
	}
	rtpProxy.OnError = proxyOnError
	rtcpProxy.OnError = proxyOnError
	rtpPort := rtpProxy.listenAddr.Port

	mediaURL := proxy.rtspURL.ResolveReference(&url.URL{Path: desc.MediaFile})
	logfile := fmt.Sprintf("amp-proxy-%v-%v.log", rtpPort, desc.MediaFile)
	rtsp, err := rtpClient.StartRtspClient(mediaURL.String(), rtpPort, logfile)
	if err != nil {
		rtpProxy.Stop()
		rtcpProxy.Stop()
		return nil, fmt.Errorf("Failed to start RTSP client: %v", err)
	}
	return &streamSession{
		backend:   rtsp,
		mediaFile: desc.MediaFile,
		port:      desc.Port,
		rtpProxy:  rtpProxy,
		rtcpProxy: rtcpProxy,
		client:    client,
		proxy:     proxy,
	}, nil
}
Esempio n. 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)
	}
}