关于RTMP的异常处理

问题描述 投票:0回答:0

我正在使用 goalng Pacakge joy4(https://github.com/nareix/joy4) 包作为 RtmpServer。 我认为需要对重复键进行异常处理。 如果我将此 url 用于 RTMP 网络流,rtmp://localhost:1935/app/test
首先,使用OBS发布数据到RTMP Server。
二、使用example/rtmp_publish/main.go,发布同一个url rtmp://localhost:1935/app/test
我认为这绝对是个问题。连接变得不稳定。
没有关于相同流密钥(“测试”)的异常处理。
有什么好主意吗?

https://github.com/nareix/joy4/blob/master/examples/http_flv_and_rtmp_server/main.go https://github.com/nareix/joy4/blob/master/format/rtmp/rtmp.go

我尝试在 HandlePublish 函数中 conn.Close。 使用地图,如果已经有相同的密钥(URL),我添加 conn.Close(), 但这并没有解决问题。

server.HandlePublish = func(conn *rtmp.Conn) {
        logger.Info("server.HandlePublish start Call")
        streams, _ := conn.Streams()

        l.Lock()
        // if key(rtmp url exists), conn.close()
        ch, ok := channels[conn.URL.Path]
        if ok {
            logger.Errorf("Already published: %s", conn.URL.Path)
            conn.Close() // add this line. 
            return
        }
        if ch == nil {
            logger.Info("after inside of HandlePublish ch is nil")
            ch = &Channel{}
            ch.que = pubsub.NewQueue()
            ch.que.WriteHeader(streams)
            channels[conn.URL.Path] = ch
        } else {
            ch = nil
        }
        l.Unlock()
        if ch == nil {
            return
        }

        avutil.CopyPackets(ch.que, conn)
        l.Lock()
        delete(channels, conn.URL.Path)
        l.Unlock()
        ch.que.Close()
    }

我试过了,但这不是解决问题的方法.. 有什么好主意吗?

go exception publish rtmp
© www.soinside.com 2019 - 2024. All rights reserved.