diff --git a/README.md b/README.md index f88445a..f4690d1 100644 --- a/README.md +++ b/README.md @@ -40,17 +40,24 @@ ffplay -i rtmp://localhost/live/test ```yaml rtmp: publish: - pubaudio: true - pubvideo: true - kickexist: false - publishtimeout: 10 - waitclosetimeout: 0 - delayclosetimeout: 0 + pubaudio: true # 是否发布音频流 + pubvideo: true # 是否发布视频流 + kickexist: false # 剔出已经存在的发布者,用于顶替原有发布者 + publishtimeout: 10s # 发布流默认过期时间,超过该时间发布者没有恢复流将被删除 + delayclosetimeout: 0 # 自动关闭触发后延迟的时间(期间内如果有新的订阅则取消触发关闭),0为关闭该功能,保持连接。 + waitclosetimeout: 0 # 发布者断开后等待时间,超过该时间发布者没有恢复流将被删除,0为关闭该功能,由订阅者决定是否删除 + buffertime: 0 # 缓存时间,用于时光回溯,0为关闭缓存 subscribe: - subaudio: true - subvideo: true - iframeonly: false - waittimeout: 10 + subaudio: true # 是否订阅音频流 + subvideo: true # 是否订阅视频流 + subaudioargname: ats # 订阅音频轨道参数名 + subvideoargname: vts # 订阅视频轨道参数名 + subdataargname: dts # 订阅数据轨道参数名 + subaudiotracks: [] # 订阅音频轨道名称列表 + subvideotracks: [] # 订阅视频轨道名称列表 + submode: 0 # 订阅模式,0为跳帧追赶模式,1为不追赶(多用于录制),2为时光回溯模式 + iframeonly: false # 只订阅关键帧 + waittimeout: 10s # 等待发布者的超时时间,用于订阅尚未发布的流 tcp: listenaddr: :1935 listennum: 0 @@ -61,7 +68,7 @@ rtmp: push: repush: 0 # 当断开后是否自动重新推流,0代表不进行重新推流,-1代表无限次重新推流 pushlist: {} # 推流列表,以 streamPath为key,远程地址为value - chunksize: 4096 + chunksize: 65536 # rtmp chunk size keepalive: false #保持rtmp连接,默认随着stream的close而主动断开 ``` :::tip 配置覆盖 diff --git a/media.go b/media.go index bce3bca..b98c193 100644 --- a/media.go +++ b/media.go @@ -121,6 +121,20 @@ type RTMPReceiver struct { NetStream } +func (r *RTMPReceiver) OnEvent(event any) { + r.Publisher.OnEvent(event) + switch event.(type) { + case IPublisher: + r.Publisher.OnEvent(event) + if r.AudioTrack != nil { + r.AudioTrack.SetStuff(r.bytePool) + } + if r.VideoTrack != nil { + r.VideoTrack.SetStuff(r.bytePool) + } + } +} + func (r *RTMPReceiver) Response(tid uint64, code, level string) error { m := new(ResponsePublishMessage) m.CommandName = Response_OnStatus