From 8398ae17e4312c7e66f42b7ea25d25856d4c3e36 Mon Sep 17 00:00:00 2001 From: xiongguangjie Date: Sun, 21 Jul 2024 20:43:52 +0800 Subject: [PATCH] compatible rtsp sdp parse no samplerate for audio (#3740) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 兼容rtsp sdp协商中未声明采样率但是可以通过a 字段中fmtp中有config中解析出来的情况 --- src/Rtsp/Rtsp.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Rtsp/Rtsp.cpp b/src/Rtsp/Rtsp.cpp index 7a7b0b2d..d1cc0356 100644 --- a/src/Rtsp/Rtsp.cpp +++ b/src/Rtsp/Rtsp.cpp @@ -15,6 +15,7 @@ #include "Common/Parser.h" #include "Common/config.h" #include "Network/Socket.h" +#include "Extension/Factory.h" using namespace std; using namespace toolkit; @@ -236,10 +237,6 @@ void SdpParser::load(const string &sdp) { track._codec = codec; track._samplerate = samplerate; } - if (!track._samplerate && track._type == TrackVideo) { - // 未设置视频采样率时,赋值为90000 - track._samplerate = 90000; - } ++it; } @@ -260,6 +257,17 @@ void SdpParser::load(const string &sdp) { if (it != track._attr.end()) { track._control = it->second; } + + if (!track._samplerate && track._type == TrackVideo) { + // 未设置视频采样率时,赋值为90000 + track._samplerate = 90000; + } else if (!track._samplerate && track._type == TrackAudio) { + // some rtsp sdp no sample rate but has fmt config to parser get sample rate + auto t = Factory::getTrackBySdp(track_ptr); + if (t) { + track._samplerate = std::static_pointer_cast(t)->getAudioSampleRate(); + } + } } }