优化纯音频流的延时

This commit is contained in:
xiongziliang 2020-01-24 22:16:28 +08:00
parent a9539eb626
commit 92f69c3915
2 changed files with 11 additions and 2 deletions

View File

@ -129,6 +129,10 @@ public:
*/ */
void onWrite(const RtmpPacket::Ptr &pkt, bool key = true) override { void onWrite(const RtmpPacket::Ptr &pkt, bool key = true) override {
lock_guard<recursive_mutex> lock(_mtx); lock_guard<recursive_mutex> lock(_mtx);
if(pkt->typeId == MSG_VIDEO){
//有视频那么启用GOP缓存
_have_video = true;
}
if (pkt->isCfgFrame()) { if (pkt->isCfgFrame()) {
_config_frame_map[pkt->typeId] = pkt; _config_frame_map[pkt->typeId] = pkt;
return; return;
@ -155,7 +159,8 @@ public:
} }
} }
_track_stamps_map[pkt->typeId] = pkt->timeStamp; _track_stamps_map[pkt->typeId] = pkt->timeStamp;
_ring->write(pkt, pkt->isVideoKeyFrame()); //不存在视频为了减少缓存延时那么关闭GOP缓存
_ring->write(pkt, _have_video ? pkt->isVideoKeyFrame() : true);
checkNoneReader(); checkNoneReader();
} }
@ -203,6 +208,7 @@ private:
protected: protected:
int _ring_size; int _ring_size;
bool _async_emit_none_reader = false; bool _async_emit_none_reader = false;
bool _have_video = false;
mutable recursive_mutex _mtx; mutable recursive_mutex _mtx;
Ticker _reader_changed_ticker; Ticker _reader_changed_ticker;
AMFValue _metadata; AMFValue _metadata;

View File

@ -153,6 +153,7 @@ public:
virtual void setSdp(const string &sdp) { virtual void setSdp(const string &sdp) {
_sdp = sdp; _sdp = sdp;
_sdp_parser.load(sdp); _sdp_parser.load(sdp);
_have_video = (bool)_sdp_parser.getTrack(TrackVideo);
if (_ring) { if (_ring) {
regist(); regist();
} }
@ -188,7 +189,8 @@ public:
regist(); regist();
} }
} }
_ring->write(rtp, keyPos); //不存在视频为了减少缓存延时那么关闭GOP缓存
_ring->write(rtp, _have_video ? keyPos : true);
checkNoneReader(); checkNoneReader();
} }
private: private:
@ -220,6 +222,7 @@ private:
protected: protected:
int _ring_size; int _ring_size;
bool _async_emit_none_reader = false; bool _async_emit_none_reader = false;
bool _have_video = false;
Ticker _reader_changed_ticker; Ticker _reader_changed_ticker;
SdpParser _sdp_parser; SdpParser _sdp_parser;
string _sdp; string _sdp;