jtt1078-video-server icon indicating copy to clipboard operation
jtt1078-video-server copied to clipboard

我用我自己的设备发送数据会报错

Open powerLxc opened this issue 5 years ago • 60 comments

io.netty.handler.codec.DecoderException: java.lang.RuntimeException: exceed the max buffer size, max length: 4096, data length: 512 at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:459) at io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java:392) at io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java:359) at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:342) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java:1409) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:927) at io.netty.channel.AbstractChannel$AbstractUnsafe$8.run(AbstractChannel.java:822) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.RuntimeException: exceed the max buffer size, max length: 4096, data length: 512 at cn.org.hentai.jtt1078.util.ByteHolder.write(ByteHolder.java:32) at cn.org.hentai.jtt1078.util.ByteHolder.write(ByteHolder.java:26) at cn.org.hentai.jtt1078.server.Jtt1078Decoder.write(Jtt1078Decoder.java:16) at cn.org.hentai.jtt1078.server.Jtt1078Decoder.write(Jtt1078Decoder.java:23) at cn.org.hentai.jtt1078.server.Jtt1078MessageDecoder.decode(Jtt1078MessageDecoder.java:31) at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489) at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428) ... 17 more

powerLxc avatar May 17 '19 03:05 powerLxc

哦哦,,终端发上来的数据有一个缓冲区,大小只有4096字节,而出现这个原因的情况一般是,解码后的消息包处理赶不上接收才会这样,你把PublisherManager类的那一大段注释解开,看看是不是ffmpeg出什么错了,看看是不是在持续的在转播视频流。。。。

glaciall avatar May 17 '19 03:05 glaciall

你可以先简单的改大一点,在Jtt1078Decoder类的12行上,加一两个0试试看看。。。

glaciall avatar May 17 '19 03:05 glaciall

还有你rtmp流媒体服务器配置正确吧?如果不正确的话,可能会出现推流推不动的可能,以至于消息包的处理赶不上接收。。。

glaciall avatar May 17 '19 03:05 glaciall

我用你的测试tcpdump.bin的数据文件推流是正常的

powerLxc avatar May 17 '19 03:05 powerLxc

在Jtt1078Decoder类的12行上加一个0后会报错 java.nio.BufferOverflowException at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:189) at java.nio.ByteBuffer.put(ByteBuffer.java:859) at cn.org.hentai.jtt1078.video.PublisherManager$Publisher.publish(PublisherManager.java:181) at cn.org.hentai.jtt1078.video.PublisherManager.publish(PublisherManager.java:82) at cn.org.hentai.jtt1078.server.Jtt1078Handler.channelRead0(Jtt1078Handler.java:54) at cn.org.hentai.jtt1078.server.Jtt1078Handler.channelRead0(Jtt1078Handler.java:19) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1414) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:945) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:146) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:748) [hentai] 2019-05-17 11:33:42,681 [WARN ] [video-server] - DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception. io.netty.handler.codec.DecoderException: java.lang.RuntimeException: invalid protocol header: 91 13 0D 5E 9F 12 B1 3B 38 3F F8 08 0B D7 8A 57 88 57 88 5A FF 2D EF 42 BA C2 99 DF 15 FD at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:459) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1414) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:945) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:146) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.RuntimeException: invalid protocol header: 91 13 0D 5E 9F 12 B1 3B 38 3F F8 08 0B D7 8A 57 88 57 88 5A FF 2D EF 42 BA C2 99 DF 15 FD at cn.org.hentai.jtt1078.server.Jtt1078Decoder.decode(Jtt1078Decoder.java:33) at cn.org.hentai.jtt1078.server.Jtt1078MessageDecoder.decode(Jtt1078MessageDecoder.java:35) at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489) at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428) ... 16 more [hentai] 2019-05-17 11:33:42,683 [WARN ] [video-server] - DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception. io.netty.handler.codec.DecoderException: java.lang.RuntimeException: invalid protocol header: 91 13 0D 5E 9F 12 B1 3B 38 3F F8 08 0B D7 8A 57 88 57 88 5A FF 2D EF 42 BA C2 99 DF 15 FD at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:459) at io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java:392) at io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java:359) at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:342) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java:1409) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:927) at io.netty.channel.AbstractChannel$AbstractUnsafe$8.run(AbstractChannel.java:822) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.RuntimeException: invalid protocol header: 91 13 0D 5E 9F 12 B1 3B 38 3F F8 08 0B D7 8A 57 88 57 88 5A FF 2D EF 42 BA C2 99 DF 15 FD at cn.org.hentai.jtt1078.server.Jtt1078Decoder.decode(Jtt1078Decoder.java:33) at cn.org.hentai.jtt1078.server.Jtt1078MessageDecoder.decode(Jtt1078MessageDecoder.java:35) at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489) at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428) ... 17 more [hentai] 2019-05-17 11:33:48,923 [DEBUG] [video-server] - PublisherManager - publisher-1 timeout and close automatically

powerLxc avatar May 17 '19 03:05 powerLxc

这是告诉你协议头有问题,你们这是自己设计开发的车载终端吗?

glaciall avatar May 17 '19 03:05 glaciall

不是,但是我抓包下来的协议头是没有问题的,30316364开头的

powerLxc avatar May 17 '19 03:05 powerLxc

这个问题我解决过,究其原因应该设备上传的数据存在粘包的情况,而楼主项目的Decoder部分没有做粘包处理,具体见Jtt1078MessageDecoder第26行,其中(int)Math.ceil(length / 512f)向上取整,对于半包的情况直接这半包就发出去了,后续剩余报文再上来就无法处理了,而楼主测试文件中的字节流比较规范,真实终端设备不会这样上传。

hf-hf avatar May 17 '19 03:05 hf-hf

我的测试文件在读跟发的时候,也是按512字节进行发送的,接收的时候是按512为整块的写入到我的缓冲区里去了,最终在Jtt1078Decoder类里完成的粘包,这不是粘包的问题,可能是传输的数据包存在错误字段导致解包错位了。

另外,你还没有回答我,你这是自己在设计和开发符合1076标准的视频终端吗? 如果是的话,1078协议到视频流推送上是有坑的。。。

glaciall avatar May 17 '19 04:05 glaciall

不是我们自己开发的,但是也是符合标准的

powerLxc avatar May 17 '19 04:05 powerLxc

**有没有看过ffmpeg进程的输出?**这个很重要。。。 厂家生产的终端也是坑得飞起,虽然他们是符合标准的,但是他们经常会加入各种协议支持,你现在正在使用中的终端,是不是正处于1078标准的工作模式下也是需要注意的。

刚刚第二段报错其实有两个地方有问题.

  1. 接收缓冲区调大后,往FIFO管道流写入的缓冲区又不够大了,报了个错,所以这两个应该修改成同样大小的比较合适。
  2. 再就是错误的协议头的问题了,你可以使用netcat做一个监听(反正视频推流是不需要回复的),把得到的数据全部导入到一个文件里去,然后再使用这个文件使用测试程序进行测试,当然其实我希望是你能够人工的分析一下存下来的内容,看看是不是有什么不正常的地方。

glaciall avatar May 17 '19 05:05 glaciall

我将PublisherManager里面的注释解开后多打印了这一段 nfiguration: --enable-shared --prefix=/monchickey/ffmpeg libavutil 56. 22.100 / 56. 22.100 libavcodec 58. 35.100 / 58. 35.100 libavformat 58. 20.100 / 58. 20.100 libavdevice 58. 5.100 / 58. 5.100 libavfilter 7. 40.101 / 7. 40.101 libswscale 5. 3.100 / 5. 3.100 libswresample 3. 3.100 / 3. 3.100 [hentai] 2019-05-17 14:22:58,281 [DEBUG] [video-server] - PublisherManager - publisher-1 timeout and close automatically

powerLxc avatar May 17 '19 06:05 powerLxc

从ffmpeg的输出上来看,ffmpeg还没有开始推流,目前阻塞在了fifo管道文件的读上了,也就是说PublisherManager一个消息包都还没有正确的得到的,还是消息包的接收上有问题,你仔细的跟踪一下车载终端发过来的数据,我项目里的tcpdump.bin就是通过netcat保存下来的车载终端发上来的数据,后面就可以用来反复的进行测试了,你多存一点儿,然后可以分析一下这个数据包。。。。

或者你把捕获的消息包文件也发我一份,我也给你瞅瞅。。。可以发我邮箱:[email protected]

glaciall avatar May 17 '19 06:05 glaciall

我发送了一个10m左右的消息包到您的邮箱里

powerLxc avatar May 17 '19 08:05 powerLxc

好,我晚上看看

glaciall avatar May 17 '19 11:05 glaciall

@powerLxc @hf-hf 更新一下项目,解决掉了读包错误问题,原因在于有些类型的数据包会少几个字段,当时没有注意,现在更正过来了,你提供的数据包可以正确完成推流,车牌号是皖牌照的是吧?

glaciall avatar May 17 '19 13:05 glaciall

对,车牌号是皖的,因为是在运营的车,希望不要把视频数据泄露出去,谢谢

powerLxc avatar May 17 '19 13:05 powerLxc

呃,我刚刚还传进来了呢,悲催,我删一下。。。不过这数据没什么关系吧。。。

glaciall avatar May 17 '19 13:05 glaciall

给别人看到了认出来了会找我麻烦

powerLxc avatar May 17 '19 14:05 powerLxc

客户都难缠

powerLxc avatar May 17 '19 14:05 powerLxc

需要的话我可以录一段我们办公室的设备的视频发给你

powerLxc avatar May 17 '19 14:05 powerLxc

不用了,我是刚好看到那个数据包里有一片我之前没碰到过的片断,所以觉得很有测试价值。。。

glaciall avatar May 17 '19 14:05 glaciall

没事,有空录一段发发给你

powerLxc avatar May 17 '19 15:05 powerLxc

我更新了之后用测试文件测试会报错 java.lang.RuntimeException: no such publisher: 1 at cn.org.hentai.jtt1078.video.PublisherManager.publish(PublisherManager.java:79) at cn.org.hentai.jtt1078.server.Jtt1078Handler.channelRead0(Jtt1078Handler.java:54) at cn.org.hentai.jtt1078.server.Jtt1078Handler.channelRead0(Jtt1078Handler.java:19) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1414) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:945) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:146) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:748)

powerLxc avatar May 18 '19 02:05 powerLxc

解决了,不好意思

powerLxc avatar May 18 '19 02:05 powerLxc

给个原因啊

glaciall avatar May 18 '19 02:05 glaciall

是因为我流媒体的地址写错了,我在同一个服务器下面地址要写127.0.0.1
我在测试车辆的时候发现长时间播放也还是会出现我上面的报错

powerLxc avatar May 18 '19 02:05 powerLxc

我在路上跑 的车视频只能放5分钟左右就报上面的错了

powerLxc avatar May 18 '19 03:05 powerLxc

呃,你上面两条回复我有点迷茫,现在是还有那个问题是吗?还是你仅仅只是在描述这个问题但是你已经解决掉了?

出现那个问题的原因是因为服务器端5秒钟都没有收到终端发来的消息包,所以被定时器给关掉了,你可以看看日志里是不是有一行publisher-1 timeout and close automatically的输出?

glaciall avatar May 18 '19 08:05 glaciall

还是那个问题,第一次我说解决了是我地址填错了,后来我试了一辆车每次只能看5分钟左右也会报那个错,我现在看不到日志因为我已经不在公司了,麻烦您了,我周一在仔细看看

powerLxc avatar May 18 '19 08:05 powerLxc