本文整理匯總了Golang中github.com/ossrs/go-oryx/core.Agent.Pump方法的典型用法代碼示例。如果您正苦於以下問題:Golang Agent.Pump方法的具體用法?Golang Agent.Pump怎麽用?Golang Agent.Pump使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ossrs/go-oryx/core.Agent
的用法示例。
在下文中一共展示了Agent.Pump方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: cycle
//.........這裏部分代碼省略.........
}
return
}
core.Info.Println("set chunk size to", core.Conf.ChunkSize)
// 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
}
core.Info.Println("response connect app ok.")
if err = conn.OnBwDone(); err != nil {
if !core.IsNormalQuit(err) {
core.Error.Println("response onBWDone failed. err is", err)
}
return
}
core.Info.Println("onBWDone ok.")
// 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
}
if err = conn.OnUrlParsed(); err != nil {
core.Error.Println("notify url parsed 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
}
// set chunk_size on vhost level.
// TODO: FIXME: support set chunk size.
var agent core.Agent
if conn.Req.Type.IsPlay() {
if agent, err = Manager.NewRtmpPlayAgent(conn, v.wc); err != nil {
core.Error.Println("create play agent failed. err is", err)
return
}
} else if conn.Req.Type.IsPublish() {
if agent, err = Manager.NewRtmpPublishAgent(conn, v.wc); err != nil {
core.Error.Println("create 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.Pump(); err != nil {
if !core.IsNormalQuit(err) && !IsControlError(err) {
core.Warn.Println("ignore rtmp agent work failed. err is", err)
}
return
}
return
}