Rtmp timestamp compatibility and rtmp timestamp compatibility
It has always been implemented using simple librtmp or other open source streaming methods. I am not paying too much attention to details.
Until the last test was pushed for a long time. A 3-byte timestamp overflow problem occurs, that is, the timestamp exceeds 0 xffffff, and the server is disconnected.
Recurrence mode:
Use yasea to push to SRS or Nginx-rtmp.
Yasea versions are and earlier.
SRS does not have special requirements. v2.0.243 release is used this time.
The Nginx-rtmp version does not have special requirements. Nginx: 1.13.3 is used this time.
Yasea pushed to srs for over 4.5 hours. When the timestamp exceeds 0 xffffff, srs reports an error:
chunk stream is fresh, fmt must be 0, actual is 1. cid=25, ret=2001(Resource temporarily unavailable)read message header failed. ret=2001(Resource temporarily unavailable)recv interlaced message failed. ret=2001(Resource temporarily unavailable)thread process message failed. ret=2001(Resource temporarily unavailable)thread recv cycle failed, ignored and retry, ret=2001recv thread failed. ret=2001(Resource temporarily unavailable)cleanup when unpublishstream service cycle failed. ret=2001(Resource temporarily unavailable)
Yasea pushed to Nginx-rtmp for over 4.5 hours. No problem.
The first response may not help but doubt the srs compatibility. Then we pushed the stream to srs and Nginx-rtmp with obs. It was okay for more than five hours.
Read rtmp_specification_1.0.pdf 6.1.2 Chunk Message Header carefully
Start with page16.
Yasea only sends Chunks of Type = 0 and Type = 3.
The only uncertain step is the use of extended timestamp.
View the yasea code and srs code. Since it is a problem of Timestamp overflow, focus on this aspect.
It takes 4.5 hours for each test.
Then, locate the corresponding Timestamp and add an initial value. Corresponding:
Audio. getHeader (). setAbsoluteTimestamp (dts + 0x00ffefff );
Video. getHeader (). setAbsoluteTimestamp (dts + 0x00ffefff );
RtmpPacket. getHeader (). setAbsoluteTimestamp (int) chunkStreamInfo. markAbsoluteTimestampTx () + 0x00ffefff );
This will soon run to ffffff. Minutes.
Print the timestamp log at the subcontracted sending interface. extended timestamp corresponds:
WriteTo () in com/github/faucamp/simplertmp/packets/RtmpHeader. java
Case TYPE_0_FULL: And case TYPE_3_RELATIVE_SINGLE_BYTE:
First Attempt:
Remove Util. writeUnsignedInt32 (out, extendedTimestamp) from Type = 3 );
Comment out the following line:
Util. writeUnsignedInt32 (out, extendedTimestamp );
When the streaming timestamp exceeds 0 xffffff, the srs is pushed normally, and an error is reported when the Nginx-rtmp is pushed.
Second Attempt:
Extended timestamp of Type = 3 must be used after Type = 0
You only need to change the following sentence:
If (absoluteTimestamp> = 0 xffffff)
Change
If (extendedTimestamp> = 0)
When the streaming timestamp exceeds 0 xffffff, an error is occasionally reported when srs is pushed, and Nginx-rtmp is normal.
Occasionally, problems may occur. The reason is unknown.
The third attempt:
The timestamp of Type = 3 is the same as the timestamp of Type = 0 when chunk is split in the same package.
The code for changing Type = 3 based on the previous modification is as follows:
if (extendedTimestamp > 0) {Util.writeUnsignedInt32(out, extendedTimestamp);}
The streaming timestamp exceeds 0 xffffff, the srs is normal, and the Nginx-rtmp is normal.
The rtmp_specification_1.0.pdf document does not have clear provisions. What should I do with this timestamp.
The Group communicates with the authors of srs and yasea projects and finds that the problem is true.
Srs great god winlin Popular Science. If you think carefully, both methods should be compatible.
If Type = 3 has a timestamp, the timestamp should be equal to the timestamp of Type = 0 in the same package.
If Type = 3, there is no timestamp. Use the timestamp of Type = 0 in the same package.
In fact, ffmpeg does this, and srs does the same. Nginx-rtmp is not compatible with the two.
In order to make it simple and practical, Type = 1 or 2.
Therefore, the faucamp/simplertmp library referenced by yasea has a bug.
Winlin's blog also mentions related issues. Reference: http://blog.csdn.net/win_lin/article/details/13363699