Skip to content

Commit b2b6087

Browse files
committed
SRT: Refine packet error handler.
1 parent 99a6d72 commit b2b6087

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

trunk/src/app/srs_app_srt_conn.cpp

+14-5
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ srs_error_t SrsMpegtsSrtConn::playing()
312312
return err;
313313
}
314314

315+
// TODO: FIXME: It's not atomic and has risk between multiple source checking.
315316
srs_error_t SrsMpegtsSrtConn::acquire_publish()
316317
{
317318
srs_error_t err = srs_success;
@@ -370,8 +371,6 @@ srs_error_t SrsMpegtsSrtConn::do_publishing()
370371
}
371372

372373
pprint->elapse();
373-
374-
// reportable
375374
if (pprint->can_print()) {
376375
SrsSrtStat s;
377376
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)
485484
{
486485
srs_error_t err = srs_success;
487486

488-
// Check srt payload, mpegts must be N times of SRS_TS_PACKET_SIZE, and the first byte must be 0x47
489-
if ((nb_buf <= 0) || (nb_buf % SRS_TS_PACKET_SIZE != 0) || (buf[0] != 0x47)) {
490-
return srs_error_new(ERROR_SRT_CONN, "invalid ts packet");
487+
// Ignore if invalid length.
488+
if (nb_buf <= 0) {
489+
return err;
490+
}
491+
492+
// Check srt payload, mpegts must be N times of SRS_TS_PACKET_SIZE
493+
if ((nb_buf % SRS_TS_PACKET_SIZE) != 0) {
494+
return srs_error_new(ERROR_SRT_CONN, "invalid ts packet len=%d", nb_buf);
495+
}
496+
497+
// Check srt payload, the first byte must be 0x47
498+
if (buf[0] != 0x47) {
499+
return srs_error_new(ERROR_SRT_CONN, "invalid ts packet first=%#x", (uint8_t)buf[0]);
491500
}
492501

493502
SrsSrtPacket* packet = new SrsSrtPacket();

trunk/src/app/srs_app_srt_source.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ srs_error_t SrsRtmpFromSrtBridge::on_packet(SrsSrtPacket *pkt)
287287
SrsBuffer* stream = new SrsBuffer(p, SRS_TS_PACKET_SIZE);
288288
SrsAutoFree(SrsBuffer, stream);
289289

290-
// process each ts packet
290+
// Process each ts packet. Note that the jitter of UDP may cause video glitch when packet loss or wrong seq. We
291+
// don't handle it because SRT will, see tlpkdrop at https://github.com/ossrs/srs/wiki/v5_EN_SRTParams
291292
if ((err = ts_ctx_->decode(stream, this)) != srs_success) {
292293
srs_warn("parse ts packet err=%s", srs_error_desc(err).c_str());
293294
srs_error_reset(err);

0 commit comments

Comments
 (0)