Esempio n. 1
0
func TestEndToEnd(t *testing.T) {

	publishCreateStreamChan = make(chan rtmp.ClientStream, 50)
	publishPublishStartChan = make(chan rtmp.ClientStream, 50)
	playCreateStreamChan = make(chan rtmp.ClientStream, 50)
	playMsgReceiver = make(chan *rtmp.Message, 50)
	playCmdReceiver = make(chan *rtmp.Command, 50)

	pubHandler := &PublishingClientConnHandler{}
	log.Printf("pub: dialing %v", LOCALSERVER)
	var err error
	var pubConn rtmp.ClientConn
	pubConn, err = rtmp.Dial(LOCALSERVER, pubHandler, 100)
	if err != nil {
		log.Println("Dial error", err)
		os.Exit(-1)
	}
	defer pubConn.Close()

	pubConn.Connect()
	if err != nil {
		log.Printf("Connect error: %s", err.Error())
		os.Exit(-1)
	}
	log.Printf("pub:connected to %v", LOCALSERVER)

	log.Println("pub: waiting for publish control stream")
	pubStream := <-publishCreateStreamChan
	pubStream.Attach(pubHandler)

	playHandler := &PlayingClientConnHandler{}
	log.Printf("play: dialing %v", LOCALSERVER)
	var playConn rtmp.ClientConn
	playConn, err = rtmp.Dial(LOCALSERVER, playHandler, 100)
	if err != nil {
		log.Println("Dial error", err)
		os.Exit(-1)
	}
	defer playConn.Close()

	playConn.Connect()
	if err != nil {
		log.Printf("Connect error: %s", err.Error())
		os.Exit(-1)
	}
	log.Printf("play: connected to %v", LOCALSERVER)

	log.Println("play: waiting for play control stream")
	playStream := <-playCreateStreamChan
	playStream.Attach(playHandler)

	// create publishing side
	streamName := fmt.Sprintf("sn_%d", time.Now().UnixNano())
	err = pubStream.Publish(streamName, "live")
	if err != nil {
		log.Printf("Publish command error: %s", err.Error())
		os.Exit(-1)
	}
	<-publishPublishStartChan

	// create playing side
	err = playStream.Play(streamName, float32(-2), float32(-1), true)
	if err != nil {
		log.Printf("Play command error: %s", err.Error())
		os.Exit(-1)
	}

	<-playMsgReceiver
	<-playMsgReceiver
	<-playMsgReceiver

	publishBytes := []byte{1, 2, 3}

	pubStream.PublishVideoData(publishBytes, uint32(time.Now().Second()))

	for {
		select {
		case msg := <-playMsgReceiver:
			msg.LogDump("## msg received:")
			log.Println(hex.Dump(msg.Buf.Bytes()))
			if msg.Type == 9 && bytes.Equal(msg.Buf.Bytes(), publishBytes) {
				// test succeeded
				break
			}
		case cmd := <-playCmdReceiver:
			cmd.LogDump("## cmd received:")
		case <-time.After(2 * time.Second):
			t.Fail()
			break
		}
	}

}
Esempio n. 2
0
func (handler *PlayingClientConnHandler) OnStatus(conn rtmp.ClientConn) {
	var err error
	var status uint
	status, err = conn.Status()
	log.Printf("play:OnStatus: %d (%s), err: %v\n", status, rtmp.StatusDisplay(status), err)
}