From e68d84be5153a0ecaa44dc1dda2e67120eae202f Mon Sep 17 00:00:00 2001 From: nanguantong Date: Sun, 29 Sep 2024 14:39:22 +0800 Subject: [PATCH] fix: ps file seek for rtsp test --- librtsp/test/media/ps-file-reader.cpp | 34 ++++++++++++++++----------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/librtsp/test/media/ps-file-reader.cpp b/librtsp/test/media/ps-file-reader.cpp index ef1165bc..8e684b05 100644 --- a/librtsp/test/media/ps-file-reader.cpp +++ b/librtsp/test/media/ps-file-reader.cpp @@ -67,25 +67,31 @@ int PSFileReader::Init() int PSFileReader::Seek(int64_t& dts) { - int r = 0; + int64_t fisrt_dts = -1; - /*vframe_t frame; - frame.time = dts; + while (1) + { + std::shared_ptr pkt(m_pkts->Cur(), avpacket_release); + if (NULL == pkt) + return -1; - vframes_t::iterator it; - it = std::lower_bound(m_videos.begin(), m_videos.end(), frame); - if (it == m_videos.end()) - return -1; + if (fisrt_dts == -1) + fisrt_dts = pkt->dts / 90; - while (it != m_videos.begin()) - { - if (it->idr) + if (dts < fisrt_dts) + break; + + if (dts >= (pkt->dts / 90)) { - m_vit = it; - return 0; + // only audio + if (m_v_start_ts < 0) + break; + + if (pkt->flags & AVPACKET_FLAG_KEY) + break; } - --it; - }*/ + } + return 0; }