Skip to content

Commit

Permalink
SRT: Refine packet error handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jun 8, 2022
1 parent 99a6d72 commit fbb7096
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
19 changes: 14 additions & 5 deletions trunk/src/app/srs_app_srt_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion trunk/src/app/srs_app_srt_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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#common-live
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);
Expand Down

0 comments on commit fbb7096

Please sign in to comment.