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 (server *LoadServer) StartStream(desc *amp.StartStream) error {
	client := desc.Client()
	if _, ok := server.sessions[client]; ok {
		return fmt.Errorf("Session already exists for client %v", client)
	}
	session, err := server.newStreamSession(desc)
	if err != nil {
		return err
	}
	server.sessions.StartSession(client, session)
	return nil
}
Esempio n. 3
0
func (proxy *AmpProxy) StartStream(desc *amp.StartStream) error {
	client := desc.Client()
	if _, ok := proxy.sessions[client]; ok {
		return fmt.Errorf("Session already exists for client %v", client)
	}

	session, err := proxy.newStreamSession(desc)
	if err != nil {
		return err
	}
	proxy.sessions.StartSession(client, session)
	return nil
}
Esempio n. 4
0
func (server *LoadServer) newStreamSession(desc *amp.StartStream) (*loadSession, error) {
	target := desc.Client()
	client := load.NewClient()
	if err := client.SetServer(target); err != nil {
		_ = client.Close()
		return nil, err
	}
	load, err := strconv.Atoi(desc.MediaFile)
	if err != nil {
		load = DefaultLoad
	}
	client.SetPayload(server.PayloadSize)
	return &loadSession{
		client: client,
		load:   uint64(load),
	}, nil
}