Closed flyminiboy closed 8 years ago
I have tested publishing overnight.
It happen each time The network is normal Sorry, I forget to see the exception
Enough, if it happens each time, the exception might well be EPIPE
. I have got it.
What I can do to avoid the this exception. In other places I have seen this exception,and the most people say it's it's caused by and extend the timestamp。
Nothing but re-connection since it is the Nginx-RTMP that closes the socket. Today I will verify it on Nginx-RTMP.
Ah, I see. This article illustrates the reason.
ngx_rtmp_recv(ngx_event_t *rev)
{
for( ;; ) {
/* parse headers */
if (b->pos == b->start) {
/* chunk basic header */
fmt = (*p >> 6) & 0x03;
csid = *p++ & 0x3f;
if (fmt <= 2 ) {
/* timestamp: big-endian 3b -> little-endian 4b */
pp = (u_char*)timestamp;
ext = (timestamp == 0x00ffffff);
if (fmt <= 1) {
/* size: big-endian 3b -> little-endian 4b type*/
pp = (u_char*)&h->mlen;
h->type = *(uint8_t*)p++;
if (fmt == 0) {
/* stream: little-endian 4b -> little-endian 4b */
pp = (u_char*)&h->msid;
}
}
}
/* extended header */
if (ext) {
pp = (u_char*)timestamp;
pp[3] = *p++;
pp[2] = *p++;
pp[1] = *p++;
pp[0] = *p++;
}
In ngx_rtmp_recv
function, once Nginx-RTMP receives extended time stamp in chunk type less than 3, then it will always parses extended time stamp in the subsequent packets whatever the chunk type is.
I get the latest code, find a new exception : java.net.UnknownHostException: Host is unresolved It happened before.
That is your URL or networking issue.
But I use the old code can push stream.
Are you sure? I downloaded and tried just now you were saying.
Sorry, Should be a network problem. Just in time is a coincidence
It seem still have the same problem And I will test again.
Maybe you can refer to this blog librtmp 时间戳
A rapid reappearance approach is adding code in rtmp/io/WriteThread.java
. It can help find the bug though no solution occurs to me currently.
while (!writeQueue.isEmpty()) {
RtmpPacket rtmpPacket = writeQueue.poll();
ChunkStreamInfo chunkStreamInfo = rtmpSessionInfo.getChunkStreamInfo(rtmpPacket.getHeader().getChunkStreamId());
chunkStreamInfo.setPrevHeaderTx(rtmpPacket.getHeader());
if (rtmpPacket instanceof Video || rtmpPacket instanceof Audio) {
rtmpPacket.getHeader().setAbsoluteTimestamp((int) chunkStreamInfo.markAbsoluteTimestampTx() + 0xffffff);
} else {
rtmpPacket.getHeader().setAbsoluteTimestamp((int) chunkStreamInfo.markAbsoluteTimestampTx());
}
rtmpPacket.writeTo(out, rtmpSessionInfo.getTxChunkSize(), chunkStreamInfo);
Log.d(TAG, "WriteThread: wrote packet: " + rtmpPacket + ", size: " + rtmpPacket.getHeader().getPacketLength());
if (rtmpPacket instanceof Command) {
rtmpSessionInfo.addInvokedCommand(((Command) rtmpPacket).getTransactionId(), ((Command) rtmpPacket).getCommandName());
}
if (rtmpPacket instanceof Video) {
publisher.getVideoFrameCacheNumber().getAndDecrement();
calcFps();
}
}
out.flush();
Final patch on this issue: https://github.com/begeekmyfriend/yasea/commit/5ee43c681e9c1124ce96799112e62e910756ec4a
I did the test Yesterday night,and It seem still exist
Stream disconnect after 10 hours.
Can I catch the exception and reconnect.
10 hours? That might not be extended time stamp. Maybe the video cache number is full and your network is weak? You may do it yourself.
Now, Continue to push flow more than 4 hours and 30 minutes,It will stop.