gwuhaolin / livego

live video streaming server in golang
MIT License
9.69k stars 2k forks source link

livego rtmp模块中readChunk通过bufio Read读取RTMP消息,如果创建RtmpConn时,指定remoteChunkSize大于128,读取上来的消息发现会在128字节后面的129字节插入一个0xc3,导致后面数据错位,解析rtmp包出错 #187

Open xianchuhan opened 3 years ago

xianchuhan commented 3 years ago

虽然这个库我们做了点修改,但是使用最新的livego源代码,编译后调试,发现跟修改后的一样,可以使用ffmpeg或者微信小程序,进行推流或者拉流,在connect时,该问题必现,下面是修改后的打印日志: 020007636f6e6e656374003ff00000000000000300036170700200036170700008666c61736856657202000d4c4e5820392c302c3132342c320005 746355726c02001972746d703a2f2f3132372e302e302e313a313933352f6170700004667061640100000c6361706162696c697469657300402e00 0000000000000b617564c3696f436f646563730040afce0000000000000b766964656f436f6465637300406f800000000000000d766964656f4675 6e6374696f6e003ff00000000000000000 r.Read return Len: 194 020007636f6e6e656374003ff00000000000000300036170700200036170700008666c61736856657202000d4c4e5820392c302c3132342c320005 746355726c02001972746d703a2f2f3132372e302e302e313a313933352f6170700004667061640100000c6361706162696c697469657300402e00 0000000000000b617564c3696f436f646563730040afce0000000000000b766964656f436f6465637300406f800000000000000d766964656f4675 6e6374696f6e003ff000000000000000002021-09-10 20:09:31.998 Debug rtmp_conn.go:92 1 ChunkStream len: 194,remoteChun kSize:512, from remote:127.0.0.1:65133 local:127.0.0.1:1935: 2021-09-10 20:09:31.998 Debug rtmp_conn.go:109 1 ChunkStream len: 194, c.DataLen: 194 from remote:127.0.0.1:65133 local:127.0.0.1:1935: 2021-09-10 20:09:31.999 Error server.go:116 SetUpPlayOrPublish failed, Amf DecodeBatch failed, decode amf0: unable to decode object value: decode amf0: unsupported type 115

matthewgao commented 3 years ago

does the chunksize alien with the ffmpeg?

xianchuhan commented 3 years ago

Until this problem is that they are accurate, described again again, micro - applet live-pusher the letter just push the audio stream,chunksize declared letter small program size is 256, but the actual individual bag will send audio packet is greater than 256,livego should be to address this exception is not handled, leading to livego crash. A similar issue with micro - letter community linked below: https://developers.weixin.qq.com/community/develop/doc/0002c84103c080f71e7c901af5ac00

matthewgao commented 2 years ago

Until this problem is that they are accurate, described again again, micro - applet live-pusher the letter just push the audio stream,chunksize declared letter small program size is 256, but the actual individual bag will send audio packet is greater than 256,livego should be to address this exception is not handled, leading to livego crash. A similar issue with micro - letter community linked below: https://developers.weixin.qq.com/community/develop/doc/0002c84103c080f71e7c901af5ac00

Check by capture the packet and see if the chunkSize and remoteChunkSize is aliened from both side, and if the control message is correctly handle, because of the rtmp protocol has same different implementation, since the implementation of it is done by reverse engineering, so the implemenation may slightly different.

xianchuhan commented 2 years ago

Does LiveGo have a plan to accommodate this issue?

q191201771 commented 2 years ago

@xianchuhan

hi,有另外一个Go rtmp开源服务处理过这个问题,感兴趣可以看看,谢谢。

https://github.com/q191201771/lal

xianchuhan commented 2 years ago

好的,非常感谢,我看下

---原始邮件--- 发件人: @.> 发送时间: 2021年12月10日(周五) 晚上9:54 收件人: @.>; 抄送: @.**@.>; 主题: Re: [gwuhaolin/livego] livego rtmp模块中readChunk通过bufio Read读取RTMP消息,如果创建RtmpConn时,指定remoteChunkSize大于128,读取上来的消息发现会在128字节后面的129字节插入一个0xc3,导致后面数据错位,解析rtmp包出错 (#187)

@xianchuhan

hi,有另外一个Go rtmp开源服务处理过这个问题,感兴趣可以看看,谢谢。

https://github.com/q191201771/lal

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

onthegit commented 2 years ago

@q191201771 where did you address this issue in your code?

q191201771 commented 2 years ago

@q191201771 where did you address this issue in your code?

If remote chunk size hasn't been set by remote yet, the message read from remote should be considered chunked with 128 by default.

you can start with:

https://github.com/q191201771/lal/blob/master/pkg/rtmp/rtmp.go#L37 https://github.com/q191201771/lal/blob/master/pkg/rtmp/chunk_composer.go

onthegit commented 2 years ago

@q191201771 from what I've seen from this issue and my own investigating is that the remote chunk size differs from the actual remote chunk size that was set. e.g the remote chunk size was set to 128 but the server receives 156.

here is what other user explained : https://developers.weixin.qq.com/community/develop/doc/0002c84103c080f71e7c901af5ac00