Skip to content

Commit e6ccd8e

Browse files
committed
For #3176: GB28181: Error and logging for HEVC. v5.0.95 (#3276)
1. Parse video codec from PSM packet. 2. Return error and logging if HEVC packet. 3. Ignore invalid AVC NALUs, drop AVC AUD and SEI. 4. Disconnect TCP connection if HEVC.
1 parent 56bf2a4 commit e6ccd8e

File tree

6 files changed

+38
-11
lines changed

6 files changed

+38
-11
lines changed

trunk/doc/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The changelog for SRS.
1818

1919
## SRS 5.0 Changelog
2020

21+
* v5.0, 2022-11-23, For [#3176](https://github.com/ossrs/srs/pull/3176): GB28181: Error and logging for HEVC. v5.0.95
2122
* v5.0, 2022-11-22, Merge [#3236](https://github.com/ossrs/srs/pull/3236): Live: Limit cached max frames by gop_cache_max_frames. v5.0.93
2223
* v5.0, 2022-11-22, Asan: Check libasan and show tips. v5.0.92
2324
* v5.0, 2022-11-21, Merge [#3264](https://github.com/ossrs/srs/pull/3264): Asan: Try to fix st_memory_leak for asan check. (#3264). v5.0.91

trunk/src/app/srs_app_gb28181.cpp

+22-4
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,10 @@ srs_error_t SrsLazyGbMediaTcpConn::cycle()
13151315
{
13161316
srs_error_t err = do_cycle();
13171317

1318+
// Should disconnect the TCP connection when stop cycle, especially when we stop first. In this situation, the
1319+
// connection won't be closed because it's shared by other objects.
1320+
srs_freep(conn_);
1321+
13181322
// Change state to disconnected.
13191323
connected_ = false;
13201324
srs_trace("PS: Media disconnect, code=%d", srs_error_code(err));
@@ -1642,10 +1646,19 @@ srs_error_t SrsGbMuxer::on_ts_video(SrsTsMessage* msg, SrsBuffer* avs)
16421646
// 5bits, 7.3.1 NAL unit syntax,
16431647
// ISO_IEC_14496-10-AVC-2003.pdf, page 44.
16441648
// 7: SPS, 8: PPS, 5: I Frame, 1: P Frame
1645-
SrsAvcNaluType nal_unit_type = (SrsAvcNaluType)(frame[0] & 0x1f);
1646-
1647-
// ignore the nalu type sps(7), pps(8), aud(9)
1648-
if (nal_unit_type == SrsAvcNaluTypeAccessUnitDelimiter) {
1649+
SrsAvcNaluType nt = (SrsAvcNaluType)(frame[0] & 0x1f);
1650+
1651+
// Ignore the nalu except video frames:
1652+
// 7: SPS, 8: PPS, 5: I Frame, 1: P Frame, 6: SEI, 9: AUD
1653+
if (
1654+
nt != SrsAvcNaluTypeSPS && nt != SrsAvcNaluTypePPS && nt != SrsAvcNaluTypeIDR &&
1655+
nt != SrsAvcNaluTypeNonIDR && nt != SrsAvcNaluTypeSEI && nt != SrsAvcNaluTypeAccessUnitDelimiter
1656+
) {
1657+
string bytes = srs_string_dumps_hex(frame, frame_size, 4);
1658+
srs_warn("GB: Ignore NALU nt=%d, frame=[%s]", nt, bytes.c_str());
1659+
return err;
1660+
}
1661+
if (nt == SrsAvcNaluTypeSEI || nt == SrsAvcNaluTypeAccessUnitDelimiter) {
16491662
continue;
16501663
}
16511664

@@ -2392,6 +2405,11 @@ srs_error_t SrsRecoverablePsContext::decode(SrsBuffer* stream, ISrsPsMessageHand
23922405
return enter_recover_mode(stream, handler, stream->pos(), srs_error_wrap(err, "decode pack"));
23932406
}
23942407

2408+
// Check stream type, error if HEVC, because not supported yet.
2409+
if (ctx_.video_stream_type_ == SrsTsStreamVideoHEVC) {
2410+
return srs_error_new(ERROR_GB_PS_HEADER, "HEVC is not supported");
2411+
}
2412+
23952413
return err;
23962414
}
23972415

trunk/src/core/srs_core_version5.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
#define VERSION_MAJOR 5
1111
#define VERSION_MINOR 0
12-
#define VERSION_REVISION 94
12+
#define VERSION_REVISION 95
1313

1414
#endif

trunk/src/kernel/srs_kernel_ps.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ SrsPsContext::SrsPsContext()
4848
current_ = NULL;
4949
helper_.ctx_ = this;
5050
detect_ps_integrity_ = false;
51+
video_stream_type_ = SrsTsStreamReserved;
52+
audio_stream_type_ = SrsTsStreamReserved;
5153
}
5254

5355
SrsPsContext::~SrsPsContext()
@@ -121,9 +123,13 @@ srs_error_t SrsPsContext::decode(SrsBuffer* stream, ISrsPsMessageHandler* handle
121123
return srs_error_wrap(err, "decode psm");
122124
}
123125

124-
srs_info("PS: Ignore PSM for video=%#x, audio=%#x", psm.video_elementary_stream_id_, psm.audio_elementary_stream_id_);
125-
//context_->set(psm.video_elementary_stream_id_, SrsTsPidApplyVideo);
126-
//context_->set(psm.audio_elementary_stream_id_, SrsTsPidApplyAudio);
126+
if (video_stream_type_ == SrsTsStreamReserved || audio_stream_type_ == SrsTsStreamReserved) {
127+
srs_trace("PS: Got PSM for video=%#x, audio=%#x", psm.video_elementary_stream_id_, psm.audio_elementary_stream_id_);
128+
} else {
129+
srs_info("PS: Got PSM for video=%#x, audio=%#x", psm.video_elementary_stream_id_, psm.audio_elementary_stream_id_);
130+
}
131+
video_stream_type_ = (SrsTsStream)psm.video_stream_type_;
132+
audio_stream_type_ = (SrsTsStream)psm.audio_stream_type_;
127133
} else if (msg->is_video() || msg->is_audio()) {
128134
// Update the total messages in pack.
129135
helper_.pack_pre_msg_last_seq_ = helper_.rtp_seq_;
@@ -467,7 +473,7 @@ srs_error_t SrsPsPsmPacket::decode(SrsBuffer* stream)
467473
b.skip(elementary_stream_info_length);
468474
srs_info("PS: Ignore %d bytes descriptor for stream=%#x", elementary_stream_info_length, stream_type);
469475

470-
if (stream_type == SrsTsStreamVideoH264) {
476+
if (stream_type == SrsTsStreamVideoH264 || stream_type == SrsTsStreamVideoHEVC) {
471477
video_stream_type_ = stream_type;
472478
video_elementary_stream_id_ = elementary_stream_id;
473479
video_elementary_stream_info_length_ = elementary_stream_info_length;

trunk/src/kernel/srs_kernel_ps.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class SrsPsContext
6666
SrsPsPacket* current_;
6767
// Whether detect PS packet header integrity.
6868
bool detect_ps_integrity_;
69+
public:
70+
// The stream type parsed from latest PSM packet.
71+
SrsTsStream video_stream_type_;
72+
SrsTsStream audio_stream_type_;
6973
public:
7074
SrsPsContext();
7175
virtual ~SrsPsContext();

trunk/src/kernel/srs_kernel_ts.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,8 @@ enum SrsTsStream
131131
// ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Reserved
132132
// 0x15-0x7F
133133
SrsTsStreamVideoH264 = 0x1b,
134-
#ifdef SRS_H265
135134
// For HEVC(H.265).
136135
SrsTsStreamVideoHEVC = 0x24,
137-
#endif
138136
// User Private
139137
// 0x80-0xFF
140138
SrsTsStreamAudioAC3 = 0x81,

0 commit comments

Comments
 (0)