• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang core.Agent类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang core.WorkerContainer类代码示例发布时间:2022-05-28
下一篇:
Golang table.Path类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap