Beispiel #1
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s version[%s]\r\nUsage: %s [OPTIONS]\r\n", programName, version, os.Args[0])
		flag.PrintDefaults()
	}
	flag.Parse()

	createStreamChan = make(chan rtmp.ClientStream, 50)
	handler := &PublishingClientConnHandler{}
	log.Printf("dialing %v", url)
	var err error
	obConn, err = rtmp.Dial(*url, handler, 100)
	if err != nil {
		log.Println("Dial error", err)
		os.Exit(-1)
	}
	defer obConn.Close()

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

	startPublishTimeout := time.After(5 * time.Second)

	for {
		select {
		case stream := <-createStreamChan:
			// Publish
			log.Printf("starting publishing on stream %d", stream.ID())
			stream.Attach(handler)
			err = stream.Publish(*streamName, "live")
			if err != nil {
				log.Printf("Publish error: %s", err.Error())
				os.Exit(-1)
			}

		case <-startPublishTimeout:
			log.Printf("start publishing has not occured")
			return

		case <-time.After(10 * time.Second):
			log.Printf("Audio size: %d bytes; Video size: %d bytes\n", audioDataSize, videoDataSize)
		}
	}
}
Beispiel #2
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s version[%s]\r\nUsage: %s [OPTIONS]\r\n", programName, version, os.Args[0])
		flag.PrintDefaults()
	}
	flag.Parse()

	// Create flv file
	if len(*dumpFlv) > 0 {
		var err error
		flvFile, err = flv.CreateFile(*dumpFlv)
		if err != nil {
			log.Println("Create FLV dump file error:", err)
			return
		}
	}
	defer func() {
		if flvFile != nil {
			flvFile.Close()
		}
	}()

	createStreamChan = make(chan rtmp.ClientStream, 50)
	testHandler := &TestClientConnHandler{}
	log.Println("to dial")

	var err error

	obConn, err = rtmp.Dial(*url, testHandler, 100)
	/*
		conn := TryHandshakeByVLC()
		obConn, err = rtmp.NewOutbounConn(conn, *url, testHandler, 100)
	*/
	if err != nil {
		log.Println("Dial error", err)
		os.Exit(-1)
	}

	defer obConn.Close()
	log.Printf("obConn: %+v\n", obConn)
	log.Printf("obConn.URL(): %s\n", obConn.URL())
	log.Println("to connect")
	//	err = obConn.Connect("33abf6e996f80e888b33ef0ea3a32bfd", "131228035", "161114738", "play", "", "", "1368083579")
	err = obConn.Connect()
	if err != nil {
		log.Printf("Connect error: %s", err.Error())
		os.Exit(-1)
	}
	for {
		select {
		case stream := <-createStreamChan:
			// Play
			err = stream.Play(*streamName, float32(-1), float32(-2), false)
			if err != nil {
				log.Printf("Play error: %s", err.Error())
				os.Exit(-1)
			}
			// Set Buffer Length

		case <-time.After(1 * time.Second):
			log.Printf("Audio size: %d bytes; Video size: %d bytes\n", audioDataSize, videoDataSize)
		}
	}
}
Beispiel #3
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
		}
	}

}