mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-23 11:17:09 +08:00
when start send rtp wait key rtp previous drop (#1789)
This commit is contained in:
parent
4f7d3d820f
commit
14da5ab2d8
@ -76,7 +76,7 @@ bool CommonRtpEncoder::inputFrame(const Frame::Ptr &frame){
|
|||||||
auto len = frame->size() - frame->prefixSize();
|
auto len = frame->size() - frame->prefixSize();
|
||||||
auto remain_size = len;
|
auto remain_size = len;
|
||||||
auto max_size = getMaxSize();
|
auto max_size = getMaxSize();
|
||||||
|
bool is_key = frame->keyFrame();
|
||||||
bool mark = false;
|
bool mark = false;
|
||||||
while (remain_size > 0) {
|
while (remain_size > 0) {
|
||||||
size_t rtp_size;
|
size_t rtp_size;
|
||||||
@ -86,9 +86,10 @@ bool CommonRtpEncoder::inputFrame(const Frame::Ptr &frame){
|
|||||||
rtp_size = remain_size;
|
rtp_size = remain_size;
|
||||||
mark = true;
|
mark = true;
|
||||||
}
|
}
|
||||||
RtpCodec::inputRtp(makeRtp(getTrackType(), ptr, rtp_size, mark, stamp), false);
|
RtpCodec::inputRtp(makeRtp(getTrackType(), ptr, rtp_size, mark, stamp), is_key);
|
||||||
ptr += rtp_size;
|
ptr += rtp_size;
|
||||||
remain_size -= rtp_size;
|
remain_size -= rtp_size;
|
||||||
|
is_key = false;
|
||||||
}
|
}
|
||||||
return len > 0;
|
return len > 0;
|
||||||
}
|
}
|
@ -391,17 +391,18 @@ class FrameFromPtr : public Frame{
|
|||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<FrameFromPtr> Ptr;
|
typedef std::shared_ptr<FrameFromPtr> Ptr;
|
||||||
|
|
||||||
FrameFromPtr(CodecId codec_id, char *ptr, size_t size, uint32_t dts, uint32_t pts = 0, size_t prefix_size = 0)
|
FrameFromPtr(CodecId codec_id, char *ptr, size_t size, uint32_t dts, uint32_t pts = 0, size_t prefix_size = 0,bool is_key = false )
|
||||||
: FrameFromPtr(ptr, size, dts, pts, prefix_size) {
|
: FrameFromPtr(ptr, size, dts, pts, prefix_size,is_key) {
|
||||||
_codec_id = codec_id;
|
_codec_id = codec_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameFromPtr(char *ptr, size_t size, uint32_t dts, uint32_t pts = 0, size_t prefix_size = 0){
|
FrameFromPtr(char *ptr, size_t size, uint32_t dts, uint32_t pts = 0, size_t prefix_size = 0,bool is_key = false){
|
||||||
_ptr = ptr;
|
_ptr = ptr;
|
||||||
_size = size;
|
_size = size;
|
||||||
_dts = dts;
|
_dts = dts;
|
||||||
_pts = pts;
|
_pts = pts;
|
||||||
_prefix_size = prefix_size;
|
_prefix_size = prefix_size;
|
||||||
|
_is_key = is_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *data() const override{
|
char *data() const override{
|
||||||
@ -440,7 +441,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool keyFrame() const override {
|
bool keyFrame() const override {
|
||||||
return false;
|
return _is_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool configFrame() const override{
|
bool configFrame() const override{
|
||||||
@ -457,6 +458,7 @@ protected:
|
|||||||
size_t _size;
|
size_t _size;
|
||||||
size_t _prefix_size;
|
size_t _prefix_size;
|
||||||
CodecId _codec_id = CodecInvalid;
|
CodecId _codec_id = CodecInvalid;
|
||||||
|
bool _is_key;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,7 +23,7 @@ PSEncoderImp::PSEncoderImp(uint32_t ssrc, uint8_t payload_type) : MpegMuxer(true
|
|||||||
_rtp_encoder = std::make_shared<CommonRtpEncoder>(CodecInvalid, ssrc, video_mtu, 90000, payload_type, 0);
|
_rtp_encoder = std::make_shared<CommonRtpEncoder>(CodecInvalid, ssrc, video_mtu, 90000, payload_type, 0);
|
||||||
_rtp_encoder->setRtpRing(std::make_shared<RtpRing::RingType>());
|
_rtp_encoder->setRtpRing(std::make_shared<RtpRing::RingType>());
|
||||||
_rtp_encoder->getRtpRing()->setDelegate(std::make_shared<RingDelegateHelper>([this](RtpPacket::Ptr rtp, bool is_key){
|
_rtp_encoder->getRtpRing()->setDelegate(std::make_shared<RingDelegateHelper>([this](RtpPacket::Ptr rtp, bool is_key){
|
||||||
onRTP(std::move(rtp));
|
onRTP(std::move(rtp),is_key);
|
||||||
}));
|
}));
|
||||||
InfoL << this << " " << printSSRC(_rtp_encoder->getSsrc());
|
InfoL << this << " " << printSSRC(_rtp_encoder->getSsrc());
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ void PSEncoderImp::onWrite(std::shared_ptr<Buffer> buffer, uint32_t stamp, bool
|
|||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_rtp_encoder->inputFrame(std::make_shared<FrameFromPtr>(buffer->data(), buffer->size(), stamp, stamp));
|
_rtp_encoder->inputFrame(std::make_shared<FrameFromPtr>(buffer->data(), buffer->size(), stamp, stamp,0,key_pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
|
@ -27,7 +27,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
//rtp打包后回调
|
//rtp打包后回调
|
||||||
virtual void onRTP(toolkit::Buffer::Ptr rtp) = 0;
|
virtual void onRTP(toolkit::Buffer::Ptr rtp,bool is_key = false) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onWrite(std::shared_ptr<toolkit::Buffer> buffer, uint32_t stamp, bool key_pos) override;
|
void onWrite(std::shared_ptr<toolkit::Buffer> buffer, uint32_t stamp, bool key_pos) override;
|
||||||
|
@ -35,7 +35,7 @@ bool RawEncoderImp::addTrack(const Track::Ptr &track){
|
|||||||
_rtp_encoder = createRtpEncoder(track);
|
_rtp_encoder = createRtpEncoder(track);
|
||||||
_rtp_encoder->setRtpRing(std::make_shared<RtpRing::RingType>());
|
_rtp_encoder->setRtpRing(std::make_shared<RtpRing::RingType>());
|
||||||
_rtp_encoder->getRtpRing()->setDelegate(std::make_shared<RingDelegateHelper>([this](RtpPacket::Ptr rtp, bool is_key){
|
_rtp_encoder->getRtpRing()->setDelegate(std::make_shared<RingDelegateHelper>([this](RtpPacket::Ptr rtp, bool is_key){
|
||||||
onRTP(std::move(rtp));
|
onRTP(std::move(rtp),true);
|
||||||
}));
|
}));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ bool RawEncoderImp::addTrack(const Track::Ptr &track){
|
|||||||
_rtp_encoder = createRtpEncoder(track);
|
_rtp_encoder = createRtpEncoder(track);
|
||||||
_rtp_encoder->setRtpRing(std::make_shared<RtpRing::RingType>());
|
_rtp_encoder->setRtpRing(std::make_shared<RtpRing::RingType>());
|
||||||
_rtp_encoder->getRtpRing()->setDelegate(std::make_shared<RingDelegateHelper>([this](RtpPacket::Ptr rtp, bool is_key){
|
_rtp_encoder->getRtpRing()->setDelegate(std::make_shared<RingDelegateHelper>([this](RtpPacket::Ptr rtp, bool is_key){
|
||||||
onRTP(std::move(rtp));
|
onRTP(std::move(rtp),is_key);
|
||||||
}));
|
}));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -43,10 +43,9 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
//rtp打包后回调
|
//rtp打包后回调
|
||||||
virtual void onRTP(toolkit::Buffer::Ptr rtp) = 0;
|
virtual void onRTP(toolkit::Buffer::Ptr rtp, bool is_key = false) = 0;
|
||||||
private:
|
private:
|
||||||
RtpCodec::Ptr createRtpEncoder(const Track::Ptr &track);
|
RtpCodec::Ptr createRtpEncoder(const Track::Ptr &track);
|
||||||
|
|
||||||
uint32_t _ssrc;
|
uint32_t _ssrc;
|
||||||
uint8_t _payload_type;
|
uint8_t _payload_type;
|
||||||
bool _sendAudio;
|
bool _sendAudio;
|
||||||
|
@ -19,25 +19,37 @@ namespace mediakit{
|
|||||||
RtpCache::RtpCache(onFlushed cb) {
|
RtpCache::RtpCache(onFlushed cb) {
|
||||||
_cb = std::move(cb);
|
_cb = std::move(cb);
|
||||||
}
|
}
|
||||||
|
bool RtpCache::firstKeyReady(bool in) {
|
||||||
|
if(_first_key){
|
||||||
|
return _first_key;
|
||||||
|
}
|
||||||
|
_first_key = in;
|
||||||
|
return _first_key;
|
||||||
|
}
|
||||||
void RtpCache::onFlush(std::shared_ptr<List<Buffer::Ptr> > rtp_list, bool) {
|
void RtpCache::onFlush(std::shared_ptr<List<Buffer::Ptr> > rtp_list, bool) {
|
||||||
_cb(std::move(rtp_list));
|
_cb(std::move(rtp_list));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtpCache::input(uint64_t stamp, Buffer::Ptr buffer) {
|
void RtpCache::input(uint64_t stamp, Buffer::Ptr buffer,bool is_key ) {
|
||||||
inputPacket(stamp, true, std::move(buffer), false);
|
inputPacket(stamp, true, std::move(buffer), is_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtpCachePS::onRTP(Buffer::Ptr buffer) {
|
void RtpCachePS::onRTP(Buffer::Ptr buffer,bool is_key) {
|
||||||
|
if(!firstKeyReady(is_key)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto rtp = std::static_pointer_cast<RtpPacket>(buffer);
|
auto rtp = std::static_pointer_cast<RtpPacket>(buffer);
|
||||||
auto stamp = rtp->getStampMS();
|
auto stamp = rtp->getStampMS();
|
||||||
input(stamp, std::move(buffer));
|
input(stamp, std::move(buffer),is_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtpCacheRaw::onRTP(Buffer::Ptr buffer) {
|
void RtpCacheRaw::onRTP(Buffer::Ptr buffer,bool is_key) {
|
||||||
|
if(!firstKeyReady(is_key)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto rtp = std::static_pointer_cast<RtpPacket>(buffer);
|
auto rtp = std::static_pointer_cast<RtpPacket>(buffer);
|
||||||
auto stamp = rtp->getStampMS();
|
auto stamp = rtp->getStampMS();
|
||||||
input(stamp, std::move(buffer));
|
input(stamp, std::move(buffer),is_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
|
@ -30,13 +30,15 @@ protected:
|
|||||||
* 输入rtp(目的是为了合并写)
|
* 输入rtp(目的是为了合并写)
|
||||||
* @param buffer rtp数据
|
* @param buffer rtp数据
|
||||||
*/
|
*/
|
||||||
void input(uint64_t stamp, toolkit::Buffer::Ptr buffer);
|
void input(uint64_t stamp, toolkit::Buffer::Ptr buffer,bool is_key = false);
|
||||||
|
|
||||||
|
bool firstKeyReady(bool in);
|
||||||
protected:
|
protected:
|
||||||
void onFlush(std::shared_ptr<toolkit::List<toolkit::Buffer::Ptr> > rtp_list, bool) override;
|
void onFlush(std::shared_ptr<toolkit::List<toolkit::Buffer::Ptr> > rtp_list, bool) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
onFlushed _cb;
|
onFlushed _cb;
|
||||||
|
bool _first_key = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RtpCachePS : public RtpCache, public PSEncoderImp{
|
class RtpCachePS : public RtpCache, public PSEncoderImp{
|
||||||
@ -45,7 +47,7 @@ public:
|
|||||||
~RtpCachePS() override = default;
|
~RtpCachePS() override = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onRTP(toolkit::Buffer::Ptr rtp) override;
|
void onRTP(toolkit::Buffer::Ptr rtp,bool is_key = false) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +57,7 @@ public:
|
|||||||
~RtpCacheRaw() override = default;
|
~RtpCacheRaw() override = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onRTP(toolkit::Buffer::Ptr rtp) override;
|
void onRTP(toolkit::Buffer::Ptr rtp,bool is_key = false) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
|
Loading…
Reference in New Issue
Block a user