From c47e875d6334cf14cbcc74fbbd2e9761851ff8a8 Mon Sep 17 00:00:00 2001 From: Keukhan Date: Mon, 23 Dec 2024 13:56:20 +0900 Subject: [PATCH] Fixed issue where data type packet statistics were not calculated --- .../mediarouter/mediarouter_stream.cpp | 20 ++++++++----------- src/projects/mediarouter/mediarouter_stream.h | 2 +- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/projects/mediarouter/mediarouter_stream.cpp b/src/projects/mediarouter/mediarouter_stream.cpp index 878cd7145..c0eb76038 100644 --- a/src/projects/mediarouter/mediarouter_stream.cpp +++ b/src/projects/mediarouter/mediarouter_stream.cpp @@ -854,6 +854,11 @@ bool MediaRouteStream::NormalizeMediaPacket(std::shared_ptr &media_t { bool result = false; + if(media_track->GetMediaType() == cmn::MediaType::Data) + { + return true; + } + switch (media_packet->GetBitstreamFormat()) { case cmn::BitstreamFormat::H264_ANNEXB: @@ -1178,11 +1183,6 @@ std::shared_ptr MediaRouteStream::PopAndNormalize() auto &media_packet = media_packet_ref.value(); - if (media_packet->GetMediaType() == MediaType::Data) - { - return media_packet; - } - //////////////////////////////////////////////////////////////////////////////////// // [ Calculating Packet Timestamp, Duration] @@ -1290,7 +1290,7 @@ std::shared_ptr MediaRouteStream::PopAndNormalize() // Detect abnormal increases in PTS. if (GetInoutType() == MediaRouterStreamType::INBOUND) { - DetectAbnormalPackets(pop_media_packet); + DetectAbnormalPackets(media_track, pop_media_packet); } // Statistics @@ -1320,22 +1320,18 @@ std::vector> MediaRouteStrea return _mirror_buffer; } -void MediaRouteStream::DetectAbnormalPackets(std::shared_ptr &packet) +void MediaRouteStream::DetectAbnormalPackets(std::shared_ptr &media_track, std::shared_ptr &packet) { auto track_id = packet->GetTrackId(); auto it = _pts_last.find(track_id); if (it != _pts_last.end()) { - auto media_track = _stream->GetTrack(track_id); - if (!media_track) - return; - int64_t ts_ms = packet->GetPts() * media_track->GetTimeBase().GetExpr(); int64_t ts_diff_ms = ts_ms - _pts_last[track_id]; if (std::abs(ts_diff_ms) > PTS_CORRECT_THRESHOLD_MS) { - if (IsImageCodec(media_track->GetCodecId()) == false) + if (IsVideoCodec(media_track->GetCodecId()) || IsAudioCodec(media_track->GetCodecId())) { logtw("[%s/%s(%u)] Detected abnormal increased timestamp. track:%u last.pts: %lld, cur.pts: %lld, tb(%d/%d), diff: %lldms", _stream->GetApplicationInfo().GetVHostAppName().CStr(), diff --git a/src/projects/mediarouter/mediarouter_stream.h b/src/projects/mediarouter/mediarouter_stream.h index 3e6e05898..5e1ff47c3 100644 --- a/src/projects/mediarouter/mediarouter_stream.h +++ b/src/projects/mediarouter/mediarouter_stream.h @@ -79,7 +79,7 @@ class MediaRouteStream private: void DropNonDecodingPackets(); - void DetectAbnormalPackets(std::shared_ptr &packet); + void DetectAbnormalPackets(std::shared_ptr &media_track, std::shared_ptr &packet); bool ProcessH264AVCCStream(std::shared_ptr &media_track, std::shared_ptr &media_packet); bool ProcessH264AnnexBStream(std::shared_ptr &media_track, std::shared_ptr &media_packet);