mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 12:37:09 +08:00
rtp ntp时间戳采用透传方式 (#2719)
This commit is contained in:
parent
5a2bf8d196
commit
63a50104fa
@ -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);
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user