diff --git a/src/Rtp/PSEncoder.cpp b/src/Rtp/PSEncoder.cpp index dc37f9e2..5195626d 100644 --- a/src/Rtp/PSEncoder.cpp +++ b/src/Rtp/PSEncoder.cpp @@ -11,6 +11,7 @@ #if defined(ENABLE_RTPPROXY) #include "PSEncoder.h" #include "Extension/H264.h" +#include "Rtsp/RtspMuxer.h" namespace mediakit{ PSEncoder::PSEncoder() { @@ -147,24 +148,6 @@ void PSEncoder::inputFrame(const Frame::Ptr &frame) { } } -//////////////////////////////////////////////////////////////////////////////////////////////// - -class RingDelegateHelper : public RingDelegate { -public: - typedef function onRtp; - - ~RingDelegateHelper() override{} - RingDelegateHelper(onRtp on_rtp){ - _on_rtp = std::move(on_rtp); - } - void onWrite(RtpPacket::Ptr in, bool is_key) override{ - _on_rtp(std::move(in), is_key); - } - -private: - onRtp _on_rtp; -}; - //////////////////////////////////////////////////////////////////////////////////////////////////////////////// PSEncoderImp::PSEncoderImp(uint32_t ssrc, uint8_t payload_type) { diff --git a/src/Rtsp/RtspMuxer.cpp b/src/Rtsp/RtspMuxer.cpp index ddb42751..93d2940d 100644 --- a/src/Rtsp/RtspMuxer.cpp +++ b/src/Rtsp/RtspMuxer.cpp @@ -13,20 +13,6 @@ namespace mediakit { -class RingDelegateHelper : public RingDelegate { -public: - RingDelegateHelper(RtspMuxer *delegate) { - _delegate = delegate; - } - - void onWrite(RtpPacket::Ptr in, bool is_key) override { - _delegate->onRtp(std::move(in), is_key); - } - -private: - RtspMuxer *_delegate; -}; - void RtspMuxer::onRtp(RtpPacket::Ptr in, bool is_key) { if (_rtp_stamp[in->type] != in->getHeader()->stamp) { //rtp时间戳变化才计算ntp,节省cpu资源 @@ -51,7 +37,9 @@ RtspMuxer::RtspMuxer(const TitleSdp::Ptr &title) { } _rtpRing = std::make_shared(); _rtpInterceptor = std::make_shared(); - _rtpInterceptor->setDelegate(std::make_shared(this)); + _rtpInterceptor->setDelegate(std::make_shared([this](RtpPacket::Ptr in, bool is_key) { + onRtp(std::move(in), is_key); + })); _ntp_stamp_start = getCurrentMillisecond(true); } diff --git a/src/Rtsp/RtspMuxer.h b/src/Rtsp/RtspMuxer.h index 8ae7cb39..eab2cbeb 100644 --- a/src/Rtsp/RtspMuxer.h +++ b/src/Rtsp/RtspMuxer.h @@ -17,12 +17,28 @@ #include "RtpCodec.h" namespace mediakit{ + +class RingDelegateHelper : public RingDelegate { +public: + typedef function onRtp; + + ~RingDelegateHelper() override{} + RingDelegateHelper(onRtp on_rtp){ + _on_rtp = std::move(on_rtp); + } + void onWrite(RtpPacket::Ptr in, bool is_key) override{ + _on_rtp(std::move(in), is_key); + } + +private: + onRtp _on_rtp; +}; + /** * rtsp生成器 */ class RtspMuxer : public MediaSinkInterface{ public: - friend class RingDelegateHelper; using Ptr = std::shared_ptr; /** @@ -62,7 +78,6 @@ public: private: void onRtp(RtpPacket::Ptr in, bool is_key); - void computeNtp(const Frame::Ptr &frame); void trySyncTrack(); private: