Skip to content

Commit

Permalink
For #3176: GB28181: Error and logging for HEVC. v5.0.95 (#3276)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
winlinvip committed Nov 24, 2022
1 parent 56bf2a4 commit e6ccd8e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
1 change: 1 addition & 0 deletions trunk/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The changelog for SRS.

## SRS 5.0 Changelog

* v5.0, 2022-11-23, For [#3176](https://github.com/ossrs/srs/pull/3176): GB28181: Error and logging for HEVC. v5.0.95
* 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
* v5.0, 2022-11-22, Asan: Check libasan and show tips. v5.0.92
* 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
Expand Down
26 changes: 22 additions & 4 deletions trunk/src/app/srs_app_gb28181.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,10 @@ srs_error_t SrsLazyGbMediaTcpConn::cycle()
{
srs_error_t err = do_cycle();

// Should disconnect the TCP connection when stop cycle, especially when we stop first. In this situation, the
// connection won't be closed because it's shared by other objects.
srs_freep(conn_);

// Change state to disconnected.
connected_ = false;
srs_trace("PS: Media disconnect, code=%d", srs_error_code(err));
Expand Down Expand Up @@ -1642,10 +1646,19 @@ srs_error_t SrsGbMuxer::on_ts_video(SrsTsMessage* msg, SrsBuffer* avs)
// 5bits, 7.3.1 NAL unit syntax,
// ISO_IEC_14496-10-AVC-2003.pdf, page 44.
// 7: SPS, 8: PPS, 5: I Frame, 1: P Frame
SrsAvcNaluType nal_unit_type = (SrsAvcNaluType)(frame[0] & 0x1f);

// ignore the nalu type sps(7), pps(8), aud(9)
if (nal_unit_type == SrsAvcNaluTypeAccessUnitDelimiter) {
SrsAvcNaluType nt = (SrsAvcNaluType)(frame[0] & 0x1f);

// Ignore the nalu except video frames:
// 7: SPS, 8: PPS, 5: I Frame, 1: P Frame, 6: SEI, 9: AUD
if (
nt != SrsAvcNaluTypeSPS && nt != SrsAvcNaluTypePPS && nt != SrsAvcNaluTypeIDR &&
nt != SrsAvcNaluTypeNonIDR && nt != SrsAvcNaluTypeSEI && nt != SrsAvcNaluTypeAccessUnitDelimiter
) {
string bytes = srs_string_dumps_hex(frame, frame_size, 4);
srs_warn("GB: Ignore NALU nt=%d, frame=[%s]", nt, bytes.c_str());
return err;
}
if (nt == SrsAvcNaluTypeSEI || nt == SrsAvcNaluTypeAccessUnitDelimiter) {
continue;
}

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

// Check stream type, error if HEVC, because not supported yet.
if (ctx_.video_stream_type_ == SrsTsStreamVideoHEVC) {
return srs_error_new(ERROR_GB_PS_HEADER, "HEVC is not supported");
}

return err;
}

Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#define VERSION_MAJOR 5
#define VERSION_MINOR 0
#define VERSION_REVISION 94
#define VERSION_REVISION 95

#endif
14 changes: 10 additions & 4 deletions trunk/src/kernel/srs_kernel_ps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ SrsPsContext::SrsPsContext()
current_ = NULL;
helper_.ctx_ = this;
detect_ps_integrity_ = false;
video_stream_type_ = SrsTsStreamReserved;
audio_stream_type_ = SrsTsStreamReserved;
}

SrsPsContext::~SrsPsContext()
Expand Down Expand Up @@ -121,9 +123,13 @@ srs_error_t SrsPsContext::decode(SrsBuffer* stream, ISrsPsMessageHandler* handle
return srs_error_wrap(err, "decode psm");
}

srs_info("PS: Ignore PSM for video=%#x, audio=%#x", psm.video_elementary_stream_id_, psm.audio_elementary_stream_id_);
//context_->set(psm.video_elementary_stream_id_, SrsTsPidApplyVideo);
//context_->set(psm.audio_elementary_stream_id_, SrsTsPidApplyAudio);
if (video_stream_type_ == SrsTsStreamReserved || audio_stream_type_ == SrsTsStreamReserved) {
srs_trace("PS: Got PSM for video=%#x, audio=%#x", psm.video_elementary_stream_id_, psm.audio_elementary_stream_id_);
} else {
srs_info("PS: Got PSM for video=%#x, audio=%#x", psm.video_elementary_stream_id_, psm.audio_elementary_stream_id_);
}
video_stream_type_ = (SrsTsStream)psm.video_stream_type_;
audio_stream_type_ = (SrsTsStream)psm.audio_stream_type_;
} else if (msg->is_video() || msg->is_audio()) {
// Update the total messages in pack.
helper_.pack_pre_msg_last_seq_ = helper_.rtp_seq_;
Expand Down Expand Up @@ -467,7 +473,7 @@ srs_error_t SrsPsPsmPacket::decode(SrsBuffer* stream)
b.skip(elementary_stream_info_length);
srs_info("PS: Ignore %d bytes descriptor for stream=%#x", elementary_stream_info_length, stream_type);

if (stream_type == SrsTsStreamVideoH264) {
if (stream_type == SrsTsStreamVideoH264 || stream_type == SrsTsStreamVideoHEVC) {
video_stream_type_ = stream_type;
video_elementary_stream_id_ = elementary_stream_id;
video_elementary_stream_info_length_ = elementary_stream_info_length;
Expand Down
4 changes: 4 additions & 0 deletions trunk/src/kernel/srs_kernel_ps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class SrsPsContext
SrsPsPacket* current_;
// Whether detect PS packet header integrity.
bool detect_ps_integrity_;
public:
// The stream type parsed from latest PSM packet.
SrsTsStream video_stream_type_;
SrsTsStream audio_stream_type_;
public:
SrsPsContext();
virtual ~SrsPsContext();
Expand Down
2 changes: 0 additions & 2 deletions trunk/src/kernel/srs_kernel_ts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,8 @@ enum SrsTsStream
// ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Reserved
// 0x15-0x7F
SrsTsStreamVideoH264 = 0x1b,
#ifdef SRS_H265
// For HEVC(H.265).
SrsTsStreamVideoHEVC = 0x24,
#endif
// User Private
// 0x80-0xFF
SrsTsStreamAudioAC3 = 0x81,
Expand Down

0 comments on commit e6ccd8e

Please sign in to comment.