Example #1
0
func (v *AgentManager) NewRtmpPublishAgent(conn *protocol.RtmpConnection, wc core.WorkerContainer) (pub core.Agent, err error) {
	v.lock.Lock()
	defer v.lock.Unlock()

	// finger the source agent out, which dup to other agent.
	var dup core.Agent
	if dup, err = v.getDupAgent(conn.Req.Uri()); err != nil {
		return
	}

	// when dup source not nil, then the source is using.
	if dup.TiedSink() != nil {
		err = AgentBusyError
		core.Error.Println("source busy. err is", err)
		return
	}

	// create the publish agent
	pub = &RtmpPublishAgent{
		conn: conn,
		wc:   wc,
	}

	if err = pub.Open(); err != nil {
		core.Warn.Println("open publish failed. err is", err)
		return
	}

	// tie the publish agent to dup source.
	if err = dup.Tie(pub); err != nil {
		core.Error.Println("tie publish failed. err is", err)
		return
	}

	return
}