當前位置: 首頁>>代碼示例>>Golang>>正文


Golang core.Agent類代碼示例

本文整理匯總了Golang中github.com/ossrs/go-oryx/core.Agent的典型用法代碼示例。如果您正苦於以下問題:Golang Agent類的具體用法?Golang Agent怎麽用?Golang Agent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Agent類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewRtmpPublishAgent

func (v *AgentManager) NewRtmpPublishAgent(conn *protocol.RtmpConnection, wc core.WorkerContainer) (core.Agent, error) {
	v.lock.Lock()
	defer v.lock.Unlock()

	// finger the source agent out, which dup to other agent.
	var ok bool
	var dup core.Agent
	if dup, ok = v.sources[conn.Req.Uri()]; !ok {
		dup = NewDupAgent()
		v.sources[conn.Req.Uri()] = dup

		if err := dup.Open(); err != nil {
			core.Error.Println("open dup agent failed. err is", err)
			return nil, err
		}

		// start async work for dup worker.
		wait := make(chan bool, 1)
		core.Recover("", func() (err error) {
			wait <- true

			if err = dup.Work(); err != nil {
				core.Error.Println("dup agent work failed. err is", err)
				return
			}
			return
		})
		<-wait
	}

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

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

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

	return r, nil
}
開發者ID:thesyncim,項目名稱:go-oryx,代碼行數:51,代碼來源:manager.go

示例2: Flow

func (v *DupAgent) Flow(source core.Agent) (err error) {
	v.sources = append(v.sources, source)

	if v.msh != nil {
		m := v.msh.Copy().SetTimestamp(v.lastTimestamp)
		if err = source.Write(m); err != nil {
			return
		}
	}

	if v.vsh != nil {
		m := v.vsh.Copy().SetTimestamp(v.lastTimestamp)
		if err = source.Write(m); err != nil {
			return
		}
	}

	if v.ash != nil {
		m := v.ash.Copy().SetTimestamp(v.lastTimestamp)
		if err = source.Write(m); err != nil {
			return
		}
	}

	return
}
開發者ID:QilongZhang,項目名稱:go-oryx,代碼行數:26,代碼來源:dup.go

示例3: NewRtmpPublishAgent

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
}
開發者ID:QilongZhang,項目名稱:go-oryx,代碼行數:36,代碼來源:manager.go

示例4: UnTie

func (v *DupAgent) UnTie(sink core.Agent) (err error) {
	v.upstream = nil
	v.msh, v.vsh, v.ash = nil, nil, nil
	return sink.UnFlow(v)
}
開發者ID:QilongZhang,項目名稱:go-oryx,代碼行數:5,代碼來源:dup.go

示例5: cycle


//.........這裏部分代碼省略.........
	}

	// do bandwidth test if connect to the vhost which is for bandwidth check.
	// TODO: FIXME: support bandwidth check.

	// do token traverse before serve it.
	// @see https://github.com/ossrs/srs/pull/239
	// TODO: FIXME: support edge token tranverse.

	// set chunk size to larger.
	// set the chunk size before any larger response greater than 128,
	// to make OBS happy, @see https://github.com/ossrs/srs/issues/454
	// TODO: FIXME: support set chunk size.

	// response the client connect ok and onBWDone.
	if err = conn.ResponseConnectApp(); err != nil {
		if !core.IsNormalQuit(err) {
			core.Error.Println("response connect app failed. err is", err)
		}
		return
	}
	if err = conn.OnBwDone(); err != nil {
		if !core.IsNormalQuit(err) {
			core.Error.Println("response onBWDone failed. err is", err)
		}
		return
	}

	// identify the client, publish or play.
	if r.Type, r.Stream, r.Duration, err = conn.Identify(); err != nil {
		if !core.IsNormalQuit(err) {
			core.Error.Println("identify client failed. err is", err)
		}
		return
	}
	core.Trace.Println(fmt.Sprintf(
		"client identified, type=%s, stream_name=%s, duration=%.2f",
		r.Type, r.Stream, r.Duration))

	// reparse the request by connect and play/publish.
	if err = r.Reparse(); err != nil {
		core.Error.Println("reparse request failed. err is", err)
		return
	}

	// security check
	// TODO: FIXME: implements it.

	// set the TCP_NODELAY to false for high performance.
	// or set tot true for realtime stream.
	// TODO: FIXME: implements it.

	// check vhost.
	// for standard rtmp, the vhost specified in connectApp(tcUrl),
	// while some new client specifies the vhost in stream.
	// for example,
	//		connect("rtmp://vhost/app"), specified in tcUrl.
	//		connect("rtmp://ip/app?vhost=vhost"), specified in tcUrl.
	//		connect("rtmp://ip/app") && play("stream?vhost=vhost"), specified in stream.
	var vhost *core.Vhost
	if vhost, err = core.Conf.Vhost(r.Vhost); err != nil {
		core.Error.Println("check vhost failed, vhost is", r.Vhost, "and err is", err)
		return
	} else if r.Vhost != vhost.Name {
		core.Trace.Println("redirect vhost", r.Vhost, "to", vhost.Name)
		r.Vhost = vhost.Name
	}

	var agent core.Agent
	if conn.Req.Type.IsPlay() {
		// TODO: FIXME: implements it.
	} else if conn.Req.Type.IsPublish() {
		if agent, err = Manager.NewRtmpPublishAgent(conn, v.wc); err != nil {
			core.Error.Println("create rtmp publish agent failed. err is", err)
			return
		}
	} else {
		core.Warn.Println("close invalid", conn.Req.Type, "client")
		return
	}

	// always create the agent when work done.
	defer func() {
		if err := agent.Close(); err != nil {
			core.Warn.Println("ignore agent close failed. err is", err)
		}
	}()

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

	if err = agent.Work(); err != nil {
		core.Warn.Println("ignore rtmp publish agent work failed. err is", err)
		return
	}

	return
}
開發者ID:thesyncim,項目名稱:go-oryx,代碼行數:101,代碼來源:rtmp.go

示例6: UnTie

func (v *RtmpPlayAgent) UnTie(sink core.Agent) (err error) {
	v.upstream = nil
	return sink.UnFlow(v)
}
開發者ID:QilongZhang,項目名稱:go-oryx,代碼行數:4,代碼來源:rtmp.go

示例7: Tie

func (v *RtmpPlayAgent) Tie(sink core.Agent) (err error) {
	v.upstream = sink
	return sink.Flow(v)
}
開發者ID:QilongZhang,項目名稱:go-oryx,代碼行數:4,代碼來源:rtmp.go


注:本文中的github.com/ossrs/go-oryx/core.Agent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。