Esempio n. 1
0
func (handler *DefaultServerStreamHandler) OnPublishStart(stream rtmp.ServerStream, publishingName string, publishingType string) {
	log.Printf("OnPublishStart requested by client for name = %q, type = %q", publishingName, publishingType)

	// TODO: decide if this request will be accepted at all

	netStreamUpstream, dispatcherHandler, err := rtmp.RegisterNewNetStream(publishingName, publishingType, stream)
	if err != nil {
		// TODO return different, appropriate status message
		log.Printf("error creating registering new net stream %q/%s - upstream: %s", publishingName, publishingType, err.Error())
		return
	}
	_ = netStreamUpstream

	if publishingType != "live" {
		recorderDownstream, err := rtmp.CreateRollingFileRecorder(netStreamUpstream.Info())
		if err != nil {
			log.Printf("error creating flv file for writing: %s", err.Error())
			return
		}
		err = rtmp.RegisterDownstream(netStreamUpstream.Info().Name, recorderDownstream)
		if err != nil {
			log.Printf("error creating registering new net stream - downstream")
			return
		}
	}

	stream.Attach(dispatcherHandler)

	message := rtmp.NewMessage(stream.ChunkStreamID(), rtmp.COMMAND_AMF0, stream.ID(), 0, nil)
	amf.WriteString(message.Buf, "onStatus")
	amf.WriteDouble(message.Buf, 0)
	amf.WriteNull(message.Buf)
	amf.WriteObject(message.Buf, amf.Object{
		"level":       "status",
		"code":        rtmp.NETSTREAM_PUBLISH_START,
		"description": "start publishing!",
	})
	message.LogDump("onpublishstart accept:")

	stream.Conn().Conn().Send(message)
}
Esempio n. 2
0
func (handler *ServerHandler) OnStreamClosed(conn rtmp.ServerConn, stream rtmp.ServerStream) {
	log.Printf("OnStreamSlosed: stream id = %d", stream.ID())
}
Esempio n. 3
0
func (handler *ServerHandler) OnStreamCreated(conn rtmp.ServerConn, stream rtmp.ServerStream) {
	log.Printf("OnStreamCreated: stream id = %d", stream.ID())
	streamHandler := server.DefaultServerStreamHandler{}
	stream.Attach(&streamHandler)
}