-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support srt benchmark #42
Conversation
lastPrint = time.Now() | ||
logger.Tf(ctx, "Stream=%v, consume Video(samples=%v, dts=%v, ts=%.3f) and Audio(samples=%v, dts=%v, ts=%.3f)", | ||
v.stream, v.avcSamples, videoDts, float64(videoDts)/1000.0, v.aacSamples, audioDts, float64(audioDts)/1000.0) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这种其实Go很容易搞:
go func() {
for {
select {
case <- ctx.Done():
return
case <-time.After(5 * time.Second):
logger.Tf(ctx, "xxx")
}
}
} ()
虽然行数可能会多,但是逻辑独立,也不需要一个lastPrint
的变量,比较好理解。
|
||
// Run all subscribers or players. | ||
for i := 0; sr != "" && i < streams && ctx.Err() == nil; i++ { | ||
r_auto := sr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go的命名是不用下划线的,要改成 rAuto
v.srtSocket.SetWriteDeadline(time.Now().Add(time.Duration(2 * time.Second))) | ||
if _, srtError = v.srtSocket.Write(tsPacket); srtError != nil { | ||
logger.Ef(ctx, "SRT write failed, err=%v", srtError) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块可能会打印很多错误。
而且它的目的是控制113行的那个Go退出,所以这块应该用context.Context来做控制。
ctx, srtCancel := context.WithParent(ctx)
tsMuxer.OnPacket = func(pkt []byte) {
if _, err = v.srtSocket.Write(tsPacket); err != nil {
srtCancel()
}
}
然后在113行判断时,只需要判断ctx是否退出了:
for ctx.Err() == nil {
}
ctx和err对象的区别是,cancel一个ctx后,依赖这些ctx的所有goroutine会退出,而err对象并不会触发退出,而是需要goroutine对象自己检查。
比如如果有些goroutine底下还调用了其他goroutine,那么ctx能把这些全部取消,也就是除了112行会检查,后续用到ctx的地方都会判断,而err必须得循环到113行检查才行。
Partially merged by 848f930 |
No description provided.