begeekmyfriend / yasea

RTMP live streaming client for Android
MIT License
4.89k stars 1.32k forks source link

About push the stream of time #16

Closed flyminiboy closed 8 years ago

flyminiboy commented 8 years ago

Now, Continue to push flow more than 4 hours and 30 minutes,It will stop.

begeekmyfriend commented 8 years ago

I have tested publishing overnight.

flyminiboy commented 8 years ago

It happen each time The network is normal Sorry, I forget to see the exception

begeekmyfriend commented 8 years ago

Enough, if it happens each time, the exception might well be EPIPE. I have got it.

flyminiboy commented 8 years ago

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。

begeekmyfriend commented 8 years ago

Nothing but re-connection since it is the Nginx-RTMP that closes the socket. Today I will verify it on Nginx-RTMP.

begeekmyfriend commented 8 years ago

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.

begeekmyfriend commented 8 years ago

Try https://github.com/begeekmyfriend/yasea/commit/9e35f22b7f758d0e3a5125a25f919606c71171d8 please.

flyminiboy commented 8 years ago

I get the latest code, find a new exception : java.net.UnknownHostException: Host is unresolved It happened before.

begeekmyfriend commented 8 years ago

That is your URL or networking issue.

flyminiboy commented 8 years ago

But I use the old code can push stream.

begeekmyfriend commented 8 years ago

Are you sure? I downloaded and tried just now you were saying.

flyminiboy commented 8 years ago

Sorry, Should be a network problem. Just in time is a coincidence

flyminiboy commented 8 years ago

It seem still have the same problem And I will test again.

flyminiboy commented 8 years ago

Maybe you can refer to this blog librtmp 时间戳

begeekmyfriend commented 8 years ago

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();
begeekmyfriend commented 8 years ago

Final patch on this issue: https://github.com/begeekmyfriend/yasea/commit/5ee43c681e9c1124ce96799112e62e910756ec4a

flyminiboy commented 8 years ago

I did the test Yesterday night,and It seem still exist

flyminiboy commented 8 years ago

Stream disconnect after 10 hours.

flyminiboy commented 8 years ago

Can I catch the exception and reconnect.

begeekmyfriend commented 8 years ago

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.