rtp ntp时间戳采用透传方式 (#2719)

This commit is contained in:
夏楚 2023-07-29 23:04:26 +08:00 committed by GitHub
parent 5a2bf8d196
commit 63a50104fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -39,7 +39,7 @@ RtpPacket::Ptr RtpInfo::makeRtp(TrackType type, const void* data, size_t len, bo
++_seq; ++_seq;
header->stamp = htonl(uint64_t(stamp) * _sample_rate / 1000); header->stamp = htonl(uint64_t(stamp) * _sample_rate / 1000);
header->ssrc = htonl(_ssrc); header->ssrc = htonl(_ssrc);
rtp->ntp_stamp = stamp;
//有效负载 //有效负载
if (data) { if (data) {
memcpy(&ptr[RtpPacket::kRtpHeaderSize + RtpPacket::kRtpTcpHeaderSize], data, len); memcpy(&ptr[RtpPacket::kRtpHeaderSize + RtpPacket::kRtpTcpHeaderSize], data, len);

View File

@ -14,9 +14,12 @@
using namespace std; using namespace std;
using namespace toolkit; using namespace toolkit;
#define ENABLE_NTP_STAMP 0
namespace mediakit { namespace mediakit {
void RtspMuxer::onRtp(RtpPacket::Ptr in, bool is_key) { void RtspMuxer::onRtp(RtpPacket::Ptr in, bool is_key) {
#if ENABLE_NTP_STAMP
if (_live) { if (_live) {
if (_rtp_stamp[in->type] != in->getHeader()->stamp) { if (_rtp_stamp[in->type] != in->getHeader()->stamp) {
//rtp时间戳变化才计算ntp节省cpu资源 //rtp时间戳变化才计算ntp节省cpu资源
@ -34,6 +37,7 @@ void RtspMuxer::onRtp(RtpPacket::Ptr in, bool is_key) {
//点播情况下设置ntp时间戳为rtp时间戳加基准ntp时间戳 //点播情况下设置ntp时间戳为rtp时间戳加基准ntp时间戳
in->ntp_stamp = _ntp_stamp_start + (in->getStamp() * uint64_t(1000) / in->sample_rate); in->ntp_stamp = _ntp_stamp_start + (in->getStamp() * uint64_t(1000) / in->sample_rate);
} }
#endif
_rtpRing->write(std::move(in), is_key); _rtpRing->write(std::move(in), is_key);
} }
@ -49,7 +53,10 @@ RtspMuxer::RtspMuxer(const TitleSdp::Ptr &title) {
_rtpInterceptor->setDelegate(std::make_shared<RingDelegateHelper>([this](RtpPacket::Ptr in, bool is_key) { _rtpInterceptor->setDelegate(std::make_shared<RingDelegateHelper>([this](RtpPacket::Ptr in, bool is_key) {
onRtp(std::move(in), is_key); onRtp(std::move(in), is_key);
})); }));
#if ENABLE_NTP_STAMP
_ntp_stamp_start = getCurrentMillisecond(true); _ntp_stamp_start = getCurrentMillisecond(true);
#endif
} }
bool RtspMuxer::addTrack(const Track::Ptr &track) { bool RtspMuxer::addTrack(const Track::Ptr &track) {
@ -75,10 +82,12 @@ bool RtspMuxer::addTrack(const Track::Ptr &track) {
} }
void RtspMuxer::trySyncTrack() { void RtspMuxer::trySyncTrack() {
#if ENABLE_NTP_STAMP
if (_encoder[TrackAudio] && _encoder[TrackVideo]) { if (_encoder[TrackAudio] && _encoder[TrackVideo]) {
//音频时间戳同步于视频,因为音频时间戳被修改后不影响播放 //音频时间戳同步于视频,因为音频时间戳被修改后不影响播放
_stamp[TrackAudio].syncTo(_stamp[TrackVideo]); _stamp[TrackAudio].syncTo(_stamp[TrackVideo]);
} }
#endif
} }
bool RtspMuxer::inputFrame(const Frame::Ptr &frame) { bool RtspMuxer::inputFrame(const Frame::Ptr &frame) {