SRT: Refine packet error handler.

pull/3089/head
winlin 3 years ago
parent 9a0db5a14f
commit 8437370c1e

@ -312,6 +312,7 @@ srs_error_t SrsMpegtsSrtConn::playing()
return err;
}
// TODO: FIXME: It's not atomic and has risk between multiple source checking.
srs_error_t SrsMpegtsSrtConn::acquire_publish()
{
srs_error_t err = srs_success;
@ -370,8 +371,6 @@ srs_error_t SrsMpegtsSrtConn::do_publishing()
}
pprint->elapse();
// reportable
if (pprint->can_print()) {
SrsSrtStat s;
if ((err = s.fetch(srt_fd_, true)) != srs_success) {
@ -485,9 +484,19 @@ srs_error_t SrsMpegtsSrtConn::on_srt_packet(char* buf, int nb_buf)
{
srs_error_t err = srs_success;
// Check srt payload, mpegts must be N times of SRS_TS_PACKET_SIZE, and the first byte must be 0x47
if ((nb_buf <= 0) || (nb_buf % SRS_TS_PACKET_SIZE != 0) || (buf[0] != 0x47)) {
return srs_error_new(ERROR_SRT_CONN, "invalid ts packet");
// Ignore if invalid length.
if (nb_buf <= 0) {
return err;
}
// Check srt payload, mpegts must be N times of SRS_TS_PACKET_SIZE
if ((nb_buf % SRS_TS_PACKET_SIZE) != 0) {
return srs_error_new(ERROR_SRT_CONN, "invalid ts packet len=%d", nb_buf);
}
// Check srt payload, the first byte must be 0x47
if (buf[0] != 0x47) {
return srs_error_new(ERROR_SRT_CONN, "invalid ts packet first=%#x", (uint8_t)buf[0]);
}
SrsSrtPacket* packet = new SrsSrtPacket();

@ -287,7 +287,8 @@ srs_error_t SrsRtmpFromSrtBridge::on_packet(SrsSrtPacket *pkt)
SrsBuffer* stream = new SrsBuffer(p, SRS_TS_PACKET_SIZE);
SrsAutoFree(SrsBuffer, stream);
// process each ts packet
// Process each ts packet. Note that the jitter of UDP may cause video glitch when packet loss or wrong seq. We
// don't handle it because SRT will, see tlpkdrop at https://github.com/ossrs/srs/wiki/v5_EN_SRTParams
if ((err = ts_ctx_->decode(stream, this)) != srs_success) {
srs_warn("parse ts packet err=%s", srs_error_desc(err).c_str());
srs_error_reset(err);

Loading…
Cancel
Save